akhauriyash/Code-Regression huggingface dataset:
# https://atcoder.jp/contests/agc037/tasks/agc037_a
import sys
sys.setrecursionlimit(12345678)
import itertools
from collections import Counter
from collections import defaultdict
from collections import deque
import bisect
from heapq import heappush, heappop


def main():
    s = input()

    k = 1
    i = 1
    prev = s[0]
    while i < len(s):
        if prev != s[i]:
            prev = s[i]
            k += 1
            i += 1
        else:
            two = s[i:(i+2)]
            if len(two) == 2:
                prev = two
                k += 1
                i += 2
            else:
                break

        # print('{} {}, {}'.format(prev, k, i))
    print(k)


if __name__ == '__main__':
    main()


Measured memory_bytes: 40176
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int res[n][3],a[n][3];
  for(int i=0;i<n;i++){
	cin>>a[i][0]>>a[i][1]>>a[i][2];}
for(int i=0;i<3;i++)
  res[0][i]=a[0][i];
  for(int i=1;i<n;i++)
  {		res[i][0]=max(res[i-1][1],res[i-1][2])+a[i][0];
   		res[i][1]=max(res[i-1][0],res[i-1][2])+a[i][1];
   		res[i][2]=max(res[i-1][1],res[i-1][0])+a[i][2];
  }
  cout<<max(res[n-1][0],max(res[n-1][1],res[n-1][2]));
  return 0;
}
   		
    

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
vector<long>a;
void f(long i,long n,long &ans)
{
	if(i!=n-1&&a[i]>0)
	{
		if(abs(a[i])>abs(a[i+1]))ans+=a[i]*(a[i]+1)/2;
		else ans+=a[i]*(a[i]-1)/2;
	}
	else if(a[i]>0)ans+=a[i]*(a[i]+1)/2;
	else if(i!=0&&a[i]<0)
	{
		if(abs(a[i-1])>abs(a[i]))ans+=abs(a[i])*(abs(a[i])-1)/2;
		else ans+=abs(a[i])*(abs(a[i])+1)/2;
	}
	else if(a[i]<0)ans+=abs(a[i])*(abs(a[i])+1)/2;
}
int main()
{
	char s[500005]={0};
	long i,n;
	for(cin>>s;s[n];n++);n++;
	long buf=s[0]=='<'?1:-1;
	for(i=1;i<n-1;i++)
	{
		if(buf>0&&s[i]=='<')buf++;
		else if(buf<0&&s[i]=='>')buf--;
		else if(buf>0&&s[i]=='>')a.emplace_back(buf),buf=-1;
		else if(buf<0&&s[i]=='<')a.emplace_back(buf),buf=1;
	}
	a.emplace_back(buf);
	n=a.size();
	if(n==1){cout<<abs(a[0])*(abs(a[0])+1)/2<<endl;return 0;}
	long ans=0;
	for(i=0;i<n;i++)f(i,n,ans);
	cout<<ans<<endl;
}

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

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

   const double EPS = (1e-7);
   const ll INF =(1e13);
   const double PI = (acos(-1));
   const ll MOD = ll(1e9) + 7;

   #define REP(i, n) for(ll i = 0; i < (ll)(n); i++)
   #define REPR(i, n) for(ll i = n; i > -1; i--)
   #define FOR(i, a, b) for (ll i = (ll)(a); i < (ll)(b); i++)
   #define ALL(x) (x).begin(),(x).end()
   #define SORT(x) sort((x).begin(), (x).end())
   #define REVERSE(x) reverse((x).begin(), (x).end())
   #define SZ(x) ((ll)(x).size())
   #define pb push_back
   #define mp make_pair

   //chmax(a, b): a>bならaをbで更新　更新したときにtrueを返す
   //chmin(a, b): a<bならaをbで更新　更新したときにtrueを返す
   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; }

   #define dump(x) cerr<< #x << "= " << (x) << endl;

   ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
   ll pow(ll a, ll b){if (b == 0) return 1; else if (b % 2 == 0) return pow(a * a, b / 2); else return pow(a * a, b / 2) * a;}


   ll dx[4]={1,0,-1,0};
   ll dy[4]={0,1,0,-1};
const ll MAX_N = 16;
ll N;
ll a[MAX_N][MAX_N];
ll dp[1 << MAX_N] = {};

int main(){
  cin >> N;
  REP(i, N){
    REP(j, N){
      cin >> a[i][j];
    }
  }
  //init dp-table
  REP(S, 1 << N){
    REP(i, N){
      REP(j, i){
        if (((S >> i) & 1) & ((S >> j) & 1)) dp[S] += a[i][j];
      }
    }
  }
  REP(S, 1 << N){
    for (ll T = S; T!= 0; T = (T -1) & S){
      chmax(dp[S], dp[T] + dp[~T & S]);
    }
  }
  cout << dp[(1 << N) - 1] << endl;
}


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

using namespace std;

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

ll dp[100005];
ll ndp[100005];
const int MOD = 1000000007;
int n, k;

void solve() {
  cin >> n >> k;
  dp[0] = 1;
  while(n--) {
    int t;
    cin >> t;
    memset(ndp, 0, sizeof(ndp));
    ll curr = 0;
    for(int i = 0; i <= k; i++) {
      curr += dp[i];
      curr %= MOD;
      curr += MOD;
      curr %= MOD;
      ndp[i] += curr;
      ndp[min(k+1, i+t+1)] -= curr;
    }
    memcpy(dp, ndp, sizeof(dp));
  }
  cout << (dp[k]%MOD+MOD)%MOD << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
#include <iostream>
using namespace std;
 
int main()
{
  int N;
  cin>>N;
  int x=0;
  x= N%1000;
  if(x>0)
    cout<<1000-x;
  else 
    cout<<0;
  return 0;
}

Measured memory_bytes: 3600
Module Module1
    Sub main()
        Dim userInput As String, userInput2 As String
        Dim total As Long

        ' データの入力
        userInput = Console.ReadLine()
        userInput2 = Console.ReadLine()
    
        For i = 1 To Len(userInput)
            If Mid(userInput, i, 1) <> Mid(userInput2, i, 1) Then
                'Console.WriteLine(Mid(userInput, i, 1) & ", " & Mid(userInput2, i, 1) & ", " & userInput)

                'userInput = Mid(userInput, 1, i - 1) & Mid(userInput2, i, 1) & Mid(userInput, i + 1, Len(userInput))
                total = total + 1

            End If
        Next
        '' 処理結果を返す
        Console.WriteLine(total)
    End Sub
End Module

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

const int MAXN = 1e5+5;

int n, m;
vector<int> g[MAXN];
int vis[MAXN];
int bip = 1;
ll ct1 = 0, ct2 = 0, one = 0;
int ct = 0;

void dfs(int v, int c) {
	vis[v] = c;
	ct++;

	for (int u : g[v]) {
		if (vis[u] == 0)
			dfs(u, 3-c);
		if (vis[u] != 3-vis[v])
			bip = 0;
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int u, v; cin >> u >> v;
		u--; v--;
		g[v].push_back(u);
		g[u].push_back(v);
	}

	ll ans = n*n;

	for (int i = 0; i < n; ++i) {
		ct = 0; bip = 1;
		if (vis[i] == 0) {
			dfs(i, 1);
			if (ct == 1)
				one++;
			else if (bip == 1)
				ct2++;
			else
				ct1++;
		}
	}

	ll s = one + ct1 + ct2;

	cout << 2*one*n - one*one + 2*ct1*ct2 + ct1*ct1 + 2*ct2*ct2 << endl;
}

Measured memory_bytes: 10880
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvld;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    int n, m, d;
    cin >> n >> m >> d;

    //数列を2項ずつに分割して、各2項の美しさの期待値を計算後、m - 1倍すればよい。
    ld exp = 0;
    if (d == 0)
    {
        exp = 1.0 / n;
    }
    else
    {
        exp = (2.0 * (n - d));
        exp /= n;
        exp /= n;
    }

    cout << setprecision(10) << setiosflags(ios::fixed);
    cout << (m - 1) * exp;

    return 0;
}

Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


# --------------------------------------------

dp = None


def main():
    N = int(input())
    L = li_input()

    x1 = 0
    x2 = 0
    x4 = 0
    for l in L:
        if l % 4 == 0:
            x4 += 1
        elif l % 2 == 0:
            x2 += 1
        else:
            x1 += 1

    if x2 == 0:
        if x1 - 1 <= x4:
            print("Yes")
        else:
            print("No")
    else:
        if x1 <= x4:
            print("Yes")
        else:
            print("No")


main()


Measured memory_bytes: 16364
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int MAXN = 3e3+5;
int n,mod,ans,C[MAXN][MAXN],s[MAXN][MAXN];
it add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
it mul(int x,int y){return 1ll*x*y%mod;}
il inc(int &x,int y){x=add(x,y);}
il Init(){
	C[0][0]=1,s[0][0]=1;
	for(ri i=1;i<=n+1;++i){
		C[i][0]=1;
		for(ri j=1;j<=i;++j) C[i][j]=add(C[i-1][j-1],C[i-1][j]);
		for(ri j=1;j<=i;++j) s[i][j]=add(s[i-1][j-1],mul(s[i-1][j],j));
	}
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	read(n),read(mod),Init();
	for(ri i=0;i<=n;++i){
		int res=mul(C[n][i],qpow(2,qpow(2,n-i,mod-1),mod)),bas=qpow(2,n-i,mod),t=0;
		for(ri j=0,k=1;j<=i;++j,k=mul(k,bas)) inc(t,mul(k,s[i+1][j+1]));
		res=mul(res,t);
		if(i&1) inc(ans,mod-res);
		else inc(ans,res);
	}
	print(ans);
	return 0;
}

Measured memory_bytes: 69504
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int K = sc.nextInt();
		sc.close();
		if((K % N == 0) ||(K%M==0)) {
			System.out.println("Yes");
		} else {
			for(int n=0; n<=N; n++) {
				for(int m=0; m<=M; m++) {
					if(n*M+m*N-2*(Math.min(m, n)*Math.max(m, n)) == K) {
						System.out.println("Yes");
						return;
					}
				}
			}
			System.out.println("No");
		}
	}

}

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

#define rep(i,a,b) for(ll i=(a);i<=(b);i++)
#define END(x) do{cout<<(x)<<endl;exit(0);}while(0)
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: x)cerr<<e<<" ";cerr<<"\n";}while(0)
#define exp2(x)  (1LL<<(x))

using namespace std;
using ll=long long;
const int NN=2*100*1000+110;
int S[NN], T[NN], X[NN]; 
int D[NN]; 
int W[NN];

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

  ll N, Q; cin >> N >> Q;
  vector<pair<ll,ll>> RB;

  rep(i,0,N-1) { 
      cin >> S[i] >> T[i] >> X[i];
      RB.emplace_back(X[i], i);
  }

  
  set<pair<ll,int>> PP;
  rep(i,0,Q-1) {
      cin >> D[i];
      PP.emplace(D[i], i);
  }

  sort(RB.begin(), RB.end());
  rep(i,0,Q-1)W[i]=-1;
  for(auto & e: RB) {
      int i = e.second;
      int lb = S[i]-X[i];
      int ub = T[i]-X[i]-1;
      if (PP.empty()) break;
      auto it = PP.lower_bound({lb,-1LL});
      while(!PP.empty() && it != PP.end() && it->first <=ub && it->first>=lb){
          int id = it->second;
          W[id]=X[i];
          PP.erase(it++);
      }
  }
  rep(i,0,Q-1) cout << W[i] << "\n";

}


Measured memory_bytes: 21740
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <stdio.h>
#include <algorithm>
#include <string.h>
#include <string>
#include <cmath>
#include <complex>
#include <map>
using namespace std;

#define rep(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define EPS 1e-8
#define F first
#define S second

static const double PI=6*asin(0.5);
typedef long long ll;
typedef complex<double> CP;
typedef pair<long long,int> P;
static const int INF=1<<24;

int main(){
	string s;
	cin>>s;
	string f1="kstnhmyrw";
	map<char,char> m;
	m['T']='a';
	m['L']='i';
	m['U']='u';
	m['R']='e';
	m['D']='o';
	rep(i,s.size()){
		if(s[i]=='0'&&s[i+1]=='U'){
			cout<<"nn";
		}
		else{
			if(s[i]=='1'){
			}
			else if(s[i]=='0'){
				cout<<"w";
			}
			else{
				cout<<f1[s[i]-'0'-2];
			}
			cout<<m[s[i+1]];
		}
		i++;
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1188
N = int(input())
UV = [tuple(map(int, input().split())) for _ in range(N-1)]
v_count = 0
e_count = 0
for n in range(1, N + 1):
    v_count += n * (N-n+1)
for u, v in UV:
    e_count += min(u, v)*(N-max(u, v)+1)
print(v_count-e_count)

Measured memory_bytes: 103520
#include<bits/stdc++.h>
#ifndef LOCAL_PROJECT
#define cerr if(0)cerr
#endif
using namespace std;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef __int128 lll;
const lll ONE=1;
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
const int mn=2e6+10;
const ll inf=0x3f3f3f3f3f3f3f3f;
const ll mod=998244353;
int num[19][19];
int main(){
#ifdef LOCAL_PROJECT
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
#else
    cin.tie(0);
    cin.sync_with_stdio(0);
#endif
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        long double x;
        cin>>x;
        ll v=x*1e9+.5;
        int a=0,b=0;
        while(v%2==0)v/=2,a++;
        while(v%5==0)v/=5,b++;
        num[min(18,a)][min(18,b)]++;
    }
    ll ans=0;
    for(int i=0;i<19;i++)for(int j=0;j<19;j++){
        for(int k=0;k<19;k++)for(int l=0;l<19;l++){
            if(i+k>=18&&j+l>=18){
                if(i==k&&j==l)ans+=1LL*num[i][j]*(num[i][j]-1);
                else ans+=1LL*num[i][j]*num[k][l];
            }
        }
    }
    printf("%lld",ans/2);
}





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

#define MD 1000000007

int dp[1005];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int H, W;
    cin >> H >> W;
    string S;
    cin >> S;
    dp[0] = 1;
    for (int j = 1; j < W; j++)
    {
        if (S[j] == '#') dp[j] = 0;
        else dp[j] = dp[j - 1];
    }
    for (int i = 1; i < H; i++)
    {
        cin >> S;
        if (S[0] == '#') dp[0] = 0;
        for (int j = 1; j < W; j++)
        {
            if (S[j] == '#') dp[j] = 0;
            else dp[j] = (dp[j] + dp[j - 1]) % MD;
        }
    }
    cout << dp[W - 1] << '\n';
    return(0);
}

Measured memory_bytes: 256
x, k, d = map(int,input().split())

if x - k * d >= 0:
    print(x - k * d)
elif x + k * d <= 0:
    print(abs(x + k * d))
else:
    dis = x % d
    dis_p = d - dis
    t = k - x // d

    if t % 2 == 0:
        print(dis)
    else:
        print(dis_p)


Measured memory_bytes: 9172
n=int(input())
l=[]
for i in range(n):
    a=list(map(int,input().split()))
    l.append(a)
l=sorted(l,key=lambda x:x[1],reverse=True)

cnt=l[0][1]
for i in range(n):
    if cnt>l[i][1]:
        cnt=l[i][1]
    cnt-=l[i][0]
if cnt>=0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 55380
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(){
    int n,p;
    scanf("%d %d",&n,&p);
    char *s;
    s=(char*)malloc(sizeof(char)*(n+1));
    scanf("%s",s);
    long long int ans=0;
    if (p==2||p==5)
    {
        for (int i = 0; i < n; i++)
        {
            if (((int)(s[n-1-i]-'0'))%p==0)
            {
                ans+=n-i;
            }
            
        }
        
    }else{
        int *mod;
        mod=(int*)malloc(sizeof(int)*p);
        for (int i = 0; i < p; i++)mod[i]=0;
        int amari=0;
        int ten=1;
        for (int i = 0; i < n; i++)
        {
            int u=((int)(s[n-1-i]-'0'));
            amari=(amari+u*ten)%p;
            ten=(ten*10)%p;
            mod[amari]++;
        }
        ans+=((long long int)mod[0]*(mod[0]+1))/2;
        for (int i = 1; i < p; i++)
        {
            ans+=((long long int)mod[i]*(mod[i]-1))/2;
        }        
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    int n;
    cin >> n;
    int sum;
    if (n & 1) sum = n;
    else sum = n + 1;
    vector <pair <int, int> > ans;
    for (int i = 1; i <= n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            if (i + j != sum) {
                ans.push_back({i, j});
            }   
        }   
    }   
    cout << ans.size() << '\n';
    for (auto e : ans) cout << e.first << ' ' << e.second << '\n';
}   

Measured memory_bytes: 384
#include<cstdio>
int cal(int x,int y)
{
	if(x%y==0)return x/y;
	if(x<y)return 0;
	return cal(x-(x-x/y*y+x/y)/(x/y+1)*(x/y+1),y);
}
int main()
{
	int n,i,a,k,s=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d%d",&a,&k),s^=cal(a,k);
	puts(s?"Takahashi":"Aoki");
}

Measured memory_bytes: 128
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define N (int)1e5
#define mod (int)(1e9 + 7)
typedef long long LL;
LL n, m, ans, sum, sum2, sum3, times;
LL xx[N], yy[N];

int extgcd(int a, int b, int& x, int& y)
{
	int d = a;
	if (b != 0)
	{
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else
	{
		x = 1; y = 0;
	}
	return d;
}
int mod_inverse(int a, int m)
{
	int x, y;
	extgcd(a, m, x, y);
	return (m + x % m) % m;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		cin >> xx[i];
	}
	for (int i = 0; i < m; i++)
	{
		cin >> yy[i];
	}
	for (int i = 0; i < n; i++)
	{
		sum += xx[i] * i;
		sum -= xx[i] * (n - i - 1);
		sum %= mod;
	}
	for (int i = 0; i < m; i++)
	{
		sum2 += yy[i] * i;
		sum2 -= yy[i] * (m - i - 1);
		sum2 %= mod;
	}
	cout << sum * sum2 % mod << endl;
}

Measured memory_bytes: 1792
/*
Character Drawing Adapted from FAKEUPDATE.NET
		   _    _____         _
		   \`,""   ,'7"r-..__/ \
		  ,'\ `, ,',','    _/   \
		 /   \, 7 / /     (   \ |
		J     \/ j  L______\  / |
		L   __JF"""/""\"\_,    /
		L,-"| O|  f O |  L_  _/
		F   \_ /  \__/   `-  j|
			.-'    `"""    ,' |          _..====.._
			\__/         r"_  A        ,' _..---.._`,
			 `-.______,,-L// / \  ___,' ,'_..:::.. `,`,
					  j   / / / 7"    `-<""=:'  '':. \ \
					 /   <,' /  F  . i , \   `,    :T W I
					 |    \,'  /    >X<  |     \   :| | L
					 |     `._/    ' ! ` |      I  :| |  G
					  \           \     /       |  :H T  |
					 __>-.__   __,-\   |        |  S P   |
					/     /|   | \  \  \_       | 'A R   |
				   /   __/ |   |  L  L   \      K./ /    L
				  /   |    |   4  I  I    |    E./ /   ,'
				 J    \    I    L F  I    |    // / _,'
		_________|     |   F    |J   F    |   //_/-'
		\   __   |    /   J     |/  J     |  /="
		\\  \_\  \__,' \  F     |   F     |
		\\\_____________\/      F__/      F
		 \\| 计算机编程 |_____/  (______/
		  \/从入门到入土/
*/
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <vector>
#include <sstream>
#include <set>
#include <queue>
#include <stack>
#include <cctype>
#include <map>
#include <climits>
#include <bitset>
#include <functional>
using namespace std;
#define MATH_PI 3.14159265358979323846
int main(){
	ios::sync_with_stdio(false);
	int n, k, iMin = INT_MAX, sum = 0, l, x, h, i;
	cin >> n >> k;
	for (i = 1; i <= n; ++i){
		cin >> x;
		l = abs(k - x);
		h = x;
		iMin = min(iMin, l);
		iMin = min(iMin, h);
		sum += iMin;
		iMin = INT_MAX;
	}
	cout << 2 * sum;
endapp:
	//system("pause > nul");
	return 0;
}

Measured memory_bytes: 256
N = int(input())
dp = [float("inf")]*(N+10)
dp[0] = 0
for i in range(1,N+5):
    k = 0
    while i-6**k >= 0:
        dp[i] = min(dp[i-6**k]+1,dp[i])
        k += 1
    k = 1
    while i-9**k >= 0:
        dp[i] = min(dp[i-9**k]+1,dp[i])
        k += 1
print(dp[N])

Measured memory_bytes: 3828
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define all(x) (x.begin()),(x.end())
#define sz(x)  ((ll)x.size())
#define FAST_IO ios_base :: sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
using namespace std;
#ifdef LOCAL
#include "uj.h"
#endif

const ll oo = 1e16;
const int maxn = 1e5 + 10;

int v[maxn],w[maxn];
int N,W;
ll dp[110][maxn];

ll Brute(int i,int wgt){
	if(i == N) return 0;
	
	ll & ans = dp[i][wgt];
	if(ans != -1) return ans;
	
	ll a = 0;
	if(wgt + w[i] <= W)
		a = Brute(i+1,wgt + w[i]) + v[i]; // i choose
	ll b = Brute(i+1,wgt); // i don't choose
	
	return ans = max(a,b);
}


void test_case(){
	memset(dp,-1,sizeof(dp));
	cin >> N >> W;
	for(int i = 0;i<N;++i)
		cin >> w[i] >> v[i];
	
	cout << Brute(0,0);
		
}

	





int main(){
	FAST_IO;
	int tt;
	//cin>>tt;
	tt = 1;
	while(tt--){
		test_case();
	}
#ifndef ONLINE_JUDGE
 	cerr << "Running Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 89600
import java.util.Scanner;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int d = sc.nextInt();
		int x = sc.nextInt();
		int[] data = new int[n];
		int sum = 0;
		for(int i=0; i<n; i++){
			data[i] = sc.nextInt();
		}

		for(int i=0; i<n; i++){
			for(int j=1; j<=d; j+=data[i]){
				sum++;
			}
		}

		System.out.println(x+sum);
	}
}

Measured memory_bytes: 23892
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>

int main()
{
	int candidateNum = 0, stoneNum = 0;
	while (scanf("%d %d", &candidateNum, &stoneNum) && candidateNum && stoneNum)
	{
		int *candidateArray = malloc(sizeof(int) * candidateNum);
		int stonePool = stoneNum;
		int counter = 0;
		while (1)
		{
			if (counter == candidateNum)
				counter = 0;
			if (*(candidateArray + counter) == stoneNum)
				break;
			if (stonePool > 0)
			{
				*(candidateArray + counter) += 1;
				stonePool--;
			}
			else
			{
				stonePool += *(candidateArray + counter);
				*(candidateArray + counter) = 0;
			}
			counter++;
		}
		printf("%d\n", counter);
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 100000;
int a[N+1], b[N+1];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
  int n, x;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (i%2) {
      b[x]++;
    } else {
      a[x]++;
    }
  }
  int ma = 0, ai = 0;
  int mb = 0, bi = 0;
  for (int i = 0; i <= N; i++) {
    if (a[i] > ma) {
      ma = a[i];
      ai = i;
    }
    if (b[i] > mb) {
      mb = b[i];
      bi = i;
    }
  }
  int s = ma+mb;
  if (ai == bi) {
    int m = 0;
    for (int i = 0; i <= N; i++) {
      if (i == ai) continue;
      m = max(m, a[i]);
    }
    s = mb+m;
    m = 0;
    for (int i = 0; i <= N; i++) {
      if (i == bi) continue;
      m = max(m, b[i]);
    }
    s = max(s, ma+m);
  }
  cout << n - s << endl;
}


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



int main() {
  //
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;

  //
  tx -= sx;
  ty -= sy;
  sx = 0;
  sy = 0;

  // 1往復
  for (int i = 0; i < ty; ++i) {
    cout << "U";
  }
  for (int i = 0; i < tx; ++i) {
    cout << "R";
  }
  for (int i = 0; i < ty; ++i) {
    cout << "D";
  }
  for (int i = 0; i < tx; ++i) {
    cout << "L";
  }

  // 2往復
  //(0, -1)
  cout << "D";

  //(tx+1, -1)
  for (int i = 0; i < tx+1; ++i) {
    cout << "R";
  }

  //(tx+1, ty)
  for (int i = 0; i < ty+1; ++i) {
    cout << "U";
  }
  // (tx, ty)
  cout << "L";

  // (tx, ty+1)
  cout << "U";

  // (sx-1, ty+1)
  for (int i = 0; i < tx+1; ++i) {
    cout << "L";
  }

  // (sx-1, sy)
  for (int i = 0; i < ty+1; ++i) {
    cout << "D";
  }

  // (sx, sy)
  cout << "R";

  cout << endl;

  return 0;
}



Measured memory_bytes: 256
N=int(input())
ans=0

if N<10:
    ans=N
elif N<100:
    ans=9
elif N<1000:
    ans=N-90
elif N<10000:
    ans=909
elif N<100000:
    ans=N-9000-90
else:
    ans=90909
    
print(ans)

Measured memory_bytes: 3060
a=-1,A=65,d;
char
*N="GKSOCNWLDFVTBRXHAJUPEMQI",
*E="PHLTIDOXQAGWECSUMBKVJFNR",
*R="BCDAFGHEJKLINOPMRSTQVWXU",
s[9];
main(c)
{
for(;c-48&&scanf("%s",s);a+=d/4+1)
{
(c=*s)<A?~a&&printf("%d\n",a),a=d=0:0;
d=c==78?d=N[d]-A:
c==69?d=E[d]-A:
c==82?d=R[d]-A:
c==83?d=N[N[N[d]-A]-A]-A:
c==87?d=E[E[E[d]-A]-A]-A:d;
if(c==76)d=R[R[R[d]-A]-A]-A;
}}

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

#include <queue>

using namespace std;

typedef struct State_Def {
	int y;
	int x;
	State_Def(int _y, int _x) {y = _y; x = _x;}
} S;

const int INF = 1e+8;
int h, w, n;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
char **data;
int **dist;
int *fX;
int *fY;

int bfs(int si, int sj, int gi, int gj)
{
	int res = 0;
	int i, j;
	queue<S> q;
	S s	= S(si, sj);
	q.push(s);

	for (i=0; i<h; i++)
		for (j=0; j<w; j++)
			dist[i][j] = INF;
	dist[si][sj] = 0;

	while (!q.empty()) {
		S t = q.front();
		q.pop();


		if (t.x == gj && t.y == gi) break;

		for (i=0; i<4; i++) {
			int nx = t.x + dx[i];
			int ny = t.y + dy[i];
			if (0<=nx && nx<w && 0<=ny && ny<h && data[ny][nx] != 'X' && dist[ny][nx] == INF) {
				dist[ny][nx] = dist[t.y][t.x] + 1;
				q.push(S(ny, nx));
			}
		}
	}

	return dist[gi][gj];	
}

int main()
{
	int i, j;
	int sI, sJ;	
	int res;

	scanf("%d%d%d ", &h, &w, &n);
	data = (char **)calloc(h, sizeof(char *));;
	for (i=0; i<h; i++)
		data[i] = (char *)calloc(w, sizeof(char));

	fX = (int *)calloc(n+1, sizeof(int));;
	fY = (int *)calloc(n+1, sizeof(int));;

	for (i=0; i<h; i++) {
		for (j=0; j<w; j++)
			scanf("%c ", &(data[i][j]));
	}

	for (i=0; i<h; i++) {
		for (j=0; j<w; j++) {
			if (data[i][j] == 'S') {
				fX[0] = j;  	
				fY[0] = i;  	
			} else if (0 < data[i][j] - '0' && data[i][j] - '0' <= n) {
				fX[ (int)(data[i][j] - '0') ] = j;  	
				fY[ (int)(data[i][j] - '0') ] = i;  	
			}
		}
	}

	dist = (int **)calloc(h, sizeof(int *));;
	for (i=0; i<h; i++) 
		dist[i] = (int *)calloc(w, sizeof(int));

	res = 0;
	for (i=0; i<n; i++) 
		res += bfs(fY[i], fX[i], fY[i+1], fX[i+1]);

	printf("%d\n", res);

	for (i=0; i<h; i++)
		free(data[i]);
	free(data);

	for (i=0; i<h; i++)
		free(dist[i]);
	free(dist);

	free(fX);
	free(fY);

	return 0;
}

Measured memory_bytes: 5752
#include <stdio.h>

int main(void) {
  int a= 0;
  int b = 0;
  int area = 0;
  int cir = 0;
 
  scanf("%d %d", &a, &b);
  area = a* b;
  cir =(a+b)*2;
 
  printf("%d %d\n", area, cir);
 
	
	
	return 0;
}

Measured memory_bytes: 596
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n, k;
    cin >> n >> k;

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

    int ret = 0;
    for (int l = 0; l <= n; l++) {
        for (int r = 0; r <= n; r++) {
            // 左からl個、右からr個取る
            if (l + r > n || l + r > k) continue;

            vector <int> vec;
            for (int i = 0; i < l; i++) vec.push_back(v[i]);
            for (int i = 0; i < r; i++) vec.push_back(v[n - 1 - i]);

            sort(vec.begin(), vec.end(), greater<int>());

            int ans = 0;
            int x = k - l - r; // 捨てられる数
            for (int i = 0; i < l + r; i++) {
                if (i >= l + r - x && vec[i] <= 0) break;
                ans += vec[i];
            }

            ret = max(ret, ans);
        }
    }

    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstring>
using namespace std;

#define sz(x) (int)(x.size())
#define fr(i,a,b) for(int i=a;i<b;++i)
#define fdr(i,a,b) for(int i=b-1;i>=a;--i)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

///////////////////////

ll const INF = 1e18;

void solve(){
	ll q, h, s, d;
	ll n;
	cin >> q >> h >> s >> d;
	cin >> n;
	n *= 4LL;
	h = min(h, 2 * q);
	s = min(s, 2 * h);
	d = min(d, s * 2);
	ll ans = 0;
	ans += (n / 8) * d;
	n %= 8;
	ans += (n / 4) * s;
	n %= 4;
	ans += (n / 2) * h;
	n %= 2;
	ans += (n / 1) * q;
	
	cout << ans << endl;
}

int main(){
#ifdef _DEBUG
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif

	solve();



	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 998244353
#define INF 1000000009
typedef long long ll;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define rollcall cout<<"I'm Sucu."<<endl
#define YES(s) s?cout << "YES" << endl:cout << "NO" << endl
#define Yes(s) s?cout << "Yes" << endl:cout << "No" << endl
#define Taka(s) s?cout << "Takahashi" << endl:cout << "Aoki" << endl
#define int ll


signed main(void){
   int A,B;
   cin >> A >> B;
   if(A<=8 && B<=8){
       cout << "Yay!" << endl;
   }else{
       cout << ":(" << endl;
   }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void)
{
  int x, y, z, t;
  
  scanf("%d %d %d",&x, &y, &z);
  
  t=x;
  x=y;
  y=t;
  
  t=x;
  x=z;
  z=t;
  
  printf("%d %d %d", x, y, z);
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
using edge = vector<VI>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T> inline istream& operator>>(istream& input, vector<T>& v) { for (auto& elemnt : v)input >> elemnt; return input; }

int main() {
    init();

    int n, m; cin >> n >> m;
    edge e(n);
    FOR(i, 0, m) {
        int a, b; cin >> a >> b;
        a--, b--;
        e[a].push_back(b);
    }

    VI ans;
    int len = INF;
    FOR(i, 0, n) {
        VI dis(n, -1), prev(n, -1);
        dis[i] = 0;
        queue<int> bfs;
        bfs.push(i);
        while (!bfs.empty()) {
            int from = bfs.front(); bfs.pop();
            for (int to : e[from]) {
                if (dis[to] != -1)continue;
                dis[to] = dis[from] + 1;
                prev[to] = from;
                bfs.push(to);
            }
        }

        FOR(j, 0, n) {
            if (j == i || dis[j] == -1)continue;
            for (int to : e[j]) {
                if (to != i)continue;
                VI p = { i };
                int now = j;
                while (now != i) {
                    p.push_back(now);
                    now = prev[now];
                }
                if (chmin(len, (int)p.size()))ans = p;
            }
        }
    }

    if (len == INF)cout << "-1\n";
    else {
        cout << len << "\n";
        for (int i : ans)cout << i + 1 << "\n";
    }
}


Measured memory_bytes: 384
n = int(input())
S = []
for _ in range(n):
    S.append(input())
alpha = [chr(ord('a') + i) for i in range(26)]
summary = [{c: 0 for c in alpha} for _ in range(n)]
for i, s in enumerate(S):
    for c in s:
        summary[i][c] += 1
ans = ''
for al in alpha:
    _min = 50
    for _su in summary:
        _min = min(_su[al], _min)
    ans += al*_min
print(ans)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long LL;

const int N = 2e5;

struct node{
	int x , y;
	friend bool operator < (node a , node b){
		if(a.x == b.x) return a.y < b.y;
		else return a.x < b.x;
	}
}a[N + 10];

map<node , int> mapp;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
	int n , m;
	scanf("%d %d",&n,&m);
	for(int i = 1 ; i <= m ; i++){
		scanf("%d %d",&a[i].x , &a[i].y);
		mapp[a[i]] = 1;
	}
	int flag = 0;
	for(int i = 1 ; i <= m ; i++){
		if(a[i].x == 1){
			node tmp;
			tmp.x = a[i].y;
			tmp.y = n;
			if(mapp[tmp] == 1) flag = 1;
		}
	}
	if(flag) printf("POSSIBLE\n");
	else printf("IMPOSSIBLE\n");
    return 0;
}

Measured memory_bytes: 20608
def cmbmod(n, r, k):
    #nCr mod kを求める（kは素数）
    p, q = 1, 1
    for i in range(r):
        p = p * (n-i) % k
        q = q * (r-i) % k
    return p * pow(q, k-2, k) % k

n, a, b = [int(_) for _ in input().split()]

const = 10**9 +7

ans = pow(2, n, const)
acmb = cmbmod(n, a, const)
bcmb = cmbmod(n, b, const)
ans = (ans-acmb-bcmb-1) %const

print(ans)

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


int main()
{
	int N=0, A=0, B=0;
	scanf("%d\n", &N);
	if (N == 1) {
		printf("Hello World");
	}
	else {
		scanf("%d\n", &A);
		scanf("%d\n", &B);
		printf("%d\n", A+B);
	}

	return 0;

}

Measured memory_bytes: 256
n = int(input())
a = []
b = []

for _ in range(n):
    c, d = map(int, input().split())
    a.append(c)
    b.append(d)

s = 0
for i in range(n-1, -1, -1):
    r = (a[i] + s) % b[i]
    if r != 0:
        s += b[i] - r
    
print(s)

Measured memory_bytes: 11040
H,W = map(int,input().split())
map_arr = []
ans = []
cnt=0
pos=0
for i in range(H):
  map_arr.extend([[i+1,idx+1,num] for idx,num in enumerate(list(map(int,input().split())))][::(-1)**i])
for x,y,num in map_arr[:-1]:
  if num%2==1:
    cnt+=1
    map_arr[pos+1][2] += 1
    ans.append([map_arr[pos][0],map_arr[pos][1],map_arr[pos+1][0],map_arr[pos+1][1]])
  pos+=1

print(cnt)
for x,y,nx,ny in ans:
  print(x,y,nx,ny)
  

    

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

#define ALL(obj) (obj).begin(), (obj).end()
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,b) for(int i=a; i<=b; i++)
using ll = long long;
#define pb push_back
class Position {
  public: 
    int x;
    int y;
    Position(int y, int x) {
      this->x = x;
      this->y = y;
    }
    Position(const Position& co) {
      this->x = co.x;
      this->y = co.y;
    }
    Position() {
      this->x = 0;
      this->y = 0;
    }
    bool equal(Position &a) {
      if ( (this->x == a.x) && (this->y == a.y) )
        return true;
      else 
        return false;
    }
};

int main()
{
  string s;
  int x,y;
  cin >> s;
  cin >> x >> y;
  set<int> hor;
  set<int> vec;
  vector<int> s_h;
  vector<int> s_v;

  int mod = 0; // for hor

  int i=0;
  while( i < s.size()) {
    int oldi = i;
    while ( (s[i] == 'F') && (i < s.size()) ) i++ ;
    if (mod == 0) {
      s_h.pb(i-oldi);
      mod = 1;
      i++;

    } else {
      s_v.pb(i-oldi);
      mod = 0;
      i++;
    }
  }

  hor.insert(s_h[0]);
  vec.insert(0);

  rep2(i,1, s_h.size()-1) {
    set<int> next_hor;
    for(auto c : hor) {
      next_hor.insert(c + s_h[i]);
      next_hor.insert(c - s_h[i]);
    }
    hor = next_hor;
  }


  rep(i, s_v.size()) {
    set<int> next_vec;
    for(auto c : vec) {
      next_vec.insert(c + s_v[i]);
      next_vec.insert(c - s_v[i]);
    }
    vec = next_vec;
  }



  if (  (hor.find(x) != hor.end()) && ((vec.find(y)) != vec.end()) ) {
    cout << "Yes" << endl;
    return 0;
  }
  cout << "No" << endl;

}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define vi vector<int>
#define pb push_back
#define pi pair<int,int>
#define vp vector<pair<int,int> >
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define INF 1000000000
#define eps 1e-7
#define mod 1000000007
#define int ll
using namespace std;

int P[100000 + 10];
vi adj[100000 + 10];
int in_deg[100000 + 10];

signed main(void) {
    int N, M;
    cin >> N >> M;
    
    REP(i, 1, N) P[i] = i;

    rep(i, N-1+M) {
        int A, B;
        cin >> A >> B;
        in_deg[B]++;
        adj[A].push_back(B);
    }
    
    /* breadth first search */
    queue<int> Q;
    REP(i, 1, N) if (in_deg[i] == 0) Q.push(i);
    while(!Q.empty()) {
        int top = Q.front();
        Q.pop();
        for (auto node : adj[top]) {
            in_deg[node]--;
            if (in_deg[node] == 0) {
                Q.push(node);
                P[node] = top;
            }
        }
    }
    
    REP(i, 1, N) {
        if (P[i] == i) cout << 0 << endl;
        else cout << P[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 7808
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
Mod = 10 ** 9 + 7

sum = 0
for i in 1..N do
  sum += lines[1][i-1]
end

sum_sc = 0
for i in 1..N do
  sum_sc += lines[1][i-1] ** 2
end

puts ((sum ** 2 - sum_sc) / 2) % Mod

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

using namespace std;

string ChangeFlickInput(const string&);
char Consonant(const char&);
char Vowel(const char&);

int main(){
  string str;
  cin >> str;
  cout << ChangeFlickInput(str) << endl;
  return 0;
}

string ChangeFlickInput(const string& in){
  string out;
  for(int i=0; i<in.size(); i+=2){
    if(in[i] == '0' && in[i+1] == 'U'){
      out.append("nn");
      continue;
    }
    if(in[i] == '1'){
      out.push_back(Vowel(in[i+1]));
      continue;
    }
    out.push_back(Consonant(in[i]));
    out.push_back(Vowel(in[i+1]));
  }
  return out;
}

char Consonant(const char& c){
  if(c == '2') return 'k';
  if(c == '3') return 's';
  if(c == '4') return 't';
  if(c == '5') return 'n';
  if(c == '6') return 'h';
  if(c == '7') return 'm';
  if(c == '8') return 'y';
  if(c == '9') return 'r';
  return 'w';
}

char Vowel(const char& c){
  if(c == 'T') return 'a';
  if(c == 'L') return 'i';
  if(c == 'U') return 'u';
  if(c == 'R') return 'e';
  return 'o';
}

Measured memory_bytes: 1184
x =list(map(int, input().split()))
y =list(map(int, input().split()))
z =list(map(int, input().split()))

if (sum(x)-sum(y)) % 3 == 0 and (sum(x)-sum(z)) % 3 ==0 \
    and ((x[0] + y[0] + z[0]) - (x[1] + y[1] + z[1])) % 3 ==0\
    and ((x[0] + y[0] + z[0]) - (x[2] + y[2] + z[2])) % 3 ==0:
        print('Yes')
else:
    print('No')

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

int main(void) {
    int N;
    char str[100] = "ABC";
    scanf("%d", &N);

    if (N>999) {
        str[2] += 1;
    }
    printf("%s\n", str);
    
    return 0;
}

Measured memory_bytes: 128
// at_abc141c.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
const int MAXN = 1e5 + 5;
int main()
{
    int players, points, wins;cin >> players >> points >> wins;
    int arr[MAXN];
    memset(arr, 0, sizeof(arr));
    for (int i = 0;i < wins;i++) {
        int temp;cin >> temp;
        arr[temp]++;
    }
    for (int i = 1;i <= players;i++) {
        if (wins - arr[i] < points) {
            cout << "Yes\n";
        }
        else {
            cout << "No\n";
        }
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define i_7 (ll)(1E9+7)
#define i_5 (ll)(1E9+5)
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
ll inf=(ll)1E12;//10^12
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
const double EPS=1E-8;
////////////////////////////////////////

bool match(string s,int k){
    int n=s.size();
    if(k>=n-2||n<=2)return false;
    if(s[k]=='A'&&s[k+1]=='B'&&s[k+2]=='C')return true;
    else return false;
}

bool dfs(string s){
    if(s=="ABC")return true;
    int n=s.size();
    if(n<=3)return false;
    
    vector<int>v;
    int c[3];memset(c,0,sizeof(c));
    rep(i,0,n-1){
        if(match(s,i)){
            v.pb(i);
            i+=2;
        }else{
            c[s[i]-'A']++;
        }
    }
    if(v.size()==0)return false;
    rep(i,0,2){
        if(c[i]==0){
            string t;
            int pos=0;
            rep(j,0,n-1){
                if(pos<=v.size()-1&&v[pos]==j){
                    t+=('A'+i);
                    j+=2;
                    pos++;
                }else{
                    t+=s[j];
                }
            }
            if(dfs(t))return true;
        }
    }
    return false;
}


int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    
    string s;cin>>s;
    if(dfs(s))cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    
    return 0;
}


Measured memory_bytes: 21784
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n; cin >> n;
	int ans=0;
	vector<string> s(n);
	for(int i=0;i<n;i++){
		cin >> s[i];
		if(s[i]=="E869120") ans++;
	}
	cout << ans << endl;
}


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

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

    string S;
    cin >> S;

    stack<char> st;

    int x = 0;
    for (int i=0; i<S.size(); i++) {
        if (S[i] == '(') {
            st.push('(');
        } else {
            if (st.empty()) {
                x++;
            } else {
                st.pop();
            }
        }
    }
    
    cout << string(x, '(') + S + string(st.size(),')') << endl;
    
    return 0;
}

Measured memory_bytes: 256
a, b, q = gets.split.map(&:to_i)

s = [-1 << 36] + a.times.map {gets.to_i} + [1 << 36]
t = [-1 << 36] + b.times.map {gets.to_i} + [1 << 36]

q.times do
    x = gets.to_i

    i = s.bsearch_index{|e| e >= x}
    j = t.bsearch_index{|e| e >= x}

    p [x - [s[i-1], t[j-1]].min, 
       [s[i], t[j]].max - x,
       t[j] - s[i-1] + [x - s[i-1], t[j] - x].min, 
       s[i] - t[j-1] + [s[i] - x, x - t[j-1]].min].min
end

Measured memory_bytes: 8116
PROGRAM ATCODER

implicit none
integer :: n, i, gcd, x, y, t
integer,allocatable :: a(:)

read(*,*) n
allocate(a(n))
read(*,*) (a(i), i = 1,n)

call hs(n,a)

gcd = a(1)
do i = 1, n-1
x = a(i+1)
y = gcd
	do 
    	if(mod(x,y) == 0) then
        	gcd = y
            exit
		end if
        t = y
        y = mod(x,y)
        x = t
    end do
    
    if(gcd == 1)then
    	write(*,'(i0)') gcd
        stop
    end if
end do

write(*,'(i0)') gcd
 
END PROGRAM ATCODER

subroutine hs(n,array)
  implicit none
  integer,intent(in) :: n
  integer,intent(inout) :: array(1:n)
  
  integer ::i,k,j,l
  integer :: t
  
  if(n <= 0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n == 1)return
 
  l=n/2+1
  k=n
  do while(k /= 1)
     if(l > 1)then
        l=l-1
        t=array(L)
     else
        t=array(k)
        array(k)=array(1)
        k=k-1
        if(k == 1) then
           array(1)=t
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j <= k)
        if(j < k)then
           if(array(j) < array(j+1))j=j+1
        endif
        if (t < array(j))then
           array(i)=array(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     enddo
     array(i)=t
  enddo
 
  return
end subroutine hs

Measured memory_bytes: 1152
#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;

using u128 = __uint128_t;

#define int long long
#define idxSet tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define atIdx find_by_order
#define idxOf order_of_key
#define MOD 1000000007
#define MAX 200005
#define endl '\n'

#define v(type) vector<type>
#define p(type1, type2) pair<type1 , type2>
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

int dp[MAX];

void solve() {
    int n , k;
    cin>>n>>k;
    int a[n];
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    int mini = LONG_LONG_MAX;
    for(int i = 0 ; i <= n - k ; i++){
        if(a[i] <= 0 &&  0 <= a[i + k - 1] ){
            mini = min(mini ,  + a[i+ k -1] - 2 * a[i]);
            mini = min(mini , 2 * a[i + k - 1]  - a[i]);
        }else if(a[i + k - 1] <= 0){
            mini = min(mini , -a[i]);
        }else {
            mini = min(mini , a[i + k - 1]);
        }
    }
    cout<<mini<<endl;
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    //cin>>t;
    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 1024