akhauriyash/Code-Regression huggingface dataset:
from math import ceil

N = int(input())

Cs = []
Ss = []
Fs = []
for j in range(N - 1):
    C, S, F = map(int, input().split())
    Cs += [C]
    Ss += [S]
    Fs += [F]

Ts = [0] * N

for iSt in range(N - 1):
    for j in range(iSt + 1):
        if Ts[j] <= Ss[iSt]:
            Ts[j] = Ss[iSt] + Cs[iSt]
        else:
            Ts[j] = Ss[iSt] + ceil((Ts[j] - Ss[iSt]) / Fs[iSt]) * Fs[iSt] + Cs[iSt]

for T in Ts:
    print(T)


Measured memory_bytes: 3188
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <map>
#include <numeric>
#include <cmath>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <complex>
#include <string.h>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <iomanip>
#include <sys/time.h>
#include <random>
using namespace std;

#define endl '\n'
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define UNIQ(v) (v).erase(unique((v).begin(), (v).end()), (v).end())
#define int long long

typedef long double ld;
typedef pair<int, int> P;
typedef complex<double> comp;
typedef vector< vector<ld> > matrix;
struct pairhash {
public:
    template<typename T, typename U>
    size_t operator()(const pair<T, U> &x) const {
	size_t seed = hash<T>()(x.first);
	return hash<U>()(x.second) + 0x9e3779b9 + (seed<<6) + (seed>>2);
    }
};
const int inf = 1e9 + 9;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
const double pi = acos(-1);

int n, m;
int x[100010];

int solve() {
    vector<int> md[100010];
    sort(x, x+n);
    int idx = 0;
    while (idx < n) {
        int c = 0;
        while (idx+c < n && x[idx] == x[idx+c]) c++;
        md[x[idx]%m].push_back(c);
        idx += c;
    }
    int res = 0;
    int z = 0;
    for (int i = 0; i < md[0].size(); i++) z += md[0][i];
    res += z / 2;
    if (m % 2 == 0) {
        int h = m / 2;
        z = 0;
        for (int i = 0; i < md[h].size(); i++) z += md[h][i];
        res += z / 2;
    }

    int p[2];
    int sum[2];
    for (int i = 1; i <= m/2; i++) {
        if (i == m-i) break;
        p[0] = p[1] = 0;
        sum[0] = sum[1] = 0;
        for (int j = 0; j < md[i].size(); j++) {
            p[0] += (md[i][j]%2);
            sum[0] += md[i][j];
            res += md[i][j] / 2;
        }
        for (int j = 0; j < md[m-i].size(); j++) {
            p[1] += (md[m-i][j]%2);
            sum[1] += md[m-i][j];
            res += md[m-i][j] / 2;
        }

        int k = (p[0] > p[1] ? 0 : 1);
        res += p[1-k];
        sum[1-k] -= p[1-k];
        p[k] -= p[1-k];
        res += min(p[k], sum[1-k]) / 2;
    }
    return res;
}

void input() {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> x[i];
}

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

    input();
    cout << solve() << endl;
}


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

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

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

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

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

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

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

  vector<int> v(3);
  rep(i, 3) { cin >> v[i]; }
  int k;
  cin >> k;

  sort(all(v), greater<int>());

  int ans = v[0] * pow(2, k) + v[1] + v[2];

  cout << ans << endl;

  return 0;
}

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<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
typedef complex<ld> Point;
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++)
const ld eps = 1e-6;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;

vector<int> G[1 << 17];

const ll t = 999999937;
const ll m = mod+2;

vector<ll> h;

void dfs(int v, int fr) {
	h[v] = 0;
	rep(j, G[v].size()) {
		int to = G[v][j];
		if (to == fr)continue;
		dfs(to, v);
		h[v] += h[to];
		if (h[v] >= m)h[v] -= m;
	}
	h[v] = (h[v] * t+1)%m;
}

void solve() {
	int n; cin >> n;
	rep(i, n - 1) {
		int a, b; cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	h.resize(n);
	dfs(0, -1);
	sort(h.begin(), h.end());
	ll ans = 0;
	rep(i, h.size()) {
		int le = i;
		while (i + 1 < n&&h[i + 1] == h[i])i++;
		ll len = i - le + 1;
		ans += len * (len - 1) / 2;
	}
	cout << ans << endl;
}

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


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

int main() {
  int N;
  cin >> N;
  vector<int>data(N);
  for(int i=0;i<N-1;i++){
    int x;
    cin >> x;
    data.at(x-1)++;
  }
  for(int i=0;i<N;i++){
    cout << data.at(i) << endl;
  }
}

Measured memory_bytes: 4044
N, K = list(map(int, input().split()))
h_list = list(map(int, input().split()))
dp_list = [float("inf")] * N
dp_list[0] = 0

for i in range(1, N):
    # j番目の足場からi番目の足場に飛ぶ

    for j in range(max(i - K, 0), i + 1):

        # j番目の足場までの最適コスト
        cum_cost = dp_list[j]

        # j番目の足場から飛んだ場合のコスト
        cost = dp_list[j] + abs(h_list[j] - h_list[i])

        # 最適コストで更新
        dp_list[i] = min(dp_list[i], cost)

ans = dp_list[-1]
print(ans)


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

int main(){
  int n; cin >> n;
  int ans=0;
  int mx=0;
  int tmp;
  for(int i=0;i<n; i++){
    cin >> tmp;
    if(mx<=tmp){ans++;mx = tmp;}
  }
  cout << ans << endl;
}

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

int N, M;
vector<vector<int>> G;
int ans;

void dfs(int v, vector<int> V) {
  if (accumulate(V.begin(), V.end(), 0) == N - 1) {
    ans++;
    return;
  }
  V.at(v) = 1;
  for (auto g : G.at(v)) {
    if (V.at(g)) continue;
    dfs(g, V);
  }
}

int main() {
  cin >> N >> M;
  G.resize(N);
  for (int i = 0, a, b; cin >> a >> b; i++) {
    G.at(--a).push_back(--b), G.at(b).push_back(a);
  }
  vector<int> V(N);
  dfs(0, V);
  cout << ans << "\n";
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <iostream>
#include <bits/stdc++.h>
    
    
using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)
#define dout(n) cout<<# n<<" = "<<n<<endl;
    
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<vector<ll>> dp(10);
    FOR(i,1,10)dp[0].push_back(i);
    FOR(i,0,9){
        FOR(j,0,dp[i].size()){
            ll r = dp[i][j]%10;
            ll x = dp[i][j]*10;
            if(r==0){
                dp[i+1].push_back(x+0);
                dp[i+1].push_back(x+1);                
            }
            else if(r == 9){
                dp[i+1].push_back(x+8);
                dp[i+1].push_back(x+9);                
            }
            else{
                dp[i+1].push_back(x+r-1);
                dp[i+1].push_back(x+r);
                dp[i+1].push_back(x+r+1);                
            }
        }
        sortAl(dp[i+1]);
    }

    ll x = 0;
    FOR(i,0,10){
        FOR(j,0,dp[i].size()){
            x++;
            if(x==n){
                cout<<dp[i][j]<<endl;
                return 0;
            }
        }
    }

}

Measured memory_bytes: 1976
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define maxn 100005
#define Mod 1000000007
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef set<int> si; 
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const ll ML = 4e18;

void solve() {
    int n;
    cin >> n;
    vll a(n);
    fori(i,0,n) cin >> a[i];
    int ans = 0;
    fori(i,0,n) {
        if(i % 2 == 0 && a[i] % 2) ans++;
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
    solve();
    
    /*clock_t start,finish;
    start = clock();
   
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


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

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<char>> data(h + 2, vector<char>(w + 2, '#'));
  for (int i = 0; i < h + 2; i++) {
    for (int j = 0; j < w + 2; j++) {
      if ((1 <= i) && (i <= h ) && (1 <= j) && (j <= w)) {
        cin >> data.at(i).at(j);
      }
      cout << data.at(i).at(j);
      if (j == w + 1) {
        cout << endl;
      }
    }
  }  
}


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

const int INF = 1E+9+1;

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

    int c[10][10];
    rep(i, 10) rep(j, 10) cin >> c[i][j];
    rep(k, 10) rep(i, 10) rep(j, 10) c[i][j] = min(c[i][j], c[i][k]+c[k][j]);

    int ai, ans=0;
    rep(h, H) rep(w, W) {
        cin >> ai;
        if (ai==-1) continue;
        ans += c[ai][1];
    }

    cout << ans << endl;

    return 0;
}



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

using namespace std; 

const int MAX_N = 100005;

int r[MAX_N]; 
int n, m; 

int main () {
	//freopen("input.txt", "r", stdin); 
	//freopen("output.txt", "w", stdout); 

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

	for (int i = 1; i <= n; i++) {
		r[i] = MAX_N; 
	}

	for (int i = 1; i <= m; i++) {
		int a, b; 
		scanf("%d %d", &a, &b); 
		r[a] = min(r[a], b - 1); 
	}

	int maxR = -1; 
	int res = 0; 

	for (int i = 1; i <= n; i++) {
		if (r[i] != MAX_N) {
			if (maxR < i) {
				maxR = r[i]; 
				res++; 
			}
			else {
				maxR = min(maxR, r[i]); 
			}
		}
	}

	printf("%d", res); 
	return 0; 
}

Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define OUT(x)                cout << #x << " = " << x << endl
#define rep(i, n)             for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r)          for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r)          for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define all(x)                (x).begin(), (x).end()
#define rall(x)               (x).rbegin(), (x).rend()
template<typename T> void pv(T a, T b) { for (T i = a; i != b; i ++) cout << *i << " "; cout << endl; }
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }
int in() { int x; scanf("%d", &x); return x; }
long long lin() { long long x; scanf("%lld", &x); return x; }

#define int long long
int dp[55][5050];

signed main() { 
        int n, a;
        cin >> n >> a;
        vector<int> x(n);
        rep(i, n) {
                cin >> x[i];
                x[i] -= a;
        }
        dp[0][2500] = 1;
        rer(i, 1, n) rep(j, 5050) {
                dp[i][j] += dp[i - 1][j];
                if (j >= x[i - 1]) {
                        dp[i][j] += dp[i - 1][j - x[i- 1]];
                }
        }
        cout << dp[n][2500] - 1 << endl;
        return 0;
}               



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

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int current = 0;
  for (int i = 0; i < n; ++i) {
  	if (a[i] == current + 1)
      current++;
  }
  cout << (current == 0 ? -1 : n - current);
}

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-
"""
B - Roller Coaster
https://atcoder.jp/contests/abc142/tasks/abc142_b

"""
import sys


def solve(N, K, heights):
    return sum(1 for h in heights if h >= K)


def main(args):
    N, K = map(int, input().split())
    heights = [int(h) for h in input().split()]
    ans = solve(N, K, heights)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 11892
#include <bits/stdc++.h>
#define fi first
#define se second
#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(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#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 pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 3005;

int main(){
    int n, k;
    cin >> n >> k;
    vi x(n);
    rep(i, n){
        cin >> x[i];
    }
    int ans = INF;
    for(int i=0;i<n-k+1;i++){
        int left = x[i];
        int right = x[i+k-1];
        int tmp = right - left;
        if(left<0 && right>0){
            tmp += min(abs(left), abs(right));
        }
        if(left<0 && right<0){
            tmp += abs(right);
        }
        if(left>0 && right>0){
            tmp += left;
        }
        
        ans = min(ans, tmp);
    }

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

Measured memory_bytes: 640
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  vector<pair<ll, int> > x(N), y(N);
  ll tmpx, tmpy;
  for(int i=0;i<N;++i) {
    cin>>tmpx>>tmpy;
    x[i] = mp(tmpx, i);
    y[i] = mp(tmpy, i);
  }
  sort(x.begin(), x.end());
  sort(y.begin(), y.end());
  vector<vector<pair<int, ll> > > edge(N);
  for(int i=1;i<N;++i) {
    edge[x[i].se].push_back(mp(x[i-1].se, x[i].fi-x[i-1].fi));
    edge[x[i-1].se].push_back(mp(x[i].se, x[i].fi-x[i-1].fi));
    edge[y[i].se].push_back(mp(y[i-1].se, y[i].fi-y[i-1].fi));
    edge[y[i-1].se].push_back(mp(y[i].se, y[i].fi-y[i-1].fi));
  }
  map<int, int> amap;
  priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > que;
  que.push(mp(0, 0));
  pair<ll, int> state;
  ll ans = 0;
  while(!que.empty()) {
    state = que.top();que.pop();
    if(amap[state.se]!=0) continue;
    ans += state.fi;
    amap[state.se] = 1;
    for(int i=0;i<edge[state.se].size();++i) {
      if(amap[edge[state.se][i].fi]!=0) continue;
      que.push(mp(edge[state.se][i].se, edge[state.se][i].fi));
    }
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 22948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	vector<ll>ch;
	while(n!=0){
		n--;
		ch.push_back(n%26);
//		cout << n%26<<endl;
		n=n/26;
	}
	reverse(ch.begin(),ch.end());
	for(ll i=0;i<ch.size();i++){
		cout <<char(ch[i]+'a');
	}
	// your code goes here
	return 0;
}

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

int cmp(const void *x, const void *y) {
  return *(int *)x - *(int *)y;
}

int main() {
  int N;
  scanf("%d", &N);
  int *d;
  d = (int *)malloc(sizeof(int) * N);
  int i;
  for(i = 0; i < N; i++) scanf("%d", &d[i]);
  qsort(d, N, sizeof(int), cmp);
  // for(i = 0; i < N; i++) printf("%d\n", d[i]);
  int mid = N / 2;
  printf("%d\n", d[mid] - d[mid - 1]);
  return 0;
}


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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;
using vii=vector<vector<int>>;

const ll LINF=1LL<<60;
const int INF=1<<29;
const int MOD=1e9+7;

vii cup;
int n, m;

ll solve(int tray){
    ll res=0;
    vii tmp=cup;
    for(int i=1; i<=n; i++){
        int pos;
        for(int j=0; j<3; j++){
            if(tmp[j].empty()) continue;
            if(tmp[j].back() == i){
                pos=j;
                tmp[j].pop_back();
                break;
            }
        }
        if(pos == tray) continue;
        else if(abs(pos-tray) == 1){
            res+=pow(3, n-i);
            tray=tray==0?2:0;
        }
        else{
            res+=pow(3,n-i)*2;
        }
        if(res > m) break;
    }
    return res;
}

int main(){
    while(1){
        cin >> n >> m;
        if(n == 0 && m == 0) break;
        cup.assign(3, vi(0));
        for(int i=0; i<3; i++){
            int c; cin >> c;
            cup[i].resize(c);
            for(auto &x : cup[i]) cin >> x;
            reverse(all(cup[i]));
        }

        ll ans=solve(0);
        ans=min(ans, solve(2));
        if(ans > m) cout << -1 << endl;
        else cout <<ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3224
#include <cstdio>
#include <cstring>
const int Maxn=600;
const int D[4][2]={{1,1},{1,-1},{-1,1},{-1,-1}};
int n,d[2];
int step[2][2][Maxn*Maxn+5];
int len[2];
int num[5];
int col[2][Maxn+5][Maxn+5];
void dfs(int k,int x,int y,int c){
	if(x<1||y<1||x>n||y>n||col[k][x][y]!=-1){
		return;
	}
	col[k][x][y]=c;
	for(int i=1;i<=len[k];i++){
		for(int j=0;j<4;j++){
			dfs(k,x+D[j][0]*step[k][0][i],y+D[j][1]*step[k][1][i],c^1);
		}
	}
}
int main(){
	scanf("%d%d%d",&n,&d[0],&d[1]);
	n<<=1;
	for(int k=0;k<2;k++){
		for(int i=0;i<=n;i++){
			for(int j=0;j<=n;j++){
				if(i*i+j*j==d[k]){
					step[k][0][++len[k]]=i;
					step[k][1][len[k]]=j;
				}
			}
		}
	}
	memset(col,-1,sizeof col);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			dfs(0,i,j,0);
			dfs(1,i,j,0);
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			num[col[1][i][j]<<1|col[0][i][j]]++;
		}
	}
	int tmp;
	for(int i=0;i<4;i++){
		if(num[i]>=(n*n>>2)){
			tmp=i;
		}
	}
	int sz=0;
	for(int i=1;i<=n&&(sz<(n*n>>2));i++){
		for(int j=1;j<=n&&(sz<(n*n>>2));j++){
			if((col[1][i][j]<<1|col[0][i][j])==tmp){
				sz++;
				printf("%d %d\n",i-1,j-1);
			}
		}
	}
	return 0;
}


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

namespace _1160
{
    class Program
    {
        static bool[,] map;
        static void bfs(int x,int y)
        {
            map[x,y] = false;
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (map[x + i,y + j]) bfs(x + i,y + j);
                }
            }
        }
        static void Main(string[] args)
        {
            while (true)
            {
                int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
                if (x.Max() == 0) break;
                map = new bool[x[1] + 2,x[0] + 2];
                for (int i = 0; i < x[1]; i++)
                {
                    int[] a = Console.ReadLine().Split().Select(int.Parse).ToArray();
                    for (int j = 0; j < x[0]; j++)
                    {
                        map[i + 1,j + 1] = a[j] == 1;
                    }
                }
                int ret = 0;
                for (int i = 0; i < x[1]; i++)
                {
                    for (int j = 0; j < x[0]; j++)
                    {
                        if (map[i + 1,j + 1])
                        {
                            ret++;
                            bfs(i + 1,j + 1);
                        }
                    }
                }
                Console.WriteLine(ret);
            }
        }
    }
}


Measured memory_bytes: 9964
#include<stdio.h>
#include<math.h>
int main()
{
	int n,a,i;
	long long int sum,sub;
	sum=1;
	sub=1;
	scanf("%d",&n);
	for (i=1;i<=n;i++)
	{
		sum=sum*3;
		scanf("%d",&a);
		if (a%2==0)
			sub=sub*2;
	}
	printf("%lld\n",sum-sub);
	return 0;

	


}

Measured memory_bytes: 128
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n, = map(int,readline().split())

s = read().split()
res = [100]*26

for i in s:
    num = [0]*26
    for j in i:
        num[ord(j)-ord("a")] += 1
    
    for j in range(26):
        res[j] = min(res[j],num[j])



ans = ""
for i in range(26):
    if res[i] != 100:
        ans += chr(ord("a")+i)*res[i]

print(ans)

Measured memory_bytes: 9152
#include<bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
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; }


vector<vector<int>> G(300010);
vector<int> d(300010, -1);
vector<int> used(300010, 0);

int main(){
    int N, M, S, T;
    cin >> N >> M;
    for(int i = 0;i < M;i++){
        int u, v;
        cin >> u >> v;
        u--;    v--;
        G[3*u].push_back(3*v+1);
        G[3*u+1].push_back(3*v+2);
        G[3*u+2].push_back((3*v));
    }
    cin >> S >> T;
    S--;    T--;
    queue<int>  que;
    que.push(3*S);
    d[3*S] = 0;
    used[3*S] = 1;
    while(!que.empty()){
        int u = que.front();
        que.pop();
        for(auto s : G[u]){
            if(!used[s]){
                d[s] = d[u]+1;
                used[s] = 1;
                que.push(s);
            }
        }
    }
    if(d[3*T] == -1)   cout << -1 << endl;
    else    cout << (d[3*T]/3) << endl;
}

Measured memory_bytes: 21984
""""
3 5
...#.
.#.#.
.#...
"""
from collections import deque
import numpy as np

H, W = map(int, input().split())
Map = [list(input()) for i in range(H)]


def make_wall(W, Map):
    for map_row in Map:
        map_row.append("#")
        map_row.insert(0, "#")

    wall = ["#"]*(W+2)
    Map.append(wall)
    Map.insert(0, wall)
    return Map


start_list = deque()
search_list = deque()
Map = make_wall(W, Map)
H += 2
W += 2

start_h = 0
for h in range(H):
    start_w = 0
    for w in range(W):
        if Map[h][w] == ".":
            start_list.append([start_h, start_w])
        start_w += 1
    start_h += 1



max_cost = 0
while start_list != deque():
    search_list.append(start_list.popleft())
    cost_map = np.array([[0] * W for i in range(H)])
    search_map = np.array([[0] * W for i in range(H)])

    while search_list != deque():
        tmp = search_list.popleft()
        x = tmp[0]
        y = tmp[1]
        search_map[x][y] = 1
        if Map[x][y+1] == "." and search_map[x][y+1] == 0 and [x, y+1] not in search_list:
            search_list.append([x, y+1])
            cost_map[x][y+1] = cost_map[x][y]+1
        if Map[x][y-1] == "." and search_map[x][y-1] == 0 and [x, y-1] not in search_list:
            search_list.append([x, y-1])
            cost_map[x][y-1] = cost_map[x][y]+1
        if Map[x+1][y] == "." and search_map[x+1][y] == 0 and [x+1, y] not in search_list:
            search_list.append([x+1, y])
            cost_map[x+1][y] = cost_map[x][y]+1
        if Map[x-1][y] == "." and search_map[x-1][y] == 0 and [x-1, y] not in search_list:
            search_list.append([x-1, y])
            cost_map[x-1][y] = cost_map[x][y]+1
    cost_map = np.array(cost_map)
    if max_cost < np.amax(cost_map):
        max_cost = np.amax(cost_map)

print(max_cost)

Measured memory_bytes: 12080
import sys
sys.setrecursionlimit(10 ** 5 + 10)


def input(): return sys.stdin.readline().strip()


def resolve():

    H, N = map(int, input().split())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, input().split())

    INF = 10**10  # INF+INFを計算してもオーバーフローしない範囲で大きく

    I, J = N, H
    # dpテーブル dp[i][j]:=i番目以下でjのダメージを与えるための最小コスト
    dp = [[INF]*(J+1) for _ in range(I+1)]
    # 初期条件
    for i in range(I):
        dp[i][0] = 0
    # ループ
    for i in range(I):
        for j in range(J+1):

            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            dp[i+1][min(j+A[i], J)] = min(dp[i+1]
                                          [min(j+A[i], J)], dp[i+1][j]+B[i])

    print(dp[I][J])


resolve()

Measured memory_bytes: 119664
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,h,w;
	scanf("%d%d%d%d",&n,&m,&h,&w);
	int k=1000000000/h/w;
	long long ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(i%h==0&&j%w==0)	ans-=(h*w-1)*k+1;
			else	ans+=k;
	if(ans<=0)	puts("No");
	else{
		puts("Yes");
		for(int i=1;i<=n;i++){
			for(int j=1;j<=m;j++)
				if(i%h==0&&j%w==0)	printf("%d ",-(h*w-1)*k-1);
				else	printf("%d ",k);
			putchar('\n');
		}
	}
	return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;

int main() {
	int N, M;
	cin>>N>>M;
	int p[N];
	for(int i=0;i<N;++i){
		cin>>p[i];
		p[i]--;
	}
	int x[M], y[M];
	for(int i=0;i<M;++i){
		cin>>x[i]>>y[i];
		x[i]--;
		y[i]--;
	}
	map<int, int> deta;
	int ans = 0;
	for(int i=0;i<M;++i){
		deta[x[i]]++;
		deta[y[i]]++;
	}
	/**
	for(int i=0;i<N;++i){
		if(deta[i]==0 & p[i]==i){
			ans++;
		}
	}
	**/

	vector<vector<int> > arr1;
	vector<int>tmparr1;
	for(int i=0;i<N;++i){
		arr1.push_back(tmparr1);
	}
	for(int i=0;i<M;++i){
		arr1[x[i]].push_back(y[i]);
		arr1[y[i]].push_back(x[i]);
	}

	queue<int> que;
	vector<vector<int> > arr;
	vector<int> tmparr;
	int state;
	map<int, int> statemap;
	for(int i=0;i<N;++i){
		if(statemap[i]!=0)continue;
		tmparr.clear();
		statemap[i]++;
		que.push(i);
		tmparr.push_back(i);
		while(!que.empty()){
			state = que.front();
			que.pop();
			for(int j=0;j<arr1[state].size();++j){
				if(statemap[arr1[state][j]] != 0)continue;
				else {
					statemap[arr1[state][j]]++;
					que.push(arr1[state][j]);
					tmparr.push_back(arr1[state][j]);
				}
			}
		}
		sort(tmparr.begin(), tmparr.end());
		arr.push_back(tmparr);
	}
	/**
	for(int i=0;i<arr.size();++i){
		for(int j=0;j<arr[i].size();++j){
			cout<<arr[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	**/
	vector<vector<int> >arr2;
	vector<int> tmparr2;
	for(int i=0;i<arr.size();++i){
		tmparr2.clear();
		for(int j=0;j<arr[i].size();++j){
			tmparr2.push_back(p[arr[i][j]]);
		}
		sort(tmparr2.begin(), tmparr2.end());
		arr2.push_back(tmparr2);
	}
	/**
	for(int i=0;i<arr2.size();++i){
		for(int j=0;j<arr2[i].size();++j){
			cout<<arr2[i][j]<<" ";
		}
		cout<<endl;
	}
	cout<<endl;
	**/
	int index, index2;
	for(int i=0;i<arr.size();++i){
		index = 0;
		index2 = 0;
		while(index<arr[i].size() & index2<arr2[i].size()){
			if(arr[i][index]==arr2[i][index2]){
				ans++;
				index++;
				index2++;
			}
			else if(arr[i][index] > arr2[i][index2]){
				index2++;
			}
			else {
				index++;
			}
		}
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 20720
<?php

fscanf(STDIN, "%d", $N);
$xs = explode(' ', fgets(STDIN));
$ys = explode(' ', fgets(STDIN));

$ans = 0;
foreach(range(0,$N-1) as $i){
    $t = $ys[$i];
    $x = min($xs[$i], $t);
    $t -= $x;
    $ans += $x;

    $x = min($xs[$i+1], $t);
    $xs[$i+1] -= $x;
    $ans += $x;
}

echo $ans . "\n";

?>

Measured memory_bytes: 25072
n=int(input())
_list=[0]
for i in range(n):
  _list.append(int(input()))

tmp=1
count=0
while(1):
  tmp=_list[tmp]
  count+=1
  if(tmp==2):
    print(count)
    break
  if(tmp==1 or n<count):
    print(-1)
    break

Measured memory_bytes: 7080
#include<cstdio>
using namespace std;
int main()
{
	int n,i,a[100],b[100],sum;
	scanf("%d",&n);
	for(i=0;i<n-1;i++)	scanf("%d",&b[i]);
	a[0]=b[0];
	for(i=0;i<n-1;i++){
		a[i+1]=b[i];
		if(b[i]<a[i])	a[i]=b[i];
	}
	sum=0;
	for(i=0;i<n;i++)	sum+=a[i];
	printf("%d\n",sum);
	return 0;
}


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

int main(){ 
  string S,T,U;
  int a, b;
  cin >> S >> T;
  cin >> a >> b;
  cin >> U;
  
  if (U == S) a--;
  else b--;
  
  cout << a << " " << b << endl;

}

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



int gcd(int a,int b){
  int bigger=max(a,b);
  int smaller=min(a,b);
  
  if (bigger%smaller==0){
    return smaller;
  }
  
  else {
    return gcd(bigger%smaller,smaller);
  }
}












int main(){


  int n,x;
  cin>>n>>x;
  
  vector<int> data(n);
  

  for (int i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    data.at(i)=abs(x-tmp);
  }
  
  
 
  int answer=data.at(0);
  
  for (int i=1;i<n;i++){
    answer=gcd(answer,data.at(i));
  }
  
  cout<<answer<<endl;
  
               
  
  
  
    
    
      
   
    
  
  
  

    
    
    

  
}

Measured memory_bytes: 640
#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Apr  4 21:00:24 JST 2020
 **/

signed main() {
    Int n, K;
    std::cin >> n >> K;
    std::cout << std::min(n % K, K - n % K) << std::endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
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; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i,n){
        cin >> x[i];
        y[i] = x[i];
    }
    sort(x.begin(), x.end());
    int m1 = x[n/2-1], m2 = x[n/2];
    rep(i,n){
        if(y[i] <= m1) cout << m2 << endl;
        else cout << m1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4736
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main(){
	char W[11], T[1001];
	int i, cnt=0;
	scanf("%s",W);
	while(1){
		scanf("%s",T);
			if(strcmp(T,"END_OF_TEXT")==0) break;
			for(i=0; i<strlen(T);i++){
				if(isupper(T[i])){
				 T[i] = tolower(T[i]);
				}
			}
			if(strcmp(W,T) == 0) {
			   cnt++;
			}
		}
	printf("%d\n",cnt);
	return 0;
	}

Measured memory_bytes: 1772
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;

ll rec(ll n,ll x){
  //cout<<n<<" "<<x<<endl;
  ll res=0;
  if(x==0||n==x)return 0;
  if(n>2*x){
    ll nn=(n-x)%x;
    res=rec(nn+x,x)+3*(n-x-nn);
  }
  else if(n<2*x){
    ll nx=x%(n-x);
    res=rec(nx+n-x,nx)+3*(x-nx);
  }
  else {
    res=3*x;
  }
  return res;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,x;cin>>n>>x;

  cout<<rec(n,x)<<endl;
  return 0;

}


Measured memory_bytes: 256
#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 speed ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long 
#define ull unsigned long long
#define db double
#define vi vector<ll>
#define vvi vector<vector<int> >
#define vvii vector<vector<pii> >
#define rep(i,a,b) for(int i=a;i<b;i++)
#define endl "\n"
#define pii pair<ll,ll>
#define piii pair<ll,pair<ll,ll> >
#define mem(a,b) memset(a , b , sizeof a ) ; 
#define pb push_back
#define pf push_front
#define F first 
#define S second 
#define mp make_pair
#define all(v) v.begin(),v.end()

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}



#define deb1(a) cout<<#a<<"=*"<<a<<endl;
#define deb2(a) cout<<#a<<"=@"<<a<<endl;
#define deb3(a) cout<<#a<<"=#"<<a<<endl;
#define deb4(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;
#define deb5(a,b) cout<<#a<<"="<<a<<" and "<<#b<<"="<<b<<endl;


typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


ll mod=1000000007;
ll vis[212345]={0};
vvi v(212345);
ll d[212345]={0};


ll pow(ll a, ll b, ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}





int main()
{
speed
char c;
cin>>c;
if(c>='A'&&c<='Z') cout<<"A";
else cout<<"a";
}



Measured memory_bytes: 8064
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef unsigned int uint;
using namespace std;

struct record{
  int st = 0;
  int ft = 0;
  int ch = 0;
  bool used = false;
};

int main(){
  int N,C;
  cin >> N >> C;
  pair<pair<int,int>,int> p[N];
  for(int i=0;i<N;i++){
    cin >> p[i].first.first >> p[i].first.second >> p[i].second;
  }
  sort(p,p+N);

  /*cout << endl;
  for(int i=0;i<N;i++){
    cout << p[i].first.first << " " << p[i].first.second << " " << p[i].second << endl;;
  }*/

  record rec[30];

  for(int i=0;i<N;i++){
    for(int j=0;j<30;j++){
      if(p[i].first.first > rec[j].ft){
        rec[j].st = p[i].first.first;
        rec[j].ft = p[i].first.second;
        rec[j].ch = p[i].second;
        rec[j].used = true;
        break;
      }
      else if(p[i].first.first == rec[j].ft && p[i].second == rec[j].ch){
        rec[j].st = p[i].first.first;
        rec[j].ft = p[i].first.second;
        rec[j].ch = p[i].second;
        rec[j].used = true;
        break;
      }
    }
  }

  int cnt = 0;
  for(int j=0;j<30;j++){
    if(rec[j].used) cnt++;
  }

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

Measured memory_bytes: 1408
from math import sqrt
N,M=map(int, input().split())
tmp=int(sqrt(M))
ma=1
for i in range(1, tmp+1):
    if not M % i:
        div = M//i
        ma = max(i if i*N <= M else 0, ma, div if div*N <= M else 0)
print(ma)


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long n;
    cin >>n;
    vector <long long> a(n+1);
    vector <long long> dp(n+1);
    
    for (int i = 1; i<=n; i++){
        cin>>a[i];
    }
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
        for(int i = 3;i<=n;i++){
    dp[i]=min(dp[i-1] + abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    }
    
    cout<<dp[n];
    
    
    
return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#define REP(i,n) for(int i=0;i<n;i++)
typedef long long ll;
using namespace std;
typedef vector<ll> vl;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;

void reach(int a[][121],int b)//b回目のリーチで行ける場所をb+1に塗りつぶす
{
	int x[6]={-1,-1,0,1,0,1};
	int y[6]={-1,0,-1,0,1,1};
	
	for(int i=0;i<121;i++)
	{
		for(int j=0;j<121;j++)
		{
			if(a[i][j]==b)
			{
				for(int k=0;k<6;k++)
				{
					if(i+x[k]>-1 && i+x[k]<121 && j+y[k]>-1 && j+y[k]<121)
					{
						if(a[i+x[k]][j+y[k]]==0)a[i+x[k]][j+y[k]]=b+1;
					}
				}
			}
		}
	}
}

int main() 
{
	int t,n;
	while(cin>>t>>n&&!(n==0&&t==0))
	{
		int a[121][121]={};//座標は0~60
		REP(i,n){int x,y;cin>>x>>y;a[x+60][y+60]=-1;} //a[x][y]=-1なら障害物あり
		int x,y;cin>>x>>y;a[x+60][y+60]=1;//便宜所スタート地点は1にする。nターン目に行ける場所をn+1で塗りつぶす
		REP(i,t) reach(a,i+1);
		int ans(0);
		REP(i,121)REP(j,121)if(a[i][j]!=0&&a[i][j]!=-1)ans++;
		//REP(i,61){REP(j,61){cout << a[j][60-i]<<" ";}cout<<endl;}
		
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include <iostream>
using namespace std;
 
int main(){
  int x[5];
  for(int i = 0; i < 5; i++){
    cin >> x[i];
  }
  int ans = 0;
  for(int i = 0; i < 5; i++){
    if(x[i] == 0) ans = i+1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(int i=a;i<=b;i++)
#define mm make_pair
#define pi 2*acos(0.0)
#define lcm(a,b) (a*b)/__gcd(a,b)
#define Case(i,ans) cout<<"Case "<<i<<": "<<ans<<endl;
#define cp(i,ans) printf("%.if",ans);
#define cpp(i,ans) cout.precision(i);cout<<fixed<<ans<<endl;
#define Y {cout<<"YES"<<endl;return 0;}
#define pb(x) push_back(x)
#define lowbit(x) (x)&(-x)
#define out(x) {cout<<x<<endl;return 0;} 
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int inf=0x3f3f3f,maxn=2e5+100;
ll gcd(ll x,ll y){if(y==0) return x;else return gcd(y,x%y);} 
ll ksm(ll a,ll b){ll r=1;while(b){if(b&1) r=(r*a)%mod;a=a*a%mod;b>>=1;}return r;} 
int n,x,sum[maxn]; 
int main()
{
	cin>>n>>x;
	int ans=0,tmp=0,flag=0;
	sum[0]=0;
	for(int i=1;i<=n;i++)
	{
		int l;cin>>l;
		sum[i]=sum[i-1]+l;
	}
	for(int i=0;i<=n;i++)
	if(sum[i]<=x) ans++;
	cout<<ans<<endl;
} 

Measured memory_bytes: 256
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#define _GLIBCXX_DEBUG // check []
#define DIVISOR 1000000007

using namespace std;
typedef pair<int,int> pii;
typedef pair<int64_t, int64_t> pII;

template<typename T>
void cins(vector<T>& arr) { for(T& e: arr) cin >> e; }

#ifdef DEBUG
#define debug(fmt, ...) \
    printf("[debug: %s] " fmt, __func__, __VA_ARGS__)
#define ps(arr) \
    for(auto e: arr) cout << e << " "; \
    cout << endl;
#else
#define debug(fmt, ...)
#define ps(arr)
#endif
#define INF (1e+9)

#define _x first
#define _y second

int manh(pii p1, pii p2) {
    return abs(p1._x-p2._x) + abs(p1._y-p2._y);
}
int main(void) {
    int num, ps;
    cin >> num >> ps;
    vector<pii> arr(num);
    for(int i = 0; i < num; i++) {
        int x,y;
        cin >> x >> y;
        arr[i] = make_pair(x, y);
    }
    vector<pii> points(ps);
    for(int i = 0; i < ps; i++) {
        int x, y;
        cin >> x >> y;
        points[i] = make_pair(x,y);
    }

    for(int i = 0; i < num; i++) {
        pii person = arr[i];
        int mmin = INF;
        int argmin = 0;
        for(int j = 1; j <= ps; j++) {
            int nnew = manh(person, points[j-1]);
            if(mmin > nnew) {
                mmin = min(mmin, nnew);
                argmin = j;
            }
        }
        cout << argmin << endl;
    }
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<P,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=4999999996000000001;
ll dp[3001];

ll s(int n){
    if(n<3) return 0;
    if(n<6) return 1;
    if(dp[n]>0) return dp[n];

    ll res=1;
    for(int i=3;i<=n-3;i++){
        res+=s(i);
        res%=MOD;
    }
    dp[n]=res;
    return res;
}

int main(){
    int n;
    cin>>n;
    cout<<s(n)<<endl;
}

Measured memory_bytes: 3128
#include <stdio.h>

int main()
{
    char fore[4], day[4];
    int corr=0;
    scanf("%s%s", fore, day);
    for(int i =0;i<3;++i){
        corr += fore[i] == day[i] ? 1: 0;
    }
    printf("%d", corr);
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pi = pair<ll, ll>;

int n, h, w;
pair<ll, pi> A[100005];
void input() {
    cin >> n >> h >> w;
    for (int i = 0; i < n; i++) {
        ll r, c, a;
        cin >> r >> c >> a;
        A[i] = { a, { r, c } };
    }
}

int P[200005];
int S[200005];
int E[200005];

int find(int x) {
    if (P[x] != x) return P[x] = find(P[x]);
    return x;
}

bool merge(int x, int y) {
    x = find(x);
    y = find(y);
    if (x != y) {
        if (S[x] + S[y] < E[x] + E[y] + 1) return 0;
        P[y] = x;
        S[x] += S[y];
        E[x] += E[y] + 1;
        return 1;
    }
    else {
        if (S[x] < E[x] + 1) return 0;
        E[x]++;
        return 1;
    }
}

void calc() {
    for (int i = 1; i <= h + w; i++) {
        P[i] = i;
        S[i] = 1;
        E[i] = 0;
    }
    sort(A, A + n);
    ll ans = 0;
    for (int i = n; i--; ) {
        ll r, c;
        tie(r, c) = A[i].second;
        if (merge(r, c + h)) ans += A[i].first;
    }
    cout << ans;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    input();
    calc();
    return 0;
}

Measured memory_bytes: 5504
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
int main(){
    double a, b, t;
    cin >> a >> b >> t;
    cout<<int((t+0.5)/a)*b<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <limits.h>

int main(void)
{
    int n;

    scanf("%d", &n);
    while (n) {

        int i, a, max, sum;

        i = sum = 0;
        max = INT_MIN;

        for (; i < n; i++) {
            scanf("%d", &a);
            sum += a;
            if (sum > max)
                max = sum;
            if (sum < 0)
                sum = 0;
        }
        
        printf("%d\n", max);
        scanf("%d", &n);
    }

    return 0;
}


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

int main(){
    string s;
    cin>>s;
    int ans=7;
    if(s[0]=='S'){
        if(s[1]=='U')ans=7;
        else ans=1;
    }
    else if(s[0]=='M')ans=6;
    else if(s[0]=='T'){
        if(s[1]=='U')ans=5;
        else ans=3;
    }
    else if(s[0]=='W')ans=4;
    else ans=2;

    cout<<ans<<endl;

    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    vector<int32> a;
    FORR(i,s.size()-1,0){
        a.pb(s[i] - '0');
    }
    vector<vector<int32>> dp(a.size()+1, vector<int32>(2,0));
    dp[1][0] = a[0];
    dp[1][1] = 10 - a[0];
    FOR(i,1,a.size()){
        dp[i+1][0] = min(dp[i][0] + a[i], dp[i][1] + a[i] + 1);
        dp[i+1][1] = min(dp[i][0] + 10 - a[i], dp[i][1] + 10 - (a[i] + 1));
        // cout << dp[i+1][0] << " " << dp[i+1][1] << endl;
    }
    ANS(min(dp[a.size()][0], dp[a.size()][1]+1));
    return 0;
}

Measured memory_bytes: 64016