akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

const int N = 2e5 + 9;
const int INF = 1e18 + 239;

int fdp[N];
int sdp[N];
int tdp[N];

int rc(int x) {
	if (x == 0) return 2;
	else return x % 2;
}

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

	int n;
	cin >> n;
	vector<int> a(n);
	for (auto &t : a) {
		cin >> t;
	}
	{	
		int ps = 0;
		for (int i = 0; i < n; i++) {
			ps += a[i];
			fdp[i + 1] = min(fdp[i] + rc(a[i]), ps);
		}
	}
	{
		int ps = 0;
		for (int i = n - 1; i >= 0; i--) {
			ps += a[i];
			sdp[i] = min(sdp[i + 1] + rc(a[i]), ps); 
		}
	}
	{
		for (int i = n - 1; i >= 0; i--) {
			tdp[i] = sdp[i];
			tdp[i] = min(tdp[i], (!(a[i] % 2)) + tdp[i + 1]);
		}
	}
	int ans = INF;
	for (int i = 0; i <= n; i++) {
		ans = min(ans, fdp[i] + tdp[i]);
	}
	cout << ans << endl;
}


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

using namespace std;


int main(){
    int n,k;
    int temp;
    int mask = 0;
    scanf("%d",&n);
    scanf("%d",&k);

    for(int i = 0;i < k;i++){
        scanf("%d",&temp);
        mask |= (1 << temp);
    }

    for(int i = 0; i < (1 << n);i++){
        if((i | mask)  == mask){
            printf("%d:",i);
            for(int j = 0;j < n;j++){
                if( i&(1<<j) ) printf(" %d",j);
            }
            printf("\n");
        } 
    }
    
    return 0;   
}



Measured memory_bytes: 3236
#!/usr/bin/env python3

from pprint import pprint
from collections import deque, defaultdict
import itertools
import math
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.buffer.readline
INF = float('inf')


N, Q = map(int, input().split())
tree = [[] for _ in range(N)]
for _ in range(N-1):
    u, v = map(int, input().split())
    tree[u-1].append(v-1)
    tree[v-1].append(u-1)
# pprint(tree)
queries = []
for _ in range(Q):
    p, x = map(int, input().split())
    queries.append([p-1, x])

counters = [0] * N
for p, x in queries:
    counters[p] += x
# print(counters)


def dfs(dist, v):
    for v_adj in tree[v]:
        if dist[v_adj] == -1:
            dist[v_adj] = 1
            counters[v_adj] += counters[v]
            dfs(dist, v_adj)


dist = [-1] * N
dist[0] = 1
# print(counters)
dfs(dist, 0)
print(*counters)


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


def solve(N: int, M: int, A: "List[int]"):
    from collections import defaultdict
    acc = [0] * (N+1)
    for i, a in enumerate(A, 1):
        acc[i] = (acc[i-1] + a) % M
    dp = defaultdict(int)        
    ans = 0
    for a in acc:
        ans += dp[a]
        dp[a] += 1
    return ans

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    print(solve(N, M, A))

if __name__ == '__main__':
    main()


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

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

int A[50];
int B[50];
  for (int i=0;i<M; i++){
  cin >>A[i] >> B[i];
  }
  
int num[50]={0};
  for (int i=0; i<M; i++){
   num [A[i]] ++;
    num [B[i]] ++ ;
  }

  for (int i=1; i<=N; i++){
  cout << num[i] << endl;  
  }
}


Measured memory_bytes: 256
def main():
    n = int(input())
    b = list(map(int, input().split()))
    ans = []
    f = True
    for i in reversed(range(n)):
        F = True
        for j in reversed(range(i+1)):
            if b[j] == j+1:
                ans.append(b.pop(j))
                F = False
                break
        if F:
            f = False
            break
    if f:
        for v in reversed(ans):
            print(v)
    else:
        print(-1)

if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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 long long mod = 1000000007;
typedef long long ll;

int n,h;
string s,t;

int main() {
  cin >> s;
  if(s.size()<26){
    for(char c='a';c<='z';c++)if(!count(all(s),c)){
      cout << s+c << endl;
      return 0;
    }
  }else{
    bool ok=false;
    rep(i,s.size()-1)if(s[i]<s[i+1]) ok=true; 
    if(!ok)
    cout << -1 << endl;
    else{
      string t=s;
      next_permutation(all(s));
      rep(i,s.size()){
        cout << s[i];
        if(s[i]!=t[i]) break;
      }
        cout << endl;
    }
  }
}

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

int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  
  if (op[0] == '+') {
    cout << (a + b) << "\n";
  } else {
    cout << (a - b) << "\n";
  }
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<iostream>
#include <iomanip>
#include<queue>
#include<algorithm>
#include <functional>
#include<vector>
using namespace std;

int N;
const int N_MAX = 51;
int V[N_MAX];
int C[N_MAX];
int ans = 0;
int sum;


int main() {
	cin >> N;
	for (int i = 0; i < N; i++) cin >> V[i];
	for (int i = 0; i < N; i++) cin >> C[i];

	for (int bit = 0; bit < (1 << N); bit++) {
		sum = 0;
		for (int i = 0; i < N; i++) {
			if (bit & (1 << i)) {
				sum += V[i]-C[i];
			}
		}
		ans = max(ans, sum);
	}

	cout << ans << endl;
}

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


int main(){

	string s1, s2;
	cin >> s1 >> s2;
	int n = s1.length(), m = s2.length();

	int dp[n + 1][m + 1];

	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= m; j++){
			if(!i || !j) dp[i][j] = 0;
			else if(s1[i - 1] == s2[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	//for printing the subsequece :8(
	int l = dp[n][m];
	char temp[l + 1];
	temp[l] = '\0';
	int row = n, col = m;
	while(row && col){
		if(s1[row - 1] == s2[col - 1]){
			temp[--l] = s1[row - 1];
			row--;
			col--;
			
		}else if(dp[row - 1][col] > dp[row][col - 1]){
			row--;
		}else{
			col--;
		}
	}
	cout << temp; 

	
	
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

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

void Main() {
    ll K;
    cin >> K;
    ll ans = 0;
    rep2(i, 1, K + 1) {
        rep2(j, 1, K + 1) {
            rep2(k, 1, K + 1) {
                ans += gcd(gcd(i, j), k);
            }
        }
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


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

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while (true) {
			String str[] = br.readLine().split(" ");
			int n = Integer.parseInt(str[0]);
			int l = Integer.parseInt(str[1]);
			int r = Integer.parseInt(str[2]);

			if (n == 0) {
				break;
			}

			int a[] = new int[n];

			for (int i = 0; i < n; i++) {
				a[i] = Integer.parseInt(br.readLine());
			}

			int ans = 0;

			for (int i = l; i <= r; i++) {
				boolean flag = false; // そのような i が存在しないとき

				for (int j = 0; j < n; j++) {
					if (i % a[j] == 0) {
						flag = true;
						if ((j + 1) % 2 != 0) {
							ans++;
						}
						break;
					}
				}
				if (!flag) {
					if (n % 2 == 0) {
						ans++;
					}
				}
			}

			System.out.println(ans);
		}
	}
}



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

int main() {
  long long n,m;
  cin>>n>>m;
  long long test=m/2-n;
  if(test<=0){
    cout<<min(n,m/2)<< endl;
    return 0;
  }
  else{
    while(test>1){
      if(test==1){
        break;
      }
      test-=2;
      n++;
    }
  }
  cout<<n<< endl;
}


Measured memory_bytes: 256
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vs=vector<string>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll mno=1007;

int main() {
    
    int h, w;
    cin >> h >> w;
    vs grids(h);
    for(int i = 0; i < h; ++i) {
        cin >> grids[i];
    }
    vvi memo(h, vi(w));
    memo[0][0] = (int)(grids[0][0] == '#');
    for(int j = 1; j < w; ++j) {
        memo[0][j] = memo[0][j-1];
        if(grids[0][j] == '#' && grids[0][j-1] == '.') {
            memo[0][j]++;
        }
    }
    for (int i = 1; i < h; i++) {
        memo[i][0] = memo[i-1][0];
        if (grids[i][0] == '#' && grids[i-1][0] == '.') memo[i][0]++;
    }
    for (int i = 1; i < h; i++) {
        for (int j = 1; j < w; j++) {
            int t1 = memo[i][j-1];
            if (grids[i][j] == '#' && grids[i][j-1] == '.') t1++;
            int t2 = memo[i-1][j];
            if (grids[i][j] == '#' && grids[i-1][j] =='.') t2++;
            memo[i][j] = min(t1, t2);
        }
    }
    cout << memo[h-1][w-1] << '\n';
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=300+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
vector<pa>g[N];
ll ans,dp[N][N][N];
int n,m;
int main(){
	read(n,m);
	re(i,0,m){
		int l,r,x;read(l,r,x);
		g[r].pb(pa(l,x));
	}dp[0][0][0]=1;
	rep(i,0,n)rep(j,0,n)rep(k,0,n){
		int r=max(i,max(j,k));
		re(o,0,g[r].size()){
			int c=g[r][o].w1;
			if((i>=c)+(j>=c)+(k>=c)!=g[r][o].w2)dp[i][j][k]=0;
			
		}if(r==n)(ans+=dp[i][j][k])%=mod;else{
			(dp[r+1][j][k]+=dp[i][j][k])%=mod;
			(dp[i][r+1][k]+=dp[i][j][k])%=mod;
			(dp[i][j][r+1]+=dp[i][j][k])%=mod;
		}
	}cout<<ans<<endl;
}

Measured memory_bytes: 219520
import sys
import heapq
def input(): return sys.stdin.readline().rstrip()

def main():
    K = int(input())
    q = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    heapq.heapify(q)
    while len(q) < K:
        K -= len(q)
        new_q = []
        for i in q:
            d1 = int(str(i)[-1])
            if d1 > 0:
                new_q.append(i * 10 + d1 - 1)
            new_q.append(i * 10 + d1)
            if d1 < 9:
                new_q.append(i * 10 + d1 + 1)
        q = new_q
        heapq.heapify(q)
    print(q[K-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 10792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <array>
#include <map>
#include <set>

using namespace std;

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    cout << ((x - a) % b) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int i, j;
    int n, m;
    int a[100][100], b[100];
    int c[100];

    scanf("%d%d", &n, &m);

    for(i = 0; i < n; i++){
        for(j = 0; j < m; j++){
            scanf("%d", &a[i][j]);
        }
    }

    for(j = 0; j < m; j++){
        scanf("%d", &b[j]);
    }

    for(i = 0; i < n; i++){
        c[i] = 0;
        for(j = 0; j < m; j++){
            c[i] += a[i][j] * b[j]; 
        }
        printf("%d", c[i]);
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2148
#include<iostream>
#include<cctype>
using namespace std;
int main(){
	char num, s;
	int a[30], b[1205], x = 0;
	for (int i = 0; i < 26; i++)
		a[i] = 0;
	while (cin >> num){
		if (isalpha(num)){
			if (isupper(num)){
				num = tolower(num);
			}
			b[x] = num - 'a';
			a[b[x]] += 1;
			x += 1;
		}
	}
	for (int i = 0; i < 26; i++){
		s = i + 'a';
		cout << s << " " << ":" << " " << a[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3076
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int X = sc.nextInt();
        int count = 0;
        ArrayList<Integer> L = new ArrayList<>();
        ArrayList<Integer> D = new ArrayList<>();
        D.add(0);

        for (int i = 0; i < N; i++){
            L.add(sc.nextInt());
        }

        for (int i = 1; i < N + 1; i++){
            D.add(D.get(i-1) + L.get(i-1));
        }

        for (int i = 0; i < D.size(); i++){
            if(D.get(i)<=X){
                count++;
            }
        }

        System.out.print(count);
        sc.close();
    }

}

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

int main () {
	int a,b,c,d ;
	d=0;
	scanf ("%d %d %d",&a,&b,&c);
	for (int i =a ; i<=b;i++)
	if (i%c == 0) {
		d++;
	}
	printf("%d",d);

	return 0;
}

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

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

#define minimum(a)					*min_element(a.begin(), a.end())
#define maximum(a)					*max_element(a.begin(), a.end())
#define all(v)                      v.begin(), v.end()
//#define debug(x) cout << '>' << #x << ':' << x << endl;
#define mp make_pair
#define ll   long long
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define MOD 1000000007

vector<list<int> > adj;
vector<bool> visited;
int k;
ll ans;
void dfs(int source){
    int temp;
    if(source == 1){
        ans*= k;
        ans%= MOD;
        temp = k-1;
    }else{
        temp = k-2;
    }
    for(int x : adj[source]){
        if(!visited[x]){
            ans*= temp;
            ans%=MOD;
            temp--;
            visited[x] = true;
            dfs(x);
        }
        
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n>>k;
    ans = 1;
    adj = vector<list<int> >(n+1);
    for(int i = 0; i<n-1; i++){
        int u, v;
        cin>>u>>v;
        adj[u].emplace_back(v);
        adj[v].emplace_back(u);
    }

    visited = vector<bool>(n+1);
    visited[1] = true;
    dfs(1);
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 11648
#include <iostream>
#include <cmath>
#include <vector>
 
using namespace std;
 
struct P
{
int x,y;
};
 
P findpoint(int m,vector<vector<int> > &map){
for(int x=0;x<map.size();x++)
for(int y=0;y<map.size();y++)
if(map[x][y]==m)
return (P){x,y};
return (P){-1,-1};
}
 
P solve(int n,int m,vector<vector<int> > &map,vector<bool> &prime){
P p=findpoint(m, map);
P res={0,0};
vector<vector<int> >dp(map.size(),vector<int>(map.size(),-1));
dp[p.x][p.y]=0;
for(int y=p.y;y<map.size();y++){
for(int x=0;x<map.size();x++){
if(map[x][y]>n)continue;
if(dp[x][y]>=0){
if(prime[map[x][y]-1]){
dp[x][y]++;
if(res.x<dp[x][y]){
res.x=dp[x][y];
res.y=map[x][y];
}else if(res.x==dp[x][y]){
	res.y=max(res.y,map[x][y]);
}
}
if(y==map.size()-1)continue;
for(int i=-1;i<=1;i++){
if(0<=x+i&&x+i<map.size()){
dp[x+i][y+1]=max(dp[x+i][y+1],dp[x][y]);
}
}
}
}
}
return res;
}
 
int main(){
int n,m,ma=-1;
vector<int>N,M;
 
while(cin >> n >> m, n|m){
N.push_back(n);
M.push_back(m);
ma=max(ma, n);
}
 
vector<bool>prime(ma+1,true);
prime[0] = false;
for(int i=2;i<=ma;i++){
if(!prime[i-1])continue;
for(int j=i*2;j<=ma;j+=i)
prime[j-1]=false;
}
int kk=(int)sqrt(ma-1)/2*2;;
int x=0,y=1;
n = m = kk*kk+1;
vector<vector<int> >map(kk+2, vector<int>(kk+2));
map[x][y]=m++;
int k=kk;
while(m<=ma){
for(int i=0;i<k;i++)
map[x][++y]=m++;
k++;
for(int i=0;i<k;i++)
map[++x][y]=m++;
for(int i=0;i<k;i++)
map[x][--y]=m++;
for(int i=0;i<k;i++)
map[--x][y]=m++;
}
x=0;
y=1;
m=n-1;
k=kk;
while(m>0){
for(int i=0;i<k&&m>0;i++)
map[++x][y]=m--;
k--;
for(int i=0;i<k&&m>0;i++)
map[x][++y]=m--;
for(int i=0;i<k&&m>0;i++)
map[--x][y]=m--;
k--;
for(int i=0;i<k&&m>0;i++)
map[x][--y]=m--;
}
 
/*
for(int j=0;j<kk+2;j++){
for(int i=0;i<kk+2;i++)
printf("%2d ",map[i][j]);
cout << endl;
}
*/
 
for(int i=0;i<N.size();i++){
P res=solve(N[i],M[i],map,prime);
cout << res.x << " " << res.y << endl;
}
 
return 0;
}

Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef vector<pii> vii;
typedef vector<pll> vll;
#define fi first
#define se second
#define pi 3.141592653589793
#define mod 998244353
#define pb push_back
#define all(v) v.begin(),v.end()
#define tc int t;cin>>t;while(t--)
#define pqmax priority_queue<int>
#define pqmin priority_queue<int,vi,greater<int>>
#define fast_io ios_base::sync_with_stdio(0), cin.tie(NULL)
#define tc_g int tt;cin>>tt;for(int ti=1;ti<=tt;ti++)
#define case_g "Case #"<<ti<<": "
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, int, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_map;

int main() {
	fast_io;
	ll x;
	cin >> x;
	ll a = 100, ans = 0;
	while (a < x) {
		a = a + a / 100;
		ans++;
	}
	cout << ans << '\n';
}


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

int main() {
   cin.tie(0);
   ios::sync_with_stdio(false);
   int n;
   cin >> n;
   set<char> mp;
   for(int i = 0;i < n;i++) {
      char x;
      cin >> x;
      mp.insert(x);
   }
   if(mp.size() == 3) {
      cout << "Three" << endl;
   } else {
      cout << "Four" << endl;
   }
   return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <utility>
#include <algorithm>
#include <cmath>
#include <climits>
#include <iomanip>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    int x, y, z;
    cin >> x >> y >> z;
    cout << z << " " << x << " " << y << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

ll CS(string ss){
	ll c=0;
	REP(i,ss.size()){
		c+=ll(ss[i]-'0');
	}
	return c;
}

int main(){
	string s;
	ll n,count=0;
	cin>>s;
	n=stoll(s);
	for(int i=1;i<s.size();i++){
		if(s[i]=='9'){
			count++;
		}
	}
	DEB(s)END
	DEB(count)END
	if(s.size()-1==count){
		cout<<CS(s)<<endl;;
	}
	else{
		REP(i,s.size()){
			if(i==0)s[i]-=1;
			else s[i]='9';
		}
		cout<<CS(s)<<endl;
	}
	return 0;
}
//1=7

Measured memory_bytes: 256
import scala.io.StdIn.readLine
case class Stack[T](private val stack: List[T]) {
    def isEmpty(): Boolean = if (stack == Nil) true else false
    def top(n: Int): T = {
        def go(n: Int, s: List[T]): T = s match {
            case x :: xs if n == 0=> x
            case x :: xs => go(n - 1, xs)
            case Nil => throw new RuntimeException("No such element.")
        }
        go(n, stack)
    }
    def pop(): Stack[T] = stack match {
        case x :: xs => new Stack[T](xs)
        case Nil => throw new RuntimeException("No such element.")
    }
    def push(x: T): Stack[T] = new Stack[T](x :: stack)
}
object Stack {
    def apply[T](): Stack[T] = new Stack[T](Nil: List[T])
}
object Main {
    def main(args: Array[String]): Unit = {
        println(calc(readLine).top(0))
    }
    
    def calc(line: String): Stack[Long] = line.split(" ").foldLeft(Stack[Long]()) { (stack, elem) => 
        elem match {
            case "+" => {
                val result = stack.top(1) + stack.top(0)
                stack.pop.pop.push(result)
            }
            case "-" => {
                val result = stack.top(1) - stack.top(0)
                stack.pop.pop.push(result)
            }
            case "*" => {
                val result = stack.top(1) * stack.top(0)
                stack.pop.pop.push(result)
            }
            case _ => stack.push(elem.toLong)
        }
    }
}


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

int main(void){
    
    int N;
    cin >> N;
    vector<int> d(N);
    for(int i = 0; i < N; i++){
        cin >> d[i];
    }

    long long ans = 0;
    
    for(int i = 0; i < N; i++){
        for(int j = i + 1; j < N; j++){
            ans += d[i] * d[j];
        }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int>P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);

int n;
int x[100], y[100], h[100];
void solve() {
	cin >> n;
	rep(i, n) {
		cin >> x[i] >> y[i] >> h[i];
	}
	rep(cx, 101) {
		rep(cy, 101) {
			int le = 0, ri =2* mod;
			bool valid = true;
			rep(i, n) {
				int dif = abs(x[i] - cx) + abs(y[i] - cy);
				if (h[i] > 0) {
					int ch = h[i] + dif;
					if (ch < le || ri < ch) {
						valid = false; break;
					}
					le = ch; ri = ch;
				}
				else {
					if (dif < le) {
						valid = false; break;
					}
					ri = min(ri, dif);
				}
			}
			if (valid) {
				cout << cx << " " << cy << " " << le << endl; return;
			}
		}
	}
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//init();
	solve();
	//stop
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    b.at(a.at(i) - 1) = i + 1;
  }
  for (int i = 0; i < n - 1; i++) cout << b.at(i) << " ";
  cout << b.at(n - 1) << endl;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int a[105] = {};
    int x, n;
    cin >> x >> n;
    rep(i,n){
        int b;
        cin >> b;
        a[b]++;
    }
    int ans = INT_MAX;
    rep(i,102){
        if(!a[i] and abs(x - ans) > abs(i - x)){
            ans = i;
        }
    }
    cout << ans << endl;
}


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

int main() {
	int N=5;
	int p;

	vector<int> x(N+1); // N個のデータ

	for (int i = 0; i < N+1; i++) x.at(i)=0;

	for (int i = 0; i < N; i++) {
		cin >> p;
		x.at(p)=p;
	}

	for (int i = 1; i < N+1; i++) {
		if (x.at(i)==0) {
			cout << i << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3576
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a[33]={0,1,1,1,2,1,2,1,5,2,2,1,5,1,2,1,14,1,5,1,5,2,2,1,15,2,2,5,4,1,4,1,51};
	int x;
	cin>>x;
	cout<<a[x];
}

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

int main() {
	int n;cin>>n;
	vector<int> h(n);
	int flag=1;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	h[0]--;
	for(int i=1;i<n;i++){
		if(h[i]>h[i-1])h[i]--;
		if(h[i]<h[i-1])flag=0;
	}
	if(flag){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}


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

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;
typedef unsigned long long int ULL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define LET(x,a) __typeof(a) x(a)

#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
//Works for forward as well as backward iteration

#define gu getchar
#define pu putchar
#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)

#define DRT() int t; si(t); while(t--)

#define PlUSWRAP(index,n) index = (index+1)%n		//index++; if(index>=n) index=0
#define MINUSWRAP(index,n) index = (index + n -1)%n 	//index--; if(index<0) index=n-1
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)	//Round off d to nearest integer

#define FLUSHN while(gu()!='\n')
#define FLUSHS while(gu()!=' ')

#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif

#define off ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() {
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
	// #endif
	off;
	int n;
	cin>>n;
	int digits=0,temp=n;
	while(temp > 0)
	{
		temp/=10;
		digits++;
	}
	int sum=0;
	rep(i,1,digits)
	{
		if(i&1)
		{
			sum+=9*(int)pow(10,i-1);
		}
	}
	int rem = n-(int)pow(10,digits-1);
	if(digits&1)
		sum+=rem+1;
	cout<<sum;
  	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		long N = sc.nextLong();
		long D = sc.nextLong();
		long count = 0;
		for(int i =0;i<N;i++) {
			long a = sc.nextLong();
			long b = sc.nextLong();
			double value = Math.sqrt(Math.abs(a)*Math.abs(a)+Math.abs(b)*Math.abs(b) );
			if(value<=D) {
				count = count + 1;
			}
		}
		System.out.println(count);

	}

}


Measured memory_bytes: 59672
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
//typedef vector<vector<int> > matrix;
 
#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))
 
#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
 
inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD=998244353;
const ll hell=1000000007;
const int INF = 1e16;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);
 
double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };
 
const int N=200005;
int dp[1001][20001];
struct S{

int w,s,v;
int r;

};
S a[N+1];
bool compare(S s1,S s2)
{
   return s1.r<s2.r;
   // if(s1.s!=s2.s)
    //return s1.s<s2.s;
      //  return s1.w<s2.w;
    
}
int solve(int i,int j)
{
if(i==0)
{
    return dp[i][j]=0;
}
if(dp[i][j]!= -1)
return dp[i][j];
dp[i][j]=solve(i-1,j);
if(j>=a[i-1].w)
{
    if((j-a[i-1].w)<=a[i-1].s)
    dp[i][j]=max(dp[i][j],solve(i-1,j-a[i-1].w)+a[i-1].v);
}
return dp[i][j];




}


void solve()
{
  memset(dp,-1,sizeof(dp));
  int n;
  cin>>n;
  for(int i=0;i<n;i++)
  {
      cin>>a[i].w>>a[i].s>>a[i].v;
      a[i].r=(a[i].s+a[i].w);
  }
  sort(a,a+n,compare);
 
  int ans=0;
  for(int j=0;j<=20000;j++)
  {
      ans=max(ans,solve(n,j));
  }
 // cout<<dp[3][4]<<endl;
  cout<<ans<<endl;
  //cout<<dp[3][4]<<endl;


}

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


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

using namespace std;

int main() {
    string str, order, p;
    int a, b, q;
    cin >> str >> q;
    for (int i = 0; i < q; ++i) {
        cin >> order >> a >> b;
        if (order == "print") {
            cout << str.substr(a, b - a + 1) << endl;
        } else if (order == "reverse") {
            reverse(str.begin() + a, str.begin() + b + 1);
        } else {
            cin >> p;
            str.replace(a, b - a + 1, p);
        }
    }
    return 0;
}


Measured memory_bytes: 3172
#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 drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  string s;
  cin >> s;
  vi cnt(2);
  rep(i,sz(s)) {
    cnt[s[i]-'0']++;
  }
  int ans = min(cnt[0],cnt[1])*2;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
ll fl[N];
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
	}
	
	k=0;
	for(i=1;i<=n;i++){
		if(ar[i]==i){
			if(i+1<=n){
				k++; swap(ar[i],ar[i+1]);
			}
			else{
				k++; swap(ar[i],ar[i-1]);
			}
		}
	}
	cout<<k;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k;
  cin>>n>>k;
  int a[n],c[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  c[0]=0;
  c[1]=abs(a[1]-a[0]);
  for(int i=2;i<n;i++)
  {
    int j=0;
    c[i]=INT_MAX;
    while(j<=min(k,i))
    {
    c[i]=min(c[i],c[i-j]+abs(a[i]-a[i-j]));
    j++;
    }
  }
  cout<<c[n-1]<<endl;
//   for(int i=0;i<n;i++)
//   cout<<c[i]<<" ";
}

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

using namespace std;

void check(int h, int w) {
	int pre = h * h + w * w;
	int tmp_h, tmp_w;
	int min = 150 * 150;
	for(int i = 1; i < w; i++) {
		for(int j = i + 1; j <= 150; j++) {
			int ans = i * i + j * j;
			if(pre < ans and ans < min ) {
				tmp_h = i;
				tmp_w = j;
				min = ans;
			}
			if(pre == ans and h < i) {
				tmp_h = i;
				tmp_w = j;
				goto end;
			}
		}
	}
	end:
	cout << tmp_h << " " << tmp_w << endl;
}

int main(void) {
	
	int h, w;
	while(1) {
		cin >> h >> w;
		if(h == 0 and w == 0) {
			break;
		}

		check(h, w);
	}
	return 0;
}

Measured memory_bytes: 3044
//****************************//
/**********  main *************/
//****************************//
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
 
using namespace std;
typedef long long ll;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(i=0;i<n;i++)
#define FOR(i,a,b) for(i=a;i<b;i++)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
 
 
int main() {
 
	std::cin.tie(0);
 
    string s;
    cin >> s;

    if(s[2]==s[3] && s[4]==s[5]) {
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;

 
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<stack>
#define inf 0x3f3f3f3f
#define esp 1e-7
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}

struct Tree{
	int sg;
	int visited;
}t[100050];
int n;
vector<int> to[100050];

void dfs(int index){
	for (unsigned int i=0;i<to[index].size();i++){
		if (t[to[index][i]].visited==0){
			t[to[index][i]].visited=1;
			dfs(to[index][i]);
			t[index].sg^=(t[to[index][i]].sg+1);
		}
	}
}

int main(){
	n=read();
	for (int i=1;i<=n;i++)	to[i].clear();
	for (int i=1,tmp1,tmp2;i<n;i++){
		tmp1=read();tmp2=read();
		to[tmp1].push_back(tmp2);
		to[tmp2].push_back(tmp1);
	}
	t[1].visited=1;
	dfs(1);
	if (t[1].sg==0)	cout<<"Bob"<<endl;
	else			cout<<"Alice"<<endl;
	return 0;
}

Measured memory_bytes: 11136
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
using namespace std;
long long int gcd(long long a,long long b){
  if(b==0){
    return a;
  }
  else{
    return gcd(b,a%b);
  }
}
int main(){
  long long int a,b,c,d,i,ans=0;
  scanf("%lld %lld\n",&a,&b);
  c=gcd(a,b);
  d=c;
  for(i=2;i*i<=c;i++){
    if(d%i==0){
      ans++;
      while(d%i==0){
        d=d/i;
      }
    }
  }
  if(d!=1){
    ans++;
  }
  printf("%lld\n",ans+1);
  return 0;
}

Measured memory_bytes: 256
while true
  n = gets.to_i
  break if n == 0
  d = Array.new(6){|i| i+1}
  ans = 1
  n.times do
    dir = gets.chomp 
    case dir
    when "North" then d[0],d[1],d[5],d[4] = d[1],d[5],d[4],d[0]
    when "South" then d[0],d[1],d[5],d[4] = d[4],d[0],d[1],d[5]
    when "West" then d[0],d[2],d[5],d[3] = d[2],d[5],d[3],d[0]
    when "East" then d[0],d[2],d[5],d[3] = d[3],d[0],d[2],d[5]
    when "Right" then d[1],d[2],d[4],d[3] = d[2],d[4],d[3],d[1]
    when "Left" then d[1],d[2],d[4],d[3] = d[3],d[1],d[2],d[4]
    end
    ans += d[0]
  end
  puts ans
end

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

using namespace std;

#define pb push_back
#define mp make_pair
#define MOD ((int)(1e9) + 7)
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define filename "lynext"
#define freop freopen(filename ".cik","w",stdout);freopen(filename ".gir","r",stdin)
const int N = ((int)1e5) + 5;
const int M = ((int)1e3) + 5;
typedef long long int lli;

int n,k,q;
int arr[N];
int main ()
{
	fast;
	//freop;
	cin >> n >> k >> q;
	for (int i = 1; i <= q; i++)
	{
		int a;
		cin >> a;
		arr[a]++;
	}
	for (int i = 1; i <= n; i++)
	{
		if (k - (q - arr[i]) > 0)
			cout << "Yes";
		else
			cout << "No";
		cout << "\n";
	}
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define SZ(X) ((int)(X).size())
#define endl "\n";
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
	int x,y;
	cin>>x>>y;
	for (int c = 0; c <=x; ++c)
	{
		 int t = x-c;
		 if(2*c+4*t==y){
		 	cout<<"Yes";
		 	return 0;
		 }

	}
	cout<<"No";
	

   return 0;
}


Measured memory_bytes: 3648
#!/usr/bin/env python
# coding: utf-8
#

import copy
import math
import fractions
from functools import reduce

def gcd(*numbers):
    return reduce(fractions.gcd, numbers)

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def main(n, start, x):
    pos = copy.deepcopy(x)
    pos.append(start)
    sp = sorted(pos)
    # print(sorted_pos)
    sabun = [ (sp[i+1] - sp[i]) for i in range(n)]
    # print(sabun)
    print(gcd_list(sabun))
        
if __name__ == '__main__':
    try:
        n, start  = list(map(int, input().strip().split(' ')))
        x = list(map(int, input().strip().split(' ')))
        main(n, start, x)
    except EOFError:
        pass


Measured memory_bytes: 16344
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define endl "\n"
#define ar array
#define deb(x) cout << #x << " = " << x << endl
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll N = 2e5 + 1;

template <class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
struct comp
{
    bool operator()(const pair<ll, ll> &x, const pair<ll, ll> &y) const
    {
        return x.first < y.first;
    }
};
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll pwr(ll x, ll n)
{
    if (n == 0)
        return 1;
    if (n & 1)
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    else
        return pwr(mul(x, x), n / 2);
}
ll modInv(ll n)
{
    return pwr(n, mod - 2);
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

int main()
{
    IOS;
    int t = 1;
   // cin >> t;
    while (t--)
    {
        string s;
        cin >> s;
        if (s.back() == 's')
            s = s + "es";
        else
            s = s + 's';
        cout << s << endl;
    }
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 998244353
using namespace std;
typedef long long ll;

ll power(ll n, ll p, ll mod) {
    ll ans = 1;
    while (p > 0) {
        if (p & 1) ans = ans * n % mod;
        n = n * n % mod;
        p >>= 1;
    }
    return ans;
}

int main() {
    int N; cin >> N;
    vector<int> D(N);
    REP(i, 0, N) cin >> D[i];

    int count[N] = {};
    REP(i, 0, N) count[D[i]]++;

    if (D[0] != 0 || count[0] != 1) {
        cout << 0 << endl;
        return 0;
    }
    
    ll ans = 1; int M = 1;
    REP(i, 1, N) {
        if (count[i] == 0) break;
        ans = (ans * power(count[i - 1], count[i], MOD)) % MOD;
        M += count[i];
    }

    if (N == M) cout << ans % MOD << endl;
    else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 1024