akhauriyash/Code-Regression huggingface dataset:
// ----------------------------------------------------------

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <iomanip>
#include <numeric>

using namespace std;

typedef long long LL;
typedef unsigned int UI;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)

#define MOD  			(LL)1e9 + 7;
#define INF  			(LL)1 << 62;
#define INF_I  			(int)100000009;

int main(int argc, const char * argv[]) {

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

	int dis[5], k;
	bool ret = true;

	for (int i = 0; i < 5; i++) {
		cin >> dis[i];
	}

	cin >> k;

	for (int i = 0; i < 5 - 1; i++) {
		for (int j = i + 1; j < 5; j++) {
			if (dis[j] - dis[i] > k) {
				ret = false;
			}
		}
	}

	if (ret) {
		cout << "Yay!" << endl;
	}
	else {
		cout << ":(" << endl;
	}

	return 0;

}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}
	public Main(){
		new AOJ2001().doIt();
	}

	class AOJ2001{
		ArrayList<ArrayList<Line>> list;
		int tate,yoko,a;
		
		void solve(){
			int target = a;
			for(int i=1000;i>=0;i--){
				if(list.get(i).size()==0)continue;
				for(int s=0;s<list.get(i).size();s++)if(list.get(i).get(s).contains(target)){
					target = list.get(i).get(s).move(target);
				}
			}
			System.out.println(target);
		}
		
		void doIt(){
			while(in.hasNext()){
				tate = in.nextInt();
				yoko = in.nextInt();
				a = in.nextInt();
				if(tate+yoko+a==0)break;
				list = new ArrayList<ArrayList<Line>>();
				for(int i=0;i<1001;i++)list.add(new ArrayList<Line>());
				for(int i=0;i<yoko;i++){
					int h = in.nextInt();
					int a = in.nextInt();
					int b = in.nextInt();
					list.get(h).add(new Line(a, b, h));
				}
				solve();
			}
		}
		class Line{
			int a,b,h;
			public Line(int a,int b,int h){
				this.a = a;
				this.b = b;
				this.h = h;
			}
			
			boolean contains(int c){
				if(a==c||b==c)return true;
				else return false;
			}
			
			int move(int c){
				if(a==c)return b;
				else if(b==c)return a;
				else return -1;
			}
			
		}
	}

}

Measured memory_bytes: 62972
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

char a[21][21];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int count;

int W, H;

void dfs(int x, int y)
{
    a[x][y] = 0;
    for (int i = 0; i < 4; i++)
    {
        int nx = x + dx[i];
        int ny = y + dy[i];
        if (0 <= nx && nx < H && 0 <= ny && ny < W && a[nx][ny] == '.')
        {
            count++;
            dfs(nx, ny);
        }
    }
}

int main()
{
    while (cin >> W >> H, W && H)
    {
        count = 1;
        for (int i = 0; i < H; i++)
        {
            cin >> a[i];
        }
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                if (a[i][j] == '@')
                {
                    dfs(i, j);
                    break;
                }
            }
        }
        cout << count << endl;
    }
}


Measured memory_bytes: 3088
import qualified Data.ByteString.Char8 as C
import Data.Maybe 
  ( fromJust )

main = do
  _  <- getLine
  as <- map (fst . fromJust . C.readInt) . C.words <$> C.getLine 
  print $ f as

f :: [Int] -> Int
f (a:b:bs) 
  | a < b     = g (a,b) bs
  | otherwise = g (b,a) bs
 
g :: (Int,Int) -> [Int] -> Int
g (s,l) [] = l-s
g sl@(s,l) (x:xs)
  | x < s = g (x,l) xs
  | l < x = g (s,x) xs
  | otherwise = g sl xs

Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define int long long
main()
{
    int n,ans=0;
    cin>>n;
    vector<int>a[26];
    string s;
    cin>>s;
    for(int i=n-1; i>=0; i--)
    {
        a[s[i]-'A'].push_back(i);
        //cout<<(s[i]-'A')<<" "<<i<<endl;
    }
    for(int i=n-1; i>=0; i--)
    {
        if(s[i]=='R')
        {
            if(a[22].size())
            {
                int c=a[22].back();
               // cout<<c<<endl;
                if(i>c){
                    swap(s[i],s[c]);
                    a[22].pop_back();
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 5768
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n,k,a;
    cin>>n>>k;
    std::deque<int> deq;
    for (int i=0;i<n;i++) {
        cin>>a;
        deq.emplace_back(a);
    }
    sort(deq.begin(),deq.end(),greater<int>());
    int sum=0;
    for (int j=0;j<k;j++) {
        sum+=deq[j];
    }
    cout<<sum<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}



int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  int n;
  cin >> n;
  if(n>=30){
	  cout << "Yes" << endl;
  }else{
	  cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

#define S(i,j) swap(s[i - 1],s[j - 1])



void f1(vector<int>& s){
  S(7,22);
  S(8,23);
  S(9,24);
  S(18,13);
  S(10,12);
}

void f2(vector<int>& s){
  S(1,28);
  S(2,29);
  S(3,30);
  S(15,16);
  S(19,21);
}

void f3(vector<int>& s){
  S(1,24);
  S(4,27);
  S(7,30);
  S(16,18);
  S(21,10);
}

void f4(vector<int>& s){
  S(3,22);
  S(6,25);
  S(9,28);
  S(19,12);
  S(15,13);
}

struct EEE{
  vector<int> first;
  int second;
};

int solve(vector<int> state){
  queue<EEE> que;
  que.push({state,0});

  while(!que.empty()){
    auto p = que.front();
    vector<int> s = p.first;
    int c = p.second;
    que.pop();

    bool OK = true;
    rep(i,0,8) OK &= (s[0] == s[i]);
    rep(i,9,11) OK &= (s[9] == s[i]);
    rep(i,12,14) OK &= (s[12] == s[i]);
    if(OK) return c;
    {
      vector<int> temp;
      copy(s.begin(), s.end(),back_inserter(temp));
      f1(temp);
      que.push({temp, c + 1});
    }
    {
      vector<int> temp;
      copy(s.begin(), s.end(),back_inserter(temp));
      f2(temp);
      que.push({temp, c + 1});
    }
    {
      vector<int> temp;
      copy(s.begin(), s.end(),back_inserter(temp));
      f3(temp);
      que.push({temp, c + 1});
    }
    {
      vector<int> temp;
      copy(s.begin(), s.end(),back_inserter(temp));
      f4(temp);
      que.push({temp, c + 1});
    }
  }
}

int main(){
  int N;
  cin >> N;
  rep(q,0,N - 1){
    vector<int> p(30);
    for(int i = 0;i < 30;i++) cin >> p[i];
    cout << solve(p) << endl;
  }
}



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

int main(){
  int n;
  cin >> n;
  int ans = 0;
  vector<int> w(n);
  for(int i=0;i<n;i++){
    cin >> w.at(i);
    ans += w.at(i);
  }
  int balance = 0;
  int min1 = 5050;
  for(int i:w){
    balance += i;
    min1 = min(abs(ans-2*balance),min1);
  }
  cout << min1 << endl;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    ll n, m;
    cin >> n >> m;
    cout << (n - 1) * (m - 1) << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <vector>
using namespace std;

int main()
{
    int n,d;
    cin >> n >> d;
    vector<vector<double>> x(n,vector<double>(d));
    int i,j,k;
    for(i = 0;i < n;++i){
        for(j = 0;j < d;++j){
            cin >> x.at(i).at(j);
        }
    }
    double distance;
    double distance_temp;
    int num = 0;
    for(i = 0;i < n-1;++i){
        for(j = i+1;j < n;++j){
            distance = 0;
            for(k = 0;k < d;++k){
                distance += (x.at(i).at(k)-x.at(j).at(k))*(x.at(i).at(k)-x.at(j).at(k));
            }
            distance = sqrt(distance);
            distance_temp = (double)(int)distance;
            if(distance == distance_temp){
                ++num;
            }
        }
    }
    cout << num << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}
template<typename T>
bool all_same(vector<T> v1,vector<T> v2)
{
    sort(ALL(v1));
    sort(ALL(v2),greater<T>());
    return v1 == v2;
}
   
// g++ -std=c++11 prac.cpp
ll Max=-1e9,Min=1e9+1;

int main(){
    ll a,b,n,m,l,w,sum=0,sum2=0,ans=0;
    string s,t;
    bool f=false;
    cin >> s >> t;
    for(int i=s.size()-t.size();i>=0;i--){
        bool ok=true;
        rep(j,t.size()){
            if(s[i+j]!=t[j] && s[i+j]!='?'){
                ok = false;
                break;
            }
        }
        if(ok){
            rep(k,t.size()){
                s[i+k] = t[k];
            }
            rep(j,s.size()){
                if(s[j]=='?') 
                    s[j]='a';
            }
            cout << s << endl;
            return 0;
        }
    }    

    cout << "UNRESTORABLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <cstdio>
#include <new>
#include <vector>
#include <cstdlib>
#include <string>
#include <set>
#include <tuple>
#include<map>

using namespace std;
int main() {
	int A, B;

	cin >> A >> B;

	int ans = A + B;

	if (ans >= 24) cout << ans - 24 << endl;
	else cout << ans << endl;

}

Measured memory_bytes: 3600
<?php
fscanf(STDIN, "%d %d", $x, $y);

$d = ($x >= $y) ? gcd($x, $y) : gcd($y, $x);
echo "$d\n";

function gcd($x, $y)
{
    if (0 == $y || 0 == $x % $y) {
        return $y;
    }

    return gcd($y, $x%$y);
}

Measured memory_bytes: 6580
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main() {
  int n;
  cin >> n;
//   長さが自由に買われる配列
  vector<string> s(10);
  s[0] = "pon";
  s[1] = "pon";
  s[2] = "hon";
  s[3] = "bon";
  s[4] = "hon";
  s[5] = "hon";
  s[6] = "pon";
  s[7] = "hon";
  s[8] = "pon";
  s[9] = "hon";
//   [n%10] の値を出力結果
  cout << s[n%10] << endl;
  return 0;
}

Measured memory_bytes: 3596
#include<stdio.h>
#include<algorithm>
#include<vector>
using namespace std;
int n, m, Q, w[101000], pv[101000], CC, ord[101000], R[101000];
struct point{
    int t, num;
    bool operator<(const point &p)const{
        return t<p.t;
    }
}P[101000];
int main(){
    int i, pp = -1;
    scanf("%d%d%d",&n,&m,&Q);
    for(i=1;i<=m;i++)P[i].num=i,P[i].t=i;
    for(i=1;i<=Q;i++){
        scanf("%d",&w[i]);
        P[w[i]].t=-i;
    }
    sort(P+1,P+m+1);
    for(i=1;i<=m;i++)ord[P[i].num] = i;
    for(i=m;i>=2;i--){
        if(P[i].num < P[i-1].num)break;
    }
    pp = i;
    R[0] = n;
    for(i=Q;i>=1;i--){
        int t = ord[w[i]];
        if(R[t] < R[t-1])R[t]++;
    }
    for(i=1;i<pp;i++){
        if(R[i] < n){
            printf("No\n");
            return 0;
        }
    }
    printf("Yes\n");
}

Measured memory_bytes: 2176
#include<iostream> 
using namespace std;
int n,m=0,a[40],b[40],c[41]; 
void solve(int l,int r){ if(l>r)return; 
int x=a[m++]; 
solve(l,c[x]-1); solve(c[x]+1,r); 
cout<<x<<(x==a[0]?"\n":" "); 
} 
int main(){ cin>>n; 
for(int i=0;i<n;i++)cin>>a[i]; 
for(int i=0;i<n;i++)cin>>b[i],c[b[i]]=i; 
solve(0,n-1);
 
return 0; 
} 


Measured memory_bytes: 3112
#include<bits/stdc++.h>
#include<string.h>
#define ll long long int
#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define MAX_LIMIT 100000
#define mp make_pair
#define pb push_back
#define bb back
#define e endl
using namespace std;
int main(){
    ll a;
    string s;
    cin>>a>>s;
    if(a<3200){
        cout<<"red"<<endl;
    }
    else{
        cout<<s<<endl;
    }
    
    
    
    return 0;
}


Measured memory_bytes: 256
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin >> s;
    ll sum = 0;
    for (int i=0;i<s.length();i++){
        int temp = s[i] - 48;
        sum += temp;
    }
    if (sum%9==0){
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 3776
import java.util.*;
 
class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
      	int b = sc.nextInt();
      	int c = sc.nextInt();
      	int sam = a+b+c;
      	int kake = a*b*c;
      	
     
		if(sam==17&&kake==175){
		System.out.print("YES");
        }else{
          System.out.print("NO");
        }
      
    }
}

Measured memory_bytes: 20692
# include <bits/stdc++.h>
using namespace std;
long long t, a, cnt, bnt;
vector <int> vc;
int main(){
	cin >> t;
	for (int i = 0; i < t; i ++){
		cin >> a;
		vc.push_back(a);
	}
	for (int i = 1; i < t; i ++){
		if (vc[i] < vc[i -1]){
            cnt = vc[i - 1] - vc[i];
            vc[i] += cnt;
            bnt += cnt;
		}
	}
	cout << bnt;
}


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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

int main()
{
    lli num;
    long double sum=0;
    vector<long double> vect(100010);

    cin >> num;

    for(lli i=0; i<num; i++){
        cin >> vect.at(i);
    }
    for(lli i=0; i<num; i++){
        sum += (long double)1/vect[i];
    }
    cout << (long double)(1/sum) << endl;
    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("O3")
#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits.h>
#include <map>
#include <math.h>
#include <queue>
#include <deque>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <chrono>
#include <random>
#include <time.h>
#include <fstream>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue<int>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define eb emplace_back
#define ep emplace
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2 vector<vec>
#define vecll2 vector<vecll>
#define vec3 vector<vec2d>
#define vecll3 vector<vecll2d>
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int in() {int x;scanf("%d",&x);return x;}
ll lin() {ll x;scanf("%lld",&x);return x;}
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;}
template<class T> inline void print(vector<T> v){for(T e:v)cout<<e<<" ";cout<<endl;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
void print(vector<vec> v){for(auto e:v){for(auto ee:e)cout<<ee<<" ";cout<<endl;}}
void print(map<int,int> mp){for(auto e:mp)cout<<e.first<<" "<<e.second<<endl;cout<<endl;}
const ll INF=1e17;
ll dp[400][400][400];
main(){
    int n=in();
    int t=in();
    vecpii v;
    rep(i,n){
        int a=in(),b=in();
        v.eb(a,b);
    }
    sort(all(v));
    vec dp(t+1);
    rep(i,n){
        rep3(j,t-1,0){
            chmax(dp[min(t,v[i].first+(int)j)],dp[j]+v[i].second);
        }
        // print(dp);
    }
    cout<<dp[t];
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

bool dp_x[8010][2 * 8010], dp_y[8010][2 * 8010];

int main() {
  string s;
  cin >> s;
  ll x, y;
  cin >> x >> y;

  ll n = s.size();
  ll start = n;
  REP(i, n) {
    if (s[i] == 'T') {
      start = i + 1;
      break;
    }
    --x;
  }

  dp_x[0][8000] = dp_y[0][8000] = true;
  ll sum = 0, cnt = 1;
  vector<ll> xs, ys;
  FOR(i, start, n) {
    if (s[i] == 'T') {
      if (cnt % 2 == 0) {
        xs.push_back(sum);
      } else {
        ys.push_back(sum);
      }
      sum = 0;
      ++cnt;
      continue;
    }
    ++sum;
  }
  if (sum != 0) {
    if (cnt % 2 == 0) {
      xs.push_back(sum);
    } else {
      ys.push_back(sum);
    }
  }

  REP(i, xs.size()) {
    REP(j, 2 * 8010) {
      if (j + xs[i] < 2 * 8010) dp_x[i + 1][j + xs[i]] |= dp_x[i][j];
      if (0 <= j - xs[i]) dp_x[i + 1][j - xs[i]] |= dp_x[i][j];
    }
  }
  REP(i, ys.size()) {
    REP(j, 2 * 8010) {
      if (j + ys[i] < 2 * 8010) dp_y[i + 1][j + ys[i]] |= dp_y[i][j];
      if (0 <= j - ys[i]) dp_y[i + 1][j - ys[i]] |= dp_y[i][j];
    }
  }

  if (dp_x[xs.size()][x + 8000] && dp_y[ys.size()][y + 8000]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 127360
#include <iostream>

using namespace std;

int main() {
    long long n, a, b;
    cin >> n >> a >> b;

    long long x_prev;
    cin >> x_prev;

    long long res = 0;
    for (int i = 1; i < n; i++) {
        long long x;
        cin >> x;

        if (a * (x - x_prev) < b) {
            res += a * (x - x_prev);
        } else {
            res += b;
        }

        x_prev = x;
    }

    cout << res << endl;
}


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

int x[10], y[10];

double dist(int i, int j){
  double x_d = x[i] - x[j];
  double y_d = y[i] - y[j];
  return pow(x_d * x_d + y_d * y_d, 0.5);
}

int main() {
    int N;
    cin >> N;
    rep(i, N){
      cin >> x[i] >> y[i];
    }
    double ans = 0;
    rep(i, N - 1){
      for(int j = i + 1; j < N; ++j){
        ans += dist(i, j) * 2 / N;
      }
    }
    cout << fixed << setprecision(15) << ans << endl;
}


Measured memory_bytes: 384
hoge=[0,0,0,0,0,0,0,0,0]
for i in range(3):
  a,b,c=map(int,input().split())
  hoge[i*3],hoge[i*3+1],hoge[i*3+2]=a,b,c
huga=[0,0,0,0,0,0,0,0,0]


n=int(input())
for i in range(n):
  a=int(input())
  for j in range(9):
    if(hoge[j]==a):
      huga[j]+=1

hoge=huga
if(hoge[0]+hoge[1]+hoge[2]==3):
  print("Yes")
elif(hoge[3]+hoge[4]+hoge[5]==3):
  print("Yes")
elif(hoge[6]+hoge[7]+hoge[8]==3):
  print("Yes")
elif(hoge[0]+hoge[3]+hoge[6]==3):
  print("Yes")
elif(hoge[1]+hoge[4]+hoge[7]==3):
  print("Yes")
elif(hoge[2]+hoge[5]+hoge[8]==3):
  print("Yes")
elif(hoge[0]+hoge[4]+hoge[8]==3):
  print("Yes")
elif(hoge[2]+hoge[4]+hoge[6]==3):
  print("Yes")
else:
  print("No")
  

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

long long int sum,k,n,num[200000],to;

int main(){

    while(1){

    long long int ans=-1000000000;
    cin >> n >> k;
    if(n==0&&k==0)break;

    for(int i=0;i<n;i++){
        cin  >> num[i];
    }

    for(int i=0;i<k;i++){
        sum+=num[i];
    }

    for(int i=k;i<n;i++){
        if(ans<sum)ans=sum;
        sum-=num[to++];
        sum+=num[i];
    }

    cout << ans << endl;

    sum=0;
    ans=0;
    to=0;

    }


return 0;
}

Measured memory_bytes: 1940
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
//const ll MOD = 1e9 + 7;
const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

vl inv(2e5+1);

vl get_inv(ll n){
  inv[1] = 1;
  for(ll i=2; i<=n; i++) inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
  return inv;
}

ll modpow(ll m, ll n) {
  if(n==0) return 1;
  else if(n%2==0) return modpow(m, n/2)*modpow(m, n/2)%MOD;
  else return m*modpow(m, n-1)%MOD;
}

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

  ll n, m, k;
  cin >> n >> m >> k;
  m--;
  
  if(m==0){
    if(k==n-1) cout << 1 << newl;
    else cout << 0 << newl;
    return 0;
  }
  
  get_inv(2e5);

  ll bc = 1;
  ll mpow = (m+1)*modpow(m, n-1)%MOD;
  
  ll ans = mpow;
  rep2(i, k) {
    (bc *= n-i) %= MOD;
    (bc *= inv[i]) %= MOD;
    (mpow *= inv[m]) %= MOD;
    (ans += bc*mpow) %= MOD;
  }
  cout << ans << newl;
  
  return 0;
}

Measured memory_bytes: 6312
// C - Neither AB nor BA
#include <bits/stdc++.h>

using namespace std;

#define	MOD	998244353

vector<long long> fact, finv;

void init_fact(int n = 1000000)
{
	fact.resize(n); finv.resize(n);
	fact[0] = finv[n - 1] = 1;
	for (int i = 1; i < n; i++) fact[i] = fact[i - 1] * i % MOD;
	for (long long x = MOD - 2, a = fact[n - 1]; x > 0; a = a * a % MOD, x >>= 1)
		if (x & 1) finv[n - 1] = finv[n - 1] * a % MOD;
	for (int i = n - 2; i >= 0; i--) finv[i] = finv[i + 1] * (i + 1) % MOD;
}

long long cnr(int n, int r)
{
	if (r < 0 || r > n) return 0;
	if (r == 0 || r == n) return 1;
	return fact[n] * finv[r] % MOD * finv[n - r] % MOD;
}

int main(int argc, char *argv[])
{
	long long n;
	cin >> n;

	init_fact(n + 1);

	long long ans = 1;
	for (long long m = n, x = 3; m > 0; x = x * x % MOD, m >>= 1) if (m & 1) ans = ans * x % MOD;

	vector<long long> p2(n + 1, 1);
	for (int i = 0; i < n; i++) p2[i + 1] = (p2[i] * 2) % MOD;
	for (long long i = n / 2 + 1; i <= n; i++)
		ans = (ans - cnr(n, i) * p2[n - i] * 2 % MOD + MOD) % MOD;

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 234624
#include<stdio.h>

int main(void){
  int n,max,ans=0;
  scanf("%d",&n);
  int h[n],i;
  for(i=0;i<n;i++) scanf("%d",&h[i]);
  max=h[0];
  for(i=0;i<n;i++){
    if(max<=h[i]){
      ans++;
      max=h[i];
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;

int main(){
  int n;
  int a,b,c,ans=0,j;
  cin >> a >> b;
  for(int i=a;i<=b;i++){
    if(i/10000==i%10){
      j=i-i/10000*10000;
      if(j/1000==((j%100)-j%10)/10)ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

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

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

    int sub[n] = {0};
    // AC = 1, WA = 2
    int ac = 0, wa = 0;

    while (m--) {
        int p;
        string s;
        cin >> p >> s;

        if (sub[p-1]==0) {
            if (s=="AC") {
                sub[p-1] = -1;
                ac++;
            }
            else {
                sub[p-1] = 1;
            }
        }
        else if (sub[p-1]!=-1) {
            if (s=="WA")
                sub[p-1]++;
            else {
                wa += sub[p-1];
                sub[p-1] = -1;
                ac++;
            }
        }
    // cout << "AC:" << ac << " WA:" << wa << "\n";
    }

    cout << ac << " " << wa << "\n";

    return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int n,m,p,q,r;
struct cards
{
	int from,to;
	cards(int f,int t)
	{
		from=f,to=t;
	}
};
deque<cards> all;
deque<cards> split(int k)
{
	deque<cards> sub;
	for(;;)
	{
		cards t=all.front();
		all.pop_front();
		k -= t.to-t.from+1;
		if(k==0)
		{
			sub.pb(t);
			break;
		}
		if(k<0)
		{
			all.push_front(cards(t.to+k+1,t.to));
			t.to+=k;
			sub.pb(t);
			break;
		}
		sub.pb(t);
	}
	return sub;
}
void shuffle(int x,int y)
{
	deque<cards> a=split(x);
	deque<cards> b=split(y-x);
	for(int i=0;i<b.size();i++)all.pb(b[i]);
	for(int i=0;i<a.size();i++)all.pb(a[i]);
}
int main()
{
	while(1)
	{
		cin >> n;
		if(n==0)break;
		all.clear();
		all.pb(cards(1,n));
		cin >> m;
		cin >> p >> q >> r;
		for(int i=0;i<m;i++)
		{
			int x,y;
			cin >> x >> y;
			shuffle(x,y);
		}
		int ans=0;
		split(p-1);
		deque<cards> res=split(q-p+1);
		for(int i=0;i<res.size();i++)
		{
			if(res[i].from<=r)
			{
				if(res[i].to>=r)
				{
					ans+=r-res[i].from+1;
				}
				else
				{
					ans+=res[i].to-res[i].from+1;
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1332
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

struct Point
{
    int index;
    int x, y;

    int ConnectionCost(const Point &other) const
    {
        return min(abs(x - other.x), abs(y - other.y));
    }
};

struct CmpX
{
    bool operator()(const Point &a, const Point &b) const
    {
        if (a.x == b.x) {
            return a.y < b.y;
        }
        return a.x < b.x;
    }
};

struct CmpY
{
    bool operator()(const Point &a, const Point &b) const
    {
        if (a.y == b.y) {
            return a.x < b.x;
        }
        return a.y < b.y;
    }
};

struct Edge
{
    int index1;
    int index2;
    int cost;

    Edge(const Point &a, const Point &b)
        : index1(a.index), index2(b.index), cost(a.ConnectionCost(b)) {}

    bool operator<(const Edge &other) const { return cost < other.cost; }
};

class DisjointSet
{
public:
    DisjointSet(int size) : fathers_(size, -1) {}

    void Unite(int a, int b);

    bool SameGroup(int a, int b) { return Root(a) == Root(b); }

private:
    int Root(int node);

    vector<int> fathers_;
};

void DisjointSet::Unite(int a, int b)
{
    auto root_a = Root(a);
    auto root_b = Root(b);

    if (root_a != root_b) {
        fathers_[root_b] = root_a;
    }
}

int DisjointSet::Root(int node)
{
    if (fathers_[node] == -1) {
        return node;
    }
    return fathers_[node] = Root(fathers_[node]);
}

vector<Edge> BuildEdges(vector<Point> &points)
{
    vector<Edge> edges;

    sort(points.begin(), points.end(), CmpX());
    for (size_t i = 0; i + 1 < points.size(); i += 1) {
        edges.push_back(Edge(points[i], points[i + 1]));
    }

    sort(points.begin(), points.end(), CmpY());
    for (size_t i = 0; i + 1 < points.size(); i += 1) {
        edges.push_back(Edge(points[i], points[i + 1]));
    }

    return edges;
}

int64_t FindCost(vector<Edge> &edges, int n)
{
    DisjointSet set(n);
    int64_t cost = 0;

    sort(edges.begin(), edges.end());
    for (const auto &e : edges) {
        if (!set.SameGroup(e.index1, e.index2)) {
            cost += e.cost;
            set.Unite(e.index1, e.index2);
        }
    }
    return cost;
}

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

    vector<Point> points(n);
    for (auto i = 0; i < n; i += 1) {
        points[i].index = i;
        cin >> points[i].x;
        cin >> points[i].y;
    }

    auto edges = BuildEdges(points);
    auto cost = FindCost(edges, n);

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


Measured memory_bytes: 6132
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()    // 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend() // 降順ソート 例：sort(DESC(vec));
#define rep(i, n) for (int i = 0; i < (n); i++)
#define Rep(i, n) for (int i = 1; i < n; i++)
#define REP(i, vec) for (auto i = vec.begin(); i != vec.end(); ++i)

const int       mod = 1000000007;
const int       inf = (1 << 21);
const long long INF = 1LL << 60;

using ii = pair<int, int>;
using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;
using vvb = vector<vector<bool>>;
using vii = vector<pair<int, int>>;
using vll = vector<pair<ll, ll>>;

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

constexpr array<int, 9> dx = { 0, 1, 0, -1, -1, 1, 1, -1, 0 };
constexpr array<int, 9> dy = { 1, 0, -1, 0, 1, 1, -1, -1, 0 };

// ──────────────────────────────────────────────────────────────────

int main() {
	ll n;
	cin >> n;
	vl a(n);
	rep(i, n) cin >> a[i];
	
	ll sum = 0;
	ll right = 0, ans = 0;
	rep(left, n) {
		while (right < n && (sum ^ a[right]) == (sum + a[right])) {
			sum += a[right];
			right++;
		}

		ans += right - left;

		if (right == left) right++;
		else sum -= a[left];
	}
	cout << ans << endl;
}

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

int main()
{
	int n;
	string s1, s2;
	int a = 0, b = 0;
	cin >> n;

	for (int i = 0; i < n; i++){
		cin >> s1 >> s2;

		if (s1 > s2) a += 3;
		else if (s1 < s2) b += 3;
		else{
			a++;
			b++;
		}
	}

	cout << a << " " << b << endl;

	return 0;
}

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

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

using namespace std;

int main() {
  int N, K; cin >> N >> K;
  map<int, int> mp;
  rep(i, N) {
    int a; cin >> a;
    mp[a]++;
  }
  vector<int> a;
  for (auto e: mp) {
    a.push_back(e.second);
  }
  sort(a.begin(), a.end());
  int U = a.size();
  U -= K;
  if (U <= 0) {
    cout << 0 << "\n";
  } else {
    int ans = 0;
    for (auto e: a) {
      U--;
      ans += e;
      if (U == 0) { break; }
    }
    cout << ans << endl;
  }
}


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

int main() {
    int x, y; cin >> x >> y;
    int g[] = {0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1};
    cout << (g[x] == g[y] ? "Yes" : "No") << endl ;
}


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

using namespace std;

const int MOD = 1000000007;
typedef long long ll;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin>>N;
  vector<ll> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }

  sort(A.begin(),A.end());

  int ok=N,ng=-1;
  while(ok-ng>1){
    int mid=(ok+ng)/2;
    ll size=A[mid];
    bool flag=true;
    for(int i=0;i<N;i++){
      if(i==mid)continue;
      if(A[i]<=2*size){
        size+=A[i];
      }else{
        flag=false;
        break;
      }
    }
    if(flag){
      ok=mid;
    }else{
      ng=mid;
    }
  }
  cout<<N-ok<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
main()
{
	int a,b,c[110],d=1,f;
	cin>>a>>b;
	for(;d<=a;d++) cin>>c[d];
	for(int e=1;e<=a;e++) b=b-c[e];
	sort(c+1,c+a+1);
	f=b/c[1];
	f=f+a;
	cout<<f;
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <bitset>
using namespace std;
#define ll long long
#define mod 1000000009

// يلعن ابو الي يعقدها على نفسه تاني

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

    ll n; cin >> n;
    ll arr[100005];
    for(ll i=0; i<n; i++){
        cin >> arr[i];
    }
    if(n == 2){
        cout << abs(arr[1]-arr[0]);
    }else{
        ll sol[100005] = {};
        sol[1] = abs(arr[1]-arr[0]);
        for(ll i=2; i<n; i++) {
            sol[i] = min(sol[i-1]+abs(arr[i]-arr[i-1]),sol[i-2]+abs(arr[i]-arr[i-2]));
        }




        cout << sol[n-1];
    }







    return 0;
}

Measured memory_bytes: 1792
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
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 Q; cin >> Q;
    while(Q--) {
        string S; cin >> S;
        int N = S.size();
        set<string> dic;
        for (int i = 1; i < N;i++) {
            string s = S.substr(0,i);
            string t = S.substr(i,N-i);
            dic.emplace(s+t);
            dic.emplace(t+s);
            reverse(all(s));
            dic.emplace(s+t);
            dic.emplace(t+s);
            reverse(all(t));
            dic.emplace(s+t);
            dic.emplace(t+s);
            reverse(all(s));
            dic.emplace(s+t);
            dic.emplace(t+s);
        }
        cout << dic.size() << endl;
    }
 
}


Measured memory_bytes: 3204
#include <stdio.h>
#include <stdlib.h>
int main(){
  int N,i,j,n,*A,count=0;
  scanf("%d",&N);
  A=(int*)malloc(sizeof(int)*N);
  for(i=0;i<N;i++)
      scanf("%d",&A[i]);
  for(i=0;i<N;i++)
    for(j=N-1;j>0;j--){
      if(A[j]<A[j-1]){
	count++;
	n=A[j];
	A[j]=A[j-1];
	A[j-1]=n;
      }
    }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i<N-1)
      printf(" ");
  }
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 200005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
 	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
int N;
int64 a[55],ans;
void Solve() {
    read(N);
    for(int i = 1 ; i <= N ; ++i) read(a[i]);
    while(1) {
	int t = 1;
	for(int i = 2 ; i <= N ; ++i) {
	    if(a[i] > a[t]) t = i;
	}
	if(a[t] < N) break;
	int64 k = (a[t] - (N - 1) - 1) / N + 1;
	a[t] -= k * N;
	ans += k;
	for(int i = 1 ; i <= N ; ++i) {
	    if(i != t) a[i] += k;
	}
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>

using namespace std;

int main()
{
    long long a,b,c;
    scanf("%lld%lld%lld",&a,&b,&c);
    if (a<0) a = -a;
    long long tmp = a/c;
    if (b<tmp) tmp=b;

    a -= tmp*c;
    b -= tmp;
    if (b%2)
        a -= c;
    if (a < 0) a=-a;

    printf("%lld\n",a);
    return 0;
}

Measured memory_bytes: 1736
n = gets.to_i
(1..n).each do |i|
  x = i
  if x % 3 == 0
    print " #{i}" 
    next
  end
  begin
    if x % 10 == 3
      print " #{i}"
      break
    end
    x /= 10
  end while x != 0
end
puts

Measured memory_bytes: 8764
/*
 *  AUTHOR : MANAV PATEl
*/
#include<bits/stdc++.h>
#include<functional>
//#include<boost/multiprecision/cpp_int.hpp>
//using namespace boost::multiprecision;
using namespace std;

namespace fastio {

	template <class T> istream &operator>>(istream &os, vector<T> & vec) {
		for (auto &u : vec)os >> u;
		return os;
	}
	template <class T> ostream &operator<<(ostream &os, const vector<T> & vec) {
		for (auto &u : vec)os << u << " ";
		return os;
	}
	template<class T1, class T2> inline istream& operator>>(istream& os, pair<T1, T2>& p) {
		return os >> p.first >> p.second;
	}
	template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
		return os << p.first << " " << p.second;
	}
	template <class T> ostream &operator<<(ostream &os, set<T> & con) {
		for (auto &u : con) os << u << " ";
		return os;
	}
	void re() {}
	template <typename T, typename... args> void re(T& x, args&... tail) {
		cin >> x;
		re(tail...);
	}
	void pr() {}
	template <typename T> void pr(const T& x) {
		cout << x;
	}
	template <typename T, typename... args> void pr(const T& x, const args&... tail) {
		cout << x << " ";
		pr(tail...);
	}
	template <typename... args> void prln(const args&... tail) {
		pr(tail...);
		cout << "\n";
	}
}
using namespace fastio;

typedef long long int ll;
typedef long double ld;

const ll mod = 1e9+7;
const ll mod1 = 998244353;

#define fill(a)  memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back

int main()
{
	cin.sync_with_stdio(false);
	cin.exceptions(cin.failbit);
	cin.tie(0);
		ll a;
  re(a);
  cout << 3*a*a<<"\n";
}



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

using namespace std;

#define debug(n) cerr << #n << ':' << n << endl;
#define dline    cerr << __LINE__ << endl;
#define rep(i,s,e) for(int i = (s); i < (e); ++i)
#define per(i,s,e) for(int i = (s)-1; i >= e; --i)

using ll = long long;
template<class T, class U> using P = pair<T,U>;
template<class T> using Heap = priority_queue<T>;
template<class T> using heaP = priority_queue<T,vector<T>,greater<T>>;

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

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

template<typename T, size_t N, typename U>
void Fill(T (&a)[N], const U&v){
    std::fill((U*)a,(U*)(a+N),v);
}

int main(){
  int size; cin>> size;
  string s; cin >> s;
  int ans = 1;
  rep(i,1,size){
    if(s[i] != s[i-1])ans ++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    int n; cin >> n;
    map<int,int> A;
    for(int i = 1; i <= n; i++){
        int a; cin >> a;
        A[a] = i;
    }

    for(auto p : A){
        cout << p.second << " ";
    }
}



Measured memory_bytes: 5504
//
// Created by Sotetsu KOYAMADA on 2020/03/02.
//

#include <iostream>

int solve(int n, int t)
{
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j)
            for (int k = j + 1; k <= n; ++k)
                if (i + j + k == t) ++ans;
    return ans;
}

int main()
{
    int n, x;
    while (true) {
        std::cin >> n >> x;
        if (n == 0 && x == 0) break;
        std::cout << solve(n, x) << std::endl;
    }
    return 0;
}


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

int main() {
    string S;
	cin >> S;
	int color_exchanged = 0;
	int odd_color_white = 0;
	int odd_color_brack = 0;
	for (int i = 0; i < S.size() / 2 + S.size() % 2; i++) {
		if (S.at(2 * i) == '1') {
			odd_color_white++;
		}
		else {
			odd_color_brack++;
		}
	}
	int even_color_white = 0;
	int even_color_brack = 0;
	for (int i = 0; i < S.size() / 2; i++) {
		if (S.at(2 * i + 1) == '1') {
			even_color_white++;
		}
		else {
			even_color_brack++;
		}
	}
	cout << min(odd_color_white + even_color_brack, odd_color_brack + even_color_white) << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("Ofast,fast-math,unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define fi first
#define se second
#define sqrt(x) sqrt(abs(x))
#define sqr(x) ((x) * (x))
#define unq(x) (x.resize(unique(all(x)) - x.begin()))
#define fill(x, y) memset(x, y, sizeof(x))
#define mp make_pair
#define pb emplace_back
#define popcnt __builtin_popcount
#define ctz __builtin_ctz

using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;

template <class T> using indexed_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T>
istream& operator >> (istream &in, vector <T> &a) {
    for (T &i: a) in >> i;
    return in;
}

template <class T>
ostream& operator << (ostream &out, vector <T> &a) {
    for (T &i: a) out << i << ' ';
    out << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream &out, set <T> &a) {
    for (auto &i: a) out << i << ' ';
    out << '\n';
    return out;
}

template <class T, class U>
istream& operator >> (istream &in, pair <T, U> &p) {
    in >> p.first >> p.second;
    return in;
}

template <class T, class U>
ostream& operator << (ostream &out, pair <T, U> &p) {
    out << p.first << ' ' << p.second << '\n';
    return out;
}

void fastIO() {
    ios_base:: sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
}

void solve();

int n, x, y;
vector <int> bober;
vector <vector <int>> g;

void bfs(int x) {
    vector <int> d(n, 100000);
    vector <bool> used(n);
    queue <int> q;

    q.push(x);
    used[x] = true;
    d[x] = 0;

    while (!q.empty()) {
        int cur = q.front();
        q.pop();

        for (auto i: g[cur]) {
            if (!used[i]) {
                used[i] = true;
                q.push(i);
                d[i] = d[cur] + 1;
            }
        }
    }

    for (auto i: d) {
        if (i != 0) bober[i]++;
    }
}

signed main() {
    fastIO();

    cin >> n >> x >> y;
    g.resize(n);
    for (int i = 0; i < n - 1; ++i) g[i].pb(i + 1);
    for (int i = 1; i < n; ++i) g[i].pb(i - 1);

    --x, --y;
    g[x].pb(y);
    g[y].pb(x);
    bober.resize(n);

    for (int i = 0; i < n; ++i) bfs(i);

    for (int i = 1; i <= n - 1; ++i) cout << bober[i] / 2 << '\n';

    return 0;
}

/// ЗАПУСКАЕМ ГУСЯ:
/*
     ▄▀▀▀▄
▄███▀░◐░░░▌
    ▌░░░░░▐
    ▐░░░░░▐
    ▌░░░░░▐▄▄
    ▌░░░░▄▀▒▒▀▀▀▀▄
   ▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
   ▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
    ▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
      ▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
           ▌▌░▌▌
           ▌▌░▌▌
         ▄▄▌▌▄▌▌        */



Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
signed main() {
	int n, K;
	cin >> n >> K;
	int ans = 0;
	vector< pair< int, pair<int, int> > > P;
	for (int i = 1; i <= n; i++) {
		int j = K - (i % K);
		// cout << "i:" << i << " j:" << j << endl;
		if (j == 0) break;
		if (j > n) continue;
		else {
			int k = K - (i % K);
			if ((j + k) % K == 0) {
				// cout << "i:" << i << " j:" << j << " k:" << k << endl;
				ans += ((n - k) / K + 1) * ((n - j) / K + 1);
				// P.push_back(make_pair(i, make_pair(j, k)));
			}
		}
	}

	// cout << "DEBUG" << endl;
	// for (int i = 0; i < P.size(); i++) {
	// 	cout << P[i].first << " " << P[i].second.first << " " << P[i].second.second << endl;
	// }

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

Measured memory_bytes: 256