akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
using namespace std;

signed main(){
  int a,b,c;
  cin>>a>>b>>c;
  if(a-b==b-c)
    cout<<"YES"<<endl;
  else
    cout<<"NO"<<endl;
}


Measured memory_bytes: 256
#if 1
#define _CRT_SECURE_NO_WARNINGS
#include <functional>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cstdlib>
#include <cassert>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <list>
#include <unordered_map>

using namespace std;

typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;

const LD eps = 1e-9;
const LD pi = acos(-1.0);
const LL inf = 1e+9;

#define mp make_pair
#define pb push_back
#define X first
#define Y second

#define dbg(x) { cerr << #x << " = " << x << endl; }

// extended template
#pragma comment(linker, "/STACK:36777216")
typedef vector<int> vi;
typedef vector<vi> vvi;

#define forn(i, n) for (int i = 0; i < n; ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

template<typename T> istream & operator >> (istream &, vector<T> &);
template<typename T> ostream & operator << (ostream &, const vector<T> &);

#define START clock_t _clock = clock();
#define END cerr << endl << "time: " << (clock() - _clock) / LD(CLOCKS_PER_SEC) << endl;

#define NAME "angle1"


void solve()
{
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for (int i = 0; i < n; i++)
		cin >> a[i];

	cout << ((n - 1) + (k - 2)) / (k - 1) << endl;
	
}

int main()
{

	//START
	//freopen(NAME ".in", "r", stdin); freopen(NAME ".out", "w", stdout);
	//freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout);
	solve();


	//END		 
	return 0;
}
/*******************************************
*******************************************/

template<typename T> istream & operator >> (istream &is, vector<T> &v)
{
	forn(i, v.size())
		is >> v[i];
	return is;
}
template<typename T> ostream & operator << (ostream &os, const vector<T> &v)
{
	forn(i, v.size())
		os << v[i] << " ";
	return os;
}
#endif

Measured memory_bytes: 640
#include "bits/stdc++.h"

using namespace std;

#define  f first
#define  lgn 25
#define  endl '\n'
#define  sc second
#define  N (int)2e5+5
#define  sz(x) x.size()
#define  ll long long int
#define  ld long double
#define  vi vector<int>
#define  vl vector<ll>
#define  vs vector<string>
#define  vc vector<char>
#define  mii map<int,int>
#define  mll map<ll,ll>
#define  pii pair<int,int>
#define  pll pair<ll,ll>
#define  vpll vector<pll>
#define  vpii vector<pii>
#define  test(x) while(x--)
#define  pb push_back
#define  eb emplace_back
#define  pq priority_queue
#define  mod 1000000007
#define  fo(i,a,n) for(int i=a;i<n;i++)
#define  rfo(i,n,a) for(int i=n;i>=a;i--)
#define  mst(a,v,n) fo(i,0,n) a[i]=v
#define  all(x) sort(begin(x),end(x))
#define  allr(x) sort(rbegin(x),rend(x))
#define  rev(x) reverse(begin(x),end(x))
#define  db(x) cout<<#x <<" : "<< x <<endl;
#define  tie ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"

const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;



void go()
{
	string a,b;
	cin>>a>>b;
	int cn=0;
	fo(i,0,3)
	{
		if(a[i]==b[i]) cn++;
	}
	cout<<cn<<endl;
}

int32_t main()
{
	tie; int t=1; 
	// cin>>t;
	test(t) go();
}

Measured memory_bytes: 256
n,k = map(int,input().split())
mod = 1000000007

memo = []
for i in range(0,n+1):
    memo.append(i)

shou = sum(memo[:k-1])
dai = sum(memo[n-k+2:])

ans = 1
for i in range(k-1,n):
    dai += memo[-i-1]
    shou += memo[i]
    ans += dai-shou+1
    ans = ans%mod
    #print(ans)
print(ans)

Measured memory_bytes: 81148
#include<iostream>
using namespace std;
int main(){
  int h,w;
  cin >> h >> w;
  string str[h];
  for(int i=0;i<h;i++){
    cin >> str[i];
  }
  bool can = true;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(str[i][j] =='#'){
        if((i != 0 && str[i-1][j] == '#') || (i != h-1 && str[i+1][j] == '#') || (
        j != 0 && str[i][j-1] == '#') || (j != w-1 && str[i][j+1] == '#')){
          continue;

        }else{
          can = false;
        }
      }
    }
  }
  if(can){
    cout<< "Yes";
  }else{
    cout << "No";
  }
}


Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    a, b, x = map(int, input().split())

    res_a = (a - 1) // x
    res_b = b // x
    print(res_b - res_a)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
from itertools import product
N, M, X = map(int, input().split())
C = []
A = [[] for _ in range(N)]
for i in range(N):
    inp = list(map(int, input().split()))
    c, a = inp[0], inp[1:]
    C.append(c)
    A[i] = a


ans = float('inf')
for pattern in product([0, 1], repeat=N):
    ms = [0] * M
    tmp_ans = 0

    for i, p in enumerate(pattern):
        if p == 0:
            continue
        tmp_ans += C[i]
        for j, a in enumerate(A[i]):
            ms[j] += a

    if all([m >= X for m in ms]):
        ans = min(ans, tmp_ans)

if ans == float('inf'):
    print(-1)
else:
    print(ans)


Measured memory_bytes: 9144
import sys
input = sys.stdin.readline
import math

MOD = 10**9+7
N = int(input())
F = []
zero_v = 0
inf = 0
zero = 0
for _ in range(N):
  x,y = map(int,input().split())
  if x==0 and y==0:
    zero_v += 1
  elif x==0:
    inf += 1
  elif y==0:
    zero += 1
  else:
    G = math.gcd(abs(x),abs(y))
    F.append((x//G,y//G))

all_keys = set()

for x,y in F:
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))
  x,y = -y,x
  if x*y >0:
    if x>0:
      all_keys.add((x,y))
    else:
      all_keys.add((-x,-y))

all_dic = {k:[0,0] for k in all_keys}

for x,y in F:
  if x*y > 0:
    if x>0:
      all_dic[(x,y)][0] += 1
    else:
      all_dic[(-x,-y)][0] += 1
  else:
    if x>0:
      all_dic[(-y,x)][1] += 1
    else:
      all_dic[(y,-x)][1] += 1

ans = (pow(2,inf,MOD)) + (pow(2,zero,MOD))-1
ans %= MOD

for k in all_keys:
  P,N = all_dic[k]
  ans *= (pow(2,P,MOD)) + (pow(2,N,MOD))-1
  ans %= MOD


ans += zero_v-1

print(ans%MOD)


Measured memory_bytes: 162468
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    int a,b,k; cin >> a >> b >> k;
    ll ans=100;

    while(1){
        if(a%ans==0 and b%ans==0) k--;
        if(k==0) break;
        ans--;
    }

    cout << ans << endl;


    return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int gcd(int x , int y) {
    int r;
    
    while(y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main(void)
{
    int x , y;
    int i;
    int temp;
        
        scanf("%d %d" , &x , &y);
        if(x < y) {
            temp = y;
            y = x;
            x = temp;
        }
    
    printf("%d\n" , gcd(x , y));
    
    return 0;
}



Measured memory_bytes: 2124
#include <iostream>
using namespace std;
long long gcd(long long x,long long y){
  if (x%y == 0) return(y);
  else  return(gcd(y, x%y));
}
long long lcm(long long x,long long y){
  return x*y/gcd(x,y);
}
int main(){
  long long a,b,c,d;
  cin >> a >> b >> c >> d;
  cout << b-(a-1)-b/c+(a-1)/c-b/d+(a-1)/d+b/lcm(c,d)-(a-1)/lcm(c,d) << "\n";
  return 0;
}

Measured memory_bytes: 3632
#include<iostream>
#include<unordered_map>
#include<algorithm>
#include<vector>
#include<string>
#include<string.h>


using namespace std;


void addEdge(vector<pair<int,int> >*adjList,int u, int v, int w)
{
    adjList[u].push_back(pair<int, int>(v, w));
    adjList[v].push_back(pair<int, int>(u, w));

}

void printGraph(vector<pair<int, int> >* adjList,int V)
{
    vector<pair<int, int> >::iterator itr;
    int i;
    for (i = 0; i < V; ++i) {
        cout << i << "->";
        for (itr = adjList[i].begin(); itr != adjList[i].end(); ++itr) {
            cout << itr->first << "," << itr->second << " ";
        }
        cout << "\n";
    }
}



int main()
{
    int n;
    string str;
    cin >> n >> str;
    int i,x=0,max=0;
    for (i = 0; i < n; ++i) {
        if (str[i] == 'I') {
            ++x;
        }
        else if (str[i] == 'D') {
            --x;
        }
        if (x > max) {
            max = x;
        }
    }
    cout << max;
   
    
}

    




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

int main() {
  string s, t;
  cin >> s >> t;
  ll n = s.length();
  ll m = t.length();
  ll dp[n+1][m+1];
  memset(dp, 0, sizeof(dp));
  for(ll x = 1; x <= n; x++) {
  	for(ll y = 1; y <= m; y++) {
      if(s[x-1] == t[y-1]) {
      	dp[x][y] = 1 + dp[x-1][y-1];
      }
      else {
      	dp[x][y] = max(dp[x-1][y], dp[x][y-1]);
      }
    }
  }
  string ans = "";
  ll x = n;
  ll y = m;
  while(x > 0 && y > 0) {
    if(s[x-1] == t[y-1]) {
      ans = s[x-1] + ans;
      x--;
      y--;
    }
    else {
      if(dp[x-1][y] > dp[x][y-1]) {
      	x--;
      }
      else {
      	y--;
      }
    }
  }
  cout << ans;
}

Measured memory_bytes: 74012
#pragma GCC optimize("O3") //コンパイラ最適化用

#define _GLIBCXX_DEBUG //配列に[]でアクセス時のエラー表示
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// forループ関係
//引数は、(ループ内変数,動く範囲)か(ループ内変数,始めの数,終わりの数)、のどちらか
// Dがついてないものはループ変数は1ずつインクリメントされ、Dがついてるものはメントされる
#define REP(i, n) for (ll i = 0; i < ll(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--) //ループ変数は1ずつデクリ
#define FOR(i, a, b) for (ll i = a; i < ll(b); i++)
#define FORD(i, a, b) for (ll i = a; i > ll(b); i--) //ループ変数は1ずつデクリ
// xにはvectorなどのコンテナ
#define ALL(x) x.begin(), x.end() // sortなどの引数を省略したい
#define SIZE(x) ll(x.size())      // sizeをsize_tからllに直しておく
//定数
#define INF 1000000000000 // 10^12:極めて大きい値,∞
#define MOD 1000000007    // 10^9+7:合同式の法
#define MAXR 100000 // 10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back // vectorヘの挿入
#define MP make_pair // pairのコンストラクタ
#define F first      // pairの一つ目の要素
#define S second     // pairの二つ目の要素
#define Umap unordered_map
#define Uset unordered_set
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000

int main() {
    ll n;
    cin >> n;
    vector<ll> A(n);
    REP(i, n) { cin >> A.at(i); }
    ll a = 0;
    ll b = 0;

    sort(ALL(A));
    reverse(ALL(A));
    REP(i, n) {
        if (i % 2 == 0) {
            a += A[i];
        } else {
            b += A[i];
        }
    }
    cout << a - b << endl;
}


Measured memory_bytes: 3688
import java.util.*;

public class Main {

    private static int mod = 1000000007;
    private static int[][] c;

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);
        char[] c = sc.next().toCharArray();
        int n = c.length;
        int[] res = new int[n];

        int pos = 0;
        while(pos < n) {
            int start = pos;
            int rmax = pos;
            while(c[pos] == 'R') {
                rmax = pos;
                pos++;
            }
            int lmin = pos;
            int end = pos;
            while(pos < n && c[pos] == 'L') {
                end = pos;
                pos++;
            }
            for(int i=start; i<=end; i++)  {
                if(i % 2 == rmax % 2) {
                    res[rmax]++;
                } else {
                    res[lmin]++;
                }
            }
        }
        System.out.print(res[0]);
        for(int i=1; i<n; i++) {
            System.out.print(" ");
            System.out.print(res[i]);
        }
    }

}


Measured memory_bytes: 54800
import java.util.*;

public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int K = sc.nextInt();
        sc.close();
        int give=0;
        for (int i = 0; i < K; i ++) {
            if (i%2 == 0) {
            if(A%2 == 1)A--;
            give = A/2;
            B += give;
            A -= give;
            }else {
            if(B%2 == 1)B--;
            give = B/2;
            A += give;
            B -= give;
            }
        }
        System.out.println(A + " " + B);
    }
}

Measured memory_bytes: 24020
#include<stdio.h>
int main()
{
	char S[100];
	
	scanf("%s", S);
	int judge = 0;
	int k;
	
	for(k=0; k<100; k++){
		if( k % 2 == 0 && S[k] == 'L'){
			judge++;
			break;
		}
		
		else if (k % 2 == 1 && S[k] == 'R'){
			judge++;
			break;
		}
		
	}
	
	if(judge > 0) printf("No");		
	else printf("Yes");
	
	return 0;
}

Measured memory_bytes: 128
/*********************************************************************************************/
/**                                                                                          //
//                            _ooOoo_                                                        //
//                           o8888888o                                                       //
//                           88" . "88                                                       //
//                           (| -_- |)                                                       //
//                            O\ = /O                                                        //
//                        ____/`---'\____                                                    //
//                      .   ' \\| |// `.                                                     //
//                       / \\||| : |||// \                                                   //
//                     / _||||| -:- |||||- \                                                 //
//                       | | \\\ - /// | |                                                   //
//                     | \_| ''\---/'' | |                                                   //
//                      \ .-\__ `-` ___/-. /                                                 //
//                   ___`. .' /--.--\ `. . __                                                //
//                ."" '< `.___\_<|>_/___.' >'"".                                             //
//               | | : `- \`.;`\ _ /`;.`/ - ` : | |                                          //
//                 \ \ `-. \_ __\ /__ _/ .-` / /                                             //
//         ======`-.____`-.___\_____/___.-`____.-'======                                     //
//                            `=---='                                                        //
//                                                       //                                  //
//         .............................................                                     //
//                  佛祖保佑             永无BUG                                            //
********************************************************************************************/
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#include<stack>
using namespace std;
const int mod=1000000009;
int vis[10000];
int main()
{
    string s;
    string s1;
    int len=0;
    cin>>s;
    stack<int> st;
    int a[100000];
    for(int i=0;i<s.size();i++)
    {
        if(s[i]=='0')
            st.push(0);
        if(s[i]=='1')
            st.push(1);
        if(s[i]=='B'&&!st.empty())
            st.pop();
    }
    while(!st.empty())
    {
        a[len++]=st.top();
        st.pop();
    }
    for(int i=len-1;i>=0;i--)
        printf("%d",a[i]);
}


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

int main() {
  int N;
  cin >> N;
  vector<int>point(N);
  for(int i=0; i<N; i++)
    cin >> point.at(i);
  int A = 0;
  int B = 0;
  int x =0;
  for(int j=0; j<N/2+1; j++){
    for (int i=0; i<N; i++){
      if(point.at(i) > x){
        x = point.at(i);
        continue;
      }
      else
        continue;
    }
    A = A+x;
    for (int i=0; i<N; i++){
      if(point.at(i) == x){
        point.at(i) =0;
        x =0;
        break;
      }
      else
        continue;
    }
    for (int i=0; i<N; i++){
      if(point.at(i) > x){
        x = point.at(i);
        continue;
      }
      else
        continue;
    }
    B = B+x;
    for (int i=0; i<N; i++){
      if(point.at(i) == x){
        point.at(i) =0;
        x =0;
        break;
      }
      else
        continue;
    }
  }
  cout << A-B << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
bool mincut(vector<int> &a,double x,int k)
{
	int k1;
  	for(auto y:a)
    {
      k1 = ceil(y/(x)) -1;
      if(round(y/(k1+1)) > x)
        k1++;
      k-=k1;
    }
  return k>=0;
}
int main()
{
  long long int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++)
    cin>>v[i];
  long long int l=0,r=1000000001,m;
  while(l<r-1)
  {
    m = l+(r-l)/2;
    if(mincut(v,m,k))
      r = m;
    else
    {
      l = m;
    }
  }
  cout<<r;
  return 0;
}

Measured memory_bytes: 4052
#include<iostream>
#include<map>
#include<algorithm>
#include<cmath>
#include<vector>
#include<iomanip>
typedef long long ll;
ll inf = 1e9;
using namespace std;
ll dp[100005];
ll h[100005];
int main() {
	int h,w ,n;
	cin >> h >>w>>n;
	int kai;
	kai = max(h, w);
	if (n < kai) {
		cout << "1" << endl;
		return 0;
	}
	if (n % kai == 0) {
		cout << n / kai << endl;
	}
	else {
		cout << n/ kai+1 << endl;
	}
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const int MAX = 510000;

ll fac[MAX], finv[MAX], inv[MAX];

void combinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAX; ++i){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD-inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1]*inv[i] % MOD;
    }
}


ll com(int n, int k){
    if(n < k) return 0;
    if(n < 0 or k < 0) return 0;
    return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    combinit();
    ll n;
    cin >> n;
    set<ll> num;
    ll dup;
    ll l, r;
    vector<ll> a(n+1);
    for(int i = 0; i <= n; ++i) {
        scanf("%lld", &a[i]);
        if(!num.insert(a[i]).second) dup = a[i], r = i;
    }
    for(int i = 0; i <= n; ++i){
        if(a[i] == dup){
            l = i; break;
        }
    }
    for(int i = 1; i <= n+1; ++i){
        printf("%lld\n", (com(n+1, i)-com(n+l-r, i-1)+MOD)%MOD);
    }



    return 0;
}


Measured memory_bytes: 18688
/*
* Problem link
* 
*/

#include<bits/stdc++.h>
using namespace std;

struct INIT{INIT(){std::cin.tie(0);ios_base::sync_with_stdio(false);} }init;

struct edge {
	int to, cost;
	bool operator<(const edge& o)const {
		return cost < o.cost;
	}
	bool operator>(const edge& o)const {
		return cost > o.cost;
	}
};
typedef vector<edge> E;
typedef vector<E> Graph;

struct node {
	E rootpath;
	E cmaxpath;
	void sort() {
		std::sort(rootpath.begin(), rootpath.end(), greater<edge>());
		std::sort(cmaxpath.begin(), cmaxpath.end(), greater<edge>());
	}
	void resize() {
		if (rootpath.size()>3u)rootpath.resize(3);
		if (cmaxpath.size()>2u)cmaxpath.resize(2);
	}
	int get_subtree_path(){
		return max(cmaxpath[0].cost,rootpath[0].cost + rootpath[1].cost);
	}
};

/*??¨????§????*/
void make_tree(int v, Graph &G, E &P, Graph &C) {
	for (auto& e : G[v]) {
		if (e.to != P[v].to) {
			C[v].push_back(e);
			P[e.to] = edge{ v,e.cost };
			make_tree(e.to, G, P, C);
		}
	}
}
void dfs(int v,Graph &C,vector<node>& V) {
	V[v].rootpath.push_back(edge{ v,0 });
	V[v].rootpath.push_back(edge{ v,0 });
	V[v].cmaxpath.push_back(edge{ v,0 });
	for (auto &e : C[v]) {
		dfs(e.to, C, V);
		V[v].rootpath.push_back(edge{ e.to,V[e.to].rootpath[0].cost + e.cost });
		V[v].cmaxpath.push_back(edge{ e.to,V[e.to].get_subtree_path()});
	}
	V[v].sort();
	//V[v].resize();
	return;
}
int solve(int v,Graph &C,vector<node> &V,int ppath,int plen) {
	int res = 0;
	for (auto& e : C[v]) {
		res = max(res, e.cost + V[e.to].get_subtree_path());
		int cpath = 0;
		int path = 0;
		if (V[v].rootpath[0].to == e.to) {
			cpath = max(V[v].rootpath[1].cost + V[v].rootpath[2].cost, V[v].rootpath[1].cost + ppath);
			path = max(V[v].rootpath[1].cost, ppath);
		}
		else {
			if(V[v].rootpath[1].to==e.to)
				cpath = max(V[v].rootpath[0].cost + V[v].rootpath[2].cost, V[v].rootpath[0].cost + ppath);
			else
				cpath = max(V[v].rootpath[0].cost + V[v].rootpath[1].cost, V[v].rootpath[0].cost + ppath);
			path = max(V[v].rootpath[0].cost, ppath);
		}
		if (V[v].cmaxpath[0].to == e.to)
			cpath = max(V[v].cmaxpath[1].cost, cpath);
		else
			cpath = max(V[v].cmaxpath[0].cost, cpath);
		cpath = max(path, cpath);
		cpath = max(cpath, plen);
		res = max(res, e.cost + cpath);
		res = max(res, solve(e.to, C, V, path + e.cost, cpath));
	}
	return res;
}

int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	int N;
	cin >> N;
	Graph G(N),child(N);
	E par(N, edge{ -1,-1 });
	vector<node> V(N);
	for (int i = 1; i < N; i++) {
		int p, w;
		cin >> p >> w;
		G[i].push_back(edge{ p,w });
		G[p].push_back(edge{ i,w });
	}
	par[0] = edge{ 0,0 };
	make_tree(0, G, par, child);
	dfs(0, child, V);
	cout << max(V[0].get_subtree_path(),solve(0, child, V, 0, 0)) << endl;
	return 0;
}

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

int main(){
    string s;
    cin >> s;
    if(s == "RRR") cout << 3 << endl;
    else if(s == "RRS" || s == "SRR") cout << 2 << endl;
    else if(s == "SSS") cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ld=long double;
using st=string;
using ch=char;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<P> vP;
typedef vector<ch> vc;
typedef vector<vc> vvc;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
#define ROF(i,a,b) for(ll i=a;i>=b;i--)
#define per(i,a) ROF(i,a,0)
const ll MOD=1000000007;
const ll MOD2=998244353;
const ld PI=acos(-1);
const ll INF=1e18;
st abc="abcdefghijklmnopqrstuvwxyz";
st ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

const ll MXN=100005;
vector<edge> G[MXN];
vector<bool> B(MXN,false);
vl ans(MXN);

void bfs(ll x,ll d){
  B[x]=true;
  ans[x]=d;
  ll k=G[x].size();
  rep(i,k){
    if(B[G[x][i].to]==false){
      bfs(G[x][i].to,G[x][i].cost+d);
    }
  }
}

  
int main() {
  ll N;
  cin >> N;
  rep(i,N-1){
    ll a,b,c;
    cin >> a >> b >> c;
    a--;b--;
    G[a].push_back({b,c});
    G[b].push_back({a,c});
  }
  ll Q,K;
  cin >> Q >> K;
  K--;
  bfs(K,0);
  rep(i,Q){
    ll x,y;
    cin >> x >> y;
    x--;y--;
    printf("%lld\n",ans[x]+ans[y]);
  }
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
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;
}


int main(){
    ll h,w,m;cin >> h >> w >> m;
    vl r(w),c(h);vpl it(m);
    rep(i,m){
        ll a,b;cin >> a >> b;a--;b--;
        it[i]={a,b};r[b]++;c[a]++;
    }
    set<ll> rr,cc;
    ll ans=0,p=0;
    rep(i,w)chmax(ans,r[i]);
    rep(i,w)if(ans==r[i])rr.ins(i);
    rep(i,h)chmax(p,c[i]);
    rep(i,h)if(p==c[i])cc.insert(i);
    ll cnt=0;
    rep(i,m){
        if(rr.count(it[i].se)&&cc.count(it[i].fi))cnt++;
    }
    if(cnt==rr.size()*cc.size())cout << ans+p-1 <<endl;
    else cout << ans+p <<endl;
}

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

using namespace std;
int main()
{
	int n;
	cin >> n;
	string s = to_string(n);
	if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[3] == s[2])) {
		cout << "Yes";
	}
	else cout << "No";
    return 0;
}

Measured memory_bytes: 256
from collections import deque

N,M = map(int,input().split())

xy = []

dic = {}
pnum = [0] * N

for i in range(M):

    x,y = map(int,input().split())
    x -= 1
    y -= 1

    if x not in dic:
        dic[x] = []

    dic[x].append(y)
    pnum[y] += 1

q = deque([])
dp = [0] * N

for i in range(N):

    if pnum[i] == 0:
        q.append(i)

#print (q)
#print (dic)

while len(q) > 0:

    now = q.popleft()

    if now not in dic:
        continue

    for i in dic[now]:

        if dp[i] < dp[now] + 1:
            dp[i] = dp[now] + 1

        pnum[i] -= 1
        if pnum[i] == 0:
            q.append(i)


print (max(dp))


Measured memory_bytes: 66904
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int N;
int main(){
  int i, j;
  rd(N);
  for(i=0;i<=N;i+=4){
    if((N-i)%7==0){
      break;
    }
  }
  if(i<=N){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N;
// {
//   int i, j;
//   rd(N);
//   for(i=0;i<=N;i+=4) if((N-i)%7==0) break;
//   wt( if[i<=N, "Yes", "No"] );
// }


Measured memory_bytes: 256
// You Are the Judge(審判は君だ！)
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2400&lang=jp
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type Team struct {
	TID         int
	Accepted    int
	WrongAnswer map[int]int
	Penalty     int
}

type Teams []Team

func (t Teams) Len() int      { return len(t) }
func (t Teams) Swap(i, j int) { t[i], t[j] = t[j], t[i] }
func (t Teams) Less(i, j int) bool {
	// より多くの問題を解いたチームは順位が上になる
	if t[i].Accepted > t[j].Accepted {
		return true
	} else if t[i].Accepted == t[j].Accepted {
		// 解いた問題が同じ場合、ペナルティの少ないチームのほうが順位が上になる
		if t[i].Penalty < t[j].Penalty {
			return true
		} else if t[i].Penalty == t[j].Penalty {
			// 解いた問題もペナルティも同じ場合、チーム番号が小さいほうのチームが順位が上になる
			if t[i].TID < t[j].TID {
				return true
			}
		}
	}
	return false
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	for {
		t, p, r := nextInt(sc), nextInt(sc), nextInt(sc)
		if t == 0 && p == 0 && r == 0 {
			break
		}

		teams := []Team{}
		for tID := 0; tID < t; tID++ {
			teams = append(teams, Team{tID + 1, 0, map[int]int{}, 0})
		}

		for i := 0; i < r; i++ {
			tID, pID, time, message := nextInt(sc), nextInt(sc), nextInt(sc), nextString(sc)
			tID--

			if message == "CORRECT" {
				teams[tID].Accepted++
				wa, _ := teams[tID].WrongAnswer[pID]
				teams[tID].Penalty += wa*1200 + time
			} else {
				teams[tID].WrongAnswer[pID]++
			}
		}

		sort.Sort(Teams(teams))

		for _, team := range teams {
			fmt.Println(team.TID, team.Accepted, team.Penalty)
		}
	}
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define all(v) v.begin(),v.end()
#define PI acos(-1)
#define EPS 1e-15



int main() {
	int n;
	cin >> n;
	vector<int> s;
	int i = 10;
	while(n){
		s.pb(n%i);
		n /= 10;
	}
	if((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}






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

class Main {
 	public static void main(String arhgs[]) throws IOException {
     	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      	StringTokenizer st = new StringTokenizer(br.readLine());
      	int N = Integer.parseInt(st.nextToken());
      	int M = Integer.parseInt(st.nextToken());
      	st = new StringTokenizer(br.readLine());
      	int[] arr = new int[N];
      	int i = 0;
      	while(st.hasMoreTokens()) {
         	 arr[i++] = Integer.parseInt(st.nextToken());
        }
      	Pair[] pairs = new Pair[M];
      	for(int j=0;j<M;j++) {
         	st = new StringTokenizer(br.readLine());
          	Pair p = new Pair();
          	p.setKey(Integer.parseInt(st.nextToken()));
          	p.setValue(Integer.parseInt(st.nextToken()));
          	pairs[j] = p;
        }
      	Arrays.sort(arr);
      	Arrays.sort(pairs);
      	long ans = 0;
      	for(int m=0,n=0;m<arr.length || n<pairs.length ; m++) {
			if(m == arr.length)
				break;
			Pair pp = null;
			int count = 0;
			int value = 0;
			if(n<pairs.length) {
				pp = pairs[n];
				count = pp.getKey();
				value = pp.getValue();
			}
          	if(arr[m] < value) {
              if(count > 0) {
				ans += value;
                count--;
                pp.setKey(count);
                pairs[n] = pp;
              } else {
                n++;
                m--;
              }
            }  else {
              ans += arr[m];
            }
        }
      	System.out.println(ans);
    }
}
          
class Pair implements Comparable<Pair>{
 	int key;
  	int value;
  	public void setKey(int key) {
     	this.key = key; 
    }
  	public void setValue(int value) {
     	this.value = value; 
    }
  	public int getKey() {
     	return this.key; 
    }
  	public int getValue() {
     	return this.value; 
    }
  	
  	public int compareTo(Pair pp) {
     	 return Integer.compare(pp.getValue(), this.value);
    }
}


Measured memory_bytes: 47200
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    ll h, w; cin >> h >> w;
    string skip = string(w, '.');
    vector<bool> iSkip(h, false);
    vector<bool> jSkip(w, false);
    vector<string> a(h);
    
    // 行が全て白じゃないかチェック
    rep(i, h){
        cin >> a[i];
        if(a[i] == skip) iSkip[i] = true;
    }

    // 列が全て白じゃないかチェック
    rep(j, w){
        bool tmp = true;
        rep(i, h){
            if(a[i][j] == '#'){
                tmp = false;
                break;
            }
        }
        if(tmp) jSkip[j] = true;
    }

    // 白のマスを詰めて出力
    rep(i, h){
        if(iSkip[i] == true) continue;
        rep(j, w){
            if(jSkip[j] == true) continue;
            cout << a[i][j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

int main(void) {
  int N, M;

  std::cin >> N >> M;
  std::vector<int> town(N, 0);
  for (int i = 0; i < M; ++i) {
    int t1, t2;
    std::cin >> t1 >> t2;
    town[t1-1]++;
    town[t2-1]++;
  }

  for (int i = 0; i < N; ++i) {
    std::cout << town[i] << std::endl;
  }

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int n;
    scanf("%d", &n);
    int a[200000] = {};
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    int amin = a[0];
    int ans = 0;
    for (int i = 0; i < n; i++) {
        if (amin >= a[i]) {
            amin = a[i];
            ans++;
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main() {
    int N;
    cin >> N;
    int k = N%10;
    if(k == 2 || k == 4 || k == 5 || k == 7 || k == 9) {
        cout << "hon" << endl;
    }
    else if(k == 0 || k == 1 || k == 6 || k == 8) {
        cout << "pon" << endl;
    }
    else cout << "bon" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
using namespace std;
typedef long long ll;
ll n;
main(){
	register int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		ll x;
		cin>>x;
		if(x%2==0){
			if(x%3==0||x%5==0);
			else{
				cout<<"DENIED"<<endl;
				return 0;
			}
		}
	}
	cout<<"APPROVED"<<endl;
	return 0;
}

Measured memory_bytes: 256
//clear adj and visited vector declared globally after each test case
//check for long long overflow
//while adding and subs check if mod becomes -ve
//while using an integer directly in a builtin function add ll
//Mod wale question mein last mein if dalo ie. Ans<0 then ans+=mod;
//Dont keep array name as size or any other key word

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define int long long
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);cout.precision(dbl::max_digits10);
#define pb push_back
#define mod 1000000007 //998244353
#define lld long double
#define mii map<int, int>
#define mci map<char, int>
#define msi map<string, int>
#define pii pair<int, int>
#define ff first
#define ss second 
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=x; i<y; i++)    
#define fill(a,b) memset(a, b, sizeof(a))
#define vi vector<int>
#define setbits(x) __builtin_popcountll(x)
#define print2d(dp,n,m) for(int i=0;i<=n;i++){for(int j=0;j<=m;j++)cout<<dp[i][j]<<" ";cout<<"\n";}
typedef std::numeric_limits< double > dbl;
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const long long N=100005, INF=2000000000000000000;
lld pi=3.1415926535897932;
int lcm(int a, int b)
{
    int g=__gcd(a, b);
    return a/g*b;
}
int power(int a, int b, int p)
    {
        if(a==0)
        return 0;
        int res=1;
        a%=p;
        while(b>0)
        {
            if(b&1)
            res=(res*a)%p;
            b>>=1;
            a=(a*a)%p;
        }
        return res;
    }
vector <int> v[N], temp;
int ch[N],n;
void dfs(int u, int p)
{
    ch[u]=1;
    for(auto to:v[u])
    {
        if(to==p)
        continue;
        dfs(to, u);
        ch[u]+=ch[to];
        //cout<<u<<" "<<to<<" "<<ch[to]<<" "<<n-ch[to]<<"\n";
        temp.pb((ch[to]*(n-ch[to])));
    }
    return;
}
int32_t main()
{
    IOS;
    string s;
    cin>>s;
    int n=s.size();
    int sum=0;
    for(int i=0;i<n;i++)
    {
        sum+=((int)(s[i]-'0'));
    }
    if(sum%9==0)
    cout<<"Yes";
    else
    cout<<"No";
}

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

  vector<int>a(N);
  for (int i = 0; i < N; i++) {
    cin >> a.at(i);
  }
  
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (a.at(i)%2 == 1 && (i+1)%2 == 1){
      count++;
    }
  }
  cout << count << endl;
}
  

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

#define MOD 1000000007

long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll mul(ll a, ll b){
    return a * b % MOD;
}

ll fact(ll n){
    ll ans = 1;
    for (ll i = 1; i <= n; i++){
       ans = (ans * i) % MOD; 
    }
    return ans;
}

int main(){


    int x, y;
    cin >> x;
    cin >> y;
    
    if ((x + y) % 3 != 0){
        cout << 0 << endl;
        return 0;
    }

    int w = (2 * x - y) / 3;
    int h = (-x + 2 * y) / 3;

    if (w < 0 || h < 0) {
        cout << 0 << endl;
        return 0;
    }

    ll a = fact(w + h);
    ll b = fact(w);
    ll c = fact(h);

    ll ans = a;
    ans = mul(ans, modinv(b, MOD));
    ans = mul(ans, modinv(c, MOD));

    cout << ans << endl;

    return 0;

} 

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int x, y, d;
    
    scanf("%d%d",&x,&y);
    
    while(1){
    d = x%y;
    if(d == 0)break;
    x = y;
    y = d;
    }
    
    printf("%d\n",y);
    
    return 0;
}




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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

lint h, w, n; 

lint to_id(lint x, lint y){
    return x + y * h;
}

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

    vector<P> d;
    rep(i, 3) rep(j, 3) d.push_back(P(i-1, j-1));

    map<lint, int> mp;

    rep(i, n){
        lint a, b; cin >> a >> b; a--; b--;
        rep(j, 9){
            lint s = a+d[j].fi, t = b+d[j].se;
            if(s <= 0 || s >= h-1 || t <= 0 || t >= w-1) continue;
            lint id = to_id(s, t);
            mp[id]++;
        }
    }

    lint ans[10];
    rep(i, 10) ans[i] = 0; ans[0] = (h-2)*(w-2);

    for(auto p : mp){
        ans[p.se] += 1;
        ans[0]--;
    }

    rep(i, 10) out(ans[i]);
}

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

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

  while(true){
    int n, x;
    cin >> n >>x;
    if(n==0&&x==0)break;
    int cnt=0;
    rep(i, n){
      for(int j=i+1; j<n; j++){
        for(int k=j+1; k<n; k++){
          if(i+1+j+1+k+1==x)cnt++;
        }
      }
    }
    cout << cnt << endl;
  }
  

  return 0;
}


Measured memory_bytes: 3232
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()

int main(){
  int n;
  cin >> n;
  int weight[n];
  int sum = 0, mn = INT_MAX;
  for(int i = 0; i < n; i++) {cin >> weight[i]; sum += weight[i];}
  int cur = 0;
  for(int i = 0; i < n; i++) {cur += weight[i]; mn = min(mn, abs(cur - (sum - cur)));}
  cout << mn;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back
#define fi first
#define se second

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;
}
void cmps(vector<int>&v,int &i){
	i=lower_bound(all(v),i)-v.begin();
}
constexpr int mod = 998244353;
constexpr int inf = 3e18;

int N,M;
vector<P>G[50];
bitset<50>use[20];
void bfs(int i,int u,int v){
	int dis[50];
	P pre[50];
	rep(i,N)dis[i]=inf;
	dis[u]=0;
	queue<int>que;que.push(u);
	while(!que.empty()){
		int i=que.front();que.pop();
		for(P j:G[i]){
			if(dis[j.first]==inf){
				dis[j.first]=dis[i]+1;que.push(j.first);
				pre[j.first]={i,j.second};
			}
		}
	}
	int now=v;
	while(now!=u){
		use[i].set(pre[now].second);
		now=pre[now].first;
	}
}
signed main(){
	cin>>N;
	rep(i,N-1){
		int a,b;cin>>a>>b;a--;b--;
		G[a].pb({b,i});G[b].pb({a,i});
	}
	cin>>M;
	rep(i,M){
		int u,v;cin>>u>>v;u--;v--;
		bfs(i,u,v);
	}
	int ans=0;
	rep(i,1<<M){
		bitset<50>bit;
		rep(j,M){
			if(i>>j&1)bit|=use[j];
		}
		int cnt=0;
		rep(j,N-1)if(!bit[j])cnt++;
		if(__builtin_popcount(i)%2==0)ans+=1ll<<cnt;
		else ans-=1ll<<cnt;
	}
	cout<<ans<<endl;
}



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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rrepa(i,a,n) for(int i=n-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define cmax(a,b) a=max(a,b)
#define cmin(a,b) a=min(a,b)
#define vc vector

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;

int main(){

    int a,p;
 	cin>>a>>p;
   	cout<<(3*a+p)/2<<"\n";

    return 0;

}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define pb push_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define REP(i,n) for(int i = 0;i < (n);i++)
#define FOR(i,a,b) for(int i = (a);i <= (b);i++)
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;

template <class T = int> T in() { T x; cin >> x; return (x); }
template <class T = int> void out(T x) { cout << (x) << endl; }

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

// value


void solve() {

    int N;
	double T, A;
	cin >> N >> T >> A;

	vector<double> H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		H[i] = fabs(A - (T - H[i] * 0.006));
	}

	int min_i;
	double min = 10000000;
	for (int i = 0; i < N; i++) {
		if(min > H[i]){
			min = H[i];
			min_i = i;
		}
	}

	cout << min_i + 1 << endl;

	return;

}

int main() {

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

	solve();

	return 0;

}


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

int main(){
    string s;

    // 標準入力
    cin >> s;

    int cnt = 0;

    if (s[0] =='1') ++cnt;
    if (s[1] =='1') ++cnt;
    if (s[2] =='1') ++cnt;

    cout << cnt << endl;

    return 0;

}

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

int main(){
  int N, L;
  
  cin >> N >> L;
  
  if (L >= 0) {
    cout << L * N + (N * (N - 1)) / 2 - L << endl;
  }
  
  else {
    if (L + N - 1 >= 0) {
      cout << L * N + (N * (N - 1)) / 2 << endl;
    }
    else {
      cout << L * N + (N * (N - 1)) / 2 - (L + N - 1) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
using namespace std;
using ll=long long;

void solve() {
	ll n, sum = 0, p = 0; cin >> n;
	vector<ll>a(n), ans(n);
	for (ll i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 1)p += a[i];
		sum += a[i];
	}
	ans[0] = sum - 2 * p;
	for (ll i = 1; i < n; i++) ans[i] = 2 * a[i - 1] - ans[i - 1];
	for (ll i = 0; i < n; i++) {
		cout << ans[i];
		if (i != n - 1)cout << " ";
	}
	cout << endl;
}

int main() {
	solve();
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#define MAXN 100010
using namespace std;

int n,a[MAXN],x;

int main()
{
	scanf("%d",&n);
	for (int i=0;i<n;i++) scanf("%d",&a[i]);
	for (int i=0;i<n;i++) x^=a[i];
	puts(x?"No":"Yes");
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 100010
using namespace std;
int n,k;
void mul(int A[],int B[],int C[]){
	static int tmp[MAXN];
	for(int i=1;i<=n;i++)	
		tmp[i]=B[C[i]];
	for(int i=1;i<=n;i++)
		A[i]=tmp[i];
}
void inv(int A[],int B[]){
	for(int i=1;i<=n;i++)
		A[B[i]]=i;
}
int p[MAXN],q[MAXN],p1[MAXN],q1[MAXN],e[MAXN],res[MAXN],res1[MAXN];
int main(){
	SF("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
		SF("%d",&p[i]);
	for(int i=1;i<=n;i++)
		SF("%d",&q[i]);
	inv(p1,p);
	inv(q1,q);
	for(int i=1;i<=n;i++){
		e[i]=i;
		res[i]=i;
	}
	mul(e,e,q);mul(e,e,p1);mul(e,e,q1);mul(e,e,p);
	int x=(k-1)/6;
	int y=(k-1)%6+1;
	while(x){
		if(x&1)
			mul(res,res,e);
		mul(e,e,e);
		x>>=1;	
	}
	if(y>=4)
		mul(res,res,q);
	if(y>=5)
		mul(res,res,p1);
	inv(res1,res);
	if(y==1){
		mul(res,res,p);
	}
	else if(y==2){
		mul(res,res,q);
	}
	else if(y==3){
		mul(res,res,q);
		mul(res,res,p1);
	}
	else if(y==4){
		mul(res,res,p1);
	}
	else if(y==5){
		mul(res,res,q1);
	}
	else{
		mul(res,res,q1);
		mul(res,res,p);
	}
	mul(res,res,res1);
	for(int i=1;i<=n;i++)
		PF("%d ",res[i]);
}

Measured memory_bytes: 3840
# encoding: utf-8
N = int(input())
a = list(map(int, input().split()))

idx = -1
mindiff = 100
ave = sum(a) / N
for i, ai in enumerate(a):
   diff = (ai - ave) if ai > ave else (ave - ai)
   if diff < mindiff:
       idx = i
       mindiff = diff

print(idx)

Measured memory_bytes: 3316
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main()
{
    int A,B,C;
    cin >> A >> B >> C;
    for (int i=1; i<B; ++i)
    {
        if(i*A%B==C)
        {
            cout << "YES" << endl;
            return 0;
        } 
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256