akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
	int n,a,i,min,max;
	long sum;
	
	scanf("%d",&n);
	for (i=1; i<=n; i++) {
		scanf("%d",&a);
		if(i==1) {
			min = max = sum = a;
		} else {
			sum += a;
			if(min > a) min = a;
			if(max < a) max = a;
		}
	}
	printf("%d %d %ld\n",min,max,sum);
	return 0;
}

Measured memory_bytes: 600
#include <stdio.h>

int main(){
  int N,i,num,Min,Max=0;


  scanf("%d",&N);
  scanf("%d",&num);
  Min=num;
  scanf("%d",&num);
  Max=num-Min;
  if(Min>num)Min=num;
  for(i=2;i<N;i++){
    scanf("%d",&num);
    if(Max<num-Min)Max=num-Min;
    if(Min>num)Min=num;
  }
  printf("%d\n",Max);
  
  return 0;
}

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


int main() {
	//code
	//cout<<"ashish"<<endl;
	int n,k;
	cin>>n>>k;
	int a[n];
	for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    int sum=0;
    for(int i=0;i<k;i++)
        sum+=a[i];
    cout<<sum;
	return 0;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
const double INF3 = 900000000000000;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()

struct edge { int to; double cost;};
vector<edge>v[10100];
double d[10100];

int main() {
	ll sx, sy, gx, gy, x[10100], y[10100], r[10100];
	int n;
	double ans;
	cin >> sx >> sy >> gx >> gy >> n;
	for (int i = 1;i <= n;i++) {
		cin >> x[i] >> y[i] >> r[i];
	}
	x[0] = sx, y[0] = sy, r[0] = 0, x[n + 1] = gx, y[n + 1] = gy, r[n + 1] = 0;
	for (int i = 0;i <= n + 1;i++) {
		for (int j = 0;j <= n + 1;j++) {
			if (i == j)continue;
			double c = max((long double)0, sqrtl((x[i] - x[j])*(x[i] - x[j]) + (y[i] - y[j])*(y[i] - y[j])) - (r[i] + r[j]));
			v[i].push_back(edge{ j,c });
			v[j].push_back(edge{ i,c });
		}
	}
	for (int i = 0;i <= n+1;i++) {
		d[i] = INF3;
	}
	d[0] = 0.0;
	std::priority_queue<P, std::vector<P>, std::greater<P>>pq;
	pq.push(make_pair(d[0], 0));
	while (!pq.empty()) {
		P a = pq.top();
		pq.pop();
		int i = a.second;
		if (d[i] < a.first)continue;
		for (int k = 0;k < v[i].size();k++) {
			edge e = v[i][k];
			if (d[e.to] <= d[i] + e.cost)continue;
			d[e.to] = d[i] + e.cost;
			pq.push(make_pair(d[e.to], e.to));
		}
	}
	std::cout << setprecision(24) <<  d[n + 1] << std::endl;

}

Measured memory_bytes: 39152
import java.util.Scanner;

class D {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final int M = sc.nextInt();
        long sum = 0;
        long ans = 0;
        for (int i = 0; i < M; i++) {
            final int d = sc.nextInt();
            final long c = sc.nextLong();
            sum += d * c;
            ans += c;
        }
        while(sum > 9) {
            ans += sum / 10;
            sum = sum % 10 + sum / 10;
        }
        System.out.println(ans - 1);
    }
}
public class Main {
    public static void main(String... args) {
        D.main();
    }
}


Measured memory_bytes: 94324
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<queue>
#include<list>
#include<stack>
//#include<unordered_map>
using namespace std;
#define ll long long
#define dd cout<<endl
const long long int inf = 1e18+7;
const int mod = 998244353;

using namespace std;

inline ll int max(ll int a,ll int b) { return a>b?a:b; }
inline ll int min(ll int a,ll int b) { return a<b?a:b; }

//const int maxn=

int main()
{
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	
	ll int k;
	
	while(cin>>k)
	{
		ll int to=k<<1;
		
		int flag=-1;
		
		ll int m=9*k;
		
		ll int base=10; 
		
		for(int i=1;i<=to;i++)
		{
			if( 7 * ( base + m - 1 ) % m == 0 )
			{
				flag=i;
				break;
			}
			base*=10;
			base%=m;
		}
		
		cout<<flag<<endl;
	
	}
	
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  int a, b, c, d;
  a = n / 1000;
  b = (n - (a * 1000)) / 100;
  c = (n - (a * 1000) - (b * 100)) / 10;
  d = n % 10;
  bool f = false;

  if(a == b && b == c) f = true;
  else if(b == c && c == d) f = true;

  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mo 1000000007
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,i,j,zz[100005],x,sum[100005],book[100005],book2[100005];
long long top2,sum2,zhan[100005],zhan2[100005],book3[100005],ans;
long long jc[100005],ny[100005],flag;
long long top,nex[100005],to[100005],fir[100005];
void lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
int ss(int v){
	int sum3=0;
	sum[v]=1-book2[v];
	for(int top1=fir[v];top1;top1=nex[top1])
		if(book2[to[top1]]==0){
			sum[v]+=ss(to[top1]);
			sum3++;
		}
	if(sum3>=2)
		flag=1;
	return sum[v];
}
long long ksm(long long u,long long v){
	long long o=1;
	while(v){
		if(v&1)
			o=o*u%mo;
		u=u*u%mo;
		v>>=1;
	}
	return o;
}
long long C(long long u,long long v){
	return jc[u]*ny[v]%mo*ny[u-v]%mo;
}
int main(){
	n=read();
	for(i=1;i<=n;i++){
		zz[i]=read();
		lj(zz[i],i);
	}
	jc[0]=1;
	for(i=1;i<=n;i++)
		jc[i]=jc[i-1]*i%mo;
	ny[n]=ksm(jc[n],mo-2);
	for(i=n-1;i>=0;i--)
		ny[i]=ny[i+1]*(i+1)%mo;
	for(i=1;i<=n;i++)
		if(book[i]==0){
			x=i;
			while(book[x]==0){
				book[x]=i;
				x=zz[x];
			}
			if(book[x]==i){
				while(book2[x]==0){
					book2[x]=1;
					x=zz[x];
				}
			}
		}
	ans=1;
	for(i=1;i<=n;i++)
		if(book2[i]==1)
			ss(i);
	if(flag==1){
		pus(0,2);
		return 0;
	}
	for(i=1;i<=n;i++)
		if(book2[i]==1){
			x=i;sum2=0;top2=0;
			while(book2[x]!=2){
				book2[x]=2;
				sum2++;
				if(sum[x]!=0){
					top2++;
					zhan[top2]=sum[x];
					zhan2[top2]=sum2;
				}
				x=zz[x];
			}
			if(top2!=0){
				zhan[top2+1]=zhan[1];
				zhan2[top2+1]=zhan2[1]+sum2;
				for(j=1;j<=top2;j++)
					if(zhan[j+1]<zhan2[j+1]-zhan2[j])
						ans=ans*2%mo;
					else if(zhan[j+1]>zhan2[j+1]-zhan2[j])
						ans=0;
			}
			else
				book3[sum2]++;
		}
	for(j=1;j<=n;j++){
		sum2=0;
		for(i=0;(i<<1)<=book3[j];i++)
			if((j&1)&&j!=1)
				sum2=(sum2+C(book3[j],i<<1)*jc[i<<1]%mo*ny[i]%mo*ksm(ksm(2,i),mo-2)%mo*ksm(j,i)%mo*ksm(2,book3[j]-(i<<1)))%mo;
			else
				sum2=(sum2+C(book3[j],i<<1)*jc[i<<1]%mo*ny[i]%mo*ksm(ksm(2,i),mo-2)%mo*ksm(j,i))%mo;
		ans=ans*sum2%mo;
	}
	pus(ans,2);
	return 0;
}

Measured memory_bytes: 11136
n,m,k=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))

tmp=0
ca=[0]
for ai in a:
  tmp+=ai
  ca.append(tmp)
tmp=0
cb=[0]
for bi in b:
  tmp+=bi
  cb.append(tmp)
import bisect
s=bisect.bisect_right(ca,k)-1
ans=ca[s]
now_a=s
z=k-ca[now_a]
now_b=bisect.bisect_right(cb,z)-1
t=ca[now_a]+cb[now_b]
#print(now_a,now_b)
ans=now_a+now_b
for i in range(s):
  now_a-=1
  t-=a[now_a]
  while now_b<m and t+b[now_b]<=k:
    t+=b[now_b]
    now_b+=1
  ans=max(ans,now_a+now_b)
print(ans)


Measured memory_bytes: 47164
mod = 10 ** 9 + 7
fib = [1, 1, 2, 3, 5, 8, 13, 21, 34]

H, W, K = map(int, input().split())

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

for _ in range(H):

    T = [0] * W

    for i in range(W):
        if 0 < i:
            T[i] += dp[i - 1] * fib[i - 1] * fib[W - i - 1]

        T[i] += dp[i] * fib[i] * fib[W - i - 1]

        if i < W - 1:
            T[i] += dp[i + 1] * fib[i] * fib[W - i - 2]

        T[i] %= mod

    dp = T

print(dp[K - 1])

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

#define int long long

using namespace std;

const int N = 2e5 + 5;

int n;
pair <int, int> a[N];

bool cmp (pair <int, int> &p1, pair <int, int> &p2) {
    return p1.first < p2.first;
}

bool cmp2 (pair <int, int> &p1, pair <int, int> &p2) {
    return p1.second < p2.second;
}

signed main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        int x, y;
        cin >> x >> y;
        a[i].first = x - y;
        a[i].second = x + y;
    }

    sort(a + 1, a + n + 1, cmp);
    int ans = max(abs(a[n].first - a[1].first), abs(a[n].second - a[1].second));
    sort(a + 1, a + n + 1, cmp2);
    ans = max(ans, max(abs(a[n].first - a[1].first), abs(a[n].second - a[1].second)));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 6732
N = int(input())
H = list(map(int, input().split()))

ans = "Yes"
for i in reversed(range(1, N)):
    if H[i-1] > H[i]:
        if H[i-1] - H[i] > 1:
            ans = "No"
            break
        else:
            H[i-1] -= 1

print(ans)
    


Measured memory_bytes: 14396
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) throws IOException {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		boolean[] b = new boolean[8];
		Arrays.fill(b, false);
		List<Integer> list = new ArrayList<>();
		Set<Integer> set = new HashSet<>();
		int c = 0;
		for(int i = 0 ; i < n; i++){
			list.add(scanner.nextInt());
		}

		for(int a : list){
			if(a < 400){
				set.add(1);
			}else if (a < 800) {
				set.add(2);
			}else if (a < 1200) {
				set.add(3);
			}else if (a < 1600) {
				set.add(4);
			}else if (a < 2000) {
				set.add(5);
			}else if (a < 2400) {
				set.add(6);
			}else if (a < 2800) {
				set.add(7);
			}else if (a < 3200) {
				set.add(8);
			}else {
				c++;
			}
		}
		c += set.size();
		if(set.size() == 0){
			System.out.println(1 + " " + c);
		}else {
			System.out.println(set.size() + " " + c);
		}
	}
}


Measured memory_bytes: 22100
#include <stdio.h>
#define MAX 10000

/*

\zFÌæÌÍið_{¼üj

{ÚÌüðø¢½Æ«ÉA¦éÌæÌÌÅåÍ
ið_|Pj{i¼üPj

*/

int main(void){
	int a[MAX+1], i;
	a[0]=1; for(i=1; i<=MAX; i++) a[i]=a[i-1]+i;
	while(~scanf("%d",&i)) printf("%d\n",a[i]);
	return 0;
}

Measured memory_bytes: 0
//
// Created by watemus on 02.05.2020.
//

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>

using namespace std;

#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff first
#define ss second

using ll = long long;
using ld = long double;
#define int ll

constexpr ll INFL = 1'000'000'000'000'000'228;
constexpr int INFI = 1'000'000'228;

#ifdef LOCAL
#else
#endif

void run() {
    int a, b, n;
    cin >> a >> b >> n;
    int x = n - n % b - 1;
    int ans = (a * n) / b - a * (n / b);
    if (x > 0) {
        ans = max(ans, (a * x) / b - a * (x / b));
    }
    cout << ans << '\n';
}

signed main() {
#ifdef LOCAL
    std::freopen("input.txt", "r", stdin);
#else
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
#endif
    int t = 1;
//    cin >> t;
    while (t--) {
        run();
    }
    return 0;
}

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

// N個のスイッチのon/offの状態は2^N通りでそれを全探索して条件に合致しているのかを調べる

int main() {
    int N, M; cin >> N >> M;
    vector<vector<int>> vec(M);
    for (int i = 0; i < M; i++) {
        int k; cin >> k;
        vec.at(i).resize(k);
        for (int j = 0; j < k; j++) {
            cin >> vec.at(i).at(j);
            vec.at(i).at(j)--;
        }
    }
    vector<int> p(M);
    for (int i = 0; i < M; i++) {
        cin >> p.at(i);
    }

    int ans = 0;
    for (int i = 0; i < (1 << N); i++) { // N個のスイッチの状態を整数にエンコードして全探索
        bool ok = true;
        for (int j = 0; j < M; j++) {
            int c = 0; // 電球jにつながっているスイッチの個数
            for (int id : vec.at(j)) {
                if (i & (1<<id)) { // ビット列iの右から数えてid番目の桁が立っているか
                    c++;
                }
            }
            c %= 2;
            if (c != p.at(j)) {
                ok = false;
            }
        }
        if (ok) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//25
#include<iostream>

using namespace std;

int main(){
  for(int n;cin>>n,n;){
    int m=0,mid;
    while(n--){
      int id,d,dd;
      cin>>id>>d>>dd;
      if(m<d+dd){
	m=d+dd;
	mid=id;
      }
    }
    cout<<mid<<' '<<m<<endl;
  }
  return 0;
}

Measured memory_bytes: 868
/*package whatever //do not write package name here */

import java.io.*;
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		
		int k=s.nextInt();
		if(k>n)
		System.out.println(0);
		else{
		int a[]=new int[n];
	long sum=0;
		for(int i=0;i<n;i++)
		{a[i]=s.nextInt();
		//sum+=a[i];
		    
		}
		Arrays.sort(a);
		for(int i=0;i<n-k;i++)
		sum+=a[i];
		
		
		
		System.out.println(sum);
		}
	}
}

Measured memory_bytes: 67248
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace B
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var s = Console.ReadLine();
            var count = 0;
            for (int i = 0, j = s.Length - 1; i < j; i++, j--)
            {
                if (s[i] != s[j]) count++;
            }
            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13140
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

public class Main {
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int m;
        int r = 0;
        try {
            String str = reader.readLine();
            r = Integer.parseInt(str);
        } catch (Exception e) {
            e.printStackTrace();
        }
        m = (int)Math.pow(r,2);
        System.out.println("" + m);
    }
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = ll(1e9 + 7);
ll gcd(ll a, ll b) {
	if(b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int p[100000];
int pos[100000];
int T[100000];
vector<ll> v[100000];

vector<int> idx[41];
vector<ll> add[41][41];
vector<ll> S[41][41];

ll sum(int l, int r, int t, int k) {
	ll ret = S[t][k][r];
	if(l - 1 >= 0) {
		ret += -S[t][k][l - 1] + MOD;
		ret %= MOD;
	}
	return ret;
}

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

	int N, Q;
	cin >> N >> Q;
	for(int i = 0; i < N; i++) {
		cin >> p[i];
		p[i]--;
	}

	for(int i = 0; i < N; i++) {
		int x = i;
		do {
			v[i].push_back(x + 1);
			x = p[x];
		} while(x != i);
		T[i] = v[i].size();
		pos[i] = idx[T[i]].size();
		idx[T[i]].push_back(i);
	}

	for(int t = 1; t <= 40; t++) {
		for(int k = 0; k <= t; k++) {
			S[t][k].assign(idx[t].size() + 1, 0);
			add[t][k].assign(idx[t].size() + 1, 0);
		}
	}

	for(int i = 0; i < N; i++) {
		for(int j = 0; j < T[i]; j++) {
			add[T[i]][j + 1][pos[i]] = v[i][j];
		}
	}

	for(int t = 1; t <= 40; t++) {
		for(int k = 0; k <= t; k++) {
			for(int i = 0; i < idx[t].size(); i++) {
				S[t][k][i] += add[t][k][i];
				S[t][k][i] %= MOD;
				S[t][k][i + 1] += S[t][k][i];
				S[t][k][i + 1] %= MOD;
			}
		}
		for(int i = 0; i < idx[t].size(); i++) {
			for(int k = 0; k < t; k++) {
				S[t][k + 1][i] += S[t][k][i];
				S[t][k + 1][i] %= MOD;
			}
		}
	}

	while(Q--) {
		int l, r;
		cin >> l >> r;
		l--, r--;
		ll LCM = 1;
		for(int t = 1; t <= 40; t++) {
			int pl = lower_bound(idx[t].begin(), idx[t].end(), l) - idx[t].begin();
			int pr = upper_bound(idx[t].begin(), idx[t].end(), r) - idx[t].begin();
			if(pl == pr) continue;
			LCM = lcm(LCM, t);
		}
		ll ans = 0;
		for(int t = 1; t <= 40; t++) {
			int pl = lower_bound(idx[t].begin(), idx[t].end(), l) - idx[t].begin();
			int pr = upper_bound(idx[t].begin(), idx[t].end(), r) - idx[t].begin();
			if(pl == pr) continue;
			pr--;
			ans += sum(pl, pr, t, t) * ((LCM / t) % MOD);
			ans %= MOD;
			ans += sum(pl, pr, t, LCM % t);
			ans %= MOD;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 122788
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<utility>
#include<cstdio>
#include<set>
#include<string>
#include<map>
#include<queue>
#include<stack>
#include <bitset>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,x,n) for (int i= x;i<n;i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using vi = vector<int>; 
using vvi = vector<vi>;
typedef pair<int,int> P;
string s;
int k;
ll INF = 10000000000000000;

int H,W;
int dh[]={1,0,-1,0};
int dw[]={0,1,0,-1};


int main(){
    cin >>H>>W;

    vector<string> grid(H);
    rep(i,H) cin >> grid[i];

    queue<P> q;
    vvi dist(H,vi(W,-1));

    if(grid[0][0] == '#'){
        cout << -1<<endl;
    }
    else{
    dist[0][0]=1;
    q.push(make_pair(0,0));

    while((!q.empty())&&(dist[H-1][W-1]==-1)){

        int  h =q.front().first;
        int  w =q.front().second;
        q.pop();

        rep(dir,4){
            int nh = h+dh[dir];
            int nw = w+dw[dir];

            if(nh<0||nw<0||nh==H||nw==W) continue;
            if(grid[nh][nw]=='#') continue;
            if(dist[nh][nw]!=-1) continue;

            dist[nh][nw] = dist[h][w] +1;
            q.push(make_pair(nh,nw));
        }

    }

    if(dist[H-1][W-1]==-1) cout << -1 <<endl;
    else{
        int sum;
        sum = 0;
        rep(i,H){
            rep(j,W){
                if (grid[i][j]=='.') sum++;
            }
        }
        cout << sum - dist[H-1][W-1]<<endl;
    }
    }
}

Measured memory_bytes: 256
// C++(GCC 9.2.1)
// 解き直し.
// https://img.atcoder.jp/abc173/editorial.pdf
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define repex(i, a, b, c) for(int i = a; i < b; i += c)
#define repx(i, a, b) repex(i, a, b, 1)
#define rep(i, n) repx(i, 0, n)
#define repr(i, a, b) for(int i = a; i >= b; i--)

int main(){
    
    // 1. 入力情報.
    LL N, u, v, uv = 0;
    scanf("%lld", &N);
    rep(i, (int)(N - 1)){
        scanf("%lld %lld", &u, &v);
        
        // 大小関係を考慮.
        if(u > v) swap(u, v);
        
        // 辺の出現数をカウント.
        // 辺 uv は, {(u - 1 + 1) * (N - v + 1)}回分, 頂点集合 S に含まれるはず.
        uv += u * (N - v + 1);
    }
    
    // 2. 部分グラフの連結成分の個数の総和.
    // -> 頂点集合 S におけるすべての頂点の出現数の総和は, 
    // 1, 4, 10, 20, 35, 56, ... と 増加するので, N * (N + 1) * (N + 2) / 6 で 計算されるはず.
    LL ans = N * (N + 1) * (N + 2) / 6 - uv;
    
    // 3. 出力.
    printf("%lld\n", ans);
    return 0;

}

Measured memory_bytes: 3836
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
const int MOD=1000000007;
const int INF=0x3f3f3f3f;
const ll INFL=0x3f3f3f3f3f3f3f3f;
ll gcd(ll x, ll y){
  if(y==0) return x;
  else return gcd(y, x%y);
}
ll lcm(ll x,ll y){
  ll g=gcd(x,y);
  return x/g*y;
}




int main(){  
  string s;
  cin >> s;
  if(s[0]=='S'){
    if(s[1]=='U') cout << 7 << endl;
    else cout << 1 << endl;
  }
  if(s[0]=='M') cout << 6 << endl;
  if(s[0]=='T'){
    if(s[1]=='U') cout << 5 << endl;
    else cout<< 3 << endl;
  }
  if(s[0]=='W') cout << 4 << endl;
  if(s[0]=='F') cout << 2 << endl;
 
  
}


Measured memory_bytes: 764
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        // boolean[][] isFriend = new boolean[n][n]; // 100000 * 100000 大丈夫? -> いいえ
        @SuppressWarnings("unchecked")
        ArrayList<Integer>[] g = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            g[i] = new ArrayList<Integer>();
        }

        for (int i = 0; i < m; i++) {
            int f1 = sc.nextInt();
            int f2 = sc.nextInt();
            g[f1].add(f2);
            g[f2].add(f1);
        }

        // Connected Component Number 
        int[] ccNum = makeCCNum(g, n);
//        UArr.printArr(ccNum);
        
        int q = sc.nextInt();
        for (int i = 0; i < q; i++) {
            int f1 = sc.nextInt();
            int f2 = sc.nextInt();
            System.out.println(ccNum[f1] == ccNum[f2] ? "yes" : "no");
        }
    }

    // 1つの連結成分につき1つ番号を与える。同じ連結成分を構成する点は同じ番号をもつ。
    static int[] makeCCNum(ArrayList<Integer>[] g, int n) {
        int[] ccNum = new int[n];
        int num = 1;
        for (int i = 0; i < n; i++) {
            if (ccNum[i] != 0)
                continue;

            // 未到達の点から連結成分を作成
            Queue<Integer> q = new LinkedList<Integer>();
            q.add(i);
            
            while (!q.isEmpty()) {
                int top = q.poll();
                ccNum[top] = num;

                for (int adj : g[top]) {
                    if (ccNum[adj] == 0) {
                        q.add(adj);
                        ccNum[adj] = num;
                    }
                }
            }

            // 次の連結成分には別の番号をつける
            num++;
        }
        return ccNum;
    }
}



Measured memory_bytes: 116248
from itertools import chain

h, w = map(int, input().split())
n = int(input())
field = chain.from_iterable([i + 1] * a for i, a in enumerate(map(int, input().split())))
for r, row in enumerate(zip(*[field] * w)):
    if r & 1:
        print(*reversed(row))
    else:
        print(*row)


Measured memory_bytes: 3828
import bisect

N = int(input())
A = sorted(map(int, input().split()))
B = list(map(int, input().split()))
C = sorted(map(int, input().split()))

print(sum(bisect.bisect_left(A, B[j]) * (N - bisect.bisect(C, B[j])) for j in range(N)))


Measured memory_bytes: 22720
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd
#define mod 1000000007
/****************************/
ll w[110];
ll v[110];
int n,wt;
ll dp[100010];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n>>wt;
	rep(i,n)
	{
		cin>>w[i]>>v[i];
	}
	rep(i,100010) dp[i]=mod;
	dp[0]=0;
	rep(i,n)
	{
		rep4(j,v[i],100010)
		{
			dp[j]=min(dp[j],w[i]+dp[j-v[i]]);
		}
	}
	rep2(i,100010)
	{
		if(dp[i]<=wt)
		{
			cout<<i;
			return 0;
		}
	}
	return 0;
}

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

#define rp(i, k, n) for (int i = k; i < n; i++)
typedef long long ll;

ll mod = 1000000007ll;
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; }
const ll inf = 1ll << 60;



int main() {
    char s[100010];
    scanf("%s", s);
    int n = strlen(s);
    int a = 0;
    int b = 0;
    rp(i, 0, n) {
        if(s[i] == '0') a++;
        else b++ ;
    }
    printf("%d", 2 * min(a,b));
    return 0;
}

Measured memory_bytes: 384
#!/usr/bin/env python3

from itertools import product

def main():
    n = int(input())
    f = []
    p = []
    for ob in (f, p):
        for i in range(n):
            ro = list(map(int, input().split()))
            ob.append(ro)
    res = -99999999999
    for open_at in product((0, 1), repeat=10):
        if 1 not in open_at:
            continue
        res = max(res, get_rieki(f, p, open_at, n))
    print(res)

def get_rieki(f, p, open_at, n):
    res = 0
    for i in range(n):
        cnt = sum(f[i][t] * open_at[t] for t in range(10))
        res += p[i][cnt]
    return res

main()


Measured memory_bytes: 3064
import collections
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
table = defaultdict(int)
for i in a:
    table[i] += 1
q = int(input())
bc = [tuple(map(int, input().split())) for _ in range(q)]
whole = sum(a)
ans = 0
for b, c in bc:
    if b in table:
        whole = whole + table[b] * (c-b)
        print(whole)
        table[c] += table[b]
        table[b] = 0
    else:
        print(whole)

Measured memory_bytes: 103404
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		List<Long> hs = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			hs.add(sc.nextLong());
		}
		Collections.sort(hs, Collections.reverseOrder());
		System.out.println(hs.stream().sorted(Collections.reverseOrder()).skip(k).mapToLong(Long::valueOf).sum());
		sc.close();
	}
}


Measured memory_bytes: 73056
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

int main(){
	string s;
	cin >> s;
	bool ret = false;
	string t = "keyence";
	rep(i,7){
		bool ret_ = true;
		rep(j,i)ret_ &= s[j] == t[j];
		rep(j,7-i)ret_ &= s[s.size()-1-j] == t[6-j];
		ret |= ret_;
	}
	if(ret)puts("YES");
	else puts("NO");
}



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

const int MX=100010;

int n, q, A[MX], m;
ll sum[MX];

bool valid(int k, int x){
	if(k*2>=n) return true;
	int r=A[n-k], l=A[n-2*k];
	return abs(r-x)<abs(l-x);
}

int main(){
	ios::sync_with_stdio(0), cin.tie(0);
	cin>>n>>q; m=(n+1)/2;
	for(int i=1; i<=n; i++) cin>>A[i];

	for(int i=1; i<=m; i++) sum[i] = sum[i-1] + A[n-i+1];
//	for(int i=0; i<=m; i++) cout<<sum[i]<<' ';
//	cout<<'\n';
	for(int i=m; i>=0; i--){
		static ll now=0;
		if(n-i*2<=0) continue;
		now += A[n-i*2]; sum[i]+=now;
//		cout<<i<<": "<<now<<'\n';
	}
//	for(int i=0; i<=m; i++) cout<<sum[i]<<' ';
//	cout<<'\n';

	for(int i=1; i<=q; i++){
		int x; cin>>x;
		int s=0, e=m;
//		cout<<"Solving "<<x<<": ";
		while(s<e){
			int mid=(s+e)/2;
			if(valid(mid,x)) e=mid;
			else s=mid+1;
//			cout<<mid<<"("<<(valid(mid,x)?'O':'X')<<") ";
		}
//		cout<<"\nans: ";
		cout<<sum[s]<<'\n';
	}

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define FI first
#define SE second
#define PB push_back
#define ll long long
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define co(i) cout<<(i)<<endl
#define fcout cout<<fixed<<setprecision(10)
#define uni(i) i.erase(unique(i.begin(), i.end()), i.end());
#define all(i) i.begin(),i.end()
#define pint pair<int, int>
#define vint vector<int>
using namespace std;

const int INF=1e9+7;
const int MOD=1e9+7;
//const int MOD=998244353;

int a[100001];
int main(){
	int n; cin>>n;
	string s="second";
	FOR(i,0,n){
		cin>>a[i];
		if(a[i]%2) s="first";
	}
	co(s);
}


Measured memory_bytes: 640
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
constexpr int INF = 1 << 30;

int N, M;
vector<vector<int>> edges, revs;

vector<int> dijkstra(int s) {
	vector<int> d(N, 1 << 30);
	priority_queue<pii, vector<pii>, greater<pii>> pq;
	d[s] = 0;
	pq.push({ 0,s });
	while (!pq.empty()) {
		int cost, now;
		tie(cost, now) = pq.top(); pq.pop();
		if (d[now] < cost)continue;
		for (int next : edges[now]) {
			if (d[now] + 1 < d[next]) {
				d[next] = cost + 1;
				pq.push({ d[next],next });
			}
		}
	}
	return d;
}

vector<int> route(vector<int> d) {
	int s = min_element(d.begin(), d.end()) - d.begin();
	set<int> goals;
	for (int goal : revs[s])goals.insert(goal);

	const int N = d.size();
	vector<pii> did;
	rep(i, N)did.push_back({ d[i],i });
	sort(did.begin(), did.end());

	int goal = 0;
	for (auto p : did)if (goals.find(p.second) != goals.end()) {
		goal = p.second;
		break;
	}

	vector<int> routes;
	routes.push_back(goal);
	while (d[goal] != 0) {
		for (int bef : revs[goal]) {
			if (d[bef] + 1 == d[goal]) {
				goal = bef;
				routes.push_back(goal);
				break;
			}
		}
	}
	reverse(routes.begin(), routes.end());
	return routes;
}

int main()
{
	cin >> N >> M;
	edges.resize(N);
	revs.resize(N);
	rep(i, M) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		edges[a].push_back(b);
		revs[b].push_back(a);
	}
	int res = INF;
	vector<int> best_d;
	rep(i, N) {
		auto d = dijkstra(i);
		for (int goal : revs[i]) {
			if (d[goal] < res) {
				res = d[goal];
				best_d = d;
			}
		}
	}
	if (res == INF) {
		cout << -1 << endl;
	}
	else {
		auto routes = route(best_d);
		cout << routes.size() << endl;
		for (int pos : routes)cout << pos + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long sn = 0;
		long div = n;
		while(div != 0) {
			sn += div % 10;
			div /= 10;
		}
		if(n % sn == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}

}


Measured memory_bytes: 23760
#include <stdio.h>
  
int main(void)
{
    int trump[4][13], No;
    int n, i, j;
    char suit;    
  
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            trump[i][j] = 0;
        }
    }
  
    scanf("%d", &n);
  
    for(i=0;i<n;i++){
        scanf("%s %d", &suit, &No);
          
        if(suit == 'S'){
            trump[0][No-1] = 1;
        }
        if(suit == 'H'){
            trump[1][No-1] = 1;
        }
        if(suit == 'C'){
            trump[2][No-1] = 1;
        }
        if(suit == 'D'){
            trump[3][No-1] = 1;
        }        
    }
  
    for(i=0;i<4;i++){
        for(j=0;j<13;j++){
            if(trump[i][j] == 0){
                if(i == 0){
                    printf("S %d\n", j+1);
                }     
                if(i == 1){
                    printf("H %d\n", j+1);
                }     
                if(i == 2){
                    printf("C %d\n", j+1);
                }     
                if(i == 3){
                    printf("D %d\n", j+1);
                }     
            }
        }
    }   
    return 0;
}


Measured memory_bytes: 2044
#include<stdio.h>

int main(void)
{
	int i = 0;
	char t;
	char s[50] = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };
	scanf("%c", &t);

	for (i = 0; i < 100; i++)
	{
		if (t == s[i])
			break;
	}
	printf("%c\n", s[i + 1]);

	return 0;
}



Measured memory_bytes: 128
H, N = map(int, input().split())
magic = list()
for _ in range(N):
    magic.append(list(map(int, input().split())))
 
magic_min = [0 for _ in range(H+1)]
for i in range(H+1):
    if i != 0 and magic_min[i] == 0:
        continue
    for A, B in magic:
        Index = i + A
        value = magic_min[i] + B
        try:
            if magic_min[Index] == 0:
                magic_min[Index] = value
            elif value < magic_min[Index]:
                magic_min[Index] = value
        
        except:
            if magic_min[-1] == 0:
                magic_min[-1] = value
            elif value < magic_min[-1]:
                magic_min[-1] = value
                
print(magic_min[-1])

Measured memory_bytes: 42328
import sys
input = sys.stdin.readline


def main():
    N, M = map(int, input().split())
    x = [0] * M
    y = [0] * M
    for i in range(M):
        x[i], y[i] = map(int, input().split())

    ball = [1] * N
    exist = [0] * N
    exist[0] = 1
    for a, b in zip(x, y):
        ball[a-1] -= 1
        ball[b-1] += 1
        if exist[a-1] == 1:
            exist[a-1] = 1 if ball[a-1] > 0 else 0
            exist[b-1] = 1

    ans = sum(exist)
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12404
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def f(x):
    res = 0
    while(x%2==0):
        res += 1
        x //= 2
    return res
def main():
    A,B,C=MI()
    if(A==B==C):
        if(A&1):
            print(0)
        else:
            print(-1)
    else:
        L=[f(A+B),f(B+C),f(C+A)]
        print(min(L))
        

if __name__ == '__main__':
    main()

Measured memory_bytes: 5332
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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

using Graph = vector<vector<pair<int, int>>>;
const int INF = 2e9;

//INT_MAX	2,147,483,647 = 2*1.0e9

vector<vector<int>> npath;
vector<vector<int>> rpath;
vector<bool> fromS;
vector<bool> toG;
Graph g;

void dfs(int _v){
  fromS[_v] = true;
  for(int i : npath[_v]){
    if(fromS[i]) continue;
    else dfs(i);
  }
}

void rdfs(int _v){
  toG[_v] = true;
  for(int i : rpath[_v]){
    if(toG[i]) continue;
    else rdfs(i);
  }
}

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

  
  g.resize(N);
  npath.resize(N);
  rpath.resize(N);
  fromS.assign(N, false);
  toG.assign(N, false);


  for(int i = 0; i < M; i++){
    int a, b ,c; cin >> a >> b >> c;
    a--; b--;
    c -= P;
    c = -c;
    npath[a].push_back(b);
    rpath[b].push_back(a);
    g[a].emplace_back(make_pair(b, c));
  }

  dfs(0);
  rdfs(N-1);

  vector<bool> ok(N);
  for(int i = 0; i < N; i++) ok[i] = fromS[i] & toG[i];

  vector<int> cost(N, INF);
  cost[0] = 0;

  bool renew = true;
  int loopcnt = 0;
  while(renew){
    renew = false;
    for(int i = 0; i < N; i++){
      if(!ok[i]) continue;
      for(auto j : g[i]){
        int b, c;
        tie(b,c) = j;
        int dist = cost[i] + c;
        if(cost[b] > dist){
          cost[b] = dist;
          renew = true;
        }
      }
    }
    loopcnt++;

    if(loopcnt > N+1){
        cout << -1 << endl;
        return 0;
    }
  }

  int ans = max(-1 * cost[N-1], 0);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i,n) for(int (i) = 0; (i) < (int)(n); (i)++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    string s;
    cin >> s;
    cout << s.substr(0, 3) << endl;
}

Measured memory_bytes: 3632
#include <stdio.h>
int main() {
  char moji[4];
  int a,b,c = 0;
  gets(moji);
  for(int i=0; i<3; i++){
	if(moji[i] == 'a') a += 1;
    if(moji[i] == 'b') b += 1;
    if(moji[i] == 'c') c += 1;
  }
  if(a==1 && b==1 && c==1) printf("Yes\n");
   else printf("No\n");
return 0;
}

Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main()
{
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;
  int ans = INT32_MAX;
  for (int i = 0; i <= max(X, Y); i++)
  {
    int tmp = 2 * C * i + A * max(0, X - i) + B * max(0, Y - i);
    if (tmp < ans)
      ans = tmp;
  }
  cout << ans << endl;
  return 0;
}

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

int n, p[65010], jo[65010];
int sum, pn;
signed main()
{
  while(true){

    cin >> n;
    if(!n){
      break;
    }
    memset(p, 0, sizeof p);
    memset(jo, 0, sizeof jo);
    sum = pn = 0;

    for(int i = 0; i < n; i++){
      cin >> p[i];
      sum += p[i];
    }
    for(int i = 0; i < n - 1; i++){
      cin >> jo[i];
    }
    sort(jo, jo + n - 1, greater<int>());
    pn = n;

    for(int i = 0; i < n - 1; i++){
      if((sum + jo[i]) * (pn - 1) > sum * pn){
	sum += jo[i];
	pn--;
      }
    }

    cout << sum * pn << endl;
  }
  return 0;
}

Measured memory_bytes: 2196
package main

import "fmt"

func main() {
	fives := 0
	sevens := 0
	n := 0
	for i := 0; i < 3; i++ {
		fmt.Scan(&n)
		if n == 5 {
			fives++
		}
		if n == 7 {
			sevens++
		}
	}
	if fives == 2 && sevens == 1 {
		fmt.Println("YES")
		return
	}
	fmt.Println("NO")
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
N = int(input())
B = [[int(x) for x in input().split()] for _ in range(N)]
def heighti(Cx,Cy,x,y,h):
    return abs(x-Cx) + abs(y-Cy) + h
def Heighti(Cx,Cy,x,y,h):
    return -abs(x-Cx) - abs(y-Cy) + h
ans = []
h0 = []
A = []
for l in B:
    if l[2] == 0:
        h0.append([l[0],l[1]])
    else:
        A.append(l)
if len(A) > 0:
    for i in range(101):
        for j in range(101):
            tempH = heighti(i,j,A[0][0],A[0][1],A[0][2])
            if tempH < 0:
                break
            else:
                flag = 1
                for k in range(1,len(A)):
                    if A[k][2] != 0 and heighti(i,j,A[k][0],A[k][1],A[k][2]) != tempH:
                        flag = 0
                        break
                if flag:
                    ans.append([i,j,tempH])
if len(ans) == 1:
    print(*ans[0])
elif len(ans) == 0:
    for i in range(101):
        for j in range(101):
            for k in range(N):
                if heighti(i,j,B[k][0],B[k][1],B[k][2]) > 0:
                    print(*[i,j,heighti(i,j,B[k][0],B[k][1],B[k][2])])
                    sys.exit()
else:
    for m in ans:
        flag = 1
        for n in h0:
            if Heighti(n[0],n[1],m[0],m[1],m[2]) > 0:
                flag = 0
                break
        if flag:
            print(*m)
            sys.exit()

Measured memory_bytes: 46188
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>

#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define pb          push_back
#define mp          make_pair
#define mt          make_tuple
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       9223372036854775807
#define LLMIN       -9223372036854775808
#define IMAX        2147483647
#define IMIN        -2147483648
typedef long long LL;

using namespace std;


#define MAX_V 200000

struct Edge{ int to,cap,rev; };
int used[MAX_V];
vector<Edge> G[MAX_V];

void addEdge(int from,int to,int cap){
    G[from].push_back((Edge){to,cap,(int)G[to].size()});
    G[to].push_back((Edge){from,0,(int)G[from].size()-1});
}
int DFS(int v,int t,int f){
    if(v==t)
        return f;
    used[v]=true;
    for(int i=0;i<(int)G[v].size();i++){
        Edge &e=G[v][i];
        if(!used[e.to] && 0<e.cap){
            int d=DFS(e.to,t,min(f,e.cap));
            if(0<d){
                e.cap-=d;
                G[e.to][e.rev].cap+=d;
                return d;
            }
        }
    }
    return 0;
}
int maxFlow(int s,int t){
    int flow=0;
    while(1){
        for(int i=0;i<MAX_V;i++)
            used[i]=false;
        int f=DFS(s,t,INT_MAX);
        if(f==0) return flow;
        flow+=f;
    }
}

int main(void){
    int H,W;
    vector<string> vs;
    cin>>H>>W;
    REP(i,H){
        string s;cin>>s;vs.pb(s);}
    int sy,sx,ty,tx;
    REP(i,H)
        REP(j,W){
            if(vs[i][j]=='S'){
                sy=i,sx=j;
                addEdge(i*W+j,H*W+j,INT_MAX);
                addEdge(i*W+j,H*W+W+i,INT_MAX);
            }else if(vs[i][j]=='T'){
                ty=i,tx=j;
                addEdge(H*W+j,i*W+j,INT_MAX);
                addEdge(H*W+W+i,i*W+j,INT_MAX);
            }else if(vs[i][j]=='o'){
                addEdge(H*W+W+i,H*W+j,1);
                addEdge(H*W+j,H*W+W+i,1);
            }
        }
    if(sy==ty || sx==tx)
        cout<<-1<<endl;
    else{
        int ans=maxFlow(sy*W+sx,ty*W+tx);
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;

int main() {
    ll n;
    cin >> n;
    ll a[n];
    for(int i = 0; i < n; i++) cin >> a[i];
    ll before = 1, tmp = 0, sum = a[0];

    if(a[0] < 1) {
        tmp += 1 - a[0];
        sum = 1;
    }
    for(int i = 1; i < n; i++) {
        sum += a[i];
        before *= -1;
        if(sum == 0) {
            sum = before;
            tmp++;
        } else if(before != (sum / llabs(sum))) {
            tmp += llabs(before) + llabs(sum);
            sum = before;
        }
    }
    ll ans = tmp;

    before = -1, tmp = 0, sum = a[0];
    if(a[0] > -1) {
        tmp += 1 + a[0];
        sum = -1;
    }
    for(int i = 1; i < n; i++) {
        sum += a[i];
        before *= -1;
        if(sum == 0) {
            sum = before;
            tmp++;
        } else if(before != (sum / llabs(sum))) {
            tmp += llabs(before) + llabs(sum);
            sum = before;
        }
    }
    ans = min(ans, tmp);
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
const long long INF = 1e7+1;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define RALL(x) x.rbegin(),x.rend()
typedef long long int ll;
typedef vector<ll> vi;
typedef vector < pair<ll, ll > > vp;
typedef vector <string> vs;
typedef vector <char> vc;
typedef list <ll> lst;

ll n,m, k, ans = 0, sum = 0, cnt = 0;
string s;
char c;

/*--------------------template--------------------*/

ll a[2000000] = { 0 };
ll b[2000000] = { 0 };

int main()
{
	while (1) {
		cin >> n >> m;
		if (n == 0 && m == 0) {
			return 0;
		} else {
			fill(a, a + 2000000, 0);
			fill(b, b + 2000000, 0);
			vi vh(n), vw(m);
			REP(i, n) cin >> vh[i];
			REP(i, m) cin >> vw[i];
			REP(i, n)
			{
				FOR(j, i, n)
				{
					sum = 0;
					FOR(k, i, j+1)
					{
						sum += vh[k];
					}
					a[sum]++;
				}
			}
			REP(i, m)
			{
				FOR(j, i, m)
				{
					sum = 0;
					FOR(k, i, j + 1)
					{
						sum += vw[k];
					}
					b[sum]++;
				}
			}
			ans = 0;
			REP(i, 2000000)
			{
				ans += a[i] * b[i];
			}
			cout << ans << endl;
		}
	}
}

Measured memory_bytes: 34300
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

//std::cout << std::fixed << std::setprecision(10)
constexpr long long MOD = 1000000007;

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

int main()
{
  long long a,b,c;
  std::cin >> a >> b >> c;
  if (0<c-a-b && 4LL*a*b<(c-a-b)*(c-a-b))
    std::cout << "Yes" << std::endl;
  else
    std::cout << "No" << std::endl;
  return 0;
}



Measured memory_bytes: 256