akhauriyash/Code-Regression huggingface dataset:
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
 
#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl
 
#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 25;

string s[N];
ll dp[N][N];
ll ans;

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

ll h,w;

bool check(ll x, ll y){
	return x>=0 and y>=0 and x<h and y<w;
}

void bfs(ll x,ll y){
	rep(i,0,h)	rep(j,0,w)	dp[i][j]=M;
	queue<pll> q;
	q.push({x,y});
	dp[x][y]=0;
	while(!q.empty()){
		pll p = q.front();
		q.pop();
		ll xx = p.ft, yy = p.sd;
		rep(i,0,4){
			if(check(xx+dx[i], yy+dy[i]) and s[xx+dx[i]][yy+dy[i]] != '#' and dp[xx+dx[i]][yy+dy[i]] > dp[xx][yy] + 1){
				dp[xx+dx[i]][yy+dy[i]] = dp[xx][yy] + 1;
				q.push({xx+dx[i], yy+dy[i]});
			}
		}
	}
	rep(i,0,h)	rep(j,0,w){
		if(s[i][j] != '#')
			ans = max(ans, dp[i][j]);
	}
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>h>>w;
	rep(i,0,h)	cin>>s[i];
	rep(i,0,h)	rep(j,0,w){
		if(s[i][j]!='#')
			bfs(i,j);
	}
	cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    cout << 180*n-360 << endl;

    return 0;
}

Measured memory_bytes: 256
n,y = map(int,input().split())

#i:10000,j:5000

for i in range(n+1):
  for j in range(n+1-i):
    if y == 10000*i + 5000*j + 1000*(n-i-j):
      print(i,j,n-i-j)
      exit()
print("-1 -1 -1")

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

using namespace std;

int n, k, ans, ta;
map< int, int > m;
map< int, int >::iterator it;
vector< int > v;

int main() {
	scanf("%d%d", &n, &k);
	while (n--) {
		scanf("%d", &ta);
		m[ta]++;
	}
	for (it = m.begin(); it != m.end(); it++)
		v.push_back(-it->second);
	sort(v.begin(), v.end());
	while (v.size() > k) {
		ans -= v.back();
		v.pop_back();
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 10748
#include <iostream>
#include <vector>

using namespace std;

typedef vector<vector<pair<int,int>>> Graph;

int dfs(Graph& g,int u,vector<int>& memo)
{
	if(~memo[u]) return memo[u];
	int res=0;
	for(auto e:g[u]){
		int v=e.first,w=e.second;
		res=max(res,w+dfs(g,v,memo));
	}
	return memo[u]=res;
}

int main()
{
	for(int n,m;cin>>n>>m && n|m;){
		Graph g(n);
		for(int i=0;i<m;i++){
			int s,d,w; cin>>s>>d>>w;
			g[s].emplace_back(d,w);
		}
		vector<int> memo(n,-1);
		cout<<dfs(g,0,memo)<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1220
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-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; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};


ll dp[101010];
bool ok[101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    REP(i,N+1) ok[i] = true;
    REP(i,M){
        int a;
        cin >> a;
        ok[a] = false;
    }
    dp[0] = 1;
    for(int i=0;i<=N;i++){
        for(int next=i+1;next<=min(N,i+2);next++){
            if(ok[next]){
                dp[next] += dp[i];
                dp[next] %= MOD;
            }
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

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

  int cnt1 = 0, cnt2 = 0;
  for(int i = 0; i < s.size(); i++) {
      if(s[i] == '0') cnt1++;
      else if (s[i] == '1') cnt2++;
  }
  cout << 2 * min(cnt1, cnt2) << endl;
}


Measured memory_bytes: 3736
#include <iostream>
#include <stdio.h>
#include <string>
#include <map>
#include <stack>
#include <vector>
#include <string.h>
#include <set>
#include <queue>
#include <cmath>
#include <algorithm>

using namespace std;

struct node
{
	int x;
	int y;
	int dist;

	node(int x , int y , int dist)
	{
		this -> x = x;
		this -> y = y;
		this -> dist = dist;
	}
};

bool vis[1010][1010];
char input[1010][1010];
int dx[4] = {- 1 , 0 , 1 , 0};
int dy[4] = {0 , 1 , 0 , - 1};
queue<node> q;
vector<node> pre;

bool inArea(int x , int y , int n , int m)
{
	return x >= 0 && x < n && y >= 0 && y < m;
}

int solve(int sx , int sy , int h , int w , int n)
{
	while (!q.empty())
		q.pop();
	pre.clear();

	int value = 1;
	q.push(node(sx , sy , 0));
	vis[sx][sy] = true;

	while (!q.empty())
	{
		node no = q.front();
		q.pop();
		pre.push_back(node(no.x , no.y , no.dist));

		if (input[no.x][no.y] >= '0' && input[no.x][no.y] <= '9' && ((input[no.x][no.y] - '0') == value))
		{
			value ++;
			if (value == n + 1)
				return no.dist;

			while (!q.empty())
			{
				node temp = q.front();
				q.pop();
				vis[temp.x][temp.y] = false;
			}

			for (int i = 0;i < pre.size() - 1;i ++)
				vis[pre[i].x][pre[i].y] = false;
			pre.clear();
			pre.push_back(node(no.x , no.y , no.dist));
		}
		for (int i = 0;i < 4;i ++)
		{
			int tx = no.x + dx[i];
			int ty = no.y + dy[i];
			if (inArea(tx , ty , h , w) && !vis[tx][ty] && input[tx][ty] != 'X')
			{
				vis[tx][ty] = true;
				q.push(node(tx , ty , no.dist + 1));
			}
		}
	}
	return - 1;
}

int main()
{
	int i , j , h , w , n;
	while (scanf("%d%d%d" , &h , &w , &n) != EOF)
	{
		for (i = 0;i < h;i ++)
			for (j = 0;j < w;j ++)
				vis[i][j] = false;

		int sx , sy;
		for (i = 0;i < h;i ++)
		{
			scanf("%s" , input[i]);
			for (j = 0;j < w;j ++)
			{
				if (input[i][j] == 'S')
				{
					sx = i;
					sy = j;
				}
			}
		}
		// ???S????§????
		printf("%d\n" , solve(sx , sy , h , w , n));
	}
	return 0;
}

Measured memory_bytes: 9544
#include <stdio.h>

int main(void)
{
	int a,b,c;
	int count=0;
	int sum=0;
	
	scanf("%d%d%d",&a,&b,&c);
	
	for(int i=0;i<101;i++){
		
		sum=sum+a;
		
		if(sum%b==c){
			count++;
		}
	}
	
	if(count!=0){
		printf("YES\n");
	}else{
		printf("NO\n");
	}
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); (i)++)
using namespace std;
typedef long long ll;
// Welcome to my source code!

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

    return i+1;
}

int main() {
    int n;
    cin >> n;
    int A[n];
    rep(i,n) cin >> A[i];
    int lastIndex = A[n];

    int q = partition(A, 0, n-1);

    rep(i,n) {
        if (i) cout << ' ';
        if (i == q) cout << '[';
        cout << A[i];
        if (i == q) cout << ']';
    }
    cout << endl;
}


Measured memory_bytes: 3396
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using llong = long long;
using P = pair<int, int>;
const int inf = 1 << 20;
const int mod = 1e9 + 7;

int main() {
   int n, m;
   cin >> n >> m;
   vector<int> pena(n), ans(n);
   rep(i, m) {
      int p;
      string s;
      cin >> p >> s;
      p--;
      if (ans[p])
         continue;
      if (s == "AC") {
         ans[p] = 1;
      } else {
         pena[p]++;
      }
   }
   int AC, PENA;
   AC = PENA = 0;
   rep(i, n) {
      AC += ans[i];
      if (ans[i] != 0)
         PENA += pena[i];
   }
   printf("%d %d\n", AC, PENA);
   return 0;
}

Measured memory_bytes: 1024
n = int(input())
d, x = map(int, input().split())
a_list = [int(input()) for _ in range(n)]
count = n
for a in a_list:
    for i in range(1, 101):
        if a*i + 1 <= d:
            count += 1
        else:
            break
print(count + x)

Measured memory_bytes: 38512
#include <iostream>
#include <queue>

using namespace std;

const int Inf = 10000*100000+100;
int V,E,R,S,T[500000+10],D[500000+10],H[500000+10],N[500000+10];
int C[100000+10],P[100000+10];

int main() {
	queue<int> Q;
	cin >> V >> E >> R;
	for (int i=1; i<=E; i++){
		cin >> S >> T[i] >> D[i];
		N[i] = H[S];
		H[S] = i;
	}
	fill(C,C+100010,Inf);
	C[R] = 0;
	Q.push(R);
	P[R] = 1;
	while(!Q.empty()){
		int u = Q.front();
		Q.pop();
		P[u] = 0;
		for (int i=H[u]; i; i=N[i]){
			int t = T[i];
			if (C[t] > C[u] + D[i]){
				C[t] = C[u]+D[i];
				if (!P[t]){
					Q.push(t);
					P[t] = 1;
				}	
			}
		}
	}
	
	for (int i=0; i<V; i++){
		if (C[i] < Inf){
			cout << C[i] << endl;
		}else{
			cout << "INF" << endl;
		}
	}	
}

Measured memory_bytes: 10148
#include <bits/stdc++.h>
using namespace std;
#define N 1009
#define INF 1000000009
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%lld%lld",&x,&y)
#define sd3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define pf(x) printf("%d",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<<" " << endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
ll dp[N][N],a[N][N];
int main(){
    int i,j,n,m,t,k,x,y;
    cin >> n >> m;
    char c;
    dp[1][1]=1;
    for(i=1;i<=n; i++){
        for(j=1; j<=m; j++){
           cin >> c;
           if(c=='.'){a[i][j]=1;}
           if(a[i][j-1]){
               dp[i][j]+=dp[i][j-1];
           }
           if(a[i-1][j]){
               dp[i][j]+=dp[i-1][j];
           }
           dp[i][j]%=MOD;
        }
    }
    tr(dp[n][m]);
}

Measured memory_bytes: 16128
#include<algorithm>
#include<cmath>
#include<iostream>
#include<vector>
#include<string>
using namespace std;
typedef long long ll;

#define REP(i, n) for(ll i=0;i<ll(n); i++)

int main(){
    int N;
    cin >> N;
    vector<int> X (N+1, 0);

    int n_max=0;
    int n_min=101;
    int i, j;

    for(i=1;i<=N;i++){
        cin >> X[i];
        if(n_max <=X[i]){n_max = X[i];}
        if(n_min > X[i]){n_min = X[i];}
    }

    ll ans, ans_tmp;

    ans = 10000000000;
    for(i=n_min;i<=n_max;i++){
        ans_tmp = 0;
        for(j=1;j<=N;j++){
            ans_tmp += pow(X[j] - i, 2.0);  
        }
        if(ans > ans_tmp){ans = ans_tmp;}
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 3192
import sys

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    if b == -1: return a
    while a % b > 0:
        a, b = b, a % b
    return b         

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(a) for a in input().split()]
    lGCD = [-1 for _ in range(N + 1)]
    rGCD = [-1 for _ in range(N + 1)]

    for i in range(N):
        lGCD[i+1] = gcd(lGCD[i], A[i])
        rGCD[N-1-i] = gcd(rGCD[N-i], A[N-i-1])

    maxGCD = 1
    for i in range(N):
        gcdI = gcd(lGCD[i], rGCD[i + 1])
        maxGCD = max(maxGCD, gcdI)
    print(maxGCD)
    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14456
s = input()

N = len(s)
a = []
a.append(s[0])

i = 1
j = 1
while i < N-1:
    pre = a[j-1]
    tmp = s[i]
    if pre == s[i]:
        tmp += s[i+1]
        i += 1
    a.append(tmp)
    i += 1
    j += 1
a.append(s[-1])

ans = len(a)
if a[-1] == a[-2] or s != ''.join(map(str, a)):
    ans -= 1

print(ans)

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

using namespace std;

vector<int64_t> dp(100010, INT64_MAX);

int64_t dfs(vector<int> &arr, int i, int k) {
    if (dp[i] != INT64_MAX) {
        return dp[i];
    }

    if (i <= 0) {
        return 0;
    } 

    //
    //  i - 1, i - 2, ... i - k への遷移を再帰的に集めてきて
    //  それの min を返り値とする
    //
    //  これは、同じ i であれば、返り値が同じになる
    //  ことがメモ化の鍵となる。
    //

    int64_t result = INT64_MAX;
    for (int l = 1; l <= k; l++) {
        //  i - k からジャンプ
        //  abs(arr[i] - arr[i - k]) だけコストが増えていく
        if (i - l >= 0) {
            result = min(result, dfs(arr, i - l, k) + abs(arr[i] - arr[i - l]));
        }
    }

    dp[i] = result;
    return result;
}

int main(int argc, char *argv[]) {
    int N, K;
    cin >> N >> K;

    vector<int> arr;
    int cur;
    for (int i = 0; i < N; i++) {
        cin >> cur;
        arr.push_back(cur);
    }

    cout << dfs(arr, N - 1, K) << endl;
    return 0;
}


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

bool checkPager(string s, int start, int finish){
  for(int i=start+1; i<=finish; i++){
    if(s[i] == '#' && s[i-1] == '#') return true; 
  }
  return false;
}

bool checkTitik(string s, int start, int finish){
  for(int i=start; i<=finish; i++){
    if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.')
      return true;
  }
  return false;
}

int main(){
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  a--; b--; c--; d--;
  string s;
  cin >> s;
  
  if(checkPager(s, a, c) || checkPager(s, b, d)){
    cout << "No" << endl;
    return 0;
  }
  
  if (c < d){
    cout << "Yes" << endl;
    return 0;
  }
  
  if(checkTitik(s, b, d)){
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
#define t_max 100000 + 5
int v[30][t_max];

int main() {
    int N, C;
    cin >> N >> C;
    REP(i, N) {
        int a, b, c;
        cin >> a >> b >> c;
        c--;
        v[c][a]++;
        v[c][b]--;
    }
    //録画機は、あるチャンネルの時刻
    // S から時刻 T までを録画するとき、時刻 S
    //− 0.5 から時刻 T までの間、他のチャンネルの録画に使うことができません。
    REP(i, C) {
        REP(j, t_max - 1) { v[i][j + 1] += v[i][j]; }
    }
    //あとから録画開始時刻を1だけ早める（これで、同じチャンネルで連続して録画するときに重複をなくせる）。
    REP(i, C) {
        REP(j, t_max - 1) {
            if(v[i][j] == 0 && v[i][j + 1] == 1)
                v[i][j]++;
        }
    }
    int ans = 0;
    REP(j, t_max) {
        int cnt = 0;
        REP(i, C) {
            if(v[i][j])
                cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 11904
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;
typedef long double ld;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll N = (ll)1e5 + 10;
const ll inf = (ll)1e18;
vector<pii> T[N];
ll vl[N];
int cnt[N];
int par[N];

int fin(int x){ 
  if(par[x]==x)return x;
  return par[x]=fin(par[x]);
}

void unite(int a, int b){
  a=fin(a);
  b=fin(b);
  if(a==b)return;
  par[a]=b;
  cnt[b]+=cnt[a];
  vl[b] += vl[a];
}

struct edge{
  int ai;
  int bi;
  ll wei;
  bool operator< (const edge &r) const {
    return wei < r.wei;
  }
};

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  for(int i = 1; i <= n; i ++ ){
    cin >> vl[i];
    par[i]=i;
  }
  vector<edge> t(m);
  for(int i = 0 ; i < m ;i ++ ){
    cin >> t[i].ai >> t[i].bi >> t[i].wei;
  }
  sort(t.begin(), t.end());
  int ans = 0;
  for(int i = 0 ; i < m ; i ++ ){
    unite(t[i].ai, t[i].bi);
    cnt[fin(t[i].ai)] ++ ;
    if(vl[fin(t[i].ai)] >= t[i].wei){
      ans += cnt[fin(t[i].ai)];
      cnt[fin(t[i].ai)]=0;
    }
  }
  cout << m - ans << "\n";
  return 0;
}

Measured memory_bytes: 5760
#include<stdio.h>

int F[45];

int fibonacci(int n){
  if(n==0||n==1){
    return F[n]=1;
  }
  if(F[n]!=-1){
    return F[n];
  }
  return F[n]=fibonacci(n-2)+fibonacci(n-1);
}

int main(void)
{
  int i,n;
  for(i=0;i<45;i++){
    F[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  
  return 0;
}

Measured memory_bytes: 1820
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long
#define hii cout << "hii" << endl
#define int long long
#define endl '\n'
#define all(s) s.begin(), s.end()
 
template <class T> ostream& operator << (ostream &os, const vector<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T> ostream& operator << (ostream &os, const set<T> &v) { for (T i : v) os << i << ' '; return os; }
template <class T, class S> ostream& operator << (ostream &os, const pair<T, S> &v) { os << v.first << ' ' << v.second; return os; }
template <class T, class S> ostream& operator << (ostream &os, const unordered_map<T, S> &v) { for (auto i : v) os << '(' << i.first << "=>" << i.second << ')' << ' '; return os; }
 
 
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <class Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << endl; }
    template <class Arg1, class... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args) {
        const char* sep = strchr(names + 1, ',');
        cerr.write(names, sep - names) << " : " << arg1 << "  ";
        __f(sep + 1, args...);
    }
#else
#define trace(...) 0
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _CRT_SECURE_NO_WARNINGS
#endif // ifndef ONLINE_JUDGE

const int N = 5e5 + 5;
const int MAX = 250000 + 5;
const int M = 5e6 + 5;
const int mod = 1e9 + 7;
const int MOD = 998244353;
const int INF = 1e15;
const int LG = 21;

int arr[N];
int brr[N];

void solve()
{
	int n;
	cin >> n;
	int ret = 0;
	for(int i = 0; i < n; i++)
	{
		cin >> arr[i];
		if(i)
		{
			if(arr[i] >= arr[i - 1]) continue;
			ret += arr[i - 1] - arr[i];
			arr[i] = arr[i - 1];
		}
	}
	cout << ret << endl;
}
 
int32_t main() 
{	
	ios_base:: sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

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

Measured memory_bytes: 5176
N, M = map(int,input().split())
P = list(map(int,input().split()))

class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
        
    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

UFT = UnionFind(N)
for _ in range(M):
    x, y = map(int,input().split())
    UFT.union(x-1, y-1)

ans = 0

for i in range(N):
    if UFT.same(P[i] - 1, i):
        ans += 1
print(ans)

Measured memory_bytes: 88556
#include<bits/stdc++.h>
using namespace std ;
 
/*                        [Template]                        */
#define async ios_base::sync_with_stdio(false); cin.tie(NULL);
#define int long long int
#define let auto
#define of :
#define all(y) y.begin(), y.end()
#define present( x, y ) x.find( y ) != x.end()
#define _matrix(T) vector<vector<T>>
template<class T>
auto matrix( int r, int c, T v ){
	return vector<vector<T>>( r, vector<T>( c, v ) ) ;
}
const int mod = (int)1e9 + 7 ;
const int inf = (int)1e18 ;
/************************************************************/

// i -> P[i]
// with cost C[P[i]]

signed main(){
	int N, K ; cin >> N >> K ;
	vector<int> P(N+1), C(N+1) ;
	for( int i = 1 ; i <= N ; i++ ) cin >> P[i] ;
	for( int i = 1 ; i <= N ; i++ ) cin >> C[i] ;
	int ans = -inf ;
	for( int i = 1 ; i <= N ; i++ ){
		int cycleSum = 0 ;
		int cycleLen = 0 ;
		int v = i ;
		while( true ) {
			cycleLen++ ;
			cycleSum += C[P[v]] ;
			if( P[v] == i ) break ;
			v = P[v] ;
		}
		v = i ;
		cycleSum = max( 0LL, cycleSum ) ;
		int partialSum = 0 ;
		int cnt = 0 ;
		while( true ){
			cnt++ ;
			partialSum += C[P[v]] ;
			int num = ( K - cnt ) / cycleLen ;
			ans = max(ans, partialSum + cycleSum * num ) ;
			if( P[v] == i ) break ;
			v = P[v] ;
			if( cnt >= K ) break ;
		}
	}
	cout << ans ;
	return 0 ;
}


Measured memory_bytes: 3716
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

using lint = long long;

template <class Cost = int>
struct Edge {
    int from, to;
    Cost cost;
    Edge(int from = -1, int to = -1, Cost cost = 1)
        : from(from), to(to), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
class Graph {
public:
    int size;
    std::vector<std::vector<Edge<Cost>>> path;

    explicit Graph(int N = 0) : size(N), path(size) {}
    void span(int from, int to, Cost cost = 1) {
        path[from].push_back(Edge<Cost>(from, to, cost));
    }
    std::vector<Edge<Cost>>& operator[](int v) { return path[v]; }
};

void fail() {
    std::cout << "NO" << std::endl;
    std::exit(0);
}

std::vector<lint> A;
Graph<> tree;

lint dfs(int v, int r) {
    std::vector<lint> ch;
    for (auto e : tree[v]) {
        if (e.to == r) continue;
        ch.push_back(dfs(e.to, v));
    }
    if (ch.empty()) return A[v];

    lint sum = std::accumulate(ch.begin(), ch.end(), 0LL);
    lint max = *std::max_element(ch.begin(), ch.end());

    lint P = std::min(sum / 2, sum - max);  // 作れる最大ペア数
    if (A[v] < sum - P || sum < A[v]) fail();

    // 実際に葉同士でペアにするのは、sum-A[v]組
    // よって親に引き継がれる葉の数は、sum-2(sum-A[v])個
    lint ret = A[v] * 2 - sum;
    return ret;
}

int main() {
    int N;
    std::cin >> N;
    A.resize(N);
    for (auto& a : A) std::cin >> a;

    tree = Graph<>(N);
    for (int i = 0; i < N - 1; ++i) {
        int u, v;
        std::cin >> u >> v;
        --u, --v;
        tree.span(u, v);
        tree.span(v, u);
    }

    // 例外
    if (N == 2) {
        std::cout << (A[0] == A[1] ? "YES" : "NO") << std::endl;
        return 0;
    }

    // 葉でない頂点からDFS
    int r;
    for (r = 0; tree[r].size() == 1; ++r) {}

    std::cout << (dfs(r, -1) == 0 ? "YES" : "NO") << std::endl;
    return 0;
}


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

using namespace std;

#define SZ(x) (int)(x.size())
#define REP(i, n) for(int i=0;i<(n);++i)
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RREP(i, n) for(int i=(int)(n);i>=0;--i)
#define RFOR(i, a, b) for(int i=(int)(a);i>=(int)(b);--i)
#define ALL(a) (a).begin(),(a).end()
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<< endl;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using P = pair<int, int>;

const double eps = 1e-8;
const ll MOD = 1000000007;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;

template <typename T1, typename T2>
bool chmax(T1 &a, const T2 &b) {
  if(a < b) {a = b; return true;}
  return false;
}

template <typename T1, typename T2>
bool chmin(T1 &a, const T2 &b) {
  if(a > b) {a = b; return true;}
  return false;
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

template<class T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  REP(i, SZ(v)) {
    if(i) os << " ";
    os << v[i];
  }
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll l, r, d; cin >> l >> r >> d;
  cout << r / d - (l-1) / d << endl;

}








Measured memory_bytes: 3608
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int mid = (s.length())/2, n = s.length();
    for(int i=1; i<=mid; i++){
        if(s[mid-i] != s[mid+i]){
            cout<<"No\n";
            return 0;
        }
    }
    //cout<<mid<<"\n";
    for(int i = 0; i < mid; i++){
        if(s[i] != s[mid-i-1]){
            //cout<<i<<" "<<mid-i-1<<"\n";
            cout<<"No\n";
            return 0;
        }
    }
    for(int i = 0; i < mid; i++){
        if(s[mid+i+1] != s[n-i-1]){
            //cout<<mid + i + 1<<" "<<n-i-1<<"\n";
            cout<<"No\n";
            return 0;
        }
    }
    cout<<"Yes\n";
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
void A(void);
void B(void);
void C(void);
void D(void);
void E(void);
void F(void);

int main(void){
    D();
}

void D(){
    long long int x,f,i,j;
    int k=0;
    cin>>x;
    for(i=-200;i<=200;i++){
        for(j=-200;j<=200;j++){
            f=i*i*i*i*i-j*j*j*j*j;
            if(f==x){
                cout<<i<<" "<<j<<endl;
                k=1;
                break;
            }
        }
        if(k==1)break;
    }
}

Measured memory_bytes: 3632
//  main.cpp
//  ABC168D

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
const int INF=1001001001;
int main(int argc, const char * argv[]) {
    int n,m;
    cin >> n >> m;
    vector<int> r[n+1];
    for (int i=0; i<m; i++) {
        int a,b;
        cin>>a>>b;
        r[a].push_back(b);
        r[b].push_back(a);
    }
    queue <int>q;
    vector<int>dist(n+1,INF); // 入り口からの距離
    dist.at(1)=0; // 入り口の洞窟
    q.push(1);
    vector<int>pre(n+1,-1); // 直前の洞窟番号
    while(!q.empty()){
        int v=q.front(); // 先頭の洞窟番号
        q.pop();
        for(int u:r[v]){
            if(dist[u]==INF){
                dist[u]=dist[v]+1;
                pre[u]=v;
                q.push(u);
            }
        }
    }
    cout<<"Yes"<<endl;
    for (int i=2; i<=n; i++) {
        cout <<pre.at(i)<<endl;
    }
    
    
    
    return 0;
}


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

int main() {
    int n, q, t;
    string name;
    queue<pair<string, int>> Q;

    cin >> n >> q;
    for (int i = 0; i < n; ++i) {
        cin >> name >> t;
        Q.push(make_pair(name, t));
    }

    pair<string, int> u;
    int elaps = 0, a;

    while (!Q.empty()) {
        u = Q.front();
        Q.pop();
        a = min(u.second, q);
        u.second -= q;
        elaps += a;
        if (u.second > 0) {
            Q.push(u);
        } else {
            cout << u.first << " " << elaps << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 6308
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = long long;
using P = pair<int, int>;

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; }
template<class T> inline void dump(vector<T> v) { for (auto& x : v) cerr << x << " "; cerr << endl; }
template<class T> inline void dump(vector<pair<T, T>> v) { for (auto& p : v) cerr << p.first << " " << p.second << endl; }
template<class T> inline void dump(vector<vector<T>> vv) { for (auto& v : vv) {for (auto& x : v) cerr << x << " "; cerr << endl;} }

const ll INF = 1e9;
const long long INFL = 1LL<<60;

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

inline bool is_inside(const int& h, const int& w, const int& u, const int& v) {
  return !(u < 0 || h <= u || v < 0 || w <= v);
}

int main() {
  int h, w, ci, cj, di, dj;
  cin >> h >> w >> ci >> cj >> di >> dj;
  ci--; cj--; di--; dj--;

  vector<string> s(h);
  rep(i, h) cin >> s[i];

  vector<vector<int>> dist(h, vector<int>(w, INF));
  dist[ci][cj] = 0;

  deque<P> deq;

  deq.push_back({ci, cj});

  while (!deq.empty()) {
    int x = deq.front().first;
    int y = deq.front().second;
    int d = dist[x][y];
    deq.pop_front();
    // コスト 0 で移動できる範囲
    rep(i, 4) {
      int nx = x + dx[i];
      int ny = y + dy[i];
      if (!is_inside(h, w, nx, ny)) continue;
      if (s[nx][ny] == '#') continue;
      if (chmin(dist[nx][ny], d)) deq.push_front({nx, ny});
    }
    // コスト 1 で移動できる範囲
    for (int u = -2; u <= 2; u++) {
      for (int v = - 2; v <= 2; v++) {
        int nx = x + u;
        int ny = y + v;
        if (!is_inside(h, w, nx, ny)) continue;
        if (s[nx][ny] == '#') continue;
        if (chmin(dist[nx][ny], d + 1)) deq.push_back({nx, ny});
      }
    }
  }

  if (dist[di][dj] == INF) {
    cout << -1 << endl;
  } else {
    cout << dist[di][dj] << endl;
  }

  return 0;
}


Measured memory_bytes: 9484
#include<stdio.h>

#define MAX 5

int main() {
  long long int max_passenger[MAX];
  long long int min_passenger = 1000000000000000;
  long long int n;
  long long int time = 0;
  int i;

  scanf("%lld", &n);
  for(i = 0; i < MAX; i++) scanf("%lld", &max_passenger[i]);

  for(i = 0; i < MAX; i++) {
    if(max_passenger[i] < min_passenger) min_passenger = max_passenger[i];
  }

  if(n % min_passenger == 0) time = n / min_passenger + 4;
  else                       time = n / min_passenger + 5;

  printf("%lld\n", time);

  return 0;
}


Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

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

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	string s,t;
	cin>>s>>t;
	int ans = 20000;
	int ss = s.size();
	int ts = t.size();
	for(int i=0;i<=ss-ts;i++){
		int cnt = 0;
		for(int j=0;j<ts;j++){
			if(s[i+j]!=t[j])cnt++;
		}
		chmin(ans,cnt);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<algorithm>
#include<math.h>
#include<cstdio>
#include<ctype.h>
#include<stdio.h>
#include<set>
#include<vector>
#include<map>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<numeric>
#include<string>
typedef long long ll;
using namespace std;
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
int main() {
	string S, T;
	cin >> S;
    cin >> T;
	ll k = S.size();
  	string ans="No";
	for (ll i = 1; i <= S.size(); i++) {
      if(S.substr(0,i)==T.substr(k-i,i)
         &&T.substr(0,k-i)==S.substr(i,k-i))
        ans="Yes";

	}
  cout<<ans<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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



		Scanner scanner = new Scanner(System.in);
		int N = scanner.nextInt();
		int[] data = new int[N];
		int ans = 0;
		boolean flag = true;
		for(int i = 0;i < data.length;i++){
			data[i] = scanner.nextInt();

			if(data[i] % 2 == 1){
				System.out.println(0);
				return;
			}
		}



		while(true){
			for(int i = 0;i < data.length;i++){
				if(data[i] % 2 == 1){
					System.out.println(ans);
					return;
				}
				data[i] /= 2;


			}
			ans++;

		}



	}


}

class Pair implements Comparable{
	int from;
	int end;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return end - otherpair.end;
	}
}



Measured memory_bytes: 21844
#include <stdio.h>

int main(void)
{
  int price;
  scanf("%d", &price);

  while (price > 0)
  {
    price -= 1000;
  }
  if (price < 0)
  {
    price *= -1;
  }
  printf("%d\n", price);
  return 0;
}


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

int main(){
    
    int n; cin>>n;
    
    vector<int> h(n);

    for(int i=0; i<n; i++) cin>>h[i];

    int flag,count =1;

    for(int i=1; i<n; i++){
        flag = 0;
        for(int j=0; j<i; j++){
            
            if(h[i] >= h[j])flag++;
        }
        if(flag == i)count++;
    }

    cout<<count<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <string.h>

using namespace std;

// #define for(i,a,b) for (int i=(a);i<(b);++i)
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,n) for(long long i = 0; i < (long long)(n); i++)
#define pb push_back // vectorに要素追加
#define INF (ll)1e18

ll mod = 1e9+7;
  
// 検索タグ
int main() {
	// 入力
	ll N,K,C;cin>>N>>K>>C;
	string S;cin>>S;
    
	// 解法
	ll forward[N];
	REP(i,N)forward[i]=0;
	ll rest = 0;
	REP(i,N){
		if (rest==0 & S[i]=='o'){
			if (i==0) forward[i] = 1;
			else forward[i] = forward[i-1]+1;
			rest = C;
		}
		else{
			rest = max((ll)0, rest-1);
			if (i==0) forward[i] = 0;
			else forward[i] = forward[i-1];
		}
	}
	// REP(i,N)printf("%lld ", forward[i]);
	// printf("\n");

	ll backward[N+1];
	REP(i,N+1)backward[i]=0;
	rest = 0;
	REP(i,N){
		if (rest==0 & S[N-i-1]=='o'){
			if (i==0) backward[N-i-1] = 1;
			backward[N-i-1] = backward[N-i]+1;
			rest = C;
		}
		else{
			rest = max((ll)0, rest-1);
			if (i==0) backward[N-i-1] = 0;
			backward[N-i-1] = backward[N-i];
		}
	}
	// REP(i,N)printf("%lld ", backward[i]);
	// printf("\n");

	REP(i, N){
		if (i==0){
			if (backward[i+1]<K){
				printf("%lld\n", i+1);
			}
		}
		else if (forward[i-1]+backward[i+1]<K){
			printf("%lld\n", i+1);
		}
	}
	//出力x
	// printf("%lld\n", ans);
}


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

int main(void){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    cout << a[n - 1];
    for(int i = n - 2; i >= 0; i--) cout << " " << a[i];
    cout << endl;
    return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(), (c).end());
const long long MOD = 1e9 + 7;
typedef long long ll;

int main(){
	int K;
	cin >> K;
	int EVEN = K / 2;
	int ODD = K - EVEN;
	int ans = EVEN * ODD;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;}
template <class T>
inline bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    int k,a,b;
    cin >> k >> a >> b;
    for (int i=a; i<=b; i++){
        if (i%k ==0){
            cout << "OK" << endl;
            return 0;}
    }
    cout << "NG" << endl;
}


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

int main() {
  int k, s;
  cin >> k >> s;

  int cnt = 0;
  for (int x = 0; x <= k; x++) {
    for (int y = 0; y <= k; y++) {
      int z = s - y - x;
      if (z >= 0 && z <= k) {
        cnt++;
      }
    }
  }

  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var NL = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = NL[0];
            var L = NL[1];
            var SList = Enumerable.Range(0, N).Select(_ => Console.ReadLine());

            var output = string.Join("", SList.OrderBy(x => x));

            Console.WriteLine(output);
        }

        static int SumOfDigits(int x)
        {
            var sum = 0;
            while (x > 0)
            {
                sum += x % 10;
                x /= 10;
            }

            return sum;
        }
    }
}


Measured memory_bytes: 13664
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define ll              long long
#define dd              double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define vi              vector<int>
#define vll             vector<long long>
#define vdd             vector<double>
#define vpii            vector<pair<int,int>>
#define vpll            vector<pair<long long,long long>>
#define vvi             vector<vector<int>>
#define vvll            vector<vector<long long>>
#define mii             map<int,int>
#define mll             map<long long,long long>
#define umii            unordered_map<int,int>
#define umll            unordered_map<long long,long long>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep2(i,a,b)     for(int i=a;i<b;i++)
#define rev(i,n)        for(int i=n;i>=0;i--)
#define rev2(i,a,b)     for(int i=a;i>=b;i--)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             9e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define wh(x)           int x; cin>>x; while(x--)
#define fio             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl            '\n'
#define all(x)          x.begin(),x.end()
#define d0(x)           cout <<x<<" "
#define d1(x)           cout <<x<<endl
#define d2(x,y)         cout <<x<<" "<<y<<endl
#define d3(x,y,z)       cout <<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w)     cout <<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define read2(x,y)      cin>>x>>y
#define read3(x,y,z)    cin>>x>>y>>z
#define read4(x,y,z,w)  cin>>x>>y>>z>>w
#define read5(x,y,z,w,a)cin>>x>>y>>z>>w>>a
#define sz(a)           (int)a.size()
#define deb(x)          cout <<#x << " is "<<x<<endl;
const ll mod=1e9+7;
const double PI = 3.14159265359;
const ll MOD=998244353;
void i_o()
{
   #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   #endif
}

ll help(vll& A){
  ll n=A.size()-1;
 // ll tot=0;
  if(n==0){
    if(A[0]==1){
      return 1;
    }
    return -1;
  }
  if(A[0]!=0) return -1;
  //d1("OK");ll
  ll ma=LLONG_MAX/2;
  ll x=1,i=0,tot=0;
  vll upmax(n+1,1);
  for(i=1;i<=n;i++){
    ll iss=2*x;
    if(iss>ma) iss=ma;
    upmax[i]=iss;
    //deb(upmax[i]);
    //tot+=iss;
    if(A[i]>iss){
   //   d1("here");
      return -1;
    }
    x=iss-A[i];
   // deb(x);
  }
  //if(2*x<A[n]) return -1;
  ll prev=A[n];
  tot=A[n];
 // d1("sure");
  if(prev==0) return -1;
  for(int i=n-1;i>=0;i--){
   // ll x_mi=ceil(((dd)(prev+2*A[i]))/2);
    ll x_ma=min(upmax[i],prev+A[i]);
    if(x_ma<A[i]) return -1;
   // x_ma=max(x_ma,x_mi);
        //if(x_mi>x_ma) return -1;
    tot+=x_ma;
    prev+=A[i];
   // if(x_ma==0) return -1;
  }
  return tot;
}
int main(){
  fio
  i_o();
  int n;
  cin>>n;
  vll A(n+1);
  rep(i,n+1) cin>>A[i];
  d1(help(A));
  return 0;
}


Measured memory_bytes: 4796
#include "bits/stdc++.h"

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

int V, E;
vector<vector<int>> g(10000), rg(10000);
vector<int> vs; // 帰りがけ順の並び
vector<bool> used(10000, false);
vector<int> cmp(10000); // 属する強連結成分のトポロジカル順序

void add_edge(int from, int to)
{
    g[from].push_back(to);
    rg[to].push_back(from);
}

void dfs(int cur)
{
    used[cur] = true;
    for (const auto &v : g[cur])
    {
        if (!used[v])
            dfs(v);
    }
    vs.push_back(cur);
}

void rdfs(int cur, int k)
{
    used[cur] = true;
    cmp[cur] = k;
    for (const auto &v : rg[cur])
    {
        if (!used[v])
            rdfs(v, k);
    }
}

int scc()
{
    for (int i = 0; i < V; i++)
        used[i] = false;
    vs.clear();
    for (int v = 0; v < V; v++)
    {
        if (!used[v])
            dfs(v);
    }
    for (int i = 0; i < V; i++)
        used[i] = false;
    int k = 0;
    for (int i = (int)vs.size() - 1; i >= 0; i--)
    {
        if (!used[vs[i]])
            rdfs(vs[i], k++);
    }
    return k;
}

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

    cin >> V >> E;
    for (int i = 0; i < E; i++)
    {
        int s, t;
        cin >> s >> t;
        add_edge(s, t);
    }
    scc();
    int Q;
    cin >> Q;
    for (int i = 0; i < Q; i++)
    {
        int u, v;
        cin >> u >> v;
        if (cmp[u] == cmp[v])
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
}



Measured memory_bytes: 4692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] arrx = new long[N];
        long[] arry = new long[N];
        long[] arrh = new long[N];
        int si = -1;
        for(int i = 0; i < N; i++) {
            arrx[i] = sc.nextLong();
            arry[i] = sc.nextLong();
            arrh[i] = sc.nextLong();
            if(arrh[i] > 0) si = i;
        }

        long resx = -1, resy = -1, resh = -1;
        for(long x = 0; x <= 100; x++) {
            for(long y = 0; y <= 100; y++) {
                long H = arrh[si] + Math.abs(x-arrx[si]) + Math.abs(y-arry[si]);
                boolean ok = true;
                for(int i = 0; i < N; i++) {
                    if(arrh[i] > 0 && H != arrh[i] + Math.abs(x-arrx[i]) + Math.abs(y-arry[i]))
                        ok = false;
                    if (arrh[i] == 0 && H > Math.abs(x - arrx[i]) + Math.abs(y - arry[i]))
                        ok = false;
                }
                if(ok) {
                    resx = x;
                    resy = y;
                    resh = H;
                }
            }
        }
        System.out.println(resx + " " + resy + " " + resh);
    }
}


Measured memory_bytes: 40124
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main(){
    ll d,t,s;cin>>d>>t>>s;
    ll len = t*s;
    if(d>len)cout <<"No";
    else cout<<"Yes";

}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
char str[1000000];
char str1[1000000];
int main()
{
    long long i,j,k,w,l,m,n;
    scanf("%s",str);
    l=strlen(str);
    scanf("%lld",&w);
    k=1;
    j=0;
    for(i=0;i<l;i++)
    {
        if(k==1)
        {
            str1[j]=str[i];
            j++;
        }
        k++;
        if(k>w)
        {
            k=1;
        }
    }
    printf("%s",str1);
    return 0;
}

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

int main(void) {
	string s[3];
	for (int i = 0;i<3;i++) 
		cin >> s[i];
	for (int i = 0;i < 3;i++)
		cout << s[i][i];
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <bitset>
#include <vector>
#include <queue>
#include <map>
#include <set>

#define i64 int64_t
#define ff(ii,nn,mm) for(int ii=nn;ii<mm;ii++)
#define st(vvv) sort(vvv.begin(),vvv.end())
#define rvs(vvv) reverse(vvv.begin(),vvv.end())
int inf = 1000000007;

using namespace std;

int main() {
	int a[9];
	ff(i, 0, 9) {
		a[i] = 0;
	}
	int n;
	cin >> n;
	ff(i, 0, n) {
		int x;
		cin >> x;
		if (x < 400)a[0]++;
		else if (x < 800)a[1]++;
		else if (x < 1200)a[2]++;
		else if (x < 1600)a[3]++;
		else if (x < 2000)a[4]++;
		else if (x < 2400)a[5]++;
		else if (x < 2800)a[6]++;
		else if (x < 3200)a[7]++;
		else a[8]++;
	}
	int min = 0;
	int max = 0;
	ff(i, 0, 8) {
		if (a[i] > 0) {
			min++;
			max++;
		}
	}
	if (a[8] > 0 && min == 0) min++;
	max += a[8];
	cout << min << " " << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {

    int N, M;
    int A[10000];

    int i;

    int homeworkday;
    int answer;

homeworkday = 0;

scanf("%d %d", &N, &M);

for(i = 0; i < M; i++) {
scanf("%d", &A[i]);

homeworkday += A[i];
}
    
answer = N - homeworkday;

if(answer < 0) printf("-1\n");
else printf("%d\n", answer);

return 0;

}

Measured memory_bytes: 1692