akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1000000007;

ll add(ll x, ll y) {
	return (x+y) % MOD;
}

ll sub(ll x, ll y) {
	return (x-y+MOD) % MOD;
}

ll mult(ll x, ll y) {
	return (x * y) % MOD;
}

ll pot(ll x, ll y) {
	if (y == 0) return 1;
	ll sol = pot(x, y/2);
	sol = mult(sol, sol);
	if (y%2) sol = mult(sol, x);
	return sol;
}

ll div_(ll x, ll y) {
	return mult(x, pot(y, MOD-2));
}

int deg[200005];
int siz[200005];
vector <int> v[200005];
int p[200005];

void dfs(int node, int par) {
	p[node] = par;
	siz[node] = 1;
	for (int i=0 ; i<v[node].size() ; i++) {
		if (v[node][i] == par) continue;
		dfs(v[node][i], node);
		siz[node] += siz[v[node][i]];
	}
}

int main() {
	int n;
	scanf("%d", &n);
	for (int i=0 ; i<n-1 ; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		v[x].pb(y);
		v[y].pb(x);
		deg[x]++;
		deg[y]++;
	}
	dfs(1, 0);
	//cout <<"ovde\n";
	ll sol = 0;
	for (int i=1 ; i<=n ; i++) {
		if (deg[i] == 1) continue;
		ll ne = div_(1LL, pot(2LL, (ll)n-1));
		int br = 1;
		for (int j=0 ; j<v[i].size() ; j++) {
			if (v[i][j] == p[i]) continue;
		//	cout <<v[i][j]<<" <<\n";
			br += siz[v[i][j]];
			ne += mult(sub(1LL, div_(1LL, pot(2LL, (ll)siz[v[i][j]]))), div_(1LL, pot(2LL, (ll)n-siz[v[i][j]]-1)));
		}
		int ost = n-br;
		if (i!=1) ne = add(ne, mult(sub(1LL, div_(1LL, pot(2LL, (ll)ost))), div_(1LL, pot(2LL, (ll)n-ost-1))));
		ll prob = div_(sub(1LL, ne), 2LL);
		//cout <<"prob = "<<prob<<endl;
		sol = add(sol, prob);
	}
	printf("%lld\n", sol);
	return 0;
}

Measured memory_bytes: 22400
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); bool s=false; if(c=='-'){s=true;c=getchar_unlocked();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar_unlocked(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar_unlocked(); int s=0; if(c=='-'){s=1;c=getchar_unlocked();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar_unlocked(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar_unlocked(); while(c==' '||c=='\n') c=getchar_unlocked(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar_unlocked(); } *s='\0'; return len; }

char s[10001];
int a[2][10001], A[2];
bool d[10000][32001];
int main(void){
	int n=nextstr(s);
	int f=0;
	{
		int d=0;
		for(int i=0; i<n; i++){
			if(s[i]=='T'){
				a[f][A[f]]=d;
				A[f]++;
				f=!f;
				d=0;
			}else{
				d++;
			}
		}
		a[f][A[f]]=d;
		A[f]++;
	}
	int x=nextint();
	int y=nextint();
	if(A[0]==0){
		if(x!=0){
			puts("No");
			return 0;
		}
	}else{
		memset(d, 0, sizeof(d));
		d[0][16000+a[0][0]]=true;
		for(int i=1; i<A[0]; i++){
			for(int j=a[0][i]; j<=32000-a[0][i]; j++){
				d[i][j] = d[i-1][j-a[0][i]] || d[i-1][j+a[0][i]];
			}
		}
		if(!d[A[0]-1][16000+x]){
			puts("No");
			return 0;
		}
	}
	if(A[1]==0){
		if(y!=0){
			puts("No");
			return 0;
		}
	}else{
		memset(d, 0, sizeof(d));
		d[0][16000+a[1][0]]=true;
		d[0][16000-a[1][0]]=true;
		for(int i=1; i<A[1]; i++){
			for(int j=a[1][i]; j<=32000-a[1][i]; j++){
				d[i][j] = d[i-1][j-a[1][i]] || d[i-1][j+a[1][i]];
			}
		}
		if(!d[A[1]-1][16000+y]){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}


Measured memory_bytes: 314060
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

Graph G;
deque<int> deq;
int goal;
bool isgoal = false;

void dfs(int v, int par){
    if(isgoal)return;
    deq.push_back(v);

    if(v == goal){
        isgoal = true;
        return;
    }

    for(auto nv : G[v]){
        if(nv == par)continue;
        dfs(nv, v);
    }

    if(isgoal)return;
    deq.pop_back();
}

int res;
void dfs_cnt(int v, int par, int restrict){
    res++;
    for(auto nv : G[v]){
        if(nv == par)continue;
        if(nv == restrict)continue;
        dfs_cnt(nv, v, restrict);
    }
}

int main(){
   int n;
   cin >> n;
   G.resize(n);
   goal = n - 1;

   rep(i, n - 1){
       int a, b;
       cin >> a >> b;
       a--;b--;
       G[a].push_back(b);
       G[b].push_back(a);
   }

   dfs(0, -1);
   int L = 0, R = 0;
   while(!deq.empty()){
       L = deq.front();
       deq.pop_front();

       if(deq.empty())break;

       R = deq.back();
       deq.pop_back();
   }

   int Fen = 0, Snu = 0;
   dfs_cnt(L, -1, R);
   Fen = res, Snu = n - res;
   cout << (Fen > Snu ? "Fennec" : "Snuke") << endl;

}



Measured memory_bytes: 10752
#include <iostream>
using ll = long long;
using namespace std;

/* initialize */
int n, A[500000], L[300000], R[300000], count = 0;
/* main */
ll merge(int A[],int left, int right){
    ll c = 0;
    int mid = (left + right) / 2;
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; ++i)  L[i] = A[left+i];
    for (int j = 0; j < n2; ++j) R[j] = A[mid+j];
    L[n1] = R[n2] = INT32_MAX;
    int i = 0, j = 0;
    for ( int k = left; k < right; k++ ){
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        }
        else {
            A[k] = R[j++];
            c += n1 - i;
        }
    }
    return c;
}

ll mergeSort(int A[], int n, int left, int right){
    if(left+1 < right){
        ll v1 = mergeSort(A, n, left,(left+right)/2);
        ll v2 = mergeSort(A, n, (left+right)/2, right);
        ll v3 = merge(A, left, right);
        return v1+v2+v3;
    }
    return 0;
}

/* main */
int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> A[i];
    ll ans = mergeSort(A, n, 0, n);
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 4664
// Package main provides
//
// File:  d.go
// Author: ymiyamoto
//
// Created on Mon Dec 17 18:43:46 2018
//
package main

import "fmt"

const MOD = 1e9 + 7

func adjacent(net int) bool {
	for i := 0; i < 7; i++ {
		if net&(0x03<<uint8(i)) == 0x03<<uint8(i) {
			return true
		}
	}
	return false
}

func main() {
	var H, W, K int
	fmt.Scan(&H, &W, &K)
	dp := make([][]int, H+1)
	for i := range dp {
		dp[i] = make([]int, W)
	}
	dp[0][0] = 1

	for h := 1; h < H+1; h++ {
		for w := 0; w < len(dp[h]); w++ {
			for i := 0; i < 1<<uint8(W-1); i++ {
				if adjacent(i) {
					continue
				}
				if w+1 < W && i&(1<<uint8(w)) != 0 {
					dp[h][w] += dp[h-1][w+1] % MOD
				} else if w > 0 && i&(1<<uint8(w-1)) != 0 {
					dp[h][w] += dp[h-1][w-1] % MOD
				} else {
					dp[h][w] += dp[h-1][w] % MOD
				}
				dp[h][w] %= MOD
			}
		}
	}

	fmt.Println(dp[H][K-1])
}


Measured memory_bytes: 512
/*
    to amy
*/

#include <bits/stdc++.h>
#define MAX 100010
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int p,q,r;
    while(cin>>p>>q>>r){
        int min_ = 100000;
        if((p+q)<min_) min_ = p+q;
        if((p+r)<min_) min_ = p+r;
        if((r+q)<min_) min_ = r+q;

        cout<<min_<<endl;
    }

    return 0;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define speed  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
ll N;
ll dp[100005];
int main(){
  cin>>N;
  ll A[N+1];
  for(ll i=1;i<=N;i++) cin>>A[i];
  dp[0]=dp[1]=0;
  dp[2]=abs(A[2]-A[1]);
  for(ll i=3;i<=N;i++){
    dp[i]=min(dp[i-2]+abs(A[i]-A[i-2]),dp[i-1]+abs(A[i]-A[i-1]));
  }
  cout<<dp[N];
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN=1e9;
int main()
{
	int n,k,s;
	cin>>n>>k>>s;
	if(s==MAXN) 
	{
		for(int i=1;i<=k;i++)
			printf("%d ",MAXN);
		for(int i=k+1;i<=n;i++)
			printf("%d ",1);
	}
	else {
		for(int i=1;i<=k;i++)
			printf("%d ",s);
		for(int i=k+1;i<=n;i++)
			printf("%d ",MAXN);
	}
}

Measured memory_bytes: 3724
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
const int INF=1e6+5;
int gcd(int x,int y) {
        return !y ? x : gcd(y,x%y);
}
int n,a[INF];
bool vis[INF];
signed main()
{
        scanf("%d",&n);
        for (int i=1; i<=n; i++) scanf("%d",&a[i]);
        int g=a[1];
        for (int i=2; i<=n; i++) g=gcd(g,a[i]);
        if (g>1) {cout<<"not coprime\n"; return 0;}
        for (int i=1; i<=n; i++) {
                int len=sqrt(a[i]);
                for (int j=2; j<=len; j++) {
                        if (vis[j] && !(a[i]%j)) {cout<<"setwise coprime\n"; return 0;}
                        while (!(a[i]%j)) a[i]/=j;
                        if (!(a[i]%j)) vis[j]=true;
                }
                if (vis[a[i]] && a[i]!=1) {cout<<"setwise coprime\n"; return 0;}
                if (a[i]!=1) vis[a[i]]=true;
        }
        cout<<"pairwise coprime\n";
        return 0;
}


Measured memory_bytes: 7612
#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int main(void)
{
  while(1){
    int n;
    cin >> n;
    if(!n) break;
    int b = -1,w = 555;
    for(int i = 0; i < n; i++){
      int sum = 0;
      for(int j = 0; j < 5; j++){
	int p;
	cin >> p;
	sum += p;
      }
      b = max(b,sum);
      w = min(w,sum);
    }
    cout << b << " " << w << endl;
  }
}

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

int H,N;

int fie[10101];

i64 dp[10101][1 << 4];

int main(){
  cin >> H >> N;
  rep(i,0,N - 1){
    int x,y;
    cin >> x >> y;
    fie[y + 1] |= (1 << x);
  }
  rep(i,0,10101 - 1){
    rep(j,0,(1 << 4) - 1){
      dp[i][j] = -1e9;
    }
  }
  dp[1][fie[1]] = 0;
  rep(i,1,H - 1){
    rep(j,0,(1 << 4) - 1){
      rep(k,0,(1 << 3) - 1){
        int next = fie[i + 1];
        bool ok = true;
        int cnt = 0;
        rep(l,0,2){
          if(!(k & (1 << l))) continue;
          if(j & (3 << l)){
            ok = false;
          }
          if(next & (3 << l)){
            ok = false;
          }
          next |= (3 << l);
          cnt++;
        }
        if(!ok) continue;
        dp[i + 1][next] = max(dp[i + 1][next],dp[i][j] + cnt);
      }
    }
  }
  i64 ans = dp[H][0];
  rep(i,0,(1 << 4) - 1){
    ans = max(ans , dp[H][i]);
  }
  cout << ans << endl;
}



Measured memory_bytes: 4388
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		String s = in.next();
		String t = in.next();
		int ans = 9999;
		for (int i = 0; i <= s.length() - t.length(); i++) {
			int x = countUnmatch(s.substring(i, i + t.length()), t);
			if (x < ans)
				ans = x;
		}
		System.out.println(ans);
	}

	private static int countUnmatch(String s, String t) {
		int ans = 0;
		for (int i = 0; i < s.length(); i++)
			if (s.charAt(i) != t.charAt(i))
				ans++;
		return ans;
	}
}


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

//#define int long long
#define DBG 0
#define dump(o) if(DBG){cerr<<#o<<" "<<(o)<<" ";}
#define dumpl(o) if(DBG){cerr<<#o<<" "<<(o)<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

unordered_map<string, int> atom;
class Parser {
public:
	using Iter = string::const_iterator;
	Iter it;
	Parser(Iter it) :it(it) {}
	void cmp(char expected) { if (*it != expected)cerr << *it << " is not " << expected << endl; assert(*it == expected); }
	/*
	EBNF
	a={Molecule}
	Molecule=b,[integer]
	b=Atom|"(",a,")"
	Atom=CapitalLetter,[SmallLetter]
	*/
	bool flag = false;
	int a() {
		dump("a");
		dumpl(*it);
		int ret = Molecule();
		while (true) {
			if (*it == '(' || isalpha(*it)) {
				ret += Molecule();
			}
			else break;
		}
		return ret;
	}
	int Molecule() {
		dump("Molecule");
		dumpl(*it);
		int ret = b();
		if (isdigit(*it))ret *= integer();
		return ret;
	}
	int b() {
		dump("b");
		dumpl(*it);
		int ret;
		if (*it == '(') {
			it++;
			ret = a();
			it++;
		}
		else {
			ret = Atom();
		}
		return ret;
	}
	int Atom() {
		dump("Atom");
		dumpl(*it);
		string name = "";
		name += *it; it++;
		if (islower(*it)) {
			name += *it; it++;
		}
		if (atom.count(name) == 0) {
			dumpl(name);
			flag = true;
			return 0;
		}
		return atom[name];
	}
	int integer() {
		int ret = 0;
		while (isdigit(*it)) {
			ret *= 10;
			ret += *it - '0';
			it++;
		}
		return ret;
	}
};

signed main() {
	for (string s; cin >> s&&s != "END_OF_FIRST_PART";) {
		int a; cin >> a;
		atom[s] = a;
	}
	cin.ignore();
	for (string s; getline(cin, s) && s != "0"; ) {
		s += "$";
		dump(s);
		Parser P(s.begin());
		int ans = P.a();
		if (P.flag)cout << "UNKNOWN" << endl;
		else cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
#define faf ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define ll long long
#define pb push_back
#define mp make_pair
const  ll modo=1e9+7;


int main()
{
    faf;
    int n;
    cin>>n;
    int ar[n+1];
    int br[n];
    int i;
    ll sum=0;
    for(i=0;i<=n;i++){cin>>ar[i];sum+=ar[i];}
    for(i=0;i<n;i++)cin>>br[i];
    int pp;
    for(i=0;i<n;i++)
    {
        pp=min(ar[i],br[i]);
        br[i]-=pp;
        ar[i]-=pp;
        pp=min(ar[i+1],br[i]);
        ar[i+1]-=pp;
    }
    ll kk=0;
    for(i=0;i<=n;i++)
    {
        kk+=ar[i];
    }
    cout<<sum-kk<<endl;

}

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

typedef long long ll;
const int maxn=505;


int main()
{
    ios::sync_with_stdio(false);
    string s;
    ll k;
    while(cin>>s>>k){
        char ans='1';
        int pos=0;
        for(int i=0;i<s.length();i++){
            if(s[i]!='1'){
                ans=s[i];
                break;
            }
            pos++;
        }
        if(pos>=k) cout<<1<<endl;
        else cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    long long  n,s=0;
    cin>>n;
    long long sum=0,o,mn=10000000000;
    vector<long long >v;
    for(int i=0;i<n;i++)
    {
        long long  x;
        cin>>x;
        v.push_back(x);


    }
    sort(v.begin(),v.end());
o=v[0];
 while(o<=v[n-1])
    {
 for(int i=0;i<n;i++)
 {

        s+=(abs(v[i]-o)*abs(v[i]-o));

 }
 mn=min(mn,s);
 s=0;
 o++;
    }
    cout<<mn<<endl;

}

Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        long a = Long.parseLong(sc.next());
        long b = Long.parseLong(sc.next());
        long c = Long.parseLong(sc.next());

        // 主処理
        boolean judge = 0 < c - a - b && 4 * a * b < (c - a - b) * (c - a - b);
        String result = judge ? "Yes" : "No";

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 23636
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,m=map(int,input().split())
    perm=list(map(lambda x:int(x)-1,input().split()))
    E=[[] for _ in range(n)]
    for _ in range(m):
        x,y=map(int,input().split())
        x-=1; y-=1
        E[x].append(y)
        E[y].append(x)

    # 連結成分ごとに分解する
    cnt=[0]
    comp=[-1]*n
    def dfs(v)->NoneType:
        if(comp[v]!=-1): return
        cnt[0]+=1
        comp[v]=cnt[0]
        Q=[v]
        while(Q):
            v=Q.pop()
            for nv in E[v]:
                if(comp[nv]!=-1): continue
                comp[nv]=cnt[0]
                Q.append(nv)

    for v in range(n): dfs(v)
    print(sum(1 for v in range(n) if(comp[v]==comp[perm[v]])))
resolve()

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

#define null				""
#define all(dat)			dat.begin(), dat.end()
#define over(msg)			cout << msg << endl, exit(0);
#define loop(i, to)			for (int i = 0; i < to; ++i)
#define cont(i, to)			for (int i = 1; i <= to; ++i)
#define foreach(i, dat)		for (__typeof(dat.begin()) i = dat.begin(); i != dat.end(); ++i)

typedef long long			num;

using namespace std;

int n, m, w[105], v[105];
num dp[100005], ans;

int main() {
	ios_base::sync_with_stdio(0);
	cin >> n >> m;
	cont (i, n) {
		cin >> w[i] >> v[i];
	}
	cont (i, n) {
		for (int j = m; j >= w[i]; --j) {
			dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
		}
	}
	cont (i, m) {
		ans = max(ans, dp[i]);
	}
	cout << ans << endl;
}


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	ll N, Q, ans=0;
	ll v, w;

	cin >> N >> Q;

	rep(i,Q){
		cin >> v >> w;
		if(N == 1){
			cout << min(v, w) << endl;
			continue;
		}
		while(abs(v-w) > 0){
			if(v > w) swap(v, w);
			if( w <= N+1 ){
				v = 1;
				break;
			}
			w = (w-2) / N + 1;
		}
		cout << v << endl;
	}

	return 0;
}


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

const int64_t MOD= 1000000007;
const int Nfac= 2000007;
#define MEMORY 0 // 1/0: 階乗を配列に格納をする前処理をする/しない
/* 剰余環 Z/nZ */
struct mint{ // Z/nZ に関する演算(n:素数の場合は除算も)をサポートする構造体
  int64_t rep; // 出力すべき代表元 rep \in {0,1,..,MOD- 1}
  mint(int64_t x=0): rep(((x%MOD)+ MOD)% MOD){}
  mint operator-() const { return mint(-rep);}
  mint& operator+=(const mint& x){
    rep+= x.rep; 
    if(rep>= MOD) rep-= MOD;
    return *this;
  }
  mint& operator-=(const mint& x){
    rep-= x.rep;
    if(rep< 0) rep+= MOD;
    return *this;
  }
  mint& operator*=(const mint& x){
    rep*= x.rep; rep%= MOD;
    return *this;
  }
  mint operator+(const mint x) const {
    mint ans(*this);
    ans+= x;
    return ans;
  }
  mint operator-(const mint x) const {
    mint ans(*this);
    ans-= x;
    return ans;
  }
  mint operator*(const mint x) const {
    mint ans(*this);
    ans*= x;
    return ans;
  }

  mint pow(int64_t d) const{ // d \geq 0
    if(d==0) return 1;
    else{
      mint ans= pow(d>>1);
      ans*= ans;
      if(d&1){ ans*= *this; }

      return ans;
    }
  }

  friend ostream& operator << (ostream &os, const mint& x) noexcept{
      return os << x.rep;
  }
  // MOD が素数(<=> Z/nZ が体)のとき
  mint inv() const{
    return pow(MOD-2);
  }
  mint& operator/=(const mint& x){
    *this *= x.inv();
    return *this;
  }
  mint operator/(const mint x) const {
    mint ans(*this);
    ans/= x;
    return ans;
  }
};

/* 階乗,二項係数 */
#if (MEMORY==1)
// 前処理として,階乗を配列に格納をするver.
vector<mint> mfac(Nfac+1), ifac(Nfac+1);
void fact_modp_init(int N= Nfac){
  mfac.at(0)= 1;
  mint buf;
  for(int i=1; i<=N; i++){
    buf= i;
    mfac.at(i)= mfac.at(i-1)* buf;
  }

  ifac.at(N)= mfac.at(N).inv();
  for(int i=N; i>0; i--){
    buf= i;
    ifac.at(i-1)= ifac.at(i)* buf;
  }
}
#else
// 前処理を回避するver.
void fact_modp_init(int N= Nfac){}
mint mfac(int N){
  mint ans= 1;
  mint buf;
  for(int i=1; i<=N; i++){
    buf= i;
    ans*= buf;
  }

  return ans;
}
#endif
// ^^^ テンプレここまで ^^^
mint binom_modp(int n, int k){
  k= min(k, n-k);
  if(n < 0 || k < 0) return 0;
  
  mint ans= 1;
  for(int i=1; i<=k; i++){
    mint num= n-i+1;
    mint den= i;
    ans*= num*den.inv();
  }
  return ans;
}

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

  mint ans= 1;
  int div= 2;
  while(div*div <= M){
    int cnt= 0;
    while(M%div==0){
      cnt++;
      M/= div;
    }
    if(cnt > 0){
      ans*= binom_modp(N+cnt-1, cnt);
    }
    div++;
  }
  if(M > 1) ans*= N; // 一番大きい素因数について非平方の場合

  cout << ans << endl;
}

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

signed main() {
  int N;
  cin >> N;
  
  vector<int> A(N);
  int gusu = 0;
  int ans = 1;
  for( int i = 0; i < N; i++ ){
    ans *= 3;
    cin >> A.at(i);
    if( A.at(i) % 2 == 0 ){
      gusu++;
    }
  }
  
  int hiku = 1;
  for( int i = 0; i < gusu; i++ ) hiku *= 2;
  
  cout << ans - hiku << endl;
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main(void) {
	double x1, y1, x2, y2;

	scanf("%lf %lf %lf %lf", &x1, &y1, &x2, &y2);
	printf("%f\n", sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)));
	return 0;
}

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

using namespace std;

int main() {
    string S;
    cin >> S;

    int ans = 1;
    int index = 1;
    string beforeS = S.substr(0, 1), nowS;
    while(index < S.size()) {
        // int end = index;
        for(int i = index; i < S.size(); ++i) {
            nowS = S.substr(index, i + 1 - index);
            // cout << index << " " << i + 1 - index << " ";
            // cout << nowS << endl;
            if(index == S.size() - 2) {
                if(S[index] == S[index + 1]) {
                    ans++;
                    cout << ans << endl;
                    return 0;
                }
            }
            if(beforeS != nowS) {
                // cout << "index = " << index << " before : " << beforeS
                //     << " now : " << nowS << endl;
                ans++;
                index += i + 1 - index;
                beforeS = nowS;
                break;
            }
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SumOfTwoIntegers | diff SumOfTwoIntegers.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SumOfTwoIntegers.cpp && ./a.out

/*
 
 11/9/2019
 
 4:00-
 
 */

int N;

void solve() {
  int res=(N%2==0)?(N/2-1):(N/2);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N;
  solve();
  
  return 0;
}


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  string A;
  cin >> A;

  ll len = A.size();
  vector<ll> cnt(26, 0);
  rep(i, len) cnt[(int)(A[i] - 'a')]++;

  ll ans = 1 + (len - 1) * len / 2;
  rep(i, 26) ans -= (cnt[i] - 1) * cnt[i] / 2;

  cout << ans << endl;
}


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

int main() {
	int a[4],b[4];
	while(cin>>a[0]>>a[1]>>a[2]>>a[3]){
		cin>>b[0]>>b[1]>>b[2]>>b[3];
		int k=0,n=0;
		for (int kk=0;kk<=3;kk++){
			if(a[kk]==b[kk]){
				k=k+1;
			}
		}
		for(int l=0;l<=3;l++){
			for(int m=0;m<=3;m++){
				if(a[l]==b[m]){
					n=n+1;
				}
		}}
		cout<<k<<" "<<n-k<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#include <string>
using namespace std;
#include<chrono>
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define foo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define min3(a,b,c)         min(a,min(b,c))
#define max3(a,b,c)         max(a,max(b,c))
#define min4(a,b,c,d)       min(a,min(b,min(c,d)))
#define max4(a,b,c,d)       max(a,max(b,max(c,d)))
#define max5(a,b,c,d,e)     max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e)     min(min3(a,b,c),min(d,e))
typedef pair<int, int>  pii;
typedef pair<ll, ll>  pl;
typedef vector<int>   vi;
typedef vector<ll>    vl;
typedef vector<pii>   vpii;
typedef vector<pl>    vpl;
typedef vector<vi>    vvi;
typedef vector<vl>    vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void DFS(int n);
bool isprime(ll n);
int gcd(int a,int b);
void rstgraph(int n);

const int mod = pow(10,9)+7;
const int N = 3e5, M = N;

//=======================================================================================
vi g[N];
int vis[N];
int nodes=0;
// ll ans=0;
void iluzn() {
 double d,t,s;
 cin>>d>>t>>s;
 double ti=d/s;
 if(ti<=t) cout<<"Yes";
 else cout<<"No";
}

 
int main() {
  #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
  #endif
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t=1,i;
    // cin>>t;
     while(t--) iluzn();
    return 0;
}
int mpow(int base, int exp) {
  base %= mod;
  int result = 1;
  while (exp > 0) {
    if (exp & 1) result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}
bool isprime(ll n){
    if(n<=1)
        return false;
    if(n==2)
        return true;
    if(n%2==0)
        return false;
    ll rt = sqrt(n);
    for(ll i=3;i<rt;i+=2){
        if(n%i==0)
            return false;
    }
    return true;
}
int gcd(int a, int b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
} 
void ipgraph(int m){
  int u, v;
  while(m--){
    cin>>u>>v;
    g[u].pb(v);
    // g[v].pb(u);
  }
}

void DFS(int n)
{  ++nodes;
    vis[n] = 1;
    for(vector<int>::iterator i = g[n].begin(); i != g[n].end() ; i++)
    {
        if(!vis[*i])
            DFS(*i);
    }
}
void rstgraph(int n){
  int i;
  fo(i,n+1){
    g[i].clear();
    vis[i]=0;
  }
  nodes=0;
}

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

const int DIM = 2e3 + 5;

int mat[DIM][DIM];

int main( void ) {
    
    int n, x;
    cin >> n >> x;
    
    long long ans = 0;
    for( int i = 0; i < n; i ++ ) {
        cin >> mat[0][i];
        ans += mat[0][i];
    }
    
    for( int i = 1; i < n; i ++ ) {
        long long cnt = 1LL * x * i;
        
        for( int j = 0; j < n; j ++ ) {
            mat[i][j] = min( mat[i - 1][j], mat[0][(j - i + n) % n] );
            cnt += mat[i][j];
        }
        
        ans = min( ans, cnt );
    }
    
    cout << ans << endl;
    return 0;
}

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

ll F[101][11] = {};
ll P[101][11] ={};
int main(){
    ll N;
    cin >> N;
    rep(i,N){
        rep(j,10){
            cin >> F[i][j];    
        }
    }
    rep(i,N){
        rep(j,11){
            cin >> P[i][j];
        }
    }
    ll M = -1e10;
    for(ll i = 1; i<(ll(1) << ll(10));i++){
        vector<ll> c(N);
        ll sum = 0;
        rep(j,10){
            if((i >> ll(j))&ll(1)){
                rep(k,N){
                    if(F[k][j] == 1){
                        c[k]++;
                    }
                }
            }
        }
        rep(j,N){
            sum += P[j][c[j]];
        }
        M = max(M, sum);
    }
    cout << M << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define INF 0x3f3f3f3f
#define pb push_back
#define eps 1e-8
#define PI 3.1415926535898
using namespace std;
const ll maxn = 1e6 + 5;
ll n,m,a,b,c,d,q;
ll NN[50][50];
string str;
struct node{
    ll a,b,c,d;
}num[maxn];
bool cmp(node a,node b){
    return a.d > b.d;
}
int main()
{
    cin >> a >> b >> n;
    ll mid = min(b - 1,n);
    ll ans = - a * (mid / b) + a * mid / b;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <chrono>
#include <math.h>
using namespace std;
using ll = long long;
using ld = long double;
using namespace std::chrono; 
#define fo(i,z,n) for(int i = z;i<n;i++)
#define Fo(i,z,n) for(ll i = z;i<n;i++)
#define INT_BITS 32
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> > 
#define pb push_back
#define f first
// #define s second
#define int long long
#define float long double
#define all(c) (c).begin(), (c).end()
#define endl '\n'
#define pi 3.14159265358979323846

ll power(ll a,ll p,ll m=mod)
{ll res=1;while(p>0){if(p&1)res=(res*a)%m;a=(a*a)%m;p>>=1;}
return res;}

int pow(int a,int b){
	if(b == 0)return 1;
	int res = pow(a,b/2);
	res = res*res;
	if(b&1)res *= a;
	return res;
}



int32_t main()
{
 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     cout.tie(0);
   	
 //    int t;
 //     cin >> t;

 //     while(t--){

     
 // }

int k;
cin >> k;
int a,b;
cin >> a>> b;
int c = b/k;
c = c*k;
if(c >= a)cout << "OK" << endl;
else cout << "NG" << endl;






return 0;
	
	}




Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=2e5+5;
const int mod=998244353;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int s;
    int w;
    cin>>s>>w;
    if(w>=s)
        cout<<"unsafe"<<'\n';
    else
        cout<<"safe"<<'\n';



}


Measured memory_bytes: 3540
#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 vtpl(x,y,z) vector<tuple<x,y,z>>
#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};
const int mod = 1000000007;
const int max_n = 200005;
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,k;cin >> h >>w >>k;
    vector<vector<char>> g(h,vector<char>(w));
    pl s;
    rep(i,h)rep(j,w){
        cin >> g[i][j];
        if(g[i][j]=='S')s={i,j};
    }
    ll ans=inf;
    queue<pl> que;
    que.push(s);
    vvl dist(h,vl(w,inf));
    dist[s.fi][s.se]=0;
    while(!que.empty()){
        pl p=que.front();
        que.pop();
        rep(i,4){
            ll ny=p.fi+dy[i],nx=p.se+dx[i];
            if(ny<0||nx<0||ny>=h||nx>=w)continue;
            if(dist[ny][nx]!=inf)continue;
            if(g[ny][nx]=='#')continue;
            dist[ny][nx]=dist[p.fi][p.se]+1;
            que.push({ny,nx});
        }
    }
    rep(i,h){
        rep(j,w){
            if(dist[i][j]>k)continue;
            //cout << i <<" " <<j <<endl;
            ll tmp=1;
            ll len=inf;
            chmin(len,i);
            chmin(len,j);
            chmin(len,h-i-1);
            chmin(len,w-j-1);
            tmp+=(len+k-1)/k;
            chmin(ans,tmp);
        }
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 6016
from sys import exit
def Fi():
    print('First')
    exit()

N = int(input())
dim = [-1]*N
Edge = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    dim[a-1] += 1
    dim[b-1] += 1
    Edge[a-1].append(b-1)
    Edge[b-1].append(a-1)
par = [None] + [0]*(N-1)
stack = [0]
visited = set([0])
while stack:
    vn = stack.pop()
    for vf in Edge[vn]:
        if vf in visited:
            continue
        visited.add(vf)
        par[vf] = vn
        stack.append(vf)

L = [i for i in range(1,N) if dim[i] == 0]
used = set(L)
stack = L[:]
mat = [0]*N
dim[0] += 2
while stack:
    vn = stack.pop()
    pv = par[vn]
    if pv is None:
        break
    if mat[vn] == 0:
        mat[vn] += 1
        mat[pv] += 1
    dim[pv] -= 1
    if dim[pv] == 0:
        stack.append(pv)
print('Second' if all(m == 1 for m in mat) else 'First')

Measured memory_bytes: 73628
used_g=0
ans=0

for i,j in enumerate(input()):
    if j=="g":
        if i-used_g<used_g:
            ans+=1
        else:
            used_g+=1
    else:
        if not i-used_g<used_g:
            ans-=1
            used_g+=1

print(ans)

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(NULL);

	int n, m, k;
	sf("%d %d %d", &n, &m, &k);
	int a[n];
	int b[m];
	for (int i = 0; i < n; ++i) {
		sf("%d", &a[i]);
	}
	for (int i = 0; i < m; ++i) {
		sf("%d", &b[i]);
	}

	ll t = 0;
	int x = -1;
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		if (t + a[i] > k) break;
		t += a[i];
		++x;
		++cnt;
	}
	int j;
	for (j = 0; j < m; ++j) {
		if (t + b[j] > k) break;
		t += b[j];
		++cnt;
	}
	int ans = cnt;
	while (j < m && x >= 0) {
		t -= a[x];
		--x;
		--cnt;

		while (j < m && t + b[j] <= k) {
			t += b[j];
			++j;
			++cnt;
		}
		ans = max(ans, cnt);
	}

	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 5376
n,m = map(int,input().split())

a = [1]*(n+1)
b = [0]*(n+1)
b[1] = 1

for _ in range(m):
    x,y = map(int,input().split())
    
    if(b[x]==1):
        b[y] = 1
    
    a[x]-=1
    a[y]+=1
    
    if(a[x]==0):
        b[x] = 0
    
cn = 0    

for i in range(1,n+1):
    if(b[i]==1 and a[i]>0):
        cn += 1
        
print(cn)

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

int main() {
	int n; string s; cin >> n >> s;
	int ans = 0, cur = 0;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] == 'I')cur++;
		else cur--;
		if (cur > ans)ans = cur;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
n, q = map(int, input().split())

# max_num
DEF = 0

# generate seg tree
seg_size = 2

while seg_size < n :
    seg_size *= 2
    
seg_size = seg_size * 2 - 1
seg_tree = [DEF for x in range(seg_size)]

answer_stk = []

# update 
def update(i, x) :
    # leaf for index @ i
    idx = seg_size // 2 + i
    seg_tree[idx] += x
    
    while idx :
        idx = (idx - 1) // 2
        l_child = seg_tree[idx * 2 + 1]
        r_child = seg_tree[idx * 2 + 2]
        
        seg_tree[idx] = l_child + r_child

# query
def query(s, t, l, r, curnode) :
    # no overlap then return INF
    if s > r or t < l :
        return DEF
    
    # full overlap then return current node
    if s <= l and t >= r :
        return seg_tree[curnode]
    
    # partial overlap then return min for next
    else :
        l_child = curnode * 2 + 1
        r_child = curnode * 2 + 2
        
        l_value = query(s, t, l, (l + r) // 2, l_child)
        r_value = query(s, t, (l + r) // 2 + 1, r, r_child)
        
        return l_value + r_value
    
# do main query
for i in range(q) :
    q, x, y = map(int, input().split())
    
    # update
    if q == 0 :
        update(x - 1, y)
        
    # query 
    else :
        answer_stk.append(query(x - 1, y - 1, 0, seg_size // 2, 0))
        
for a in answer_stk :
    print(a)


Measured memory_bytes: 13052
import java.util.Scanner;
public class Main
{
	public static void main(String arg[])
	{
		Scanner in = new Scanner(System.in);
		while(in.hasNext())
		{
			int ans=0;
			int inde=0;
			for(int  i=0;i<5;i++)
			{
				int sum=in.nextInt()+in.nextInt();
				if(sum==0)
					return;
				if(ans<sum)
				{
					ans=sum;
					inde=i;
				}
			}
			char ch='A';
			ch= (char) (ch+inde);
			System.out.println(ch+" "+ans);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>

int main(){
    char s[4];

    scanf("%s",s);

    if(s[0]==s[1]){
        printf("Bad\n");
    }else if(s[2]==s[1]){
        printf("Bad\n");
    }else if(s[2]==s[3]){
        printf("Bad\n");
    }else{
        printf("Good\n");
    }

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long N;
	cin >> N;
	long long ans = 0;
	for (int i = 357; i <= N; ) {
		int cnt = 1;
		bool e = false;
		set<int> A = {};
		long long x = i;
		while (x > 0) {
			
			int n = x % 10;
			
			if (n != 7) {
				if (n != 3) {
					if (n != 5) {
						e = true;
						i += cnt;
						break;
					}
				}
			}
			x /= 10;
			cnt *= 10;
			A.insert(n);
		}
		if (!e) {
			if (A.size() == 3) {
				ans++;
			}
			i++;
		}
		
	}
	cout << ans << endl;
}

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

//諸機能
#pragma region MACRO 
#define putans(x)  std::cerr << "answer: " ; cout << (x) << endl
#define dputans(x) std::cerr << "answer: "; cout << setprecision(10) << (double)(x) << endl
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define RREP(i,a,n) for(int i=(int)(n-1); i>= a; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) begin((a)),end((a))
#define mp make_pair
#define exist(container, n) ((container).find((n)) != (container).end())
#define substr(s,i,l) string((s), (i), (l))
#define tos(x) (to_string((x)))
#ifdef _DEBUG //ファイルからテストデータを読み込む
std::ifstream ifs("data.txt");
#define put ifs >>
#else //いい感じにやる
#define put cin >>
#endif
#pragma endregion
//デバッグなどの支援
#pragma region CODING_SUPPORT
#define dbg(var0) { std::cerr << ( #var0 ) << "=" << ( var0 ) << endl; }
#define dbg2(var0, var1) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg(var1); }
#define dbg3(var0, var1, var2) { std::cerr << ( #var0 ) << "=" << ( var0 ) << ", "; dbg2(var1, var2); }
#define dbgArray(a,n) {std::cerr << (#a) << "=";  rep(i,n){std::cerr <<(a[i])<<",";} cerr<<endl;} 
#ifndef _DEBUG
#define dbg1 {}
#define dbg2 {}
#define dbg3 {}
#define dbgArray {}
#endif 
#pragma endregion 
//typedef（書き換える、書き足す可能性ある）
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii; typedef pair<string, string> pss; typedef pair<int, string>pis;
typedef vector<string> vs; typedef vector<int> vi;
#pragma endregion
//諸々の定数(書き換える可能性ある)
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (ll)(1e9 + 7)
#define INF (ll)(1e9)
#pragma endregion


char alphabet[26] = { 'a','b','c','d','e','f','g'
,'h','i','j','k','l','m','n'
,'o','p','q','r','s','t','u'
,'v','w','x','y','z' };


int main() {
	string s; put s;
	int k; put k;
	ll remain = k;
	string ss = s;

	rep(i, ss.length()) {
		if (remain == 0)break;
		int length = ss[i] == 'a' ? 0 : 26 - ( ss[i] - 'a' );
		if (remain - length >= 0) {
			ss.at(i) = 'a';
			remain = remain - length;
		}
	}
	if (remain != 0) {
		remain = remain % 26;
		ss.at(ss.size() - 1) = alphabet[(remain + ss.at(ss.size()-1) - 'a') % 26];
		remain -= ss.at(ss.size() - 1) - 'a';
	}

	putans(ss);
	return 0;
}


//if (remain > 0) {
//	rrep(i, ss.length()) {
//		if (remain == 0)break;
//		int zlength = 'z' - ss[i];
//		dbg(zlength);
//		if (remain - zlength >= 0) {
//			ss.at(i) = 'z';
//			remain = remain - zlength;
//		}
//		else {

//			ss.at(i) = alphabet[remain + ss[i] - 'a'];
//			remain = 0;
//			break;
//		}
//	}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,c;
    cin>>n;
    a=n%10;
    n=n/10;
    b=n%10;
    n=n/10;
    c=n%10;
    n=n/10;
    if((a==7||b==7)||c==7)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
       int count=10000;
       Scanner scan= new Scanner(System.in);

       for(int i=1;i<=count;i++){
           int x=scan.nextInt();
           if(x==0){
               break;
           }else{
               System.out.println("Case "+i+": "+x);
           }
       }
    }
}



Measured memory_bytes: 42652
#include<iostream>
#include<cstring>
using namespace std;
main(){
  char find[11];
  int n,count=0;
  char yubiwa[11];
  int now=0;
  int size;
  cin>>find>>n;
  size=strlen(find);
  for(int a=0;a<n;a++){
    now=0;
    bool check=false;
    for(int i=0;i<10;i++){
      cin>>yubiwa[i];
      if(yubiwa[i]==find[now]){
	now=now+1;
      }
      else if(yubiwa[i]==find[0]){
	now=1;
      }
      else{
	now=0;
      }
      if(i==9&&now<size){
	int nowx=0;
	while(yubiwa[nowx]==find[now]&&now<size){
	  now=now+1;
	  nowx=nowx+1;
	}
      }
      if(now==size){
	check=true;
      }
    }
    if(check==true){
      count=count+1;
    }
  }
  cout<<count<<endl;
}
	

Measured memory_bytes: 1164
#include <iostream>
#define INF 10000000
using namespace std;

int main(){
  int n,x[302][302]={},y[302][302]={};
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)cin>>y[i][j],x[i][j]=y[i][j];

  for(int i=0;i<n;i++)
    for(int j=n-2;j>=0;j--) {
      x[i][j]+=x[i][j+1];
      y[j][i]+=y[j+1][i];
    }
  
  int ans=y[0][n-1],sum,K[302][302]={},t=0,f=1;
  while(f){
    t++,f=0;
    for(int i=0;i<n;i++) //yoko
      for(int j=i+1;j<n;j++) {//yoko
	int a=K[i][j],nk=a;
	sum=-INF;
	for(int k=a+1;k<n;k++) { //tate
	  int X=(x[a][i]-x[a][j+1])+(x[k][i]-x[k][j+1]);
	  int Y=(y[a+1][i]-y[k][i])+(y[a+1][j]-y[k][j]);
	  if(sum<=X+Y)sum=X+Y,nk=k;
	}
	ans=max(ans,sum);
	
	if(nk<n-1)f=1;
	for(int k=a+1;k<nk;k++){//tate
	  sum+=(x[k][i+1]-x[k][j])-(x[k-1][i]-x[k-1][j+1]);
	  ans=max(ans,sum);
	}
	if(a+1==nk&&j-i!=1) nk=n-1;
	K[i][j]=nk;
      }
  }
  cout <<ans<<endl;
	  
  return 0; 
}

Measured memory_bytes: 2236
n = int(input())
prf = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        prf[i].append((x-1, y))

res = 0
for i in range(1<<n):
    flg = True
    cnt = 0
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            cnt += 1
    for j in range(n):
        if ( i >>j & 1 ) == 1:
            for x,y in prf[j]:
                if y == 0 and ( i >> x & 1 ) == 1:
                    flg = False
                if y == 1 and ( i >> x & 1 ) == 0:
                    flg = False
    if flg:
        res = max(res, cnt)
print(res)


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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N,M;
ll D[101010];
vector<pair<ll,pll>> uvv[101010];
ll ans[101010],ans2[202020];
vector<ll> sv[101010];
ll i, j;

//Union木
struct UnionFind{
    vector<int> nxt;
    void init(int x){
        nxt.clear();
        nxt.resize(x);
        for (int i = 0; i < x;i++){
            nxt[i] = i;
        }
    }
    int find(int x){
        if(nxt[x]==x)
            return x;
        return nxt[x] =find(nxt[x]);
    }
    inline void unite(int x,int y){
        nxt[find(y)] = find(x);
    }
};

void no(){
    printf("-1");
    exit(0);
}
void dfs(ll a,ll c){
    ll i = 0;
    ans[a] = c + 1;
    fornum(i,0,sv[a].size()){
        dfs(sv[a][i], c ^ 1);
    }
}

int main(){
    scanf("%lld%lld",&N,&M);
    fornum(i,0,N){
        scanf("%lld", &D[i + 1]);
    }


    fornum(i,0,M){
        ll u, v;
        scanf("%lld%lld", &u, &v);
        uvv[u].push_back({D[v], {v, i}});
        uvv[v].push_back({D[u], {u, i}});
    }

    fornum(i,0,N){
        sort(uvv[i + 1].begin(), uvv[i + 1].end());
        auto uv = uvv[i + 1][0];
        if(D[i+1]<uv.first){
            no();
        }
        if(ans2[uv.second.second]!=0&&ans2[uv.second.second]!=D[i+1]){
            no();
        }
        if(ans2[uv.second.second]==0){
            ans2[uv.second.second] = D[i + 1];
            sv[uv.second.first].push_back(i + 1);
            ans[i + 1] = 1;
        }
    }
    fornum(i,0,N){
        if (ans[i + 1] != 0)
            continue;
        dfs(i + 1, 0);
    }
    fornum(i,0,N){
        if(ans[i+1]==1){
            printf("B");
        }else{
            printf("W");
        }
    }
    fornum(i,0,M){
        printf("\n%lld", ans2[i] == 0 ? (ll)1e9 : ans2[i]);
    }
    

    
    return 0;
}

Measured memory_bytes: 25472
#include <iostream>
#include <algorithm>

#define MAX_N 100005
using namespace std;
int root[MAX_N];
int n,m;
int x,y,z;
int cnt;
int find(int k){
    int tmp = k;
    while(root[tmp]!=tmp)tmp=root[tmp];
    root[k] = tmp;
    return root[k];
}

bool unite(int p,int q)
{
    int a = find(p);
    int b = find(q);
    if(a==b)return false;
    root[b] = a;
    return true;
}


int main()
{
    
    cin>>n>>m;
    for(int i = 0;i<=n+1;i++)root[i]=i;
    cnt = n;
    for(int i = 0;i<m;i++){
        cin>>x>>y>>z;
        if(unite(x,y))cnt--;
    }
    cout<<cnt<<endl;

}


Measured memory_bytes: 640