akhauriyash/Code-Regression huggingface dataset:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    a, b, c = map(int, input().split())
    k = int(input())
    n = 0
    while a >= b:
        b <<= 1
        n += 1
    while b >= c:
        c <<= 1
        n += 1
    print("Yes" if n <= k else "No")
resolve()

Measured memory_bytes: 61808
main = do
  getLine
  li <- getLine
  let as = map read $ words li
  li <- getLine
  let bs = map read $ words li
  let ans = compute as bs
  print ans

compute :: [Int] -> [Int] -> Int
compute as bs = fst $ foldl step (0,0) $ zip as $ bs++[0]

step (total,carry) (a,b) = (t1,b1)
  where
    a1 = max 0 (a - carry)
    a2 = max 0 (a1 - b)
    t1 = total + a - a2
    b1 = b - (a1 - a2)


Measured memory_bytes: 165244
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

int bit(long bits) {
  bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
  bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
  bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
  bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
  return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main()
{
	int n,k;
	string str;
	while( cin >> n >> k && n || k ){
		set<string> ret;
		vector<string> num(n);
		for(int i=0;i<n;i++){
			cin >> num[i];
		}
		sort(num.begin(),num.end());
		for(int mask=0;mask < (1<<n); mask++){
			if(bit(mask)!=k)continue;
			vector<string> uuu;
			for(int j=0;j<n;j++){
				if( mask & (1<<j) )uuu.push_back(num[j]);
			}

			do{
				str="";
				for(int i=0;i<k;i++){
					str+=uuu[i];
				}
				ret.insert(str);
			}while( next_permutation(uuu.begin(),uuu.end()) );
		}
		cout << ret.size() << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
//#define _GLIBCXX_DEBUG

signed main() {
  int K; cin >> K;
  string S; cin >> S;
  
  if(S.size() <= K) cout << S << endl;
  else cout << S.substr(0, K) << "..." << endl;
  

}

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

template<class I> I chmax(I &x, I y) { return x < y ? x = y : x; }
template<class I> I chmin(I &x, I y) { return x > y ? x = y : x; }

char s[103];
short F[103][103][103][103];
short s1[103][103], s2[103][103];

int main()
{
	int n, m, tx = 0, ty = 0;
	scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", s + 1);
		for(int j = 1; j <= m; j++)
		{
			s1[i][j] = s1[i][j - 1] + (s[j] == 'o');
			s2[i][j] = s2[i - 1][j] + (s[j] == 'o');
			if(s[j] == 'E') tx = i, ty = j;
		}
	}
	int limu = tx - 1, limd = n - tx;
	int liml = ty - 1, limr = m - ty;
	for(int u = 0; u <= limu; u++)
	for(int d = 0; d <= limd; d++)
	for(int l = 0; l <= liml; l++)
	for(int r = 0; r <= limr; r++)
	{
		int L = max(ty - l, r + 1), R = min(ty + r, m - l);
		if(L <= R)
		{
			chmax(F[u + 1][d][l][r], (short) (F[u][d][l][r] + (tx - u - 1 >= d + 1 ? s1[tx - u - 1][R] - s1[tx - u - 1][L - 1] : (short) 0)));
			chmax(F[u][d + 1][l][r], (short) (F[u][d][l][r] + (tx + d + 1 <= n - u ? s1[tx + d + 1][R] - s1[tx + d + 1][L - 1] : (short) 0)));
		}
		L = max(tx - u, d + 1), R = min(tx + d, n - u);
		if(L <= R)
		{
			chmax(F[u][d][l + 1][r], (short) (F[u][d][l][r] + (ty - l - 1 >= r + 1 ? s2[R][ty - l - 1] - s2[L - 1][ty - l - 1] : (short) 0)));
			chmax(F[u][d][l][r + 1], (short) (F[u][d][l][r] + (ty + r + 1 <= m - l ? s2[R][ty + r + 1] - s2[L - 1][ty + r + 1] : (short) 0)));
		}
	}
	printf("%d\n", F[limu][limd][liml][limr]);
	return 0;
}


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

int main()
{
    string s, t;
    cin >> s >> t;
    int res = 0, size =  s.size();
    
    for(int i = 0; i < size; ++i)
    {
        if(s[i] != t[i]) res++;
    }

    cout << res << "\n";
}

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

int main() {
	int A, B,count=0;
	cin >> A >> B;
	for (int i = A; i <= B; i++) {
		int m1 = i % 10; //1の位
		int m2 = (i % 100 - m1)/10; //10
		int m3 = (i % 1000-m1-m2*10)/pow(10,2); //100
		int m4 = (i % 10000 - m3 * 100 - m2 * 10 - m1)/pow(10,3); //1000
		int m5 = (i - m1  - m2 * 10 - m3 * 100 - m4 * pow(10, 3))/pow(10,4); //10000
		if (m1 == m5 && m2 == m4) {
			count++;
		}
	}
	cout << count;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define All(a) a.begin(),a.end()
#define INF 1000000007
const int MOD = 1000000007;
//accumulate(vec.begin(), vec.end(), 0)
//std::sort(v.begin(), v.end(), std::greater<Type>());
//set_intersection(x, x+7, y, y+6, back_inserter(v));
//set_union(x, x+7, y, y+6, back_inserter(v));
//set_difference(x, x+7, y, y+6, back_inserter(v));

int gcd(int x,int y){
  if(x%y==0) return y;
  else return gcd(y,x%y);
}

bool isPrime(int n){
  if(n < 2) return false;
  else if(n == 2) return true;
  else if(n%2==0) return false;

  for(int i=3;i<=sqrt(n);i++){
    if(n%i==0) return false;
  }
  return true;
}


int main(){
  int n;
  cin >> n;
  string s = "";
  while(n!=0){
    int r = n%2;
    if(r < 0) r+=2;

    n = (n-r) / (-2);

    s += char('0'+ r);
  }
  reverse(All(s));
  if(s.size()==0) s = "0";
  cout<< s <<endl;
}


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

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private void solve(Scanner sc) {
        String s = sc.next();
        s = s.replaceAll(",", " ");
        _out.println(s);
    }
    private long C(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        for (long i = r; i > 1; --i) {
            res /= i;
        }
        return res;
    }
    private long P(long n, long r) {
        long res = 1;
        for (long i = n; i > n - r; --i) {
            res *= i;
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 10316
#include<stdio.h>
#include<stdlib.h>

typedef struct{
  char simbol;
  int value;
}CARD;

int isStable(CARD *, CARD *, int);

int main(){
  int i, j, minj, N;

  CARD temp, C_bubble[36], C_select[36], C_store[36];
  
  scanf("%d", &N);
  if(N >= 1 && N <= 36){
    for(i = 0; i < N; i++){
      scanf(" %c", &C_bubble[i].simbol);
      scanf("%d", &C_bubble[i].value);
      C_select[i] = C_bubble[i];
      C_store[i] = C_bubble[i];
    }
      
    //BubbleSort
    for(i = 0; i < N; i++){
      for(j = N-1; j > i; j--){
	if(C_bubble[j].value < C_bubble[j-1].value){
	  temp = C_bubble[j];
	  C_bubble[j] = C_bubble[j-1];
	  C_bubble[j-1] = temp;
	}
      }
    }
    
    for(j = 0; j < N; j++){
      if(j != N-1) printf("%c%d ", C_bubble[j].simbol, C_bubble[j].value);
      else printf("%c%d\n", C_bubble[j].simbol, C_bubble[j].value);
    }
    if(isStable(&C_store[0], &C_bubble[0], N) == 1)
      printf("Stable\n");
    else
      printf("Not stable\n");
    
    //SelectionSort
    for(i = 0; i < N; i++){
      minj = i;
      for(j = i; j < N; j++){
	if (C_select[j].value < C_select[minj].value)
	  minj = j;
      }
      if(i != minj){
	temp = C_select[i];
	C_select[i] = C_select[minj];
	C_select[minj] = temp;
      }
    }
    for(i = 0; i < N; i++){
      if(i != N-1) printf("%c%d ", C_select[i].simbol, C_select[i].value);
      else printf("%c%d\n", C_select[i].simbol, C_select[i].value);
    }
    if(isStable(&C_store[0], &C_select[0], N) == 1)
      printf("Stable\n");
    else
      printf("Not stable\n");
  }
  return 0;
}

int isStable(CARD *in, CARD *out, int N){
  int i, j, a, b;
  for(i=0; i < N; i++)
    for(j = i+1;j < N; j++)
      for(a = 0; a < N; a++)
	for( b = a+1; b < N; b++)
	  if(in[i].value == in[j].value && in[i].simbol == out[b].simbol && in[j].simbol == out[a].simbol && in[i].value == out[b].value && in[j].value == out[a].value)
	    return 0;
  return 1;
}



Measured memory_bytes: 2104
#include<bits/stdc++.h>
    using namespace std;
    #define rep(i,b) for(i=0;i<b;++i)
    #define repp(i,a,b) for(i=a;i<b;++i)
    #define per(i,n) for(i=n-1;i>=0;i--)
    #define endl "\n"
    #define pb push_back
    typedef long long int lli;
    const lli mod=1000000007;
    typedef vector<lli> vi;
    typedef pair<lli,lli> pi;
    #define mp make_pair
    #define pb push_back
    int main(){
       //ios_base::sync_with_stdio(false);
       //cin.tie(NULL);
        lli n,t,i,k,j,f,g,m;
        string s;
        vi v;
        map<lli,lli> mm;
        map<lli,lli> :: iterator it;
        cin>>n>>m;
        g=m/n;
        for(i=g;i>0;i--){
            if(m%i==0){
                cout<<i<<endl;
                break;
            }
        }
        return 0;
    }



Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <map>
#include<unordered_map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include<bitset>
#include<deque>
#include<string>
#include<list>
#include<iterator>
#include<sstream>
#include <algorithm>
#include <numeric>
#include <math.h>

#define user spaesk
#define lli long long int
#define ld long double
#define ff first
#define ss second
#define lower(a) transform(a.begin(),a.end(),a.begin(),::tolower);

using namespace std;

const int N = 3e5 + 500;
const long long mod = 1e9 + 7;
const long long cmod = 998244353 ;
const long long inf = 1LL << 61;
const int M = 1e6 + 500;
const lli ths = 1LL << 40;
const int NN = 5e3 + 6;

void solve()
{
    string s;
    cin>>s;
    if(s[0] == '7' || s[1] == '7' || s[2] == '7')
        cout<<"Yes";
    else
        cout<<"No";
    cout<<"\n";
    return ;
}

/*
*/

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

    int t = 1;
//    cin>>t;
    while(t --)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3660
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;


public class Main {
	static class pair{
		int x,y;
		pair(int x,int y){
			this.x=x;
			this.y=y;
		}
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int w=sc.nextInt(),h=sc.nextInt();
			if(w==0&&h==0) return;
			int[][] field = new int[h+2][w+2];
			for(int i=1;i<=h;i++){
				for(int j=1;j<=w;j++){
					field[i][j] = sc.nextInt();
				}
			}
			int result=0;
			for(int i=1;i<=h;i++){
				for(int j=1;j<=w;j++){
					if(field[i][j]==1){
						field = bfs(field,i,j);
						result++;
					}
				}
			}
			System.out.println(result);
		}
	}
	private static int[][] bfs(int[][] field,int x,int y){
		Queue<pair> q = new LinkedList<pair>();
		q.add(new pair(x,y));
		pair now;
		int[] correction = {-1,0,1};
		while(!q.isEmpty()){
			now = q.poll();
			for(int i:correction){
				for(int j:correction){
					if(field[now.x+i][now.y+j]==1){
						q.add(new pair(now.x+i,now.y+j));
						field[now.x+i][now.y+j]=0;
					}
				}
			}
		}
		return field;
	}
}

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

typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<bool>> vvb;
typedef vector<vector<int>> vvi;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)

int main() {
	int n;
	cin >> n;
	vi a(n);
	rep(i, n) cin >> a.at(i);
	bool ok = true;
	int ans = 0;
	while (ok) {
		rep(i, n) {
			if (a.at(i) % 2 == 1)ok = false;
		}
		if (ok) {
			rep(i, n) {
				a.at(i) /= 2;
			}
			ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    vector<string> c(2);
    rep(i,2) cin >> c[i];
    reverse(ALL(c[0]));
    if(c[0] == c[1]) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n],b[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
    b[i]=a[i];
  }
  sort(a,a+n);
  int k=a[n/2],l=a[n/2-1];
  for(int i=0;i<n;i++){
    if(b[i]>=k)cout << l << endl;
    else cout << k << endl;
  }
}


Measured memory_bytes: 3712
A,B,C,D = map(int,input())
pm = {1:"+",-1:"-"}
breakFlg = False
for i in (1,-1):
    for j in (1,-1):
        for k in (1,-1):
            if A+B*i+C*j+D*k == 7:
                print(str(A)+pm[i]+str(B)+pm[j]+str(C)+pm[k]+str(D)+"=7")
                breakFlg = True
                break
        if breakFlg:
            break
    if breakFlg:
        break


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

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

template<class T>
    bool chmin(T& a, T b) {
        if (a > b) {
            a = b;
            return true;
        }
        return false;
}
template<class T> 
    bool chmax(T& a, T b) {
        if (a < b) {
            a = b;
            return true;
        }
        return false;
}

const ll INF = 1e10;;

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n+5);
    vector<ll> b(n+5);
    vector<ll> c(n+5);

    rep(i,n){
        cin >> a[i] >> b[i] >> c[i];
    }

    vector<vector<ll>> dp(n+5,vector<ll>(3,-1));
    dp[0][0] = 0;
    dp[0][1] = 0;
    dp[0][2] = 0;

    rep(i,n){
        chmax(dp[i+1][0], dp[i][1]+a[i]);
        chmax(dp[i+1][0], dp[i][2]+a[i]);
        chmax(dp[i+1][1], dp[i][0]+b[i]);
        chmax(dp[i+1][1], dp[i][2]+b[i]);
        chmax(dp[i+1][2], dp[i][0]+c[i]);
        chmax(dp[i+1][2], dp[i][1]+c[i]);
    }

    cout << max({dp[n][0],dp[n][1],dp[n][2]}) << endl;

    return 0;
}

Measured memory_bytes: 8064
# ABC103-D

N, M = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(M)]

ab.sort(key=lambda x: x[1])

ans = 1
bridge = ab[0][1] - 1

for pair in ab:
    if bridge < pair[0]:
        bridge = pair[1] - 1
        ans += 1

print(ans)


Measured memory_bytes: 64600
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <bitset>
using namespace std;

typedef long long ll;
const int MAX_N = 100000 + 1;
ll A[MAX_N];
ll B[MAX_N];

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

  ll N, M;
  cin >> N >> M;

  // 1-index
  for (int i = 1; i <= N; i++) cin >> A[i];
  B[0] = 0;
  for (int i = 1; i <= N; i++) B[i] = A[i] + B[i - 1];

  map<ll, ll> mp;
  for (int i = 0; i <= N; i++) {
    ll x = B[i] % M;
    if (mp.find(x) != mp.end()) mp[x]++;
    else mp[x] = 1;
  }

  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    ll n = itr->second;
    ans += n*(n-1) / 2;
  }

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


Measured memory_bytes: 8508
a = list(map(int, input().split()))
k = int(input())
b=max(a)
if(a[0] == b):
    a[0] *= 2 ** k
elif a[1] == b:
    a[1] *= 2 ** k
else:
    a[2] *= 2 ** k
print(sum(a))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll l, r;
    cin >> l >> r;

    if (r - l + 1 >= 2019)
    {
        cout << 0 << endl;
        return 0;
    }

    ll ans = 2020;
    for (int i = l; i < r; i++)
    {
        for (int j = i + 1; j <= r; j++)
        {
            ll t1 = i % 2019;
            ll t2 = j % 2019;
            ans = min((t1 * t2) % 2019, ans);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3544
#include <iostream>
#include <vector>
#include <bits/stdc++.h>

using namespace std;

int main () {
    int n;
    vector<int> h;
    int elem;
    vector<int> dp(100000+7);
    
     cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> elem;
        h.push_back(elem);
    }
    
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    for (int i = 2; i < n; i++) {
        int j2 = dp[i-2] + (abs(h[i] - h[i-2]));
        int j1 = dp[i-1] + (abs(h[i] - h[i-1]));
        dp[i] = min(j2, j1);
    }
    cout <<  dp[n-1];
}


Measured memory_bytes: 1276
#pragma GCC optimize("Ofast", "unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()

using ll = long long;
using ld = double;
using pii = pair<int, int>;
using uint = unsigned int;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
default_random_engine generator;

void solve();

int main() {
#ifdef LOCAL
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);  
#endif 
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;  

    int tests = 1;
    // cin >> tests;

    while (tests--) {
        solve();
    }

#ifdef LOCAL
    cerr << "Time: " << double(clock()) / CLOCKS_PER_SEC << endl;
#endif
}

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

int p;

void add(int &a, int b) {
    a += b;
    if (a >= p) {
        a -= p;
    }
}

void sub(int &a, int b) {
    a -= b;
    if (a < 0) {
        a += p;
    }
}

void mul(int &a, int b) {
    a = ll(a) * b % p;
}

void solve() {  
    

    int n;
    cin >> n >> p;

    vector<vector<int>> dp(n + 1, vector<int>(n + 1));

    dp[0][0] = 1;
    for (int k = 1; k <= n; ++k) {
        dp[k][0] = 1;
        for (int sum = 1; sum <= n; ++sum) {
            dp[k][sum] = dp[k - 1][sum];
            if (sum >= k) {
                add(dp[k][sum], dp[k][sum - k]);
            }
        }
    }

    // for (int k = 1; k <= n; ++k) {
    //     for (int sum = 0; sum <= n; ++sum) {
    //         cout << dp[k][sum] << " ";
    //     }
    //     cout << endl;
    // }

    vector<int> pref(n + 2);

    for (int j = 0; j <= n; ++j) {
        pref[j + 1] = pref[j];
        add(pref[j + 1], dp[n / 2][j]);
    }

    vector<vector<int>> f(n + 1, vector<int>(n + 1));

    for (int i = 0; i <= n; ++i) {
        f[0][i] = 1;
    }

    for (int k = 1; k <= n; ++k) {
        f[k][0] = 1;
        for (int m = 0; m <= n; ++m) {
            f[k][m] = f[k - 1][m];
            if (m - 1 - k >= 0) {
                add(f[k][m], f[k][m - 1 - k]);
            }
        }
    }

    int res = 0;
    for (int d = 1; d <= n; ++d) {
        int cur = pref[d];
        mul(cur, f[(n - 1) / 2][n - d]);
        add(res, cur);

        // cout << d << " " << cur << " " << pref[d] << " " << f[(n - 1) / 2][n - d] << endl;
    }

    cout << res << endl;
}


Measured memory_bytes: 196096
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <math.h>
using namespace std;

#define int long long

#if defined(__GNUC__)
#define __int32 __int32_t
#endif // __GNUC__

#define itn __int32
#define REP(i, n) for(itn (i) = 0; (i) < (n); (i)++)
#define REP2(i, x, n) for(itn (i) = x; (i) < (n); (i)++)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define SORT(x) sort(ALL(x))
#define RSORT(x, T) sort(ALL(x), greater<(T)>())
#define REVERCE(x) reverce(ALL(x))

#define INT_POW(x, y) [](int a, int b){int c = a; REP(i, b - 1){c *= a;} return c;}(x, y)

itn main() {
	ios::sync_with_stdio(false);

	int n;

	cin >> n;

	vector<int> x(n);
	vector<int> y(n);

	REP(i, n) {
		cin >> x[i] >> y[i];
	}

	double dissum = 0;

	REP(i, n - 1) {
		REP2(j, i + 1, n) {
			dissum += sqrt((x[i] - x[j]) * (x[i] - x[j]) + (y[i] - y[j]) * (y[i] - y[j]));
		}
	}

	int right, left;
	right = left = 1;

	for (int i = n; i > 1; i--) {
		right *= i;
		left *= i - 1;
	}

	right /= 2;

	cout << fixed;
	cout << setprecision(10) << (dissum * ((double)left / right));

	return 0;
}


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

int main(){
  int K,A,B,i=1;
  cin >> K >> A >> B;
  
 if(A%K==0 || B%K==0 || B/K!=A/K)
   cout << "OK" << endl;
 else
   cout << "NG" << endl;
  
  
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long mod = 1e9 + 7;

ll gcd(ll a, ll b) {
	return b ? gcd(b, a % b) : a;
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

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

	int ans = 0;

	for (int i = 0; i < 3; i++) {
		if (s[i] == t[i]) {
			ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d %d", $n, $m);
$X = array_map('intval', explode(' ', trim(fgets(STDIN))));

if ($n >= $m) {
    echo 0, PHP_EOL;
    return;
}

sort($X);
$div = [];
for ($i = 0; $i < $m - 1; ++$i) {
    $div[] = $X[$i + 1] - $X[$i];
}

$ans = 0;
rsort($div);
for ($i = $n - 1; $i < $m; ++$i) {
    $ans += $div[$i];
}
echo $ans, PHP_EOL;


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  if (N % 2 == 1) {
    cout << "No" <<endl;
  }
  else {
    int n = N / 2;
    string s1, s2;
    for (int i = 0; i < n; i++) {
      s1 += S.at(i);
      s2 += S.at(i + n);
    }
  if (s1 == s2) {
    cout << "Yes" <<endl;
  }
  else {
    cout << "No" <<endl;
  }
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype

template <class T>
int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define popcount __builtin_popcount

const double EPS = 1e-8;
typedef long long ll;
typedef pair<int, int> pint;


int dijkstra(map<int, vector<pint> >& edge, int s, int t)
{
	map<int, int> d;
	priority_queue<pint, vector<pint>, greater<pint> > q;
	q.push(pint(0, s));
	d[s] = 0;
	while (!q.empty())
	{
		pint e = q.top();
		q.pop();
		int dis = e.first;
		int from = e.second;

		if (d[from] < dis)
			continue;
		else if (from == t)
			return dis;

		for (int i = 0; i < edge[from].size(); ++i)
		{
			int to = edge[from][i].second;
			int nextDis = dis + edge[from][i].first;
			if (!d.count(to) || nextDis < d[to])
			{
				q.push(pint(nextDis, to));
				d[to] = nextDis;
			}
		}
	}

	return -1;
}
int manha(pint a, pint b)
{
	return abs(a.first-b.first) + abs(a.second-b.second);
}
int id(pint pos)
{
	return pos.first * 1000 + pos.second;
}
int main()
{
	int w, h;
	while (cin >> w >> h, w | h)
	{
		map<int, vector<pint> > pos;
		int gx, gy, m = 0;

		for (int i = 0; i < h; ++i)
		{
			for (int j = 0; j < w; ++j)
			{
				string s;
				cin >> s;
				if (s[0] == 'S')
					pos[0].push_back(pint(j, i));
				else if (s[0] == 'G')
				{
					gx = j;
					gy = i;
				}
				else if (isdigit(s[0]))
				{
					int t = atoi(s.c_str());
					pos[t].push_back(pint(j, i));
					m = max(m, t);
				}
			}
		}
		++m;
		pos[m].push_back(pint(gx, gy));

		map<int, vector<pint> > edge;
		for (int i = 0; i < m; ++i)
			for (int j = 0; j < pos[i].size(); ++j)
				for (int k = 0; k < pos[i+1].size(); ++k)
					edge[id(pos[i][j])].push_back(pint(manha(pos[i][j], pos[i+1][k]), id(pos[i+1][k])));

		cout << dijkstra(edge, id(pos[0][0]), id(pos[m][0])) << endl;
	}

	return 0;
}

Measured memory_bytes: 4568
#![allow(unused_imports, unused_variables, dead_code)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

trait InputValue {
    fn parse(s: &str) -> Self;
}

fn read<T: InputValue>() -> T {
    let mut buf = String::new();
    let _ = stdin().read_line(&mut buf);
    T::parse(&buf.trim())
}

fn readnc<T: InputValue>() -> Vec<T> {
    let mut vec = vec![];
    let line: String = read();
    for token in line.split_whitespace() {
        vec.push(T::parse(token));
    }
    vec
}

fn readn<T: InputValue>(n: usize) -> Vec<T> {
    let mut vec = vec![];
    for _ in 0..n {
        vec.push(read());
    }
    vec
}

macro_rules! parse_single_value {
    ($($t:ty),*) => {
        $(
            impl InputValue for $t {
                fn parse(s: &str) -> $t { s.parse().unwrap() }
            }
        )*
	}
}
parse_single_value!(i32, i64, f32, f64, usize, String);

macro_rules! parse_tuple {
	($($t:ident),*) => {
		impl<$($t),*> InputValue for ($($t),*) where $($t: InputValue),* {
			fn parse(s: &str) -> ($($t),*) {
				let mut tokens = s.split_whitespace();
				let t = ($($t::parse(tokens.next().unwrap())),*);
				t
			}
		}
	}
}
parse_tuple!(A, B);
parse_tuple!(A, B, C);
parse_tuple!(A, B, C, D);

// ===

fn compute_partial_sum(s: String) -> Vec<i32> {
    let n = s.len();
    let mut sum = vec![0; n+1];

    let s = s.into_bytes();
    for i in 0..n {
        if s[i] == 'A' as u8 {
            sum[i+1] = sum[i] + 1;
        } else {
            sum[i+1] = sum[i] + 2;
        }
    }
    sum
}

fn main() {
    let s: String = read();
    let t: String = read();

    let s = compute_partial_sum(s);
    let t = compute_partial_sum(t);

    let q: usize = read();
    for i in 0..q {
        let (a, b, c, d): (usize, usize, usize, usize) = read();

        if (s[b] - s[a-1]) % 3 == (t[d] - t[c-1]) % 3 {
            println!("YES");
        } else {
            println!("NO");
        }
    }
}

Measured memory_bytes: 4732
#include<bits/stdc++.h>
#define mo 998244353
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,i,j,x,y,l,r,mid,min1,flag,top2,b[300005],c[300005];
vector<pair<long long,long long> > a[300005];
long long top,qu[300005],nex[300005],to[300005],fir[300005];
void lj(int u,int v,long long w){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
	qu[top]=w;
}
void ss(int v,long long w){
	if(flag==1)
		return;
	if(fir[v]==0){
		a[v].insert(a[v].end(),make_pair(w,w));
		return;
	}
	for(int top1=fir[v];top1;top1=nex[top1])
		ss(to[top1],qu[top1]);
	if(flag==1)
		return;
	int l=to[fir[v]],r=to[nex[fir[v]]];
	if(a[l].size()>a[r].size())
		swap(a[l],a[r]);
	long long m1=a[l].size(),m2=a[r].size();
	if(v==1){
		if(a[l][0].first+a[r][0].first<=mid||a[l][0].first+a[r][m2-1].second<=mid||
		   a[l][m1-1].second+a[r][0].first<=mid||a[l][m1-1].second+a[r][m2-1].second<=mid)
			return;
		else{
			flag=1;
			return;
		}
	}
	j=m2-1;
	top2=0;
	for(i=0;i<m1;i++){
		while(a[l][i].first+a[r][j].first>mid){
			j--;
			if(j==-1)
				break;
		}
		if(j==-1)
			break;
		top2++;
		b[top2]=a[r][j].second;
		c[top2]=a[l][i].second;
	}
	for(i=1;i<=top2;i++){
		b[top2+i]=c[top2-i+1];
		c[top2+i]=b[top2-i+1];
	}
	i=1;
	j=top2+1;
	long long min2=1000000000000LL;
	while(i<=top2&&j<=(top2<<1)){
		if(b[i]<b[j]){
			if(c[i]+w<min2){
				a[v].insert(a[v].end(),make_pair(b[i]+w,c[i]+w));
				min2=c[i]+w;
			}
			i++;
		}
		else{
			if(c[j]+w<min2){
				a[v].insert(a[v].end(),make_pair(b[j]+w,c[j]+w));
				min2=c[j]+w;
			}
			j++;
		}
	}
	while(i<=top2){
		if(c[i]+w<min2){
			a[v].insert(a[v].end(),make_pair(b[i]+w,c[i]+w));
			min2=c[i]+w;
		}
		i++;
	}
	while(j<=(top2<<1)){
		if(c[j]+w<min2){
			a[v].insert(a[v].end(),make_pair(b[j]+w,c[j]+w));
			min2=c[j]+w;
		}
		j++;
	}
	if(a[v].size()==0)
		flag=1;
}
int main(){
	n=read();
	for(i=2;i<=n;i++){
		x=read();y=read();
		lj(x,i,y);
	}
	l=0;r=1000000000000LL;mid=(l+r>>1);min1=r;
	while(l<=r){
		flag=0;
		ss(1,0);
		if(flag==1)
			l=mid+1;
		else{
			r=mid-1;
			min1=min(min1,mid);
		}
		mid=(l+r>>1);
		for(i=1;i<=n;i++)
			a[i].clear();
	}
	pus(min1,2);
	return 0;
}

Measured memory_bytes: 40952
// AOJ 0508
#include<algorithm>
#include<iostream>
#include<vector>
#include<cstring>

int n;
std::vector<int> es[101];
bool used[101];

int dfs( int p )
{
	int ret = 1;
	
	for( int i = 0; i != es[p].size(); ++i )
	{
		if( !used[es[p][i]] )
		{
			used[es[p][i]] = true;
			ret = std::max( ret, dfs( es[p][i] ) + 1 );
			used[es[p][i]] = false;
		}
	}

	return ret;
}

int main()
{
	while( std::cin >> n, n )
	{
		for( int i = 0; i <= 100; ++i )
			es[i].clear();
		
		for( int i = 0; i != n; ++i )
		{
			int a, b;
			std::cin >> a >> b;

			es[a].push_back( b );
			es[b].push_back( a );
		}

		int m = 101;
		for( int i = 1; i <= 100; ++i )
			if( !es[i].empty() )
				m = std::min( m, (int)es[i].size() );

		int ans = 0;
		for( int i = 1; i <= 100; ++i )
		{
			if( es[i].size() == m )
			{
				memset( used, false, sizeof( used ) );
				used[i] = true;
				ans = std::max( ans, dfs( i ) );
			}
		}

		std::cout << ans << std::endl;
	}

	return 0;
}

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

int main() {
  int n,x;
  while(1) {
    cin >> n >> x;
    int count = 0;
    if(n == 0 && x == 0) break;
    for(int a = 1; a <= n; ++a) {
      for(int b = a + 1; b <= n; ++b) {
        for(int c = b + 1;c <= n; ++c) {
          if(a + b + c == x) ++count;
        }
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 3092
/**********************************************************
* @Author: 			   Kirito
* @Last Modified by:   Kirito
* @Remark:
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=111111;


int main()
{
	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if(k<=a) cout<<k<<endl;
	else if(k<=a+b) cout<<a<<endl;
	else if(k<=a+b+c) cout<<a-(k-a-b)<<endl;
	else cout<<a-c<<endl;
	return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <stdint.h>
#include <string>

using namespace std;

int main() {
  int N;
  cin >> N;
  string s = to_string(N);
  int cnt = 1;
  for (int i = 1; i < s.size(); ++i) {
    if (s[i] == s[i - 1]) {
      ++cnt;
      if (cnt == 3) {
        printf("Yes\n");
        return 0;
      }
    } else {
      cnt = 1;
    }
  }
  printf("No\n");
}

Measured memory_bytes: 3120
/*
找规律发现滚一次球后串变为取反后左移一位，末尾补位A
大致原因就是
A-> B 变成 A A->
A-> A 变成 B A->
开头和结尾也符合规律

发现 2n 步必然会把初始的串给替换掉，串就变成了 ABABAB... 或者 BABABA... 的形式
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 2e5 + 10;
typedef long long ll;
int n, K, a[N];
char s[N];

int main() {
    cin >> n >> K;
    scanf("%s", s + 1);
    rep(i, 1, n) a[i] = s[i] - 'A';
    int pos = 1, st = a[1];  // pos 表示删到哪一位了
    while (K--) {
        if (!st) {
            st ^= 1, a[pos] ^= 1;
        } else {
            ++pos;
            st = (a[pos] ^ ((pos - 1) & 1));
        }
        if (pos > n) break;
    }
    if (pos <= n) {
        rep(i, pos, n) printf("%c", 'A' + (a[i] ^ ((pos - 1) & 1)));
        int c = (pos & 1);
        rep(i, 1, pos - 1) printf("%c", 'A' + c), c ^= 1;
    } else {
        if (pos & 1) {
            rep(i, 1, n) printf("%c", 'A' + (i & 1));
        } else {
            printf("%c", 'A' + (K & 1));
            rep(i, 1, n - 1) printf("%c", 'A' + (i & 1));
        }
    }
    puts("");
    return 0;
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(x,y) for(lli i=x;i<y;i++)
#define repb(a,b) for(lli i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define bg() begin()
#define en() end()
#define ft first
#define sc second
#define vect_lli_it vector<lli>::iterator
#define set_lli_it set<lli>::iterator
#define inf 1e18
#define all(X) X.begin(),X.end()
#define iterate(X) for(it=X.begin();it!=X.end();it++)
lli combi(lli n,lli k)
{
    lli ans=1;
    k=k>n-k?n-k:k;
    lli j=1;
    for(;j<=k;j++,n--)
    {
        if(n%j==0)
        {
            ans*=n/j;
        }else
        if(ans%j==0)
        {
            ans=ans/j*n;
        }else
        {
            ans=(ans*n)/j;
        }
    }
    return ans;
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli n,x;
    cin>>n>>x;
    vector <lli> arr;
    lli p;
    rep(0,n){
    	cin>>p;
    	arr.pb(p);
	}
	vector <lli> drr;
	drr.pb(0);
	lli ans=0;
	if(0<=x)
	ans++;
	rep(0,n){
		lli d=*(drr.rbegin())+arr[i];
		if(d<=x)
		ans++;
		drr.pb(d);
	}
	cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>

using namespace std;

signed main() {
    long long N, A, B;
    cin >> N >> A >> B;
    long long mins = (A * 2 + N - 2) * (N - 2 + 1) / 2 + B;
    long long maxs = (B * 2 + N - 2) * (N - 2 + 1) / 2 + A;
    cout << max(maxs - mins + 1, 0ll) << endl;
    return 0;
}

Measured memory_bytes: 3592
object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val r = sc.nextInt
    val D = sc.nextInt
    var x = sc.nextInt

    for (i <- 1 to 10) {
      x = r*x - D
      println(x)
    }
  }
}


Measured memory_bytes: 25544
#include<stdio.h>
#include<iostream>

using namespace std;
int main(void){
  int a,b,res;
  int i=0;

  while(cin>>a>>b){
    i=0;
    res=a+b;

    while(res>0){
      res=res/10;
      i++;
    }

    printf("%d\n",i);
  }

  return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const int INF=1e9;
const int MOD=100000;
int dp[101][101];
int main(){
      int d,n;
      while(cin>>d>>n&&(d||n)){
            int a[n],e[n],r[n];
            REP(i,n)cin>>a[i]>>e[i]>>r[i];
            REP(i,101)REP(j,101)dp[i][j]=INF;
            dp[0][0]=0;
            REP(i,d+1){
                  REP(j,101){//current keikenchi
                        if(dp[j][i]==INF)continue;
                        REP(k,n){
                              if(r[k]>j)continue;
                              int nj=min(100,j+e[k]);
                              int ni=min(d,i+a[k]);
                              dp[nj][ni]=min(dp[nj][ni],dp[j][i]+1);
                        }
                  }
            }
            int ans=INF;
            REP(i,101)if(dp[i][d]!=-1)ans=min(ans,dp[i][d]);
            if(ans==INF)cout<<"NA"<<endl;
            else cout<<ans<<endl;
      }
}

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

int main() {
  ll x, k, d, ans;
  cin >> x >> k >> d;
  x = abs(x);
  if (k > x / d + 1) {
    k -= x / d;
    ans = x % d;
    if (k % 2 != 0) ans = abs(ans-d);  
  } else {
    ans = abs(x - k * d);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
//???????????§??¨?????£?????\?????°???????????£?????????????????¨??????????????£??????????????????????????????????????????????????????????????£???????????£?????????????±??????????????????????????????£?????????
#include<iostream>
#include<cmath>
#include <stdio.h>
#include<vector>
#include<sstream>
#include<istream>
#include<string>
#include <stdlib.h>
using namespace std;

double area(double a,double b,double c){
  double z=(a+b+c)/2.0;
  return sqrt(z*(z-a)*(z-b)*(z-c));
}

double len(double x1,double x2,double y1,double y2){
  return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
}
  

int main(){
  double x[21],y[21];
  double s=0.0;
  int n=0;
  while(true){
    vector<string> v;
    string s;
    cin >>s;
    if(!cin) break;
    else{
      stringstream ss;
      ss << s;
      string buf;
      while(getline(ss,buf,',')){
	v.push_back(buf);
      }
      istringstream xs(v[0]);
      istringstream ys(v[1]);

      xs>>x[n];
      ys>>y[n];
      n++;
    }
  }
  n-=1;
  for(int i=1;i<n;i++){
    double a,b,c;
    a=len(x[0],x[i],y[0],y[i]);
    b=len(x[i],x[i+1],y[i],y[i+1]);
    c=len(x[i+1],x[0],y[i+1],y[0]);;
    s+=area(a,b,c);
  }
  printf("%.6f\n",s);
}

Measured memory_bytes: 3160
#include<bits/stdc++.h>
#include<vector>
#include<string>
using namespace std;
#define l long long
#define pb push_back
#define mem(a,n) memset(a,n,sizeof(a))
//#define find(v,n) find(v.begin(),v.end(),n)
#define sort1(v) sort(v.begin(),v.end())
#define lb(v,n) lower_bound(v.begin(),v.end(),n)-v.begin()
//#define ub(v,n) upper_bound(v.begin(),v.end(),n)-v.begin()
#define mod 1000000007
#define reverse(s) reverse(s.begin(),s.end())
//#define pi pair<l,l> 
const double pi=3.141592653589793;
bool isprime(l n)
{
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
			return false;
	}
	return true;
}
/*bool fact(l n)
{
	vector<l> v;
	for(l i=2;i*i<=n;i++)
	{
		if(n%i==0)
		{
			if(i%2==1||(n/i)%2==1)
			{
				return true;
			}
		}
	}
	return false;
}*/
l power(l a,l b)
{
	l ans=1;
	while(b>0)
	{
		if(b&1)
		{
			ans=(ans*a)%mod;
		}
		b>>=1;
		a=(a*a)%mod;
	}
	return ans%mod;
}//prefixsums
l ncr(l n,l r,vector<l> fact)
{
	l ans=(fact[n]/((fact[n-r]*fact[r])%mod))%mod;
	return ans;
}
void frooty(l t1)
{
	l n,x,t;
	cin>>n>>x>>t;
	if(n%x==0)
	{
		cout<<(n/x)*t<<"\n";
	}
	else
	{
		cout<<(n/x+1)*t<<"\n";
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int q=1;
	//cin>>q;
	//q++;
	for(int i=0;i<q;i++)
	{
		char c[]="anudeep";
		frooty(i+1);
	}
}

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

int main(){
  
  int H,W;
  cin >> H >> W;
  
  vector<vector<char>> S(H,vector<char>(W));
  
  for(int i = 0; i < H; ++i){
    	for(int j = 0; j < W; ++j){
  
      		cin >> S.at(i).at(j);
      
    	}
  }
  
  vector<int> dx = {-1,0,1};
  vector<int> dy = {-1,0,1};
  
  for(int i = 0; i < H; ++i){
    	for(int j = 0; j < W; ++j){
  
      		if(S.at(i).at(j) == '.'){
      
        		int count = 0;
              
        		for(int x : dx){
          			for(int y : dy){
          
            			if(0 <= i+x && i+x <= H-1 && 0 <= j+y && j+y <= W-1){
                          	if(S.at(i+x).at(j+y) == '#'){
              					++count;
                            }
            			}
            
          			}
        		}
        
        		cout << count;
      
      		}else{
            
              	cout << "#";
            
            }
      
    	}
    cout << endl;
  }

  return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


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

  ll ret = 0;
  REP(i,1,N+1){
    int head = i;
    while(true){
      if(head/10 == 0) break;
      head /= 10;
    }
    int tail = i%10;
    if(tail == 0) continue;

    ll tmp = 0;
    if(head == tail) tmp++;

    rep(keta,10){
      ll p = tail;
      rep(j,keta+1) p *= 10;
      p += head;
      if(p > N) break;
      ll q = tail;
      rep(j,keta+1){
        q *= 10;
        if(j<keta) q += 9;
      }
      q += head;
      if(q > N) {
        if(N%10 < p%10){
          tmp += (N/10-1) - (p/10) + 1;
        }else{
          tmp += (N/10) - (p/10) + 1;
        }
        break;
      }

      int x = 1;
      rep(j,keta) x *= 10;
      tmp += x;
    }
    //cout << i << "\t" << tmp << endl;
    ret += tmp;

    /*
    int tmp2 = 0;
    REP(j,1,N+1){
      int h = j;
      while(true){
        if(h/10==0) break;
        h /= 10;
      }
      int t = j%10;
      if(t == 0) continue;

      if(head == t && tail == h){
        tmp2++;
        //cout << " " << j << endl;
      }
    }
    if(tmp != tmp2){
      cout << i << " " << tmp << " " << tmp2 << endl;
    }
      //*/
  }

  cout << ret << endl;
  
  return 0;
}


Measured memory_bytes: 256
/**OOO**/
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long ull;
using namespace std;


#define mems(arr,VAL)           memset(arr,VAL,sizeof(arr))
#define pii                     pair<int,int>
#define mk                      make_pair
#define pb                      push_back
#define ff                      first
#define ss                      second
#define PI                      acos(-1.0)

#define pf                      printf
#define sc                      scanf
//#define Mod                     1000000007
#define hiii                    1e9//1000000000
#define looo                   -1e9//-1000000000


#define LL             ll
#define input                   freopen("desk.in","r",stdin);
#define output                  freopen("desk.out","w",stdout);




int main()
{

       string st;
       ll cnt =0, len;
       cin>>st;
       len = st.size();

       for(int i=0;i<len;i++){
            if(st[i]=='+')cnt++;
            else cnt--;
       }
       cout<<cnt<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	string t = s;
	int n = s.size();
	reverse(all(t));
	if (s != t) {
		puts("No");
		return 0;
	}
	string k = s.substr(0, (n - 1) / 2);
	string h = k;
	reverse(all(h));
	if (h != k) {
		puts("No");
		return 0;
	}
	string d = s.substr((n + 3) / 2 - 1, n - (n + 3) / 2 + 1);
	string q = d;
	reverse(all(q));
	if (q != d) {
		puts("No");
		return 0;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 256
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define mini(vec) return *std::min_element(vec.begin(), vec.end());
#define maxi(vec) return *std::max_element(vec.begin(), vec.end());

int main() {
    int count=0;
    bool flag = true;
    vector<int> vec(100000000);
    cin >>vec.at(0);
    for(int i=0;i<100000000;i++){
        if(vec.at(i)%2==0){
            vec.at(i+1)=vec.at(i)/2;
        }
        else{
            vec.at(i+1)=3*(vec.at(i))+1;
        }
        for(int j=0;j<i;j++){
            //cout<<vec.at(i+1)<<"A"<<vec.at(j)<<endl;
            if(vec.at(i+1)==vec.at(j)){
                cout<<i+2<<endl;
                flag=false;
                break;
            }
        }
        if(flag==false){
            break;
        }
    }
    
}



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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define VACANT 'V'
#define MALE   'M'
#define FEMALE 'F'

char buf[256];

int query(int i) {
    printf("%d\n", i);
    fflush(stdout);

    fgets(buf, 255, stdin);
    return (int)buf[0];
}

bool sync(int x, int y, int ax, int ay) {
    if ((x - y) % 2 == 0) {
        return ax == ay;
    } else {
        return ax != ay;
    }
}

int main() {
    fgets(buf, 255, stdin);
    int N = atoi(buf);

    int al = query(0);
    if (al == VACANT) return 0;

    int l=0, h=N;
    int ah = al;

    rep(i, 16) {
        int m = (l+h)/2;
        int am = query(m);
        if (am == VACANT) return 0;

        if (sync(l,m, al,am)) {
            l = m; al = am;
        } else {
            h = m; ah = am;
        }
    }
    for (int m=l+1; m<h; ++m) {
        int am = query(m);
        if (am == VACANT) return 0;
    }

    return 0;
}


Measured memory_bytes: 852
def calcPattern(N, Y):
    for i in range(0, N+1):
        for j in range(0, N+1-i):
            if i == ((Y - 1000*N - 4000*j) / 9000):
                if (N-i-j) >= 0: return (str(i) + " " + str(j) + " " +str(N-i-j))
    return ("-1 -1 -1")
    
n,y = map(int, input().split())
print(calcPattern(n,y))

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

const int N = 500;
const int Mod = 1e9 + 7;
int n, m, f[N], used[N]; char s[N][N]; vector <int> g[N];

inline int dec(int x) {return x < 0 ? x + Mod : x;}
inline int inc(int x) {return x >= Mod ? x - Mod : x;}

template <class T> inline void in(T &x) {
	x = 0; int f = 1; char ch = getchar();
	for (; ch<'0' || ch>'9';) {if (ch=='-') f=-1; ch = getchar();}
	for (; ch>='0' && ch<='9';) x = x*10 + ch-'0', ch = getchar();
	x *= f;
}

inline int Count(string p) {
	sort(p.begin(), p.end());
	int n = p.size(), res = f[(int)p.size()];
	for (int l = 0, r; l < n; l = r) {
		r = l;
		for (; r < n && p[r] == p[l];) ++r;
		res /= f[r - l];
	}
	return res;
}

inline void dfs(int u) {
	used[u] = 1;
	for (auto v : g[u])
		if (!used[v]) dfs(v);
}

int main() {
	in(n), in(m), f[0] = 1;
	for (int i = 1; i < 5; ++i) f[i] = f[i - 1] * i;
	for (int i = 0; i < n; ++i) scanf("%s", s[i]);

	int ans = 1;
	for (int i = 0; i < n / 2; ++i)
		for (int j = 0; j < m / 2; ++j) {
			string p = "";
			p += s[i][j];
			p += s[n - i - 1][j];
			p += s[i][m - j - 1];
			p += s[n - i - 1][m - j - 1];
			int z = Count(p);
			if (z == 24) {
				z = 12;
				g[i].push_back(n + j);
				g[n + j].push_back(i);
			}
			ans = 1LL * ans * z % Mod;
		}

	if (n & 1) {
		int ok = false;
		for (int i = 0; !ok && i < m / 2; ++i)
			if (s[n / 2][i] != s[n / 2][m - i - 1])
				ok = true, ans = inc(ans << 1);
	}
	if (m & 1) {
		int ok = false;
		for (int i = 0; !ok && i < n / 2; ++i)
			if (s[i][m / 2] != s[n - i - 1][m / 2])
				ok = true, ans = inc(ans << 1);
	}

	int res = n + m;
	for (int i = 0; i < n + m; ++i)
		if (!used[i]) -- res, dfs(i);
	for (int i = 0; i < res; ++i) ans = inc(ans << 1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 512
N, M = (int(i) for i in input().split())
P_Y = {}
for i in range(M):
    P_Y[i] = [int(i) for i in input().split()]

sorted_city = {}
count = [1 for i in range(N)]
S = sorted(P_Y.values())

for j, v in S:
    sorted_city[v] = str(j).zfill(6) \
    + str(count[j-1]).zfill(6)
    count[j-1] += 1

for i in range(M):
    print(sorted_city[P_Y[i][1]])


Measured memory_bytes: 49084