akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ll long long
#define PB push_back
#define MP make_pair
#define PF push_front
#define all(v) begin(v), end(v)
#define sz(v) (int)(v).size()
#define ft first
#define sc second

#define FOR(i, a, b) for(int i = (a); i <= (b); i++)
#define REP(i, a, b, c) for(int i = (a); i <= (b); i += (c))
#define FORL(i, a, b) for(int i = (a); i < (b); i++)
#define ROF(i, a, b) for(int i = (a); i >= (b); i--)
#define ROFL(i, a, b) for(int i = (a); i > (b); i--)
#define LLFOR(i, a, b) for(ll i = (a); i <= (b); i++)
#define LLFORL(i, a, b) for(ll i = (a); i < (b); i++)
#define LLROF(i, a, b) for(ll i = (a); i >= (b); i--)
#define LLROFL(i, a, b) for(ll i = (a); i > (b); i--)


using namespace std;

typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;

const int mod = 1e9 + 7;
const double PI = acos(-1);

ll exp(ll x,ll n){
    if(n == 0) return 1;
    if(n == 1) return x;
    if(n%2 == 0) return exp((x*x)%mod,n/2);
    if(n%2 == 1) return (x*exp((x*x)%mod,n/2))%mod;
}

ll modpow(ll b, ll p, ll m)
{
    ll r = 1;
    while(p){
        if(p & 1) r = r*b%m;
        b = b*b%m;
        p /= 2;
    }

    return r;
}

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

    string s;
    cin >> s;

    int len = s.length();

    if(s[len-1] != 's') s += 's';
    else s += "es";

    cout << s;

    return 0;
}


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

using namespace std;

int main(void) {

	int N, D, X;
	int sum = 0, j, k;

	cin >> N >> D >> X;
	
	vector<int> A (N);

	for (int i = 0; i < N; i++) {

		cin >> A[i];

	}

	sum = sum + X;

	for ( j = 0; j < N; j++) {

		k = 1;

		for (int i = 0; k <= D; i++) {

			k = i*A[j] + 1;

			if (k <= D)
				sum++;

		}

	}
	cout << sum << endl;
}

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

template<typename T, typename U> bool chmin(T &a, const U &b) {
	return (a > b ? a = b, true : false);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
	return (a < b ? a = b, true : false);
}

typedef long long ll;

#define writeln(n) cout<<n<<"\n";

typedef pair<int, int> P;
typedef pair<string, int> Psi;


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

	int n;cin>>n;
	int d;cin>>d;
	int tmp = 2*d+1;
	writeln((n+tmp-1)/tmp)
}




Measured memory_bytes: 256
using System;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int k = int.Parse(Console.ReadLine());
            for (int i = 0; i < k; i++)
                Console.WriteLine(Console.ReadLine().Replace("Hoshino", "Hoshina"));
        }
    }
}

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

void solve() {
  int n;
  string s;
  cin >> n;
  vector<int> v(4);
  string v2[] = {"AC x ", "WA x ", "TLE x ", "RE x "};
  rep(i, n) {
    cin >> s;
    if (s == "AC") ++v[0];
    else if (s == "WA") ++v[1];
    else if (s == "TLE") ++v[2];
    else ++v[3];
  }
  rep(i, 4) {
    cout << v2[i] << v[i] << endl;
  }
}

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

Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long

#define INF 1e+9
#define MAX_V 100008
vector<long long>cnt;
vector<long long>ans;
void dfs(vector<vector<int>> & G, int v, int p, long long x){
    ans[v] += x;
    for (auto nv: G[v]){
        if(nv == p) continue;
        dfs(G, nv, v, x + cnt[nv]);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    vector<vector<int>> G(n);
    rep(i, 0, n-1){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    cnt.resize(n);
    ans.resize(n);

    for(int i=0; i<q; i++){
        int p;
        long long x;
        cin >> p >> x;
        p--;
        cnt[p] += x;
    }
    dfs(G, 0, -1, cnt[0]);
    for (int i=0; i<n; i++){
        if(i==0) cout << ans[i];
        else cout << " " << ans[i];
    }
    cout << endl;
}


Measured memory_bytes: 28928
#include <bits/stdc++.h>
using namespace std;
//for(int i = 0; i < n; i++)
 
int main() {
  int n, s = 0, ss = 0, ans = 0;
  cin >> n;
  vector<int> w(n);
  for(int i = 0; i < n; i++) {
    cin >> w.at(i);
    s += w.at(i);
  }
  for(int i = 0; i < n; i++){
    ss += w.at(i);
    if(ss * 2 < s) ;
    else if(ss * 2 == s) break;
    else {
      ans = min(abs(ss * 2 - s), abs((ss - w.at(i)) * 2 - s));
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<string>
using namespace std;
typedef long long int ll;
#pragma GCC optimize "trapv"
#define fi first
#define sec second
#define pb push_back
//#define endl '\n'
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
vector<ll> fact;
void fact_init(int n,int mod=1e9+7){
	int s=0;
	fact.pb(1);
	s++;
	for(s=1;s<=n;s++){
		fact.pb((fact[s-1]*s)%mod);
	}
	return;
}
ll pow_i(ll base,int exp,int mod=1e9+7,bool ok=0){
	if(ok){base%=(mod-1);} // if ok that means mod is a prime so speed up
	ll ans=1;
	while(exp>0){
		if(exp&1){ans*=base;ans%=mod;}
		base*=base;
		base%=mod;
		exp>>=1;
	}
	return ans;
	
}
const int nax=5e5+1;
const int mod=1e9+7;
void solve(){
	int n;
	cin>>n;
	int m;
	cin>>m;
	fact_init(nax);
	ll ans=1;
	ans*=fact[m];
	ans%=mod;
	ll t=pow_i(fact[m-n],mod-2);
	t%=mod;
	t*=t;
	t%=mod;
	ans*=t;
	ans%=mod;
	int sign=1;
	ll temp=0;
	for(int  i=0;i<=n;i++){
		ll val=fact[m-i];
		val%=mod;
		val*=fact[n];
		val%=mod;
		val*=(pow_i(fact[n-i],mod-2))%mod;
		val%=mod;
		val*=pow_i(fact[i],mod-2)%mod;
		val%=mod;
		val*=sign;
		val%=mod;
		if(val<0){val+=mod;}
		temp+=val;
		temp%=mod;
		sign*=-1;
	}
	ans*=temp;
	ans%=mod;
	cout<<ans<<endl;
}
int main(){
	fio;
	int test;
	//cin>>test;
	test=1;
	while(test--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 7388
#include <stdio.h>
int main()
{
	int N,max=0,sum=0,i;
	char a[100];
	scanf("%d",&N);
	scanf("%s",&a);
	for(i=0;i<N;i++){
		if(a[i]=='I'){
			sum++;
			if(sum>max)
			   max=sum;
		}
		else{
			sum--;
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 128
#pragma GCC optimize("Ofast")
#include<stdio.h>
int main(void)
{
  char buf1[400001];
  gets(buf1);
  gets(buf1 + 200000);
  int ans = 0;
  int i = 200000;
  do if(buf1[i - 200000] != buf1[i]) ++ans; while(buf1[++i]);
  printf("%d", ans);
  return 0;
}


Measured memory_bytes: 2000
/// kAAzuki Hoshino
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 998244353
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int n;
int cnt[101010]; 
int modpow(int x, int n, int m) {
    if (n == 0) return 1%m;
    long long u = modpow(x,n/2,m);
    u = (u*u)%m;
    if (n%2 == 1) u = (u*x)%m;
    return u;
}

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
        
    cin >> n;
    int x;
    cin >> x;
    cnt[x]++;
    if(x!=0){
    	cout << 0 << endl;
    	return 0;
    }
    for(int i=2;i<=n;i++){
    	int x;
    	cin >> x;
    	cnt[x]++;
    }
    if(cnt[0]!=1){
    	cout << 0 << endl;
    	return 0;
    }
    int ans = 1;
    for(int i=1;i<=n;i++){
    	if(cnt[i]){
    		if(cnt[i-1]){
    			ans = ans*modpow(cnt[i-1], cnt[i], mod)%mod;
    		}
    		else {
    			ans = 0;
    		}
    	}
    }
    cout << ans << endl;

return 0;
}
///....


Measured memory_bytes: 1024
/*-------------------------------------------------------------------------------------------------------------
//ASHUTOSH K SINGH(Free_Electron_)->Impossible only means that you haven’t found the solution yet
-------------------------------------------------------------------------------------------------------------*/
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MP make_pair
#define all(v) v.begin(),v.end()
const int M=1e9+7;
#define int long long
typedef long long ll;
int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
    y=y>>1;x=(1ll*x*x)%M;} return res;}
int ncr(int n,int r){ int res=1; if(r>n-r)r=n-r; for(int i=0;i<r;i++) {  res*=n-i;  res/=i+1; } return res;}
bool prime(ll n){ll i;for(i=2;i<=sqrt(n);i++){if(n%i==0)return false;}return true;}
/*-------------------------------------------------------------------------------------------------------------
--->FREE_ELECTRON<---         --->ASHUTOSH K SINGH<---          --->AIT PUNE<---          
--------------------------------------------------------------------------------------------------------------*/
int parent[100005];
int size[100005];
int find(int x)
{
  if(x==parent[x])
    return x;
  else
    return parent[x]=find(parent[x]);
}
void uni(int x,int y)
{
  int px=find(x);
  int py=find(y);
  if(px!=py)
  {
    if(size[px]>size[py])
      swap(px,py);
    parent[px]=py;
    size[py]+=size[px];
  }
}
signed main()
{  
   gearup;
   int t=1;
   //cin>>t;
   for(int j=0;j<=100000;j++)
   {
    parent[j]=j;
    size[j]=1;
   }
   while(t--)
   {
    int n,m,i;
    cin>>n>>m;
    int a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i];
    while(m--)
    {
      int x,y;
      cin>>x>>y;
      uni(x,y);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
      if(find(i)==find(a[i]))
        ans++;
    cout<<ans;
   }
  return 0;
}

Measured memory_bytes: 2560
n,m = map(int,input().split())
ks = [list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))

ans = 0
def switch(count,onoff):
    global ans
    if count == n:
  #      print(count,onoff)
        l = 0
        for i,P in zip(ks,p):
            c = 0
            for j in i[1:]:
                c += onoff[j-1]
     #       print(c%2,P)
            if c%2 == P:
                l += 1
   #     print(l)
        if l == m:
            ans += 1
    else:
        count += 1
        switch(count,onoff+[1])
        switch(count,onoff+[0])

switch(0,[])
print(ans)

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

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

#define Omar45 ios_base::sync_with_stdio(false); cin.tie(NULL);
#define ll long long
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define mod 1e9 + 7
const ll maxN = 1e5+5;
const ll inf = 0x3f3f3f3f;

ll weight[maxN], value[maxN], dp[105][maxN];

int main() {
	Omar45
    int N, W; cin >> N >> W;
    for (int i=1; i<=N; i++)
        cin >> weight[i] >> value[i];

    for (int item=1; item<=N; item++) {
        for (int rem=1; rem<=W; rem++){
            ll opt1 = dp[item-1][rem];
            ll opt2 = 0;
            if (rem>=weight[item])
                opt2 += dp[item-1][rem-weight[item]] + value[item];
            dp[item][rem] = max(opt1, opt2);
        }
    }
    cout << dp[N][W] << endl;
}


Measured memory_bytes: 79360
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;
#define int long long int
#define mod 1000000007
int fact[1000001];
void function(){
   
   fact[0]=1;
   int j;
   for(j=1;j<=1000000;j++)
   {
	   fact[j]=(j*fact[j-1])%mod;
   }
}
int power(int a,int b)
{
	if(b==0)
	  return 1;
	else
    {
		int r=power(a,b/2);
		if(b%2==0)
		{
			return (r*r)%mod;
		}
		else
		{
			int x=(r*r)%mod;
			return (a*x)%mod;
		}
	}
}
int ncr(int n,int r)
{
	if(r>n)
	   return 0;
	int answer=fact[n];
	answer*=power(fact[r],mod-2);
	answer%=mod;
	answer*=power(fact[n-r],mod-2);
	answer%=mod;
	return answer;
}
int32_t main()
{
	function();
	int n,m;
	cin>>n>>m;
	int j;
	int y=m;
	map<int,int> mp;
	for(j=2;j*j<=y;j++)
	{
		if(m%j==0)
		{
			while(m%j==0)
			{
				m/=j;
				mp[j]++;
			}
		}
	}
	if(m!=1)
	  mp[m]++;
	int answer=1;
	for(auto p:mp)
	{
		int count=p.second;
		int here=ncr(count+n-1,n-1);
		here=here%mod;
		answer=answer*here;
		answer=answer%mod;
	}
	cout<<answer<<endl;
}


Measured memory_bytes: 8064
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
#define int long long
class UnionFind {
private:
    int sz;
    vector<int> par, size_;
public:
    UnionFind(){}
    UnionFind(int node_size) : sz(node_size), par(sz), size_(sz, 1){
        iota(par.begin(), par.end(), 0);
    }
    int find(int x){
        if(par[x] == x) return x;
        else return par[x] = find(par[x]);
    }
    void unite(int x,int y){
        x = find(x), y = find(y);
        if(x == y) return;
        if(size_[x] < size_[y]) swap(x,y);
        par[y] = x;
        size_[x] += size_[y];
    }
    int size(int x){
        x = find(x);
        return size_[x];
    }
    bool same(int x,int y){
        return find(x) == find(y);
    }
};

vector<vector<int> > gg;
pair<int,int> dfs(int id,int pre){
    pair<int,int> sm = MP(0,0);
    for(auto x:gg[id]){
        if(x!=pre){
            pair<int,int> tmp = dfs(x,id);
            sm.first += tmp.first;
            sm.second += tmp.second;
        }
    }
    sm.second += sm.first;
    sm.first++;
    return sm;
}


signed main(){
    int n;
    cin >> n;
    UnionFind uf(n+1);
    vector<pair<int,int> > v;
    map<int,int> p;
    rep(i,n){
        int d;
        cin >> d;
        p[d] = i+1;
        v.push_back(MP(d,i+1));
    }
    sort(v.begin(),v.end(),greater<pair<int,int> >());
    map<int,int> mp;
    gg.resize(n+1);
    vector<pair<int,int> > g;
    bool ng = 1;
    rep(i,n){
        int k = v[i].first;
        int u = v[i].second;
        int c = mp[k];
        c++;
        //cerr << k << " " << u << " " << c << endl;
        if(c==n&&i==n-1){
            ng = 0;
            continue;
        }
        int nxt = k - (n-c-c);
        if(p.find(nxt)==p.end()){
            cout << -1 << endl;
            return 0;
        }
        mp[nxt]+=c;
        g.push_back(MP(u,p[nxt]));
        gg[u].push_back(p[nxt]);
        gg[p[nxt]].push_back(u);
        uf.unite(u,p[nxt]);
    }
    for(int i=1;i<=n;i++){
        if(!uf.same(i,1)){
            cout << -1 << endl;
            return 0;
        }
    }
    if(ng){
        cout << -1 << endl;
        return 0;
    }
    if(dfs(v[n-1].second,-1).second!=v[n-1].first){
        cout << -1 << endl;
        return 0;
    }
    for(auto x:g){

        cout << x.first << " " << x.second << endl;
    }
    return 0;
}


Measured memory_bytes: 27248
import sys
def input(): return sys.stdin.readline().strip()


def main():
    K = int(input())
    a, b = map(int, input().split())
    if a % K == 0 or b % K == 0:
        print("OK")
    elif a // K != b // K:
        print("OK")
    else:
        print("NG")


if __name__ == "__main__":
    main()

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

int main()
{
    int numr, numg, numb, num;
    cin >> numr >>numg >> numb >> num;

    int count =0 ;
    int sum , sumtwo;

    for(int i=0;i<=num/numr;i++){
        sum = num - numr*i;
        for(int j=0;j<=sum/numg;j++){
            sumtwo = sum - j*numg;
            if(sumtwo%numb==0){
                count ++;
            }
        }
    }

    cout << count << endl;
    return 0;
}

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

int main(){
    int N,K,Ans=1000000000;
    cin>>N>>K;
    int x[N];
    for(int i=0;i<N;i++){
        cin>>x[i];
    }
    for(int i=0;i<N-K+1;i++){
        if(x[i]<0){
            if(x[i+K-1]<0){
                Ans=min(Ans,-x[i]);
            }else{
                Ans=min(Ans,min(-2*x[i]+x[i+K-1],-x[i]+2*x[i+K-1]));
            }
        }else{
            Ans=min(Ans,x[i+K-1]);
        }
    }
    cout<<"\n"<<Ans<<endl;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define max0(a,b,c) max(max(a,b),c)
#define min0(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;

int main(){
    vec a(3);
    int n;
    cin>>n;
    rep(i,3){
        a[i]=n%10;
        n/=10;
    }
    if(a[0]==a[2]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
def divisor(n):
    fac = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0: 
            fac.append(i)
            if i*i != n: fac.append(n//i)
    return sorted(fac)

n = int(input())
ans = 0
for i in divisor(n):
    if i == 1: continue
    m = i-1
    p,r = divmod(n,m)
    if p == r: ans += m
print(ans)

Measured memory_bytes: 9416
N, A, B = map(int, input().split())
S = input()

for l in S:
	if l == "a":
		if A + B > 0:
			print("Yes")
			A -= 1
		else:
			print("No")
	elif l == "b":
		if A + B> 0 and B > 0:
			print("Yes")
			B -= 1
		else:
			print("No")
	else:
		print("No")


Measured memory_bytes: 4116
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main()
{
    int A,B,X;
    cin >> A >> B >> X;
    int remain = X - A;
    if(remain < 0)
    {
        cout << "NO";
    }
    else if(remain <= B)
    {
        cout << "YES";
    }
    else
    {
        cout << "NO";
    }
}

Measured memory_bytes: 256
#include<stdio.h>
typedef long long ll;
ll solve(ll x,ll n)
{
    ll ans;
    if(n%x==0)
        return n*2-x;
    ans=n/x*x*2+solve(n%x,x);
    return ans;
}
int main()
{
    ll n,x;
    ll ans;
 
    scanf("%lld%lld",&n,&x);
    ans=solve(x,n-x)+n;
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,l,t;
    scanf("%d%d%d",&n,&l,&t);
    int x[n], w[n];
    for (int i =0 ; i < n; i++){
        scanf("%d%d",&x[i],&w[i]);
        if (w[i] == 2) w[i] = -1;
    }
    int finalpos[n];
    int P[n];
    for (int i = 0; i < n; i++){
        finalpos[i] = P[i] = ((x[i] + w[i]*t)%l + l)%l;
        //printf("%d %d %d\n",x[i],w[i],finalpos[i]);
    }
    sort(P,P+n);
    int label[n];
    int nummeets = 0;
    for (int i = 0; i < n; i++){
        if (w[i] != w[0]){
            int rounds = (t/l);
            int left = t-rounds*l;
            nummeets += (rounds*2)%n;
            nummeets %= n;
            //printf("%d rounds\n",rounds);
            int dist = x[i]-x[0];
            if (w[0] == -1) dist = l-dist;
            //printf("dist is %d, timeleft %d\n",dist,left);
            if (left > (dist+l)/2) nummeets++;
            if (left > dist/2) nummeets++;
        }
    }
    //printf("0 meets %d times\n",nummeets);
    int k = ((w[0]*nummeets)%n + n) % n;
    int ans[n];
    ans[k] = finalpos[0];
    int anchor = finalpos[0];
    for (int i = 0; i < n; i++){
        if (P[i] == anchor){
            if (P[i+1] == anchor && w[0] == -1) continue;
            for (int j = 0; j < n; j++){
                //printf("%d -> %d\n",(k+j)%n,(i+j)%n);
                ans[(k+j)%n] = P[(i+j)%n];
            }
            break;
        }
    }
    for (int i =0 ; i < n; i++){
        printf("%d\n",ans[i]);
    }

}


Measured memory_bytes: 3200
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var t = o.a();
  var c = o.m(n);
  var ans = 9e9;
  for(var i = 0; i < n; i++){
    if(c[i][1] <= t && c[i][0] < ans)ans = c[i][0];
  }
  if(ans === 9e9)return "TLE";
  return ans;
}

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

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int i;
    int sum=1;
    for(i=1; i<10&&i<=n; i++)
    {
        sum*=2;
        if(sum>k)
            break;
    }
    if(i==n+1)
        cout << sum << endl;
    else
    {
        int cnt=n-i;
        cout << sum+k*cnt << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)
#define mp std::make_pair

const int INF = 1 << 24;
const int dx[8] = {0, 0, 1, -1, 1, 1, -1, -1}, dy[8] = {1, -1, 0, 0, 1, -1, 1, -1};

typedef unsigned long long ull;
typedef std::pair<int,int> P;

int N;
// dp[i][j]: 色i(i0: 白, i1: 黒)をつかい，j個白がたまった．
int t[10000], dp[2][2][5001];

int main(){
    std::cin >> N;
    
    FOR(i, 1, N){
        std::cin >> t[i];
    }

    REP(i, 2){
        REP(j, 2){
            REP(k, N/2+1){
                dp[i][j][k] = INF;
            }
        }
    }

    dp[0][0][1] = 0;
    dp[0][1][0] = 0;

    FOR(i, 1, N){
        REP(j, 2){
            REP(k, 5001){
                dp[1][j][k] = INF;
            }
        }

        dp[1][1][0] = dp[0][1][0];

        FOR(j, 1, N/2+1){
            dp[1][0][j] = std::min(dp[0][0][j-1], dp[0][1][j-1] + t[i]);
            dp[1][1][j] = std::min(dp[0][1][j], dp[0][0][j] + t[i]);
        }

        std::swap(dp[0], dp[1]);
    }

    std::cout << std::min(dp[0][0][N/2], dp[0][1][N/2]) << std::endl;
}

Measured memory_bytes: 1276
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>

using namespace std;

int main(){

    string A;
    string B;

    cin >> A >> B;


    if(A.size() > B.size()){
    	cout << "GREATER";
    }else if(B.size() > A.size()){
    	cout << "LESS";
    }else{
    	int a = A[0] - '0';
    	int b = B[0] - '0';

    	if(a > b){
    		cout << "GREATER";
    	}else if(b > a){
    		cout << "LESS";
    	}else{
    		cout << "EQUAL";
    	}

    }


}


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

void startup()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    
}


int main()
{
startup();

long long int n;
cin>>n;
long long int ar[n];
for(long long int i=0 ; i<n ; ++i)
    cin>>ar[i];
long long int ans=0;


for(long long int i=1 ; i<n ; ++i)
{
    if(ar[i]<ar[i-1])
    {
        ans+=ar[i-1]-ar[i];
        ar[i]+=ar[i-1]-ar[i] ;
    }
}
cout<<ans;




	return 0;
}



Measured memory_bytes: 5200
n, q = map(int, input().split())
s = input()
dp = [0 for _ in range(len(s))]

for i in range(1, len(s)):
    if(s[i-1: i+1] == 'AC'): dp[i] = dp[i-1] + 1
    else: dp[i] = dp[i-1]

for _ in range(q):
    l, r = map(int, input().split())
    print(dp[r-1] - dp[l-1])

Measured memory_bytes: 6160
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int main() {
  int a,d=0;cin>>a;
  char b;
  map<char,int>c;
  rep(i,a){
    cin>>b;
    c[b]++;
  }
  if(c.count('Y'))d++;
    if(c.count('P'))d++;
    if(c.count('W'))d++;
    if(c.count('G'))d++;
  if(d==3)cout<<"Three";
  else cout<<"Four";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
const ll inf=1000;
int main(void){
    // Your code here!
    ll n;
    cin>>n;
    vector<pair<string,ll>>a(n);
    vector<pair<string,ll>>b(n);
    rep(0,i,n){
        cin>>a[i].first>>a[i].second;
        a[i].second=inf-a[i].second;
        b[i].first=a[i].first;
        b[i].second=a[i].second;
    }
    sort(a.begin(),a.end());
    //rep(0,i,n)cout<<a[i].first<<" "<<a[i].second<<endl;
    rep(0,i,n){
        rep(0,j,n){
            if(a[i].first==b[j].first && a[i].second==b[j].second)cout<<j+1<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF INT_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(ll i=0; i<n; ++i)
#define FOR(i, s, e) for(ll i=s; i<e; ++i)
#define MOD 1000000007
using namespace std;
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;}

int main() {
  vector<int> ans(2200, 0);

  int N, X, Y;
  cin >> N >> X >> Y;

  for(int i=1; i<N; ++i) {
    for(int j=i+1; j<=N; ++j) {
      int dist = min(j-i, abs(X-i)+1+abs(Y-j));
      ans[dist]++;
    }
  }

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

Measured memory_bytes: 3628
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<map>
using namespace std;

#define ll long long

#define debug_message 0
#define debug if (debug_message)

#define sz(x) (int)x.size()

int i,t,j;
int n,m,nt,a[100005],b[100005],cnt;
string s,s1,s2;
map<int,int> posa,posb;

int main(){
	scanf("%d",&n);
	
	for (i=1; i<=n; ++i){
		scanf("%d",&a[i]);
		b[i]=a[i];
		posa[a[i]]=i;
	}
	
	sort(b+1,b+n+1);
	
	for (i=1; i<=n; ++i){
		posb[b[i]]=i;
	}
	
	for (i=1; i<=n; ++i){
		if (abs(posa[a[i]]-posb[a[i]])%2==1){
			++cnt;
		}
	}
	
	printf("%d\n",cnt/2);
	
	return 0;
}
/*
3: odd difference
2: even difference
*/

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

int main() {
	int n,q,a[200000+25],l,r,x,re=0;
	cin >> n;
	for(int i=0; i<n; i++) 
	{
		cin>>a[i];
		re ^= a[i];
	}
	for(int i=0; i<n; i++)
	{
		cout<<(re^a[i])<<" ";
	}
	return 0;
}

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

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		int l=0, r=0, b=1;
		int count=0;
		rep(i,n){
			string f;
			cin >> f;
			if( f[0] == 'l' ){
				l ^= 1;
			}else{
				r ^= 1;
			}
			if( l == b && r == b ){
				count++;
				b ^= 1;
			}
		}
		cout << count << endl;
	}
	return 0;
}

Measured memory_bytes: 3008
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
using namespace std;
using vint = vector<int>;
using ll = long long;
using vll = vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }
void yes() { cout << "Yes" << endl; exit(0); }
void no() { cout << "No" << endl; exit(0); }

int main() {
    int n; cin >> n;
    vint h(n);
    rep(i, n) cin >> h[i];
    vint dp(n+1, 0);
    dp[1] = abs(h[1] - h[0]);
    FOR(i, 2, n) {
        dp[i] = min(dp[i-1] + abs(h[i] - h[i-1]), dp[i-2] + abs(h[i] - h[i-2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <unordered_map>
#include <string>
#include <cmath>
#include <set>
using namespace std;



void solve()
{
	int a, b;
	cin >> a >> b;
	if (1 <= a && a <= 9 && 1 <= b && b <= 9)
	{
		cout << a * b;
	}
	else
	{
		cout << -1;
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	//freopen("file.in", "r", stdin);//freopen("file.out", "w", stdout);

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

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int sum[5001] = {};
	while (cin >> n, n)
	{
		//累積和の配列を作る
		for (int i = 0; i < n; i++)
		{
			int a;
			cin >> a;
			sum[i + 1] = sum[i] + a;
		}

		//さっき作った配列の中から最大値を選ぶ
		int ret = sum[1];
		for (int i = 0; i <= n; i++)
		{
			for (int j = i + 1; j <= n; j++)
			{
				ret = max(ret, sum[j] - sum[i]);
			}
		}
		cout << ret << endl;
	}
}


Measured memory_bytes: 3028
N = int(input())
d = {}
for i in range(N):
  s = input()
  d[s] = d.get(s, 0) + 1
base = sorted(d.items(), key=lambda x: x[1], reverse=True)[0][1]
items = [k for k, v in d.items() if v==base]
for item in sorted(items):
  print(item)

Measured memory_bytes: 43228
#include <bits/stdc++.h>
using namespace std;
using PP = pair<long, long>;
const int INF = 1e9;
template <class T> T Next() { T buf; cin >> buf; return buf; }

int main() {
  long k;
  cin >> k;
  vector<long> a;
  for (int i = 0; i < 5; ++i) {
    a.push_back(Next<long>());
  }
  
  long mn = *min_element(a.begin(), a.end());
  cout << (k + mn - 1) / mn + 4 << endl;
}

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

int main(){
    string w;
    cin >> w;
    vector<int> num(26,0);
    for(int i=0;i<w.size();i++){
        int it = w[i]-'a';
        num[it]++;
    }

    for(int i=0;i<26;i++){
        if(num[i]%2==1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, c) for(ll i = 1; i <= (ll)c; i++)
#define ll long long
#define upd_max(maxer, updater) if (maxer < updater) maxer = updater;
#define upd_min(miner, updater) if (miner > updater) miner = updater;
const int inf = 1000000000; // 10^9

int main(){
    ll k, a, b, i = 1;
    bool j = false;
    cin >> k >> a >> b;

    while(i * k <= b){
        if(i * k >= a && i * k <= b){
            j = true;
            break;
        }
        i++;
    }

    if(j) cout << "OK" << endl;
    else cout << "NG" << endl;


    return 0;
}

Measured memory_bytes: 3632
#if 0

#endif


#include <iostream>
#include <cstdio>
using namespace std;

int N, M, A, B, C, D, x1, x2, y1, y2;
int K[32][32];
const int inf=1001001001;

int main() {
	long long pay,ans;
	for(int i=0;i<32;i++)
		for(int j=0;j<32;j++)
			K[i][j]=inf;

	scanf("%d%d", &N, &M);
	for (int i=0; i<M; ++i) {
		scanf("%d,%d,%d,%d", &A, &B, &C, &D);
		//cerr << "read " << A <<" "<< B <<" " << C <<" " << D<< endl;
		//?????????
		K[A][B]=C; // A ??? B ????????????C
		K[B][A]=D;// B ??? A ????????????D    
	}
	/*
	for(int i=1;i<N+1;i++){//?????§?????????
		for(int j=1;j<N+1;j++){
			if(K[i][j]==inf){
	cout<<"i"<<" ";
			}else{
	cout<<K[i][j]<<" ";
			}
		}
		cout<<endl;
	}
	*/
	for(int k=1;k<N+1;k++){
		for(int i=1;i<N+1;i++){
			for(int j=1;j<N+1;j++){
	if(K[i][j]>K[i][k]+K[k][j]){
		K[i][j]=K[i][k]+K[k][j];
	}
			}
		}/*
		for(int l=1;l<N+1;l++){//?????§??????2???
		for(int m=1;m<N+1;m++){
			if(K[l][m]==inf){
	cout<<"i"<<" ";
			}else{
	cout<<K[l][m]<<" ";
			}
		}
		cout<<endl;
		} 
		cout<<endl;*/
	}
	scanf("%d,%d,%d,%d", &A, &B, &C, &D);
	pay=K[A][B]+K[B][A];
	ans=C-D-pay;
	cout<<ans<<endl; 
}

Measured memory_bytes: 3120
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n,k,q;
	scanf("%d", &n);
	scanf("%d", &k);
	scanf("%d", &q);
	int a[q+1],score[n+1]={};
	fill(score,score+n+1,k);
	for(int i=1;i<=q;i++) {
		scanf("%d", &a[i]);
		score[a[i]]+=1;
	}

	score[1]-=q;
	if(score[1]>0){
		printf("Yes");
	}else{
		printf("No");
	}
	for(int i=2;i<=n;i++) {
		score[i]-=q;
		if(score[i]>0){
			printf("\nYes");
		}else{
			printf("\nNo");
		}
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
int main(){
     
      int a, b;
      cin >> a >> b;
      set<int> s;
      s.insert(a);
      s.insert(b);
      
      for(int i = 1 ; i <= 3; i++){
             if(s.count(i) == 0){
                    cout << i << endl;
                    return 0;
             }
      }

}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;

namespace AtCoderProject
{
    struct Store
    {
        public int price;
        public int num;
    }
    public class Program
    {
        public object Calc()
        {
            var line = consoleReader.SplitInt32();
            var N = line[0];
            var m = line[1];

            var stores = consoleReader.RepeatSplitInt32(N)
                .Select(l => new Store { price = l[0], num = l[1] })
                .OrderBy(s => s.price);

            long money = 0;
            foreach (var store in stores)
            {
                if (store.num < m)
                {
                    money += (long)store.num * store.price;
                    m -= store.num;
                }
                else
                {
                    return money + (long)m * store.price;
                }
            }

            return 0;
        }

        const int mod = 1000000007;
        private readonly ConsoleReader consoleReader;
        public Program() : this(new ConsoleReader()) { }
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program().Calc());
        public static string MultiLine<T>(IEnumerable<T> source) => string.Join("\n", source);
    }

    public class ConsoleReader
    {
        public virtual string String() => Console.ReadLine();
        public int Int32() => int.Parse(String());
        public long Int64() => long.Parse(String());
        public ulong UInt64() => ulong.Parse(String());
        public double Double() => double.Parse(String());
        public string[] Split() => String().Split().ToArray();
        public int[] SplitInt32() => String().Split().Select(int.Parse).ToArray();
        public long[] SplitInt64() => String().Split().Select(long.Parse).ToArray();
        public ulong[] SplitUInt64() => String().Split().Select(ulong.Parse).ToArray();
        public double[] SplitDouble() => String().Split().Select(double.Parse).ToArray();

        public IEnumerable<string> Repeat(int count)
        {
            for (int i = 0; i < count; i++)
                yield return String();
        }
        public IEnumerable<int> RepeatInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int32();
        }
        public IEnumerable<long> RepeatInt64(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Int64();
        }
        public IEnumerable<string[]> RepeatSplit(int count)
        {
            for (int i = 0; i < count; i++)
                yield return Split();
        }
        public IEnumerable<int[]> RepeatSplitInt32(int count)
        {
            for (int i = 0; i < count; i++)
                yield return SplitInt32();
        }
    }
}


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

void solve(string S)
{
    vector<string> w = {"Sunny", "Cloudy", "Rainy"};
    map<string, int> wtoi = {{"Sunny", 0}, {"Cloudy", 1}, {"Rainy", 2}};
    int i = wtoi.at(S);
    cout << w.at((i + 1) % 3) << endl;
}

int main()
{
    string S;
    cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<string>


using namespace std;

int main()
{
	int a, b=0;
	string s;
	cin >> s;
	a = s.find('A');
	for (int i = 0; i < s.size(); i++)
	{
		char t = s[i];
		if ('Z' == t && i > a)
		{
			b = i;
		}
	}
	cout << b - (a-1) << endl;
	return 0;
}

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

#define rep(i,begin,end) for(int i=begin; i<end; i++)
#define revrep(i,begin,end) for(int i=begin; i>end; i--)
#define lld long long int

typedef struct node{
    int x, y, id;
    lld cost;
}node;

int cmpAsc(const void* a, const void* b){
    int x = ((node*)a)->id, y = ((node*)b)->id;
    if(x > y){
        return 1;
    }
    if(x < y){
        return -1;
    }
    return 0;
}

int main(){
    int h, w, d;
    scanf("%d %d %d", &h, &w, &d);
    node a[h*w + 1];
    a[0].x = -1; a[0].y = -1, a[0].cost = 0; a[0].id = 0;
    int id = 1;
    rep(y, 1, h+1){
        rep(x, 1, w+1){
            int buf;
            scanf("%d", &buf);
            a[id].id = buf;
            a[id].x = x;
            a[id].y = y;
            a[id].cost = 0;
            id++;
        }
    }
    qsort(a, h*w+1, sizeof(node), cmpAsc);
    rep(i, d+1, h*w+1){
        a[i].cost = (lld)abs(a[i].x - a[i-d].x) + (lld)abs(a[i].y - a[i-d].y) + a[i-d].cost;
    }
    int q;
    scanf("%d", &q);
    lld ans[q];
    rep(i, 0, q){
        int l, r;
        scanf("%d %d", &l, &r);
        ans[i] = a[r].cost - a[l].cost;
    }
    rep(i, 0, q){
        printf("%lld\n", ans[i]);
    }

    return 0;
}

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

int field[2005][2005];
int hcos[2005][2005];
int wcos[2005][2005];
int main(){
    int h,w;
    cin>>h>>w;
    REP(i,h){
        string s;
        cin>>s;
        REP(j,w){
            if(s[j-1]=='.'){
                field[i][j]=0;
            }else{
                field[i][j]=1;
            }
        }
    }

    REP(i,h){
        int cnt=0;
        REP(j,w){
            if(field[i][j]==1){
                cnt = 0;
                hcos[i][j]=0;
            }else{
                cnt++;
                hcos[i][j]=cnt;
            }
        }
        for(int j=w-1;j>0;j--){
            if(hcos[i][j]==0) continue;
            if(hcos[i][j]<hcos[i][j+1]){
                hcos[i][j]=hcos[i][j+1];
            }
        }
    }

    REP(j,w){
        int cnt=0;
        REP(i,h){
            if(field[i][j]==1){
                cnt = 0;
                wcos[i][j]=0;
            }else{
                cnt++;
                wcos[i][j]=cnt;
            }
        }
        for(int i=h-1;i>0;i--){
            if(wcos[i][j]==0) continue;
            if(wcos[i][j]<wcos[i+1][j]){
                wcos[i][j]=wcos[i+1][j];
            }
        }
    }
    int ans = 0;
    REP(i,h){
        REP(j,w){
            if(field[i][j]==1) continue;
            ans = max(ans,wcos[i][j]+hcos[i][j]-1);
        }
    }

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

Measured memory_bytes: 47360
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}

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

  return gcd(b, a%b);
}

/*
n
a1 ... an

n 10^5
ai 10^9
 */
int n,a[100000];
int main(){
  cin>>n;
  REP(i,n){
    cin>>a[i];
  }
  
  int ans=a[0];
  FOR_IN(i,1,n){
    ans = gcd(ans, a[i]);
  }

  cout<<ans <<endl;

  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	vector<int> A(N);
	for (int i = 0; i < N; i++) cin >> A[i];

	cout << (N - 1) / (K - 1) + !!((N - 1) % (K - 1));

	return 0;
}


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

int main(){
    int n;
    cin >> n;
    int w[101];
    for(int i=1;i<=n;i++) cin >> w[i];

    int ans = 1000000;
    for(int t=1;t<n;t++){
        int s1 = 0,s2 = 0;
        for(int i=1;i<=t;i++)  s1 += w[i];
        for(int i=t+1;i<=n;i++) s2 += w[i];
        ans = min(ans, abs(s1-s2));
    }

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

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

int main(){
  int i,N,A[21],B[21],C[21],sum=0 ;
  
  cin >> N ;
  
  for(i=0;i<N;i++){
    cin >> A[i] ;
    A[i] = A[i] - 1 ;
  }
  for(i=0;i<N;i++){
    cin >> B[i] ;
  }
  for(i=0;i<N-1;i++){
    cin >> C[i] ;
  }
  
  for(i=0;i<N;i++){
    sum += B[i];
  }
  
  for(i=0;i<N-1;i++){
    if(A[i+1]-A[i]==1){
      sum += C[A[i]] ;
    }
  }
  
  cout << sum ;
}

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

using namespace std;

int func(int n, int a) {
    int res = 0;

    while(n > 0) {
        res += n % a;
        n /= a;
    }

    return res;
}

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

    // inf扱いでnを使用
    int ans = n;

    for(int i = 0; i <= n; ++i) {
        ans = min(ans, func(i, 6) + func(n-i, 9));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
 
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define lli long long int
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pll pair<lli,lli>
#define ve vector<lli>
#define vep vector<pair<lli,lli> >
#define fr(i,a,n) for(lli i=a;i<(n);i++)
#define frj(j,a,n) for(lli j=a;j<(n);j++)
#define frx(i,a,n) for(lli i=a;i>(n);i--)
#define frxj(j,a,n) for(lli j=a;j>(n);j--)
#define lb lower_bound
#define ub upper_bound
#define F first
#define S second
#define db(x) cout << "[ " << x << " ]" << endl;
#define dbarr(arr,a,n) {fr(i,0,n) cout<<arr[i]<<" "; cout<<endl;}


int main() {
    lli mod=1e9+7;
    lli s;
    cin>>s;
    vector<vector<lli>> dp(700,vector<lli>(s+1,0));
    ve suf(s+1,0);
    fr(i,3,s+1){
        dp[1][i]=1;
        suf[i]=i-2;
    }
    fr(i,2,700){
        ve temp(s+1,0);
        frj(j,0,s+1){
            lli prev=max(0LL,j-3);
            dp[i][j]=suf[prev];
            temp[j]=dp[i][j];
        }
        frj(j,1,s+1)temp[j]=(temp[j]+temp[j-1])%mod;
        suf=temp;
    }
    // for(int i=1;i<3;i++){
    //     for(int j=0;j<s;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<endl;
    // }
    lli ans=0;
    fr(i,0,700) ans=(ans+dp[i][s])%mod;
    cout<<ans;
}

Measured memory_bytes: 14432
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

template<typename T,typename MERGE,typename UPDATE>
class segtree {
    int n;
    vector<T> val;
    T identity;
    MERGE merge;
    UPDATE _update;

public:
    segtree(int _n,vector<T> init,T identity,
            MERGE merge,UPDATE update)
            :identity(identity),merge(merge),_update(update) {
        n = 1;
        while(n < _n) n *= 2;
        val = vector<T>(2*n-1,identity);
        rep(i,_n) val[i+n-1] = init[i];
        rrep(i,n-1) val[i] = merge(val[i*2+1],val[i*2+2]);
    }
    void update(int i,T x) {
        i += n-1;
        val[i] = _update(val[i],x);
        while(i > 0) {
            i = (i-1)/2;
            val[i] = merge(val[i*2+1],val[i*2+2]);
        }
    }
    // segment [a,b)
    T query(int a,int b,int k = 0,int l = 0,int r = -1) {
        if(r == -1) r = n;
        if(b <= l || r <= a) return identity;
        if(a <= l && r <= b) return val[k];
        T t1 = query(a,b,2*k+1,l,(l+r)/2);
        T t2 = query(a,b,2*k+2,(l+r)/2,r);
        return merge(t1,t2);
    }
    T operator[](int i) const { return val[i]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    vi h(n),a(n);
    cin >> h >> a;
    rep(i,n) h[i]--;
    auto f = [](ll a,ll b){ return max(a,b); };
    auto g = [](ll a,ll b){ return max(a,b); };
    segtree<ll, decltype(f), decltype(g)> st(n,vl(n,0),0,f,g);
    rep(i,n) {
        st.update(h[i],st.query(0,h[i])+a[i]);
    }
    cout << st.query(0,n) << endl;
}


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

int main(){
  int n,m;
  double l;
  
  string a,b; 

  //a = "1234";

  cin>>l>>n>>m;
  double ans ;
  ans = l/m;
  if(ans>n)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
  

}

Measured memory_bytes: 3748
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include<math.h>
using namespace std;
#define INF 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<string,int> P;

int C[110000];

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

  for(int i=0;i<2*M;i++){
      cin>>a;
      C[a]++;
  }
  for(int i=1;i<=N;i++){
      if(C[i]%2==1){
          cout<<"NO"<<endl;
          return 0;
      }
  }
  cout<<"YES"<<endl;
}


Measured memory_bytes: 640