akhauriyash/Code-Regression huggingface dataset:
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.regex : regex;
import std.container;

void main()
{
	while (1) {
		auto x = readln.chomp.split.map!(to!int);
		if (x[0] == 0) break;
		auto teams = new int[][](x[0], 3);
		auto quest = new int[][](x[0], x[1]);
		foreach (i; 0..x[0]) {
			teams[i][0] = i;
		}
		foreach (i; 0..x[2]) {
			auto a = readln.chomp.split;
			auto data = a[0..3].map!(to!int);
			if (a[3] == "WRONG") {
				quest[data[0]-1][data[1]-1]++;
			} else {
				teams[data[0]-1][1]++;
				teams[data[0]-1][2] += quest[data[0]-1][data[1]-1] * 1200 + data[2];
			}
		}

		teams = teams.array.sort!((b, c) => b[1] == c[1] ? b[2] == c[2] ? b[0] < c[0] : b[2] < c[2] : b[1] > c[1]).array;
		foreach (e; teams) {
			writeln(e[0]+1, " ", e[1], " ", e[2]);
		}
	}
}

Measured memory_bytes: 2028
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<lint>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    vec a(n), b(m);
    rep(i, n) cin >> a[i];
    rep(i, m) cin >> b[i];

    vec as(n+1), bs(m+1);
    rep(i, n) as[i+1] = as[i] + a[i];
    rep(i, m) bs[i+1] = bs[i] + b[i];

    int res = 0;

    for (int i = 0; i <= n; i++) {
        if (as[i] > k) break;
        int j = lower_bound(all(bs), k+1-as[i]) - bs.begin();
        res = max(res, i + j - 1);
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 9592
using System;

class Program
    {
        static void Main()
        {
            while (true)
            {
                string[] line = Console.ReadLine().Split(' ');

                int height = int.Parse(line[0]);
                int width = int.Parse(line[1]);

                if (height == 0 && width == 0)
                    break;

                for (int i = 0; i < height; i++)
                {
                    for (int j = 0; j < width; j++)
                    {
                        if(i != 0 && i != height - 1
                            && j != 0 && j != width - 1)
                            Console.Write(".");
                        else
                            Console.Write("#");
                    }
                    Console.Write("\n");
                }
                Console.Write("\n");
            }
        }
    }

Measured memory_bytes: 5280
from collections import defaultdict

n = int(input())

temp_dict = defaultdict(int)
for _ in range(n):
    s_list = list(input())
    s_list.sort()
    s = "".join(s_list)
    temp_dict[s] += 1

ans = 0
for v in temp_dict.values():
    ans += v * (v - 1) // 2
print(ans)

Measured memory_bytes: 18188
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  string s; cin >> s;
  int N = s.size();

  int res = 0;
  rep(i,N){
    int a = (int)(s[i] - '0');
    (res += a) %= 9;
  }
  if (res==0) cout << "Yes" << endl;
  else cout << "No" << endl;



  // cout << fixed << setprecision(10);
  
  return 0;
}

Measured memory_bytes: 3716
#include<stdio.h>

int main(void){
	int N, A, N2;
	do{
		scanf("%d", &N);
		N2 = N * N;	/*N^2を定義しておく*/
		scanf("%d", &A);
	}while(N < 1 || N > 100 || A < 0 || A > N2);

	printf("%d\n", N2 - A);

	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<utility>
#include<algorithm>
#include<cstdio>
#include<iomanip>
#include<queue>
#include<stack>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

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

    ll N;
    cin >> N;
    vector<ll> A(N);
    Rep (i, N) {
        cin >> A[i];
        if (A[i] > i) {
            cout << -1 << endl;
            return 0;
        }
    }

    ll ans = 0;
    Rep (i, N) {
        if (i+1 < N && A[i]+1 < A[i+1]) {
            cout << -1 << endl;
            return 0;
        }
        if (A[i] > 0) {
            // cout << i << "\t";
            ll tmp = A[i];
            while (i+1 < N && A[i+1] == A[i] + 1) {
                tmp++;
                i++;
            }
            // cout << tmp << endl;
            ans += tmp;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

int main() {
    string s;
    cin >> s;
    string year;
    year = s.substr(0, 4);
    int ynum = atoi(year.c_str());
    string month;
    month = s.substr(5, 2);
    int mnum = atoi(month.c_str());
    if (ynum < 2019){
        cout << "Heisei" << endl;
    }
    else if (ynum > 2019){
        cout << "TBD" << endl;
    }
    else if (ynum == 2019){
        if (mnum < 5){
            cout << "Heisei" << endl;
        }
        else {
            cout << "TBD" << endl;
        }
    }
}

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

int main(){
	// sengen
	int a,b;
	// nyuryoku
	cin >> a >> b;
	// keisan
	for(int i=1;i<1001;i++){
		int atax = i*8/100;
		int btax = i/10;
		if(atax == a && btax == b){
			cout << i;
			break;
		}
		if(i == 1000){
			cout << "-1";
		}
	}
	// syutsuryoku
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;

int n,a[1000000] ={};

int main(){
	cin >> n;
	int cnt = 0;

	for(int i=0;i<n;i++){
		cin >> a[i];
	}
	for(int i=0;i<n;i++){
	//	cout << i << " " << a[i] << " " << a[a[i]-1] <<endl;
		if(a[a[i]-1] == i+1)cnt++;
	}
	cout << cnt/2 <<endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.*;
import java.io.PrintWriter; 

public class Main{
	public static void main(String[] args) {
		new Main().run();
	}
	
	public void run() {
		Scanner sc = new Scanner(System.in);
		double a,b,c,d,e,f,z,x,y;
		while(sc.hasNext()){
			a = sc.nextDouble();
			b = sc.nextDouble();
			c = sc.nextDouble();
			d = sc.nextDouble();
			e = sc.nextDouble();
			f = sc.nextDouble();
			z = a*e-b*d;
			x = (c*e-b*f)/z;
			y = (a*f-c*d)/z;
			if(-0.0005< x && x <= 0)x = 0;
			if(-0.0005< y && y <= 0)y = 0; 
			System.out.println(String.format("%.3f %.3f",x ,y )); 
		}
	}
}

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

using namespace std;

int main() {
  int n;
  vector<long long> dp(3, 0);

  cin >> n;

  for(int days = 0; days < n; days++){
    vector<int> c(3, 0);
    vector<long long> new_dp(3, 0);
    for(int i = 0; i < 3; i++){
      cin >> c[i];
    }
    for(int i = 0; i < 3; i++){
      for(int j = 0; j < 3; j++){
        if(i != j){
          new_dp[j] = max(dp[i] + c[j], new_dp[j]);
        }
      }
    }
    dp = new_dp;
  }
  cout << max(max(dp[0], dp[1]), dp[2]) << "\n";
  return 0;
}

Measured memory_bytes: 888
#include <cmath>
#include <iostream>
#include <vector>
#include <array>
#include <unordered_map>
#include <unordered_set>
 
using namespace std;

bool helper(const string& s, int idx, int num, vector<char>& ops) {
	if (idx >= s.size()) return num == 7;
	ops.push_back('+');
	if (helper(s, idx + 1, num + (s[idx] - '0'), ops)) return true;
	ops.pop_back();
	ops.push_back('-');
	if (helper(s, idx + 1, num - (s[idx] - '0'), ops)) {
		return true;
	}
	ops.pop_back();
	return false;
}
 
int main (int argc, char* argv[]) {
	string s;
	cin >> s;

	vector<char> ops;
	helper(s, 1, s[0] - '0', ops);
	
	cout << s[0];
	for (int i = 1; i < s.size(); i++) {
		cout << ops[i - 1] << s[i];
	}
	cout << "=7" << endl;
}


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


#define f(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define char_f(i,a) for(int i=(int)(a);(char)s[i]!='\0';i++)
#define rf(i,a,b) for(int i=(int)(b);i>=(int)(a);i--)
#define llf(i,a,b) for(long long int i=(long long int)(a);i<=(long long int)(b);i++)
#define llrf(i,a,b) for(long long int i=(long long int)(b);i>=(long long int)(a);i--)



#define ll long long
#define fi first
#define se second
#define pb push_back
#define pop pop_back
#define mem(ara) memset((ara),0,sizeof(ara))
#define memn(ara) memset((ara),-1,sizeof(ara))
#define b begin()
#define e end()
#define em emplace
#define eb emplace_back





#define si set<int>
#define sd set<double>
#define sll set<long long int>
#define ss set<string>
#define sc set<char>

#define pii pair<int,int>
#define pli pair<long long int,int>
#define pil pair<int,long long int>
#define pll pair<long long int,long long int>
#define pci pair<char,int>
#define pic pair<int,char>
#define pcl pair<char,long long int>
#define plc pair<long long int,char>

#define pss pair<string,string>
#define pcc pair<char,char>

#define pis pair<int,string>
#define psi pair<string,int>
#define pls pair<long long int,string>
#define psl pair<string,long long int>
#define pdd pair<double,double>
#define pcs pair<char,string>
#define psc pair<string,char>



#define vi  vector<int>
#define vll vector<long long int>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vii vector<pii>



#define mod 1000000007
#define mx (1<<30)-1
#define llmx (1ll<<62)
#define n_size 100005
#define g_size 10000005
double PI=acos(-1);



///unsigned int uMAX=4294967295;
///unsigned ll int ullMAX=18446744073709551615;



int arr[g_size];




ll int fact(ll n)
{
    ll res=1;
    f(i,1,n){
        res=((res%mod)*(i%mod))%mod;
    }
    return res;
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);

	int n,m,T,res;

	int maxi=mx,mini=-mx,count=0;

    	int i,j,k;

	string s1,s2;

	char s[100000];

	int ara1[n_size],ara2[n_size];

    cin>>n;

    cout<<fact(n)<<endl;

}



Measured memory_bytes: 256
/*          (: -_-_-_- IN THE NAME OF ALLAH -_-_-_- :)          */
/*                    | S e y e d |                             */
/*                    |    3 7    |                             */
/*                   HASHEMESHOON hastam ;)                     */
/*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*//*/
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstdio>
#include <map>
#include <string>
#include <set>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <ctime>
#include <list>
#include <iterator>
#define ll long long
#define ss second
#define ff first
#define pb push_back
using namespace std;
ll n,m,x,y,z,w,t,d,b[200100],a[200100];
string s;
pair <ll,ll> p[200100],q[200100];
map <ll,ll> mp,mq;
int main(){
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        if(i%2==0)mp[a[i]]++;
        else mq[a[i]]++;
    }
    for(int i=0;i<n;i++){
        if(i%2==0){
            p[i/2].ff=n/2-mp[a[i]];
            p[i/2].ss=a[i];
        }
        else {
            q[i/2].ff=n/2-mq[a[i]];
            q[i/2].ss=a[i];
        }
    }
    p[n/2].ff=n/2;
    p[n/2].ss=1e9;
    q[n/2].ff=n/2;
    q[n/2].ss=1e12;
    sort(p,p+n/2+1);
    sort(q,q+n/2+1);
    unique(p,p+n/2+1);
    unique(q,q+n/2+1);
    if(p[0].ss!=q[0].ss)return cout<<q[0].ff+p[0].ff,0;
    cout<<min(p[0].ff+q[1].ff,q[0].ff+p[1].ff);
    return 0;
}


Measured memory_bytes: 11392
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
	int n, k;
	scanf("%d %d",&n,&k);
	for (int m = 0; m < 200; m++){
		for (int a = 0; a < 200; a++){
			for (int x = 0; x <= k; x++){
				if (a * x + (a + m) * (k - x) == n){
					printf("%d\n",m);
					return 0;
				}
			}
		}
	}
}

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

// to increase precision
// std::cout<<std::fixed;
// 	std::cout<<std::setprecision(6)<<z;
//clock_t tStart = clock();
//printf("Time taken: %.9fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);
#define maxn 100007

#define ll long long int

ll mod=998244353;
int main(){
	int h,w,k;
	cin>>h>>w>>k;
	vector<string> in(h);
	for (int i = 0; i < h; ++i)
	{
		cin>>in[i];
	}
	int ans=0;
	for(int i=0;i<(1<<h);i++){
		for(int j=0;j<(1<<w);j++){
			vector<string> temp=in;
			for(int x=0;x<h;x++){
				for(int y=0;y<w;y++){
					if(  (i&(1<<x)) || (j&(1<<y) ) ){
						temp[x][y]='r';
					}
				}
			}
			int ct=0;
			for(int x=0;x<h;x++){
				for(int y=0;y<w;y++){
					if(temp[x][y]=='#')
						ct++;
				}
			}
			ans+=(ct==k);



		}
	}

	cout<<ans<<endl;

}

Measured memory_bytes: 3628
h, w = map(int, input().split())
s = []
for i in range(h):
    s.append(input())

y = [0, -1, -1, -1, 0, 1, 1, 1]
x = [1, 1, 0, -1, -1, -1, 0, 1]

for i in range(h):
    for j in range(w):
        cnt = 0
        for m, n in zip(y, x):
            if 0 <= i + m < h and 0 <= j + n < w:
                if s[i + m][j + n] == '#':
                    cnt += 1

        if s[i][j] == '#':
            print('#', end='')
        else:
            print(cnt, end='')
    print()


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
int N,K;
vector<int>G[111111];
vector<int>P[1111111];
int ans[111111];
bool F[111111];
int main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		ans[i]=-1;F[i]=false;
	}
	for(int i=0;i<N-1;i++){
		int A,B;
		scanf("%d%d",&A,&B);A--;B--;
		G[A].pb(B);
		G[B].pb(A);
	}
	scanf("%d",&K);
	for(int i=0;i<K;i++){
		int v,p;
		scanf("%d%d",&v,&p);v--;
		P[p].pb(v);ans[v]=p;F[v]=true;
	}
	for(int i=0;i<1111111;i++){
		for(int j=0;j<(int)P[i].size();j++){
			int now=P[i][j];
			if(ans[now]==-1){
				ans[now]=i;
			}
			for(int k=0;k<(int)G[now].size();k++){
				if(ans[G[now][k]]==-1){
					if(!F[G[now][k]]){
						P[i+1].pb(G[now][k]);F[G[now][k]]=true;
					}
				}
				else if(ans[G[now][k]]-i!=1&&ans[G[now][k]]-i!=-1){
					printf("No\n");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
	for(int i=0;i<N;i++){
		printf("%d\n",ans[i]);
	}
	return 0;
}


Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define each(i, mp) for(auto& i:mp)

vector<int> A;

int main()
{
	string s;
	cin >> s;
	map<ll, ll> mp;
	mp[0] = 1;
	reverse(s.begin(), s.end());
	ll now = 0, ten = 1;
	each(e, s)
	{
		now = (now + (e - '0') * ten) % 2019;
		ten *= 10;
		ten %= 2019;
		mp[now]++;
	}
	ll ans = 0;
	each(e, mp)
	{
		ans += e.second * (e.second - 1) / 2;
	}

	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define SIT set<Node>::iterator
using namespace std;
inline int read()
{
	char c;int res=0;
	for(;!isdigit(c);c=getchar());
	for(;isdigit(c);res=(res<<1)+(res<<3)+(c^48),c=getchar());
	return res;
}
struct Node
{
	int l,r;
	mutable bool v;
	Node(int L,int R=-1,bool V=0):l(L),r(R),v(V){}
	bool operator <(const Node &x)const
	{
		return l<x.l;
	}
};
set<Node>s;
SIT split(int pos)
{
	SIT it=s.lower_bound(Node(pos));
	if(it!=s.end()&&it->l==pos)return it;
	it--;
	int l=it->l,r=it->r;
	bool v=it->v;
	s.erase(it);
	s.insert(Node(l,pos-1,v));
	return s.insert(Node(pos,r,v)).first;
}
void assign_val(int l,int r,bool v)
{
	SIT itr=split(r+1),itl=split(l);
	s.erase(itl,itr);
	s.insert(Node(l,r,v));
}
int n,l,r;
int main()
{
	s.insert(Node(1,100000,0));
	n=read();
	for(int i=1;i<=n;i++)
	{
		l=read(),r=read();
		assign_val(l,r,1);
	}
	int ans=0;
	for(SIT itr=split(100001),itl=split(1);itl!=itr;itl++)
	{
		ans+=(itl->r-itl->l+1)*(itl->v);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
def main():
    a,b,c,k = map(int,input().split())
    if a>=k:
        print(k)
    else:
        k = k-a
        if b>=k:
            print(a)
        else:
            k = k-b
            print(a-k)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9172
k = int(input())

s = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(s[k-1])


Measured memory_bytes: 2940
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 80000;
int nodeID[N];
vector<vector<int> > g;
vector<pair<int,int> > val;
int n, L;
int Not(int u) {
	if (u < L)
		return u + L;
	return u - L;
}
void addEdge(int u, int v) {
	g[Not(u)].push_back(v);
	g[Not(v)].push_back(u);
}
vector<int> S;
int comp[N], low[N], idx[N], dfs, cmp;
bool vis[N];
void DFS(int u) {
	idx[u] = low[u] = ++dfs;
	vis[u] = true;
	S.push_back(u);
	for (int i = 0; i < g[u].size(); ++i) {
		int v = g[u][i];
		if (!low[v])
			DFS(v);
		if (vis[v])
			low[u] = min(low[u], low[v]);
	}
	if (low[u] == idx[u]) {
		while (true) {
			int v = S.back();
			S.pop_back();
			vis[v] = false;
			comp[v] = cmp;
			if (u == v)
				break;
		}
		++cmp;
	}
}
int id;
void setID(int n, int s, int e) {
	if (s == e)
		return;
	nodeID[n] = id++;
	setID(n * 2, s, (s + e) / 2);
	setID(n * 2 + 1, (s + e) / 2 + 1, e);
}
void initEdges(int n, int s, int e) {
	if (s == e) {
		nodeID[n] = val[s].second;
		return;
	}
	initEdges(n * 2, s, (s + e) / 2);
	initEdges(n * 2 + 1, (s + e) / 2 + 1, e);
	g[Not(nodeID[n])].push_back(Not(nodeID[n * 2]));
	g[Not(nodeID[n])].push_back(Not(nodeID[n * 2 + 1]));
}
int ql, qr;
void addEdges(int n, int s, int e, int u) {
	if (qr<s || ql>e)
		return;
	if (s >= ql && e <= qr) {
		g[u].push_back(Not(nodeID[n]));
		return;
	}
	addEdges(n * 2, s, (s + e) / 2, u);
	addEdges(n * 2 + 1, (s + e) / 2 + 1, e, u);
}
vector<int> sz;
bool check(int d) {
	for (int i = 0; i < g.size(); ++i)
		g[i].resize(sz[i]);
	for (int i = 1; i < val.size(); ++i) {
		ql = lower_bound(val.begin() + 1, val.end(), make_pair(val[i].first - d + 1, -1)) - val.begin();
		if (ql < i) {
			qr = i - 1;
			addEdges(1, 1, n * 2, val[i].second);
		}
		ql = i + 1;
		qr = lower_bound(val.begin() + 1, val.end(), make_pair(val[i].first + d, -1)) - val.begin();
		--qr;
		if (ql <= qr)
			addEdges(1, 1, n * 2, val[i].second);
	}
	memset(low, 0, sizeof(low));
	dfs = cmp = 0;
	for (int i = 0; i < g.size(); ++i)
		if (!low[i])
			DFS(i);
	for (int i = 0; i < L; ++i)
		if (comp[i] == comp[Not(i)])
			return false;
	return true;
}
int main()
{
	scanf("%d", &n);
	id = n;
	setID(1, 1, n * 2);
	L = id;
	val.resize(n * 2 + 1);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &val[i].first);
		val[i].second = i - 1;
		scanf("%d", &val[i + n].first);
		val[i + n].second = Not(i - 1);
	}
	sort(val.begin() + 1, val.end());
	g.resize(L << 1);
	initEdges(1, 1, n * 2);
	for (int i = 0; i < g.size(); ++i)
		sz.push_back(g[i].size());
	int l = 0, r = 1e9, m, res = 0;
	while (l <= r) {
		m = (l + r) / 2;
		if (check(m)) {
			res = m;
			l = m + 1;
		}else
			r = m - 1;
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 10876
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <set>
#include <map>
#include <list>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const ll inf = (ll) 1e18;

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

  int n;
  cin >> n;

  int ans = max(0, (n + 1) / 2 - 1);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
//printf("%.10f\n", n);
ll yo[12345678], ta[12345678];
signed main() {
    ll n, m, t = 0, yoko = 0, tate = 0; string s; cin >> s >> n >> m;
    queue<ll> queyoko, quetate; quetate.push(0);
    if (s[s.size() - 1] == 'F') { s.push_back('T'); }
    for (int h = 0; h < s.size(); h++) {
        if (s[h] == 'F') {
            if (t % 2 == 0) { yoko++; }
            else { tate++; }
        }
        else {
            if (t == 0) { queyoko.push(yoko); yoko = 0; }
            else if (t % 2 == 1) {
                ll z = quetate.size(); map<ll, ll> ima;
                for (int h = 0; h < z; h++) {
                    if (ima[quetate.front() + tate] == 0) {
                        quetate.push(quetate.front() + tate);
                        ima[quetate.front() + tate]++;
                    }
                    if (ima[quetate.front() - tate] == 0) {
                        quetate.push(quetate.front() - tate);
                        ima[quetate.front() - tate]++;
                    }
                    quetate.pop();
                }
                tate = 0;
            }
            else {
                ll z = queyoko.size(); map<ll, ll> ima;
                for (int h = 0; h < z; h++) {
                    if (ima[queyoko.front() + yoko] == 0) {
                        queyoko.push(queyoko.front() + yoko);
                        ima[queyoko.front() + yoko]++;
                    }
                    if (ima[queyoko.front() - yoko] == 0) {
                        queyoko.push(queyoko.front() - yoko);
                        ima[queyoko.front() - yoko]++;
                    }
                    queyoko.pop();
                }
                yoko = 0;
            }
            t++;
        }
    }
    ll z = 0;
    while (!queyoko.empty()) {
        //cout << queyoko.front() << endl;
        if (queyoko.front() == n) { z++; break; }
        queyoko.pop();
    }
    while (!quetate.empty()) {
        //cout << ' ' << quetate.front() << endl;
        if (quetate.front() == m) { z++; break; }
        quetate.pop();
    }
    if (z == 2) { cout << "Yes" << endl; }
    else { cout << "No" << endl; }
    return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

  


  int a,b,x;

  bool f=true;
  cin >> a>>b>>x;

  if(a>x)
    f=false;

  if(a+b<x)
    f=false;
  
  if(f==true){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}


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

int main() {
  int64_t N,K;
  cin>>N>>K;
  int64_t t=N%K;
  if(t<(K-t))cout<<t<<endl;
  else{
    int64_t ans=K-t;
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define INF (1<<29)

int N, M, R;
int d[201][201];
int r[9];
int A, B, C;
int res;
bool used[9];

void dfs(int c, int las, int dist) {
    if (c == R + 1) {
        if (res > dist) res = dist;
        return;
    }
    for (int i = 1; i <= R; ++i) {
        if (!used[i]) {
            used[i] = true;
            if (las == -1) {
                dfs(c + 1, i, 0);
            } else {
                dfs(c + 1, i, dist + d[r[las]][r[i]]);
            }
            used[i] = false;
        }
    }
}

int main(void) {
    cin >> N >> M >> R;
    for (int i = 1; i <= N; ++i) {
        for (int j = 1; j <= N; ++j) {
            if (i != j) {
                d[i][j] = INF;
            }
        }
    }
    for (int i = 1; i <= R; ++i) {
        cin >> r[i];
    }
    for (int i = 1; i <= M; ++i) {
        cin >> A >> B >> C;
        if (d[A][B] > C) {
            d[A][B] = d[B][A] = C;
        }
    }

    for (int k = 1; k <= N; ++k) {
        for (int i = 1; i <= N; ++i) {
            for (int j = 1; j <= N; ++j) {
                if (d[i][j] > d[i][k] + d[k][j]) {
                    d[i][j] = d[i][k] + d[k][j];
                }
            }
        }
    }

    res = INF;
    dfs(1, -1, 0);

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 384
import java.io.*;
import java.util.*;
import java.util.function.*;

final class Solver {
	void solve(Supplier<String> sc) {
		int N = Integer.parseInt(sc.get());
		int[] count = new int[N + 1];
		for (int i = 1; i <= N; i++) {
			for (int j = 0; j <= N; j+=i) {
				count[j] += 1;
			}
		}
		long result = 0;
		for (int i = 1; i <= N; i++) {
			result += (long) i * count[i];
		}
		System.out.println(result);
	}
}

class Main {
	public static void main(String... args) {
		System.setOut(new PrintStream(new BufferedOutputStream(System.out)));
		var reader = new BufferedReader(new InputStreamReader(System.in));
		new Solver().solve(new Supplier<>() {
			StringTokenizer line;

			public String get() {
				while (line == null || !line.hasMoreTokens()) try {
					line = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new UncheckedIOException(e);
				}
				return line.nextToken();
			}
		});
		System.out.flush();
	}
}

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

	int n;
	cin >> n;
	int W[105] = {};

	int sum = 0;
	rep(i,n) {
		int w;
		cin >> w;
		sum += w;
		W[i] = w;
	}

	int b_dif = sum;
	int ans;
	int tem = 0;
	rep(i,n) {
		//cout << b_dif << endl;
		tem += W[i];
		int rest = sum - tem;
		int dif = abs(tem - rest);
		if (b_dif < dif) {
			ans = b_dif;
			break;
		}
		b_dif = dif;
	}

	cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<P> p;
  int count = 0;
  rep(i, n) {
    int a, b;
    cin >> a >> b;
    p.emplace_back(a, b);
  }
  rep(i, n) {
    if (p[i].first == p[i].second) {
      count++;
      if (count == 3) break;
      }
    else count = 0;
  }
  cout << (count == 3 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
from itertools import permutations

def check(adj, pat):
    pos = 1
    for p in pat:
        if p not in adj[pos]:
            return 0
        else:
            pos = p
    return 1

def main():
    n, m = [int(i) for i in input().split()]
    adj = {i+1:[] for i in range(n)}
    for _ in range(m):
        a, b = [int(i) for i in input().split()]
        adj[a].append(b)
        adj[b].append(a)

    res = 0
    for t in permutations(range(2, n+1)):
        res += check(adj, t)
    print(res)

if __name__ == '__main__':
    main()



Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int n,W;
int v[10010],w[10010];
int dp[110][10010];
int main(void){
    cin>>n>>W;
    for(int i=0;i<n;i++){
        cin>>v[i]>>w[i];
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<=W;j++){
            if(j>=w[i]){
            dp[i+1][j]=max(dp[i][j],dp[i+1][j-w[i]]+v[i]);
            }
            else dp[i+1][j]=dp[i][j];
        }
    }
    cout<<dp[n][W]<<endl;;
    // Your code here!
    
}

Measured memory_bytes: 7012
#include <algorithm>
#include <cstdio>

inline int read(){
	char c=getchar(); int x=0;
	for(;c<'0'||c>'9';c=getchar());
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x;
}

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

inline void swap(int& a,int& b){
	int tmp=a; a=b; b=tmp;
}

const int N=2e5+5;

int n,q,m,w[N],fa[N],sz[N];

struct Edge{
	int u,v,w;
	bool operator < (const Edge& r) const { return w<r.w; }
}e[N<<1];

int find(int x){
	if(x==fa[x]) return x; else return fa[x]=find(fa[x]);
}

inline void unit(int x,int y){
	if(sz[x]<sz[y]) swap(x,y); fa[y]=x; sz[x]+=sz[y];
}

int main(){
	n=read(); q=read(); int pos=0;
	for(int i=0;i<n;++i) w[i]=2e9;
	for(int i=1,a,b,c;i<=q;++i){
		a=read(); b=read(); c=read();
		e[++m]=(Edge){a,b,c};
		w[(a+1)%n]=min(w[(a+1)%n],c+1);
		w[(b+1)%n]=min(w[(b+1)%n],c+2);
	}
	for(int i=0;i<n;++i) if(w[i]<w[pos]) pos=i;
	for(int i=(pos+1)%n,j=pos;i!=pos;){
		w[i]=min(w[i],w[j]+2); j=i; i=(i+1)%n;
	}
	for(int i=0;i<n;++i) e[++m]=(Edge){(i+n-1)%n,i,w[i]};
	std::sort(e+1,e+1+m); long long ans=0;
	for(int i=0;i<n;++i) fa[i]=i,sz[i]=1;
	for(int i=1;i<=m;++i){
		int u=find(e[i].u),v=find(e[i].v);
		if(u^v) unit(u,v),ans+=e[i].w;
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(){
  string n ;
  cin >> n ;
  int s = n.size();
  int ans = 0;
  if(n=="0") cout << "Yes" << endl;
  else{
  for(int i=0;i<s;i++){
    ans += n[i]-'0';
    ans %= 9;
  }
  if(ans%9==0) cout << "Yes" << endl;
  else cout << "No" << endl;
  }
}

Measured memory_bytes: 3760
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
bool like(char p,int *L,int len)
{
	int d= p - '0';
	for (int i=0;i<len;i++){
		if (L[i]==d){
			return true;
		}
	}
	return false;
}
int getGreater(char p,int *L,int len)
{
	int d= p - '0';
	for (int i=0;i<len;i++){
		if (L[i]>d){
			return L[i];
		}
	}
	return -1;
}
int main(int argc, char* argv[])
{
	int N,K;
	cin>>N>>K;
	int D[10];
	int L[10];
	int i,j;
	int d;
	for (i=0;i<10;i++){
		D[i]=-1;
	}
	for (i=0;i<K;i++){
		cin>>d;
		D[d]=d;
	}
	j=0;
	for (i=0;i<10;i++){
		if (D[i]==-1){
			L[j++]=i;
		}
	}
	char S[10];
	sprintf(S,"%d",N);
	char *p=S;
	i=0;
	while (*p != '\0'){
		if (i==0){
			if (!like(*p,L,j)){
				i=1;
				continue;
			}
		}else{
			d=getGreater(*p,L,j);
			if (d==-1){
				if (p==S){
					j=(int)strlen(S);
					i=0;
					while (L[i]==0){
						i++;
					}
					S[0] = L[i] + '0';
					int k;
					for (k=1;k<j+1;k++){
						S[k]=L[0] + '0';
					}
					S[k] = '\0';
					cout<<S<<endl;
					return 0;
				}else{
					p--;
					continue;
				}
			}else{
				*p = d + '0';
				p++;
				while (*p != '\0'){
					*p = L[0] + '0';
					p++;
				}
				cout<<S<<endl;
				return 0;
			}
		}
		p++;
	}
	cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int i, d, s;
	
	while (scanf("%d", &d) != EOF) {
		s = 0;
		for (i = 1; i*d < 600; i++) s += (i*d)*(i*d)*d;
		printf("%d\n", s);
	}
	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
int main(){
  	
  	int N,Q;
  	cin >> N >> Q;
	string S;
  	cin >> S;
  	std::vector<int> memo;
  	int c = 0;
  	for(int i = 0; i <= N ; i++){
 
        if(S[i-1] =='A'&&S[i]=='C'){

          c++;
          memo.push_back(c);
		
       	}else{
          
        		memo.push_back(c);
        
        }

    }

  	int l,r;
  	int flag,count;
  
  	for(int i = 0; i < Q;i++){
    	cin >> l >> r;
	//cout << memo[r-1] << " "<< memo[l]<<endl;
		count = memo[r-1]-memo[l-1];
      	cout << count << endl;
 
    }
 
 
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
#define ADD(a, b) a = (a + ll(b)) % mod
#define MUL(a, b) a = (a * ll(b)) % mod
#define MAX(a, b) a = max(a, b)
#define MIN(a, b) a = min(a, b)
#define rep(i, a, b) for(int i = int(a); i < int(b); i++)
#define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--)
#define all(a) (a).begin(), (a).end()
#define sz(v) (int)(v).size()
#define pb push_back
#define sec second
#define fst first
#define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<int, pi> ppi;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> mat;
typedef complex<double> comp;
void Debug() {cout << '\n'; }
template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){
	cout<<arg<<" ";Debug(rest...);}
template<class T>ostream& operator<<(ostream& out,const vector<T>& v) {
	out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;}
template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){
	out<<"("<<v.first<<", "<<v.second<<")";return out;}
const int MAX_N = 200010;
const int MAX_V = 100010;
const double eps = 1e-6;
const ll mod = 1000000007;
const int inf = 1 << 29;
const ll linf = 1LL << 60;
const double PI = 3.14159265358979323846;
///////////////////////////////////////////////////////////////////////////////////////////////////

int N;
map<ll, ll> S;

void solve() {
	cin >> N;
	ll sum = 0;
	S[sum]++;
	rep(i, 0, N) {
		ll a; cin >> a;
		sum += a;
		S[sum]++;
	}
	ll ans = 0;
	for(auto p : S) {
		ans += p.sec * (p.sec - 1) / 2;
	}
	cout << ans << "\n";
}

int main() {
#ifndef LOCAL
	ios::sync_with_stdio(false);
    cin.tie(0);
#endif
    cout << fixed;
	cout.precision(20);
	srand((unsigned int)time(NULL));
#ifdef LOCAL
	//freopen("in.txt", "wt", stdout); //for tester
    freopen("in.txt", "rt", stdin);
#endif	
	solve();
#ifdef LOCAL
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}



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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int r;
	cin >> r;
	int ans = 3 * r * r;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
using namespace std;

vector<int> c, a;

int dp(int b) {
	if (a[b] != -1) return a[b];
	int d = INT_MAX;
	for (int& i : c) {
		if (i <= b) d = min(dp(b - i) + 1, d);
	}
	a[b] = d;
	return d;
}

int main() {
	int n, m;
	cin >> n >> m;
	c.resize(m);
	for (int& i : c) cin >> i;
	a.resize(n + 1);
	fill(a.begin(), a.end(), -1);
	a.front() = 0;
	cout << dp(n) << endl;
}


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

#define _USE_MATH_DEFINES
#include<cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <deque>
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iterator>
#include<iomanip>
#include<unordered_set>
#include<bitset>
#include<complex>

using namespace std;

#define rep(i,a,b) for(int i=(a), i##_len=(b);i<i##_len;i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)

#define int ll
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair

//typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pdd;
typedef vector< vector<int> > mat;

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

const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD =  (int)1e9 + 7;
const double EPS = 1e-9;

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

	int N;
	string S;
	cin >> N >> S;

	int ans = 0;
	rep(i, 0, N - 2)
	{
		if (S[i] == 'A'&&S[i + 1] == 'B'&&S[i + 2] == 'C')
		{
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Ti = tuple<int, int, int>;
using Tl = tuple<ll, ll, ll>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
#define Get(t, i) get<(i)>((t))
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, f, n) for(int i = (int)(f); i < (int)(n); i++)
#define each(a, b) for(auto& a : b)

const int inf = 1 << 25;
const ll INF = 1LL << 55;

int main()
{
  int n; cin >> n;
  stack<int> st;
  bool flag = true;
  rep(i, n) {
    string s;
    cin >> s;
    if(s == "A") st.push(1);
    else {
      if(st.empty()) {
	flag = false;
      } else {
	st.pop();
      }
    }
  }
  cout << (flag && st.empty() ? "YES":"NO") << endl;
  return 0;
}

Measured memory_bytes: 3176
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = "1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51";
		String[] arr = str.split(", ");
		
		int k = sc.nextInt();
		System.out.println(arr[k - 1]);
		
		sc.close();
	}
}


Measured memory_bytes: 25300
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5;
#define mst(a) memset(a,0,sizeof a)
ll a,b,c,d,n;
unordered_map<ll,ll>mp; 
ll dfs(ll n){
	if(!n) return 0;
	if(n==1) return d;
	if(mp[n]) return mp[n];
	ll res=1e18;
	if(n<res/d) res=n*d;
	res=min(res,a+n%2*d+dfs(n/2));
	res=min(res,a+(2-n%2)*d+dfs((n+1)/2));
	res=min(res,b+n%3*d+dfs(n/3));
	res=min(res,b+(3-n%3)*d+dfs((n+2)/3));
	res=min(res,c+n%5*d+dfs(n/5));
	res=min(res,c+(5-n%5)*d+dfs((n+4)/5));
	mp[n]=res;
	return res;
}
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		mp.clear();
	scanf("%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d);
	  printf("%lld\n",dfs(n));
	 }
	return 0;
} 

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

using namespace std;

int main(){
  string s, t; cin >> s >> t;
  string res = "Yes";
  for(int i=0; i<s.size(); ++i){
    if(s[i] != t[i]) res = "No";
  }
  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define X first
#define Y second
using namespace std;

typedef long long ll;
typedef pair<ll,ll> pll;
const ll N = 100005;

ll n, d[N], cnt[N], rd[N];
map<ll,ll> dti, itd;
vector<ll> adj[N];
vector<pll> ans;

void dfs1 (ll I) {
	for(auto &T : adj[I]) {
		dfs1(T);
		rd[I] += rd[T] + cnt[T];
	}
}

void dfs2 (ll I) {
	for(auto &T : adj[I]) {
		rd[T] = rd[I] - cnt[T] + (n-cnt[T]);
		dfs2(T);
	}
}

int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++) {
		scanf("%lld",&d[i]);
		dti[d[i]] = i;
		itd[i] = d[i];
	}
	sort(d+1, d+1+n);
	for(ll i=n;i>=2;i--) {
		ll I = dti[d[i]];
		ll C = ++cnt[I];
		ll J = dti[d[i] - (n-C) + C];
		if(J == 0) {
			puts("-1");
			return 0;
		}
		ans.push_back({I, J});
		cnt[J] += cnt[I];
		adj[J].push_back(I);
	}
	ll R = dti[d[1]];
	dfs1(R);
	dfs2(R);
	for(ll i=1;i<=n;i++) {
		if(itd[i] != rd[i]) {
			puts("-1");
			return 0;
		}
	}
	for(auto &T : ans) {
		printf("%lld %lld\n", T.X, T.Y);
	}
}


Measured memory_bytes: 24816
from math import *
def isok(x):
    res=0
    for i in range(N):
        if A[i]<=x:
            continue
        res+=floor(A[i]/x)
    if res<=K:
        return True
    else:
        return False

N,K=map(int,input().split())
A=list(map(int,input().split()))

ng,ok=0,10**10

while(ok-ng>1):
    mid=(ok+ng)//2
    if isok(mid):
        ok=mid#最大をmid以下にするのが可能かどうか
    else:
        ng=mid
print(ok)

Measured memory_bytes: 93804
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
using namespace std;
#define MAX 300000
typedef long long ll;
typedef pair<ll,int> P;

int main(){
  int x,a;
  cin>>x>>a;
  if(x<a) cout<<0<<endl;
  else cout<<10<<endl;
}


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

using namespace std;

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

const int MAX_V = 100000;

vector<P> G[MAX_V];
ll dist[MAX_V];

void dfs(int v, int p) {
	for (int i = 0; i < G[v].size(); i++) {
		if (G[v][i].first != p) {
			dist[G[v][i].first] = dist[v] + G[v][i].second;
			dfs(G[v][i].first, v);
		}
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		a--;
		b--;
		G[a].emplace_back(b, c);
		G[b].emplace_back(a, c);
	}

	int q, k;
	cin >> q >> k;
	k--;
	dfs(k, -1);
	for (int i = 0; i < q; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		cout << dist[x] + dist[y] << endl;
	}
	return 0;
}

Measured memory_bytes: 14336
import std.stdio, std.conv, std.array, std.string, std.algorithm, std.container, std.range, core.stdc.stdlib, std.math, std.typecons;
T[][] combinations(T)(T[] s, in int m) {   if (!m) return [[]];   if (s.empty) return [];   return s[1 .. $].combinations(m - 1).map!(x => s[0] ~ x).array ~ s[1 .. $].combinations(m); }

void main() {
  int N, K; readf("%d %d\n", &N, &K);
  auto points = readln.split.to!(long[]);
  auto pattern = readln.chomp.map!(s => s == 'r' ? 2 : s == 's' ? 0 : 1).array;

  void solve() {
    long point;
    bool[] win = new bool[N];
    foreach(i; 0..N) {
      auto x = pattern[i];

      if (i >= K && win[i - K] == true && pattern[i - K] == x) {
        continue;
      }
      
      point += points[x];
      win[i] = true;
    }
    point.writeln;
  }

  solve();
}


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

using namespace std;

int main()	{
  long long n;
  cin >> n;
  long long a[n] = {0};
  long long max = 0;
  long long sum = 0;
  long long smallest_not_divisible = 1000000;
  long long number_not_divisible = 0;
  for (long long i = 0; i < n; i++)	{
    cin >> a[i];
    sum += a[i];
    if (a[i] % 10)	{
      number_not_divisible++;
      if (smallest_not_divisible > a[i])	{
        smallest_not_divisible = a[i];
      }
    }
  }
  if (sum % 10)	{
    cout << sum << endl;
    return 0;
  }
  if (number_not_divisible == 0)	{
    cout << 0 << endl;
  }
  else if (number_not_divisible == 1)	{
    cout << sum << endl;
  }
  else	{
    cout << sum - smallest_not_divisible << endl;
  }
  return 0;
}

Measured memory_bytes: 3580
import java.util.Scanner


object Main {


  def read() = {
    val sc = new Scanner(System.in)
    val n, l = sc.nextInt()
    (n, l)
  }

  def solve(n: Int, l: Int): Long = {
    def aji(i: Int) = l + i - 1

    val sum = (1 to n).map(aji).sum
    (1 to n).map { i =>
      // i: 1つだけ食べるりんご
      val others = sum - aji(i)
      (math.abs(others - sum), others)
    }.minBy(_._1)._2
  }

  def main(args: Array[String]): Unit = {
    val (n, l) = read()
    println(solve(n, l))
  }
}

Measured memory_bytes: 25796
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int s = stdIn.nextInt();
        int w = stdIn.nextInt();

        if(w >= s){
          System.out.println("unsafe");
        }else{
          System.out.println("safe");
        }
    }
}

Measured memory_bytes: 35780
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define SQ(x) ((x)*(x))
#define Mod(x, mod) (((x)+(mod)%(mod))
#define MP make_pair
#define PB push_back
#define Fi first
#define Se second
#define INF (1<<29)
#define EPS 1e-10
#define MOD 1000000007

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

ll dp[32];
int N;

int main(){
  while(cin >> N, N){
    memset(dp,0,sizeof(dp));
    dp[0]=1;
    for(int i=0;i<N;i++){
      for(int j=1;j<=3;j++){
	dp[i+j] += dp[i];
      }
    }
    int day = dp[N]/10 + ((dp[N]%10)?1:0);
    int res = day/365 + ((day%365)?1:0);
    cout <<  res << endl;
    //    cout << dp[N] << endl;;
  }
  return 0;
}

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

#define ll long long
#define sz(x) (int)x.size();

using namespace std;

ll n;

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	ll ans=1e18;
	for(ll i=1;i*i<=n;i++){
		if(n%i==0){
			ans=min(i-1+n/i-1,ans);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 3564
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#include "bits/stdc++.h"
#define REP(i,a,b) for(i=a;i<b;++i)
#define rep(i,n) REP(i,0,n)
#define ll long long
#define ull unsigned ll
typedef long double ld;
#define ALL(a) (a).begin(),(a).end()
#define ifnot(a) if(not a)
#define dump(x)  cerr << #x << " = " << (x) << endl
using namespace std;

void reader(int &a) { scanf("%d", &a); }
void reader(double &a) { scanf("%lf", &a); }
void reader(char a[]) { scanf("%s", a); }
void reader(char &a) { scanf(" %c", &a); }
void reader(ll &a) { scanf("%lld", &a); }
void reader(ull &a) { scanf("%llu", &a); }
// void reader(string& a){cin >> a;};
template<class T, class U> void reader(T& t, U& u) { reader(t); reader(u); }
template<class T, class U, class V> void reader(T& t, U& u, V& v) { reader(t); reader(u); reader(v); }

void writer(const int a, char c) { printf("%d", a); putchar(c); }
void writer(const ll a, char c) { printf("%lld", a); putchar(c); }
void writer(const ull a, char c) { printf("%llu", a); putchar(c); }
void writer(const double a, char c) { printf("%.20lf", a); putchar(c); }
void writer(const char a[]) { printf("%s", a); };
void writer(const char a[], char c) { printf("%s", a); putchar(c); };
void writer(const char a, char c) { putchar(a); putchar(c); };
template<class T> void writerLn(T t) { writer(t, '\n'); }
template<class T, class U> void writerLn(T t, U u) { writer(t, ' '); writer(u, '\n'); }
template<class T, class U, class V> void writerLn(T t, U u, V v) { writer(t, ' '); writer(u, ' '); writer(v, '\n'); }
template<class T> void writerArr(T x[], int n) { int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }
template<class T> void writerVec(vector<T> x) { int n = x.size(); int i; if (!n) { putchar('\n'); return; }rep(i, n - 1) writer(x[i], ' '); writer(x[n - 1], '\n'); }

vector<string> split(const string &str, char sep) { vector<string> v; stringstream ss(str); string buffer; while (getline(ss, buffer, sep)) { v.push_back(buffer); }return v; }
// #define int ll
bool test = 1;
int dx[] = { 0,1,0,-1 };
int dy[] = { 1,0,-1,0 };
#define MAX 300000
//.....................
ull mod = (int)1e9 + 7;

signed main(void)
{
	int i, j, k;
	int q;
	cin >> q;
	rep(i, q) {
		string s;
		cin >> s;
		int n = stoi(s);
		int cnt = 0;
		while (n > 9) {
			cnt++;
			int next_n = INT_MIN;
			REP(j, 1, s.size()) {
				int a1 = stoi(s.substr(0, j));
				int a2 = stoi(s.substr(j));
				if (a1*a2 > next_n) {
					next_n = a1*a2;
				}
			}
			n = next_n;
			s = to_string(n);
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; 
const int INF = 0x3f3f3f3f;
const int M = 1e9 + 7;
const int N = 100000 + 5;
ll a[N],b[N],f[N];
ll qpow(ll x, ll y){
    ll res = 1;
	while(y){
		if(y & 1) res = (res*x)%M;
		x = (x*x)%M;
		y >>= 1;
	}
	return res%M;
}
ll inv(ll a){return qpow(a,M-2);}
void table(int n,int k){
	if(k == 0)
		for(int i = 0;i <= n;i++)
			f[i] = 1;
	else{
		for(int i = 0;i <= k; i++)
			f[i] = 1;
		for(int i = k+1;i <= n;i++){
			f[i] = ((f[i-1] * i) % M) * inv(i-k) % M;
		}	
	}
	return ;
}
int main()
{
    int n,k;
    cin >> n >> k;
    table(n,k-2);
    for(int i = 1; i <= n; i++)
    	cin >> a[i];
	sort(a+1,a+n+1);
	b[0] = 0;
	for(int i = 1; i <= n; i++)
		b[i] = b[i-1] + a[i];
	if(k == 1)
		cout << 0 << endl;
	else if(k == n)
		cout << a[n] - a[1] << endl;
	else{
		ll sum = 0;
		for(int i = n - 2; i >= k - 2; i--){
			ll t1 = (b[n] - b[i+1]) % M;
			ll t2 = b[n-i-1] % M;
			sum = sum + ((t1 - t2) % M * f[i] % M);
			sum %= M;
		}
		cout << sum << endl;	
	}
    return 0;
}

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

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

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



int main(){
    int n, m;
    cin >> n >> m;
    VEC(ll, h, n);

    Graph G(n);
    vector<ll> MAX(n, -1);
    rep(i, m){
        int a, b;
        cin >> a >> b;
        a--;b--;

        G[a].push_back(b);
        MAX[a] = max(MAX[a], h[b]);
        G[b].push_back(a);
        MAX[b] = max(MAX[b], h[a]);
    }

    int res = 0;
    rep(i, n){
        if(h[i] > MAX[i])res++;
    }
    cout << res << endl;
}



Measured memory_bytes: 9452