akhauriyash/Code-Regression huggingface dataset:
towns = Hash.new([])
n = $<.gets.to_i
(m = $<.gets.to_i).times do
  a, b, c, d = $<.gets.split(",").map(&:to_i)
  towns[a] += [[b, c]]
  towns[b] += [[a, d]]
end
s, g, v, p = $<.gets.split(",").map(&:to_i)

travel = ->(start, goal) {
  minimum = Float::INFINITY
  walk = ->(town, visited, cost = 0) {
    if town == goal
      minimum = [minimum, cost].min
    else
      towns[town].each do |nxt, c|
        walk.(nxt, visited + [nxt], cost + c) unless visited.include?(nxt)
      end
    end
  }
  walk.(start, [start])
  minimum
}

v -= travel.(s, g)
v -= travel.(g, s)
puts v - p


Measured memory_bytes: 7684
X = int(input())


if 400 <= X <= 599:
    print(8)
elif 600 <= X <= 799:
    print(7)
elif 800 <= X <= 999:
    print(6)
elif 1000 <= X <= 1199:
    print(5)
elif 1200 <= X <= 1399:
    print(4)
elif 1400 <= X <= 1599:
    print(3)
elif 1600 <= X <= 1799:
    print(2)     
elif 1800 <= X <= 1999:
    print(1)                         

Measured memory_bytes: 61764
N, M, V, P = map(int, input().split())

As = [10**9+1] + list(map(int, input().split()))

As.sort(reverse=True)


rlt = P
memo = [0]*(N+1)

for i in range(P+1,N+1):
  memo[i] = memo[i-1] + As[i-1]

for i in range(P+1,N+1):
  if As[i] == As[i-1]:
    rlt += 1
    continue
  if As[i] + M < As[P]:
    break
  if N - i >= V - P:
    rlt += 1
  else:
    t = i - P
    v = V - N + t
    if t*(As[i]+M) - memo[i] >= M*v:
      rlt += 1
    else:
      break
      
print(rlt)


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

int main(void) {
  string s;
  cin >> s;

  int cnt = 0;
  rep (i, s.size() / 2) {
    if (s[i] != s[s.size() - 1 - i])cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (a, b, c) = readLine()?.split(" ")?.map(String::toInt) ?: return
    // ぜんぶ同じか、ぜんぶ異なる
    when {
        a == b && b == c -> {
            println("No")
        }
        a != b && b != c && c != a -> {
            println("No")
        }
        else -> {
            println("Yes")
        }
    }
}

Measured memory_bytes: 37684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int MAXN = 2e6+5;

int n, a[MAXN], m, s[MAXN];
map<pii, int> dp;

int comp(int f, int x) {
    //best = a at position x
    // assert(f < s[x]);
    if (dp.count(pii(f, x)) > 0)
        return dp[pii(f, x)];
    if (x == 0) {
        dp[pii(f, x)] = f;
        return f;
    }
    if (f < s[0]) {
        dp[pii(f, x)] = 2*s[0] - f;
        return 2*s[0]-f;
    }
    int lo = 0, hi = x-1;
    while (lo != hi) {
        int mid = (lo+hi+1)/2;
        if (s[mid] <= f)
            lo = mid;
        else
            hi = mid-1;
    }
    dp[pii(f, x)] = comp(2*s[lo]-f, lo);
    return dp[pii(f, x)];
}

int main() {
    cin >> n;
    for (int i = 0; i < n-1; ++i) {
        cin >> a[i];
        if (i == 0)
            s[i] = a[i];
        else
            s[i] = s[i-1] + a[i];
    }

    cin >> m;

    for (int i = 0; i < m; ++i) {
        int x; cin >> x;
        s[n-1] = a[n-2] + x;
        a[n-1] = x;
        cout << comp(s[n-2] - a[n-1], n-2) << "\n";
    }
}

Measured memory_bytes: 75264
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#define llong long long
#define INF (__INT32_MAX__ / 2)
#define EPS 10e-8
#define MAX_N 100000

using namespace std;
typedef pair<int, int> ipair;
llong modulo(llong left, llong right) { return (left % right + right) % right; }

string S;
int main(int argc, char **argv) {
    cin >> S;
    bool res = true;
    for(int i = 0; i < S.size(); ++i) {
        if(i % 2 == 0) {
            if(S[i] != 'R' && S[i] != 'U' && S[i] != 'D')
                res = false;
        } else {
            if(S[i] != 'L' && S[i] != 'U' && S[i] != 'D')
                res = false;
        }
    }

    cout << (res ? "Yes" : "No") << endl;
}

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

int main() {

    char s[3];
    scanf("%s", s);

    char week[7][4] = {"SAT", "FRI", "THU", "WED", "TUE", "MON", "SUN"};

    for (int i = 0; i < 7; i++) {

        if (strcmp(week[i],s) == 0) {
            printf("%d",i+1);
            break;
        }

    }


    return 0;

}


Measured memory_bytes: 128
#include <iostream>
#include <cstring>
#include <cstdio>
#include<algorithm>
#include <queue>
#include <cmath>
#include <limits>
#include <map>
#include <iomanip>
using namespace std;
#define ll long long int

int main(){
  int n, m;
  cin >> n >> m;
  int day = 0;
  int error = -1;
  for (int i = 0; i < m; i++)
  {
    int temp = 0;
    cin >> temp;
    day = day + temp;
  }
  if (n - day >= 0)
    cout << n - day << endl;
    else cout << error << endl;
  return 0;
}

Measured memory_bytes: 3220
#
import sys
import math
import numpy as np
import itertools


# いくつか入力
n, p = (int(i) for i in input().split())  

f=[]
r=2
root = math.sqrt(p)
while root >= r:
    if p % r == 0:
        f.append(r)
        p = p // r
    else:
        r += 1
if p > 2:
    f.append(p)

#print(f)
answer = 1
now = 1
k=0
for i in f:
    if now == i:
        k += 1
    else:
        answer = answer * (now ** (k // n) )
        now = i
#        print(i,k,answer)
        k=1
answer = answer * (now ** (k // n) )
print(answer)



Measured memory_bytes: 12496
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int A[300][300];
int main() {
	int N;
	cin >> N;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			cin >> A[i][j];
		}
	}
	LL sum=0;
	for(int i=0;i<N;i++){
		for(int j=i+1;j<N;j++){
			bool ok=false;
			for(int k=0;k<N;k++){
				if(i==k||j==k)continue;
				if(A[i][j]>A[i][k]+A[k][j]){
					puts("-1");
					return 0;
				}
				if(A[i][j]==A[i][k]+A[k][j]){
					ok=true;
					break;
				}
			}
			if(!ok){
				sum+=A[i][j];
			}
		}
	}
	cout << sum << endl;

	return 0;
}



Measured memory_bytes: 640
#include<stdio.h>
using namespace std;
#define N 100000
int main()
{
    int n;
    char s[N];
    scanf("%d%s",&n,s);
    int max=0;
    for(int i=0;i<n-2*max;i++)
    {
        for(int j=i+max+1;j<n-max;j++)
        {
            if(s[i]==s[j])
            {
                int ii=i;
                int jj=j;
                int sum=1;
                while(s[++ii]==s[++jj]&&ii<j)
                {
                    sum++;
                }
                if(sum>max)
                    max=sum;
            }
        }
    }
    printf("%d\n",max);
    return 0;
}


Measured memory_bytes: 632
#include<iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<iomanip>
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>

#define rep(i,n) for(int i=0; i<(n); ++i)
#define pai 3.1415926535897932384

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

int main(int argc, const char * argv[]) {
    
    int N;
    cin >> N;
    
    vector<int> d1(N);
    vector<int> d2(N);
    
    int Ans = 0;
    int sum = 0;
    for(int i=0; i<N; i++){
        cin >> d1[i] >> d2[i];
        
        if(d1[i] == d2[i]){
            sum++;
            Ans = max(Ans, sum);
        }else{
            sum=0;
        }
    }
    
    if(Ans>=3) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}

//<< fixed << setprecision(10)


Measured memory_bytes: 3128
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<random>
#include <iomanip>

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "

int main(int argc, const char *argv[]){
    int n;
    cin >> n;
    vector<double> v(n);
    double ans = 0;
    rep(i,n)cin >> v[i];
    sort(v.begin(),v.end(), greater<int>());
    rep(i,n-1) ans += v[i]*pow(0.5,i+1);
    ans+=v[n-1]*pow(0.5,n-1);
    cout << fixed;
    cout << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define FOR(i, a, n) for(int (i) = (int)(a); (i) < (int)(n); ++(i))
#define FORe(i, a, n) for(int (i) = (int)(a); (i) <= (int)(n); ++(i))
#define rFOR(i, a, n) for(int (i) = (int)(n)-1; (i) >= (int)(a); --(i))
#define rFORe(i, a, n) for(int (i) = (int)(n); (i) >= (int)(a); --(i))
#define REP(i, n) FOR((i), 0, (n))
#define REPe(i, n) FORe((i), 1, (n))
#define REPo(i, n) FORe((i), 0, (n))
#define rREP(i, n) rFOR((i), 0, (n))
#define rREPe(i, n) rFORe((i), 1, (n))
#define rREPo(i, n) rFORe((i), 0, (n))
#define rep(i, n) FOR((i), 0, (n))
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define fi first
#define se second
#define dup(x, y) (((x)+(y)-1)/(y))
#define vc(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using P = pair<int,int>;
using pll = pair<ll,ll>;
using T = tuple<int,int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using vp = vector<P>;
using vt = vector<T>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
  ll a,v,b,w;
  ll t;
  cin>>a>>v>>b>>w>>t;
  ll a1,a2,b1,b2;
  a1 = a-v*t;
  a2 = a+v*t;
  b1 = b-w*t;
  b2 = b+w*t;
  if(v<=w) {
    cout << "NO" << endl;
  }else {
    if(a<b) {
      if(a2<b2) cout << "NO" << endl;
      else cout << "YES" << endl;
    }else {
      if(a1>b1) cout << "NO" << endl;
      else cout << "YES" << endl;
    }
  }


  return 0;
}

Measured memory_bytes: 3620
#include <cstdio>
int n,k;
int main(){
	scanf("%d %d",&n,&k);
	if((1<<n)<=k || (n == 1 && k == 1))return printf("-1"),0;
	if(n == 1&&k == 0)return printf("0 0 1 1"),0;
	for(int i=0;i<(1<<n);++i)
		if(i != k)printf("%d ",i);
	printf("%d ",k);
	for(int i=(1<<n)-1;~i;--i)
		if(i != k)printf("%d ",i);
	printf("%d ",k);
	return 0;
}

Measured memory_bytes: 1904
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;

int main(){
    ll n,W;cin>>n>>W;
    vvll wei(4);
    rep(i,4)wei[i].push_back(inf);
    ll w,v,tmp;cin>>w>>v;
    tmp=w;wei[0].push_back(v);
    rep(i,n-1){
        cin>>w>>v;
        wei[w-tmp].push_back(v);
    }
    rep(i,4){
        sort(all(wei[i]));
        reverse(all(wei[i]));
        wei[i][0]=0;
    }
    rep(i,4)rep(j,wei[i].size()-1)wei[i][j+1]+=wei[i][j];
    ll ans=0;
    rep(i,wei[0].size())rep(j,wei[1].size())rep(k,wei[2].size())rep(l,wei[3].size()){
        if((i+j+k+l)*tmp+j+2*k+3*l<=W){
            ans=max(ans,wei[0][i]+wei[1][j]+wei[2][k]+wei[3][l]);
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<iostream>
using namespace std;

int N,Q;
long long int x[112345];

string S;
int main (){
    cin >> N >> Q >> S;
    int t = S.size();
    for(int i=0; i<t-1; i++) {
        if( S[i] == 'A' && S[i+1] == 'C') x[i+1] += x[i] + 1;
        else x[i+1] = x[i];
    }
    for(int i=0; i<Q; i++) {
        int l,r;
        cin >> l >> r;
        l--;r--;
        cout << x[r] - x[l] << endl;
    }
    return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    long long int sum = 0;
    for(int i = 1; i <= n; i++){
        if(i%3 == 0 || i%5 == 0) continue;
        sum = sum + i;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int main() {
    int N;
    cin >> N;
    int A[N + 1], B[N + 1], C[N + 1];
    for (int i = 1; i <= N; ++i) cin >> A[i];
    for (int i = 1; i <= N; ++i) cin >> B[i];
    for (int i = 1; i < N; ++i) cin >> C[i];
    C[N] = 0;
    int total = 0;
    for (int i = 1, eve = 0; i <= N; ++i) {
        int sat = B[A[i]];
        if (i > 1) if (eve == A[i] - 1) sat += C[eve];
        eve = A[i];
        total += sat;
    }
    cout << total << endl;
}


Measured memory_bytes: 888
#!/usr/bin/env python3
import sys


def solve(N: int, S: "List[str]", P: "List[int]"):
    sp = sorted(
        [(s, p, index) for (s, p, index) in zip(S, P, range(1, N + 1))],
        key=lambda x: (x[0], -x[1]),
    )
    for s, p, index in sp:
        print(index)
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word

    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = [str()] * (N)  # type: "List[str]"
    P = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        S[i] = next(tokens)
        P[i] = int(next(tokens))
    solve(N, S, P)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
int a,b,c,k;
cin >>a>>b>>c>>k;
int count =0;
while(a>=b){
b =2*b;
count ++;
}
while(b>=c){
c =2*c;
count ++;
}
if(count<=k){
cout<<"Yes"<<endl;  
}else {
cout<<"No"<<endl;  
}
}



Measured memory_bytes: 3608
#include <iostream>

using namespace std;

#define MIN(a,b) ((a)<(b)?(a):(b))

int main()
{
    int P;
    int minR=200,minS=200;
    int total=0;

    for(int i=0; i<4; ++i) {
        cin >> P;
        total+=P;
        minR=MIN(P,minR);
    }
    for(int i=0; i<2; ++i) {
        cin >> P;
        total+=P;
        minS=MIN(P,minS);
    }
    cout << total - minR - minS << endl;
    return 0;
}

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

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int INF = 1000000000;
const ll LINF = (ll) 4000000000000000000;
const ll MOD = (ll) 1000000007;
const double PI = acos(1.0);
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define repll3(i,n) REPLL(i,0,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())
#define Size(s) (int) s.size()

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

int main() {
    ll a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;

    ll cost1 = a * x + b * y;
    ll cost2 = 2 * c * max(x, y);
    ll cost3 = (x - y >= 0 ? a * (x - y) + 2 * c * y : LINF);
    ll cost4 = (y - x >= 0 ? b * (y - x) + 2 * c * x : LINF);

    cout << min({cost1, cost2, cost3, cost4}) << endl;

    return 0;
}

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

signed main () {
	int n, m;
	cin >> n >> m;
	vector < pair < int, int > > oneoff(n);
	for (int i = 0; i < n; ++i) 
		cin >> oneoff[i].second >> oneoff[i].first;
	sort(oneoff.rbegin(), oneoff.rend());
	set < int > days;
	for (int i = 0; i <= m; ++i)
		days.insert(i);
	int64_t ans = 0;
	for (int i = 0; i < n; ++i) {
		int a = oneoff[i].second, b = oneoff[i].first;
		if (a <= m) {
			auto j = days.upper_bound(m - a);
			if (!days.empty() && j != days.begin()) {
				days.erase(prev(j));
				ans += b;
			}
		}
	}
	cout << ans << '\n';
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
using ull =unsigned long long;
const ll INF =1001001001;

//10億7。　　　100000007

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}


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


 string A,s,C;
  cin>>A>>s>>C;
  cout<<"A"<<s[0]<<"C"<<endl;

  
  
  
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-
H, W = list(map(int, input().split()))

c = [[0 for i in range(10)] for j in range(10)]
for i in range(10):
    line = list(map(int, input().split()))
    for j in range(10):
        c[i][j] = line[j]

A = [[0 for j in range(W)] for i in range(H)]
for i in range(H):
    line = list(map(int, input().split()))
    for j in range(W):
        A[i][j] = line[j]

for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min(c[i][j], c[i][k] + c[k][j])

total = 0
for i in range(H):
    for j in range(W):
        if A[i][j] != -1:
            total += c[A[i][j]][1]

print(total)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
#define ll long long
using namespace std;
struct aaa{
	int x,y,w,id;
}a[200010],b[200010];
int n,ans,cnt,fa[200010];
bool cmpx(aaa a,aaa b){
	return a.x<b.x;
}
bool cmpy(aaa a,aaa b){
	return a.y<b.y;
}
bool cmp(aaa a,aaa b){
	return a.w<b.w;
}
int find(int x){
	if(x==fa[x])return x;
	return fa[x]=find(fa[x]);
}
int main(){
	int i,x,y;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d%d",&a[i].x,&a[i].y);
		a[i].id=i;
	}
	sort(a+1,a+n+1,cmpx);
	for(i=1;i<n;i++)b[++cnt].x=a[i].id,b[cnt].y=a[i+1].id,b[cnt].w=min(abs(a[i].x-a[i+1].x),abs(a[i].y-a[i+1].y));
	sort(a+1,a+n+1,cmpy);
	for(i=1;i<n;i++)b[++cnt].x=a[i].id,b[cnt].y=a[i+1].id,b[cnt].w=min(abs(a[i].x-a[i+1].x),abs(a[i].y-a[i+1].y));
	sort(b+1,b+cnt+1,cmp);
	for(i=1;i<=cnt;i++)fa[i]=i;
	for(i=1;i<=cnt;i++){
		x=find(b[i].x);y=find(b[i].y);
		if(x!=y){
			fa[x]=y;ans+=b[i].w;
		}
	}
	printf("%d",ans);
}

Measured memory_bytes: 6400
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))
tmp = 10 ** 10
for i in range(N):
    if tmp > abs(A - T + H[i]*0.006):
        tmp = abs(A - T + H[i]*0.006)
        res = i
print(res+1)
    

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define AB_BHI_NI_DEGI ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define N 500009
#define inf 1e18
//int mod=1e9+7;
int mod=998244353;
#define P pair<int,int>
#define F first
#define S second
#define ll long long
#define all(v) v.begin(),v.end()

#define ordered_set tree<P, null_type,less<P>, rb_tree_tag,tree_order_statistics_node_update> 

void end(int n=-1){
	cout<<n<<"\n";exit(0);
}
int n;
int a[N][4];
int dp[N][4];
int fun(int i,int j){
	if(i>n){
		return 0;
	}
	int &ans=dp[i][j];
	if(ans!=-1)return ans;
	for(int k=0;k<3;k++){
		if(k!=j){
			ans=max(ans,fun(i+1,k)+a[i][k]);
		}
	}
	return ans;
}

int32_t main(){
    AB_BHI_NI_DEGI
	cin>>n;
	for(int i=1;i<=n;i++)
		for(int j=0;j<3;j++)
			cin>>a[i][j];
	memset(dp,-1,sizeof(dp));
	int ans=-1;
	for(int i=0;i<3;i++){
		ans=max(ans,fun(2,i)+a[1][i]);
	}
	cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 30144
use std::io;


/// 22:23 ~ 22:53
fn main() {
    let mut n = read_one::<isize>();
    let mut buf = Vec::new();
    if n == 0 { println!("0"); return; }
    while n != 0 {
        if n % 2 != 0 {
            buf.push("1");
            n -= 1;
        } else { buf.push("0"); }
        n /= -2;
    }

    for c in buf.iter().rev() {
        print!("{}", c);
    }
    println!();
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 4352
N = int(input())
# iが何回出現するか考える
# 1 -> 1,2,3,4
# 2 -> 2,4
# 3 -> 3
ans = 0
for i in range(1, N+1):
    ans += i*(N//i)*(N//i+1)//2
print(ans)

Measured memory_bytes: 63276
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>

using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;


int n;

int main(){

    cin >> n;
    int ans = 0;

    for(int i = 1; i <= n; i++){
        int tmp = i;
        int c = 0;

        while(tmp){
            tmp /= 10;
            c++;
        }

        if(c%2) ans++;
    }

    cout << ans << endl;

    return 0;
}

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

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i,h) cin >> c.at(i);
    int ans = 0;
    for(int i = 0; i < (1 << h);i++){
        bitset<6> sh(i);
        vector<string> tmp1 = c;
        for(int l = 0;l < 6;l++){
            if(!sh.test(l)) continue;
            for(int m = 0; m < w;m++) tmp1.at(l).at(m) = 'r';
        }
        for(int j = 0; j < (1 << w);j++){
            bitset<6> sw(j);
            vector<string> tmp2 = tmp1;
            for(int l = 0;l < 6;l++){
                if(!sw.test(l)) continue;
                for(int m = 0; m < h;m++) tmp2.at(m).at(l) = 'r';
            }
            int count = 0;
            rep(y,h)rep(x,w) if(tmp2.at(y).at(x) == '#') count++;
            if(count == k) ans++; 
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<cstdio>
using namespace std;

map<int,int>mp[5];
int D[40][40],cost[5][40],ans=pow(10,9);
vector<int> v;

void func(const set<int> S,int i,int sum,vector<int> color){
    
    for(auto s:S){
        int x=sum;
        vector<int> vec=color;
        x+=cost[i][s];

        if(i==2){
            if(s!=color[0]&&s!=color[1]&&color[0]!=color[1])
                ans=min(ans,x);
            continue;
        }
        vec.push_back(s);
        func(S,i+1,x,vec);
    }
}

int main(){
    int N,C;cin>>N>>C;
    set<int> Set;
    for(int i=1;i<=C;i++){
        Set.insert(i);
        for(int j=1;j<=C;j++)
            cin>>D[i][j];
    }
    
    int c;
    for(int i=1;i<=N;i++){
        for(int j=1;j<=N;j++){
            cin>>c;
            mp[(i+j)%3][c]++;
        }
    }

    for(int i=0;i<3;i++){
        for(int c=1;c<=C;c++){
            cost[i][c]=0;
            for(auto itr=mp[i].begin();itr!=mp[i].end();itr++)
                cost[i][c]+=itr->second*D[itr->first][c];
        }
    }

    func(Set,0,0,v);
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool p[1000001];
int main(){
	for(int i=2;i*i<1000001;i++)if(!p[i])for(int j=i+i;j<1000001;j+=i)p[j]=1;
	int a,b,sa,sb,mfa,mfb;
	while(cin>>a>>b,a){
		sa=sb=0;
		for(int i=2;i<=a;i++)if(!p[i]&&a%i==0)sa+=(mfa=i);
		for(int i=2;i<=b;i++)if(!p[i]&&b%i==0)sb+=(mfb=i);
		cout<<(2*mfa-sa>2*mfb-sb?'a':'b')<<endl;
	}
	return 0;
}

Measured memory_bytes: 1832
#include <stdio.h>

int main()
{
	int N, K, X, Y;
	
	scanf("%d %d %d %d", &N, &K, &X, &Y);
	
	if(N<=K) printf("%d\n", N*X);
	else printf("%d\n", K*X + (N-K)*Y);
	
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int maxx=1e6+10;
int dp[maxx];
int in[maxx];
int main(){
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&in[i]);
	}
	dp[0]=0;
	dp[1]=abs(in[1]-in[0]);
	for(int i=2;i<n;i++){
		int temp1=abs(in[i]-in[i-1]);
		int temp2=abs(in[i]-in[i-2]);
		dp[i]=min(temp1+dp[i-1],temp2+dp[i-2]);
	}
	printf("%d",dp[n-1]);
}

Measured memory_bytes: 4736
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE BlockArguments #-}
import Control.Monad
import Data.Maybe
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.ByteString.Char8 as BS

tuplify2 (x:y:_) = (x,y)
tuplify2 _ = undefined

--Input functions with ByteString
readInt = fst . fromJust . BS.readInteger
readIntTuple = tuplify2 . map readInt . BS.words
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntNList n = map readIntList <$> replicateM (fromIntegral n) BS.getLine
getIntMatrix = map readIntList . BS.lines <$> BS.getContents
getIntTuple = readIntTuple <$> BS.getLine
getIntNTuples n = map readIntTuple <$> replicateM (fromIntegral n) BS.getLine
getIntTuples = map readIntTuple . BS.lines <$> BS.getContents


main = do
  n <- readLn @Int
  as <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

  let v :: U.Vector Int
      v = U.create do
        v <- UM.replicate n 0
        forM_ as \a -> UM.modify v (+ 1) (a - 1)
        return v
  U.forM_ v \n -> print n

Measured memory_bytes: 9912
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;

int stackReturn(stack<int> *S){
	int x = (*S).top();
	(*S).pop();
	return x;
}

int main(){
	stack<int> S;
	string str;
	int a;

	while(cin>>str){
		if(str == "+")
			S.push(stackReturn(&S) + stackReturn(&S));
		else if(str == "-"){
			a = stackReturn(&S);
			S.push(stackReturn(&S) - a);
		}else if(str == "*")
			S.push(stackReturn(&S) * stackReturn(&S));
		else
			S.push(atoi(str.c_str()));
	}

	cout<<S.top()<<endl;

	return 0;
}

Measured memory_bytes: 1200
#define _USE_MATH_DEFINES

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <vector>

using namespace std;

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

	int a = 0;
	for (int i = 0; i < s.length(); i++)
	{
		if (s.substr(i, 1) == "+")
		{
			a++;
		}
		else
		{
			a--;
		}
	}

	cout << a << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <iomanip>
#include <iostream>

using namespace std;

int main()
{
	int n;

	while (true)
	{
		cin >> n;

		if (n == 0) { break; }

		vector<vector<int> > R(n + 1, vector<int>(n + 1, 0));

		for (int i = 0; i < n; i++)
		{
			for (int j = 0; j < n; j++)
			{
				cin >> R[i][j];
			}
		}

		for (int i = 0; i <= n; i++)
		{
			int sum1 = 0;
			int sum2 = 0;

			for (int j = 0; j < n; j++)
			{
				sum1 += R[i][j];
				sum2 += R[j][i];
			}

			R[i][n] = sum1;
			R[n][i] = sum2;
		}

		for (int i = 0; i <= n; i++)
		{
			for (int j = 0; j <= n; j++)
			{
				cout << setw(5) << R[i][j];
			}

			cout << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3032
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
int pris[100000+3],cnt;
int mindiv[100000+3];
int a[100000+3];
void solve(int n){
	for(int i=2;i<=n;i++){
		if(!mindiv[i])
			mindiv[i]=pris[++cnt]=i;
		for(int j=1,k;j<=cnt&&(k=i*pris[j])<=n;j++){
			mindiv[k]=pris[j];
			if(i%pris[j]==0)break;
		}
	}
}
bool isp(int x){
    return mindiv[x]==x;
}
bool check(int x){
    if(x&1==0)return false;
    return isp(x) && isp((x+1)>>1);
}
int main(){
    solve(100000);
    for(int i=1;i<=100000;i++)a[i]=a[i-1]+check(i);
    int T;cin>>T;
    while(T--){
        int l,r;cin>>l>>r;
        cout<<a[r]-a[l-1]<<endl;
    }
    return 0;
}

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

int main() {
string s,t;
int ans =0;
  cin >> s >> t;
  for(int i=0; i<s.size(); i++){
    if (s.at(i) != t.at(i)){
      ans ++;
    }
  }
  cout << ans <<endl;
}


Measured memory_bytes: 3864
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll h = in(), w = in();
	REP(i, h) {
		REP(j, w) {
			string s; cin >> s;
			if (s == "snuke") {
				cout << (char)('A' + j) << i + 1 << endl;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
import itertools
s=input()
n=len(s)
l=list(itertools.product(range(2),repeat=n-1))
tl=[]
for i in range(len(l)):
    t=s[0]
    for j in range(n-1):
        if l[i][j]==1:
            t+='+'
        t+=s[j+1]
    tl.append(t)
print(sum(map(eval,tl)))

Measured memory_bytes: 3188
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

ll dp1[110][40000];
ll dp2[110][40000];
int main(){
	ll n,k;
	scanf("%lld%lld",&n,&k);
	ll sqN=sqrt(n);
	int n1=sqN;
	int n2=sqN-1+(sqN*(sqN+1)<=n);
	rep(i,1,n1+1)dp1[1][i]=1;
	rep(i,1,n2+1)dp2[1][i]=n/i-n/(i+1);
	rep(c,1,k){
		ll m=0;
		rep(i,1,n1+1)m=(m+dp1[c][i])%MOD;
		rep(i,1,n1+1)dp1[c+1][i]=m;
		for(int i=n2;i>=1;i--){
			m=(m-dp1[c][i+1])%MOD;
			dp2[c+1][i]=m*(n/i-n/(i+1))%MOD;
		}
		ll M=0;
		rep(i,1,n2+1)M=(M+dp2[c][i])%MOD;
		rep(i,1,n1+1){
			dp1[c+1][i]=(dp1[c+1][i]+M)%MOD;
			M=(M-dp2[c][i])%MOD;
		}
	}
	ll ans=0;
	rep(i,1,n1+1)ans=(ans+dp1[k][i])%MOD;
	rep(i,1,n2+1)ans=(ans+dp2[k][i])%MOD;
	printf("%lld",(ans+MOD)%MOD);
}


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

int main()
{
  string s;
  int k;
  cin>>k;
  cin>>s;
  int len = s.size();
  if(len<=k)
  {
      cout<<s<<endl;
  }
  else
  {
      for(int i = 0; i < k; i++)
      {
          cout<<s[i];
      }
      cout<<"...\n";
  }

  return 0;
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL)
using namespace std;
typedef long long ll;


vector<ll> Songs(200010);
unordered_map<ll, ll> indexes;
unordered_set<ll> indx;

int main(){
    fast_io();
    string N;
    cin >> N;
    bool flag = false;
    rep(i,N.size()){
        if(N[i] == '7') flag = true;
    }
    cout << (flag? "Yes\n" : "No\n");
    return 0;
}


Measured memory_bytes: 4612
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>

#define MAX_W 90
#define MAX_H 90

using namespace std;

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

int width,height;
bool field[MAX_W][MAX_H];

int ans;

void solve(int sx,int sy,int sum){
	if(sx >= width || sx < 0) return ;
	if(sy >= height || sy < 0) return ;
	bool now = field[sx][sy];
	if(now){
		field[sx][sy] = false;
		ans = max(ans,sum + 1);
		for(int i = 0;i < 4;i++){
			solve(sx + dx[i],sy + dy[i],sum + 1);
		}
		field[sx][sy] = true;
	}
	return ;
}

int main (){

	while(true){

	scanf("%d%d",&width,&height);
	if(width == 0 && height == 0) break;
	int fake;
	for(int i = 0;i < width;i++){
		for(int j = 0;j < height;j++){
			scanf("%d",&fake);
			field[i][j] = (fake == 1);
		}
	}

	ans = 0;
	for(int i = 0;i < width;i++){
		for(int j = 0;j < height;j++){
			solve(i,j,0);
		}
	}
	printf("%d\n",ans);

	}

	return 0;

}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  
  if(N%2 == 0 && N <= 18){
    cout << "Yes" << endl;
  }
  else if(N <= 9){
    cout <<"Yes" << endl;
  }
  else if(N%3 == 0 && N <=27){
    cout << "Yes" << endl;
  }
  else if(N%4 == 0 && N <=36){
    cout << "Yes" << endl;
  }
  else if(N%5 == 0 && N <=45 ){
    cout << "Yes" << endl;
  }
  else if(N%6 == 0 && N <=54){
    cout << "Yes" << endl;
  }
  else if(N%7 ==0 && N <= 63){
    cout << "Yes" << endl;
  }
   else if(N%8 == 0 && N <=72){
    cout << "Yes" << endl;
  }
   else if(N%9 == 0 && N <=81){
    cout << "Yes" << endl;
  }
  else if(N == 1){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

  
  

Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10, gcd
from itertools import permutations, combinations, product, accumulate, combinations_with_replacement
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
#from fractions import gcd
from decimal import *
import heapq
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

d, t, s = MAP()
if d > s * t:
    print('No')
else:
    print('Yes')

Measured memory_bytes: 72688
def convert(S):
    cur = 0
    def parse():
        nonlocal cur
        if S[cur] == ')':
            return ()
        cur += 1 # '('
        left = parse()
        cur += 2 # ')['
        num = 0
        while S[cur] != ']':
            num = 10*num + int(S[cur])
            cur += 1
        cur += 2 # ']('
        right = parse()
        cur += 1 # ')'
        return left, num, right
    return parse()
def dfs(A, B):
    if not A or not B:
        return ()
    return (dfs(A[0], B[0]), [A[1] + B[1]], dfs(A[2], B[2]))
print(str(dfs(convert(input()), convert(input()))).replace(", ","")[1:-1])

Measured memory_bytes: 7804
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int len=s.length();
	int flag=1;
	for(int i=0;i<len;i++){
		if((i+1)%2==1){
			if(s[i]=='R'||s[i]=='U'||s[i]=='D')
				continue;
			else{
				flag=0;
				break;
			}
		}else{
			if(s[i]=='L'||s[i]=='U'||s[i]=='D')
				continue;
			else{
				flag=0;
				break;
			}
		}
	}
	if(flag==1)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int d1,d2,n;
int a[5005][5005];
int gao(int d)
{
	int b=0;
	while(d%4==0)
	{
		d/=4;
		b++;
	}
	if(d&1)
	{
		for(int i=0;i<2*n;i++)
		for(int j=0;j<2*n;j++)
		if(((i>>b)+(j>>b))&1)
		a[i][j]=1;
	}
	else 
	{
		for(int i=0;i<2*n;i++)
		for(int j=0;j<2*n;j++)
		if((i>>b)&1)
		a[i][j]=1;
	}
}
int z=0;
int main()
{
	cin>>n>>d1>>d2;
	gao(d1);gao(d2);
	for(int i=0;i<2*n;i++)
	for(int j=0;j<2*n;j++)
	if(!a[i][j]&&z<n*n)
	{
		cout<<i<<' '<<j<<endl;
		z++;
	}
	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
using namespace std;
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
Apparently, the tree supports the same operations as the set 
(at least I haven't any problems with them before), but also there are two new features — 
find_by_order() — The first returns an iterator to the k-th largest element (counting from zero)
order_of_key() — the number of items in a set that are strictly smaller than our item. 
https://codeforces.com/blog/entry/11080
using namespace __gnu_pbds; */
using namespace std;
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define int long long
// #define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ld long double
#define endl '\n'
int m(int a, int MOD) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b, int MOD) {
    int res = 1;
    while(b > 0){
        if(b&1) res = m(m(res, MOD)*m(a, MOD), MOD);
        a = m(m(a, MOD)*m(a, MOD), MOD);
        b >>= 1;
    }
    return res;
} 
signed main(){
    fast();
    int n;
    cin >> n;
    string s;
    cin >> s;
    set<int> st, st2;
    int w = 0, r = 0, ans;
    for(int i=0; i<n; i++){
        if(s[i] == 'W'){
            w++;
            st.ins(i);
        }
        else{
            r++;
        }
    }
    int other = 0, other2 = 0;
    string s2 = s;
    ans = min(w, r);
    for(int i=n-1; i>=0; i--){
        if(s[i] == 'R'){
            if(st.lower_bound(0) != st.end()){
                int ind = *st.lower_bound(0);
                if(i > ind){
                    swap(s[ind], s[i]);
                    st.erase(ind);
                    other++;
                }
                else break;
            }
            else break;
        }
    }
    cout << min(other, ans) << endl;
    cerr << "\nTime elapsed : " << 1000 * clock() / CLOCKS_PER_SEC << " ms\n";
}

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

int main()
{
    int n;
    cin>>n;
    int arr[n][2];
    for(int i=0;i<n;i++){
        cin>>arr[i][0]>>arr[i][1];
    }
    int thre = 0;
    for(int i=0;i<n;i++){
        if(arr[i][0]==arr[i][1]){
            thre++;
            if(thre==3){
                break;
            }
        }
        else{
            thre=0;
        }
    }
    if(thre==3){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }


    return 0;
}


Measured memory_bytes: 3616
#pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#if __cplusplus >= 201103L
#include <chrono>
using namespace std::chrono;
#endif
using namespace std;
#define ll long long
#define ull unsigned long long
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#ifdef LOCAL
#define prln(x) (cout << #x << ' ' << x << endl)
#define pr(x) (cout << #x << ' ' << x << ' ' )
#define prv(x) (cout << x << ' ')
#else
#define prln(x) 
#define pr(x)
#define prv(x)
#endif
#define clr(x) memset((x), 0, sizeof((x)))
#define clr1(x) memset((x), -1, sizeof((x)))
#define endl "\n"
#define pi acos(-1)
#define rep(i, st, ed) for (int i = (st); i <= (ed); ++i)
#define rep0(i, st, ed) for (int i = (st); i < (ed); ++i)
#define per0(i, st, ed) for (int i = (st); i > ed; --i)
#define per(i, st, ed) for (int i = (st); i >= ed; --i)
#define chmin(a, b) (a = a > b ? b : a)
#define chmax(a, b) (a = a < b ? b : a)
template<class T> void _sf(T &x) {cin >> x;}
void _sf(int &x) {scanf("%d", &x);}
void _sf(ll &x) {scanf("%lld", &x);}
void _sf(double &x) {scanf("%lf", &x);}
void _sf(char &x) {scanf(" %c", &x);}
void _sf(char *x) {scanf("%s", x);}
void sf() {}
template <class T, class...U> void sf(T & head, U&... tail) { _sf(head); sf(tail...);}
template<class T> void _out(const T &x) { cout << x; }
void _out(const int &x) { printf("%d", x); }
void _out(const ll &x) { printf("%lld", x); }
void _out(const double &x) { printf("%.16f", x); }
void _out(const char &x) { putchar(x); }
void _out(const char *x) { printf("%s", x); }
template<class T,class U> void _out(const pair<T,U> &x) {_out(x.F); putchar(' '); _out(x.S);}
template<class T> void _out(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _out(*i++)) if (i != x.cbegin()) putchar(' '); }
void out() {}
template<class T, class... U> void out(const T &head, const U &... tail) { _out(head); putchar(sizeof...(tail) ? ' ' : '\n'); out(tail...); }
const int mod = 1e9 + 7;
const int INF = 0x3f3f3f3f;

int read() {
    int x = 0, f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') {
        if (ch == '-') f = -1;
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9') {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
const int maxn = 1e5 + 5;
int a[maxn];

int main(){
    #ifdef LOCAL
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
    int n;
    sf(n);
    rep(i, 1, n) {
        sf(a[i]);
    }
    int cnt  = 0;
    rep(i, 1, n) {
        prln(a[i]);
        if ((i & 1) && (a[i] & 1)) {
            ++cnt;
        }
    }
    out(cnt);
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <stack>
#include <string>
#include <sstream>

using namespace std;

int main(){
  string str;
  stack<int> s;
  while(cin>>str){
    if(str == "+"){
      int s1 = s.top(); s.pop();
      int s2 = s.top(); s.pop();
      s.push(s1+s2);
    }
    else if(str == "-"){
      int s1 = s.top(); s.pop();
      int s2 = s.top(); s.pop();
      s.push(s2-s1);
    }
    else if(str == "*"){
      int s1 = s.top(); s.pop();
      int s2 = s.top(); s.pop();
      s.push(s1*s2);
    }
    else{
      stringstream ss(str);
      int x; ss >> x;
      s.push(x);
    }
  }
  cout << s.top() << endl;

  return 0;
}

Measured memory_bytes: 1236
# 点数は全部100で割った状態で扱う
D, G = map(int, input().split())
G //= 100
pc = []
for d in range(D):
  p, c = map(int, input().split())
  pc.append([p, c//100])


ans = 10 ** 4
# 各配点の問題に対して全問解くかどうかを全探索
for i in range(2**D):
  points = 0
  num = 0
  idx = -1
  for d in range(D):
    # bitで1が立ってる配点の問題は全問解く
    if i>>d & 1:
      points += pc[d][0]*(d+1) + pc[d][1]
      num += pc[d][0]
    else:
      idx = d
  if points >= G:
    ans = min(ans, num)
  elif idx >= 0: # これまでで点数が足りない場合、まだ解いていない問題で最も配点の高い問題で補填する
    num_add = - (- (G - points) // (idx + 1))
    if num_add <= pc[idx][0]:
      ans = min(ans, num + num_add)

print(ans)

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int w;
	int h;
	int x;
	int y;
	int r;

	scanf("%d%d%d%d%d", &w, &h, &x, &y, &r);

	if( x<-100 || x>100 || y<-100 || y>100 || w<0 || w>100 || h<0 || h>100 || r<0 || r>100 )
	{
		return 1;
	}

	if(x-r<0 || y-r<0 || w-x<r || h-y<r)
	{
		printf("No\n");
	}
	else
	{
		printf("Yes\n");
	}

	return 0;
}

Measured memory_bytes: 584
using System;
using System.Collections;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{

	//Main
	static void Main(string[] args)
	{
		//読み込む
		int N = int.Parse(Console.ReadLine());
		int[] An = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();

		//バケツを用意
		int[] bucket = new int[N];

		//バケツに放り込む（AnはN-1項しかないことに注意）
		for(int i=0; i<N-1; i++){
				int idx = An[i] - 1;
				bucket[idx]++;
		}

		foreach(int num in bucket){
				Console.WriteLine(num);
		}
	}
}



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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(base, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
ll N;

ll find_5s(ll n)
{
    if(n < 5)
    {
        return 0LL;
    }
    return n/5 + find_5s(n/5);
}

int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> N;
    ll ans;
    if(N%2 == 1)
        ans = 0;
    else
        ans = find_5s(N/2);
    cout << ans;
    return 0;
}


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

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<double, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<ll> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}


bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);

//const ll mod = 1e10;
//typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;

class CumulativeSum {
    vector<ll> numbers;
    vector<ll> sums;

public:
    CumulativeSum(int n) {
        numbers.resize(n);
        sums.resize(n);
    }

    void set(int i, ll value) {
        numbers[i] = value;
    }

    ll getSum(int i) {
        if (i == -1) return 0;
        if (i == sums.size()) return sums.back();
        return sums[i];
    }

    ll getSectionSum(int start, int end) {
        return getSum(end) - getSum(start - 1);
    }

    void calculate() {
        for (int i = 0; i < numbers.size(); i++) {
            sums[i] = getSum(i - 1) + numbers[i];
        }
    }

};

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

    vector<ll> v(n);
    rep(i, n) cin >> v[i];

    CumulativeSum cs1(n), cs2(n);
    rep(i, n) cs1.set(i, v[i]);
    rep(i, n) cs2.set(i, max<ll>(v[i], 0));
    cs1.calculate();
    cs2.calculate();

    ll ans = -INF;
    for (int i = 0; i <= n - k; i++) {
        ll l = cs2.getSectionSum(0, i - 1);
        ll r = cs2.getSectionSum(i + k, n - 1);
        ll c = max<ll>(cs1.getSectionSum(i, i + k - 1), 0);
        ll now = l + r + c;
        cmax(ans, now);
    }
    cout << ans << endl;

}

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

int n;
vector<int> color;
struct Edge{
  int to; int id;
};
vector<vector<Edge> > graph;

void dfs(int v, int p, int c){

  int n = 0;
  rep(i,graph[v].size()){
    int u = graph[v][i].to; int ei = graph[v][i].id;
    if(u == p) continue;
    if(n == c) ++n;
    color[ei] = n;
    dfs(u, v, n);
    ++n;
  }

  return;
}

int main(){

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

  int k = 0;
  rep(i,n){
    int s = graph[i].size();
    k = max(k, s);
  }
  cout << k << endl;

  color.resize(n-1);
  dfs(0,-1,-1);
  rep(i,n-1){
    int ans = ++color[i];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 8320