akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
int n,k,a[100005],b[100005];
int main(){
	cin>>n>>k;
	rep(i,n)cin>>a[i]>>b[i];
	int val = 0;
	ll ans = 0;
	rep(i,n){
		if((a[i]|k) == k){
			ans += b[i];
		}
	}
	for(int i=29;i>=0;i--){
		if(!((k>>i)&1)) continue;
		for(int x=0;x<i;x++) val += (1<<x); //cout<<val<<endl;
		ll ret = 0;
		rep(i,n){
			if((a[i]|val)==val) ret += b[i];
		}
		ans = max(ans,ret);
		for(int x=0;x<i;x++) val -= (1<<x);
		val += (1<<i);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
import java.util.Scanner;
class Main{
  public static void main(String args[]){
	Scanner scanner=new Scanner(System.in);
    int num=scanner.nextInt();
    int count=0;
    for(int i=0;i<=5;i++){
    	if(num/((int)Math.pow(10,i))>0){
        	count=i+1;
        }else{
        	break;
        }
    }
    int answer=0;
    for(int i=1;i<=count;i++){
      	if(i%2==1 && i!=count){
        	answer+=(int)Math.pow(10,i)-(int)Math.pow(10,i-1);
        }else if(i%2==1 && i==count){
        	int add=num-(int)Math.pow(10,i-1)+1;
          	answer+=add;
        }else if(i%2==0){
        	continue;
        }
    }
    System.out.println(answer);
  }
}

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

edge = [[] for _ in range(n)]

for _ in range(m):
    a,b = map(int,input().split())
    a,b = a-1,b-1

    edge[a].append(b)
    edge[b].append(a)


from collections import deque

d = deque([0])

dist = [-1]*n
dist[0] = 0

while d:
    v = d.popleft()

    for w in edge[v]:
        if dist[w]==-1:
            dist[w]=dist[v]+1
            d.append(w)

 
if dist[-1]==2:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')



Measured memory_bytes: 40492
from itertools import combinations

n=int(input())
cnt=[0]*26

for i in range(n):
    s=input()
    cnt[ord(s[0])-ord('A')]+=1

ans=0

for c1,c2,c3 in combinations(["M","A","R","C","H"],3):
    c1=ord(c1)-ord("A")
    c2=ord(c2)-ord("A")
    c3=ord(c3)-ord("A")

    ans+=cnt[c1]*cnt[c2]*cnt[c3]

print(ans)

Measured memory_bytes: 74496
import java.util.*;
import java.io.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.lang.Math.*;

public class Main {

	int INF = 1 << 28;
	//long INF = 1L << 62;
	double EPS = 1e-10;

	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(), t = sc.nextInt(), s = sc.nextInt();
		int[] as = new int[n], bs = new int[n];
		
		for(int i=0;i<n;i++) {
			as[i] = sc.nextInt(); bs[i] = sc.nextInt();
		}
		
		int[] dp1 = new int[s+1], dp2 = new int[n+1];
		fill(dp1, -1); dp1[0] = 0;
		for(int i=0;i<n;i++) for(int j=s;j>=0;j--) if(dp1[j] >= 0){
			if(bs[i] + j <= s && dp1[bs[i]+j] < dp1[j] + as[i]) {
				dp1[bs[i]+j] = dp1[j] + as[i];
				dp2[i+1] = max(dp1[bs[i]+j], dp2[i+1]);
			}
		}
		for(int i=1;i<=n;i++) dp2[i] = max(dp2[i], dp2[i-1]);
		
		int[] dp3 = new int[t-s+1], dp4 = new int[n+1];
		fill(dp3, -1); dp3[0] = 0;
		for(int i=n-1;i>=0;i--) for(int j=t-s;j>=0;j--) if(dp3[j] >= 0) {
			if(bs[i] + j <= t-s && dp3[bs[i]+j] < dp3[j] + as[i]) {
				dp3[bs[i]+j] = dp3[j] + as[i];
				dp4[n-i] = max(dp3[bs[i]+j], dp4[n-i]);
			}
		}
		for(int i=1;i<=n;i++) dp4[i] = max(dp4[i], dp4[i-1]);
		
		int max = 0;
		for(int i=0;i<n;i++) max = max(max, dp2[i] + dp4[n-i]);
		System.out.println(max);
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}

	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 30020
#len(s)//2-s.count("p")
iG = 0
iR = 0
for s in input().rstrip():
    if s == "g" :
        if 0 < iG:
            iR += 1
            iG -= 1
        else:
            iG += 1
    else:
        if 0 < iG:
            iG -= 1
        else:
            iR -= 1
            iG += 1
print(iR)


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

using namespace std;
using lli = int_fast64_t;
using ulli = unsigned long long;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = copy(x);cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

constexpr lli MOD = (lli)1e9 + 7;
constexpr lli LIMIT = 1000000000000000000 * 5;



int main() {
	int N;
	cin >> N;
	map<string, int> ma;
	ma["AC"] = 0;
	ma["WA"] = 0;
	ma["TLE"] = 0;
	ma["RE"] = 0;
	while (N--) {
		string s;
		cin >> s;
		ma[s]++;
	}

	cout << "AC x " << ma["AC"] << endl;
	cout << "WA x " << ma["WA"] << endl;
	cout << "TLE x " << ma["TLE"] << endl;
	cout << "RE x " << ma["RE"] << endl;

	return 0;
}



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

int main() {
    int H, W;
    cin >> H >> W;
    while(!(H == 0 && W == 0)) {
        for(int i = 0; i < H; i++) {
            for(int j = 0; j < W; j++)
                cout << '#';
            cout << endl;
        }
        cout << endl;
        cin >> H >> W;
    }
    return 0;
}


Measured memory_bytes: 3080
l,r=map(int,input().split())
if r-l>=2019:
    print(0)
    exit()
else:
    mini=10000000000000000 
    for i in range(l,r+1):
        for j in range(i+1,r+1):
            mini=min(mini,i*j%2019)
    print(mini)

Measured memory_bytes: 2940
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in range(N)]

AB.sort()

money = 0
for a, b in AB:
  if M > b:
    money += a * b
    M -= b
  else:
    money += a * M
    break
    
print(money)

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

using namespace std;

int N;

int dfs(long long cur, bool f7, bool f5, bool f3) {
    static int ans = 0;
    if (cur > N)
        return 0;
    if (f7 && f5 && f3)
        ans++;
    dfs(cur * 10 + 7, true, f5, f3);
    dfs(cur * 10 + 5, f7, true, f3);
    dfs(cur * 10 + 3, f7, f5, true);
    return ans;
}

int main() {
    cin >> N;

    cout << dfs(0, false, false, false) << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cctype>

typedef long long LL;

int N;
int buk[19][19];
LL Ans;

int main() {
	scanf("%d", &N);
	for (int i = 1; i <= N; ++i) {
		char S[19];
		scanf("%s", S + 1);
		int len = strlen(S + 1);
		int pos = len;
		while (pos > 1 && isdigit(S[pos - 1])) --pos;
		if (pos == 1) pos = len + 2;
		LL x = 0;
		for (int j = 1; j < pos - 1; ++j)
			x = x * 10 + (S[j] - '0');
		for (int j = 0; j < 9; ++j)
			x = x * 10 + (pos + j <= len ? S[pos + j] - '0' : 0);
		int c2 = 0, c5 = 0;
		while (x % 2 == 0) ++c2, x /= 2;
		while (x % 5 == 0) ++c5, x /= 5;
		if (c2 > 18) c2 = 18;
		if (c5 > 18) c5 = 18;
		int t2 = 18 - c2, t5 = 18 - c5;
		for (int i2 = t2; i2 <= 18; ++i2)
			for (int i5 = t5; i5 <= 18; ++i5)
				Ans += buk[i2][i5];
		++buk[c2][c5];
	}
	printf("%lld\n", Ans);
	return 0;
}

Measured memory_bytes: 1708
N, C = map(int, input().split())
V = [0]
X = [0]
Y = []
for i in range(N):
  x, v = map(int, input().split())
  X += [x]
  Y += [C-x]
  V += [v]
Y += [0]
f = [0]
g = [0]
for i in range(1,N+1):
  f += [f[-1]+X[i-1]+V[i]-X[i]]
  g += [g[-1]+Y[N-i+1]+V[N-i+1]-Y[N-i]]
g = g[::-1]

m = -1
ans1 = 0
for i in range(N+1):
  if m<f[i]:
    m = f[i]
  ans1 = max(ans1, m+g[i]-Y[i])

m = -1
ans2 = 0
for i in range(N, -1, -1):
  if m<g[i]:
    m = g[i]
  ans2 = max(ans2, m+f[i]-X[i])

print(max(ans1, ans2))

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

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define MOD 1000000007
#define el endl
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25


int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans;
    ans = (n / (a+b)) * a;
    n = n % (a+b);
    if(n >= a){
        ans += a;
    }else{
        ans += n;
    }
    cout << ans << endl;
}




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

long long len,a,dis,ans;

int main()
{
	cin>>len>>a>>dis;
    if (len%(a+dis)>=dis)  ans=len/(a+dis);
    else ans=(len/(a+dis))-1;
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
from collections import defaultdict

class LCM_mod:
    """
    最小公倍数の計算を行う
    オーバーフローが発生しないように素因数分解し,
    因数の積を逐次余りに置き換えて最小公倍数を導出する.
    """
    def __init__(self, max_num, p=10**9+7):
        self.max_num = max_num + 1
        self.p = p
        self.prime = [0 for _ in range(self.max_num)]
        self.max_map = defaultdict(int)
        self.sieve()

    def rep_sqr(self, base, k):
        # 繰り返し二乗法
        if k == 0:
            return 1
        elif k % 2 == 0:
            return (self.rep_sqr(base, k / 2) ** 2) % self.p
        else:
            return (self.rep_sqr(base, k - 1) * base) % self.p

    def sieve(self):
        """
        エラトステネスの篩　O(n)
        nまでに含まれる素数を導出
        """
        self.prime[0], self.prime[1] = 1, 1
        for i in range(2, self.max_num):
            if self.prime[i] == 0:
                for j in range(i * 2, self.max_num, i):
                    if self.prime[j] == 0:
                        self.prime[j] = i
                self.prime[i] = i

    def lcm_list_mod(self, arr):
        """
        listのそれぞれの要素について、素因数分解する
        それぞれの因数について最大であれば更新する
        """
        for i in range(len(arr)):
            num = arr[i]
            d = defaultdict(int)

            while num > 1:
                fact = self.prime[num]
                d[fact] += 1
                num //= fact

            for i in d.keys():
                self.max_map[i] = max(self.max_map[i], d[i])

        ans = 1
        for i in self.max_map.keys():
            ans = (ans * self.rep_sqr(i, self.max_map[i])) % self.p
        return ans


class FLT:
    def __init__(self, mod=10**9+7):
        self.mod = mod

    def rep_sqr(self, base, k):
        if k == 0:
            return 1
        elif k % 2 == 0:
            return (self.rep_sqr(base, k // 2) ** 2) % self.mod
        else:
            return (self.rep_sqr(base, k - 1) * base) % self.mod

    def inv(self, a):
        """ 逆元を取る """
        return self.rep_sqr(a, self.mod-2)

def main():
    n = int(input())
    a = list(map(int, input().split()))
    MOD = 10**9+7

    lcm_mod = LCM_mod(max(a), MOD)
    lcm_all = lcm_mod.lcm_list_mod(a)
    flt = FLT(MOD)

    b = list(map(lambda x: lcm_all * flt.inv(x), a))
    ans = 0
    for i in range(len(b)):
        ans += b[i]
        ans %= MOD
    print(ans)

main()

Measured memory_bytes: 115312
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

char convNext(char ch) {
	if('a' <= ch && ch <= 'y') return ch+1;
	if(ch=='z')return 'a';
	return ch;
}
int main() {
	char str[90];
	while(true) {
		if(!fgets(str, 90, stdin))break;
		for(int i = 0; i < 26; i++) {
			if(strstr(str,"this") || strstr(str,"that") || strstr(str,"the"))break;
			for(int j = 0; str[j]; j++) {
				str[j]=convNext(str[j]);
			}
		}
		fputs(str, stdout);
	}
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().run();
	}
	
	private void run() {
		Scanner scan = new Scanner(System.in);
		while (scan.hasNext()) {
			double d = scan.nextInt();
			int s = 0;
			for (int i = 0; i < 600; i += d) {
				s += i * i * d;
			}
			System.out.println(s);
		}
	}
	
	private void debug() {
		System.out.println();
	}

}

Measured memory_bytes: 17184
#include<bits/stdc++.h>
using namespace std;
const int maxn = 100010;
long long t[maxn], a[maxn];
long long pre[maxn], suf[maxn];
long long n;

inline void update(long long x){
    while(x<maxn){
        t[x]++; x+=x&(-x);
    }
    return ;
}

inline long long query(long long x){
    long long res=0;
    while(x>0){
        res+=t[x];  x-=x&(-x);
    }
    return res;
}

void initpre(){
    memset(t,0,sizeof(t));
    pre[0]=0;
    for (long long i=1;i<=n;++i){
        //pre[i]=pre[i-1];
        pre[i]=i-1-query(a[i]);
        update(a[i]);
    }
    return ;
}

void initsuf(){
    memset(t,0,sizeof(t));
    suf[0]=0;
    for (long long i=n;i>=1;--i){
        //suf[i]=suf[i+1];
        suf[i]=(n-i-query(a[i]));
        update(a[i]);
    }
    return ;
}

int main(){
    scanf("%lld",&n);
    for (int i=1;i<=n;++i){
        scanf("%lld",&a[i]);
    }
    initpre();
    initsuf();
    long long ans = 1e18, ex;
    ans = 0;
    for (int i=1;i<n;++i){
        ans += min(suf[i],pre[i]);
    }
    printf("%lld\n",ans);
    return 0;
}



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

int main() {
    int n;
    cin >> n;
    int ans;
    int div = -1;
    auto cnt = [](int n) {
        int ret = 0;
        while(n%2 == 0) {
            ret++;
            n /= 2;
        }
        return ret;
    };
    rep2(i,1,n+1) {
        if(cnt(i) > div) {
            ans = i;
            div = cnt(i);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// Template
#include <bits/stdc++.h>
#define rep_override(x, y, z, name, ...) name
#define rep2(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep3(i, l, r) for (int i = (int)(l); i < (int)(r); ++i)
#define rep(...) rep_override(__VA_ARGS__, rep3, rep2)(__VA_ARGS__)
#define per(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
constexpr int inf = 1001001001;
constexpr ll INF = 3003003003003003003;
template <typename T> inline bool chmin(T& x, const T& y) {if (x > y) {x = y; return 1;} return 0;}
template <typename T> inline bool chmax(T& x, const T& y) {if (x < y) {x = y; return 1;} return 0;}
struct IOSET {IOSET() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} ioset;

int main() {
    string s, t;
    cin >> s >> t;
    
    int ans = inf;
    rep(i, s.size() - t.size() + 1) {
        int cnt = 0;
        rep(j, t.size()) {
            if (s[i + j] != t[j]) ++cnt;
        }
        chmin(ans, cnt);
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 3644
program C177
    implicit none
    integer(8) :: N
    integer(8), allocatable, dimension(:) :: A
    integer(8) :: i, ans, b, c, d, c1, c2, j

    read(5,*) N
    allocate(A(N))
    read(5,*) (A(i), i = 1, N)

    

    c = 0
    d = 0
    c1 = 0
    c2 = 0

    do i = 1, N
        c = c + A(i)
        d = d + A(i) * A(i)
        if (c > 1000000007) then
            c1 = c / 1000000007
            c = c - c1 * 1000000007
        end if        
        if (d > 1000000007) then
            c2 = d / 1000000007
            d = d - c2 * 1000000007
        end if
 
    end do

    b = mod(c**2-d,1000000007)

    if (mod(b,2) == 0) then
        ans = b / 2
    else
        ans = (b+1000000007) / 2
    end if





    write(6,*) ans

    
end program C177

Measured memory_bytes: 4660
n=int(input())
tp = 0
hp = 0
for _ in range(n):
    taro,hanaco = input().split()
    if taro == hanaco :
        tp +=1
        hp +=1
    elif taro > hanaco :
        tp += 3
    else: hp += 3
print('{} {}'.format(tp,hp))

Measured memory_bytes: 7652
def f_c():
    n = int(input())
    h = list(map(int, input().split()))
    h = h[::-1]
    c = [0]
    for i in range(1, n):
        if h[i] >= h[i-1]:
            c.append(c[-1]+1)
        else:
            c.append(0)
    print(max(c))

if __name__ == "__main__":
    f_c()


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

int cha(vector<int>&a,int b){
  int ma=0;
  for(int i=b+1;i<10;i++){
    ma=max(ma,a.at(i));
  }
  if(ma+1>a.at(b)){
    a.at(b)+=1;
    if(b>0){
      for(int j=0;j<b;j++){
        a.at(j)=0;
      }
    }
  }else{
    cha(a,b+1);
  }
}

int main() {
  vector<char>A(11);
  vector<int>n(10,0);
  A={'a','b','c','d','e','f','g','h','i','j'};
  int N;
  cin >> N;
  for(int i=0;i<99999999;i++){
    for(int j=N-1;j>=0;j--){
      cout << A.at(n.at(j));
    }
    cout << endl;
    cha(n,0);
    if(n.at(N-1)==1){
      break;
    }
  }
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>
#include<cstdint>
#include<bits/stdc++.h>
#include<queue>
#include<set>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep_r(i, n) for(int i = n-1; i >= 0; i--)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((ll)(x).size())
#define bit(n) (1LL<<(n))
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define INF bit(60)
#define pb push_back
#define mod 1000000007

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;
using uif=uint_fast64_t;
using ll=long long int;

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mod;a=1ll*a*a%mod;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

ll fb[4]={2,1,1,0};

double next(double p1,double p2,ll ind){
  if(ind==0) return p1*p2;
  else if(ind==1) return (1.0-p1)*p2;
  else if(ind==2) return p1*(1.0-p2);
  //else if(ind==3) return (1.0-p1)*(1.0-p2);
  else return (1.0-p1)*(1.0-p2);

  
}

int main(void){

  ll n;
  cin>>n;
  vector<double> p(n+1);
  vector< vector<double> > q( 3000, vector<double>(3000,0.0) );
  rep(i,n){
    cin>>p[i];
  }

  q[0][0]=1.0;

  rep(i,n) q[i+1][0]=q[i][0]*(1.0-p[i]);
  
  rep(i,n){
    rep(j,i+1){

      q[i+1][j+1]=q[i][j]*p[i]+q[i][j+1]*(1.0-p[i]);
      
    }
  }
  double ans=0.0;
  for(ll i=n;i>n-i;i--){
    //cout << i << "," << n-i << endl;
    ans+=q[n][i];
  }
  
  cout << setprecision(20) << ans << endl;

  return 0;

}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B1 = 0,B2 = 0, B3 = 0,B4 = 0, C = 0, count = 0;
  cin >> A;
  vector<int> vec(100);
  int i;
  int j = 0;
  
  for (i = 0; i < A; i++) {
    cin >> vec.at(i);
  }
  for(i = 0;i < A;i++){
    j = 0;
    while(j <= C){
      B1 += vec.at(j);
      j++;
    }
    while(j < A){
      B2 += vec.at(j);
      j++;
    }
    if(count < 1){
      B3 = B1 - B2;
      if(B3 < 0){
        B3 *= -1;
      }
      count++;
    }
    else{
      B4 = B1 - B2;
        if(B4 < 0){
          B4 *= -1;
        }
      if(B3 > B4){
        B3 = B4;
      }
    }
    C++;
    B1 = 0;
    B2 = 0;
  }
  cout << B3 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for (int i = 0; i < n; i++)
using namespace std;

int main()
{
    int n;  cin >> n;
    int r[n];
    rep(i,n)  cin >> r[i];

    int maxv = -2000000000;
    int minv = r[0];

    for (int i = 1; i < n; i++) {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }
    cout << maxv << endl;
}


Measured memory_bytes: 3880
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

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

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	ll a, b;
	char op;
	cin >> a >> op >> b;
	ll ans;
	if(op == '+') ans = a + b;
	else ans = a - b;
	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++)
//long long mo = 1e9 + 7;
typedef long long ll;
typedef pair<int,int> P;
#include <deque> 

int main(){
    string S;
    cin >> S;
    deque<char> que;
    rep(i,S.size()){
        que.push_back(S[i]);
    }
    ll cnt = 0;
    int Q;
    cin >> Q;
    int T,F;
    char C;
    rep(i,Q){
        cin >> T;
        if(T == 1){
            cnt++;
        }else{
            cin >> F >> C;
            if(F == 1){
                if(cnt % 2 == 0){
                    que.push_front(C);
                }else{
                    que.push_back(C);
                }
            }else{
                if(cnt % 2 == 0){
                    que.push_back(C);
                }else{
                    que.push_front(C);
                }
            }
        }
    }
    if(cnt % 2 == 0){
        rep(i,que.size()){
            cout << que[i];
        }
    }else{
        rep(i,que.size()){
            cout << que[que.size()-1-i];
        }
    }
    cout << endl;
}


Measured memory_bytes: 896
#include<stdio.h>

int main()
{
  int n,m;
  int a[51],b[51],c[51][51],ans[51];
  int i,j;
  scanf("%d%d",&n,&m);
  for(i=0;i<m;i++){
    scanf("%d%d",&a[i],&b[i]);
  }
  for(i=0;i<n;i++){
    ans[i]=0;
  }
  for(i=0;i<m;i++){
    ans[a[i]-1]++;
    ans[b[i]-1]++;
  }
  for(i=0;i<n;i++){
    printf("%d\n",ans[i]);
  }
  return 0;
}


Measured memory_bytes: 1736
import java.util.Scanner;

public class Main {
    private static int M = 1046527;
    private static String[] H = new String[M];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < n; i++) {
            String cmd = scanner.next();
            String s = scanner.next();
            if("insert".equals(cmd)) {
                insert(s);
            } else {
                System.out.println(find(s) ? "yes" : "no");
            }
        }
    }

    private static int getChar(char c) {
        if (c == 'A') {
            return 1;
        } else if (c == 'C') {
            return 2;
        } else if (c == 'G') {
            return 3;
        } else if (c == 'T') {
            return 4;
        } else {
            return 0;
        }
    }

    private static int getKey(char[] c) {
        int sum = 0;
        int p = 1;
        for (int i = 0; i < c.length; i++) {
            sum += p *getChar(c[i]);
            p *= 5;
        }
        return sum;
    }

    private static int h1(int key) {
        return key % M;
    }

    private static int h2(int key) {
        return 1 + (key % (M - 1));
    }

    private static boolean find(String s) {
        int key = getKey(s.toCharArray());
        int i = 0;
        while (true) {
            int h = (h1(key) + i * h2(key)) % M;
            if (s.equals(H[h])) {
                return true;
            } else if (H[h] == null) {
                return false;
            }
            i++;
        }
    }

    private static boolean insert(String s) {
        int key = getKey(s.toCharArray());
        int i = 0;
        while (true) {
            int h = (h1(key) + i * h2(key)) % M;
            if (s.equals(H[h])) {
                return true;
            } else if (H[h] == null) {
                H[h] = s;
                return false;
            }
            i++;
        }
    }
}

Measured memory_bytes: 275720
from functools import lru_cache

H, W, K = map(int, input().split())
MOD = 10**9 + 7
K -= 1

if W == 1:
    print(1)
    exit()

@lru_cache(maxsize=None)
def fib(width):
    if width < -1:
        return 0
    if width == -1:
        return 1
    return (fib(width - 1) + fib(width - 2)) % MOD

dp = [0] * W
dp[0] = 1

for _ in range(H):
    newDp = [0] * W

    newDp[0] = (dp[0] * fib(W - 2) + dp[1] * fib(W - 3)) % MOD
    newDp[W - 1] = (dp[W - 1] * fib(W - 2) + dp[W - 2] * fib(W - 3)) % MOD

    for w in range(1, W - 1):
        left = dp[w - 1] * max(1, fib(w - 2)) * max(1, fib(W - 1 - w - 1))
        right = dp[w + 1] * max(1, fib(w - 1)) * max(1, fib(W - 1 - w - 2))
        mid = dp[w] * max(1, fib(w - 1)) * max(1, fib(W - 1 - w - 1))
        newDp[w] = (left + mid + right) % MOD
    dp = newDp

print(dp[K])

Measured memory_bytes: 3572
#include <bits/stdc++.h> 
using namespace std; 
  
int minimumChar(string S1, string S2) 
{ 
    // Get the sizes of both strings 
    int n = S1.size(), m = S2.size(); 
  
    int ans = INT_MAX; 
  
   
    for (int i = 0; i < m - n + 1; i++) 
    { 
        int minRemovedChar = 0; 
  
       
       



        for (int j = 0; j < n; j++) 
        { 
            if (S1[j] != S2[i + j]) 
            { 
                minRemovedChar++; 
            } 
        } 
  
       
        ans = min(minRemovedChar, ans); 
    } 
  
    
    return ans; 
} 
  

int main() 
{ 
    string s1,s2;
    cin>>s1>>s2;
    cout<<minimumChar(s2,s1); 
  
    return 0; 
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <complex>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long ll;

#define omajinai ios::sync_with_stdio(false);cin.tie(0)

//container util
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define UNIQUE(a)  (a).erase(unique((a).begin(),(a).end()),(a).end())
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << "[L " << __LINE__ << "] " << #x << " = " << (x) << "\n";

const int INF = 1e9;
const double EPS = 1e-10;

int n,m,k;

int main() {
	cin>>n>>m>>k;
	REP(i,n+1)REP(j,m+1){
		if((n-i)*j+(m-j)*i==k){
			cout << "Yes"<<endl;
			return 0;
		}
	}
	cout << "No"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)

int main()
{
   ll n,k;
   cin>>n>>k;
   ll kk=0;
   while(n>0)
   {
	   kk++;
	   n/=k;
   }
   cout<<kk<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<cmath>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<numeric>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
int dx[4] = {1,0,-1,0}, dy[4] = {0,1,0,-1};


ll ans = 0;


int main()
{

    ll H;
    cin >> H;
    ll ans = 0;

    ll cnt = 0;
    while(H>0)
    {
        ans += powl(2,cnt);
        H /= 2;
        ++ cnt;
    }

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

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
	int n;
	cin >> n;
	vector<int>a(n);
	int ans = 0;
	for (int i = 0;i < n;i++) {
		cin >> a[i];
		ans += a[i];
	}
	sort(a.begin(), a.end());
	if (ans % 10 != 0) {
		cout << ans << endl;
	}
	else {
		for (int i = 0;i < n;i++) {
			if (a[i] % 10 != 0) {
				cout << ans - a[i] << endl;
				break;
			}
			if (i == n - 1) {
				cout << 0 << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
  {
  int n;
    scanf("%d",&n);
    switch (n % 10){
     case 2:
     case 4:
     case 5:
     case 7:
     case 9:
     printf("hon");
        break;
     case 0:
     case 1:
     case 6:
     case 8:
        printf("pon");
        break;
     case 3:
        printf("bon");
        break;
    }
    return 0;
    }

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

using namespace std;

long long a[1001];

long long gcd(long long a, long long b) {
    while (b > 0) {
        a %= b;
        swap(a, b);
    }
    return a;
}


int main() {
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    sort (a, a + n);
    long long ans = a[n-1], q = 0;
    for (int i = 0; i < n-1; ++i) {
        q = a[n-1]/gcd(a[n-1],a[i])*a[i];
        ans = q/gcd(ans,q)*ans;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
 
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define all(v) (v).begin(), (v).end()
#define rev(s) (s).rbegin(), (s).rend()
#define MP make_pair
#define X first
#define Y second
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;

int main(){
	int n;
	while(cin >> n, n){
		priority_queue<P, vector<P>, greater<P> > q;
		rep(i, n){
			int m, a, b;
			cin >> m >> a >> b;
			q.push(MP(a, m));
			q.push(MP(b, -m));
		}
		int sum = 0;
		while(!q.empty()){
			sum += q.top().second;
			q.pop();
			if(sum > 150) break;
		}
		cout << (sum>150?"NG":"OK") << endl;
	}


	return 0;
}

Measured memory_bytes: 1196
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define pi acos(-1)
#define cross(a,b) (conj(a)*(b)).imag()
#define dot(a,b) (conj(a)*(b)).real()
#define vec(a,b) b-a
#define Reka ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;

int main()
{
    Reka
   int n;
   cin>>n;
   int h[n];
for(int i=0;i<n;i++)
{
    cin>>h[i];
}
int ans[n];
ans[0] = 0;
ans[1] = abs(h[0]-h[1]);
for(int i=2;i<n;i++)
{
    ans[i] = min(ans[i-1]+abs(h[i-1]-h[i])
                 ,ans[i-2]+abs(h[i]-h[i-2]));
}
/*
for(int i=2;i<n;i++)
{
ans[i] = 1e9;
for(int j=i-1;j<max(0,abs(x-i));j--)
{
ans[i] = min(ans[j]+abs(h[i]-h[j]),ans[i])
}
}*/
cout<<ans[n-1];
    return 0;
}


Measured memory_bytes: 1024
import java.util.*;

public class Main {
	
	public static final double PI = 3.1415926535897;

	public static void main(String[] args) {
		// Origin = ( -1, 0)
		int num;
		double x, y, rad;
		Scanner scan = new Scanner(System.in);
		while(true) {
			num = scan.nextInt();
			if(num==-1) break;

			x = 1.0; y = 0.0; rad = PI/2.0;
			for( int i=0; i<num-1; i++) {
				x += Math.cos(rad);
				y += Math.sin(rad);
				
				rad = Math.atan2(y, x) + PI/2.0;
			}
			System.out.println(""+x+"\n"+y);
		}
	}
}

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

/* {{{ */
#define CL(N) cout << N << endl
#define DCT(N) cout << "debug " << N << endl
#define REP(i, N) for (int i = 0; i < N; i++)
/* }}} */

int K[128], menu[128][4][4];

int check(int n, int m, int d1, int d2)
{
    if (m > n) return (1);
    if (menu[m][d1][d2]) return (menu[m][d1][d2]);

    if (d1 == d2 && d1 == K[m] && d1) return (0);

    if (K[m]){
        menu[m][d1][d2] = check(n, m + 1, d2, K[m]) % 10000;
    }
    else {
        for (int i = 1; i <= 3; i++){
            if (d1 != d2 || d1 != i) menu[m][d1][d2] += check(n, m + 1, d2, i) % 10000;
        }
    }

    return (menu[m][d1][d2]);
}

int main()
{
    int n, k;

    cin >> n >> k;

    REP(i, k){
        int a, b;
        cin >> a >> b;
        K[a] = b;
    }

    CL(check(n, 1, 0, 0) % 10000);

    return (0);
}

Measured memory_bytes: 3068
#include <iostream>

int main(){
  std::string s;
  std::cin >> s;
  if(s == "Sunny")
    std::cout << "Cloudy" << std::endl;
  else if(s == "Cloudy")
    std::cout << "Rainy" << std::endl;
  else if(s == "Rainy")
    std::cout << "Sunny" << std::endl;
  return 0;
}


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

int n,q;
vector<vector<int>> G;
vector<int> d;
vector<int> visited;

void bfs(int s){
    queue<int> que;
    que.push(s);
    visited[s] = true;

    while(!que.empty()){
        int from = que.front();
        que.pop();

        for(auto to : G[from]){
            if(!visited[to]) {
                d[to] += d[from];
                que.push(to);
                visited[to] = true;
            }
        }
    }
}

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

    G.resize(n);
    d.resize(n,0);
    visited.resize(n,false);

    for(int i = 0; i < n - 1; i++){
        int a,b;
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for (int i = 0; i < q; i++) {
        int p, x;
        cin >> p >> x;
        p--;
        d[p] += x;
    }

    bfs(0);

    for(auto it : d) cout << it << " ";
    cout << endl;

}

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

struct solver {
    ll x, fx;
    map<ll, int> used;
    int l, r;
    solver() {
        x = 0;
        fx = 0;
        l = r = 0;
    }

    void update(ll a, ll b) {
        fx += abs(x - a) + b;
        used[a] += 1;
        if (a < x) {
            ++ l;
            while (l >= used[x] + r) {
                ll nx = prev(used.find(x))->first;
                fx -= (x - nx) * (l - used[x] - r);
                r += used[x];
                l -= used[nx];
                x = nx;
            }
        } else if (x < a) {
            ++ r;
            while (l + used[x] < r) {
                ll nx = next(used.find(x))->first;
                fx -= (nx - x) * (r - used[x] - l);
                l += used[x];
                r -= used[nx];
                x = nx;
            }
        } else {
            // nop
        }
    }

    pair<ll, ll> get() {
        return make_pair(x, fx);
    }
};

int main() {
    solver f;
    int q; cin >> q;
    while (q --) {
        int t; cin >> t;
        if (t == 1) {
            ll a, b; cin >> a >> b;
            f.update(a, b);
        } else if (t == 2) {
            ll x, y; tie(x, y) = f.get();
            cout << x << ' ' << y << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 8832
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;


public class Main {

    int a,b;

    private void solve() {
        a = nextInt();
        b = nextInt();

        char c = 'x';
        if (a + b == 15) {
            c = '+';
        }

        if (a * b == 15) {
            c = '*';
        }

        out.println(c);
    }

    public static void main(String[] args) {
        out.flush();
        new Main().solve();
        out.close();
    }

    /* Input */
    private static final InputStream in = System.in;
    private static final PrintWriter out = new PrintWriter(System.out);
    private final byte[] buffer = new byte[4096];
    private int p = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (p < buflen)
            return true;
        p = 0;
        try {
            buflen = in.read(buffer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (buflen <= 0)
            return false;
        return true;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrint(buffer[p])) {
            p++;
        }
        return hasNextByte();
    }

    private boolean isPrint(int ch) {
        if (ch >= '!' && ch <= '~')
            return true;
        return false;
    }

    private int nextByte() {
        if (!hasNextByte())
            return -1;
        return buffer[p++];
    }

    public String next() {
        if (!hasNext())
            throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = -1;
        while (isPrint((b = nextByte()))) {
            sb.appendCodePoint(b);
        }
        return sb.toString();
    }

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

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

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


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

#define fast_cin ios_base::sync_with_stdio(false); cin.tie(NULL)

#define LL long long

#define SIZE 105

LL N, K;

LL W[SIZE], V[SIZE];

LL dp[SIZE][100005];

LL call(int pos, int curr) {
    if(pos==N) {
        return 0;
    }

    if(dp[pos][curr]!=-1) {
        return dp[pos][curr];
    }

    LL val1 = 0, val2 = 0;

    if(curr+W[pos]<=K) {
        val1 = V[pos] + call(pos+1, curr+W[pos]);
    }

    val2 = call(pos+1, curr);

    return dp[pos][curr] = max(val1, val2);
}

int main() {
    #ifdef forthright48
    freopen("input.txt", "r", stdin);
    //freopne("output.txt", "w", stdout);
    #endif // forthright48

    fast_cin;

    cin >> N >> K;

    for(int i=0; i<N; i++) {
        cin >> W[i] >> V[i];
    }

    memset(dp, -1, sizeof(dp));

    LL ret = call(0, 0);

    cout << ret << "\n";

    return 0;
}


Measured memory_bytes: 82304
#include <iostream>
#define REP(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) REP(i,0,n)
using namespace std;
int A[51], B[51], C[51], D[51];
int *a, *b, *c, *d, *t;
int main()
{
	int n, r, k;
	while (cin >> n >> r) {
		int an = n/2+n%2, bn = n/2;
		a=A, b=B, c=C, d=D;
		rep(i, n) d[i] = i;
		while (r--) {
			cin >> k;
			int ai=0, bi=0, ci=0, di=0;
			rep(i, bn) b[i] = d[di++];
			rep(i, an) a[i] = d[di++];
			while(ai<an || bi<bn) {
				for (int i=0; ai<an && i<k; ++i) c[ci++] = a[ai++];
				for (int i=0; bi<bn && i<k; ++i) c[ci++] = b[bi++];
			}
			t = c; c = d; d = t;
		}
		cout << d[n-1] << endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>

int main()
{
	int N=0;
	char Color;
	int Syurui=3;

	scanf("%d",&N);
	for(int i=0; i<N; i++)
	{
		scanf("%c",&Color);
		if(Color == 'Y') Syurui = 4;
	}

	if(Syurui == 3) printf("Three");
	else printf("Four");

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner sc = new Scanner(System.in);
        int K = sc.nextInt();
        int A = sc.nextInt();
        int B = sc.nextInt();

        boolean ans = false;
        int n = 0;

        while(n <= B){
            if(n >= A){
                ans = true;
            }
            n += K;
        }

        System.out.println(ans?"OK":"NG");
    }
}


Measured memory_bytes: 35792
#include <bits/stdc++.h>
using namespace std;
#define PI 3.14159265

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	
	int n ,m;
	cin>>n>>m;
	int a[m];
	int sum=0;
	for(int i=0; i<m; i++) {
		cin>>a[i];
		sum+=a[i];
	}
	if(sum>n) cout<<-1;
	else if(sum==n) cout<<0;
	else {
		cout<<n-sum;
	}
	
    return 0;
}

Measured memory_bytes: 3652
//グラフは隣接リスト表現で扱う。
//メモリ量O(E), 計算量O(V+E) (Vは頂点, Eは辺の数)
//辺が少ない疎なグラフで有利。

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

#define MAX 105000
#define NIL -1

int n;
vector<int> G[MAX];
int color[MAX];

void dfs(int r, int c){
    stack<int> S;
    S.push(r);
    color[r] = c;

    while(!(S.empty())){
        int u = S.top(); S.pop();
        for(int i=0; i<G[u].size(); i++){
            int v = G[u][i];
            if(color[v] == NIL){
                color[v] = c;
                S.push(v);
            }
        }
    }
}

void bfs(int r, int c){
    //最初だけ別にpushしてやる
    queue<int> Q;
    Q.push(r);
    color[r] = c;

    while(!(Q.empty())){
        int u = Q.front(); Q.pop();
        for(int i=0; i<G[u].size(); i++){
            int v = G[u][i];
            if(color[v] == NIL){
                color[v] = c;
                Q.push(v);
            }
        }
    }
}

void assignColor(){
    int id = 1;
    for(int i=0; i<n; i++) color[i] = NIL;
    for(int u=0; u<n; u++){
        //if(color[u] == NIL) dfs(u, id++);
        if(color[u] == NIL) bfs(u, id++);
    }
}

int main(){
    int s, t, m, q;
    cin >> n >> m;

    //隣接リスト表現
    for(int i=0; i<m; i++){
        cin >> s >> t;
        G[s].push_back(t);
        G[t].push_back(s);
    }

    assignColor();

    cin >> q;
    
    for(int i=0; i<q; i++){
        cin >> s >> t;
        if(color[s] == color[t]){
            cout << "yes" << endl;
        }else{
            cout << "no" << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 9072
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

string s;
int main(){
	cin >> s;
	int ans = 700;
	for(int i = 0; i < 3 ; ++ i)
		ans += (s[i] == 'o') * 100;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rush() int T;scanf("%d",&T);int kase=1;while(T--)
#define all(x) (x).begin(),(x).End()
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define pb(x) push_back(x)
#define mem(a) memset(a,0,sizeof(a))
using namespace std;
using std::bitset;
typedef long long ll;
const ll maxn=1e6+5;
const ll mod=998244353;
const ll INF=0x3f3f3f3f3f3f3f3f;
const long double PI=acos(-1.0);
const long double eps=1e-5;
inline ll read(){ll ans=0,flag=1;char c;c=getchar();while(c<'0' || c>'9'){if(c=='-')flag=-1;c=getchar();}while(c>='0' && c<='9'){ans=ans*10+(ll)(c-'0');c=getchar();}return ans*flag;}
ll quickpow(ll x,ll y,ll mod){ll ans=1;while(y){if(y&1)ans=ans*x%mod;x=x*x%mod;y>>=1;}return ans;}

vector<int>a;

bool cmp(int a,int b)
{
    return a>b;
}

int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        a.push_back(x);
    }
    sort(a.begin(),a.end(),cmp);
    ll sum=0;
    if(k>=n)
        cout<<"0";
    else
    {
        for(int i=k;i<n;i++)
        {
            sum+=a[i];
        }
        cout<<sum;
    }
    return 0;
}


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

using namespace std;

vector <int> e[200005];
int d[200005];

bool ban[200005],val[200005];

int dis[200005];

int dfs(int x,int fa) {
  dis[x]=dis[fa]+val[x];
  int ans=x;
  for(int i=0;i<e[x].size();i++)
    if (e[x][i]!=fa&&!ban[e[x][i]]) {
    	int u=e[x][i];
    	int t=dfs(u,x);
    	if (dis[t]>dis[ans]) ans=t;
	}
  return ans;
}

char str[200005];
queue <int> q;

int main() {
  int n;
  scanf("%d",&n);
  for(int i=1;i<n;i++) {
  	int x,y;
  	scanf("%d%d",&x,&y);
  	e[x].push_back(y);
  	e[y].push_back(x);
  	d[x]++;d[y]++;
  }
  scanf("%s",str+1);
  bool ok=0;
  for(int i=1;i<=n;i++) {
  	val[i]=(str[i]=='W');
  	ok|=val[i];
  }
  if (!ok) {
  	puts("0");
  	return 0;
  }
  for(int i=1;i<=n;i++)
    if (!val[i]&&d[i]<=1) q.push(i);
  while (!q.empty()) {
  	int x=q.front();q.pop();
  	ban[x]=1;
  	for(int i=0;i<e[x].size();i++)
  	  if (!ban[e[x][i]]) {
  	  	  int u=e[x][i];
  	  	  d[u]--;
  	  	  if (!val[u]&&d[u]<=1) q.push(u);
		}
  }
  int rt=0,s=-2;
  for(int i=1;i<=n;i++)
    if (!ban[i]) {
    	rt=i;
    	for(int j=0;j<e[i].size();j++)
    	  if (!ban[e[i][j]]) val[e[i][j]]^=1;
    	s+=2;
	}
  for(int i=1;i<=n;i++)
    if (!ban[i]) s+=val[i];
  rt=dfs(rt,0);
  int x=dfs(rt,0);
  printf("%d\n",max(1,s-2*dis[x]));
  return 0;
}

Measured memory_bytes: 15360
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <functional>
#include <numeric>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
using namespace std;
#define INT_MAX 2147483647
#define INT_MIN (-2147483647 - 1)
#define INF (int)1e8
#define _INF (int)-1e8
#define INFLL (long long)1e14
#define _INFLL (long long)-1e14
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#define Loop1(i, n) for(int i = 1; i <= (int)n; i++)
#define Loopr(i, n) for(int i = (int)n - 1; i >= 0; i--)
#define Loopr1(i, n) for(int i = (int)n; i >= 1; i--)
#define bitmanip(m,val) static_cast<bitset<(int)m>>(val)
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;

class BIT {
private:
	vll bi;
	int n;
	ll sum_0start(int t) {
		int x = 1, p = t;
		ll ret = 0;
		while (p > 0) {
			if (x & t) {
				ret += bi[p];
				p -= x;
			}
			x <<= 1;
		}
		return ret;
	}
public:
	BIT(vll a) {
		n = a.size();
		vll s(n + 1, 0);
		Loop1(i, n) {
			s[i] = s[i - 1] + a[i - 1];
		}
		bi.resize(n + 1, 0);
		Loop1(i, n) {
			int x = i;
			x = x & (x*(-1));
			bi[i] = s[i] - s[i - x];
		}
	}
	ll sum(int s, int t) {
		return sum_0start(t) - sum_0start(s);
	}
	void add(int k, int x) {
		k++;
		do {
			bi[k] += x;
			k += k&(k*(-1));
		} while (k <= n);
	}
};

int main() {
	int n, q; cin >> n >> q;
	vll a(n, 0);
	BIT bit(a);
	Loop(i, q) {
		int com, x, y; cin >> com >> x >> y;
		if (com == 0) bit.add(x - 1, y);
		else cout << bit.sum(x - 1, y) << endl;
	}
	return 0;
}

Measured memory_bytes: 5972
import sys

N, D = map(int,input().split())
X = [0]*N
Y = [0]*N
for i in range(N):
  X[i], Y[i] = map(int,input().split())

def solve():
  ret = 0
  for i in range(N):
    if X[i]*X[i]+Y[i]*Y[i] <= D*D:
      ret += 1
  return ret

print(solve())

Measured memory_bytes: 24700
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;

typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;
typedef vector<string> vstring;

typedef vector<pair<int, int>> vpint;
typedef vector<pair<ll, ll>> vpll;
typedef vector<pair<double, double>> vpdouble;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int c_YET = -1;
//const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const ll MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


	ll N;
	cin >> N;

	vll A(N), B(N), C(N);
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i] >> C[i];
	}

	vvll dp(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++) {
			dp[i].emplace_back(0);
		}
	}

	dp[0][0] = A[0];
	dp[0][1] = B[0];
	dp[0][2] = C[0];

	for (int i = 1; i < N; i++) {
		dp[i][0] = max(dp[i - 1][1] + A[i], dp[i - 1][2] + A[i]);
		dp[i][1] = max(dp[i - 1][2] + B[i], dp[i - 1][0] + B[i]);
		dp[i][2] = max(dp[i - 1][0] + C[i], dp[i - 1][1] + C[i]);
	}

	cout << max(dp[N - 1][0], max(dp[N - 1][1], dp[N - 1][2]));


}



Measured memory_bytes: 9600