akhauriyash/Code-Regression huggingface dataset:
#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 INF 1e9;
using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> data;

  UnionFind(int sz) { data.assign(sz, -1); }

  bool unite(int x, int y) {
    x = find(x), y = find(y);
    if (x == y) return (false);
    if (data[x] > data[y]) swap(x, y);
    data[x] += data[y];
    data[y] = x;
    return (true);
  }

  int find(int k) {
    if (data[k] < 0) return (k);
    return (data[k] = find(data[k]));
  }

  int size(int k) { return (-data[find(k)]); }
};

int main() {
  ll N, M;
  cin >> N >> M;
  ll A[M], B[M];
  REP(i, M) {
    cin >> A[i] >> B[i];
    A[i]--, B[i]--;
  }

  ll ans = 0;
  REP(i, M) {
    UnionFind uf(N);
    REP(j, M) if (j != i) uf.unite(A[j], B[j]);
    if (uf.size(A[i]) != N) ans++;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <bits/stdc++.h>
#include <set>
#include <list> //list<???> a; a.push_back ,insert(追加したい要素),a.sort(),参照できない
#include <vector> //vector<???> a; a.push_back,sort(a.begin(),a.end());a[i]
//配列 int a[N];a[i]=追加したい要素;sort(a,a+N);a[i]
using namespace std;
typedef long  ll;
#define rep(i,n) for(int i=0;i<(n);i++)


//using namespace std;
//


int main(){
  string moji;cin>>moji;
  if (moji=="a" || moji=="i" || moji=="u" || moji=="e" || moji=="o"){
    cout<<"vowel"<<endl;

  }else{
    cout<<"consonant"<<endl;
  }
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Deque;
import java.util.List;
import java.util.Scanner;

//方針はBFS
public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<List<Integer>> edge = new ArrayList<>(N+1);
        List<List<Integer>> cost = new ArrayList<>(N+1);
        for(int i=1;i<=N+1;i++){
          edge.add(new ArrayList<>());
          cost.add(new ArrayList<>());
        }

        for(int i=1;i<=N;i++){
          edge.get(i).add(0);
          cost.get(i).add(0);
        }

        for(int i=1;i<=N-1;i++){
          int u = sc.nextInt();
          int v = sc.nextInt();
          int w = sc.nextInt();

            edge.get(u).add(v);
            edge.get(v).add(u);
            cost.get(u).add(w);
            cost.get(v).add(w);

        }


        Deque <Integer> dq = new ArrayDeque<>();
        int status [] = new int[N+1];
        int ans [] = new int[N+1];


        for(int i=1;i<=N;i++){
            ans[i]=0;
            status[i]=0;
        }

        dq.push(1);
        status[1]=1;
        while(!dq.isEmpty()){
            int first_in = dq.pollLast();
            //
            for(int i=1;i<=edge.get(first_in).size()-1;i++){
                if(status[edge.get(first_in).get(i)]==0){
                    dq.push(edge.get(first_in).get(i));
                    status[edge.get(first_in).get(i)]=1;
                    int w = cost.get(first_in).get(i);
                    ans[edge.get(first_in).get(i)]=(ans[first_in] + w) % 2;
                    }
                }
      }
        for(int j=1;j<=N;j++) {
            System.out.println(ans[j]);
        }
    }
}

Measured memory_bytes: 126424
#include<bits/stdc++.h>
using namespace std;
/* I can't know bit!!! >< */
int n, c, a[31][16], b[31][16];
int dp[31][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2][2];
 
int main()
{
  while(cin >> n >> c, n) {
    for(int i = 0; i < n; i++) {
      for(int j = 0; j < 16; j++) {
        cin >> a[i][j];
      }
    }
    for(int i = 0; i < c; i++) {
      for(int j = 0; j < 16; j++) {
        cin >> b[i][j];
      }
    }
#define R(i, n) for(int i = 0; i < n; i++)
#define get(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) [a][b][c][d][e][f][g][h][i][j][k][l][m][n][o][p]
     
    memset(dp, -1, sizeof(dp));
    dp[0]get(a[0][0],a[0][1],a[0][2],a[0][3],a[0][4],a[0][5],a[0][6],a[0][7],a[0][8],a[0][9],a[0][10],a[0][11],a[0][12],a[0][13],a[0][14],a[0][15]) = 0;
    for(int i = 0; i < n; i++) {
      R(A,2) R(B,2) R(C,2) R(D,2) R(E,2) R(F,2) R(G,2) R(H,2) R(I,2) R(J,2) R(K,2) R(L,2) R(M,2) R(N,2) R(O,2) R(P,2) {
        if(dp[i]get(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P) == -1) continue;
        for(int j = 0; j < c; j++) {
          dp[i+1]get((A&~b[j][0])|a[i+1][0],(B&~b[j][1])|a[i+1][1],(C&~b[j][2])|a[i+1][2],(D&~b[j][3])|a[i+1][3],(E&~b[j][4])|a[i+1][4],(F&~b[j][5])|a[i+1][5],(G&~b[j][6])|a[i+1][6],(H&~b[j][7])|a[i+1][7],(I&~b[j][8])|a[i+1][8],(J&~b[j][9])|a[i+1][9],(K&~b[j][10])|a[i+1][10],(L&~b[j][11])|a[i+1][11],(M&~b[j][12])|a[i+1][12],(N&~b[j][13])|a[i+1][13],(O&~b[j][14])|a[i+1][14],(P&~b[j][15])|a[i+1][15]) = max(dp[i+1]get((A&~b[j][0])|a[i+1][0],(B&~b[j][1])|a[i+1][1],(C&~b[j][2])|a[i+1][2],(D&~b[j][3])|a[i+1][3],(E&~b[j][4])|a[i+1][4],(F&~b[j][5])|a[i+1][5],(G&~b[j][6])|a[i+1][6],(H&~b[j][7])|a[i+1][7],(I&~b[j][8])|a[i+1][8],(J&~b[j][9])|a[i+1][9],(K&~b[j][10])|a[i+1][10],(L&~b[j][11])|a[i+1][11],(M&~b[j][12])|a[i+1][12],(N&~b[j][13])|a[i+1][13],(O&~b[j][14])|a[i+1][14],(P&~b[j][15])|a[i+1][15]),dp[i]get(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P)+(A&b[j][0])+(B&b[j][1])+(C&b[j][2])+(D&b[j][3])+(E&b[j][4])+(F&b[j][5])+(G&b[j][6])+(H&b[j][7])+(I&b[j][8])+(J&b[j][9])+(K&b[j][10])+(L&b[j][11])+(M&b[j][12])+(N&b[j][13])+(O&b[j][14])+(P&b[j][15]));
        }
      }
    }
    int ret = 0;
    R(A,2) R(B,2) R(C,2) R(D,2) R(E,2) R(F,2) R(G,2) R(H,2) R(I,2) R(J,2) R(K,2) R(L,2) R(M,2) R(N,2) R(O,2) R(P,2) {
      ret = max(ret, dp[n]get(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P));
    }
    cout << ret << endl;
  }
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;



int main() {

    ll N;
    cin >> N;
    vector<ll> A(N);
    map<ll, ll> cov;
    REP(i, N){
        cin >> A[i];
        cov[A[i]]++;
    }
    ll ans = 0;
    for(auto itr = cov.begin(); itr != cov.end(); ++itr) {
        ans += (itr->second) * (itr->second - 1) / 2;
    }

    REP(i, N){
        ll n = cov[A[i]];
        ll tmp = ans - (n * (n - 1) / 2);
        n--;
        tmp += (n * (n - 1) / 2);
        cout << tmp << " ";
    }



}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/


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



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

#define loop(s, e, i) for (int i = s; i < e; ++i)
#define print(s) cout << s << endl;
using namespace std;
using ll = long long;
using lld = long long;

/*
浮動小数点の入力
cout << fixed << setprecision(9) << endl;
*/

ll gcd(ll a, ll b)
{
  if (a < b)
  {
    return gcd(b, a);
  }
  while (b != 0)
  {
    ll tmp = b;
    b = a % b;
    a = tmp;
  }
  return a;
}

int main() {
  int N, X, T;
  cin >> N >> X >> T;

  int result = 0;
  if (N%X == 0) {
    result = N/X *T;
  } else {
    result = (N/X+1) *T;
  }
  print(result);
}

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

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(void){
  ios::sync_with_stdio(false);

  ll N, K;
  cin >> N >> K;
  ll tmp = N/K;
  ll conf = N - tmp * K;
  ll con2 = abs(N - (tmp + 1) * K);
  ll ans  = min(conf, con2);
  cout << ans << endl;



  return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    int r, g, b;
    cin >> r >> g >> b;
    if((g * 10 + b) % 4 == 0)
        cout << "YES" << endl;
    else
    {
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import itertools

d,g = map(int,input().split())
    
arr = []
    
for i in range(d):
    arr.append(list(map(int,input().split())))
    
ans = 10**10

for i in itertools.product((0,1),repeat=d):
    score=0
    num=0
    index=0
    
    for j in range(d):
        if i[j]==1:
            score += (j+1)*100*arr[j][0] + arr[j][1]
            num +=arr[j][0]
        else:
            index = max(j,index)
    
    if g - score <=0:
        ans = min(ans,num)
    
    elif g - score <= (index+1) *100*(arr[index][0]-1):
        num+= -(-(g-score)//(100*(index+1)))
        ans =min(ans,num)

print(ans)
    

Measured memory_bytes: 40560
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    string s, t;
    cin >> s >> t;
    bool ok = true;
    rep(i, s.size()) if(s[i] != t[i]) ok = false;
    if(ok) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main(void){
  char number[3];
  for(int i=0;i<3;i++){
    cin>>number[i];
  }
  int count=0;
  for(int i=0;i<3;i++){
    if(number[i]=='7') count++;
  }
  if(count>=1) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}


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

int main(){
    int h,n,a;
    cin >> h >> n;
    for(int i = 0; i < n;i++){
        cin >> a;
        h -= a;
    }
    if(h > 0){
        cout << "No\n";
    }
    else{
        cout << "Yes\n";
    }
    return 0;

}

Measured memory_bytes: 256
H, W = map(int, input().split())
a = [input() for i in range(H)]
b = []
for i in range(H):
    if '#' in a[i]:
        b.append(a[i])
c = [i for i in zip(*b)]

d =[]
for i in range(len(c)):
    if '#' in c[i]:
        d.append(c[i])
e = [i for i in zip(*d)]

for i in e:
    print(''.join(i))

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

int main(){
  int n;
  cin >> n;
  
  vector<int> button(n);
  for(int i=0; i<n; i++){
    cin >> button[i];
  }
  
  int count = 0;
  int num = 1;
  
  for(int i=0; i<n; i++){
    count++;
    num = button[num-1];
    if(num==2){
      cout << count << endl;
      break;
    }
  }
  if(count==n)
    cout << -1 << endl;
}

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

int min(int a, int b) {
	if (a >= b) return b;
	else return a;
}

int main() {
	int n, x, y, ans[2000] = {};
	scanf("%d%d%d", &n, &x, &y);
	for (int i = 1; i <= n-1; i++) {
		for (int j = i + 1; j <= n; j++) {
			ans[min(j - i, abs(x - i) + abs(y - j) + 1)-1]++;
		}
	}
	for (int i = 0; i < n-1; i++) {
		printf("%d\n", ans[i]);
	}

	return 0;
}

Measured memory_bytes: 128
from collections import Counter


N=int(input())
l=['']*N
for i in range(N):
    l[i]=input()

l.sort()

c=1
c_crt=1
pre=""
ans=[]
for e in l+[""]:
    if e == pre:
        c_crt+=1
    else:
        if c_crt > c:
            ans=[pre]
            c=c_crt
        elif c_crt == c:
            ans.append(pre)
        c_crt=1
    pre=e
for e in ans:
    print(e)

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

#define REPR2(v) for(int i =0 ;i < v.size(); i++) { for(int j = 0; j < v[0].size(); j++) cout << v[i][j] << " "; cout << endl; } cout << endl

using namespace std;

typedef long long ll;

const ll INF = 100000000000000000ll;

int N;
vector<ll> slimes, csum;
vector<vector<ll>> dp;

// ll solve(int l, int r){
// 	if (p[l][r] == -1) return 0;
// 	int k = p[l][r];
// 	cout << dp[l][r] << endl;
// 	return dp[l][r] + solve(l, k) + solve(k+1, r);
// }

int main(){
	cin >> N;

	slimes.assign(N, 0);
	csum.assign(N+1, 0);
	dp.assign(N, vector<ll>(N, INF));
	// p.assign(N, vector<ll>(N, -1));

	for(int i =0; i < N; i++){
		cin >> slimes[i];
		csum[i+1] = csum[i] + slimes[i];
	}

	for(int r = 0; r < N; r++){
		for(int l = r; l >= 0; l--){
			if (l == r) { dp[l][r] = 0; }
			else if (l+1 == r) {dp[l][r] = slimes[l] + slimes[r];}
			else {
				for(int k = l; k < r; k++) {
					ll s = (l == k? slimes[l] : dp[l][k] + csum[k+1] - csum[l]) 
						+ (k+1 == r? slimes[r] : dp[k+1][r] + csum[r+1] - csum[k+1]);
					// ll s = 2*(dp[l][k] + dp[k+1][r]);
					if (s <= dp[l][r]) {
						dp[l][r] = s;
						// p[l][r] = k;
					}
				}
			}
		}
	}

	// REPR2(dp);
	// REPR2(p);

	cout << dp[0][N-1] << endl;
	// cout << solve(0, N-1) << endl;

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	int n;cin>>n;
	string s;cin>>s;
	int cnt=0;
	for(int i=0;i<=999;++i){
		string t=to_string(i);
        while(t.size()<3){
            t='0'+t;
        }
		int m=0;
		for(int j=0;j<n;++j){
			if(s[j]==t[m]){
				m++;
			}
			if(m==3){
				cnt++;
				break;
			}
		}
	}
	cout<<cnt<<endl;
}

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

#define F first
#define S second
#define prev azaza
#define MP make_pair
#define PB push_back

using namespace std;
typedef long long ll;
typedef long double ld;

const int max_n = 100111, max_log = 22, inf = 1000111222;

vector<pair<int, pair<int, int>>> v[max_n];
int pr[max_n][max_log];
int tin[max_n];
int tout[max_n];
int curt = 1;

ll d[max_n];

void dfs(int cur, int p, ll cur_d) {
    d[cur] = cur_d;
    tin[cur] = curt++;
    pr[cur][0] = p;
    for (int l = 0; l < max_log; ++l) {
        if (pr[cur][l] != -1 && pr[pr[cur][l]][l] != -1) {
            pr[cur][l + 1] = pr[pr[cur][l]][l];
        } else {
            break;
        }
    }

    for (int i = 0; i < v[cur].size(); ++i) {
        int to = v[cur][i].F;
        if (to != p) {
            dfs(to, cur, cur_d + v[cur][i].S.S);
        }
    }

    tout[cur] = curt++;
}

bool is_anc(int a, int b) {
    if (a == -1) return 1;
    return tin[a] <= tin[b] && tout[a] >= tout[b];
}

int lca(int a, int b) {
    if (is_anc(a, b)) return a;
    if (is_anc(b, a)) return b;

    for (int l = max_log - 1; l > 0; --l) {
        if (!is_anc(pr[a][l - 1], b)) {
            a = pr[a][l - 1];
        }
    }
    return pr[a][0];
}

int n, q;

ll ans[max_n];

// color, query
vector<pair<int, pair<int, int>>> qsum[max_n];

ll sum[max_n];

void dfs_sum(int cur, int pr) {
    for (auto c : qsum[cur]) {
        ans[c.S.F] += c.S.S * sum[c.F];
    }
    for (auto to : v[cur]) {
        if (to.F == pr) continue;
        sum[to.S.F] += to.S.S;
        dfs_sum(to.F, cur);
        sum[to.S.F] -= to.S.S;
    }
}


vector<pair<int, pair<int, int>>> qcnt[max_n];

ll cnt[max_n];

void dfs_cnt(int cur, int pr) {
    for (auto c : qcnt[cur]) {
        ans[c.S.F] += c.S.S * cnt[c.F];
    }
    for (auto to : v[cur]) {
        if (to.F == pr) continue;
        cnt[to.S.F]++;
        dfs_cnt(to.F, cur);
        cnt[to.S.F]--;
    }
}


int main() {
    //freopen("input.txt", "r", stdin);
    for (int i = 0 ; i < max_n; ++i) {
        for (int j = 0; j < max_log; ++j) {
            pr[i][j] = -1;
        }
    }
    cin >> n >> q;
    for (int i = 0; i + 1 < n; ++i) {
        int a, b, c, d;
        scanf("%d%d%d%d", &a, &b, &c, &d);
        --a, --b;
        v[a].PB(MP(b, MP(c, d)));
        v[b].PB(MP(a, MP(c, d)));
    }
    dfs(0, -1, 0);
    for (int i = 0; i < q; ++i) {
        int c, dd, x, y;
        scanf("%d%d%d%d", &c, &dd, &x, &y);
        --x, --y;
        int lc = lca(x, y);
        ans[i] = d[x] + d[y] - 2 * d[lc];
        qsum[x].push_back(MP(c, MP(i, -1)));
        qsum[y].push_back(MP(c, MP(i, -1)));
        qsum[lc].push_back(MP(c, MP(i, 2)));


        qcnt[x].push_back(MP(c, MP(i, dd)));
        qcnt[y].push_back(MP(c, MP(i, dd)));
        qcnt[lc].push_back(MP(c, MP(i, -2 * dd)));
    }
    dfs_sum(0, -1);
    dfs_cnt(0, -1);
    for (int i = 0; i < q; ++i) {
        cout << ans[i] << "\n";
    }
    return 0;
}




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

public class Main {
    static class Writer {
        PrintWriter cout;

        Writer() throws IOException {
            cout = new PrintWriter(System.out);
        }

        Writer(String name) throws IOException {
            cout = new PrintWriter(new FileWriter(name));
        }

        StringBuilder out = new StringBuilder();

        void print(Object a) {
            out.append(a);
        }

        void close() {
            cout.print(out.toString());
            cout.close();
        }
    }

    static class Reader {
        BufferedReader in;

        Reader() throws IOException {
            in = new BufferedReader(new InputStreamReader(System.in));
        }

        Reader(String name) throws IOException {
            in = new BufferedReader(new FileReader(name));
        }

        StringTokenizer tokin = new StringTokenizer("");

        String next() throws IOException {
            if (!tokin.hasMoreTokens()) {
                tokin = new StringTokenizer(in.readLine());
            }
            return tokin.nextToken();
        }

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

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

    public static void main(String args[]) throws IOException {
        Reader in = new Reader();
        Writer out = new Writer();
        int n = in.nextInt();
        long x = in.nextLong();
        ArrayList<Long> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(in.nextLong());
        }
        Collections.sort(a);
        int ans = 0;
        long sum = 0;
        for (int i = 0; i < n && sum < x; i++) {
            if(sum + a.get(i) <= x){
                sum += a.get(i);
                ans++;
            } else {
                break;
            }
        }
        if(ans == n && x > sum){
            ans = Math.max(ans - 1, 0);
        }
        out.print(ans);
        out.close();
    }
}

Measured memory_bytes: 23380
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
int main() {
	bool f = 0;
	ll p[168] = { 2,3,5,7,11,13,17,19,23,29,31,37 }, cnt = 12;
	for (int i = 38; i <= 1000; i++) {
		for (int j = 2; j <= 37; j++) {
			if (!(i%j)) {
				f = 1;
				break;
			}
		}
		if (f)f = 0;
		else {
			p[cnt] = i;
			cnt++;
		}
	}

	ll n, a[168] = {}, ans = 1, mod = 1e9 + 7, yojo;
	cin >> n;
	for (int i = 2; i <= n; i++) {
		yojo = i;
		for (int j = 0; j < 168; j++) {
			while (!(yojo%p[j])) {
				a[j]++;
				yojo /= p[j];
			}
		}
	}
	for (int i = 0; i < 168; i++) {
		ans *= (a[i] + 1);
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {

    int N;
    string Si;
    int P = 0, W = 0, G = 0, Y = 0;

    cin >> N;

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

        if(Si == "P")
            P += 1;
        else if(Si == "W")
            W += 1;
        else if(Si == "G")
            G += 1;
        else if(Si == "Y")
            Y += 1;
    }    
    
    if(P >= 1 && W >= 1 && G >= 1 && Y >= 1)
        cout << "Four";
    else if(P >= 1 && W >= 1 && G >= 1 && Y == 0)
        cout << "Three";
    
    
}

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

using namespace std;

const int max_n = 202, max_x = 100111, mod = 1000000007;

int n, x, a[max_n], dp[max_n][max_x];
int c[max_n][max_n], f[max_n];

int mul(int x, int y) {
    return 1LL * x * y % mod;
}

void get_all_c() {
    f[0] = 1;
    for (int i = 1; i < max_n; ++i) {
        f[i] = mul(f[i - 1], i);
    }
    for (int i = 0; i < max_n; ++i) {
        c[i][0] = 1;
        for (int j = 1; j <= i; ++j) {
            c[i][j] = (c[i - 1][j - 1] + c[i - 1][j]) % mod;
        }
    }
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    get_all_c();
    scanf("%d%d", &n, &x);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }
    sort(a + 1, a + n + 1);
    dp[n][x] = 1;
    for (int i = n; i >= 1; --i) {
        int sum = 0;
        for (int x = 0; x < max_x; ++x) {
            sum += dp[i][x];
            if (!dp[i][x]) {
                continue;
            }
            for (int last = 1; last <= i; ++last) {
                dp[last - 1][x % a[last]] += mul(dp[i][x], mul(c[i - 1][last - 1], f[i - last]));
                dp[last - 1][x % a[last]] %= mod;
            }
        }
    }
    int ans = 0;
    for (int x = 0; x < max_x; ++x) {
        ans += mul(dp[0][x], x);
        ans %= mod;
    }
    printf("%d\n", ans);
    return 0;
}


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

using namespace std;

struct UnionFind
{
    vector<int> data;

    UnionFind(int size) : data(size, -1) { }

    bool unionSet(int x, int y) {
        x = root(x); y = root(y);
        if (x != y) {
            if (data[y] < data[x]) swap(x, y);
            data[x] += data[y]; data[y] = x;
        }
        return x != y;
    }

    bool findSet(int x, int y) {
        return root(x) == root(y);
    }

    int root(int x) {
        return data[x] < 0 ? x : data[x] = root(data[x]);
    }

    int size(int x) {
        return -data[root(x)];
    }
};

int main()
{
    int n, q, com, x, y;

    cin >> n >> q;

    UnionFind uf(n);

    while (q--) {
        cin >> com >> x >> y;

        if (com == 0) { // unite
            uf.unionSet(x, y);
        }
        else { // same
            if (uf.findSet(x, y))
                cout << "1\n";
            else
                cout << "0\n";
        }
    }

    return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
vector<int>g[maxn];
int n, m;

int dp[maxn];
bool visited[maxn];
int result;

void dfs(int node) {
	visited[node] = true;
	for(int i:g[node]) {
		if(!visited[i]) {
			dfs(i);
		}
		dp[node] = max(dp[node], dp[i] + 1);
	}
	result = max(result, dp[node]);
}

int main() {
	cin>>n>>m;
	int a, b;
	for(int i=0;i<m;i++) {
		cin>>a>>b;
		g[a].pb(b);
	}

	for(int i=1;i<=n;i++) {
		if(!visited[i]) dfs(i);
	}
	cout<<result<<"\n";
}

Measured memory_bytes: 8192
package main

import (
	"bufio"
	"fmt"
	"os"
)

var scanner = bufio.NewScanner(os.Stdin)

func NextStr() string {
	scanner.Scan()
	return scanner.Text()
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	s, t := NextStr(), NextStr()
	var ans = 1001
	for i := 0; i < len(s)-len(t)+1; i++ {
		substr := s[i : len(t)+i]
		count := 0
		for j := 0; j < len(t); j++ {
			if substr[j] != t[j] {
				count++
			}
		}
		ans = min(ans, count)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <queue>

using namespace std;

int main(){
  string s;
  cin >> s;
  string S="";

  long n=0;
  long ans=0;
  for(long i=0; s[i] != '\0'; i++){
    n++;
  }
  for(long i=0; i<n; i++){
    if(s[i] == 'B' && i != n-1 && s[i+1] == 'C'){S += 'D';i++;}
    else S += s[i];
  }
  long adcount = 0;
  long dcount = 0;

  for(long i=0; S[i] != '\0'; i++){
    if(S[i] == 'A' || S[i] == 'D'){
      adcount++;
      if(S[i] == 'D'){
        dcount++;
        ans += adcount - dcount;
      }
    }
    else{
      adcount = 0;
      dcount=0;
    }
  }


  //cout << S << endl;
  cout << ans << endl;
}


Measured memory_bytes: 900
N = int(input())
A = [int(input()) for _ in range(N)]

count = 0
for i in range(N):
    if i == 0 and A[i] > 0:
        print(-1)
        exit()
    if A[i] == 0:
        continue
    else:
        if A[i] == (A[i-1] + 1):
            count += 1
        elif A[i] > A[i-1] + 1:
            print(-1)
            exit()
        else:
            count += A[i]

print(count)


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

int main(){
  int n,count=0,a;
  cin >> n;
  map<int,int> mp;
  r(i,n){
    cin >> a;
    mp[a]++;
  }
  for(auto it=mp.begin();it!=mp.end();it++){
    if((*it).first!=(*it).second){
      if((*it).second>(*it).first)count+=(*it).second-(*it).first;
      else count+=(*it).second;
    }
  }
  cout << count<<endl;
}


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

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

    vector<int> cost(N);
    vector<vector<int> > understand_rate(N, vector<int>(M));

    for (int i = 0; i < N; i++){
        cin >> cost[i];
        for (int j = 0; j < M; j++){
            cin >> understand_rate[i][j];
        }
    }

    //参考書の選択パターンの集合
    vector<int> passed_cost;
    for (int bit = 0; bit < (1<<N); bit++){//(1 << N) で 2 ^ N を表している
        vector<int> S;
        vector<int> rate(M);
        int payed = 0;

        for (int i = 0; i < N; i++){
            if(bit & (1<<i) ){//& : 両方のビットが 1のとき、 1となる
                S.push_back(i);
            }
        }

        // bit の表す集合の出力
        for (int i = 0; i < (int)S.size(); i++) {
            payed += cost[S[i]];
            for (int j = 0; j < M; j++){
                rate[j] += understand_rate[S[i]][j];
            }
        }

        int minElement = *std::min_element(rate.begin(), rate.end());
        if(minElement >= X){
            passed_cost.push_back(payed);
        }
    }

    if(passed_cost.empty()){
        cout << "-1" << endl;
    }else{
        int min_cost = *std::min_element(passed_cost.begin(), passed_cost.end());
        cout << min_cost << endl;
    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main(){
    FAST
    int h,n;
    cin>>h>>n;
    int a[n],b[n];
    for(int i=0;i<n;i++) cin>>a[i]>>b[i];
    int dp[h+1];
    for(int i=0;i<=h;i++) dp[i] = INT_MAX;
    dp[0] = 0;
    for(int i=1;i<=h;i++){
        for(int j=0;j<n;j++){
            dp[i] = min(dp[i],dp[max(0,i-a[j])]+b[j]);
        }
    }
    cout<<dp[h];
}

Measured memory_bytes: 256
'''
完全順列(derangement)
モンモール数(Montmort number)
'''

MOD = 10**9+7
N, M = map(int, input().split())

# 片方の順列の総数を求める
ans = 1
for i in range(N):
    ans *= M-i
    ans %= MOD

# M枚からN枚選ぶ完全順列を計算
d = [1, M-N]
for i in range(2, N+1):
    # 1がk番目にある
    # 1番目にkがある
    t = (i-1)*d[-2] % MOD
    # 1番目にkがない
    t += (M-N+i-1)*d[-1] % MOD
    d.append(t)

print(ans*d[-1] % MOD)


Measured memory_bytes: 102856
#include<stdio.h>
#include<string.h>
int H,W,i,j,sh,sw;
char P[30][30];

int dfs(int ph,int pw)
{
	int m[5]={0,1,0,-1,0},i,r=0;
	P[ph][pw]='#';
	for(i=0;i<4;i++)
	{
		if(P[ph+m[i]][pw+m[i+1]]=='.')
			r+=dfs(ph+m[i],pw+m[i+1])+1;
	}
	return r;
}

int main()
{
	for(;scanf("%d%d\n",&W,&H),H;)
	{
		memset(P,0,sizeof(P));
		for(i=1;i<=H;i++)
			for(j=1;j<=W+1;j++)
			{
				P[i][j]=getchar();
				if(P[i][j]=='@')sh=i,sw=j,P[i][j]='.';
			}
		printf("%d\n",dfs(sh,sw)+1);
	}
	return 0;
}

Measured memory_bytes: 636
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a,b,c) for(b=(c);b<(a);b++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline ll kaizyo(ll);
ll combination(ll, ll);
int main() {
	int n, k;
	cin >> n >> k;
	if (n%k == 0) {
		cout << 0;
	}
	else {
		cout << 1;
	}
	return 0;
}


inline ll kaizyo(ll x) {
	long ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}

Measured memory_bytes: 256
h,w = map(int,raw_input().split())
canv = [[] for i in range(h+2)]
canv[0]=canv[-1] = '.'*(w+2)
for i in range(1,h+1): # . input .
    canv[i] = '.' + raw_input() + '.'
noflag = False
for i in range(1,h+1):
    if noflag:
        break
    for j in range(1,w+1):
        if canv[i][j] == '#':
            if canv[i+1][j]+canv[i-1][j]+canv[i][j+1]+canv[i][j-1] == '....':
                noflag = True
if noflag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 2692
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
#define NN 9
using namespace std;
typedef long long ll;
typedef pair<vector<int>, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};
vector<int> start(NN);
vector<int> goal(NN);
int bfs()
{
    queue<P> que;
    map<vector<int>, int> mp;
    que.push(P(start, 0));
    mp[start] = 0;
    while(que.size())
    {
        P p = que.front();
        que.pop();
        vector<int> now = p.first;
        int res = p.second;
        if(now == goal) return res;
        int y, x, pos;
        for(int i = 0; i < NN; i++)
        {
            if(now[i] != 0) continue;
            x = i % 3;
            y = i / 3;
            pos = i;
        }
        res++;
        for(int i = 0; i < 4; i++)
        {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if(ny < 0 || nx < 0 || ny >= 3 || nx >= 3) continue;
            int idx = 3 * ny + nx;
            vector<int> next = now;
            swap(next[pos], next[idx]);
            if(mp.count(next) == 0 || mp[next] > res)
            {
                mp[next] = res;
                que.push(P(next, res));
            }
        }
    }
    return -1;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    for(int i = 0; i < NN; i++) 
    {
        cin >> start[i];
        goal[i] = (i + 1) % NN;
    }
    cout << bfs() << endl;
    return 0;
}




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

using namespace std;

int main() {
//    rotation
    string a;
    string b;

    cin >> a;
    cin >> b;

    int a_size = a.length();
    int b_size = b.length();

    if (a_size != b_size) {
        cout << "NO" << "\n";
    } else {
        string reverse_b;
        for (int i = b.length() - 1; i >= 0; --i) {
            reverse_b += b[i];
        }

        if (a == reverse_b) {
            cout << "YES" << "\n";
        } else {
            cout << "NO" << "\n";
        }

    }
    return 0;
}

Measured memory_bytes: 256
import sys,itertools as it
f=sys.stdin.readline
n=int(f())
ll=[]
for i in range(n):
    a=int(f())
    for _ in range(a):
        x,y=map(int,f().split())
        ll+=[(i,x-1,y)]
c=0
for p in it.product([0,1],repeat=n):
    if all(p[i]<1 or p[x]==y for i,x,y in ll):
        c=max(c,sum(p))
print(c)


Measured memory_bytes: 3064
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.call(in,out);
        out.close();
    }

    static class TaskA {
        public void call(InputReader in, PrintWriter out) {
            int n , a;
            n= in.nextInt();
            a = n%10;
            if(a==3)
                out.println("bon");
            else if(a==0||a==1||a==6||a==8)
                out.println("pon");
            else
                out.println("hon");




        }
    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }

    }
}

Measured memory_bytes: 32900
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B;
  cin >> A >> B;
  
  if(A >= 10){
    cout << -1 << endl;
  }
  else if(B >= 10){
    cout << -1 << endl;
  }
  else{
    cout << A*B << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
#define reps(i, S, E) for (ll i = (S); i <= (E); i++)
#define rep(i, N) reps(i, 0, N-1)
#define deps(i, E, S) for (ll i = (E); i >= (S); i--)
#define dep(i, N) deps(i, N-1, 0)
const ll MOD = 1000000007;
const ll INF = 1LL << 60;


//AtCoder Beginner Contest 133 - A B
int main() {
	ll N;
	scanf("%lld", &N);
	ll A;
	scanf("%lld", &A);
	ll B;
	scanf("%lld", &B);

	ll result = min(A * N, B);

	printf("%lld\n", result);
}

//AtCoder Beginner Contest 134 - A B
/*
int main() {
	ll N;
	scanf("%lld", &N);
	ll D;
	scanf("%lld", &D);

	ll result = (ll)ceil((double)N / (1 + D * 2));

	printf("%lld\n", result);
}
*/

/*
int main() {
	ll r;
	scanf("%lld", &r);

	ll result = 3 * r * r;

	printf("%lld\n", result);
}
*/

//AtCoder Beginner Contest 135 - B
/*
int main() {
	ll N;
	scanf("%lld", &N);
	vector<ll> p(N);
	for (ll i = 0; i < N; i++) {
		scanf("%lld", &p[i]);
	}

	ll err = 0;
	rep(i, N) {
		if (p[i] != i + 1) {
			err++;
		}
	}

	if (err <= 2) {
		printf("YES\n");
	}
	else {
		printf("NO\n");
	}
}
*/

//AtCoder Beginner Contest 135 - A
/*
int main() {
	ll A;
	scanf("%lld", &A);
	ll B;
	scanf("%lld", &B);

	if (abs(A - B) % 2 == 1) {
		printf("IMPOSSIBLE\n");
		return 0;
	}

	ll ans = abs(A - B) / 2;
	ll result = min(A, B) + ans;

	printf("%lld\n", result);
}
*/

//AtCoder Beginner Contest 126 - B
/*
int main() {
	char s[101010];
	scanf("%s", s);
	ll len = strlen(s);

	ll front = (s[0] - '0') * 10 + (s[1] - '0');
	ll back = (s[2] - '0') * 10 + (s[3] - '0');

	if ((front > 12 && back > 12) || (front > 12 && back == 0) || (back > 12 && front == 0) || (back == 0 && front == 0)) {
		printf("NA\n");
	}
	else if (front > 12 || front == 0) {
		printf("YYMM\n");
	}
	else if (back > 12 || back == 0) {
		printf("MMYY\n");
	}
	else {
		printf("AMBIGUOUS\n");
	}
}
*/

//AtCoder Beginner Contest 126 - A
/*
int main() {
	ll N;
	scanf("%lld", &N);
	ll K;
	scanf("%lld", &K);
	char s[101010];
	scanf("%s", s);
	ll len = strlen(s);

	s[K - 1] = s[K - 1] - 'A' + 'a';

	printf("%s\n", s);
}
*/

Measured memory_bytes: 256
n,m,b,a,t[100001],i;
int main(){
	for(scanf("%d%*d",&n);++i<n;t[i]=t[i-1]+a)scanf("%d",&a);
	for(;~scanf("%d",&a);m+=a,b%=100000)b+=abs(t[m]-t[m+a]);
	n=!printf("%d\n",b);
}

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

#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define mo 998244353
string str;
//map<int, int>::iterator itr; 
ull bin(ull a, ull n) {
    ull res = 1;
    while (n) {
        if (n & 1) res = 1LL * res * a % mo;
        a = 1LL * a * a % mo;
        n >>= 1;
    }
    return res;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;t=1;
    while(t--){
        ll n;cin>>n;
        ll arr[n];
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        ll a=205,b=1000,c=0,d=1000;
        for(int i=0;i<n;i++){
            if(arr[i]<a){
                if(i!=0)
                b+=a*c;
                c=b/arr[i];
                b=b%arr[i];
                a=arr[i];
            }
            else if(arr[i]>a){
                b+=arr[i]*c;
                d=max(b,d);
                c=b/arr[i];
                b=b%arr[i];
                a=arr[i];
            }
           // cout<<a<<" "<<b<<" "<<c<<"\n";
        }
        cout<<d;
        }
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  char a, b, c;
  in3(a, b, c);
  if(a == b && b == c)
    out("No");
  else
    out("Yes");
  memi;
}


Measured memory_bytes: 256
k, a, b = map(int, input().split())

if a >= b:
    print(k + 1)
else:
    d = b-a
    if k < a or d // 2 <= 1:
        print(k + 1)
    else:
        t = k - (a - 1)
        print(a + t//2 * d + t % 2)


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
	// your code goes here
	int n,k;
	cin>>n>>k;
	int a[n];
	rep(i,n)
	cin>>a[i];
	int dp[n];
	rep(i,n)
	dp[i]=INT_MAX;
	dp[0]=0;
	dp[1]=abs(a[1]-a[0]);
	
	for(int i=2;i<n;i++)
	{
	    for(int j=i-1;j>max(-1,i-1-k);j--)
	    dp[i]=min(dp[i],dp[j]+abs(a[i]-a[j]));
	}
	cout<<dp[n-1];
	return 0;
}


Measured memory_bytes: 1024
n, m = map(int, input().split())
ab = [map(int, input().split()) for _ in range(m)]

near = [set([]) for _ in range(n)]
for a, b in ab:
    near[a - 1].add(b - 1)
    near[b - 1].add(a - 1)

for i in near[0]:
    if i in near[n - 1]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')


Measured memory_bytes: 146036
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    long n;
    cin >> n;
    vector<int> l(n);
    vector<bool> m(n, false);
    for(long i = 0; i < n; i++){
        cin >> l[i];
        l[i]--;
    }
    long ans = 0, it = 0;
    while(true){
        m[it] = true;
        if(m[l[it]]){
            cout << "-1" << endl;
            break;
        }
        if(l[it] == 1){
            ans++;
            cout << ans << endl;
            break;
        }
        ans++;
        it = l[it];
    }
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int>A(N+1);
    for (int i = 0; i < N+1; ++i) {
      cin >> A[i];
    }
    vector<int>B(N);
    for (int i = 0; i < N; ++i) {
      cin >> B[i];
    }
    ll ans = 0;
    int rem = A[0];
    for (int i = 0; i < N; ++i) {
        if(B[i] <= rem){
            ans += B[i];
            rem = A[i+1];
        } else{
            ans += rem;
            B[i] -= rem;
            if(A[i+1] <= B[i]){
                ans += A[i+1];
                rem = 0;
            } else{
                ans += B[i];
                rem = A[i+1] - B[i];
            }
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
while True:
    a=0
    n,x=map(int,input().split())
    if(n==0 and x==0):
        break
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if(i+j+k==x):
                    a=a+1
                elif(n==0 and x==0):
                    print()
    print(a)


Measured memory_bytes: 5592
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iterator>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;

int main() {
    int n, k; cin >> n >> k;
    vector<long long> p(n);
    rep(i, n) cin >> p[i], ++p[i];

    vector<long long> s(n + 1, 0);
    rep(i, n) s[i + 1] = s[i] + p[i];

    long long res = 0;
    for (int i = 0; i + k <= n; i++) {
        res = max(res, s[i + k] - s[i]);
    }
    cout << fixed << setprecision(10)
         << static_cast<double>(res) / 2 << endl;
}


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

int main(){
  ll a,b,c;
  cin >>a >>b >>c;
  if(a+b+1>=c) cout << b+c << endl;
  else cout << b+(a+b+1) << endl;
  return 0;
}

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

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

    int f=0;
    for(int i=0;i<=25;i++)
    {
        for(int j=0;j<=14;j++)
        {
            int p=4*i+7*j;
                if(p==n)
                {
                    f=1;
                    break;
                }
        }
    }
    if(f)
    {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace test
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = ReadInt();
            var SP = new List<string[]>();
            for (int i = 0; i < N; i++)
            {
                var input = Read().Split(' ').ToArray();
                var S = input[0];
                var P = input[1];
                SP.Add(new string[] { S, P, (i + 1).ToString() });
            }
            SP = SP.OrderBy(sp => sp[0]).ThenByDescending(sp => int.Parse(sp[1])).ToList();
            foreach (var sp in SP) Console.WriteLine(sp[2]);

            Console.WriteLine();
            Console.ReadLine();
        }

        static string Read() { return Console.ReadLine(); }
        static int ReadInt() { return int.Parse(Read()); }
        static long ReadLong() { return long.Parse(Read()); }
        static int[] ReadArrayInt() { return Read().Split(' ').Select(s => int.Parse(s)).ToArray(); }
        static long[] ReadArrayLong() { return Read().Split(' ').Select(s => long.Parse(s)).ToArray(); }
    }
}

Measured memory_bytes: 13664
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define MOD2 100000000
#define ll long long
#define pb push_back
#define mp make_pair
#define x first
#define y second
#define all(v) v.begin(),v.end()
ll mod=MOD;
using namespace std;
long long int fast_exp(long long int base,long long int ex) {
    long long int res=1;
    while(ex>0) {
       if(ex%2==1) res=(res*base)%mod;
       base=(base*base)%mod;
       ex/=2;
    }
    return res%mod;
}
long long int gcd(long long int a, long long int b)
{
    if(b==0)return a;
     return gcd(b,a%b);
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k; cin>>n>>k;
    ll h[n];
    ll ans[200000];
    memset(ans,0,sizeof(ans));
    for(int i=0;i<n;i++)
    {
        cin>>h[i];
        ans[i]=1e18;
    }
    for(int i=n;i<n+k;i++)
    {
        ans[i]=1e18;
    }
    ans[0]=0;
    for(int i=0;i<n;i++)
    {
        for(int j=1;j<=k;j++)
            ans[i+j]=min(ans[i+j],ans[i]+abs(h[i+j]-h[i]));
    }
    cout<<ans[n-1]<<"\n";
    return 0;
}


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

bool isTriangle(int a, int b, int c)
{
	return a != b && a != c && b != c && 
		a + b > c && b + c > a && c + a > b;
}

int main()
{
	int n, L[101];
	cin >> n;
	for (int i = 0; i < n; ++i)
		cin >> L[i];
	int c = 0;
	for (int i = 0; i < n - 2; ++i)
		for (int j = i + 1; j < n - 1; ++j)
			for (int k = j + 1; k < n; ++k)
				if (isTriangle(L[i], L[j], L[k]))
					c++;
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 3600
n,m=map(int,input().split())
ks=[list(map(int,input().split())) for _ in range(m)]
ps=list(map(int,input().split()))
ans=0
for i in range(2**n):
  cnt=0
  os=[0]*n
  pos=0
  while i!=0:
    if i%2==1:
      os[pos]=1
      i-=1
    i=i//2
    pos+=1
  for j in range(m):
    tmp=0
    for k in range(ks[j][0]):
      if os[ks[j][1+k]-1]==1:
        tmp+=1
    if tmp%2==ps[j]:
      cnt+=1
  if cnt==m:
    ans+=1
print(ans)

Measured memory_bytes: 3188