akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;
int n, d;

int main() {
  cin >> n >> d;
  int x[n + 1][d + 1];
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < d; ++j) cin >> x[i][j];

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int subtot = 0;
      for (int k = 0; k < d; ++k) {
        subtot += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
      }
      double subtotsq = sqrt(subtot);
      if (floor(subtotsq) == subtotsq) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.io.PrintWriter;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int a = Integer.parseInt(str[0]);
    int b = Integer.parseInt(str[1]);
    PrintWriter pw = new PrintWriter(System.out);
    pw.println(a!=2 && b!=2?"Yes":"No");
    pw.flush();
  }
}

Measured memory_bytes: 22612
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
nf = lambda: float(ns())
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda x: [na() for _ in range(x)]
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
x, u = [], []
for i in range(n):
    s = nas()
    a, b = float(s[0]), s[1].rstrip()
    x.append(a)
    u.append(b)

ans = 0.0
for i in range(n):
    if u[i] == "JPY":
        ans += x[i]
    else:
        ans += 380000.0 * x[i]

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <queue>
#include <cstdlib>

using namespace std;
typedef long long int ll;

bool debug = false;
#define show(x) if (debug) {cout << "" # x << " = " << x << endl;}
#define rep(x, a, b) for (int x = a; x < b; x++)

int main() {
  string s;
  cin >> s;

  int a = 0;
  int n = 0;
  for (auto c : s) {
    if (c == 'S') {
      n++;
    } else if (n > 0) {
      n--;
    } else {
      a++;
    }
  }

  cout << a + n << endl;
  
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;

using ll = long long;
#define REP(i,n) for(int i=0; i < (n); ++i)
#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
// #define INF 1e9
constexpr ll INF = 1LL << 60;
constexpr ll mod = 1e9+7;

int main(){
  ll m, n;
  cin >> m >> n;
  ll ans = 1;
  ll beki = m;
  REP(i, 32){
    if(n>>i & 1){
      ans *= beki;
      ans %= mod;
    }
    beki *= beki;
    beki %= mod;
  }
  cout << ans << endl;
  return 0;
}




Measured memory_bytes: 3112
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String W = in.readLine();

		String ans = "";
		for(int i=0;i<W.length();i++){
			ans+="x";
		}
		System.out.println(ans);

	}


}


Measured memory_bytes: 22612
#include<iostream>
using namespace std;
int main(){
int h,w;
while(1){
cin >> h >> w;
if(h==0 && w==0)break;
for(int i=0; i<h; i++){
for(int j=0; j<w; j++){
cout << "#";
}
cout <<endl;
}
cout <<endl;
}
return 0;
}


Measured memory_bytes: 3136
def ABC_163_B():
    N,M = map(int, input().split())
    A = list(map(int, input().split()))
    sum = 0

    for i in range(len(A)):
        sum+=A[i]

    if sum <= N:
        print(N-sum)
    else:
        print('-1')

if __name__ == '__main__':

    ABC_163_B()

Measured memory_bytes: 9992
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
const long double PI=(acos(-1));
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,m,c;
  cin>>n>>m>>c;
  int b[m];
  rep(i,m){
    cin>>b[i];
  }
  int a[n][m];
  rep(i,n){
    rep(j,m){
      cin>>a[i][j];
    }
  }
  int ans=0;
  int sum[n];
  rep(i,n){
    int sum1=0;
    rep(j,m){
      sum1+=(a[i][j])*b[j];
    }
    sum[i]=sum1+c;
    if(sum[i]>0){
      ans++;
    }
  }
  cout<<ans<<endl;      
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

const int MOD = 998244353;

int main() {
    int n; cin >> n;
    string s; cin >> s;
    
    int m = s.size();
    vector<int> a(m, 0);

    for(int i = 0; i < m; i += 1) {
        if(s[i] == 'R')
            a[i] = 1;
        else if (s[i] == 'G')
            a[i] = 2;
        else
            a[i] = 4;
    }

    vector<int> freq(8, 0);
    int ans = 1;

    for(int i = 0; i < m; i += 1) {
        bool matched = false;

        for(int mask = 0; mask < 8; mask += 1) {
            if(freq[mask] > 0 and (a[i] | mask) == 7) {
                ans = 1LL * ans * freq[mask] % MOD;
                freq[mask] -= 1;
                matched = true;
            }
        }

        if (matched)
            continue;

        for(int mask = 0; mask < 8; mask += 1) {
            if(freq[mask] == 0)
                continue;
            if((a[i] | mask) > mask) {
                ans = 1LL * ans * freq[mask] % MOD;
                freq[mask] -= 1;
                freq[a[i] | mask] += 1;
                matched = true;
            }
        }

        if (matched)
            continue;
        
        freq[a[i]] += 1;
    }
    
    for(int i = 1; i <= n; i += 1)
        ans = 1LL * ans * i % MOD;

    cout << ans << "\n";
}

Measured memory_bytes: 1796
#include <bits/stdc++.h>
//#include "Header.h"

#define pi 3.14159265358979323846264

#define ll long long
#define fori(n) for(long long i=0;i<n;i++)
#define forj(n) for(long long j=0;j<n;j++)

#define sp(n) setprecision(n)
#define d7 1000000007
#define mkp make_pair
#define mkt make_tuple

using namespace std;

bool isPrime(long long k){
    if(k<=1){return false;}
    if(k==2){return true;}
    if(k%2==0){return false;}
    long long i = 3;
   while (i*i <= k) {if (k % i == 0) {return false;}i += 2;}
return true;
}

ll binomialCoeff(ll n, ll k){
    ll C[n + 1][k + 1];ll i, j;
    for (i = 0; i <= n; i++){
        for (j = 0; j <= min(i, k); j++){
            if (j == 0 || j == i){C[i][j] = 1;}
            else{C[i][j] = (C[i - 1][j - 1]%d7 + C[i - 1][j]%d7)%d7;}}}
    return C[n][k]%d7;
 }

ll gcd(ll a, ll b){if (b == 0)
        return a;return gcd(b, a % b);}

ll srihrg(ll n,ll k,ll m){
    ll ans;
    ans=1;
    fori(k){
        ans=(ans*n)%m;
    }
    return ans;
}

ll kk=1;
void dfsi(vector<bool> &vis, vector<ll> adj1[], ll n, ll start, vector<ll> &pre, vector<ll> &pos){
    vis[start]=true;
    pre[start]=kk;kk++;
    for(ll i: adj1[start]){
        if(!vis[i]){
            vis[i]=true;
            dfsi(vis,adj1,n,i,pre,pos);
        }
    }
    pos[start]=kk;kk++;
}

void bfsi(vector<ll> &dis, vector<ll> adj[], ll s, vector<ll> &parent){
    dis[s]=-1;
    queue<ll> q;
    q.push(s);
    while(!q.empty()){
        ll z=q.front();
        q.pop();
        for(ll v:adj[z]){
            if(dis[v]==0){
            q.push(v);
            dis[v]=-dis[z];
                parent[v]=z;}
        }
    }
}

void make_set(ll v, vector<ll> &parent, vector<ll> &krank) {
    parent[v] = v;
    krank[v] = 0;
}

ll find_set(ll v,vector<ll> &parent, vector<ll> &krank) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v], parent, krank);
}

void union_sets(ll a, ll b,vector<ll> &parent, vector<ll> &krank) {
    a = find_set(a,parent,krank);
    b = find_set(b,parent,krank);
    if (a != b) {
        if (krank[a] < krank[b])
            swap(a, b);
        parent[b] = a;
        if (krank[a] == krank[b])
            krank[a]++;
    }
}

void dijkstra(ll s, vector<ll> &dist, vector<ll> &parent, ll n, vector<pair<ll,ll>> adj[]){
    dist[s]=0;
    vector<bool> u(n,false);
    fori(n){
        ll v=-1;
        forj(n){
            if(!u[j] &&(v==-1||(dist[j]<dist[v]))) v=j;
        }
        if(dist[v]==d7) break;
        u[v]=true;
        for(auto j:adj[v]){
            ll a,b;
            a=j.first;
            b=j.second;
            if(dist[v]+b<dist[a]){
                dist[a]=dist[v]+b;
                parent[a]=v;
            }
        }
    }
}

int main(int argc, const char * argv[]) {
 //cout<<"Om\n";
 //Praise to Lord
 //make cin/cout faster
 ios_base::sync_with_stdio(false);
 cin.tie(NULL);
// code now
   
    ll n;
    cin>>n;
    ll ans=1;
    fori(3){
        ans=n*ans;
    }
    cout<<ans;
    
//code ends
    return 0;
}


Measured memory_bytes: 256
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict
from bisect import bisect

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
S = input()

former = defaultdict(int)
latter = defaultdict(int)

for bits in range(1 << N):
  bs1 = []; rs1 = []; bs2 = []; rs2 = []
  for i in range(N):
    if (1 << i) & bits:
      rs1.append(S[i])
      rs2.append(S[-1-i])
    else:
      bs1.append(S[i])
      bs2.append(S[-1-i])
  former["".join(rs1), "".join(bs1)] += 1
  latter["".join(bs2), "".join(rs2)] += 1

ans = 0
for k, v in former.items():
  if k in latter:
    ans += v * latter[k]

print(ans)

Measured memory_bytes: 176636
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

#define PB push_back
#define MP make_pair

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m; cin >> n >> m;
    vector<pair<int, int>> id;
    int maxl = 0, minr = 1e6;
    for (int i = 0; i < m; ++i) {
        int l, r; cin >> l >> r;
        maxl = max(maxl, l);
        minr = min(minr, r);
        id.PB(MP(l, r));
    }
    int ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (i >= maxl && i <= minr) ans++;
    }
    cout << ans << "\n";
}

/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* print new lines
*/

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL); 

#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
#define zeroes(x) memset(x,0,sizeof(x))
typedef long long int ll;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ll mod =1e9+7;
const ll maxn=100000;
ll ans=0,visited[100001]={0},f[100006],k;
vl g[100001];
ll power(ll x,ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
}
void  dfs(ll u)
{
    if(u!=0)
    {
        ans=(((ans*f[k-2])%mod)*power(f[k-2-g[u].size()+1],mod-2))%mod;
    }
    visited[u]=true;
    for(auto v:g[u])
    {
        if(!visited[v])
        {
            dfs(v);
        }
    }
}

int main()
{		
	
 
    IOS
    ll n;
    cin>>n>>k;
    if(n==1)
    {
        cout<<k;
        return 0;
    }
    if(n==2)
    {
        if(k<2)
            cout<<0;
        else
            cout<<(k*(k-1))%mod;
        return 0;
    }
    f[0]=1;
    for(ll i=1;i<=k+5;i++)
    {
        f[i]=(f[i-1]*i)%mod;
    }
    for(ll i=0;i<n-1;i++)
    {   ll u,v;
        cin>>u>>v;
        u--;
        v--;
        g[u].pb(v);
        g[v].pb(u);
    }

    for(ll i=0;i<n;i++)
    {
        if(k<3||g[i].size()>=k)
        {
            cout<<0;
            return 0;
        }

    }


    ans=k%mod;
    ans=(((ans*f[k-1])%mod)*(power(f[k-g[0].size()-1],mod-2)))%mod;
    //trace(ans);
    dfs(0);
    cout<<ans<<endl;



}


Measured memory_bytes: 8832
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    long long N;
    cin >> N;
    

    
    for(int h = 1; h < 3501;h++){
        
        for(int n = 1; n < 3501;n++){
        
                auto upper = N*h*n;
                auto lower = 4*h*n - N*n-N*h;
                if(lower!=0){
                    if(upper%lower ==0&&upper/lower>0){
                        cout << h <<" "<<n <<" "<<upper/lower<<endl; 
                        return 0;
                    }
                }
        
              
        
        
        }
        
        
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main() {
  int N, K, Q;

  cin >> N >> K >> Q;

  int a[Q], person[N];

  rep(i, N) {
    person[i] = K;
  }

  rep(i, Q) {
    cin >> a[i];
    a[i]--;
    person[a[i]]++;
  }

  rep(i, N) {
    if (person[i] - Q > 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;
class Main{
	
    public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int H=sc.nextInt();
int W=sc.nextInt();
 String a[][]=new String[H+2][W+2];
 String b[]=new String[H];
 for(int k=0;k<H;k++) {
	 b[k]=sc.next();
 }
 for(int i=0;i<=H+1;i++) {
	 for(int j=0;j<=W+1;j++) {
		 a[i][j]=".";
	    }
    }
 for(int i=1;i<=H;i++) {
	 for(int j=1;j<=W;j++) {
		 a[i][j]=b[i-1].substring(j-1,j);
	    }
    }	
boolean out[][]=new boolean[H+2][W+2];

//inside
 for(int i=1;i<=H;i++) {
	 for(int j=1;j<=W;j++) {
		 if(a[i][j].equals("#")) {
	      if(!(a[i-1][j].equals("#")||a[i+1][j].equals("#")||a[i][j-1].equals("#")||a[i][j+1].equals("#"))){
	    	  out[i][j]=true;
	      }
		 }
	 }
 }
 String answer="Yes";
 for(int i=1;i<=H;i++) {
	 for(int j=1;j<=W;j++) {
		 if(out[i][j]) {
			 answer="No";
			 break;
		 }
	    }
    }	
 System.out.println(answer);
 }
}

Measured memory_bytes: 23380
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, -1, 0, 1 };

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

signed main() {
    int N;
    cin >> N;

    vector<int> a;
    inputVector(a, N);

    int ret = 0;
    int flag = 0;
    REP(i, 1, N - 1) {
	if (flag == 0) {
	    if (a[i] == a[i - 1]) continue;
	    if (a[i] > a[i - 1]) flag = 1;
	    else flag = -1;
	} else if (flag == 1 && a[i] < a[i - 1] || flag == -1 && a[i] > a[i - 1]) {
	    flag = 0;
	    ret++;
	}
    }
    ret++;

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 1024
fun main() {
    var n = readLine()!!.toInt()
    var a = readLine()!!.split(" ").map{it.toInt()}

    a = a.sortedDescending()
    var c = a[0].toLong()

    for(i in 2 until n) {
        c += a[i / 2]
    }
    println(c)
}

Measured memory_bytes: 65516
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int func( string s ) {
    int ret = 0;
    for ( int i = 0; i < s.length(); i++ ) {
        ret += s[i]-'0';
    }
    return ret;
}

int main() {
    
    int N;
    cin >> N;
    int ans = INT_MAX;
    for ( int a = 1; a <= N-1; a++ ) {
        int b = N-a;

        string x = to_string(a);
        string y = to_string(b);

        int c = func(x) + func(y);
        ans = min( ans, c );

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
//#include<bits\stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define ldb long double
#define pb push_back
#define get(x) x=read()
#define gt(x) scanf("%d",&x)
#define put(x) printf("%d\n",x)
#define putl(x) printf("%lld\n",x)
#define gc(a) scanf("%s",a+1)
#define rep(p,n,i) for(RE int i=p;i<=n;++i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define fep(n,p,i) for(RE int i=n;i>=p;--i)
#define pii pair<int,int> 
#define mk make_pair
#define RE register
#define P 1000000007
#define S second
#define F first
#define mod 998244353
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define ull unsigned long long
#define ui unsigned
using namespace std;
char buf[1<<15],*fs,*ft;
inline char getc()
{
    return (fs==ft&&(ft=(fs=buf)+fread(buf,1,1<<15,stdin),fs==ft))?0:*fs++;
}
inline int read()
{
    register int x=0,f=1;register char ch=getc();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getc();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getc();}
    return x*f;
}
const int MAXN=200010;
int n,len;
ll ans[MAXN];
int a[MAXN],sz[MAXN],s[MAXN];
int lin[MAXN],ver[MAXN<<1],nex[MAXN<<1];
inline void add(int x,int y)
{
	ver[++len]=y;
	nex[len]=lin[x];
	lin[x]=len;
}
inline ll SUM(int x){return (ll)x*(x-1)/2;}
inline void dfs(int x,int father)
{
	sz[x]=1;int ss=s[a[x]],pre=s[a[x]];
	go(x)
	{
		if(tn==father)continue;
		dfs(tn,x);
		sz[x]+=sz[tn];
		ans[a[x]]-=SUM(sz[tn]-(s[a[x]]-pre));
		pre=s[a[x]];
	}
	s[a[x]]=ss+sz[x];
}
int main()
{
	//freopen("1.in","r",stdin);
	get(n);
	rep(1,n,i)get(a[i]),++ans[a[i]],ans[i]+=SUM(n);
	rep(2,n,i)
	{
		int get(x);int get(y);
		add(x,y);add(y,x);
	}
	dfs(1,0);
	rep(1,n,i)ans[i]-=SUM(n-s[i]);
	rep(1,n,i)putl(ans[i]);
	return 0;
}


Measured memory_bytes: 27116
#include <iostream>
using namespace std;
#define rep(i,q) for(int i = 0; q > i; i++)
int main(){
  int N;
  cin >> N;
  int saityo = 0;
  int nagasa = 0;
  rep(i,N){
    int tmp;
    cin >> tmp;
    if(tmp == 1) nagasa++;
    else {
      if(saityo < nagasa) saityo = nagasa;
      nagasa = 0;
    }
  }
  if(saityo < nagasa) saityo = nagasa;
  cout << saityo + 1 << endl;
}


Measured memory_bytes: 3096
use std;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn read_verical_vec<T: std::str::FromStr>(n: u32) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read::<T>());
    }
    return vec;
}

fn c_h_and_v() {
    let hwk = read_vec::<u32>();
    let h = hwk[0];
    let w = hwk[1];
    let k = hwk[2];
    let c = read_verical_vec::<String>(h);

    let count = (0..(1 << h))
        .flat_map(move |a| (0..(1 << w)).map(move |b| (a,b)))
        .map(|(a,b)| {
            c.iter().enumerate().fold(0, |acc, (i, row)| {
                let mut c = 0;
                row.chars().enumerate().for_each(|(j,col)| {
                    if (a >> i & 1) == 0 && (b >> j & 1) == 0 && col == '#' {
                        c+=1;
                    }
                });
                acc + c
            })
        })
        .filter(|c| c == &k)
        .count();
    println!("{}", count);
}

fn main() {
    c_h_and_v();
}


Measured memory_bytes: 2132
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
lint numz[10];
lint mo=1000000007;
lint zyo(lint x,lint y){
    lint ret=1,a=x;
    while(y>0){
    	if(y%2==1) ret=(ret*a)%mo;
    	a=(a*a)%mo;y/=2;
    }
    return ret;
}
lint s;
//dig桁のをnum個とるとり方
lint cal(int dig,int num){
	if(dig<10 && 9*zyo(10,dig-1)<(lint)num) return 0;
	lint ret=(9*zyo(10,dig-1)-num+1)%mo;
	if(s/num>=8) ret--;
	return ret;
}
int main()
{
	cin>>s;lint out=0;
	numz[0]=1;rep(i,9) numz[i+1]=numz[i]*10;
	//1つの桁だけ
	for(int i=1;i*i<=s;i++){
		if(s%i>0){
			//if(s/i>=8) out++;
		}
		else{
			out+=cal(i,s/i);
			if(i*i<s) out+=cal(s/i,i);
		}
		out%=mo;
	}
	out+=s/8;
	REP(i,1,8) REP(j,i+1,9){
		lint numd=0;
		REP(k,i+1,j) numd+=k*9*numz[k-1];
		if(numd>=s) continue;
		REP(k,1,9*(int)numz[i-1]+1){
			lint rest=s-numd-i*k;
			if(rest%j>0LL || rest<1LL || rest/j>9*numz[j-1]) continue;
			out++;out%=mo;
		}
	}
	/*REP(i,1,8){
		if(s%i==0LL && s/i<=9*numz[i-1]) out+=9*numz[i-1]-s/i+1;
		out%=mo;
	}*/
	cout<<(out%mo+mo)%mo<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int INF = 99;
typedef pair<int, int> P;
int dx[] = {0,1,0,-1};
int dy[] = {1,0,-1,0};

#define N_MAX 100
#define M_MAX 100

int N, M;
string maze[N_MAX];
int sx, sy, gx, gy;

int d[N_MAX][M_MAX];

bool isOK(int x, int y, int N, int M){
    return ( 0<=x and x<N  and  0<=y and y<M );
}

int bfs(){
    
    queue<P> que;
    for(int i=0; i<N; i++)
        for(int j=0; j<M; j++)
            d[i][j]=INF;
            
    que.push(P(sx,sy));
    d[sx][sy]=0;
    
    while(que.size()){
        P p = que.front(); que.pop();
        // if(p.first==gx and p.second==gy) break; // goalについたときに探索をやめる。
        
        for(int i=0; i<4; i++){
            int nx=p.first+dx[i], ny=p.second+dy[i];
            if(isOK(nx,ny,N,M) and maze[nx][ny]!='#' and d[nx][ny]==INF){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }
    
    // 最大距離の更新
    int ret = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            if( d[i][j] != INF && ret <= d[i][j] ){
                ret = d[i][j];
            }
        }
    }
    
    return ret;
}

int main(){
    
    cin>>N>>M;
    for(string &s:maze) cin >> s;
    
    int ans = 0;
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            sx=i, sy=j;
            if(maze[i][j] == '#') continue;
            int tmp = bfs();
            if( ans < tmp ){
                ans = tmp;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int64_t INF=999999999;

int main() {
   int a,b,c,d,e,k;
   cin>>a>>b>>c>>d>>e>>k;
   if(max({a,b,c,d,e})-min({a,b,c,d,e})>k){cout<<":("<<endl;}
   else{cout<<"Yay!"<<endl;}
   
return 0;}

Measured memory_bytes: 256
import functools

@functools.lru_cache(maxsize=None)
def factorial(N):
    if N == 0:
        return 1
    if N == 1:
        return 1
    else:
        return N * factorial(N - 1)


def c(n, r):
    if n < r:
        return 0
    return factorial(n) // (factorial(r) * factorial(n-r))


N, M = [int(x) for x in input().split()]

print(
    c(N, 2) + c(M, 2)
)


Measured memory_bytes: 3684
# 累積和, 尺取り法
from itertools import accumulate
_ = int(input())
*a, = accumulate(map(int,input().split()))
l,r,e,ans = 0, 2, a[-1], a[-1]
for m in a[1:-2]:
    # 右部分列を極力等しくしたい
    while a[r] - m < e - a[r+1]:
        r += 1
    # 左部分列を極力等しくしたい
    while a[l] < m - a[l+1]:
        l += 1
    tmp = sorted([ a[l], m-a[l], a[r]-m, e-a[r] ])
    ans = min(ans, tmp[-1]-tmp[0] )
print(ans)

Measured memory_bytes: 25972
n = int(input())
t, a = map(int, input().split())
h = list(map(int, input().split()))

ans = 0
diff = 100000
for i in range(n):
    if abs(t - h[i] * 0.006 - a) < diff:
        ans = i + 1
        diff = abs(t - h[i] * 0.006 - a)

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;

vector<int> edges[100001];
int n,m;
bool *visited = new bool[100001]();

void dfs(int ind){
	
	visited[ind] = true;
	for(int i=0;i<edges[ind].size();i++){
		if(!visited[edges[ind][i]]){
			dfs(edges[ind][i]);
		}
			
	}
	
}

int main() {
	// your code goes here

	cin>>n>>m;
	
	for(int i=0;i<m;i++){
		int f,s;
		cin>>f>>s;
		edges[f].push_back(s);
		edges[s].push_back(f);
	}
	int cnt = 0;
	for(int i=1;i<=n;i++){
		if(!visited[i]){
			cnt++;
			dfs(i);
		}	
	}
	cout<<cnt-1;
	return 0;
}

Measured memory_bytes: 9688
import sys
import heapq
K, T = map(int, input().split())
m = [-int(i) for i in input().split()]
heapq.heapify(m)

if T == 1:
    print(K-1)
    sys.exit()

while len(m) > 1:
    l = heapq.heappop(m)
    r = heapq.heappop(m)
    if r+1 != 0:
        heapq.heappush(m, l+1)
        heapq.heappush(m, r+1)
    else:
        if l+1 != 0:
            heapq.heappush(m, l+1)
if len(m) == 0:
    print(0)
else:
    print(-m[0]-1)

Measured memory_bytes: 3064
(N, M) = (int(i) for i in input().split(' '))
(l0,r0) = (1, N)

n = -1
for i in range(0,M):
    # gate i can be opened by following card set
    (l, r) = (int(j) for j in input().split(' '))
    #print(cards, set(range(l,r+1)))
    if l > r0 or r < l0:
        n = 0
        break
    (l0,r0) = (max(l,l0), min(r,r0))

if n == -1:
    n = r0-l0 +1
    
print(n)
    

Measured memory_bytes: 3060
#include <vector>
#include <iostream>
using namespace std;

int main(){
  int H, W;
  cin >> H >> W;
  vector<string> S(H+2,string(W+2,'?'));
  S[0][0] = '.';
  S[0][1] = '.';
  S[1][0] = '.';
  S[H+1][W+1] = '.';
  S[H+0][W+1] = '.';
  S[H+1][W+0] = '.';
  for(int i = 0; i < H; ++i){
    string s;
    cin >> s;
    for(int j = 0; j < W; ++j)
      S[i+1][j+1] = s[j];
  }
  H += 2;
  W += 2;
  const int INF = 1e9;
  vector<vector<vector<int>>> dp(H,vector<vector<int>>(W,vector<int>(H+10,INF)));
  dp[0][0][0] = 0;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      for(int k = 0; k < H+10; ++k){
        if(dp[i][j][k] == INF) continue;
        if(j+1 < W){
          int d = ((S[i][j+1] != S[i][j]) or (S[i][j+1] == '?'));
          dp[i][j+1][k] = min(dp[i][j+1][k],dp[i][j][k]+d);
        }
        if(i+1 < H){
          int d = ((S[i+1][j] != S[i][j]) or (S[i+1][j] == '?'));
          dp[i+1][j][k+d] = min(dp[i+1][j][k+d],dp[i][j][k]);
        }
      }
    }
  }
  int ans = INF;
  for(int i = 0; i < H+10; ++i){
    int tmp = max(i,dp[H-1][W-1][i]);
    // cerr << i << " " << tmp << endl;
    ans = min(ans,tmp);
  }
  cout << ans << endl;
}


Measured memory_bytes: 5376
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
int main()
{
    string s;
    cin >> s;
    long long sum = 0;
    rep(i,s.size()){
        int tmp = s[i] - '0';
        sum += tmp;
    }
    if(sum%9 == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3716
#include <bits/stdc++.h>
using namespace std;
static const int INFTY = 2000000000;
static const int NIL = -1;
typedef long long ll;

int main(){
    int n,k,tmp,ans = 0;
    scanf("%d %d",&n,&k);
    for(int i=0;i<n;i++){
        scanf("%d",&tmp);
        ans += min(tmp,k-tmp);
    }
    printf("%d\n",ans*2);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long m=998244353;
vector<int> g[2010];
int dis[2010][2010];
int d[2010];

long long power(long long x,long long y)
{
    long long res = 1; x=x%m;
    while (y > 0)
    {
        if (y & 1) res = (res*x)%m;
        y = y>>1;
        x = (x*x)%m;
    }
    return res%m;
}

void bfs(int u,int n)
{
    bool v[n]={0};
    queue<int> q;
    q.push(u); d[u]=0;
    v[u] = true;
    while (!q.empty()) {
        int f = q.front();
        q.pop();
        for (auto i = g[f].begin(); i != g[f].end(); i++) {
            if (!v[*i]) {
                q.push(*i);
                v[*i] = true;
                d[*i]=d[f]+1;
            }
        }
    }
}


int main()
{
    int n,x,y;
    cin>>n>>x>>y;
    int freq[n+1]={0};
    for(int i=0; i<=2005; i++)
        for(int j=0; j<=2005; j++)
            dis[i][j]=INT_MAX;
    for(int i=0; i<n-1; i++)
    {
        g[i].push_back(i+1);
        g[i+1].push_back(i);
    }
    g[x-1].push_back(y-1);
    g[y-1].push_back(x-1);
    for(int i=0; i<n; i++)
    {
        memset(d,0,sizeof(d));
        bfs(i,n);
        for(int j=0; j<n; j++)
        {
            dis[i][j]=min(dis[i][j],d[j]);
            dis[j][i]=min(dis[j][i],d[j]);
        }
    }
    for(int i=0; i<n; i++)
        for(int j=i+1; j<n; j++)
            freq[dis[i][j]]++;
    for(int i=1; i<=n-1; i++)
        cout<<freq[i]<<endl;
    return 0;
}


Measured memory_bytes: 16128
<?php

$array_data=array();
$end_word="END_OF_TEXT";

while(1){

	$x=trim(fgets(STDIN));

	// end_word?????¨?????????
	if($x==$end_word){

		break;
	}

	$array_data[]=$x;
}


// print_r($array_data);

$W=$array_data[0];

$cnt=0;
for($i=1;$i<count($array_data);$i++){

	WordCheck($array_data[$i],$W,$cnt);

}

printf("%d\n",$cnt);

function WordCheck($T,$W,&$cnt){

	// ??????????????§????§£?????????????????????
	foreach(explode(" ",$T) as $val){

		if(strtolower($val)==$W){

			$cnt+=1;

		}

	}

}

Measured memory_bytes: 15484
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int H, W, K;
  cin >> H >> W >> K;
  vector<vector<char>> s(H, vector<char>(W));
  rep(i, H){
    rep(j, W){
      cin >> s.at(i).at(j);
    }
  }
  int str = 0;
  bool fst = true;
  bool flg = false;
  rep(i, H){
    rep(j, W){
      if(s.at(i).at(j) == '#'){
        str = i;
        flg = true;
        break;
      }
    }
    if(flg){
      break;
    }
  }
  vector<vector<int>> ans(H, vector<int>(W, 0));
  int cut = 1;
  rep(i, str+1){
    cut = 1;
    rep(j, W){
      if(s.at(str).at(j) == '#'){
        if(!fst){
          cut++;
        }
        else{
          fst = false;
        }
      }
      ans.at(i).at(j) = cut;
    }
    fst = true;
  }
  fst = true;
  bool emp = false;
  rep2(i, str+1, H){
    rep(j, W){
      if(s.at(i).at(j) == '#'){
        break;
      }
      if(j == W-1){
        emp = true;
      }
    }
    if(emp){
      rep(j, W){
        ans.at(i).at(j) = ans.at(i-1).at(j);
      }
      emp = false;
    }
    else{
      cut++;
      rep(j, W){
        ans.at(i).at(j) = cut;
        if(s.at(i).at(j) == '#'){
          if(!fst){
            cut++;
            ans.at(i).at(j) = cut;
          }
          else{
            fst = false;
          }
        }
      }
      fst = true;
    }
  }
  rep(i, H){
    rep(j, W){
      if(j != W-1){
        cout << ans.at(i).at(j) << " ";
      }
      else{
        cout << ans.at(i).at(j) << endl;
      }
    }
  }
}


Measured memory_bytes: 1280
n = int(input())
P = list(input().split())
a = 0
for i in range(1,n-1):
  p1 = int(P[i-1])
  p2 = int(P[i])
  p3 = int(P[i+1])
  if (p1 < p2 < p3) or (p1 > p2 > p3):
    a = a + 1
print(a)

Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	      Scanner sc = new Scanner(System.in);
	      int A = sc.nextInt();
	      int B = sc.nextInt();
	      int C = sc.nextInt();
	      int X = sc.nextInt();
	      int Y = sc.nextInt();
	      sc.close();
	      
	      int price = 0;
	      
	      if(A + B > 2 * C) {
	    	  	price += Math.min(X, Y) * 2 * C;
	    	  	if(X > Y) {
	    	  		price += (Math.max(X, Y) - Math.min(X, Y)) * Math.min(A, 2 * C);
	    	  	}else {
	    	  		price += (Math.max(X, Y) - Math.min(X, Y)) * Math.min(B, 2 * C);
	    	  	}
	      }else {
	    	  	price += A * X + B * Y;
	      }
	      
	      System.out.println(price);
	      System.exit(0);
	    }
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

int main() {
  string s;
  cin >> s;
  string ss = s;
  string w, x, y;

  string zen;
  zen = s.substr(0, (s.length() - 1) / 2);
  string zenn = zen;
  string kou = s.substr((s.length() + 1) / 2, s.length() - 1);
  string kouu = kou;

  reverse(all(ss));
  reverse(all(zen));
  reverse(all(kou));

  if (s == ss) {
    if (zen == zenn) {
      if (kou == kouu) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;

class Main{
public static void main(String args[]){
   Scanner sc = new Scanner(System.in);
   double L = sc.nextInt();
   double ret = Math.pow((L/3),3);
   System.out.println(BigDecimal.valueOf(ret).toPlainString());
}
  static boolean isPalindrome (String s) {
	int n = s.length();
	for (int i=0; i<n/2; i++) {
		if (s.charAt(i)!=s.charAt(n-i-1)) {return false;}
	}
	return true;
}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    ll x;
    vector<ll> a(3, -1);
    ll ans = 1;
    for(int i=0;i<n;i++){
    	cin >> x;
    	ll ret = 0;
    	for(int j=0;j<3;j++) if(a[j] == x - 1) ret++;
    	ans *= ret;
        for(int j = 0;j<3;j++) {
        	if(a[j] == x - 1) {
        		a[j]++;
        		j = 1919;
        	}
        }
        ans %= mod;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>

const int N = 100000 + 10;
const int M = N << 2;

int a[N], b[N], id[N];
int n, m;

#define L(u) ((u) << 1)
#define R(u) (((u) << 1) | 1)

int empty[M], right[M];

void build(int u, int l, int r) {
  if (l == r) {
    empty[u] = 1;
    right[u] = l;
  } else {
    int m = (l + r) / 2;
    build(L(u), l, m);
    build(R(u), m + 1, r);
    empty[u] = r - l + 1;
    right[u] = r;
  }
}

void update(int u) {
  empty[u] = empty[L(u)] + empty[R(u)];
  if (right[R(u)] != -1) {
    right[u] = right[R(u)];
  } else {
    right[u] = right[L(u)];
  }
}

void insert(int u, int l, int r, int x) {
  if (l == r) {
    empty[u] = 0;
    right[u] = -1;
  } else {
    int m = (l + r) / 2;
    if (x <= m) {
      insert(L(u), l, m, x);
    } else {
      insert(R(u), m + 1, r, x);
    }
    update(u);
  }
}

int query(int u, int l, int r, int a, int b) {
  if (b < l || a > r) {
    return -1;
  }
  if (a <= l && b >= r) {
    return right[u];
  }
  int m = (l + r) / 2;
  int x = query(R(u), m + 1, r, a, b);
  if (x == -1) {
    x = query(L(u), l, m, a, b);
  }
  return x;
}

bool cmp(int x, int y) {
  if (b[x] == b[y]) {
    return a[x] > a[y];
  }
  return b[x] > b[y];
}

int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; ++ i) {
    scanf("%d%d", a + i, b + i);
    a[i] = m - a[i] + 1;
    id[i] = i;
  }
  std::sort(id + 1, id + n + 1, cmp);

  build(1, 1, n);
  int answer = 0;
  for (int i = 1; i <= n; ++ i) {
    int u = id[i];
    int pos = query(1, 1, n, 1, a[u]);
    if (pos != -1) {
      answer += b[u];
      insert(1, 1, n, pos);
    }
  }
  printf("%d\n", answer);
  return 0;
}


Measured memory_bytes: 3968
def mlcs(xs, ys):
    table = {("", ""): ""}

    def lcs(xs, ys):
        if (xs, ys) in table:
            return table[(xs, ys)]

        ret = ""
        if xs == "" or ys == "":
            ret = ""
        elif xs[-1] == ys[-1]:
            ret = lcs(xs[:-1], ys[:-1]) + xs[-1]
        else:
            l = lcs(xs[:-1], ys)
            r = lcs(xs, ys[:-1])
            if len(l) > len(r):
                ret = l
            else:
                ret = r

        table[(xs, ys)] = ret
        return ret

    return lcs(xs, ys)


if __name__ == '__main__':
    n = int(input())
    S = ["".join(sorted(list(input()))) for i in range(n)]

    ans = S[0]
    for i in range(1, n):
        ans = mlcs(ans, S[i])
    print(ans)


Measured memory_bytes: 5876
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MOD 1000000000 + 7
#define PI 3.14159265359

const long long INF = 100000;
typedef pair<int,int> P;
typedef long long ll;

using Graph = vector<vector<int>>;
ll A, B;
ll func(ll x) {
	return A*x / B - A * (x/B);
}
int main() {
	int N, M, X;
	cin >> N >> M >> X;
	vector<int> C(N);
	vector<vector<int>> A(N, vector<int>(M));

	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= M; j++) {
			if (j == 0) cin >> C[i];
			else cin >> A[i][j-1];
		}
	}
	/*for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if (j == M - 1) cout << A[i][j] << endl;
			else cout << A[i][j] << " ";
		}
	}*/
	bool flag = true;

	for (int i = 0; i < M; i++) {
		ll sumM = 0;//各アルゴリズムの最大の理解度
		for (int j = 0; j < N; j++) {
			sumM += A[j][i];
		}
		if (sumM < X) {
			flag = false;
			break;
		}
	}
	if (flag == false) cout << -1 << endl;

	else {
		//vector<vector<pair<int, int>>> v(M, vector<pair<int, int>>(N));
		
		
		ll ans = 10000000;
		for (int tmp = 0; tmp < (1 << N); tmp++) {
			
			bool flag2 = true; //各ビットパターンがokかどうか
			vector<ll> num(M);//num[i]はi個目のアルゴリズムの理解度の総和
			bitset<12> s(tmp);
			ll res = 0;
			for (int i = 0; i < N; i++) {
				
				if (s.test(i)) {//i番目の参考書を買う
					res += C[i];
					for (int j = 0; j < M; j++) num[j] += A[i][j];
				}
			}

			for (int i = 0; i < M; i++) {
				if (num[i] < X) {
					flag2 = false;
					break;
				}
			}
			if (flag2 == true) ans = min(ans, res);
		}
		cout << ans << endl;
	}
	
	
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#define fore(i,x,y) for(long long i=x;i<y;i++)
typedef long long ll;
using namespace std;
int main()
{
	string str,ANS="No";
	cin >> str;
	if(str[0]==str[1]&&str[1]==str[2])ANS="Yes";
	if(str[1]==str[2]&&str[1]==str[3])ANS="Yes";
	cout << ANS << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(X,A,B) for(int X=A;X<=B;X++)
#define tep(X,A,B) for(int X=A;X>=B;X--)
#define LL long long 
const int N=210;
const int M=100010;
const int INF=100000;
using namespace std;

int n;
char s[N];
int dis[N][N],vis[N],dep[N];
int edge[M],lst[N],nxt[M],t=0;

void ADD(int x,int y){
	edge[++t]=y;nxt[t]=lst[x];lst[x]=t;
}

void READ(){
	scanf("%d",&n);
	rep(i,1,n){
		rep(j,1,n)dis[i][j]=INF;
		dis[i][i]=0;
	}
	rep(i,1,n){
		scanf("%s",s+1);
		rep(j,1,n)if(s[j]=='1'){
			ADD(i,j);
			ADD(j,i);
			dis[i][j]=dis[j][i]=1;
		}
	}
}

int SEARCH(int x,int pa){
	dep[x]=dep[pa]+1;
	vis[x]=1;
	for(int r=lst[x];r;r=nxt[r]){
		int pos=edge[r];
		if(pos==pa)continue;
		if(vis[pos]==1){
			if((dep[x]-dep[pos])%2==0)return 0;
			continue;
		}
		if(vis[pos]==0){
			if(!SEARCH(pos,x))return 0;
		}
	}
	vis[x]=-1;
	return 1;
}

int SOLVE(){
	if(SEARCH(1,0)==0)return -1;
	rep(k,1,n)rep(i,1,n)rep(j,1,n){
		dis[j][i]=dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
	}
	int ans=0;
	rep(i,1,n)rep(j,1,n)ans=max(ans,dis[i][j]);
	return ans+1;
}

int main(){
	READ();
	printf("%d\n",SOLVE());
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  ll N,A,B; cin>>N>>A>>B;
  ll x=N/(A+B);
  N-=x*(A+B);;
  cout<<A*x+min(A,N)<<endl;
  return 0;
}

Measured memory_bytes: 256
def win_lose(A,B,C,D):
   while True:
     C-=B
     if C<=0:
        return 'Yes'
     A-=D
     if A<=0:
        return 'No'

A,B,C,D=map(int,input().split())      
print(win_lose(A,B,C,D))

Measured memory_bytes: 9180
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(ll i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln = '\n';

const int mx=200010;
const ll mod=1e9+7;

#define bit(n,k) ((n>>k)&1) //*n no k bit me 1 or 0*/

int main(){
  int h,w,k;
  cin >> h >> w >> k;
  vector<string> a(h);
  rep(i,h){
    cin >> a[i];
  }

  int ans = 0;
  rep(i,(1<<h))rep(j,(1<<w)){
    int tmp = 0;
    rep(x,h)rep(y,w){
      if(bit(i,x) && bit(j,y) && a[x][y]=='#') tmp++;
    }
    if(k==tmp) ans++;
  }

  cout << ans << ln;

  return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
using namespace std;

int main(){
    char name[1001]="";
    while(1){
        int i=0 ;
        int ans=0;
        scanf("%s",name);
        while(name[i]){
            ans+=name[i]-'0';
            i++;
        }
        if (name[0]=='0') break;
        else printf("%d\n",ans);
    }
    return 0;
} 


Measured memory_bytes: 2728
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(ll i=0,_n=(n);(i)<(ll)_n;++i)
#define REPR(i,n) for(ll i=(ll)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(ll i=(ll)a,_b=(ll)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(ll i=(ll)(b)-1,_a=(ll)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
#define FI first
#define SE second
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}
string YN(bool v) { return v ? "yes":"no"; }
void uniq(VI& es) { sort(ALL(es)); es.erase(unique(ALL(es)), es.end()); }

#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll N,M,W,H,K;
	string s;
	while(cin>>s) {
		set<char> ss;
		REP(i, s.size()) ss.insert(s[i]);
		ll ans=s.size()==ss.size();
		cout<<YN(ans)<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  vector<int> n(3);
  for (int i = 0; i < 3; i++)
    cin >> n.at(i);
  
  int K;
  cin >> K;
  
  int x = 1;
  for (int i = 0; i < K; i++)
    x *= 2;
  
  sort(n.begin(),n.end());
  
  n.at(2) *= x;
  
  cout << n.at(0) + n.at(1) + n.at(2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

long long N, X;
long long res;

int main() {
  cin >> N >> X;
  long long A = N - X, B = X;
  res = N;
  while(true) {
    if(A == B) { res += A; break; }
    else {
      long long Q = (A - 1) / B;
      res += 2 * Q * B; A -= Q * B; swap(A, B);
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll L, R; cin >> L >> R;

    ll ans = 1<<30;
    for (ll i = L; i <= R; i++) {
        for (ll j = i+1; j <= R; j++) {
            ll tmp = i*j%2019;
            ans = min(ans, tmp);
            if (tmp == 0) {
                cout << 0 << endl;
                return 0;
            }
        }
    }   

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<62)           //1LL<<63でオーバーフロー

int main(int argc,char* argv[]){
    int l,r,d;
    cin >> l >> r >> d;

    int ans=(r/d)-(l/d);

    if(l%d==0)ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
import java.io.*;
 
public class Main {
    
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        
        int[] counter=new int[26];
        String text;
        
        while((text=br.readLine())!=null){
            for(int i=0;i<text.length();i++){
                char character=Character.toLowerCase(text.charAt(i));
                char alpha='a';
                for(int j=0;j<counter.length;j++){
                    if(character==alpha){
                        counter[j]++;
                    }
                    alpha++;
                }
            }
        }
        
        char alpha='a';
        for(int i=0;i<counter.length;i++){
            System.out.println(alpha+" : "+counter[i]);
            alpha++;
        }
        
    }
}

Measured memory_bytes: 24140
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;

int main(){
	ll n; cin >>n;
	ll sum=0;
	ll cnt=-1;
	for(int i=1;;i++){
		sum+=i;
		if(n<=sum){
			cnt=i;
			break;
		}
	}
	for(int i=1;i<=cnt;i++){
		if(sum-i!=n)cout << i <<endl;
	}
}


Measured memory_bytes: 256