akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)

int main(){
    int n,K;
    
    while(cin >> n >> K , n + K){
        map<string,int> m;
        string str[11],in;
        rep(i,n){
            cin >> str[i];
        }
        int cnt = 0;
        if(K == 2){
            rep(i,n){
                rep(j,n){
                    if(i == j) continue;
                    in = str[i]+str[j];
                    if(!m[in]){
                        m[in]++;
                        cnt++;
                    }
                }
            }
        }
        else if(K == 3){
            rep(i,n){
                rep(j,n){
                    if(i == j) continue;
                    rep(k,n){
                        if(i == k ||j == k) continue;
                        in = str[i]+str[j]+str[k];
                        if(!m[in]){
                            m[in]++;
                            cnt++;
                        }
                    }
                }
            }
        }
        else{
            rep(i,n){
               rep(j,n){
                   if(i == j) continue;
                    rep(k,n){
                        if(i == k || j == k) continue;
                        rep(l,n){
                            if(i == l || j == l || k == l) continue;
                            in = str[i]+str[j]+str[k]+str[l];
                            if(!m[in]){
                                m[in]++;
                                cnt++;
                            }
                        }
                    }
                }
            }
        }
        cout << cnt << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1508
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if((a+b) > (c+d)) cout << "Left" << endl;
  else if((a+b) == (c+d)) cout << "Balanced" << endl;
  else cout << "Right" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int N, sum = 0, n;
	scanf("%d", &N);
	n = N;

	while (N != 0) {
		sum += N % 10;
		N /= 10;
	}

	if ((n % sum) == 0) {
		printf("Yes");
	} else {
		printf("No");
	}

	return 0;
}

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

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

using ll = long long;
using i_i = tuple<int, int>;

bool digit(char c) {
    return '0' <= c && c <= '9';
}

vector<int> f(string s) {
    int N = s.length();
    vector<int> v;
    v.pb(0);
    for (int i = 1; i <= N - 1; i++)
        if (!digit(s[i - 1]) || !digit(s[i]))
            v.pb(i);
    v.pb(N);
    vector<int> ans;
    rep(k, v.size() - 1) {
        int l = v[k];
        int r = v[k + 1];
        if (digit(s[l])) ans.pb(stoi(s.substr(l, r - l)));
        else ans.pb(1e9 + s[l]);
    }
    return ans;
}

int main() {
    int Q; cin >> Q;
    string s; cin >> s;
    vector<int> a = f(s);
    while (Q--) {
        string t; cin >> t;
        vector<int> b = f(t);
        cout << (b < a ? '-' : '+') << endl;
    }
}



Measured memory_bytes: 3208
N, M = map(int, input().split())
# x = [0]*M
# y = [0]*M
	

##
dp = [False]*(N+1)
dp[1] = True
ball = [1]*(N+1)

for i in range(M):
	x, y = map(int, input().split())
	ball[x] -= 1
	ball[y] += 1
	if dp[x]:
		dp[y] = True
		if ball[x] == 0:
			dp[x] = False

cnt = 0
for i in range(1, N+1):
	if dp[i]:
		cnt += 1

print(cnt)


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

#define MAX 1000000

int main(void) {
	char s[MAX+1];
	int i;

	while (fgets(s, MAX, stdin) != NULL) {
		s[strlen(s)-1] = '\0';	// üsR[hÆ½©iUS(ASCII CODE 0x1F) jbgæØèHjðí

		for (i = 0; i < strlen(s); i++) {
			if ('a' <= s[i] && s[i] <= 'z')
				s[i] += 'A'-'a';
			printf("%1c", s[i]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp7
{
	class Program
	{
		static void Main(string[] args)
		{
			var dice = Console.ReadLine().Split(' '); //1~6面の数字
			var N = Console.ReadLine(); //転がす方向
			string top = dice[0]; //開始位置,上
			string front = dice[1];
			string right = dice[2];
			string left = dice[3];
			string back = dice[4];
			string bottom = dice[5];
			string n_top = top;
			string n_front = front;
			string n_right = right;
			string n_left = left;
			string n_back = back;
			string n_bottom = bottom;


			for(int i = 0; i < N.Length; i++)
			{
				string r = N.Substring(i, 1); //方角を1文字ずつ取得
				

				switch (r)
				{
					case "N":
						n_top = front;
						n_front = bottom;
						n_back = top;
						n_bottom = back;
						break;

					case "E":
						n_top = left;
						n_right = top;
						n_left = bottom;
						n_bottom = right;
						break;

					case "S":
						n_top = back;
						n_front = top;
						n_back = bottom;
						n_bottom = front;
						break;

					case "W":
						n_top = right;
						n_right = bottom;
						n_left = top;
						n_bottom = left;
						break;
				}

				top = n_top;
				front = n_front;
				right = n_right;
				left = n_left;
				back = n_back;
				bottom = n_bottom;

			}

			Console.WriteLine(top);
			
		}
	}
}



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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

struct N {
  ll a, b;
};

bool operator<(const N &l, const N &r) {
  return l.b > r.b;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n), b(n), aa, bb;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) cin >> b[i];
  aa = a;
  bb = b;
  sort(aa.begin(), aa.end());
  sort(bb.begin(), bb.end());
  for (int i = 0; i < n; i++) {
    if (aa[i] > bb[i]) {
      cout << "No" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == b[i]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  for (int i = 1; i < n; i++) {
    if (aa[i - 1] <= bb[i] && aa[i] <= bb[i - 1]) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  map<ll, ll> mp;
  for (int i = 0; i < n; i++) {
    mp[aa[i]] = bb[i];
  }
  map<ll, int> ainv, binv;
  for (int i = 0; i < n; i++) {
    ainv[a[i]] = i;
    binv[b[i]] = i;
  }

  for (int i = 0; i < n - 1; i++) {
    if (mp[a[i]] == b[i]) {
      cout << "Yes" << endl;
      return 0;
    } else {
      ll tmp = b[i];
      b[i] = mp[a[i]];
      int j = binv[mp[a[i]]];
      b[binv[mp[a[i]]]] = tmp;
      binv[tmp] = j;
    }
  }
  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 23808
#include <bits/stdc++.h>
#define inf 100000000
using namespace std;
int main (){
 int n,m;

 cin >> n >> m;

 if(n>m){
     int t=n;
     n=m;
     m=t;
 }

 for(int i=0;i<m;i++){
     cout << n;
 }
 cout<< endl;

 return 0;
}

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

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

    vector<int> t(n);
    int sum = 0;
    rep(i,n)
    {
        t[i] = l+i;
        sum += l+i;
    }

    int ans = 0;
    int min_diff = 1e9;
    rep(i,n)
    {
        if(abs(t[i]) < min_diff)
        {
            min_diff = abs(t[i]);
            ans = sum - t[i];
        }
    }

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

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    int n,x,y; cin>>n>>x>>y;
    x--; y--;
    vector<int> k(n-1,0);
    for(int i=0;i<n-1;i++){
        for(int j=i+1;j<n;j++){
            int a=min(j-i,abs(x-i)+abs(y-j)+1);
            k[a-1]++;
        }
    }
    rep(i,n-1) cout<<k[i]<<endl;
}

Measured memory_bytes: 256
#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 rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

#define MAXN 400

ll dp[MAXN+10][MAXN+10];
bool used[MAXN+10][MAXN+10];
vector<ll>a(MAXN+10), suma(MAXN+10);


ll f(int l, int r){
  if(used[l][r])return dp[l][r];
  used[l][r]=true;

  if(l==r)return 0;

  ll sum = suma[r]-suma[l-1];
  ll fans = INF;
  for(int m=l; m<=r; m++){
    fans = min<ll>( fans, f(l, m) + f(m+1, r) );
  }
//cout<<l<<' '<<r<<' '<<sum<<' '<<fans<<endl;
  return dp[l][r] = fans + sum;
}

int main(){
  int n;cin>>n;
  rep(i, n)cin>>a[i];
  ll sum=0;
  rep(i, n)sum+=a[i];
  rep(i, n)suma[i+1]+=suma[i]+a[i];

  cout<<f(1, n)<<endl;

  return 0;

rep(i, n+1){
  rep(j, n+1)cout<<dp[i][j]<<' ';
  cout<<endl;
}

  return 0;
}


Measured memory_bytes: 5060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
using namespace std;

typedef long long int ll;



int n,m,k;
int main(void){
	cin >> n >> m >> k;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=m;j++){
			int c = i*j + (n-i)*(m-j);
			if (c==k) {cout << "Yes" << endl; return 0;}
		}
	}
	cout << "No" << endl;

	return 0;
}


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

int h, w, x;
int g[12][12], ans;

int main(){
    cin >> h >> w;
    for(int i = 0; i <= 9; ++i){
        for(int j = 0; j <= 9; ++j){
            cin >> g[i][j];
        }
    }
    for(int i = 0; i <= 9; ++i){
        for(int j = 0; j <= 9; ++j){
            for(int k = 0; k <= 9; ++k){
                g[j][k] = min(g[j][k], g[j][i] + g[i][k]);
            }
        }
    }
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> x;
            if(x != -1){
                ans += g[x][1];
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

int calculate(string a){
  //vector<char> max(a.size());
  //vector<char> min(a.size());
  //max = a.c_str();
  //min = max;

  string max(a, 0, a.size());
  string min(a, 0, a.size());

  sort(min.begin(),min.end());
  sort(max.begin(), max.end(), greater<char>());

  int subtract = stoi(max) - stoi(min);
  return subtract;
}

int main(){
  string a0;
  int l;
  while(cin>>a0>>l&&a0!="0",l!=0){
    vector<string> a;
    if(a0.size()!=l) {
      a0.insert(a0.begin(), l-a0.size(), '0');
    }
    a.push_back(a0);

    while(a.size()<=20){
      int res;

      res = calculate(a[a.size()-1]);
      a.push_back(to_string(res));

      // 0を前に加える処理
      if(a[a.size()-1].size()!=l){
        a[a.size()-1].insert(a[a.size()-1].begin(), l-a[a.size()-1].size(), '0');
      }

      int flag=0;
      for(int i=0;i<a.size()-1;i++){
        if(a[i]==a[a.size()-1]){
          cout << i << " " << stoi(a[a.size()-1], nullptr, 10) << " " << a.size()-1-i << endl;
          flag=1;
        }
      }

      if(flag==1) {
        break;
      }
    }

  }

  return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = 998244353;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;

int main() {
    cin>>N>>S;
    string red, blue;
    ll r, b, min_roop, ans = 0;
    rep(s, (1LL<<N)){
        red = blue = "";
        rep(j,N) ((s>>j)&1 ? red.push_back(S[j]) : blue.push_back(S[j]));
        //reverse(ALL(red)), reverse(ALL(blue));
        r = red.size(), b = blue.size();
        //min_roop = min(r, b);
        mat dp(r+1, vec(b+1,0));
        dp[0][0] = 1;
        Rreps(revi, N*2, N){
            ll roop = N*2 + 1 - revi;
            rep(i, roop){
                ll j = roop - 1  - i;
                if(i > r || j > b) continue;
                if(i != 0) if(S[revi] == red[i - 1]) dp[i][j] += dp[i-1][j];
                if(j != 0) if(S[revi] == blue[j - 1]) dp[i][j] += dp[i][j-1];
                if(revi == N) ans += dp[i][j];
            }
        }
        /*if(s == 2){
            rep(i,r+1){
                rep(j,b+1) cout<<dp[i][j]<<' ';
                cout<<endl;
            }
        }*/
        //cout<<bitset<4>(s)<<' '<<ans<<endl;
    }
    cout<<ans<<endl;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

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

  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  set<int> st;
  int tmp = 0;
  rep(i, n) {
    if(a[i] < 400) st.insert(0);
    else if(a[i] < 800)  st.insert(1);
    else if(a[i] < 1200) st.insert(2);
    else if(a[i] < 1600) st.insert(3);
    else if(a[i] < 2000) st.insert(4);
    else if(a[i] < 2400) st.insert(5);
    else if(a[i] < 2800) st.insert(6);
    else if(a[i] < 3200) st.insert(7);
    else tmp++;
  }

  cout << max((int)st.size(), 1) << " " << st.size()+tmp << '\n';
  return 0;
}


Measured memory_bytes: 256
N, x = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)

sum = 0
ans = 0
for i in range(len(a)):
    sum += a[i]
    if x >= sum:
        ans += 1
        if ans == N:
            if sum != x:
                ans -= 1
                break
    else:
        break
print(ans)


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

using namespace std;
typedef long long ll;

const int N = 100'010;
vector<int> f[N], b[N];
int group[N], sz[N];

void dfs(int v, int p, int g) {
    group[v] = g, sz[g]++;
    for (auto to : f[v]) {
        if (to == p || group[to]) continue;
        dfs(to, v, g);
    }
}

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    int u, v;
    for (int i = 0; i < m; i++) {
        cin >> u >> v;
        f[u].push_back(v), f[v].push_back(u);
    }
    for (int i = 0; i < k; i++) {
        cin >> u >> v;
        b[u].push_back(v), b[v].push_back(u);
    }
    int g = 1;
    for (int i = 1; i <= n; i++) {
        if (!group[i]) {
            dfs(i, -1, g);
            g++;
        }
    }
    for (int i = 1; i <= n; i++) {
        int ans = sz[group[i]] - f[i].size() - 1;
        for (auto to : b[i]) {
            if (group[to] == group[i]) ans--;
        }
        cout << ans << " ";
    }
    cout << "\n";
}


Measured memory_bytes: 15900
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
ll n;
cin>>n;
n--;
if(n%2==0)cout<<(n+1)*(n/2)<<endl;
else cout<<(n)*((n-1)/2)+n<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
    deque<char> dq;
	string s;
    cin>>s;
    for(const auto x:s){
        dq.push_back(x);
    }
    int q,f=0;
    cin>>q;
    FOR(i,0,q){
        int t;
        cin>>t;
        t--;
        if(t==0){
            f^=1;
        }else{
            int ff;
            string ss;
            cin>>ff>>ss;
            ff--;
            ff^=f;
            if(ff==1){
                dq.push_back(ss[0]);
            }else{
                dq.push_front(ss[0]);
            }
        }
    }
    while (dq.size())
    {
        char a;
        if(f==0){
            a=dq.front();
            dq.pop_front();
        }else{
            a=dq.back();
            dq.pop_back();
        }
        cout<<a;
    }
    
}


Measured memory_bytes: 896
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            long N = sc.nextLong();

            BigInteger ans = BigInteger.valueOf(N).multiply(BigInteger.valueOf(N - 1)).divide(BigInteger.valueOf(2));

            System.out.println(ans);
        }
    }

}


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T>
struct SegmentTree{
  using F = function<T(T,T)>;
  F f;
  T ti;
  SegmentTree(F f,T ti):f(f),ti(ti){}

  struct Node{
    Node *l,*r;
    T dat;
    Node(T dat):dat(dat){l=r=nullptr;}
  };

  Node* clone(Node *a){
    return new Node(*a);
  }

  Node* reflect(Node *a){
    a->dat=f(a->l->dat,a->r->dat);
    return a;
  }

  int n,height;
  Node* build(const vector<T> &v){
    int n_=v.size();
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    vector<Node*> vs(n<<1);
    for(int i=0;i<n_;i++) vs[n+i]=new Node(v[i]);
    for(int i=n_;i<n;i++) vs[n+i]=new Node(ti);
    for(int i=n-1;i;i--){
      vs[i]=new Node(ti);
      vs[i]->l=vs[(i<<1)|0];
      vs[i]->r=vs[(i<<1)|1];
      reflect(vs[i]);
    }
    return vs[1];
  }

  Node* set_val(Node* t,int k,T x,int h){
    t=clone(t);
    if(h<0){
      t->dat=x;
      return t;
    }
    if((k>>h)&1) t->r=set_val(t->r,k,x,h-1);
    else t->l=set_val(t->l,k,x,h-1);
    return reflect(t);
  }

  T query(Node* t,int l,int r,int lb,int ub){
    if(r<=lb||ub<=l) return ti;
    if(l<=lb&&ub<=r) return t->dat;
    int m=(lb+ub)>>1;
    return f(query(t->l,l,r,lb,m),query(t->r,l,r,m,ub));
  }

  Node* set_val(Node* t,int k,T x){
    return set_val(t,k,x,height-1);
  }

  T query(Node* t,int l,int r){
    return query(t,l,r,0,n);
  }
};
//END CUT HERE
//INSERT ABOVE HERE
signed HAPPYQUERY_B(){
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  auto f=[](int a,int b){return min(a,b);};
  int ti=INT_MAX;
  SegmentTree<int> seg(f,ti);
  auto rt=seg.build(as);

  vector<decltype(rt)> rts;
  rts.emplace_back(rt);

  int q1;
  cin>>q1;
  rts.reserve(q1+1);

  for(int i=0;i<q1;i++){
    int p,x;
    cin>>p>>x;
    p--;
    rt=seg.set_val(rt,p,x);
    rts.emplace_back(rt);
  }

  int q2;
  cin>>q2;
  int x=0;
  for(int i=0;i<q2;i++){
    int a,b,c;
    cin>>a>>b>>c;
    int k=a^x;
    int l=(b^x)-1;
    int r=(c^x);
    assert(l<r);
    x=seg.query(rts[k],l,r);
    cout<<x<<"\n";
  }
  cout<<flush;
  return 0;
}
/*
  verified on 2019/06/22
  https://www.hackerrank.com/contests/happy-query-contest/challenges/minimum-history-query
*/

signed AOJ_3024(){
  cin.tie(0);
  ios::sync_with_stdio(0);

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

  auto f=[](int a,int b){return min(a,b);};
  int ti=INT_MAX;
  SegmentTree<int> seg(f,ti);
  auto ra=seg.build(as);
  auto rb=seg.build(bs);

  int q;
  cin>>q;
  for(int i=0;i<q;i++){
    int x,y,z;
    cin>>x>>y>>z;
    y--;
    if(x==1) ra=seg.set_val(ra,y,z);
    if(x==2) rb=seg.set_val(rb,y,z);
    if(x==3) cout<<seg.query(ra,y,z)<<"\n";
    if(x==4) cout<<seg.query(rb,y,z)<<"\n";
    if(x==5) ra=seg.clone(rb);
    if(x==6) rb=seg.clone(ra);
  }
  cout<<flush;
  return 0;
}

signed main(){
  //HAPPYQUERY_B();
  AOJ_3024();
  return 0;
}



Measured memory_bytes: 91532
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
	int n; cin>>n; vector<ll>a(n); for(int i=0;i<=n-1;i++) cin>>a[i];
	ll r=a[0];
	for(int i=1;i<=n-1;i++) r^=a[i];
    for(int i=0;i<=n-1;i++){ ll res=r^a[i]; cout<<res<<" ";}
    	return 0;
}


Measured memory_bytes: 4708
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
int N;
string S;
vector<int> R,G,B;

void solve(){
    int64_t ans = 0;
    int l,r,dame1,dame2,dame3;

    for(int a:R){
        for(int b:G){

            l = min(a,b);
            r = max(a,b);

            dame1 = 2*l-r;
            dame2 = 2*r-l;
            if((l-r)%2 == 0) dame3 = (l+r)/2;
            else dame3 = -1;
            
            ans += B.size();
            if(dame1 >=0 && dame1 <= N-1 && S.at(dame1) == 'B'){ans--;}
            if(dame2 >=0 && dame2 <= N-1 && S.at(dame2) == 'B'){ans--;}
            if(dame3 >=0 && dame3 <= N-1 && S.at(dame3) == 'B'){ans--;}
        }
    }
    cout << ans << endl;
}

int main(){
    cin >> N >> S;
    rep(i,N){
        if(S.at(i) == 'R') R.push_back(i);
        else if(S.at(i) == 'G') G.push_back(i);
        else B.push_back(i);
    }
    solve();
}   

Measured memory_bytes: 3668
#include<bits/stdc++.h>
using namespace std;
 
#define f first
#define s second
#define pb push_back
#define ll long long
#define MAX 100005
#define mp make_pair
const int M=1e9+7;
vector<int> adj[MAX];
bool vis[MAX];
ll qpow(ll x, ll k,ll m) {return k==0? 1: 1ll*qpow(1ll*x*x%m,k>>1,m)*(k&1?x:1)%m;}
ll modinv(ll a,ll m){ll g=__gcd(a,m);return (g==1)? qpow(a,m-2,m):-1;}

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int n;
    cin>>n;
    double dp[n+1][n+1];
    double p[n+1];
    for(int i=1;i<=n;i++)
        cin>>p[i];
    dp[0][0]=1.0;
    for(int i=1;i<=n;i++)
    {
        dp[i][0]=dp[i-1][0]*(1-p[i]);
        for(int j=1;j<=i;j++)
        {
            dp[i][j]=dp[i-1][j-1]*p[i] + dp[i-1][j]*(1-p[i]);
        }
    }
    double ans=0;
    for(int i=(n+1)/2;i<=n;i++)
        ans+=dp[n][i];
    printf("%.15lf",ans);
    return 0;
}




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

//#define int long long
typedef long long ll;
//const int INF = 2e9;
const ll INF = 9e18;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i=0;i<N;i++) cin >> A[i];
    vector<int> B(N);
    for (int i=0;i<N;i++) B[i] = A[i] - (i+1);
    sort(B.begin(),B.end());
    ll ans = INF;
    if (N%2==1){
        ll sum = 0;
        for (int i=0;i<N;i++){
            sum += abs(B[i] - B[(N-1)/2]);
        }
        ans = min(ans, sum);
    } else {
        ll sum = 0;
        for (int i=0;i<N;i++){
            sum += abs(B[i] - B[(N-1)/2]);
        }
        ans = min(ans,sum);
        sum = 0;
        for (int i=0;i<N;i++){
            sum += abs(B[i] - B[N/2]);
        }
        ans = min(ans,sum);
    }
    cout << ans << "\n";
}

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

int main(){
    stack<int> x;
    int a,b;
    string s;
    while(cin >> s){
        if(s[0] == '+'){
            a = x.top();
            x.pop();
            b = x.top();
            x.pop();
            x.push(a + b);
        }
        else if(s[0] == '-'){
            a = x.top();
            x.pop();
            b = x.top();
            x.pop();
            x.push(b-a);
        }else if(s[0] == '*'){
            a = x.top();
            x.pop();
            b = x.top();
            x.pop();
            x.push(a * b);
        }else{
            int y = atoi(s.c_str());
            x.push(y);
        }
    }    
    cout << x.top() << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const int INF = 1e9;

int main(void){

	
	int A[3][3];

	REP(i,3) REP(j,3) cin >> A[i][j];

	int flag[3][3] = {0};
	int N; cin >> N;

	REP(i,N){
		int b; cin >> b;
		REP(j,3){
			REP(k,3){
				if(b == A[j][k]) flag[j][k] = 1;
			}
		}
	}

	bool ans = false;
	if((flag[0][0] + flag[0][1] + flag[0][2]) == 3) ans = true;
	else if((flag[1][0] + flag[1][1] + flag[1][2]) == 3) ans = true;
	else if((flag[2][0] + flag[2][1] + flag[2][2]) == 3) ans = true;
	else if((flag[0][0] + flag[1][0] + flag[2][0]) == 3) ans = true;
	else if((flag[0][1] + flag[1][1] + flag[2][1]) == 3) ans = true;
	else if((flag[0][2] + flag[1][2] + flag[2][2]) == 3) ans = true;
	else if((flag[0][0] + flag[1][1] + flag[2][2]) == 3) ans = true;
	else if((flag[0][2] + flag[1][1] + flag[2][0]) == 3) ans = true;

	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;


	return 0;

}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int c[1000001];
inline void solve(){
    int n; cin>>n; 
    int g=0,mx=0;
    for (int i=0,a;i<n;i++){
        cin >> a ; 
        c[a]++;
        g = __gcd(g,a);
    }
    if (g != 1){
        cout << "not coprime" << endl;
        return ;
    }
    int p=1;
    for (int i=2;i<=1000000;i++){
        int cur=0;
        for (int j=i;j<=1000000;j+=i) cur += c[j];
        if (cur>1) {
            p = 0; break;
        }
        if (i&1) i++;
    }
    if (p>0) cout << "pairwise coprime" << endl;
    else cout << "setwise coprime" << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}
// https://atcoder.jp/contests/abc177/tasks/abc177_e


Measured memory_bytes: 11400
#include<stdio.h>

int main()
{
	int a , b , c;
	scanf("%d %d %d" , &a , &b , &c);
	if(a<b && b<c)
	{
		printf("Yes\n");
	}
	else
	{
		printf("No\n");
		}
			
	return 0;
 } 


Measured memory_bytes: 2608
#include<cstdio>
#define MAX 100
int A[MAX][MAX] = {0};

int main()
{
	int n,u,k,v;
	scanf("%d", &n);
	for(int i=0; i<n; i++)
	{
		scanf("%d%d", &u, &k);
		for(int j=0; j<k; j++)
		{
			scanf("%d", &v);
			A[u-1][v-1] = 1;
		}
	}

	for(int i=0; i<n; i++)
	{
		for(int j=0; j<n; j++)
		{
			if(j) printf(" ");
			printf("%d", A[i][j]);
		}
		printf("\n");
	}

	return 0;

}


Measured memory_bytes: 2776
#include<bits/stdc++.h>
#define PI 3.1415926535898
using namespace std;

double a,b,x;
double theta;

int main()
{
	scanf("%lf %lf %lf",&a,&b,&x);
	double h=x*2.0/(a*b);
	if(h>a) {
		double tmp=2.0*x/a/a;
		double t=2.0*b-tmp;
		theta=atan(t/a);
	}
	else {
		theta=atan(b/h);
	}
	theta=theta*180.0/PI;
	printf("%.8lf",theta);
}

Measured memory_bytes: 384
#include <stdio.h>

int main(){
  long i,n,a[200005],b[200005],c,m=0;
  scanf("%ld",&n);
  for(i=0;i<n;i++){
    b[i]=0;
  }
  for(i=0;i<n;i++){
    scanf("%ld",&c);
    a[i]=c-1;
    b[c-1]++;
  }
  for(i=0;i<n;i++){
    m+=b[i]*(b[i]-1)/2;
  }
  for(i=0;i<n;i++){
    printf("%ld\n",m-b[a[i]]+1);
  }
  return(0);
}

Measured memory_bytes: 5632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<utility>
using namespace std;
#define MS(m,z) memset(m,z,sizeof(m))
typedef unsigned U; typedef pair<int,int > P; typedef long long ll;
void inp();
int main(){
#ifdef XS
	//freopen(".in","r",stdin);
#endif
	inp();
	return 0;
}
int cnt2,cnt4;
void inp(){
	int f,i,x;
	int n;scanf("%d",&n);
	for(i=0;i<n;i++){scanf("%d",&x);
		if(x%4==0)cnt4++;
		else if(x%2==0)cnt2++;
	}
	if(cnt2)n-=cnt2,n++;
	if(cnt4>=n/2)f=1;
	else f=0;
	char ans[][10]={"No","Yes"};
	puts(ans[f]);
}
//at80c.cc by xsthunder at Sun Aug  6 20:08:31 2017


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

int A,B,C,X;
int a[405][5];

int max(int a, int b)
{
	return (a>=b?a:b);
}
int main()
{
//	freopen("in.txt","r",stdin);
//	freopen("out.txt","w",stdout);

	scanf("%d%d%d%d",&A,&B,&C,&X);
	memset(a,0,sizeof(a));		
	X /= 50;
	int count = 0;
	for(int i=0;i<=A;i++)
	{
		for(int j=0;j<=B;j++)
		{
			for(int k=0;k<=C;k++)
			{
				if(i*10+j*2+k==X)
				{
					count++;
				}
			}
		}
	}
	printf("%d\n",count);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;
 
class Main {
	int n;
	int m;
	int[] ab;
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		Main m = new Main(sc);
		m.solve();
		sc.close();
	}
	Main(Scanner sc){
		n = sc.nextInt();
		m = sc.nextInt();
		ab = new int[2*m];
		for(int i=0;i<2*m;i+=2){
			ab[i] = sc.nextInt();
			ab[i+1] = sc.nextInt();
		}
	}
	void solve(){
		int[] c = new int[n];
		for(int i=0;i<2*m;i++){
			c[ab[i]-1]++;
		}
		for(int i:c){
			System.out.println(i);
		}
	}
}

Measured memory_bytes: 21844
#include<cstdio>
int main(){
    int n,h[102]={};
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    int ans=0;
    bool iszero=true;
    for(int i=0;i<100;i++){
        for(int j=0;j<=n+1;j++){
            if(!iszero && h[j]==0)ans++;
            iszero=(h[j]==0);
            if(!iszero)h[j]--;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
(eval-when  (:compile-toplevel :load-toplevel :execute)
  (defun script-p ()
    (eql sb-sys:*stdin* *standard-input*)))

(macrolet ((optimize (pred)
	     (if pred
		 `(declaim (optimize (speed 3) (debug 0) (safety 0)))
		 `(declaim (optimize (speed 0) (debug 3) (safety 3))))))
  (optimize #. (script-p)))

;;; Library
(defun hashmap-to-alist (hashmap)
  (loop
     for k being the hash-keys in hashmap
     for v being the hash-values in hashmap
     collect (list k v)))

;;; Main
(defun calc-gcd (n map)
  (reduce #'*
          (mapcar (lambda (kv)
                    (destructuring-bind (prime count) kv
                      (expt prime (floor count n))))
                  (hashmap-to-alist map))))

(defun inc (n map)
  (incf (gethash n map 0))
  map)

(defun factorize (p cur map)
  (cond
    ((> (* cur cur) p)   (inc p map))
    ((zerop (rem p cur)) (factorize (floor p cur) cur (inc cur map)))
    (t                   (factorize p (1+ cur) map))))

(defun main (n p)
  (calc-gcd n (factorize p 2 (make-hash-table :test 'eq))  ))

;;; Interface
(defun repl ()
  (format t "~a~%" (main (read) (read))))

(repl)


Measured memory_bytes: 32484
#include <bits/stdc++.h>
using namespace std;
int main(){
int N;
cin >> N;

for( int i = 1; i < 10; i++ ){
for( int j = 1; j < 10; j++ ){
if( i*j == N ){
cout << "Yes" << endl;
return 0;
}
}
}
cout << "No" << endl;


}


Measured memory_bytes: 256
MOD = 10 ** 9 + 7
INF = 10 ** 12
import sys
sys.setrecursionlimit(1000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from  itertools import permutations

def main():
    n = int(input())
    a = list(map(int,input().split()))
    
    dic = {i:0 for i in range(n)}
    for num in a:
        dic[num - 1] += 1
    
    for i in dic:
        print(dic[i])
   

if __name__ =='__main__':
    main() 

Measured memory_bytes: 40332
# -*- coding: utf-8 -*-
import numpy as np
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect


def zz():
    return list(map(int, input().split()))


def z():
    return int(input())


def S():
    return input()


def C(line):
    return [input() for _ in range(line)]


def get_ashi(x, y):
    return 2*x + 4*y


N, K = zz()
p = zz()
p = sorted(p)
print(sum(p[:K]))


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

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

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


ll dp[101010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> six, nine;
    for(int i=0;pow(3,i)<=N;i++) six.push_back(pow(6,i));
    for(int i=0;pow(9,i)<=N;i++) nine.push_back(pow(9,i));

    dp[0] = 0;
    REP(i,N) dp[i+1] = INF;
    
    for(int i=1;i<=N;i++){
        for(int j=0;j<(int)nine.size();j++){
            if(i - nine[j] >= 0) chmin(dp[i], dp[i-nine[j]] + 1);
        }
        for(int j=0;j<(int)six.size();j++){
            if(i - six[j] >= 0) chmin(dp[i], dp[i-six[j]] + 1);
        }
    }
    cout << dp[N] << endl;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int N;
    cin >> N;
    int ans = 0;
    
    for(int i = 0; i < N; i++){
        string S;
        cin >> S;
        if(S == "Y"){
            ans++;
        }
    }
    
    if(ans == 0){
        cout << "Three" << endl;
    }
    else{
        cout << "Four" << endl;
    }
    
    return 0;
}


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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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; }



void func(long long A, long long B){
    cout<<A*B<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    func(A, B);
    return 0;
}


Measured memory_bytes: 3684
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main() {
    int H, N;
    cin >> H >> N;
    int sum = 0, tmp;
    for (int i = 0; i < N; i++) {
        cin >> tmp;
        sum += tmp;
    }
    if (sum >= H) {
        cout << "Yes\n";
    }
    else {
        cout << "No\n";
    }
    return 0;
}


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


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = rbegin(s); i != rend(s); ++i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.ne(); }
template<class T> constexpr T pow2(const T a) { return a * a; }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }
template<class A, int N, class T>
void fillArray(A(&array)[N], const T& val) { std::fill((T*)array, (T*)(array + N), val); }

int h, w, k;
char a[805][805];
int d[805][805];
void solve() {
    cin >> h >> w >> k;
    int sx = 0, sy = 0;
    rep(i, h) rep(j, w) {
        cin >> a[i][j];
        if (a[i][j] == 'S') {
            sx = i; sy = j;
            a[i][j] = '.';
        }
    }

    fillArray(d, iinf);
    d[sx][sy] = 0;
    queue<pair<int, int>> que;
    que.emplace(sx, sy);
    int dx[] = { 1,0,-1,0 };
    int dy[] = { 0,1,0,-1 };
    while (!que.empty()) {
        auto pos = que.front(); que.pop();
        if (pos.first == 0 || pos.first == h - 1 || pos.second == 0 || pos.second == w - 1) continue;
        rep(i, 4) {
            int nx = pos.first + dx[i];
            int ny = pos.second + dy[i];
            if (a[nx][ny] == '#') continue;
            if (d[pos.first][pos.second] + 1 < d[nx][ny]) {
                d[nx][ny] = d[pos.first][pos.second] + 1;
                que.emplace(nx, ny);
            }
        }
    }

    int ans = iinf;
    rep(i, h) rep(j, w) if (a[i][j] == '.' && d[i][j] <= k) {
        mins(ans, 1 + (min({ i, h - i - 1, j, w - j - 1 }) + k - 1) / k);
    }
    cout << ans << endn;
}

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


Measured memory_bytes: 3456
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
 
		Scanner sc = new Scanner(System.in);
 
		int N = sc.nextInt();
		int sum=0;
		int ten=N;
		
		while(ten>0) {
			sum+=ten %10;
			ten/=10;
		}
		System.out.println(N%sum==0 ? "Yes":"No");
		
	}
}

Measured memory_bytes: 21844
#include "bits/stdc++.h"
#define rep(var,cnt) for(int (var)=0; (var)<(cnt); ++(var))

using namespace std;

using int64 = int64_t;

using pi=pair<int,int>;

template <int mod>
struct ModInt {
	int x;
	ModInt() : x(0) {}
	ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
	ModInt &operator+=(const ModInt &p) {
		if((x += p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator-=(const ModInt &p) {
		if((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}
	ModInt &operator*=(const ModInt &p) {
		x = (int)(1ll * x * p.x % mod);
		return *this;
	}
	ModInt &operator/=(const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}
	ModInt operator-() const {return ModInt(-x);}
	ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
	ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
	ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
	ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
	bool operator==(const ModInt& p) const {return x == p.x; }
	bool operator!=(const ModInt& p) const {return x != p.x; }
	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while(b > 0) {
			t = a / b;
			swap(a -= t * b, b);
			swap(u -= t * v, v);
		}
		return ModInt(u);
	}
	ModInt pow(int64_t n) const {
		ModInt ret(1), mul(x);
		while(n > 0) {
		if(n & 1) ret *= mul;
		mul *= mul;
		n >>= 1;
		}
		return ret;
	}
	friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
};

const int MOD = 1e9 + 7;

int main() {
	int64 N, K; cin >> N >> K;
	int64 sum = 0;
	int64 ans = 0;
	while(true) {
		int64 res = ceil(1.0 * (N - sum) / (K + 1));
		ans++;
		sum += res;
		if(N - sum == 0) break;
	}
	
	cout << ans << endl;
}


Measured memory_bytes: 3096
n = gets.to_i
a = []
n.times do
  a << gets.to_i
end

if a[0] == 2
  puts "1"
  exit
end

dec = a[0] - 1
counter = 1
until counter > n
  dec = a[dec]
  counter += 1
  if dec == 2
    puts counter
    exit
  end
  dec -= 1
end

puts "-1"


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

int main() {
  int a, b, c, d;
  int inputNumber;
  cin >> inputNumber;

  d = inputNumber % 10;
  inputNumber /= 10;
  c = inputNumber % 10;
  inputNumber /= 10;
  b = inputNumber % 10;
  inputNumber /= 10;
  a = inputNumber;

  if (b != c) {
    cout << "No" << endl;
  } else if (a != b && c != d) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 3596
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;
using System.Runtime.InteropServices.ComTypes;
using System.Xml.Schema;
using System.ComponentModel.DataAnnotations;
using System.Security.Cryptography;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Linq.Expressions;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var (A, P) = Slice2<long>();
            WriteLine((A * 3 + P) / 2);
        }

        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
        static public (T a, T b, T c, T d) Slice4<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)),
            (T)Convert.ChangeType(t[3], typeof(T)));
        }
    }
}

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

int charToInt(char c){
    char zero_num = '0';
    return (int)c - (int)zero_num;
}

signed main(){
    int K; cin>>K;
    if(K%2==0 || K%5==0){
        cout<<"-1"<<endl;
        return 0;
    }

    int res, prev_res;
    int index=1;

    res = 7%K;
    prev_res = 7%K;
    if(res==0){
        cout<<1<<endl;
        return 0;
    }

    while(true){
        prev_res = (prev_res*10)%K;
        res = (res+ prev_res)%K;
        index++;
        // cout<<index<<" "<<prev_res<<" "<<res<<endl;
    if(res==0){
        cout<<index<<endl;
        return 0;
    }


    }




    return 0;
}

Measured memory_bytes: 3632
n, m, q = gets.split.map &:to_i

abcds = q.times.map {gets.split.map &:to_i}
max = 0
seq = [1] * n
loop do
  sum = 0
  abcds.each do |abcd|
    a, b, c, d = abcd
    if seq[b-1] - seq[a-1] == c
      sum += d
    end
  end
  max = [max, sum].max

  # next
  i = n-1
  while i >= 0
    if seq[i] == m
      i -= 1
    else
      seq[i] += 1
      (i...n).each { |j| seq[j] = seq[i] }
      break
    end
  end
  if i < 0
    break
  end
end
p max


Measured memory_bytes: 14368
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<climits>
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  int h,a; cin >> h >> a;
  if(h%a==0) cout << h / a << endl;
  else cout << h / a + 1 << endl;
  return 0;
}

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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

ll INF = 1ll << 60;

int main(){
  ll x, k, d;
  cin >> x >> k >> d;
  
  x = abs(x);
  ll a = abs(x/d);
  ll cnt;  
  
  if((k-a) % 2 == 0)
    cnt = 0;
  else
    cnt = 1;
  
  if(k-a < 0){
    cout << abs(x-(k*d)) << endl;
  }
  else{
    cout << abs(x-(a*d) - (d*cnt)) << endl;
  }
  
  return 0;
  
}

Measured memory_bytes: 3632
# https://atcoder.jp/contests/abc111/tasks/arc103_a
# C - /\/\/\/
import collections

n = int(input().split()[0])
v_list = list(map(int, input().split()))

# 奇数番目の数
odd_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 1]
# 偶数番目の数
even_list = [str(v) for i, v in enumerate(v_list) if i % 2 == 0]

# 奇数の最頻値（No1とNo2)
odd_counter = collections.Counter(odd_list)
odd_1 = odd_counter.most_common()[0][0]

if len(odd_counter) >= 2:
    odd_2 = odd_counter.most_common()[1][0]
else:
    odd_2 = '*' # dummy

# 偶数の最頻値（No1とNo2)
even_counter = collections.Counter(even_list)
even_1 = even_counter.most_common()[0][0]

if len(even_counter) >= 2:
    even_2 = even_counter.most_common()[1][0]
else:
    even_2 = '+' # dummy

# 以前の方法だと条件分岐が複雑になるので
# とりうる操作を全部試して、回数が少ない方をとる

if even_1 == odd_1:
    # 偶数側の操作回数（最頻値で置き換え）
    even_op_count = len([v for v in even_list if v != even_1])
    # 奇数の操作回数
    odd_op_count = len([v for v in odd_list if v != odd_2])
    count_1 = even_op_count + odd_op_count

    # 偶数側の操作回数
    even_op_count = len([v for v in even_list if v != even_2])
    # 奇数側の操作回数（最頻値で置き換え）
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count_2 = even_op_count + odd_op_count

    count = min(count_1, count_2)
else:
    # 偶数側も奇数側も最頻値で置き換えればよい
    even_op_count = len([v for v in even_list if v != even_1])
    odd_op_count = len([v for v in odd_list if v != odd_1])
    count = even_op_count + odd_op_count

print(count)


Measured memory_bytes: 23864
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		while(sc.hasNextInt()){
			int a=sc.nextInt();
			int b=sc.nextInt();
			System.out.println(gcd(a,b)+" "+lcm(a,b));
		}
		sc.close();
	}
	static int gcd(int a,int b){
		int c=Math.max(a, b);
		int d=Math.min(a, b);
		while(c%d!=0){
			int e=c%d;
			c=d;
			d=e;
		}
		return d;
	}
	static int lcm(int a,int b){
		int gcd=gcd(a,b);
		int resa=a/gcd;
		int resb=b/gcd;
		int lcm=resa*resb*gcd;
		return lcm;
	}
}

Measured memory_bytes: 26300