akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(long long i=(long long)(a);i<(long long)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
vvll cost;
//Dijkstra法(cost[i][j]は節点iから節点jへのコスト，startは始点番号，nは節点数)
vector<int> Dijkstra(int start, int n)
{
	vector<int> dist(n, 1e9); //dist[i]はstartからiへの最短コスト
	vector<bool> used(n, true); //used[i]はstartから節点iへのコストが未確定か否かを示す
	vector<int> prev(n, 1e9);  //prev[i]は節点iへ繋ぐ節点番号を格納

							 //始点のコストは0
	dist[start]=0;
	for(int i=0; i<n; i++){
		//節点コストが確定していない点の中で，startからのコストが最小の節点min_jを求める
		int min=1e9+1, min_j;
		for(int j=0; j<n; j++){
			if(min>dist[j]&&used[j]){
				min=dist[j]; min_j=j;
			}
		}
		//節点min_jのコストを決定する
		used[min_j]=false;
		for(int j=0; j<n; j++){
			if(dist[j]>dist[min_j]+cost[min_j][j]&&used[j]){
				dist[j]=dist[min_j]+cost[min_j][j];
				prev[j]=min_j;
			}
		}
	}
	return prev;
}
int main(void)
{
	ll n, m;

	cin>>n>>m;

	cost=vvll(n, vll(n, 1e18));

	vvb flag(n, vb(n, true));

	vi prev;

	rep(i, m){
		ll a, b, c;
		cin>>a>>b>>c;
		cost[a-1][b-1]=c;
		cost[b-1][a-1]=c;
		flag[a-1][b-1]=false;
		flag[b-1][a-1]=false;
	}

	rep(i, n){
		prev=Dijkstra(i, n);

		rep(i, n){
			if(prev[i]!=1e9){
				flag[i][prev[i]]=true;
				flag[prev[i]][i]=true;
			}
		}
	}

	ll ans=0;
	rep(i, n){
		repr(j, i+1, n){
			if(!flag[i][j]) ans++;
		}
	}
	cout<<ans<<endl;
}


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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<bool> broken(n+1, false);
    for (int i = 0; i < m; ++i) {
        int a;
        cin >> a;
        broken[a] = true;
    }
    vector<long long> count(n+1, 0LL);
    count[0] = 1LL;
    count[1] = broken[1] ? 0LL : 1LL;
    for (int i = 2; i <= n; ++i) {
        if (broken[i]) {
            count[i] = 0;
        } else {
            count[i] = (count[i-1] + count[i-2]) % 1000000007;
        }
    }
    cout << count[n] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<stdio.h>
int main(void){
	int w;
	while(1){
		int fee=1150;
		scanf("%d",&w);
		if(w==-1)break;
		if(w>10){
			w-=10;
			if(w>10)fee+=125*10;
			else fee+=125*w;
			if(w>10){
				w-=10;
				if(w>10)fee+=140*10;
				else fee+=140*w;
				if(w>10){
					w-=10;
					fee+=160*w;
				}
			}

		}
		printf("%d\n",4280-fee);
	}
	return 0;
}

Measured memory_bytes: 1028
import sys
def input():
    return sys.stdin.readline()[:-1]

N, K = map(int, input().split())
KK = 2*K
m = [[0] * (2*KK+1) for i in range(2*KK+1)]
for i in range(N):
    x, y, c = input().split()
    x, y = int(x), int(y)
    if c == 'B':
        y += K
    x %= KK
    y %= KK
    m[y+1][x+1] += 1
    m[y+KK+1][x+KK+1] += 1
    m[y+1][x+KK+1] += 1
    m[y+KK+1][x+1] += 1
for i in range(1, 2*KK+1):
    for j in range(2*KK):
        m[i][j+1] += m[i][j]
for j in range(1, 2*KK+1):
    for i in range(2*KK):
        m[i+1][j] += m[i][j]
ans = 0
for i in range(KK):
    for j in range(KK):
        ans = max(ans, 2*m[i+K][j+K]-m[i+K][j]-m[i][j+K]+m[i][j]+m[i+KK][j+KK]-m[i+KK][j+K]-m[i+K][j+KK])
print(ans)


Measured memory_bytes: 166492
#include <iostream>
#include <iomanip> // << fixed << setprecision(xxx)
#include <algorithm> // do { } while ( next_permutation(A, A+xxx) ) ;
#include <vector>
#include <string> // to_string(nnn) // substr(m, n) // stoi(nnn)
#include <complex>
#include <tuple> // get<n>(xxx)
#include <queue>
#include <stack>
#include <map> // if (M.find(key) != M.end()) { }
#include <set> // S.insert(M);
// if (S.find(key) != S.end()) { }
// for (auto it=S.begin(); it != S.end(); it++) { }
// auto it = S.lower_bound(M);
#include <random> // random_device rd; mt19937 mt(rd());
#include <cctype>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib> // atoi(xxx)
using namespace std;

#define DEBUG 0 // change 0 -> 1 if we need debug.
// insert #if<tab> by my emacs. #if DEBUG == 1 ... #end

typedef long long ll;

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

// const int C = 1e6+10;
// const ll M = 1000000007;

ll hen(ll n) {
  return n * (n-1) / 2;
}

int main () {
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<int> V[100010];
  for (auto i = 0; i < M; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    V[a].push_back(b);
    V[b].push_back(a);    
  }
  bool visited[100010];
  fill(visited, visited+100010, false);
  stack<int> S;
  S.push(0);
  int zero = 0;
  while (!S.empty()) {
    int src = S.top();
    S.pop();
    if (!visited[src]) {
      visited[src] = true;
      zero++;
      for (auto x : V[src]) {
        if (!visited[x]) {
          S.push(x);
        }
      }
    }
  }
  S.push(1);
  int one = 0;
  while (!S.empty()) {
    int src = S.top();
    S.pop();
    if (!visited[src]) {
      visited[src] = true;
      one++;
      for (auto x : V[src]) {
        if (!visited[x]) {
          S.push(x);
        }
      }
    }
  }
  if (one < zero) swap(one, zero);
  one = N - zero;
  cout << hen(one) + hen(zero) - M << endl;
}


Measured memory_bytes: 5888
#include<bits/stdc++.h>
// #define int long long
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repa(i, s, n) for(int i = s; i < (int)n; i++)
#define MOD 1000000007
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> P;

signed main(){
    int n;
    cin >> n;
    vector<P> robots(n);
    rep(i, n){
        int x, l;
        cin >> x >> l;
        robots[i] = make_pair(x+l, x-l);
    }
    sort(robots.begin(), robots.end());

    int ans = 0, now_x = -100000000;

    rep(i, n){
        /* printf("%d, %d\n", robots[i].first, now_x); */
        if(now_x <= robots[i].second){
            ans++;
            now_x = robots[i].first;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3996
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
if((b-a > k) or (c-b > k) or (d-c > k) or (e-d > k) or (c-a > k) or (d-a > k) or (e-a > k) or (d-b > k) or (e-b > k) or (e-c > k)):
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long
inline ll read() {
    ll x=0,f=1; char ch=getchar();
    for(;ch<'0'||ch>'9';ch=getchar())
        if(ch=='-')f=-f;
    for(;ch>='0'&&ch<='9';ch=getchar())
        x=x*10+ch-'0';
    return x*f;
}
inline void chkmin( int &a,int b ) { if(a>b) a=b; }
inline void chkmax( int &a,int b ) { if(a<b) a=b; }
#define _ read()
inline int gcd( int a,int b ) { return b==0?a:gcd(b,a%b); } 
int main() {
	set< int > s;
	int a=_,b=_,c=_;
	for( int i=max(a,b);i;i-- ) {
		if(a%i==0&&b%i==0) c--;
		if(!c) return cout<<i<<"\n",0;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
#define db double
#define zero(x) (fabs(x)<eps)
#define sgn(x) (zero(x)?0:((x)>0?1:-1))
const db eps=1e-10;
struct point{
    db x,y;
    point(){}
    point(db x,db y):x(x),y(y){}
    point operator + (point B){ return point(x+B.x,y+B.y); }
    point operator - (point B){ return point(x-B.x,y-B.y); }
    point operator * (db k){ return point(k*x,k*y); }
    db operator * (point B){ return x*B.y-y*B.x; }
    db operator ^ (point B){ return x*B.x+y*B.y; }
    bool operator < (point B){ return (y>0)!=(B.y>0)?y>0:((*this)*B)>0; }
};
db dis2(point A,point B){ return (A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y); }
struct line{
    point A,B;
    line(){}
    line(point A,point B):A(A),B(B){}
};
point projection(line l,point P){
    point dir=l.B-l.A; P=P-l.A;
    return dir*((P^dir)/dis2(l.A,l.B))+l.A;
}
point reflection(line l,point P){
    return projection(l,P)*2-P;
}
int direction(point P0,point P1,point P2){
    db det=(P2-P0)*(P1-P0); return sgn(det);
}
bool parallel(line l1,line l2){
    return zero((l1.B-l1.A)*(l2.B-l2.A));
}
bool orthogonal(line l1,line l2){
    return zero((l1.B-l1.A)^(l2.B-l2.A));
}
bool intersect(line l1,line l2){
    int d1=direction(l1.A,l1.B,l2.A),d2=direction(l1.A,l1.B,l2.B);
    int d3=direction(l2.A,l2.B,l1.A),d4=direction(l2.A,l2.B,l1.B);
    if (d1*d2>0||d3*d4>0) return false;
    if (l1.A.x>l1.B.x) swap(l1.A.x,l1.B.x);
    if (l1.A.y>l1.B.y) swap(l1.A.y,l1.B.y);
    if (l2.A.x>l2.B.x) swap(l2.A.x,l2.B.x);
    if (l2.A.y>l2.B.y) swap(l2.A.y,l2.B.y);
    return !(l1.B.x<l2.A.x||l2.B.x<l1.A.x||l1.B.y<l2.A.y||l2.B.y<l1.A.y);
}
point cross_point(line l1,line l2){
    db s1=fabs((l2.B-l2.A)*(l1.A-l2.A)),s2=fabs((l2.B-l2.A)*(l1.B-l2.A));
    return l1.A+(l1.B-l1.A)*(s1/(s1+s2));
}
double dis(line l,point P){
    point proj=projection(l,P);
    if (min(l.A.x,l.B.x)-eps<proj.x&&proj.x<max(l.A.x,l.B.x)+eps)
        if (min(l.A.y,l.B.y)-eps<proj.y&&proj.y<max(l.A.y,l.B.y)+eps)
            return sqrt(dis2(P,proj));
    return sqrt(min(dis2(P,l.A),dis2(P,l.B)));
}
double distance(line l1,line l2){
    if (intersect(l1,l2)) return 0;
    return min(min(dis(l1,l2.A),dis(l1,l2.B)),min(dis(l2,l1.A),dis(l2,l1.B)));
}
int main(){
    int q; scanf("%d",&q);
    while (q--){
        db x1,y1,x2,y2; line l1,l2;
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); l1=line(point(x1,y1),point(x2,y2));
        scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2); l2=line(point(x1,y1),point(x2,y2));
        printf("%.9f\n",distance(l1,l2));
    }
}



Measured memory_bytes: 3228
#include<bits/stdc++.h>
 
#define INF 1000010000
#define nl '\n'
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int,int>
#define pdd pair<double,double>
#define all(c) (c).begin(), (c).end()
#define SORT(c) sort(all(c))
#define sz(c) (c).size()
#define rep(i,n) for( int i = 0; i < n; ++i )
#define repi(i,n) for( int i = 1 ; i <= n; ++i )
#define repn(i,n) for( int i = n - 1 ; i >= 0 ; --i )
#define repf(j,i,n) for( int j = i ; j < n ; ++j )
#define die(s) {std::cout << s << nl;}
#define dier(s) {std::cout << s; return 0;}
#define vi vector<int>
typedef long long ll;
 
using namespace std;
 
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.precision(0); 
	cout.setf(ios::fixed);
 
	vi d;
	
	rep(kk , 10){
		int l = (kk ? 0 : 1) , r = 9;
		while(r - l > 1){
			int mid = (r + l) / 2;
			cout << flush << "? ";
			rep(i , 12){
				cout << (i < sz(d) ? d[i] : (i == sz(d) ? mid : 9));
			}
			cout << nl << flush;
			string ans;
			cin >> ans;
			if(ans == "Y"){
				r = mid;
			}else{
				l = mid;
			}
		}
		string ans;

		if(l == 0 && r == 1 && kk == 0){
			d.pb(1);
		}else{
			cout << flush << "? ";
			rep(i , 12){
				cout << (i < sz(d) ? d[i] : (i == sz(d) ? l : 9));
			}
			cout << nl << flush;
			cin >> ans;
			if(ans == "Y")r = l;
			d.pb(r);
		}
	//	if(kk == 8)break;
		cout << flush << "? ";
		if(d[0] == 1){
			rep(i , sz(d))cout << 9;
			cout << nl << flush;
			cin >> ans;
			if(ans == "Y"){
				break;
			}
		}else{
			cout << to_string((ll)pow(10 , sz(d))) << nl << flush;
			cin >> ans;
			if(ans == "N"){
				break;
			}
		}
	}
	cout << flush << "! ";
	for(int e : d)cout << e;
 
	return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int cost[10]={0,2,5,5,4,5,6,3,7,6};
  Int n,m;
  cin>>n>>m;
  vector<Int> a(m);
  for(Int i=0;i<m;i++) cin>>a[i];
  //sort(a.begin(),a.end());

  vector<string> dp(n+100,"");
  auto cmp=[](string a,string b){
             if(a.size()!=b.size()) return a.size()<b.size();
             for(Int i=0;i<(Int)a.size();i++)
               if(a[i]!=b[i]) return a[i]<b[i];
             return false;
           };
  
  for(Int i=0;i<n;i++){
    if(i&&dp[i]==""s) continue;
    for(Int x:a){
      if(cmp(dp[i+cost[x]],dp[i]+char('0'+x))) dp[i+cost[x]]=dp[i]+char('0'+x);
    }
  }
  cout<<dp[n]<<endl;
  return 0;
}


Measured memory_bytes: 43520
import math
n=int(input())
c=[0]*(n-1)
s=[0]*(n-1)
f=[0]*(n-1)
for i in range(n-1):
  c[i],s[i],f[i] = map(int,input().split())

for i in range(n):
  ans=0
  for j in range(i,n-1):
    ans = max(s[j], math.ceil(ans/f[j])*f[j]) + c[j]
  print(ans)

Measured memory_bytes: 74484
n = int(input())

x= [0,0,0,0,0,0,0,0,0,0]
v= [0,0,0,0,0,0,0,0,0,0]
ans = 0
for i in range(n):
    x[i], v[i] = input().split()

for i in range(n):
    x[i] = float(x[i])
    if v[i] == 'JPY':
        ans += x[i]
    else:
        ans += (x[i] * 380000.0)

print(ans)
    


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;
using ll = long long;

template<typename T>
vector<int> compress(const vector<T> &src){
    const int n = src.size();
    vector<pair<T, int>> sorted(n);
    for (int i = 0; i != n; ++i){
        sorted[i] = {src[i], i};
    }
    sort(sorted.begin(), sorted.end());
    int j = 0;
    auto prev_val = sorted[0].first;
    vector<int> compressed(n, 0);
    for (int i = 0; i != n; ++i){
        if (sorted[i].first != prev_val) {
            ++j;
            prev_val = sorted[i].first;
        }
        compressed[sorted[i].second] = j;
    }
    return compressed;
};



template<typename T>
struct BIT{
    vector<T> bit;
    BIT(int n) : bit(n, 0){}
    T range_sum(int i, int j) {return sum(j) - sum(i - 1);}
    // return sum of v[i] to v[j] including both ends.
    T sum(int j){
        T s = 0;
        for (; j >= 0; j = (j & (j + 1)) - 1) s += bit[j];
        return s;
    }
    void add(int k, T a) {for (; k < bit.size(); k |= k + 1) bit[k] += a;}
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, K;
    cin >> N >> K;
    vector<ll> cum(N + 1);
    ll a;
    cum[0] = 0;
    for (int i = 0; i != N; ++i) {
        cin >> a;
        cum[i + 1] = cum[i] + a - K;
    }
    auto compressed = compress(cum);
    int n = *max_element(compressed.begin(), compressed.end());
    BIT<ll> freq(n + 1);
    ll ans = 0;
    for (auto c : compressed) freq.add(c, 1);
    for (auto c : compressed){
        freq.add(c, -1);
        ans += freq.range_sum(c, n);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

//---------------------------------------------
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

int main() {
    int N,K,L;
    cin >> N >> K >>L;
    
    UnionFind UFK(N),UFL(N);

    rep(i,K) {
        int p,q;
        cin >> p >> q;
        p--;
        q--;
        UFK.merge(p,q);
    }
    rep(i,L) {
        int r,s;
        cin >> r >> s;
        r--;
        s--;
        UFL.merge(r,s);
    }

    map<pair<ll,ll>,int> m;

    rep(i,N) {
        m[{UFK.root(i),UFL.root(i)}]++;
    }
    rep(i,N) {
        cout << m[{UFK.root(i),UFL.root(i)}] << " ";
    }
    cout << endl;

}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define ff first               // For pairs
#define ss second              // For pairs
#define sz(a) int((a).size())  // Function to determine size of any container
#define pb push_back           // Pushback to vector
#define mp make_pair           // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end()
#define tr(container, it) for (auto it = container.begin(); it != container.end(); it++)  //traversing macro
#define lp(it, it1, it2) for (auto it = it1; it < it2; it++)                              //loop
#define present(c, x) (c.find(x) != c.end())
using namespace std;
using namespace std::chrono;
typedef vector<ll> vi;            // Vector of long long
typedef vector<vi> vvi;           // Vector of vi
typedef vector<pair<ll, ll>> ii;  // Vector of pairs
typedef vector<ii> vii;           // Vector of ii
int main() {
    ll n, k;
    cin >> n >> k;
    vi v(n + 1), w(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
    }
    vvi dp(n + 1, vi(k + 1));
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++) {
            if (i - w[j] >= 0)
                dp[j][i] = max(dp[j - 1][i - w[j]] + v[j], dp[j - 1][i]);
            else
                dp[j][i] = dp[j - 1][i];
        }
    }
    cout << dp[n][k] << "\n";
    return 0;
}


Measured memory_bytes: 80256
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
typedef long long unsigned int ll;




int main(){
    int n,k;
    cin>>n>>k;
    ll ans;
    if(k%2!=0){
        int a;
        a=n/k;
        ans=pow(a,3);
        cout<<ans<<endl;
    }else{
        k=k/2;
        int a=(n/k)/2;
        int b=n/k-a;
        ans=pow(a,3)+pow(b,3);
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
   int n;cin>>n;
   int dp[n][2];
   int x,y;
   for(int i=0;i<n;i++)
   cin>>dp[i][0]>>dp[i][1];
  bool f=0;
    for(int i=0;i<n-2;i++){
        bool h=dp[i][0]==dp[i][1];
         bool h1=dp[i+1][0]==dp[i+1][1];
          bool h2=dp[i+2][0]==dp[i+2][1];
          if(h&&h1&&h2) {cout<<"Yes";f=1;break;}
    }
    if(f==0) cout<<"No";
    return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++) cin >> S[i];
	int ans = 0;
	for (int A = 0; A < N; A++) {
		int sum = N;
		for (int i = 0; i < N; i++) {
			for (int j = i+1; j < N; j++) {
				if (S[(i+A)%N][j] != S[(j+A)%N][i]) {
					sum = 0;
					break;
				}
			}
		}
		ans += sum;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3756
#include <bits/stdc++.h>
using namespace std;
 
#define MOD 1000000007
#define INF 100000000
#define MAX 100001
#define int ll
#define ll long long
#define ld long double
#define vi vector<int>
#define pa pair<int, int>
#define pb push_back
#define mp make_pair
 
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...)type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T& t) { cin >> t; }
template<typename First, typename...Rest>void MACRO_VAR_Scan(First& first, Rest&...rest) { cin >> first; MACRO_VAR_Scan(rest...); }
#define VEC(type, c, n) vector<type> c(n);for(auto& i:c)cin>>i;
#define MAT(type, c, m, n) vector<vector<type>> c(m, vector<type>(n));for(auto& r:c)for(auto& i:r)cin>>i;
 
#define BR cout << "\n";
#define SP cout << " ";
#define ENDL cout<<endl;
#define OUT(d) cout<<(d);
#define OUTL(d) cout<<(d)<<endl;
#define YES OUTL("YES")
#define Yes OUTL("Yes")
#define NO OUTL("NO")
#define No OUTL("No")
#define RET return 0;
 
#define REP(i, n) for(int i=0;i<(n);i++)
#define RREP(i, n) for(int i=n-1;i>=0;--i)
#define FOR(i, m, n) for(int i = m;i < n; i++)
#define RFOR(i, a, b) for(int i=(a)-1;i>=(b);--i)
#define AREP(a, n) for(auto (a):(n))
#define ALL(a) (a).begin(),(a).end()
#define IN(n, a, b) ((a)<=(n)&&(n)<(b))

signed main(){ INIT;
    VAR(string, s);
    string a[] = {
        "AKIHABARA", "KIHABARA", "AKIHBARA", "AKIHABRA", "AKIHABAR",
        "KIHBARA", "KIHABRA", "KIHABAR", "AKIHBRA", "AKIHBAR", "AKIHBAR",
        "KIHBRA", "KIHBAR", "KIHABR", "AKIHBR", "KIHBR"
    };
    REP(i, 16) if(a[i] == s){
        YES; RET;
    }
    NO;
RET;}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for(ll i = a; i < (ll)(b); i++)

#define ALL(x) (x).begin(), (x).end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))

using namespace std;
using ll = long long;
using vel = vector<ll>;
using ves = vector<string>;
using veb = vector<bool>;

using qul = queue<ll>;

int main() {
    ll N, M, a, b;
    cin >> N >> M;
    vector<vel> edge(N);

    REP(i, M) {
        cin >> a >> b;
        a--;
        b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    vel Ans(N, -1);
    veb visited(N, false);

    qul Queue;
    Queue.push(0);
    visited[0] = true;

    while(!Queue.empty()){
        ll t = Queue.front();
        Queue.pop();
        for(ll v:edge[t]){
            if(visited[v])
                continue;
            Queue.push(v);
            Ans[v] = t;
            visited[v] = true;
        }
    }

    cout << "Yes" << endl;
    FOR(i, 1, N) cout << Ans[i] + 1 << endl;
}

Measured memory_bytes: 12912
from collections import deque
n = int(input())
q = deque(list(map(int, input().split())))
q.appendleft(0)
q.append(0)

cost = [0] * (len(q) - 1)

for i in range(n + 1):
    cost[i] = abs(q[i] - q[i + 1])

costs = sum(cost)

for i in range(1, len(q) - 1):
    temp = costs + abs(q[i - 1] - q[i + 1]) - (abs(q[i - 1] - q[i]) + abs(q[i + 1] - q[i]))
    print(temp)


Measured memory_bytes: 14524
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG true
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
   int n;
   cin>>n;
   if(n==3||n==5||n==7)
       cout << "YES" << endl;
       else{
           cout << "NO" << endl;
       
       }
       return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC_Training
{



    public class Program
    {
        static void Main(string[] args)
        {
            var r = int.Parse(Console.ReadLine());

            Console.WriteLine(Calc.Ans(r));
        }
    }
    public static class Calc
    {
        public static int Ans(int r)
        {
            return r * r;
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
const ll MOD = 1e9;

int main(){
  ll n;
  cin>>n;
  if(n==1){
	cout<<"Yes"<<endl;
	cout<<2<<endl;
	cout<<1<<" "<<1<<endl;
	cout<<1<<" "<<1<<endl;
	return 0;
  }
  ll f=0;
  ll k;
  for(int i=0;i<n;i++){
	if(i*(i+1)==n*2){
	  f=1;
	  k=i;
	}
  }
  if(f==0){
	cout<<"No"<<endl;
	return 0;
  }
  cout<<"Yes"<<endl;
  cout<<k+1<<endl;
  ll cnt=1;
  vector<ll> v[1111];
  for(int i=1;i<=k;i++){
	v[1].push_back(i);
	cnt++;
  }
  for(int i=2;i<=k;i++){
	v[i].push_back(i);
	for(int j=2;j<i;j++){
	  v[i].push_back(v[j][i-2]);
	}
	ll r=k-v[i].size();
	for(int j=0;j<r;j++){
	  v[i].push_back(cnt);
	  cnt++;
	}
  }
  //  cout<<"A"<<endl;
  for(int i=1;i<=k;i++){
	cout<<k;
	for(int j=0;j<v[i].size();j++){
	  cout<<" "<<v[i][j];
	}
	cout<<endl;
  }
  cout<<k<<" "<<1;
  for(int i=2;i<=k;i++){
	cout<<" "<<v[i][k-1];
  }
  cout<<endl;
  return 0;
}


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

int main(){
    int x_1,y_1,x_2,y_2;
    cin>>x_1>>y_1>>x_2>>y_2;

    int a=y_1-y_2;
    int b=x_2-x_1;

    int x_3,y_3,x_4,y_4;
    x_3=x_2+a;
    y_3=y_2+b;
    x_4=x_3-b;
    y_4=y_3+a;

    cout<<x_3<<" "<<y_3<<" "<<x_4<<" "<<y_4<<endl;
}

Measured memory_bytes: 256
a = [list(map(int, input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]

for i in b:
    for j in range(0,3):
        for k in range(0,3):
            if i == a[j][k]:
                a[j][k] = 0


if a[0][0]==0 and a[0][1]==0 and a[0][2]==0:
    print("Yes")
elif a[1][0]==0 and a[1][1]==0 and a[1][2]==0:
    print("Yes")
elif a[2][0]==0 and a[2][1]==0 and a[2][2]==0:
    print("Yes")
elif a[0][0]==0 and a[1][0]==0 and a[2][0]==0:
    print("Yes")
elif a[0][1]==0 and a[1][1]==0 and a[2][1]==0:
    print("Yes")
elif a[0][2]==0 and a[1][2]==0 and a[2][2]==0:
    print("Yes")
elif a[0][0]==0 and a[1][1]==0 and a[2][2]==0:
    print("Yes")
elif a[0][2]==0 and a[1][1]==0 and a[2][0]==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9240
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int[] alphabetList = new int[26];
        String line;
        while (null != (line = br.readLine())) {
            for (int c : line.toCharArray()) {
                c = c >= 65 && c <= 90 ? c - 65 : c >= 97 && c <= 122 ? c - 97 : c;
                if (c >= 0 && c <= 26) {
                    alphabetList[c]++;
                }
            }
        }
        int n = 0;
        for (int i : alphabetList) {
            System.out.println((char) (++n + 96) + " : " + i);
        }
    }
}

Measured memory_bytes: 24184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
10^12=2^40
論理和とって0になればOK
01011
0だったら、11か00
A[0]+[1]=32とかだったら、1<<4がどちらも1でないと満たせない
1だったら、01か10
*/
int main(){
  ll N,oo=1e12; cin>>N;
  vector<ll> A(N,0),B(0,0),C(0,0);
  ll x=0;
  for(ll i=0; i<N; i++) cin>>A[i];
  for(ll i=0; i<N; i++) x^=A[i];
  if(x==0){
    cout<<0<<endl;
    return 0;
  }
  x^=A[0];
  x^=A[1];
  ll tmp=A[0]+A[1];
  ll res=0;
  //30-40bit目だけ
  for(ll i=10; i>=0; i--){
    ll n=(1<<30);
    n*=(1<<i);
    if((x&n)==0){
      if(tmp>=n*2){
        res+=n*2;
        tmp-=n*2;
      }
    }
    else{//01の際1をどちらに入れるか選択
      B.push_back(n);
      tmp-=n;
    }
  }
  //~29bit目まで
  for(ll i=29; i>=0; i--){
    ll n=(1<<i);    
    if((x&n)==0){
      if(tmp>=n*2){
        res+=n*2;
        tmp-=n*2;
      }
    }
    else{//01の際1をどちらに入れるか選択
      B.push_back(n);
      tmp-=n;
    }
  }
  if(tmp!=0){
    cout<<-1<<endl;
    return 0;
  }
  res/=2;
  for(auto v:B){
    if(res+v > A[0]) C.emplace_back(res+v);//A[0]を上回ったら候補。
    else res+=v;//下回ってるなら和をとっちゃう
  }
  C.emplace_back(res);
  sort(C.begin(),C.end());
  ll ans=1e12;
  for(auto v: C){
    if(v>A[0] || v==0) continue;
    ans=min(ans,A[0]-v);
  }
  if (ans==oo) cout<<-1<<endl;
  else cout<<ans<<endl;
}


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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  ll n;
  cin >> n;

  ll dp[n+1] = {};
  dp[0] = 0;
  for(int i=1;i<=n;i++){
    dp[i] = INF;
    
    dp[i] = min(dp[i],dp[i-1]+1);
    
    int nineP = 9;
    for(int j=0;j<5;j++){
      if(nineP>i) break;
      dp[i] = min(dp[i],dp[i-nineP]+1);
      nineP *= 9;
    }
    int sixP = 6;
    for(int j=0;j<6;j++){
      if(sixP>i) break;
      dp[i] = min(dp[i],dp[i-sixP]+1);
      sixP *= 6;
    }
    //cout << i << "=" << dp[i] << endl;
  }

  cout << dp[n] << endl;
  return 0;
}



Measured memory_bytes: 4436
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>


using namespace std; 

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

    long long sqrtN;
    sqrtN = sqrt(N);

    long long res = 0;
    for (long long i=sqrtN; 0<i; i--) {
        if (N % i == 0) {
            long long j = N / i;
            res = i + j - 2;
            break;
        }
    }
    
    cout << res << endl;

    return 0;
}

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(ll)(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) reps(i,0,((n)+1))
#define repst(i,s,n) reps(i,s,((n)+1))
#define reprt(i,n,t) for(ll (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto (itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}
#define YES cout<<"YES"<<ln
#define NO cout<<"NO"<<ln
#define Yes cout<<"Yes"<<ln
#define No cout<<"No"<<ln

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b, c, n, m, p[114514], q[114514];
string s, t;

signed main() {
	cin >> n >> a;
	n %= 500;
	if (a>=n) Yes;
	else No;
}

Measured memory_bytes: 892
//B - Unhappy Hacking: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    string s, ansF;
    vector<char> ans;

    cin >> s;
    for(auto x : s) {
        if(x == 'B') {
            if(!ans.empty()) ans.pop_back();
        }
        else if(x == '1') ans.pb('1');
        else ans.pb('0');
    }
    ansF = "";
    for(auto x: ans) ansF += x;
    cout << ansF << '\n';
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define st first
#define nd second
#define endl '\n'


typedef pair<int,int> pii;
const int N = 1e5+5;
const int INF = 1e9;
const int MOD = 1e9+7;

long long n;
int32_t main()
{
	IOS
	//freopen("input.txt", "r", stdin);
	cin >> n;
	if (n&1) {
		cout << 0 << endl;
		return 0;
	}
	n /= 2;
	long long ans = 0;
	while(n){
		ans += n/5;
		n /= 5;
	}
	cout << ans << endl;
	
	return 0;
}


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

bool ok(i64 n) {
    return 1 <= n && n <= 12;
}

int main(void) {
    i64 l, r;
    string s;
    cin >> s;
    l = (s[0] - '0') * 10 + (s[1] - '0'),
        r = (s[2] - '0') * 10 + (s[3] - '0');
    if (ok(l) && ok(r)) cout << "AMBIGUOUS" << endl;
    else if (ok(l) && !ok(r)) cout << "MMYY" << endl;
    else if (!ok(l) && ok(r)) cout << "YYMM" << endl;
    else cout << "NA" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<ll>A(N);
    map<ll, int>mp;
    ll ans = 0;
    rep(i, 0, N){
        cin >> A[i];
        mp[A[i]]++;
    }
   
    rep(i, 0, N){
        if(mp[A[i]] != A[i]){
            mp[A[i]]--;
            ans++;
        }
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7040
import java.util.*;

public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        
        long numHP = sc.nextLong();
        long attackCnt = 0;

        if(numHP == 1) {
            attackCnt = 1;
        }
        
        for (int i=0; i<numHP; i++) {
            if(numHP >= Math.pow(2, i)) {
                if(numHP < Math.pow(2, i+1)) {
                    attackCnt = (long)Math.pow(2, i + 1) - 1;
                    break;
                }
            } 
        }

        
        System.out.println(attackCnt);
    }
}


Measured memory_bytes: 23636
import numpy as np

s=np.array(list(input()))
t=np.array(list(input()))

ans = len(t)

for i in range(len(s)-len(t)+1):
    tmp = sum(s[i:i+len(t)] == t)
    if ans > len(t) - tmp:
        ans = len(t) - tmp

print(ans)

Measured memory_bytes: 27200
n = int(input())
ans = n

prime = []
for i in range(2, int(n**0.5)+1):
    if n%i != 0:
        continue

    prime.append(i)

    while n%i == 0:
        n //= i

if n != 1:
    prime.append(n)

for p in prime:
    ans *= (1-1/p)

print(int(ans))


Measured memory_bytes: 5636
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
//#include <ext/hash_map>
#include <tr1/unordered_map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using namespace tr1;
//using namespace __gnu_cxx;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define DEB 0

/*
real	0m2.093s  --> 
real	0m2.000s
*/
const int dx[] = {1,0,-1,0}; //r,d,l,u
const int dy[] = {0,1,0,-1};

int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];
int hS[25],hx[25],hy[25],edge[25][4][25]; //[src][dir][dest]
//hash_map<int,int> hii;
unordered_map<int,int> hii;


inline bool isnotgoal(int s){
  return (((last&s)) == last);
}
inline bool isnot(int s){
  rep(i,home)if( !(s&(1<<i)) ){
    if( (hS[i]&s)==hS[i] ) return true;
  }
  return false;
}
inline bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}

int dfs(int S){
  int src = S&((1<<5)-1);
  int x = hx[src];
  int y = hy[src];
  int s = S>>5;

  if( (1<<home)-1 == s ){ //ツ静「ツ妥篠づ可姪淞づェツづゥ
    return 1;
  }
  if( isnotgoal(s) ){ //ツ仰ウツ嘉ッツづ可姪淞づゥツつスツづ淞づ個嘉づーツ湘氾ッツつオツつスツつゥツづつ、ツつゥ
    return 0;
  }
  //hash_map<int,int>::iterator it = hii.find(S);
  unordered_map<int,int>::iterator it = hii.find(S);
  if( it!=hii.end() ){ //ツ探ツ催オツ催渉づ敖づ個湘ウツ妥板つゥツづつ、ツつゥ
    return it->second;
  }

  // ツプツδ個ゼツδ督トツつェツ置ツつッツづ按つ「ツ嘉づ個有ツ鳴ウ
  if( s>0 && ((s&(s-1))!=0) && isnot(s&~(1<<src)) ){
    return 0;
  }
  
  int ret = 0;
  rep(k,4){
    for(int j=0; edge[src][k][j]!=-1; j++){
      int dest = edge[src][k][j];
      int nx = hx[dest];
      int ny = hy[dest];
      if( field[ny][nx]==1 ){
	field[ny][nx] = 0;
	ret += dfs(((s|(1<<dest))<<5)|dest);
	field[ny][nx] = 1;
	break;
      }
    }
  }
  hii.insert(make_pair(S,ret));
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    hii.clear();
    memset(num,-1,sizeof(num));
    memset(edge,-1,sizeof(edge));
    memset(hS,0,sizeof(hS));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}
	if( field[i][j]==1 ){
	  hx[home]=j; hy[home]=i;
	  num[i][j] = home;
	  home++;
	}
      }
    }
    hx[home] = sx;
    hy[home] = sy;

    // other homes
    rep(i,home){
      rep(k,4){
	int sz = 0;
	for(int j=1; j<20; j++){
	  int tx = hx[i] + dx[k]*j;
	  int ty = hy[i] + dy[k]*j;
	  if( inside(tx,ty) ) break;
	  if( field[ty][tx]==1 ){
	    hS[i] |= (1<<num[ty][tx]);
	    edge[i][k][sz++] = num[ty][tx];
	  }
	}
      }
    }

    //last homes
    rep(k,4){
      int sz = 0;
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	  edge[home][k][sz++] = num[ty][tx];
	}
      }
    }
    printf("%d\n",dfs(home));
  }
  

  return 0;
}

Measured memory_bytes: 18000
#include<iostream>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<climits>
#include<map>
#include<string>
#include<functional>
#include<iomanip>
#include<deque>
#include<random>
#include<set>
#include<bitset>
#include<cassert>

using namespace std;
typedef long long ll;
typedef double lldo;
#define mp make_pair
#define pub push_back
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else  return gcd(b, a % b); }
ll lcm(ll a, ll b) { if (a == 0) { return b; }return a / gcd(a, b) * b; }
template<class T>ll LBI(vector<T>& ar, T in) { return lower_bound(ar.begin(), ar.end(), in) - ar.begin(); }
template<class T>ll UBI(vector<T>& ar, T in) { return upper_bound(ar.begin(), ar.end(), in) - ar.begin(); }

ll a, b, c;

int main() {
	cin >> a >> b >> c;
	if (c - a - b > 0 && 4 * a* b < (c - a - b) * (c - a - b)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



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

cout<<t<<s<<endl;
 return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
#define HohleFeuerwerke using namespace std
#define int long long
#define MAXN 100005
HohleFeuerwerke;
int a,b,c,k;
inline int read(){
	int s=0,f=1;char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) s=s*10+c-'0';
	return s*f;
}
signed main()
{
	a=read(),b=read(),c=read(),k=read();
	if(a>=k) printf("%lld\n",k);
	else printf("%lld\n",2*a+b-k);
}

Measured memory_bytes: 3716
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N = INT()
A = LIST()

A_acc = []
tmp = 0
for a in A:
	tmp += a
	tmp %= mod
	A_acc.append(tmp)

ans = 0
for i, a in enumerate(A):
	ans += a*(A_acc[-1]-A_acc[i])
	ans %= mod

print(ans)


Measured memory_bytes: 34344
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        int k = sc.nextInt();
        for (int i = 0; i < k; i++) {
            if(i % 2 == 0) {
                if(a % 2 == 1) {
                    a--;
                }
                b += a / 2;
                a /= 2;
            } else {
                if(b % 2 == 1) {
                    b--;
                }
                a += b / 2;
                b /= 2;
            }
        }
        System.out.println(a + " " + b);
    }
}

Measured memory_bytes: 38936
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	var n int
	fmt.Scan(&n)
	A := make([]int, n, n)
	for i := 0; i < n; i++ {
		A[i] = nextInt()
	}

	loop := true
	count := 0
	for loop {

		for i := 0; i < n; i++ {
			if A[i]%2 == 1 {
				loop = false
			}
			A[i] = A[i] / 2
		}
		
		if loop {
			count++
		}

	}

	fmt.Println(count)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main()
{
    int N,D;
    cin >> N >> D;
    cout << (N + (2*D +1) - 1)/ (2*D +1);
}


Measured memory_bytes: 3576
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val d = sc.nextInt()

    val capacity = d * 2 + 1
    var ans = n / capacity
    if (n % capacity != 0) {
        ans++
    }
    println(ans)
}

Measured memory_bytes: 29600
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int solve(int,int);
int c[3][102];
int main()
{
    int n,max,k;
    max=-1;
    scanf("%d",&n);
    for(int i=1;i<=2;++i)
    {
        for(int j=1;j<=n;++j)
        {
            scanf("%d",&c[i][j]);
        }
    }
    for(int i=1;i<=n;++i)
    {
        k=solve(i,n);
        if(max<k)
        {
            max=k;
        }
        
    }
    cout<<max<<endl;
    return 0;
}
int solve(int t,int m)
{
    int count=0;
    for(int i=0;i<=t;++i)
    {
        count+=c[1][i];
    }
    for(int i=t;i<=m;++i)
    {
        count+=c[2][i];
    }
    return count;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
a = [-1]*n
for i in range(m):
    s, c = map(int, input().split())
    if a[s-1] == -1:
        a[s-1] = c
    elif a[s-1] != c:
        print(-1)
        exit()
    if n != 1 and s == 1 and c == 0:
        print(-1)
        exit()
for i in range(n):
    if a[i] == -1:
        a[i] = 0
if n != 1 and a[0] == 0:
    a[0] = 1
for i in range(n):
    print(a[i], end="")

Measured memory_bytes: 9168
#include <iostream>
#include <string>

using namespace std;

main(){
    int A,B,C;
    cin >> A >> B >> C;
    int Atemp=0, Btemp=0, Ctemp=0;
    int cont = 0;
    bool infinite = false;
    while(true){
        if(A%2==1 or B%2==1 or C%2==1) break;
        if(A==B and B==C and A==C){infinite=true;break;}
        Atemp = (B/2) + (C/2);
        Btemp = (A/2) + (C/2);
        Ctemp = (A/2) + (B/2);
        A = Atemp; B = Btemp; C = Ctemp;
        cont++;
    }
    if(infinite) cout << -1 << endl;
    else cout << cont << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef vector<int> vi;
// #define ll long long 
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9+7;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+2;
int cnt[10][10];
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<=n;i++)
	{
		string s=to_string(i);
		int first=s[0]-'0';
		int last=s[(int)s.size()-1]-'0';
		cnt[first][last]++;
		ans+=2*cnt[last][first];
		if(first==last) ans--;
	}
	cout<<ans;
}
// I never lose. I either win or I learn

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define uniqueV(x)                                                             \
  sort(x.begin(), x.end());                                                    \
  x.erase(unique(x.begin(), x.end()), x.end());
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y)                                                           \
  cerr << "(" << #x << ", " << #y << ") = "                                    \
       << "(" << x << ", " << y << ")" << '\n'

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

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

// ----------------------------------------------

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int k;
  cin >> k;

  string s;
  cin >> s;

  int n = s.size();

  if (n <= k) {
    cout << s << endl;
  } else {
    string a = s.substr(0, k);
    cout << a << "..." << endl;
  }

  return 0;
}

Measured memory_bytes: 3616
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int

def solve(L: str):
    N = len(L)

    #dp[i][j] = i桁めまでみたとき、j=0のとき、L以下であることが確定していない、j=1確定している
    dp = [[0]*2 for _ in range(N+1)]
    dp[0][0] = 1    

    for i in range(N):
        dp[i+1][1] += dp[i][1]*3
        if L[i] == "1":
            dp[i+1][1] += dp[i][0]
            dp[i+1][0] += dp[i][0]*2
        else: # 0
            #0のときは確定することはない
            dp[i+1][0] += dp[i][0]
        dp[i+1][0]%=MOD
        dp[i+1][1]%=MOD

    print((dp[N][0]+dp[N][1])%MOD)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    L = next(tokens)
    solve(L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 20692