akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, char>;

int main(){
    char c;
    cin >> c;
    c++;
    cout << c <<endl;

    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>

int main(){
  int a,b,k;
  std::cin >> a >> b >> k;
  if((b-a)<k*2){
    for(; a!=b+1; ++a){
      std::cout << a << std::endl;
    }
  }else{
    for(   int i=0; i<k; ++i) std::cout << a+i << std::endl;
    for(int i=k-1; i>=0; --i) std::cout << b-i << std::endl;
  }
  return 0;
}

//1.2.3.4.5.6.7


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

#define llong long long
#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i++))
#define _min(a,b) ((a)<(b)?(a):(b))
#define _max(a,b) ((a)>(b)?(a):(b))
#define _abs(a,b) (((a)-(b))>0?((a)-(b)):((b)-(a)))

using namespace std;

int main(){
	int X; cin >> X;
	if( X >= 30 ) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <math.h>
#include <algorithm>

using namespace std ;

int main(void){
    int H,W;
    cin >> H >> W;
    char a[100][101];
    char b[102][102];

    for(int i=0; i<H+2; i++){
        for(int j=0; j<W+2; j++){
            b[i][j]='#';
        }
    }

    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> a[i][j];
        }
    }
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            b[i+1][j+1] = a[i][j];
        }
    }

    for(int i=0; i<H+2; i++){
        for(int j=0; j<W+2; j++){
            cout << b[i][j];
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
#define rep(i,a,b) for (int i = (a); i < (b); i++)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef complex<double> com;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int inf = 2e9;



int main(){
	int n, m; cin >> n >> m;
	vector<int> cnt(n);
	rep(i, 0, m) {
		int p, q; cin >> p >> q;
		p--; q--;
		cnt[p]++; cnt[q]++;
	}
	rep(i, 0, n) {
		if (cnt[i] % 2) {
			printf("NO"); return 0;
		}
	}
	printf("YES");
	return 0;
}


Measured memory_bytes: 640
import java.util.Arrays;
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        
        int n = sc.nextInt();
        int[] p = new int[n];
        int[] t = new int[n];
        for(int i = 0; i < n; i++){
            p[i] = sc.nextInt();
            t[i] = p[i];
        }

        Arrays.sort(p);
        int count = 0;
        for(int i = 0; i < n; i++){
            if(p[i] != t[i]){
                count++;
            }
        }
        
        if(count <= 2){
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
        
    }
}

Measured memory_bytes: 21972
import java.util.*;
public class Main {
	int n;
	int [] data;
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			n = sc.nextInt();
			int m = sc.nextInt();
			if((n|m) == 0) break;
			sc.nextLine();
			data = new int[n];
			HashMap<String, Integer> nametoind = new HashMap<String, Integer>();
			for(int i = 0; i < n; i++){
				String input = sc.nextLine();
				String [] inputarray = input.split(" ");
				data[i] = inputarray.length -1;
				nametoind.put(inputarray[inputarray.length - 1], nametoind.size());
			}
			for(int i =0; i < m; i++){
				String input = sc.nextLine();
				String [] inputarray = input.split("[ .]");
				int x = nametoind.get(inputarray[0]);
				String op = inputarray[3];
				int y = nametoind.get(inputarray[5]);
				boolean ans = true;
				switch(op.charAt(0)){
				case 'c':
					ans = isChild(x,y);
					break;
				case 'p':
					ans = isChild(y,x);
					break;
				case 's':
					ans = isSib(x,y);
					break;
				case 'd':
					ans = isDes(x,y);
					break;
				case 'a':
					ans = isDes(y,x);
					break;
				}
				System.out.println(ans ? "True" : "False");
			}
			System.out.println();
		}
	}

	private boolean isDes(int x, int y) {
		for(int i = y + 1; i < n; i++){
			if(data[i] <= data[y]){
				return false;
			}
			if(i == x){
				return true;
			}
		}
		return false;
	}

	private boolean isSib(int x, int y) {
		if(data[x] != data[y]){
			return false;
		}
		int min = Math.min(x,y);
		int max = Math.max(x,y);
		for(int i = min + 1; i < n; i++){
			if(data[i] < data[x]){
				return false;
			}
			if(i == max){
				return true;
			}
		}
		return false;
	}

	private boolean isChild(int child, int parent) {
		if(data[parent] + 1 != data[child]){
			return false;
		}
		for(int i = parent + 1; i < n; i++){
			if(data[i] <= data[parent]){
				return false;
			}
			if(i == child){
				return true;
			}
		}
		return false;
	}
	
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doit();
	}
}

Measured memory_bytes: 13000
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define dd double
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pll pair<ll,ll>
#define fo(i,n) for(int i=0;i<n;i++)
#define fo1(i,n) for(int i=1;i<=n;i++)
ll mod=1000000007;
ll n,k,t,m,q,flag=0;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// using namespace __gnu_pbds; 
// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(a) -- no. of elements strictly less than a
// s.find_by_order(i) -- itertor to ith element (0 indexed)
ll min(ll a,ll b){if(a>b)return b;else return a;}
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll gcd(ll a , ll b){ if(b > a) return gcd(b , a) ; if(b == 0) return a ; return gcd(b , a%b) ;}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifdef NOOBxCODER
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else 
    #define NOOBxCODER 0
    #endif
    //cin>>t;
    t=1;
    while(t--){
        ll s,w;
        cin>>s>>w;
        if(w>=s)cout<<"unsafe"<<endl;
        else cout<<"safe"<<endl;





        
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 3800
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>

int main()
{
  char s[200001],t[200001];
  int a=0;
  int i;
  int l;
  scanf("%s",s);
  scanf("%s",t);
  l=strlen(s);
  for(i=0;i<l;i++){
    if(s[i]!=t[i]) a++;
  }
  printf("%d",a);
  return 0;
}


Measured memory_bytes: 2116
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

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

ll num[2];
ll color[222222];
ll keynoom[3];
ll n;
ll ans[222222];
vector<vector<ll> > v(222222);

void dfs(int now, int cou, int pre){
	color[now] = cou % 2;
	num[cou%2]++;
	REP(i, v[now].size()){
		if(v[now][i] == pre)continue;
		dfs(v[now][i], cou+1, now);
	}
}

void solve_a(){
	//cout << "in solve_a" << endl;
	REP(i, n){
		if(color[i] == 1){
			if(3 * keynoom[1] + 1 <= n){
				ans[i] = 3 * keynoom[1] + 1;
				keynoom[1]++;
			}
			else{
				ans[i] = 3 * keynoom[0] + 3;
				keynoom[0]++;
			}
		}
		else {
			if(3 * keynoom[2] + 2 <= n){
				ans[i] = 3 * keynoom[2] + 2;
				keynoom[2]++;
			}
			else{
				ans[i] = 3 * keynoom[0] + 3;
				keynoom[0]++;
			}
		}
	}
}

void solve_b(){
	//cout << "in solve_b" << endl;
	ll ma = 0;
	if(num[0] < num[1])ma = 1;
	REP(i, n){
		if(color[i] == ma){
			if(3 * keynoom[1] + 1 <= n){
				ans[i] = 3 * keynoom[1] + 1;
				keynoom[1]++;
			}
			else if(3 * keynoom[2] + 2 <= n){
				ans[i] = 3 * keynoom[2] + 2;
				keynoom[2]++;
			}
			else{
				ans[i] = 3 * keynoom[0] + 3;
				keynoom[0]++;
			}
		}
		else {
			ans[i] = 3 * keynoom[0] + 3;
			keynoom[0]++;
		}
	}
}

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

	cin >> n;
	REP(i, n-1){
		ll a, b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
		v[b].PB(a);
	}

	dfs(0, 0, -1);
	ll seica = 0;
	REP(i, n)if((i+1) % 3 != 0)seica++;

	if(max(num[0], num[1]) < seica)solve_a();
	else solve_b();

	SHOW1d(color, n);
	REP(i, n)cout << ans[i] << " ";cout << endl;

	return 0;
}


Measured memory_bytes: 20736
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    VL a(n);
    ll sum = 0;
    REP(i,n){
        scanf("%lld", &a[i]);
        sum += a[i];
    }
    ll ans = 1e18, x = 0;
    REP(i,n-1){
        x += a[i];
        ans = min(ans, abs(sum - 2 * x));
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1792
/*
    Author: Arham_doshi
    @quote "Code like there's no tommorow!"
     ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
    */
    #include <bits/stdc++.h>
     
    #define int         long long
    #define double      long double
    #define pb          push_back
    #define pf          push_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    #define x           first
    #define y           second
    #define sz(x)       (int)x.size()
    #define endl        '\n'
    #define hell        998244353 
    #define PI          3.141592653589
    #define bs(v,n)     binary_search(all((v)),(n))
    #define lb(v,n)     lower_bound(all((v)),(n))
    #define ub(v,n)     upper_bound(all((v)),(n))
    #define fo(i,l,u)   for(i=l;i<u;i++)
    #define rfo(i,l,u)  for(i=l;i>=u;i--)
    #define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
    #define _init(b)     memset(b,-1,sizeof(b))
    #define _init0(b)     memset(b,0,sizeof(b))
     
    using namespace std;
     
    int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
    bool mod(double a,double b) {return a/b - floor(a/b);}
     
    int occurs(vi v,int n){
    auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}
     
    int logb(int base, int x) {
        return (log(x) / log(base));
    }
     
     
    int a[100005][3],b[100005][3];
     
     
    int cost(int n,int k){
        if(n<0)return 0;
        else if(b[n][k]!=-1)return b[n][k];
        else{
            
            
            b[n][k]=cost(n-1,(k+1)%3)+a[n][k];
            b[n][k]=max(b[n][k],cost(n-1,(k+2)%3)+a[n][k]);
            
            //b[n]=min(cost(n-1)+abs(a[i]-a[i-1]),cost(n-2)+abs(a[i]-a[i-2]));
            return b[n][k];
        }
    }
     
     
     
    signed main()
    {
        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
        int i,j,x,t,n,k;
        cin>>n;
        _init(b);
        
        fo(i,0,n){
            fo(j,0,3){
                cin>>x;
                a[i][j]=x;
                //cout<<a[i][j]<<" ";
            }
            //cout<<endl;
        }
        t=max({cost(n-1,0),cost(n-1,1),cost(n-1,2)});
        
        cout<<t;
        
        
        return 0;
    }

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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;


int main(){
    cout << "Yes" << endl;
    int N, M;
    cin >> N >> M;
    int A,B;
    vi2 Graph (N);
    
    REP(i,M){
        cin >> A >> B;
        Graph[A-1].push_back(B-1);
        Graph[B-1].push_back(A-1);
    }
    
    vector<bool> checked (N, false);
    
    queue<int> que;
    que.push(0);
    
    vi milestone (N);
    
    while(!que.empty()){
        int i;
        i = que.front();
        que.pop();
        REP(j,Graph[i].size()){
            if(!checked[Graph[i][j]]){
                que.push(Graph[i][j]);
                milestone[Graph[i][j]] = i+1;
              	checked[Graph[i][j]] = true;
            }
        }
    }
    
    REP(i,N-1){
        cout << milestone[i+1] << endl;
    }
}


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

long long int a[300][300];
bool use[300][300];
long long int ans = 0;


int n;

int main() {

    cin >> n;

    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            cin >> a[i][j];
            use[i][j] = true;
        }
    }

    for(int k=0; k<n; k++){
        for(int i=0; i<n; i++){
            for(int j=0; j<n; j++){
                if(a[i][j] > a[i][k] + a[k][j]){
                    cout << -1 << endl;
                    return 0;
                }
                else if(a[i][j] != 0 && a[i][k] != 0 && a[k][j] != 0 && a[i][j] == a[i][k] + a[k][j]){
                    use[i][j] = false;
                }
            }
        }
    }


    for(int i=0; i<n; i++){
        for(int j=0; j<n; j++){
            if(use[i][j]) {
                ans += a[i][j];
            }
        }
    }

    cout << ans/2 << endl;


    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    int A[n];
    long long ans = 0;
    for (int i = 0; i < n;i++){
        cin >> A[i];
    }
    for (int i = 1; i < n;i++){
        if(A[i]<A[i-1]){

            ans += A[i - 1]-A[i];
            A[i] = A[i - 1];
        }

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

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

ll K;

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

int main() { 
    cin >> K;
    ll out = 0;
    for (ll i = 1; i <= K; i++) {
      for (ll j = 1; j <= K; j++){
        for (ll k = 1; k <= K; k++){
          ll tmp = gcd(i, j);
          out += gcd(tmp, k);
        }
      }
    }
    cout << out << endl;
    return 0;
}

Measured memory_bytes: 3632
//	ZapZu's code hohoho
//	#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define dfs_black 1
#define dfs_white -1
#define pr pair
#define vt vector
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef double db;
typedef long long li;
typedef long double ld;

typedef pr<int, int> ii;
typedef pr<ld,ld> dd;

typedef vt<int> vi;
typedef vt<li> vli;
typedef vt<ld> vld;
typedef vt<ii> vii;

typedef map<int, int> mii;
typedef map<int, bool> mib;
typedef map<int, char> mic;

typedef set<int> s_i;
typedef set<char> s_c;

const int MOD = 1e9+7;
const li INF = 1e18;
const ld PI = 4*atan((ld)1);
vi v[2];
signed main()
{
//	freopen(".inp", "r", stdin);
//	freopen(".out", "w", stdout);
	int n, k;
	cin>>n>>k;
	for(int i=1; i<=n; i++)
	{
		int temp;
		cin>>temp;
		if(temp<0) v[0].eb(-temp);
		else v[1].eb(temp);
	}
	for(int i=0; i<2; i++)
	{
		v[i].eb(0);
		sort(begin(v[i]), end(v[i]));
	}
	int ans=INT_MAX;
	for(int i=0; i<=k; i++)
	{
		int j=k-i;
		if(v[0].size()<=i or v[1].size()<=j) continue;
		ans=min(ans, v[0][i]+v[1][j]+min(v[0][i],  v[1][j]));
	}
	cout<<ans<<endl;
}




Measured memory_bytes: 1020
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    int n,a = 0;
    char buf[30];

    fgets(buf, sizeof(buf), stdin);

    n = atoi(buf);

    if (n>=1 & n<=10)

        a = n + (n*n) + (n*n*n);

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

Measured memory_bytes: 1704
(defvar x (read))
(defvar y (read))
(defvar A (read))
(defvar B (read))
(defvar C (read))

(defvar  p (loop repeat A collect (read)))
(defvar  q (loop repeat B collect (read)))
(defvar  r (loop repeat C collect (read)))

(setf r (sort r #'>))

(defvar pq (sort (nconc 
                  (nthcdr (- A x)  (sort p #'<))
                  (nthcdr (- B y)  (sort q #'<))
                  ) #'<))


(princ (loop repeat (+ x y)
             sum (max (or (car r) 0) (car pq))
             do (setf  r (cdr r))
             (setf  pq (cdr pq))
            ))



Measured memory_bytes: 63912
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
 
int main(){
    int N;
    cin >> N;
    int A[100000];
    for(int i=0;i<N;i++)
        cin >> A[i];

    if(N == 1){
        if(A[0] == 0)
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return 0;
    }

    int B[100000], i;
    if(N%2 == 0){
        B[0] = 1;
        B[1] = 1;
        i = 3;
        for(int j=2;j<N;j+=2, i+=2)
            B[j] = B[j+1] = i;
    }else{
        B[0] = 0;
        i = 2;
        for(int j=1;j<N;j+=2, i+=2)
            B[j] = B[j+1] = i;
    }
    // 昇順ソート
    sort(A, A + N);
    sort(B, B + N);
    for(int i=0;i<N;i++){
        if(A[i] != B[i]){
            cout << 0 << endl;
            return 0;
        }
    }

    ll ans = 1;
    for(int i=0;i<N/2;i++)
        ans = (ans*2) % MOD;
    
    cout << ans << endl;


}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main {
    
    public static void main (String[] args){
        
        Main main = new Main ();
        
        Scanner sc = new Scanner (System.in);
        
        int N = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();
        
        if(N*A>B){
            System.out.println(B);
        } else {
            System.out.println(N*A);
        }
    }
}

Measured memory_bytes: 22740
#include <bits/stdc++.h>
#define MOD 1000000007
#define MAX 55

using namespace std;
typedef long long ll;

int n;
ll dp[MAX];
char s1[MAX], s2[MAX];

int main() {
  scanf("%d%s%s", &n, s1, s2);

  int i = 0;
  vector<int> v;
  while(i < n)
    if(s1[i] == s2[i]) v.push_back(1), i += 1;
    else               v.push_back(2), i += 2;

  if(v[0] == 1) dp[0] = 3;
  else          dp[0] = 6;

  for(int i = 1; i < v.size(); i++) {
    if(v[i] == 1 && v[i-1] == 1) dp[i] = (dp[i-1] * 2) % MOD;
    if(v[i] == 1 && v[i-1] == 2) dp[i] = dp[i-1];

    if(v[i] == 2 && v[i-1] == 1) dp[i] = (dp[i-1] * 2) % MOD;
    if(v[i] == 2 && v[i-1] == 2) dp[i] = (dp[i-1] * 3) % MOD;
  }

  printf("%lld\n", dp[v.size()-1]);
}

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

struct Card{
	char a;
	int b;
};

bool compare_as_ints(Card i,Card j){
	return (i.b<j.b);
}

int partition(Card A[],int p,int r){
	Card x=A[r];
	int i=p-1;
	
	for(int j=p;j<=r-1;j++){
		if(A[j].b<=x.b){
			i++;	
			swap(A[i],A[j]);
		}
	}

	swap(A[i+1],A[r]);

	return i+1;
}

void quickSort(Card A[],int p,int r){
	if(p<r){
		int q=partition(A,p,r);
		quickSort(A,p,q-1);
		quickSort(A,q+1,r);
	}
}

int main(){
	int n;
	cin>>n;
	
	Card A[100000],B[100000];
	for(int i=0;i<n;i++){
		cin>>A[i].a>>A[i].b;
		B[i]=A[i];
	}
	
	quickSort(A,0,n-1);
	stable_sort(B,B+n,compare_as_ints);

	for(int i=0;i<n;i++){
		if(A[i].a!=B[i].a){
			cout<<"Not stable"<<endl;
			break;
		}
		if(i==n-1){
			cout<<"Stable"<<endl;
		}
	}
	
	for(int i=0;i<n;i++){
		cout<<A[i].a<<' '<<A[i].b<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 4708
#include <iostream>


class Dice {
    public:
        int label[7];
        Dice() {};
        void turn_dice(char c) {
           
            if(c == 'S') {
               int w = label[5];
               label[5] = label[6];
               label[6] = label[2];
               label[2] = label[1];
               label[1] = w;
            }
            else if(c == 'E') {
                int w = label[4];
                label[4] = label[6];
                label[6] = label[3];
                label[3] = label[1];
                label[1] = w;
            }
            else if(c == 'N') {
                int w = label[2];
                label[2] = label[6];
                label[6] = label[5];
                label[5] = label[1];
                label[1] = w;
            }
            else if(c == 'W') {
                int w = label[3];
                label[3] = label[6];
                label[6] = label[4];
                label[4] = label[1];
                label[1] = w;
            }
        };
};

int main() {
    Dice dice1;
    char s[102];
    for(int i = 1; i <= 6; i++) {
       std::cin >> dice1.label[i];
    }
    std::cin >> s;
    for(int j = 0; s[j] != '\0'; j++) {
        dice1.turn_dice(s[j]);
    }
    std::cout << dice1.label[1] << std::endl;

    return 0;
}


Measured memory_bytes: 3096
#include "bits/stdc++.h"
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
#define pb push_back
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
typedef long long ll;
const int inf = 1000000001;
const ll INF = 1e18 * 4;
using namespace std;

int main(){
    int N; cin >> N;
    string s; cin >> s;
    unordered_map<char, int> D;
    D['R'] = 0;
    D['G'] = 1;
    D['B'] = 2;
    vii d(3, vi());
    set<int> count[3];
    rep(i, 0, N){
        d[D[s[i]]].pb(i);
        count[D[s[i]]].insert(i);
    }
    ll cnt = 0;
    rep(i, 0, N){
        rep(j, 0, N){
            char targ;
            if(i >= j) continue;
            if(s[i] == s[j]) continue;
            if(s[i] == 'R' && s[j] == 'G') targ = 'B';
            if(s[i] == 'R' && s[j] == 'B') targ = 'G';
            if(s[i] == 'G' && s[j] == 'R') targ = 'B';
            if(s[i] == 'G' && s[j] == 'B') targ = 'R';
            if(s[i] == 'B' && s[j] == 'R') targ = 'G';
            if(s[i] == 'B' && s[j] == 'G') targ = 'R';
            vi v = d[D[targ]];
            auto ix = distance(v.begin(), lower_bound(v.begin(), v.end(), j+1));
            cnt += (v.size() - ix);
            if(count[D[targ]].find(2*j - i) != count[D[targ]].end()){
                cnt -= 1;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 3824
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    string s;
    cin >> s;
    ll p=0;
    for (ll i=0;i<s.size();i++){
        p+=(s[i]-'0');
        p%=9;
    }
    if (p){
        cout << "No" << endl; 
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}


Measured memory_bytes: 3752
#include<stdio.h>
#include<string.h>

typedef struct{
    int kind;
    int f;
    char c;
}query;

typedef struct{
    char mbuf[200000];
    int size;
}buffer;

int main(void){
    char i_s[100001];
    scanf("%s",i_s);
    int q_n;
    scanf("%d",&q_n);
    query q[q_n];
    buffer f,b;
    f.size = 0;
    b.size = 0;
    buffer *tf,*tb;
    tf = &f;
    tb = &b;
    for(int i = 0;i < q_n;i++){
        scanf("%d",&q[i].kind);
        if(q[i].kind == 2)scanf("%d %c",&q[i].f,&q[i].c);
    }
    for(int i = 0;i < q_n;i++){
        if(q[i].kind == 1){
            buffer *tmp = tf;
            tf = tb;
            tb = tmp;
            continue;
        }
        if(q[i].f == 1){
            tf->size++;
            tf->mbuf[tf->size-1] = q[i].c;
        }
        else {
            tb->size++;
            tb->mbuf[tb->size-1] = q[i].c;
        }
    }
    for(int i = tf->size-1;i >= 0;i--)printf("%c",tf->mbuf[i]);
    if(tf == &b)for(int i = strlen(i_s)-1;i >= 0;i--)putchar(i_s[i]);
    else printf("%s",i_s);
    for(int i = 0;i < tb->size;i++)printf("%c",tb->mbuf[i]);
    return 0;
}

Measured memory_bytes: 3072
# -*- coding: utf-8 -*-

"""
参考：http://at274.hatenablog.com/entry/2018/02/02/173000
・Union-Find木
"""

class UnionFind:
    def __init__(self, n):
        # 親要素のノード番号を格納。par[x] == xの時そのノードは根
        # 1-indexedのままでOK、その場合は[0]は未使用
        self.par = [i for i in range(n+1)]
        # 木の高さを格納する（初期状態では0）
        self.rank = [0] * (n+1)

    # 検索
    def find(self, x):
        # 根ならその番号を返す
        if self.par[x] == x:
            return x
        else:
            # 走査していく過程で親を書き換える
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    # 併合
    def union(self, x, y):
        # 根を探す
        x = self.find(x)
        y = self.find(y)
        # 木の高さを比較し、低いほうから高いほうに辺を張る
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            # 木の高さが同じなら片方を1増やす
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    # 同じ集合に属するか判定
    def same_check(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
pN = list(map(int, input().split()))
uf = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    uf.union(x, y)

cnt = 0
for i in range(N):
    if uf.same_check(pN[i], i+1):
        cnt += 1
print(cnt)


Measured memory_bytes: 13812
#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;
  map<int,int> cnt;
  rep(i,N){
    int a;
    cin >> a;
    cnt[a]++;
  }

  if(cnt.size() == N) cout << "YES" << endl;
  else cout << "NO" << endl;
  
  return 0;
}


Measured memory_bytes: 12980
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include<string>
#include <stack>
#include<queue>
#include<map>
#include <stdlib.h>
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {

	int n;
	cin>>n;
	ll a;
	set<ll>s;
	for(int i=0;i<n;i++){
		cin>>a;
		if(s.count(a)){
			s.erase(a);
		}else{
			s.insert(a);
		}
	}
	cout<<s.size()<<endl;
	return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

    vector<int> v;
    for(int i = 1; i <= W; ++i) v.push_back(i);
    while(N--) {
        int a, b;
        char c;
        cin >> a >> c >> b;
        swap(v[a-1], v[b-1]);
    }
    for(int i = 0; i < v.size(); ++i) cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int x,y;
  cin>>x>>y;
  int fibo[50];
  fibo[0]=1,fibo[1]=1;
  repi(i,2,50) fibo[i]=fibo[i-1]+fibo[i-2];
  int l=0,r=0,u=0,d=0;
  int color=1,cnt=0;
  while(!(x<=r && x>=l && y<=u && y>=d)){
    if(cnt%4==0){
      r+=fibo[color];
    }
    if(cnt%4==1){
      u+=fibo[color];
    }
    if(cnt%4==2){
      l-=fibo[color];
    }
    if(cnt%4==3){
      d-=fibo[color];
    }
    color++;
    cnt++;
  }
  cout<<1+(color-1)%3<<endl;
  return 0;
}


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

#define ll long long
#define ull unsigned long long
#define pb push_back
#define pf push_front
#define pof pop_front
#define pob pop_back
#define mp make_pair
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(s) s.begin(),s.end()
#define vll vector<ll>
#define vi vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define vd vector<double>
#define vull vector<ull>
#define vc vector<char>
#define vs vector<string>
#define fi first
#define se second
#define sz(x) x.size()
#define cinarr(n,a) for(int i = 0; i < n; i++) cin >> a[i];
#define coutarr(n,a) for(int i = 0; i < n; i++) cout << a[i] << (i+1==n?'\n':' ');
#define fori(i,a,b,x) for(int i = a; i <= b; i+=x)
#define ford(i,a,b,x) for(int i = a; i >= b; i-=x)
#define tc int tt; cin >> tt; for(int cs = 1; cs <= tt; cs++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(NULL);
#define ld long double
#define reset(x,y) memset(x,y,sizeof x);
#define sqr(x) 1LL*(x)*(x)
#define cube(x) 1LL*(x)*(x)*(x)
#define ub(v, a) upper_bound(all(v), a)
#define lb(v, a) lower_bound(all(v), a)
#define EPS 1e-10
#define INF 2000000000
#define mod 1000000007
#define minof(a) min_element(all(a))
#define maxof(a) max_element(all(a))
#define debug(val) cerr << "The value of " << #val << " is = " << val << endl;
#define testing cerr << "--------------------------\n";

int main() {
	IOS
	int n;
	cin>>n;
	ll a[n+5];
	for(int i = 0; i < n; i++) {
		cin>>a[i];
	}
	ll res=0;
	for(ll i = 0; i < 60; i++) {
		ll c0=0,c1=0;
		for(int j = 0; j < n; j++) {
			if(a[j] & (1LL<<i)) {
				c1++;
			} else {
				c0++;
			}
		}
		res=(res+c1*c0%mod*((1LL<<i)%mod))%mod;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 5964
def getprime(n):
    if not isinstance(n, int):
        raise TypeError("Input int")
    if n < 2:
        raise ValueError("N >= 2")
    prime = []
    # 約数はsqrt(N)まで調べればOK
    data = [i+1 for i in range(1,n)]
    while True:
        p = data[0]
        if p >= int(n**0.5):
            return prime+data
        prime.append(p)
        # pで割り切れないものだけを残す
        data = [d for d in data if d%p != 0]

X = int(input())
ps = getprime(X*2)
print(min([p for p in ps if p >= X]))

Measured memory_bytes: 11800
#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() {
    int x;
    cin >> x;
    int ans = 0;
    rep(a, 100) {
        int sa = x;
        sa -= a * 101;
        if (sa < 0) continue;
        rep(b, 50) {
            int sb = sa - b * 102;
            if (sb < 0) break;
            rep(c, 34) {
                int sc = sb - c * 103;
                if (sc < 0) break;
                rep(d, 25) {
                    int sd = sc - d * 104;
                    if (sd < 0) break;
                    rep(e, 20) {
                        int se = sd - e * 105;
                        if (se < 0) break;
                        if (se%100 == 0) ans = 1;
                    }
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3632
#print#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
from collections import Counter
def resolve():
    N,=pin()
    A=lispin()
    temp=0
    cnt=0
    for i in range(1,N):
        if A[i]<=A[i-1]:
            #print(i)
            cnt+=1
        else:
            temp=max(temp,cnt)
            cnt=0
    print(max(temp,cnt))
    #print(A,B,C)


#%%submit!
resolve()


Measured memory_bytes: 63984
local mfl, mce, mmi = math.floor, math.ceil, math.min
local SegTree = {}
SegTree.updateAll = function(self)
  for i = self.stagenum - 1, 1, -1 do
    for j = 1, self.cnt[i] do
      self.stage[i][j] = false
    end
  end
end
SegTree.create = function(self, n)
  local stagenum, mul = 1, 1
  self.cnt, self.stage, self.size = {1}, {{}}, {}
  while mul < n do
    mul, stagenum = mul * 2, stagenum + 1
    self.cnt[stagenum], self.stage[stagenum] = mul, {}
  end
  for i = 1, stagenum do self.size[i] = self.cnt[stagenum + 1 - i] end
  self.stagenum = stagenum
  for i = 1, mul do self.stage[stagenum][i] = false end
  self:updateAll()
end
SegTree.getRange = function(self, left, right)
  if left == right then return self.stage[self.stagenum][left] end
  local start_stage = 1
  while right - left + 1 < self.size[start_stage] do
    start_stage = start_stage + 1
  end
  local ret = false
  local t1, t2, t3 = {start_stage}, {left}, {right}
  while 0 < #t1 do
    local stage, l, r = t1[#t1], t2[#t1], t3[#t1]
    table.remove(t1) table.remove(t2) table.remove(t3)
    local sz = self.size[stage]
    if (l - 1) % sz ~= 0 then
      local newr = mmi(r, mce((l - 1) / sz) * sz)
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, newr)
      l = newr + 1
    end
    if sz <= r + 1 - l then
      ret = ret or self.stage[stage][mce(l / sz)]
      l = l + sz
    end
    if l <= r then
      table.insert(t1, stage + 1) table.insert(t2, l) table.insert(t3, r)
    end
    if ret then break end
  end
  return ret
end
SegTree.setValue = function(self, idx, value)
  self.stage[self.stagenum][idx] = value
  for i = self.stagenum - 1, 1, -1 do
    local dst = mce(idx / 2)
    local rem = dst * 4 - 1 - idx
    self.stage[i][dst] = self.stage[i + 1][idx] or self.stage[i + 1][rem]
    idx = dst
  end
end
SegTree.new = function(n, func, emptyvalue)
  local obj = {}
  setmetatable(obj, {__index = SegTree})
  obj:create(n, func, emptyvalue)
  return obj
end

local n = io.read("*n", "*l")
local s = io.read()
local q = io.read("*n", "*l")
local sts = {}
local t = {}
for i = 1, 26 do
  sts[i] = SegTree.new(n, function(a, b) return a or b end, false)
end
for i = 1, n do
  t[i] = s:sub(i, i):byte() - 96
  sts[t[i]]:setValue(i, true)
end

for iq = 1, q do
  local iqstr = io.read()
  local ic = iqstr:sub(1, 1)
  if ic == "1" then
    local i, cs = iqstr:match("%d (%d+) (%w)")
    i = tonumber(i)
    local c = cs:byte() - 96
    if t[i] ~= c then
      sts[t[i]]:setValue(i, false)
      t[i] = c
      sts[c]:setValue(i, true)
    end
  else
    local l, r = iqstr:match("%d (%d+) (%d+)")
    l, r = tonumber(l), tonumber(r)
    local cnt = 0
    for i = 1, 26 do
      if sts[i]:getRange(l, r) then cnt = cnt + 1 end
    end
    print(cnt)
  end
end


Measured memory_bytes: 317420
import java.io.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();        
        long N = r.l();
      	long[] capa = r.ll(5);
      	long[] city = new long[6];
      	city[0] = N;
      	long time;
        int minIdx = minIdx(capa);
        time = 5 + (N-1)/capa[minIdx];   
        print(time);
    }
    public static int minIdx(long[] capa){
        int idx = 0;
        long min = capa[0];
        for(int i = 1; i < 5; i++){
            if(capa[i] < min){
                min = capa[i];
                idx = i;
            }
        }
        return idx;
    }
    static void print(String s){
        System.out.println(s);
    }
    static void print(int i){
        System.out.println(i);
    }
    static void print(double d){
        System.out.println(d);
    }
    static void print(long l){
        System.out.println(l);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }
        String s() throws IOException{
            return readLine();
        }
        String[] ss() throws IOException{
            return readLine().split(" ");
        }
        int i() throws IOException{
            return Integer.parseInt(readLine());
        }
        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++){
                ii[j] = Integer.parseInt(ss[j]);
            }
            return ii;
        }
        int[] ii(int N) throws IOException{
            int[] ii = new int[N];
            for(int j = 0; j < N; j++){
                ii[j] = i();
            }
            return ii;
        }
        long l() throws IOException{
            return Long.parseLong(readLine());
        }
        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++){
                ll[j] = Long.parseLong(ss[j]);
            }
            return ll;
        }
        long[] ll(int N) throws IOException{
            long[] ll = new long[N];
            for(int j = 0; j < N; j++){
                ll[j] = l();
            }
            return ll;
        }
    }
}

Measured memory_bytes: 22996
fun main(){
    var (a,b,c,k) =readLine()!!.split(" ").map{it.toInt()}
    var res = 0
    var remain = k
    while(remain > 0) {
        if (a > 0) {
            res++
            remain--
            a--
        } else if (b > 0) {
            remain--
            b--
        } else if (c > 0) {
            remain--
            c--
            res--
        }
    }
    println(res)
}

Measured memory_bytes: 36868
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
const int MAX_W=20;
const int DIRECTIONS=4;//0:up/1:right/2:down/3:left
const int MAX_DEPTH=10;
const int INF=1<<27;

struct tpl{
  int ary[MAX_W][MAX_W];
  int depth;
  int last;
  int x;
  int y;
};

int w,h;
int dfs(const tpl& t){
  int minDepth=INF;
  if(t.depth+1>MAX_DEPTH)return minDepth;
  REP(i,DIRECTIONS){
    tpl u;
    u.depth=t.depth+1;
    u.last=i;
    REP(j,h)REP(k,w)u.ary[j][k]=t.ary[j][k];
    u.x=t.x;
    u.y=t.y;
    if(i==0&&u.y>0&&u.ary[u.y-1][u.x]!=1){
      for(;u.y>=0;u.y--){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.y>0&&u.ary[u.y-1][u.x]==1){
	  u.ary[u.y-1][u.x]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }else if(i==1&&u.x<w-1&&u.ary[u.y][u.x+1]!=1){
      for(;u.x<=w-1;u.x++){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.x<w-1&&u.ary[u.y][u.x+1]==1){
	  u.ary[u.y][u.x+1]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }else if(i==2&&u.y<h-1&&u.ary[u.y+1][u.x]!=1){
      for(;u.y<=h-1;u.y++){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.y<h-1&&u.ary[u.y+1][u.x]==1){
	  u.ary[u.y+1][u.x]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }else if(i==3&&u.x>0&&u.ary[u.y][u.x-1]!=1){
      for(;u.x>=0;u.x--){
	if(u.ary[u.y][u.x]==3){
	  minDepth=min(minDepth,u.depth);
	  break;
	}else if(u.x>0&&u.ary[u.y][u.x-1]==1){
	  u.ary[u.y][u.x-1]=0;
	  minDepth=min(minDepth,dfs(u));
	  break;
	}
      }
    }
  }
  return minDepth;
}

void solve(const tpl& t){
  int result=dfs(t);
  cout<<(result==INF?-1:result)<<endl;
}
int main(){ _;
  while(cin>>w>>h,(w|h)!=0){
    tpl t;
    t.depth=0;
    t.last=-1;
    REP(i,h)REP(j,w){
      cin>>t.ary[i][j];
      if(t.ary[i][j]==2){
	t.ary[i][j]=0;
	t.x=j;
	t.y=i;
      }
    }
    solve(t);
  }
}

Measured memory_bytes: 1208
from collections import deque
s = deque(input())
n = len(s)

temp = [0]*2019
t = 1
num = 0
for i in range(n):
    num += int(s.pop())*t 
    temp[num % 2019] += 1
    t = t*10 % 2019 

ans = temp[0]
for t in temp:
    if t > 1:
        ans += t*(t-1)/2

print(int(ans))

Measured memory_bytes: 10920
#include<string>
#include<vector>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<sstream>
#include<functional>
#include<map>
#include<set>
#include<cmath>

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

using namespace std;

int main(){

	string s,s1;
	int n;

	cin >> s;
	cin >> n;

	int c=0;
	rep(i,n){
	cin >> s1;

	string s2=s1+s1;

	string::size_type pos;
	pos=s2.find(s);
	if(pos!=string::npos) c++;

	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 1212
N = int(input())
A = [0] * N
for i in range(N):
    A[i] = int(input())
tmp = sorted(A)
m1 = tmp[-1]
m2 = tmp[-2]
for i in range(N):
    if A[i] != m1:
        print(m1)
    else:
        print(m2)


Measured memory_bytes: 14096
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll k,a,b;
cin >> k >> a >> b;
if(a + 1 >= b){
    cout << 1 + k << endl;
    return 0;
}
ll biscuits = 1;
 k -= (a - 1);
 biscuits += (a - 1);
 ll cycle = k / 2;
 biscuits += cycle * (b - a);
 if(k % 2 != 0){
     biscuits++;
 }
 cout << biscuits << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
using namespace std;

int main(){
  int N=0;
  long long int tmp=0ll, l=2ll, l_next=1ll; 
  cin >> N;
  
  for(int i=1; i<N; i++){
    tmp = l_next;
    l_next += l;
    l = tmp;
  }
  cout << l_next << endl;
  return 0;
}



Measured memory_bytes: 256
//#pragma comment(linker, "/STACK:102400000,102400000")
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <cassert>
//#include <unordered_map>
//#include <unordered_set>
using namespace std;

typedef long long ll;
#define eps 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int dx4[5] = { 0,-1,0,1,0 };
const int dy4[5] = { 0,0,1,0,-1 };
const int dx8[9] = { 0,-1,0,1,0,1,1,-1,-1 };
const int dy8[9] = { 0,0,1,0,-1,1,-1,1,-1 };
const int maxn = 1e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b, ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a, ll b) { if (a == 0) { return b; } else { return gcd(b%a, a); } }
void YES() { puts("YES"); exit(0); }
void Yes() { puts("Yes"); exit(0); }
void NO() { puts("NO"); exit(0); }
void No() { puts("No"); exit(0); }
void one() { puts("-1"); exit(0); }

int n, c, k;
int t[maxn];

void solve()
{
	sa(n), sa(c), sa(k);
	repp(i, 1, n)
	{
		sa(t[i]);
	}
	sort(t + 1, t + n + 1);
	
	int cnt = 0;
	int ans = 0;
	int ti = -1;

	repp(i, 1, n)
	{
		if (ti == -1)
		{
			ti = t[i];
		}
		cnt++;
		if (cnt > c || t[i] > ti + k)
		{
			ans++;
			cnt = 1;
			ti = t[i];
		}

	}
	if(cnt)ans++;
	printf("%d\n", ans);
}

int main()
{
	solve();
	//system("pause");
	return 0;
}

Measured memory_bytes: 640
n=int(input())
s=[]
for i in range(n):
    s.append(input())
total=True
for i in range(n-1):
    if s[i][-1]!=s[i+1][0]:
        total=False
        break
    for j in range(len(s)):
        if i!=j:
            if s[i]==s[j]:
                total=False
                break
    if total==False:
        break
if total==False:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 9148
#include <algorithm>
#include <iostream>
#include <map>
#include <vector>

int main() {
    int N, K;
    std::cin >> N >> K;

    std::map<int, int> m;
    int a;
    for (int i = 0; i < N; ++i) {
        std::cin >> a;
        ++m[a];
    }

    int ret = 0;
    const int size = static_cast<int>(m.size());
    if (size > K) {
        std::vector<int> v;
        v.reserve(N);
        for (const auto& iPair : m) {
            v.push_back(iPair.second);
        }
        std::sort(v.begin(), v.end());

        const int num = size - K;
        for (int i = 0; i < num; ++i) {
            ret += v[i];
        }
    }

    std::cout << ret << std::endl;
}


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

typedef long long ll;
#define PB push_back

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	ll k, n; cin >> k >> n;
	vector<ll> houses;
	for (ll i = 0; i < n; i++) {
		ll a; cin >> a;
		houses.PB(a);
	}
	
	ll gap = k - houses[n - 1] + houses[0];
	ll cw = 0, m = 0, idx;
	for (ll i = 1; i < n; i++) {
		ll d = houses[i] - houses[i - 1];
		cw += d;
		if (d > m) {
			m = d;
			idx = i - 1;
		}
	}
	ll ccw = 0;
	for (ll i = idx; i > 0; i--) {
		ccw += houses[i] - houses[i - 1];
	}
	for (ll i = n - 1; i > idx + 1; i--) {
		ccw += houses[i] - houses[i - 1];
	}
	ccw += gap;
	 
	ll res = min(cw, ccw);
	cout << res;
}


Measured memory_bytes: 2420
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
using namespace std;

#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define ldb ldouble

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 18;
int MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;
#define szz(x) (int)(x).size()
#define rep(i, n) for(int i=0;i<n;i++)
#define Se second
#define Fi first

const int MX = 205;
const int MM = 1000000007;

int D[MX];
int N;
vector<int> L;

void rot(int k){
	L.push_back(k);
	for(int i=k;i<N;i++)
		swap(D[i],D[i-k]);
}

int main()
{
	scanf("%d", &N);
	for(int i = 0; i < N; i++) scanf("%d", D+i);
	for(int i = 1; i <= N; i++){
		rot(1);
		for(int j = 1; j < N; j++){
			if(D[0] < D[N-1]) rot(N-1);
			rot(1);
		}
	}
	printf("%d\n", L.size());
	for(int c : L) printf("%d\n", c);
}


Measured memory_bytes: 764