akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//#include <mylib.h>
using namespace std;
//cin.sync_with_stdio(false);

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define FOR_EQ(i,a,b) for(int i = (a); i <= (b); ++i)
#define FOR_RE(i,a,b) for(int i = (a); i > (b); --i)
#define rep(i,n) FOR(i,0,n)
#define rep_eq(i,n) FOR_EQ(i,0,n)
#define rep_re(i,n) FOR_RE(i,n,0)

#define WHITE 1//（未訪問）
#define GRAY 2//（訪問）未だに訪問していない頂点への辺を持っている。スタックに退避。
#define BLACK 3//（訪問完了）未訪問への頂点への辺を持たない
#define N 100
#define INFTY (1 << 21) //10^21
int M[N][N];//隣接行列
int color[N];

//1個上から時計周り
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
//上右下左
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
static const int NIL = -1;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> Vector;
typedef vector<Vector>	DVector;
//int n;

//配列の表示
void printArray(int array[], int n){
    rep(i, n){
        if(i)   cout << " ";
        cout << array[i];
    }
    cout << endl;
}

#define div 1000000007

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    unsigned int n, m;
    unsigned long long int dog = 1, monkey = 1;
    
    cin >> n >> m;
    bool flg;
    
    if(n == m){
        flg = true;
    }else{
        flg = false;
    }
    
    int rem = n - m;
    if(abs(rem) >= 2){
        cout << 0 << endl;
        return 0;
    }
    
    FOR_RE(i, n, 0){
        dog *= i;
        dog %= div;
    }
    //cout << "dog " << dog << endl;
    
    FOR_RE(i, m, 0){
        monkey *= i;
        monkey %= div;
    }
    //cout << "monkey " << monkey << endl;
    
    unsigned long long int ans;
    ans = (dog * monkey) % div;
    
    if(flg){
        ans = ans * 2 % div;
    }else{
        ans = ans % div;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<memory>
#include<cmath>
#include<stack>
#include<tuple>
#include<numeric>
#include<cassert>

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define pb push_back
#define DEBUG false

using namespace std;

using ll = long long;
using P = pair<int,int>;

const int mod=1e9+7,INF=1<<30;
const double EPS=1e-12,PI=3.1415926535897932384626;
const ll LINF=1LL<<60;
const int MAX_N=3003;
const ll lmod = 1e9+7;
vector<int> water,sugar;

int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f ;
  int x = 0;
  rep(i,f/a) rep(j,f/b){
    if(!(i==0&&j==0)&&(a*i+b*j)*100<f) water.pb(a*i+b*j);
  }
  sort(ALL(water));
  water.erase(unique(ALL(water)),water.end());

  rep(i,f/c) rep(j,f/d){
    if(!(i==0&&j==0)&&(c*i+d*j)<f) sugar.pb(c*i+d*j);
  }
  sort(ALL(sugar));
  sugar.erase(unique(ALL(sugar)),sugar.end());
  int ans_s,ans_w;

  ans_s = sugar[0];
  ans_w = water[water.size()-1];
  if(ans_s>e*ans_w){
    cout << a*100 << " 0" << endl;
    return 0;
  }
  for(auto w:water){
    for(auto s:sugar){
      if(100*w+s>f) break;
      if((s<=w*e)&&(s*ans_w>w*ans_s)){
        ans_s = s;
        ans_w = w;
      }
    }
  }
  cout << 100*ans_w+ans_s << " " << ans_s << endl;
  return 0;
}

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

typedef long long ll;
int main(){
	ll h;
	int n;

	cin>>h>>n;

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

	for(int i =0;i<n;i++)
	{	h = h - arr[i];
		if(h <= 0)
			break;}

	if(h <= 0)
		cout<<"Yes";
	else
		cout<<"No";

	return 0;
}

Measured memory_bytes: 640
H, W = map(int, input().split())

if H == 1 or W == 1:
    print(1)
else:
    if H % 2 == 1 and W % 2 == 1:
        print(int(H * (W + 1) / 2) - H // 2)
    else:
        print(int(H * W / 2))


Measured memory_bytes: 9064
#include<cstdio>
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<complex>
#include<set>
#include<map>
#include<queue>

using namespace std;

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

typedef pair<int,int> pii;

class P{
	public:
	int now,used;
	double val;
	P(int now,double val,int used):now(now),val(val),used(used){}
	bool operator<(const P& a)const{
		return val>a.val;
	}
};

const int M = 33;
const int H = 8;

int visit[M][1<<H];

int main(){
	A:;
	int n,m,r,st,en;
	cin>>n>>m>>r>>st>>en;
	
	if(m==0)return 0;
	
	int hors[H];
	rep(i,n)cin>>hors[i];
	
	vector<pii> edge[M];
	rep(i,r){
		int a,b,c;
		cin>>a>>b>>c;
		edge[a].push_back(pii(b,c));
		edge[b].push_back(pii(a,c));
	}
	
	priority_queue<P> que;
	que.push(P(st,0,0));
	
	rep(i,M)rep(j,1<<H)visit[i][j]=0;
	
	double answer = -1;
	while(1){
		if(que.empty())break;
		
		P u = que.top();
		que.pop();
		
		if(visit[u.now][u.used]==1)continue;
		visit[u.now][u.used]=1;
		
		if(u.now==en){
			answer = u.val;
			break;
		}
		/*
		printf("now=%d ",u.now);
		printf("used=");
		rep(i,n)printf("%d",((u.used&(1<<i))>0));
		printf(" val=%lf\n",u.val);
		*/
		rep(i,edge[u.now].size()){
			int next = edge[u.now][i].first;
			double len = edge[u.now][i].second;
			
			rep(j,n){
				if((u.used & (1<<j))>0)continue;
				que.push( P(next, u.val+len/hors[j], u.used|(1<<j)) );
			}
		}
	}
	
	if(answer==-1)puts("Impossible");
	else printf("%lf\n",answer);
	
	goto A;
}

Measured memory_bytes: 16160
import java.util.Map.Entry;
import java.util.*;

import org.w3c.dom.css.Counter;

/*
ボールが N個あり、 i番目のボールには整数 
Aiが書かれています。
k=1,2,...,N
 に対して以下の問題を解いて、答えをそれぞれ出力してください。

k 番目のボールを除いた 
N−1 個のボールから、書かれている整数が等しいような異なる 
2 つのボールを選び出す方法の数を求めてください。選ぶ順序は考慮しません。
*/



public class Main {
    public static void main(final String[] args){
        //スキャン
        final Scanner s = new Scanner(System.in);
        int N = s.nextInt();
        HashMap<Integer,Long> counter = new HashMap<>();
        List<Integer> list = new ArrayList<Integer>();
        final int[] As = new int[N];

        for(int i = 0;i<=N-1;i++){
            As[i] = s.nextInt();
            if(!counter.containsKey(As[i])){
                //重複数を数え始める
                counter.put(As[i], (long) 1);
            }else{
                counter.put(As[i],counter.get(As[i])+1);
            }
        }
        s.close();
        
        //全組み合わせ計算
        Long allnum =0L;
        for(Entry<Integer,Long> entry :counter.entrySet()){
            Long param = entry.getValue();
            allnum += param*(param-1)/2;
        }
        //ｋの選択パターンを網羅
        for(int k = 0;k<=N-1;k++){
            //選ばれたkと同じ値は減衰させる
            if(counter.containsKey(As[k])){
                System.out.println(allnum - counter.get(As[k])+1);
            }else{
            System.out.println(allnum);
            }
        }
    }
}


Measured memory_bytes: 110584
import std.stdio;
import std.string;
import std.conv;

void main()
{
    int[] arr = readln.chomp.split.to!(int[]);
    int d = arr[0], n = arr[1];

    if (d == 0) {
        if (n == 100) writeln(101);
        else writeln(n);
    }
    else if (d == 1) {
        if (n == 100) writeln(100 * n + 100);
        else writeln(100 * n);
    }
    else if (d == 2) {
        if (n == 100) writeln(10000 * n + 10000);
        else writeln(10000 * n);
    }
}

Measured memory_bytes: 256
//
// Created by ryo on 2019/11/17.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <map>
#include <unordered_map>
#include <set>
#include <iomanip>
using namespace std;

typedef long long ll;

#define INF 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { debug(itr); }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

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

    cout << fixed << setprecision(11);

    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i, n) {
        cin >> x[i] >> y[i];
    }

    vector<int> path(n);
    rep(i, n) {
        path[i] = i;
    }

    auto dist = [](int a, int b, int c, int d) -> double {
        return sqrt(abs(a - c) * abs(a - c) + abs(b - d) * abs(b - d));
    };

    double ans = 0;
    ll cnt = 0;

    do {
        cnt += 1;
        double total = 0;
        for (int i = 0; i < n - 1; ++i) {

            total += dist(x[path[i]], y[path[i]], x[path[i+1]], y[path[i+1]]);
        }
        ans += total;
        // cout << endl;
        // cout << total << endl;
    } while (next_permutation(path.begin(), path.end()));


    cout << (double) ans / cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
string S;
vi va, vb;
int C[7];

int ketasu(int n) {
  int t = n;
  int r = 0;
  if (n == 0) {
    return 1;
  }
  while (n) {
    r++;
    n /= 10;
  }
  return r;
}
void input() {
  bool exist = true;
  rep(i, 0, 6) { C[i] = -1; }
  cin >> N >> M;

  rep(i, 1, M) {
    int s, c;
    cin >> s >> c;
    if ((C[s] == -1) || (C[s] == c)) {
      C[s] = c;
    } else {
      cout << -1 << endl;
      exist = false;
      return;
    }
  }

  rep(i, 0, 999) {
    if (ketasu(i) == N) {
      int n = i;
      deque<int> dq;
      dq.push_back(0);

      while (n) {
        dq.push_front(n % 10);
        n /= 10;
      }
      dq.push_front(0);

      bool tmp = true;
      rep(j, 1, N) {
        if (dq[j] == C[j] || (C[j] == -1)) {
          // ok
        } else {
          tmp = false;
        }
      }
      if (tmp) {
        cout << i << endl;
        return;
      }

      ;
      ;
    }
  }

  cout << -1 << endl;
}
void solve() {
  ;
  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <iomanip>
using namespace std;
#define INF 2001001001
#define MOD 1000000007
typedef long long ll;

ll N,X;
ll arr[101];

int main()
{
  ios_base::sync_with_stdio(0);cin.tie(0);
  cin>>N>>X;
  for (int i=0;i<N;i++)
    cin>>arr[i];
  sort(arr,arr+N);
  ll ans=0;
  for (int i=0;i<N;i++)
    if (X-arr[i]>=0){
      X-=arr[i];
      ans++;
    }
  if (X>0 && ans==N)
    ans--;
  ans=max(ans,0LL);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
import Data.List

ans :: String -> String
ans [] = []
ans str@(s:ss) =
  if isPrefixOf "apple" str
  then "peach" ++ ans (drop 5 str)
  else
    if isPrefixOf "peach" str
    then "apple" ++ ans (drop 5 str)
    else s:(ans ss)

main = do
  c <- getContents
  let l = lines c
      o = map ans l
  mapM_ putStrLn o

Measured memory_bytes: 3684
from itertools import permutations


def main():
    a,b,c = input().split()
    lst = ["+",a,b,c]
    perm = list(permutations(lst))
    mx = 0
    for p in perm:
        if p[0] == "+" or p[-1] == "+":
            continue
        mx = max(mx,eval("".join(p)))
    print(mx)



if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fast_cin ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define pb push_back
#define all(con) (con).begin(), (con).end()
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<b;++i)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define rpe(i,a,b) for(i=a-1;i>=b;i--)
#define rp(i,n) rep(i,0,n)
#define fr(i,n) fre(i,1,n)
#define ff(i,a,b) for(int i=a;i<=b;i++)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
		res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;

const int N = 1e5 + 10 ;

void solve() {
        int a,b;
        cin>>a>>b;
        int ans=ceil(1.0*a/b) ; 
        cout<<ans<<endl;
}

signed main() {
        fast_cin;
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
        #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    	#endif

	int tests=1;
	// cin>>tests;
	while(tests--) {
		solve();
	}

return 0 ;
}



Measured memory_bytes: 256
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

signed main() {
  int N;
  cin >> N;
  vector<string> S(N);
  map<string, int> m;
  rep(i, N) {
    cin >> S[i];
    m[S[i]]++;
  }

  cout << "AC" << ' ' << 'x' << ' ' << m["AC"] << endl;
  cout << "WA" << ' ' << 'x' << ' ' << m["WA"] << endl;
  cout << "TLE" << ' ' << 'x' << ' ' << m["TLE"] << endl;
  cout << "RE" << ' ' << 'x' << ' ' << m["RE"] << endl;
}

Measured memory_bytes: 6440
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

const int inf = INT_MAX;
const int MOD = 1000000007;
const long long INF = LLONG_MAX;

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

ll D;
ll c[30];
ll s[400][30];
ll t[400];
ll last[30];
ll score;

ll calc_score(ll day, ll ct) {
  ll res = 0;
  ll last_tmp[30];
  rep(i, 1, 26) { last_tmp[i] = last[i]; }

  res += s[day][ct];
  last_tmp[ct] = day;

  repe(i, 1, 26) { res -= c[i] * (day - last_tmp[i]); }

  return res;
}

int main() {
  cin >> D;
  repe(i, 1, 26) { cin >> c[i]; }
  repe(i, 1, D) {
    repe(j, 1, 26) { cin >> s[i][j]; }
  }

  repe(i, 1, D) {
    ll ct;
    ll gain = 0;
    repe(j, 1, 26) {
      if (chmax(gain, calc_score(i, j))) {
        ct = j;
      }
    }

    score += gain;
    last[ct] = i;

    cout << ct << "\n";
  }
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
  #define FASTIO std::ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  using namespace std;
  #define endl '\n'
  #define deb cout<<"sab_badhiya"<<endl;
  typedef long long int ll;
  // const long long INF = 1000 * 1000 * 1000 * 1ll * 1000 * 1000 * 1000;
  const long INF = 1000 * 1000 * 1000 + 7;
  int main() {
    int x;
    cin >> x;
    ll ans = 1000 * (x / 500);
    x = x % 500;
    ans += 5 * (x / 5);
    cout << ans << endl; 
  }


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

using namespace std;
using ll = long long;

const int N = 305;
int h, w, k;
char mat[N][N];
int ans[N][N];

int main() {

	scanf("%d %d %d", &h, &w, &k);

	for(int i = 0; i < h; i++) scanf(" %s", mat[i]);

	int cnt = 0;
	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			int tmp = j;
			while(tmp < w and mat[i][tmp] != '#') tmp++;
			if(tmp == w) {
				if(j == 0) break;
				while(j < w) ans[i][j++] = cnt;
			}
			else {
				cnt++;
				while(j <= tmp) ans[i][j++] = cnt;
				j = tmp;
			}
		}
	}

	while(1) {
		bool any = false;
		for(int i = 0; i < h; i++) {
			if(ans[i][0] == 0) {
				any = true;
				int add = i + 1 < h ? 1 : -1;
				if(ans[i + add][0] == 0) {
					add *= -1;
					if(i + add < 0 or i + add >= h) continue;
					if(ans[i + add][0] == 0) continue;
				}
				for(int j = 0; j < w; j++) {
					ans[i][j] = ans[i + add][j];
				}
			}
		}
		if(!any) break;
	}

	for(int i = 0; i < h; i++) {
		for(int j = 0; j < w; j++) {
			printf("%d%c", ans[i][j], " \n"[j + 1 == w]);
		}
	}
}


Measured memory_bytes: 1152
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>
#include <random>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
//#define int long long

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

constexpr int MOD = 1'000'000'007;

int solve() {
    int n;
    cin >> n;
    VLL a(n);
    REP(i,0,n) cin >> a[i];
    REP(i,0,n) if (a[i] > i) {
        return 0;
    }
    if (n == 1) return 3;
    VLL dp(n);
    dp[0] = 3;
    VI cnt(n+1);
    cnt[0] = 3;
    cnt[1] = 1;
    REP(i,1,n) {
        int m = cnt[a[i]] - cnt[a[i]+1];
        if (m <= 0) return 0;
        dp[i] = (dp[i-1] * m) % MOD;
        cnt[a[i]+1]++;
        if (cnt[a[i]+1] > 3) return 0;
        //dump(dp[i]);
    }
    return dp[n-1];
}

signed main() {
    cout << (solve()) % MOD << endl;
    
    return 0;
}

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

int main() {
	char b;
	cin >> b;
	char ans;
	if(b == 'A') {
		ans = 'T';
	} else if (b == 'T') {
		ans = 'A';
	} else if (b == 'C') {
		ans = 'G';
	} else {
		ans = 'C';
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
A,B,C = map(int,input().split())

NG_flg = 1
for i in range(B):
    if (i*(A%B))%B == C%B: # B未満の任意の整数*(A mod B) = C mod B とできるか？
        NG_flg = 0

print("NO" if NG_flg == 1 else "YES")

Measured memory_bytes: 2940
#include <iostream>

using namespace std;

int main()
{
	int n;
	cin >> n;
	int * CBTree = new int[n+1];
	
	for (int i =1; i <= n; i++)
	{
		cin >> CBTree[i];
	}
	
	for (int i =1; i <= n; i++)
	{
		cout << "node " << i << ": ";
		cout << "key = " << CBTree[i] << ", ";
		
		if (i != 1)
			cout << "parent key = " << CBTree[i/2] << ", ";
		if (2*i <= n)
			cout << "left key = " << CBTree[2*i] << ", ";
		if (2*i+1 <= n)
			cout << "right key = " << CBTree[2*i+1] << ", ";
		
		cout << endl;
	}
}


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

using namespace std;
typedef long long ll;

int main(void)
{
    ll N;
    string S;
    cin>>N>>S;

    string ans ="ABC";

    int num = 0;
    int res =0;
    for(ll i=0;i<N;i++){
        if(ans.at(num)==S.at(i)){
            num++;
        }
        else{
          if(S.at(i)=='A'){
            num=1;
          }
          else{
            num=0;
          }
        }

        if(num==3){
            res++;
            num=0;
        }
    }

    cout<<res<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;
using ll = long long;

int main(void) {
    int S, W;
    cin >> S >> W;

    if(W>=S){
        cout << "unsafe" << endl;
    } else {
        cout << "safe" <<endl;
    }

    return 0;
}


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

struct IM
{
  int i;
  int m;
};

int main()
{
  int N, M;
  cin >> N >> M;
  vector<int> a(N), b(N);
  for (int i = 0; i < N; ++i)
    cin >> a[i] >> b[i];
  vector<int> c(M), d(M);
  for (int i = 0; i < M; ++i)
    cin >> c[i] >> d[i];
  for (int i = 0; i < N; ++i)
  {
    vector<IM> im(M);
    for (int j = 0; j < M; ++j)
    {
      im[j].i = j + 1;
      im[j].m = abs(a[i] - c[j]) + abs(b[i] - d[j]);
    }
    sort(im.begin(), im.end(), [](auto & l, auto & r){
      return (l.m < r.m) ? true : ((l.m == r.m) ? l.i < r.i : false);
    });
    cout << im[0].i << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string s;
    getline(cin,s);
    int i;
    for(i=0;i<s.size();i++){
        if(s[i]>='a'&&s[i]<='z')
            s[i]+='A'-'a';
        else if(s[i]>='A'&&s[i]<='Z')
            s[i]+='a'-'A';
    }
    cout << s << endl;
}


Measured memory_bytes: 3168
N,K = gets.chomp.split(" ").map(&:to_i);

win = []

N.times do |n|
  count = 0
  score = n + 1
  while score <= K - 1  do
    score *= 2
    count += 1
  end
  if count == 0
    win << N
  else
    win <<  2**count * N
  end
end

win_win = 0.to_f

win.each do |num|
  win_win += ( 1 / num.to_f )
end

puts win_win

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

using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    double a, b;
    cin >> a >> b;
    double t = (a+b);
    t /= 0.18;
    int e = (int)t - 2;
    bool is = true;
    for(int i = 0; i < 100; ++i){
        int k = e + i;
        if((int)((double)k * 0.08) == a and (int)((double)k * 0.1) == b){
            cout << k << endl;
            is = false;
            break;
        }
    }
    if(is){
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<tuple>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define INF 1e9+7
#define LLINF 1e18
// #define int ll
using namespace std;
const int MOD = 1e9 +7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, C;
    int imos[30][101010];
    cin>>N>>C;
    rep(i,N){
        int  a,b,c;
        cin>>a>>b>>c;
        a--;c--;
        imos[c][a]++;
        imos[c][b]--;
    }
    rep(c,C) rep2(i,1,100010) imos[c][i] += imos[c][i-1];
    rep(c,C) rep(i,100010) if(imos[c][i]) imos[c][i]=1;
    int ans=0;
    rep(i,100010){
        int cnt=0;
        rep(c,C) cnt +=  imos[c][i];
        ans=max(ans,cnt);
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 12160
import java.io.*;
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		solver.solve(1, scan, out);
		out.close();
	}
	
	static class Task {
		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			int n = scan.nextInt();
			double curr = 0;
			for(int i = 0; i < n; i++) curr += 1/scan.nextDouble();
			out.println(1/curr);
		}
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

}


Measured memory_bytes: 21460
import sys

N,M=map(int,input().split())
A=[int(x) for x in input().split()]
A.sort()
pos=[0 for x in range(M)]
dis=[]
for i in range(M-1):
  dis.append([abs(A[i]-A[i+1]),i+1])

if N>=M:
  print(0)
  sys.exit()
  
dis=sorted(dis,key=lambda x:-x[0])
for i in range(N-1):
  pos[dis[i][1]]=1
  
ans=0
cnt=A[0]
for i in range(M-1):
  if pos[i+1]==1:
    cnt=A[i+1]
  else:
    ans+=abs(cnt-A[i+1])
    cnt=A[i+1]
  
print(ans)

Measured memory_bytes: 23288
#include<map>
#include<set>
#include<list>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<stack>
#include<string>
#include<vector>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<complex>
#include<iostream>
#include<algorithm>
#define rep(i,s,t) for(register int i=s;i<=t;++i)
#define _rep(i,s,t) for(register int i=s;i>=t;--i)
#define Rep(i,s,t) for(register int i=s;i<t;++i)
#define go(x) for(register int e=las[x];e;e=nxt[e])
#define re register
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define is insert
#define es erase
#define pii pair<int,int>
#define ms(f,x) memset(f,x,sizeof f)
#define mc(f,x) memcpy(f,x,sizeof f)
#define open(x) freopen(#x".in","r",stdin),freopen(#x".out","w",stdout)
#define gi(x) read(x)
#define gii(x,y) read(x),read(y)
#define giii(x,y,z) read(x),read(y),read(z)
namespace IO{
    #define gc getchar()
    #define pc(x) putchar(x)
    template<typename T>inline void read(T &x){
        x=0;int f=1;char ch=gc;while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=gc;}
        while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=gc;x*=f;return;
    }
    template<typename T>inline void write(T x=0){
        T wr[51];wr[0]=0;if(x<0)pc('-'),x=-x;if(!x)pc(48);
        while(x)wr[++wr[0]]=x%10,x/=10;while(wr[0])pc(48+wr[wr[0]--]);return;
    }
}
using IO::read;
using IO::write;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef unsigned long long ull;
using namespace std;
const int N=1e6+11;
int n,ans;
char s[N];
int sum[N],k[N],l[N];
int main(){
	gi(n);
	scanf("%s",s+1);
	ans=n;
	rep(i,1,n){
		k[i]=k[i-1]+(s[i]=='.');
		l[i]=l[i-1]+(s[i]=='#');
	}
	rep(i,1,n)
		k[i]=min(l[i],k[i]);
	_rep(i,n,1){
		sum[i]=sum[i+1]+(s[i]=='.');
		ans=min(ans,sum[i]+k[i-1]);
	}
	ans=min(ans,k[n]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
#define ll long long int
#define pb(x) push_back(x)
#define TEST int inox,t;cin>>t; for(inox=1;inox<=t;inox++)
#define rep(i,n) for(i=0;i<n;i++)
#define repr(i,n) for(i=n-1;i>=0;i--)
#define FAST    ios::sync_with_stdio(false); cin.tie(0);
using namespace std;
#define modd 998244353 
 
int main(){
 
ll n,m; cin>>n>>m;
cout<<min(abs(n%m),abs(m-abs(n%m)));
}

Measured memory_bytes: 256
/*

This Submission is to determine how many 120/240 min const. delivery point there are.

//info
120 req. steps <= 5
*/
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 1000000007
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)

unsigned long xor128() {
	static unsigned long x = time(NULL), y = 362436069, z = 521288629, w = 88675123;
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
int main() {
	int n;
	cin >> n;
	double bot = 0;
	REP(i, n) {
		double a;
		cin >> a;
		bot += 1.0 / a;
	}
	cout << fixed << setprecision(10);
	cout << 1.0 / bot << endl;
}

Measured memory_bytes: 888
import itertools

n,m=map(int, input().split())
List=[list(map(int,input().split())) for i in range(m)]
p = list(map(int,input().split()))

seq = [0,1] #反復する配列
v_list = list((itertools.product(seq,repeat = n))) #2進数でon/offを用意しておく

ans = 0

for i in range(2**n):
  All_ok = 0
  for j in range(m):
    on_off = 0
    for k in range(List[j][0]):
      on_off += v_list[i][List[j][k+1]-1]
    if on_off % 2 == p[j]:
      All_ok += 1
  if All_ok == m:
    ans += 1
print(ans)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define mod 924844033
using namespace std;
int read();
int M(int x) { return x >= mod ? x - mod : x; }
int fsp(int bs, int p) {
    int rt = 1;
    while (p) {
        if (p & 1) rt = 1ll * rt * bs % mod;
        bs = 1ll * bs * bs % mod, p >>= 1;
    }
    return rt;
}

int n;

int fac[200005], caf[200005];
void init() {
    int lim = 200000;
    fac[0] = 1;
    for (int i = 1; i <= lim; ++i) fac[i] = 1ll * fac[i - 1] * i % mod;
    caf[lim] = fsp(fac[lim], mod - 2);
    for (int i = lim; i >= 1; --i) caf[i - 1] = 1ll * caf[i] * i % mod;
}
int C(int x, int y) { return 1ll * fac[x] * caf[y] % mod * caf[x - y] % mod; }

vector<int> e[200005];
void add(int u, int v) { e[u].push_back(v), e[v].push_back(u); }
int cnt[200005];
int dfs(int u, int fa) {
    int sz = 1;
    for (int i = 0, v, t; i < e[u].size(); ++i)
        if ((v = e[u][i]) != fa) ++cnt[t = dfs(v, u)], ++cnt[n - t], sz += t;
    return sz;
}
int rtt[600005];
void getrtt(int len, int w) {
    for (int i = 1; i < len; ++i) rtt[i] = (rtt[i >> 1] >> 1) | ((i & 1) << w);
}
struct Poly {
    int x[600005];
    int &operator[](int p) { return x[p]; }
    void ntt(int len) {
        for (int i = 1; i < len; ++i)
            if (rtt[i] > i) swap(x[i], x[rtt[i]]);
        for (int l = 2; l <= len; l <<= 1) {
            int m = l >> 1, O = fsp(5, (mod - 1) / l);
            for (int i = 0; i < len; i += l)
                for (int j = i, tO = 1, t; j < i + m; ++j) {
                    t = 1ll * x[j + m] * tO % mod;
                    x[j + m] = M(x[j] - t + mod), x[j] = M(x[j] + t);
                    tO = 1ll * tO * O % mod;
                }
        }
    }

    void idft(int len) {
        ntt(len), reverse(x + 1, x + len);
        int ny = fsp(len, mod - 2);
        for (int i = 0; i < len; ++i) x[i] = 1ll * x[i] * ny % mod;
    }
} a, b;

int main() {
    n = read(), init();
    for (int i = 1, u, v; i < n; ++i) u = read(), v = read(), add(u, v);
    dfs(1, 0);
    for (int i = 1; i < n; ++i) a[i] = 1ll * cnt[i] * fac[i] % mod;
    for (int i = 0; i < n; ++i) b[n - i - 1] = caf[i];

    int len = 2, w = 1;
    while (len < (n << 1)) len <<= 1, ++w;
    getrtt(len, w - 1), a.ntt(len), b.ntt(len);
    for (int i = 0; i < len; ++i) a[i] = 1ll * a[i] * b[i] % mod;
    a.idft(len);

    for (int i = 1; i <= n; ++i) {
        printf("%d\n", M(1ll * n * C(n, i) % mod -
                         1ll * a[n + i - 1] * caf[i] % mod + mod));
    }
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}


Measured memory_bytes: 30464
#include <stdio.h>
   
int main()
{
    int H, W;
   
    scanf("%d %d", &H, &W);
    while ((H != 0) || (W != 0)) {
        int i, j;
        for (i = 0; i < H; i++) {
            for (j = 0; j < W; j++) {
                printf("#");
            }
        putchar('\n');
        }
    putchar('\n');
    scanf("%d %d", &H, &W);
    }
   
    return 0;
}

Measured memory_bytes: 576
#include<iostream>

int main()
{
    int n;
    unsigned int R[200000];
    unsigned int Min=0;
    int res=0;
    int temp=0;
    std::cin>>n;
    for(int i=0;i<n;i++)
    {
        std::cin>>R[i];
    }
    res=R[1]-R[0];
    Min =R[0];
    for(int j=1;j<n;j++)
    {
        temp=R[j]-Min;
        if(temp>res)
        {
            res=temp;
        }
         if(Min>R[j])
        {
            Min=R[j];
        }

    }
    std::cout<<res<<std::endl;
}


Measured memory_bytes: 3864
n, m = map(int, input().split())
store = [[0, 0] for i in range(n)]
for i in range(n):
    store[i] = list(map(int, input().split()))
store.sort(key=lambda x:(x[0],x[1]))
count = m
money = 0
for el in store:
    a, b = el
    if count <= b:
        money += a*count
        break
    else:
        count -= b
        money += a*b
print(money)

Measured memory_bytes: 35364
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i=0;i<N;i++){cin >> d.at(i);}
  sort(d.begin(), d.end());
  int count=0;
  for(int i=0;i<N-1;i++){
    if(d.at(i)!=d.at(i+1)){count++;}
  }
  cout << count+1 << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int ChartoInt(char chr)
{
    switch(chr){
        case '1':return 1; break;
        case '2':return 2; break;
        case '3':return 3; break;
        case '4':return 4; break;
        case '5':return 5; break;
        case '6':return 6; break;
        case '7':return 7; break;
        case '8':return 8; break;
        case '9':return 9; break;
        case '0':return 0; break;
    }

    return 10;
}

int main(){
    char n[200020];
    int sum = 0;
    int num;
    char c;
    
    scanf("%s",n);
    for(int i = 0; i < strlen(n); i++){
        sum += ChartoInt(n[i]);
    }
    
    // printf("%d\n",sum);
    if(sum % 9 == 0) printf("Yes\n");
    else printf("No\n");
    return 0;
}




Measured memory_bytes: 1780
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma warning(disable:4996)
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <list>
#include <set>
#include <ctime>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

const int INF = 1001001001;
const int MAX_M = 100000;

int dp[5005][5005];


int main(int argc, char *args[]) {
	int N;
	cin >> N;
	bool flag = false;
	for (int i = 1; i <= 9; i++) {
		int ans = N / i;
		int r = N % i;
		if (ans >= 1 && ans <= 9 && r == 0) {
			flag = true;
			break;
		}
	}
	if (flag == true) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

}

Measured memory_bytes: 256
#include<iostream>
#include<list>
#include<vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<math.h>
#include<unordered_map>
#include<map>

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;


bool solve()
{
	int n; cin >> n;
	if (n == 0)return false;


	vector<string> S(n);
	vector<int>    indent(n);
	for(int i=0;i<n;++i)
	{
		cin >> S[i];
	}

	for (int i = 0; i < n; ++i)
	{
		int j = 0;
		for (j = 0; S[i][j + 1] == '.'; ++j)
		{
			S[i][j] = ' ';
		}
		if (S[i][j] == '.')S[i][j] = '+', indent[i] = j;
		else indent[i] = 0;
	}

	for (int i = n - 1; i > 0; --i)
	{
		for (int j = i - 1; j > 0 && indent[i]<S[j].length() && indent[j]>indent[i]; --j)
		{
			S[j][indent[i]] = '|';
		}
	}


	for (auto & s : S)
	{
		cout << s << endl;
	}

	return true;
}


int main()
{
	while(solve())
	{

	}

	return 0;
}


Measured memory_bytes: 3624
fun f(a : Long, b : Long) : Long {
    if (b == 0L) return -a
    if (a < b) return f(b, a)
    val m = a / b
    return m * 2 * b + f(b, a % b)
}

fun main(args: Array<String>) {
    val (n, x) = readLine()!!.split(' ').map(String::toLong)
    println(f(x, n - x) + n)
}

Measured memory_bytes: 22188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
using namespace std;

int n;

class Road
{public:
	int t, next;
}e[201010];
int p[101010];
int z = -1;

void add(int u, int v)
{
	++z;
	e[z].t = v;
	e[z].next = p[u];
	p[u] = z;
}

int a[101010];
int pos[101010];
int sign[101010];
int l[101010], r[101010];

void dfs(int u, int fa)
{
	if(a[u] >= 0)
	{
		l[u] = r[u] = a[u];
		sign[u] = a[u]&1;
	}
	else
	{
		l[u] = -1e8, r[u] = 1e8;
		sign[u] = -1;
	}
	for(int tmp = p[u]; tmp != -1; tmp = e[tmp].next)
	{
		if(e[tmp].t != fa)
		{
			dfs(e[tmp].t, u);
			if(sign[e[tmp].t] != -1)
			{
				if(sign[u] == sign[e[tmp].t])
				{
					puts("No");
					exit(0);
				}
				sign[u] = sign[e[tmp].t]^1;
				l[u] = max(l[u], l[e[tmp].t] - 1);
				r[u] = min(r[u], r[e[tmp].t] + 1);
				if(l[u] > r[u])
				{
					puts("No");
					exit(0);
				}
			}
		}
	}
	//cout<<u<<" "<<l[u]<<" "<<r[u]<<" "<<sign[u]<<endl;
}

void dfs1(int u, int fa)
{
	//cout<<l[u]<<" "<<sign[u]<<" "<<u<<endl;
	if(sign[u] == -1)
		a[u] = a[fa] + 1;
	else
	{
		if(fa)
			if(a[fa] + 1 >= l[u] && a[fa] + 1 <= r[u])
				a[u] = a[fa] + 1;
			else
				a[u] = a[fa] - 1;
		else
			a[u] = l[u];
	}
	for(int tmp = p[u]; tmp != -1; tmp = e[tmp].next)
		if(e[tmp].t != fa)
			dfs1(e[tmp].t, u);
}

int k;

int main()
{
	memset(p, -1, sizeof(p));
	memset(a, -1, sizeof(a));
	
	scanf("%d", &n);
	int u, v;
	for(int i = 1; i < n; ++i)
	{
		scanf("%d%d", &u, &v);
		add(u, v);
		add(v, u);
	}
	scanf("%d", &k);
	for(int i = 1; i <= k; ++i)
	{
		scanf("%d%d", &pos[i], &v);
		a[pos[i]] = v;
	}
	dfs(1, 0);
	dfs1(1, 0);
	puts("Yes");
	for(int i = 1; i <= n; ++i)
	{
		printf("%d\n", a[i]);
	}

	return 0;
}

Measured memory_bytes: 9216
#２２０5~

import sys
[a,b,c]=list(map(int,input().split()))# W H N
lst=[]
for i in range(c):
    lst.append(list(map(int,input().split())))
#print(a,b,c,lst)

lstxmax=[0]
lstxmin=[a]
lstymax=[0]
lstymin=[b]
for i in lst:
    if i[2]==1:
        lstxmax.append(i[0])
    if i[2]==2:
        lstxmin.append(i[0])
    if i[2]==3:
        lstymax.append(i[1])
    if i[2]==4:
        lstymin.append(i[1])

xmin=min(lstxmin)
xmax=max(lstxmax)
ymin=min(lstymin)
ymax=max(lstymax)

#print(xmax,xmin,ymax,ymin)
if xmin-xmax>=0 and ymin-ymax>=0:
    print((xmin-xmax)*(ymin-ymax))
else:
    print(0)



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

const int mod = 1e9 + 7;

inline int add(int a, int b)
{
	return (0LL + a + b)%mod;
}

inline int mult(int a, int b)
{
	return (1LL*a*b)%mod;
}

class Tree
{
public:
	int vertex;
	vector<vector<int>> adj;
	vector<int> dp_incl, dp_excl, dp;

public:
	Tree(int vertex);
	void addEdge(int u, int v);
	void computeWays(int source, int parent);
};

Tree :: Tree(int vertex)
{
	this->vertex = vertex;
	adj.resize(vertex);
	dp_incl.resize(vertex), dp_excl.resize(vertex);
	dp.resize(vertex);
}

void Tree :: addEdge(int u, int v)
{
	adj[u].push_back(v);
	adj[v].push_back(u);
}

void Tree :: computeWays(int source, int parent)
{
	dp_incl[source] = 1;
	dp_excl[source] = 1;

	for(int child : adj[source])
	{
		if(child != parent)
		{
			computeWays(child, source);
			dp_incl[source] = mult(dp_incl[source], dp_excl[child]);
			dp_excl[source] = mult(dp_excl[source],  dp[child]);
		}
	}

	dp[source] = add(dp_incl[source], dp_excl[source]);
}

void IndependentSet()
{
	int n;
	cin >> n;

	int edges = n - 1;

	Tree tree(n);

	for(int i = 0; i < edges; i++)
	{
		int u,v;
		cin >> u >> v;
		u--; v--;

		tree.addEdge(u, v);
	}

	tree.computeWays(0, -1);
	cout << tree.dp[0] << endl;
}

int main()
{
	IndependentSet();
	return 0;
}



Measured memory_bytes: 13824
#include<bits/stdc++.h>
using namespace std;
 
int arr[505][505];
int memo[505][505];

int dp(int l,int r){
	if(l==r) return memo[l][r]=arr[l][r];
	if(l>r) return 0;
	if(memo[l][r]!=-1) return memo[l][r];
	return memo[l][r] = arr[l][r] + dp(l+1,r) + dp(l,r-1) - dp(l+1,r-1);
}
 
int main(){
	int n,m,q;
	int l,r;
	memset(arr,0,sizeof(arr));
	memset(memo,-1,sizeof(memo));
	scanf("%d%d%d",&n,&m,&q);
	for(int i = 0 ; i < m ; i ++){
		scanf("%d%d",&l,&r);
		arr[l][r]++;
	}
	int ans = dp(1,n);
	for(int  i = 0 ; i < q ; i ++){
		scanf("%d%d",&l,&r);
		if(memo[l][r] == -1) printf("0\n");
		else
		printf("%d\n",memo[l][r]);
	}
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
 
using namespace std;
 
#define mp make_pair
#define endl '\n'
using ll=long long;
 
const int INF=1e9+5;
const ll lim=(ll)3e16;
const int N=3e3+5;
const int mod=1e9+7;
const ll oo=1e18+5;


int main(){
	ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(0);
	int n;
	cin>>n;
	int minn=INF;
	int ans=0;
	for(int i=0;i<n;++i){
		int x;
		cin>>x;
		if(minn>x) ++ans;
		minn=min(minn,x);
	} 
	cout<<ans;
	return 0;
}


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

int main() {
    int N, x;
    cin >> N >> x;
    vector<int> a(N);
    rep(i, N) cin >> a[i];

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

    int end = 0;
    rep(i, N) {
        if (a[i] <= x) {
            x -= a[i];
        } else {
            break;
        }
        ++end;
    }

    if (end == N && x > 0)
        --end;
    cout << end << endl;

    return 0;
}

Measured memory_bytes: 256
/*
*ID: juryc
*LANG: C++
*/
#include<bits/stdc++.h>
using namespace std;
int main(){
int d,t,s; cin>>d>>t>>s;
int v=ceil(d/(double)s);
if(t>=v) cout<<"Yes"<<endl;
else cout<<"No"<<endl; 
return 0;
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // 100円, 101円, 102円, 103円, 104円, 105円の組合せ
  int X;
  cin >> X;
  // 最大値10万円なので、0円から100000円まで（100001個）の配列dpを準備
  // その金額で買える場合はtrue、買えない場合はfalse
  // 最初は全てfalseに設定する
  vector<bool> dp(100001, false);
  // 初期設定
  // 0円の場合は常に可能
  // 100円, 101円, 102円, 103円, 104円, 105円の場合も可能
  dp.at(0) = true;
  for(int i = 100; i <= 105; i++){
    dp.at(i) = true;
  }
  //　dp.at(200)からdp.at(X)まで検査していく
  for(int i = 200; i <= X; i++){
    for(int j = 100; j <= 105; j++){
      dp.at(i) = dp.at(i) || dp.at(i-j);
    }
  }
  cout << dp.at(X) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define modulo 1000000007
#define fast_io ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
using namespace std;
int main(){
	fast_io;
	ll n,length=0,ans=0;
	cin>>n;
	ll a[n];
	for (int i = 0; i < n; ++i){
		cin>>a[i];
		length=max(length,a[i]);
	}
	sort(a,a+n);
	ll b[length+1]={0};
	for (int i = 0; i < n; ++i){
		b[a[i]]++;
	}
	for (int i = 1; i <= length; ++i){
		b[i]+=b[i-1];
	}
	for (ll i = 0; i < n; ++i){
		for (ll j = i+1; j < n; ++j){
			ans+=max((ll)0,b[min(a[i]+a[j]-1,length)]-j-1);
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 256