akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(){
    int m, f, r;
    int TRUE=1;
    for(;;){
        scanf("%d %d %d", &m, &f, &r);
        if(m==-1&&f==-1&&r==-1)break;
        if(m==-1 || f==-1)printf("F\n");
        else if(m+f>=80)printf("A\n");
        else if(m+f>=65)printf("B\n");
        else if(m+f>=50 || r>=50)printf("C\n");
        else if(m+f>=30)printf("D\n");
        else printf("F\n");
    }
    return 0;
}

Measured memory_bytes: 2564
#!/usr/bin/env python

n = int(input())
a = list(map(int, input().split()))
a = [0] + a + [0] 

total = 0 
for i in range(n+1):
   total += abs(a[i]-a[i+1])

for i in range(1, n+1):
    ans = total-(abs(a[i]-a[i-1])+abs(a[i+1]-a[i]))+abs(a[i+1]-a[i-1])
    print(ans)


Measured memory_bytes: 20492
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
typedef pair<pint,int> tint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
set<pint> s1,s2;
int l[100100],r[100100];
int n,inf=1001001;
void outp(set<pint> s){
	set<pint>::iterator it=s.begin();
	while(it!=s.end()){
		cout<<(*it).fi<<','<<(*it).se<<' ';it++;
	}
	cout<<endl;
}
lint cal(int t){
	lint out=0;int now=0;
	rep(i,n){
		s1.insert(mp(-l[i],i));
		s2.insert(mp(r[i],i));
	}
	rep(i,n){
		//outp(s1);outp(s2);
		set<pint>::iterator it=s1.lower_bound(mp(-inf,0)),i2=s2.lower_bound(mp(-inf,0));
		int n1=-(*it).fi,n2=(*i2).fi,id1=(*it).se,id2=(*i2).se;
		if(n1<=now && now<=n2){
			s1.erase(it);
			s2.erase(s2.lower_bound(mp(r[id1],id1)));
		}
		else if(n1>now && n2<now){
			if(t==0){
				out+=n1-now;
				now=n1;
				s1.erase(it);
				s2.erase(s2.lower_bound(mp(r[id1],id1)));
			}
			else{
				out+=now-n2;
				now=n2;
				s2.erase(i2);
				s1.erase(s1.lower_bound(mp(-l[id2],id2)));
			}
		}
		else if(n1-now > now-n2){
			out+=n1-now;
			now=n1;
			s1.erase(it);
			s2.erase(s2.lower_bound(mp(r[id1],id1)));
		}
		else{
			out+=now-n2;
			now=n2;
			s2.erase(i2);
			s1.erase(s1.lower_bound(mp(-l[id2],id2)));
		}
		//cout<<now<<endl;
	}
	return out+abs(now);
	//cout<<out+abs(now)<<endl;
}
int main()
{
	cin>>n;
	rep(i,n){
		cin>>l[i]>>r[i];
	}
	/*rep(i,n){
		s1.insert(mp(-l[i],i));
		s2.insert(mp(r[i],i));
	}
	rep(i,n){
		//outp(s1);outp(s2);
		set<pint>::iterator it=s1.lower_bound(mp(-inf,0)),i2=s2.lower_bound(mp(-inf,0));
		int n1=-(*it).fi,n2=(*i2).fi,id1=(*it).se,id2=(*i2).se;
		if(n1<=now && now<=n2){
			s1.erase(it);
			s2.erase(s2.lower_bound(mp(r[id1],id1)));
		}
		//else if(now<n1 && (now<=n2 || abs(now-n1)>abs(now-n2)))
		else if(n1-now > now-n2){
			out+=n1-now;
			now=n1;
			s1.erase(it);
			s2.erase(s2.lower_bound(mp(r[id1],id1)));
		}
		else{
			out+=now-n2;
			now=n2;
			s2.erase(i2);
			s1.erase(s1.lower_bound(mp(-l[id2],id2)));
		}
		//cout<<now<<endl;
	}
	cout<<out+abs(now)<<endl;*/
	cout<<max(cal(0),cal(1))<<endl;
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, n, m) for (int i = n; i < m; i++)
#define ll long long int

using namespace std;

int main()
{
  int n, a, b, c, d;
  cin >> n >> a >> b >> c >> d;
  string s;
  cin >> s;

  bool dpa[200001] = {};
  bool dpb[200001] = {};

  // a
  dpa[a] = true;
  FOR(i, a + 1, c + 1)
  {
    dpa[i] = (dpa[i - 1] || dpa[max(i - 2, 0)]) && s[i - 1] != '#';
  }

  dpb[b] = true;
  FOR(i, b + 1, d + 1)
  {
    dpb[i] = (dpb[i - 1] || dpb[max(i - 2, 0)]) && s[i - 1] != '#';
  }

  // 追い越せるか
  bool oikoshi = false;
  FOR(i, b - 1, d)
  {
    if (i + 2 >= n)
      continue;
    if (s[i - 1] == '.' && s[i] == '.' && s[i + 1] == '.' && dpb[i + 1] && dpa[i])
    {
      oikoshi = true;
      break;
    }
  }

  if (c < d)
  {
    if (dpa[c] && dpb[d])
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
  else
  {
    if (dpa[c] && dpb[d] && oikoshi)
    {
      cout << "Yes" << endl;
    }
    else
    {
      cout << "No" << endl;
    }
  }
}


Measured memory_bytes: 900
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
#define int long long int
#define all(x) (x).begin(), (x).end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
typedef pair<int,int> pii;
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define ub upper_bound
#define lb lower_bound
#define present(c,x) (c.find(x) != c.end())
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'	
#define fill(s,x,n) vector
 x(n); rep(i,0,n) cin>>x[i];
#define INF 1000000007 
#define MOD 998244353
#define INF64 1e18

void solve(){
	int n,W;
	cin>>n>>W;
	vector<int> v(n+1);
	vector<int> w(n+1);
	rep(i,1,n+1)
		cin>>w[i]>>v[i];

	// vector<vector<int>> dp(n+1,vector<int> (W+1,0));
	vector<int> dp(W+1,0);
	rep(i,1,n+1){
		rep(j,W+1,1){
			if(j>=w[i])
				dp[j]=max(dp[j-w[i]]+v[i],dp[j]);
		}
	}

	cout<<dp[W];
}
 
int32_t main(){
	
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
 
	int T;
	// cin>>T;
	T=1;
	while(T--){
		solve();
	}
}

Measured memory_bytes: 3988
#include <bits/stdc++.h>
using namespace std;
int i,j,ans=0,n,m,d,l,f[10001][101][2];
char a[10001];
int main()
{
	scanf("%s",a);
	scanf("%d",&d);
	n=strlen(a);
	f[0][0][1]=1;
	for(i=0;i<n;i++)
	{
		for(j=0;j<d;j++)
		{
			for(l=0;l<=9;l++)
			{
				f[i+1][(j+l)%d][0]=(f[i+1][(j+l)%d][0]+f[i][j][0])%1000000007;
			}
			for(l=0;l<=a[i]-'0';l++)
			{
				if(l==a[i]-'0')
					f[i+1][(j+l)%d][1]=(f[i][j][1]+f[i+1][(j+l)%d][1])%1000000007;
				else
					f[i+1][(j+l)%d][0]=(f[i+1][(j+l)%d][0]+f[i][j][1])%1000000007;
			}
		}
	}
	printf("%d",(f[n][0][0]+f[n][0][1]+1000000007-1)%1000000007);
}

Measured memory_bytes: 8192
using System;
using System.Collections.Generic;
using System.Linq;
class Program{
    static void Main(string[] args){
    var N = int.Parse(Console.ReadLine());
    var A=new List<int>();
    for(int i=0;i<N;i++){
        A.Add(int.Parse(Console.ReadLine()));
    }
    int ans=A.Max();
    int cnt=A.Count(n=>n==ans);
    for(int i=0;i<N;i++){
        if(A[i]!=ans){
    Console.WriteLine(ans);
        }
        else{
            if(cnt>1){
                Console.WriteLine(ans);
            }
            else{
            var B=new List<int>(A); //値渡しにする！
            B.Remove(ans);
            Console.WriteLine(B.Max());
            }
        }
    }
    }
}

Measured memory_bytes: 19284
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String x = "";
		try {
			x = in.readLine();
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		String[] values = x.split(" ");

		int width = Integer.parseInt(values[0]);
		int height = Integer.parseInt(values[1]);
		int cx = Integer.parseInt(values[2]);
		int cy = Integer.parseInt(values[3]);
		int r = Integer.parseInt(values[4]);

		if (((cx - r) < 0) || ((cy - r) < 0) || ((cx + r) > width) || ((cy + r) > height)) {
			System.out.println("No");
		} else {
			System.out.println("Yes");
		}
	}
}

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

int n,k,h,w,a,b;  
string s,t;
bool g[15][15];

int main() {
  cin >> n >> h >> w;
  int ans=0;
  rep(i,n){
  cin >> a >> b;
  if(a/h>=1 && b/w>=1) ans+=min(a/h,b/w);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n = s.size();
    int b = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i; j < n; j++) {
            if (s.substr(0, i) + s.substr(j) == "keyence") {
                b = 1;
                break;
            }
        }
    }

    cout << (b ? "YES" : "NO") << endl;

    return 0;
}

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

#define MAX 1000001

//最初に列挙
int h_hamingu[MAX] = {0};

//掛ける変数
const int h_kakeru[3] = {2 , 3 , 5};

//----- 関数で列挙 -----//
void f_rekkyo();


int main(void)
{
	//入力変数
	int first = 0;
	int second = 0;

	//関数で列挙
	f_rekkyo();

	while (true)
	{
		//入力
		cin >> first;
		if (first == 0)	{	return 0;	}
		cin >> second;
		//カウント変数
		int count = 0;

		for (int i = first; i <= second; i++)
		{
			if (h_hamingu[i] == 1)
			{
				count++;
			}
		}

		cout << count << endl;
	}

	return 0;
}



//*****----- 最初に列挙 -----*****//

void f_rekkyo()
{
	//1はハミング
	h_hamingu[1] = 1;

	for (int i = 0; i < MAX; i++)
	{
		if (h_hamingu[i] == 1)
		{
			for (int j = 0; j < 3; j++)
			{
				if (i * h_kakeru[j] <= 1000000)
				{
					h_hamingu[i * h_kakeru[j]] = 1;
				}
			}
		}
	}
}

Measured memory_bytes: 2240
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define rep(i,m,n) for(int i = (m);i < (n);i++)
#define P pair<int,int>
#define pb push_back
#define mk make_pair
using namespace std;
#define Vec(a) vector <int> a
#define F first
#define S second
const int INF = 1 << 20;
const int MOD = 1e9+7;





int main(){

    int r,s,p;
    cin >> r >> s >> p;
    int a[500010] = {};
    REP(i,p){
        int c,d;
        cin >> c >> d;
        if(d <= s)
            a[(r+1 - c) + (abs(d-s)+1)]++;
        
        else
        {
            a[(r+1 - c) + (d-s)]++;
        }
    }
    REP(i,500010){
        if(a[i] > 1){
            a[i+1] += (a[i]-1);
            a[i] = 1;
        }
    }
    int x = 0;
    REP(i,500010){
        if(a[i] > 0){
            x = i;
        }
    }
    cout << x << endl;

    return 0;
}



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

using namespace std;


// sufficient but not necessary
// 8 4 4 4 3 2 1 1 
void wrong_solve() {
    int n; cin >> n;
    vector<int> a(1<<n);
    for (auto& x: a) {
        cin >> x;
    }
    sort(a.begin(), a.end(), greater<int>());
    for (int j = 0; j < n; j++) {
        int k = 1<<j;
        for (int i = 0; i < k; i++) {
            if (a[i] <= a[i+k]) {
                cout << "No"; return;
            }
        }
    }
    cout << "Yes";
}

void solve() {
    int n; cin >> n;
    multiset<int, greater<int>> st;
    const int N = 1<<n; 
    for (int i = 0; i < N; i++) {
        int x; cin >> x;
        st.insert(x);
    }
    multiset<int, greater<int>> pa;
    pa.insert(*st.begin()); st.erase(st.begin());
    for (int i = 0; i < n; i++) {
        int k=1<<i;
        vector<int> sn(k);
        int j=0;
        for (int x: pa) {
            auto it = st.upper_bound(x);
            if (it == st.end()) {
                cout << "No"; return;
            }
            sn[j++] = *it;
            st.erase(it);
        }
        for (int x: sn) pa.insert(x);
    }
    cout << "Yes";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 13180
N , Q = map(int, input().split())
S = input()
LR = [[int(i)-1 for i in input().split()] for j in range(Q)]
T = list(S)
ACtimes = [0] * len(T)

for i in range(1,len(T)):
    if T[i-1] == "A" and T[i] == "C":
        ACtimes[i] = ACtimes[i-1] + 1
    else:
        ACtimes[i] = ACtimes[i-1]

for k in LR:
    print(ACtimes[k[1]] - ACtimes[k[0]])


Measured memory_bytes: 25268
#B
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans=0
for i in range(n - 1):
    if a[i] + 1 == a[i + 1]:
        ans += c[a[i]-1]
ans += sum(b)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

string nav(int diffx, int diffy){
  string res = "";
  rep(i, diffy){
    res += "U";
  }
  rep(i, diffx){
    res += "R";
  }
  return res;
}
string nav_rev(int diffx, int diffy){
  string res = "";
  rep(i, diffy){
    res += "D";
  }
  rep(i, diffx){
    res += "L";
  }
  return res;
}

int main(){
  string ans = "";
  int sx, sy, tx, ty;
  cin >> sx >> sy >> tx >> ty;
  int diffx = abs(tx - sx), diffy = abs(ty - sy);
  ans = nav(diffx, diffy);
  ans += nav_rev(diffx, diffy);
  ans += "L";
  ans += nav(diffx + 1, diffy + 1);
  ans += "D";
  ans += "R";
  ans += nav_rev(diffx + 1, diffy + 1);
  ans += "U";
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<math.h>
#include<vector>

using namespace std;
int main() {
	int a, b;

	cin >> a >> b;
	if ((a*b)%2==0)
	{
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}

	return 0;

}


Measured memory_bytes: 256
#include<cstdio>
typedef long long ll;
const ll mod=998244353;
inline ll rev(ll x)
{ll k=mod-2,r=1;for(;k;k>>=1,(x*=x)%=mod)if(k&1)(r*=x)%=mod;return r;}
ll fac[1111111],inv[1111111];
inline ll C(int n,int r)
{return((((fac[n]*inv[r])%mod)*inv[n-r])%mod);}
int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	if(n<m)n^=m,m^=n,n^=m;
	fac[0]=inv[0]=1;
	register int i;
	for(i=1;i<=n+m;i++)fac[i]=(fac[i-1]*i)%mod;
	inv[n+m]=rev(fac[n+m]);
	for(i=n+m-1;i;i--)inv[i]=inv[i+1]*(i+1)%mod;
	ll ans=0;
	for(i=1;i<=m;i++)
		(ans+=C(i*2,i)*C(n+m-2*i,n-i))%=mod;
	(((ans*=rev(2*C(n+m,n)))%=mod)+=n+mod)%=mod;
	printf("%lld\n",ans);
}

Measured memory_bytes: 16640
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> tmp;
vector<vector<int> > c;
void dfs(int pos,vector<int> tmp,vector<bool> visit);
int main(){
    cin>>n;
    vector<int> p(n);
    vector<int> q(n);
    vector<bool> visit(n+1,false);
    for(int i=0;i<n;i++){
        cin>>p[i];
    }
    for(int i=0;i<n;i++){
        cin>>q[i];
    }
    dfs(0,tmp,visit);
    int a,b;
    //cout<<endl;
    for(int i=0;i<c.size();i++){
        bool flaga=true,flagb=true;
        for(int j=0;j<n;j++){
            //cout<<c[i][j]<<" ";
            if(c[i][j]!=p[j]){
                flaga=false;
            }
            if(c[i][j]!=q[j]){
                flagb=false;
            }
        }
        //cout<<endl;
        if(flaga)a=i+1;
        if(flagb)b=i+1;
    }
    //cout<<a<<" "<<b<<endl;
    cout<<abs(a-b)<<endl;
    return 0;
}
void dfs(int pos,vector<int> tmp,vector<bool> visit){
    if(pos==n){
        c.push_back(tmp);
        return;
    }
    for(int i=1;i<=n;i++){
        if(!visit[i]){
            visit[i]=true;
            tmp.push_back(i);
            dfs(pos+1,tmp,visit);
            tmp.pop_back();
            visit[i]=false;
        }
        
    }
}

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

#define MAX 10010

using namespace std;
typedef long long int lli;

int n;

int a[MAX];
int b[MAX];

lli movesA;
lli movesB;

int main()
{
	scanf("%d",&n);

	for(int g = 1 ; g <= n ; g++)
		scanf("%d",&a[g]);

	for(int g = 1 ; g <= n ; g++)
		scanf("%d",&b[g]);

	for(int g = 1 ; g <= n ; g++)
	{
		if(a[g] > b[g]) movesB += a[g] - b[g];
		if(a[g] < b[g])
		{
			movesA += (b[g] - a[g] + 1)/2;

			if((b[g] - a[g])%2 == 1) movesB++;
		}
	}

	if(movesA >= movesB) printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdio>
#include <string>
#include <sstream>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define repn(i, n) for(int i = 1; i <= (int)n; ++i)
#define pb push_back
#define lb lower_bound
#define mp make_pair
#define ite iterator
#define max2(x, y) ((x) > (y)) ? (x) : (y)
#define max3(x,y,z) max2((x), max2((y),(z)))
#define max4(v,w,x,y) max2(max2((v),(w)), max2((x),(y)))
#define min2(x, y) ((x) > (y)) ? (y) : (x)
#define min3(x,y,z) min2((x), min2((y),(z)))
#define min4(v,w,x,y) min2(min2((v),(w)), min2((x),(y)))
#define ul unsigned long
#define ull unsigned long long
#define INF 1000000007
#define MOD 1000000007
#define fs first
#define sd second

template<typename T>
bool elem(set<T> st, T val){
	return (st.find(val) != st.end());
}

template<typename T>
void printv(vector<T> vt){
    rep(i, vt.size() - 1)
        cout << vt[i] << " ";
    cout << vt[vt.size() - 1] << endl;
}

typedef vector<int> vint;
typedef vector<ul> vul;
typedef vector<ull> vull;
typedef pair<int, int> pii;


int main(void){
    ull a, b;
    while(cin >> a >> b){
        ull g = __gcd(a, b);
        ull l = a/g*b;
        cout << g << " " << l << endl;
    }
    return 0;
}

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

int func(int x) {
    if (x < 10) {
        return x;
    }
    else {
        return x % 10 + func(x / 10);
    }
}

int main() {
    int N, A, B;
    cin >> N >> A >> B;

    int sum = 0;
    for (int i = 1; i <= N; i++) {
        if (A <= func(i) && func(i) <= B) {
            sum += i;
        }
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	a, b, c := ReadInt(), ReadInt(), ReadInt()
	m := make(map[int]bool)
	m[a] = true
	m[b] = true
	m[c] = true
	fmt.Println(len(m))
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }


Measured memory_bytes: 1840
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};


int main(){
    CIN(N);CIN(M);
    vector<vector<int>> vec(N);
    REP(a,M){
        CIN(b);CIN(c);
        vec.at(b-1).push_back(a);
        vec.at(c-1).push_back(a);
    }
    set<int> ins;
    int ans = 0;
    REP(a,N){
        set<int> s;
        bool w = false;
        REP(b,vec.at(a).size()){
            if(ins.find(vec.at(a).at(b)) != ins.end() && !w){
               // COUT(vec.at(a).at(b));
                //COUT(a);
                ans++;
                w = true;
            }else{
                s.insert(vec.at(a).at(b));
            }
            ins.insert(vec.at(a).at(b));
        }
        if(w){
            ins = s;
        }
    }
    COUT(ans);
    return 0;
}


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

int main(){
    int cnt[100]={0};
    rep(i,10)rep(j,10)rep(k,10)rep(l,10){
        int a=i+j+k+l;
        if(a<=50)cnt[a]++;
    }

    int n;
    while(scanf("%d",&n)!=EOF)printf("%d\n",cnt[n]);

    return 0;
}

Measured memory_bytes: 1188
def resolve():
    N = int(input())
    arr = tuple(map(int, input().split()))
    from collections import Counter
    cnt = Counter(arr)
    m = 10 ** 9 + 7
    ans = 1
    for i in range(N - 1, 0, -2):
        if i not in cnt or cnt[i] != 2:
            ans = 0
            break
        ans = (ans << 1) % m
    if N % 2 and (0 not in cnt or cnt[0] != 1):
        ans = 0
    print(ans % m)

resolve()

Measured memory_bytes: 58092
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

const int MAXN=1e5+5;
ll dp[MAXN];

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

    int n,W; cin>>n>>W;

    FOR(i,n) {
        ll w,v; cin>>w>>v;

        for(int j=W-w; j>=0; j--) {
            dp[j+w] |= MAX(dp[j]+v);
        }
    }

    cout<<dp[W]<<endl;
    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

typedef struct _Numbers {
	int size;
	int *s;
}Numbers;

int main(void) {
	int n, m, sw;
	Numbers Num;
	scanf("%d", &n);
	Num.s = (int *)malloc(sizeof(int)*n);
	scanf("%d", Num.s);
	Num.size = 1;
	for (int i = 1; i < n; i++) {
		sw = 1;
		scanf("%d", &m);
		for (int j = 0; j < Num.size; j++) {
			if (m == Num.s[j]) {
				sw = 0;
				break;
			}
		}
		if (sw) {
			Num.s[Num.size] = m;
			Num.size++;
		}
	}
	printf("%d\n", Num.size);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#define rep(i,x,y) for(int i=(x);i<=(y);++i)
#define per(i,x,y) for(int i=(x);i>=(y);--i)
const int N=1e5+10;
inline bool vaild(char c){return c=='o'||c=='x';}
inline char gc(){char c=getchar();while(!vaild(c))c=getchar();return c;}
int n;
int s[N],a[N];
bool work(int a1,int a2){
	a[1]=a1;a[2]=a2;
	rep(i,3,n){
		a[i]=a[i-1]^s[i-1]^a[i-2];
	}
	return a[n]^a[2]^a[1]^s[1]==0&&a[n]^s[n]^a[n-1]^a[1]==0;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n)s[i]=(gc()=='x');
	if(work(0,0)||work(0,1)||work(1,0)||work(1,1)){
		rep(i,1,n)printf("%c",a[i]?'W':'S');
	}else puts("-1");
	return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 998244353;

int main() {
	string S;
	cin >> S;
	if (S[S.size() - 1] == 's') {
		cout << S << "es" << endl;
	}
	else {
		cout << S << "s" << endl;
	}
}

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

int N;
vector<int> visit, dis, ans;
vector<set<int> > adj_0, adj_1;


void dfs(int a){
  visit[a] = 1;
  for (int i: adj_0[a]){
    if (visit[i]==0) {
      ans[i] = ans[a];
      dfs(i);
    }
  }
  for (int i: adj_1[a]){
    if (visit[i]==0) {
      ans[i] = (ans[a]+1)%2;
      dfs(i);
    }
  }
}

int main(){
  cin >> N;

  visit.resize(N+1);
  ans.resize(N+1);
  adj_0.resize(N+1);
  adj_1.resize(N+1);

  for(int i=0; i<N+1; i++){
    visit[i] = 0;
    ans[i] = -1;
  }

  int u,v,w;
  for(int i=1; i<N; i++){
    cin >> u >> v >> w;
    if(w%2 == 0){
      adj_0[u].insert(v);
      adj_0[v].insert(u);
    } else {
      adj_1[u].insert(v);
      adj_1[v].insert(u);
    }
  }

  ans[1] = 0;
  dfs(1);

  for(int i=1; i<N+1; i++){
    printf("%d\n", ans[i]);
  }
}


Measured memory_bytes: 20864
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){
    int n;
    int k;
    cin >> n >> k;
    vector<int> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int sum = 0;
    for(int i = 0; i < k; i++){
        sum += p[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3628
import sys
import math
import collections
import bisect
import itertools

# import numpy as np

sys.setrecursionlimit(10 ** 7)
INF = 10 ** 20
MOD = 10 ** 9 + 7
# MOD = 998244353

ni = lambda: int(sys.stdin.readline().rstrip())
ns = lambda: map(int, sys.stdin.readline().rstrip().split())
na = lambda: list(map(int, sys.stdin.readline().rstrip().split()))
na1 = lambda: list(map(lambda x: int(x) - 1, sys.stdin.readline().rstrip().split()))


# ===CODE===

def main():
    n = ni()
    a = [ni() for _ in range(n)]
    a_sorted = sorted(a)

    ans = 0
    for i, ai in enumerate(a):
        idx = bisect.bisect_left(a_sorted, ai)
        if (idx - i) % 2:
            ans += 1

    print(ans // 2)


if __name__ == '__main__':
    main()


Measured memory_bytes: 14388
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

int main(int argc,char **argv){
  int32_t x,a;
  std::cin>>x>>a;

  if(x<a){
    std::cout<<0<<std::endl;
  }else{
    std::cout<<10<<std::endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

#define MAX 20
#define INF 1e9

int H,W,ax,ay,bx,by;
char field[MAX][MAX];
string str;
const int dx[] = {-1,0,0,1,0};
const int dy[] = {0,-1,1,0,0};

struct State{
  int sx,sy,gx,gy;
  State(int sx,int sy,int gx,int gy) : sx(sx),sy(sy),gx(gx),gy(gy) {}
};

bool inField(int y,int x){
  return 0 <= y && y < H && 0 <= x && x < W;
}

int getDir(char ch){
  if(ch == '4') return 0;
  if(ch == '8') return 1;
  if(ch == '2') return 2;
  if(ch == '6') return 3;
  return 4;
}

void bfs(){
  int size = str.size();
  bool visited[MAX][MAX][MAX][MAX][MAX];
  memset(visited,0,sizeof(visited));
  visited[ay][ax][by][bx][0] = true;
  queue<State> Q;
  queue<int> Count;
  Q.push(State(ax,ay,bx,by));
  Count.push(0);
  while(!Q.empty()){
    State s = Q.front(); Q.pop();
    int cnt = Count.front(); Count.pop();

    if(s.sx == s.gx && s.sy == s.gy){
      cout << cnt << " " << s.sy << " " << s.sx << endl;
      return;
    }

    int dir = getDir(str[cnt%size]);
    int Gx = s.gx + dx[dir], Gy = s.gy + dy[dir];
    if(!inField(Gy,Gx)) Gx = s.gx, Gy = s.gy;

    for(int i = 0 ; i < 5 ; i++){
      int nx = s.sx + dx[i], ny = s.sy + dy[i];
      if(!inField(ny,nx)) continue;
      if(field[ny][nx] == '#') continue;
      if(visited[ny][nx][Gy][Gx][(cnt+1)%size]) continue;
      visited[ny][nx][Gy][Gx][(cnt+1)%size] = true;
      Q.push(State(nx,ny,Gx,Gy));
      Count.push(cnt+1);
    }
  }
  cout << "impossible" << endl;
}

int main(){
  while(cin >> H >> W, (H|W)){
    for(int i = 0 ; i < H ; i++){
      for(int j = 0 ; j < W ; j++){
        cin >> field[i][j];
        if(field[i][j] == 'A'){
          ax = j, ay = i;
        }else if(field[i][j] == 'B'){
          bx = j, by = i;
        }
      }
    }
    cin >> str;
    bfs();
  }

  return 0;
}

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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  cout << min(N * A, B) << endl;
  return 0;
}

Measured memory_bytes: 3632
n, a, b, c = gets.split.map &:to_i

l = []

n.times{
	l << gets.to_i
}

x = [0, 1, 2, nil]

d = x.repeated_permutation(l.size)

min_count = 100000000000000000000

d.each{ |x|
	count = 0

	sum = Array.new(3, 0)

	x.each_with_index{ |index, i|
		if index != nil then
			if sum[index] != 0 then
				count += 10
			end
			
			sum[index] += l[i]
		end
	}
	
	if sum[0] == 0 || sum[1] == 0 || sum[2] == 0 then
		next
	end
	
	count += (sum[0] - a).abs + (sum[1] - b).abs + (sum[2] - c).abs
	
	if count < min_count then
		min_count=  count
	end
}

puts min_count

Measured memory_bytes: 1916
#include <iostream>
using namespace std;
int main(void){
    int n,t[100000],a[100000],u=0,b;
    long long q=1,p=1e9+7;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>t[i];
        if(i>0){
            if(t[i]>t[i-1]){
                u=i;
            }
        }
    }
    b=n-1;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(i>0&&b==n-1){
            if(a[i]<a[i-1]){
                b=i-1;
                if(b<u){
                    cout<<0<<endl;
                    return 0;
                }
            }
        }
    }
    if(t[u]!=a[b]){
        cout<<0<<endl;
        return 0;
    }
    for(int i=1;i<n-1;i++){
        if(i<u&&t[i]==t[i-1]){
            q=(q*t[i])%p;
        }else if(i>u&&a[i]==a[i+1]){
            q=(q*a[i])%p;
        }
    }
    cout<<q<<endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
#define fi first
#define se second

signed main(){
  string s;
  cin>>s;
  int a=0,b=0;
  r(i,s.size()){
    if(s[i]=='0')a++;
    else b++;
  }
  int c=min(a,b);
  a-=c;
  b-=c;
  cout<<c*2<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
using namespace std;

int main(void) {
	int N;
	int ans = 0;
	cin >> N;
	for (int i = N;i > 0;i /= 10) {
		ans += i % 10;
	}
	if (N==10 || N == 100 || N == 1000 || N == 10000 || N == 100000 )
		ans = 10;
	cout << ans << endl;


}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	static int N, ans[];
	static String s;
	static boolean out;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		N = sc.nextInt();
		s = sc.next();
		sc.close();
		ans = new int[N];
		//羊が0、狼は1
		for(int i=0;i<4;i++) {
			out = false;
			char firstChar = s.charAt(0); 
			Arrays.fill(ans, -1);
			if(i==0) {
				ans[N-1]=ans[0]=0;
			}
			else if(i==1) {
				ans[N-1]=0;ans[0]=1;
			}
			else if(i==2) {
				ans[N-1]=1;ans[0]=0;
			}
			else if(i==3) {
				ans[N-1]=ans[0]=1;
			}
			first_next(firstChar,0,N-1);
			
			for(int j=1;j<N-1;j++) {
				char now = s.charAt(j);
				next(now, j);
				if(out)break;
			}
			lastCheck(s.charAt(N-1),0,N-1);
			if(!out) {
				StringBuilder sb = new StringBuilder();
				for(int t : ans) {
					if(t==0)sb.append("S");
					else sb.append("W");
				}
				System.out.println(sb.toString());
				return;
			}
			

		}
		System.out.println(-1);	
	}
	static void next(char now, int center) {
		if(now=='o') {
			if(ans[center-1]==0&&ans[center]==0)if(!check(center+1, 0))return;
			if(ans[center-1]==0&&ans[center]==1)if(!check(center+1, 1))return;
			if(ans[center-1]==1&&ans[center]==0)if(!check(center+1, 1))return;
			if(ans[center-1]==1&&ans[center]==1)if(!check(center+1, 0))return;
		}else {
			if(ans[center-1]==0&&ans[center]==0)if(!check(center+1, 1))return;
			if(ans[center-1]==0&&ans[center]==1)if(!check(center+1, 0))return;
			if(ans[center-1]==1&&ans[center]==0)if(!check(center+1, 0))return;
			if(ans[center-1]==1&&ans[center]==1)if(!check(center+1, 1))return;
		}
	}
	static boolean check(int next, int z_o) {
		if(ans[next]!=-1&&ans[next]!=z_o) {
			out = true;
			return false;
		}
		ans[next]=z_o;
		return true;
	}
	
	static void first_next(char lastChar, int start, int last) {
		if(lastChar=='o') {
			if(ans[last]==0&&ans[start]==0)if(!check(start+1, 0))return;
			if(ans[last]==0&&ans[start]==1)if(!check(start+1, 1))return;
			if(ans[last]==1&&ans[start]==0)if(!check(start+1, 1))return;
			if(ans[last]==1&&ans[start]==1)if(!check(start+1, 0))return;
		}else {
			if(ans[last]==0&&ans[start]==0)if(!check(start+1, 1))return;
			if(ans[last]==0&&ans[start]==1)if(!check(start+1, 0))return;
			if(ans[last]==1&&ans[start]==0)if(!check(start+1, 0))return;
			if(ans[last]==1&&ans[start]==1)if(!check(start+1, 1))return;
		}
	}
	static void lastCheck(char now, int start, int last) {
		if(now=='o') {
			if(ans[last-1]==0&&ans[last]==0)if(!check(start, 0))return;
			if(ans[last-1]==0&&ans[last]==1)if(!check(start, 1))return;
			if(ans[last-1]==1&&ans[last]==0)if(!check(start, 1))return;
			if(ans[last-1]==1&&ans[last]==1)if(!check(start, 0))return;
		}else {
			if(ans[last-1]==0&&ans[last]==0)if(!check(start, 1))return;
			if(ans[last-1]==0&&ans[last]==1)if(!check(start, 0))return;
			if(ans[last-1]==1&&ans[last]==0)if(!check(start, 0))return;
			if(ans[last-1]==1&&ans[last]==1)if(!check(start, 1))return;
		}
	}
}


Measured memory_bytes: 27624
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define rep(i, init, n) for(int i = init; i <(int)(n); i++)

struct coun{
    vector<int> v;
    ll size;
    void update(char c, char c1){
        ll i = c - 'a';
        ll i1 = c1 - 'a';
        v[i]--;
        if (v[i] == 0) size--;
        if (v[i1] == 0) size++;
        v[i1]++;
    }
};
class BIT
{
public:
    vector<coun> bit;
    int M;

    BIT(int M):
        M(M), bit(M+1) {
            REP(i, M+1){
                vector<int> hoge(27, 0);
                bit[i].v = hoge;}
        }
    void set(int i, char c){
        if (i > M) return;
        int h = c - 'a';
        bit[i].v[h]++;
        set(i+(i&-i), c);

    }
    vector<int> sum(int i) {
        vector<int> vv(27, 0);
        if (!i) return vv;
        vv = sum(i-(i&-i));
        return mm(vv, bit[i].v);
    }

    void update(int i, char x, char y) {
        if (i > M) return;
        bit[i].update(x, y);
        update(i+(i&-i), x, y);
    }

    vector<int> mm(vector<int>& a, vector<int>& b){
    int n = a.size();
    vector<int> hoge(n, 0);
    REP(i, n) hoge[i] = a[i] + b[i];
    return hoge;
    }
};


int main() {
    ll N, Q;
    string S;
    cin >> N;
    cin >> S;
    cin >> Q;

    BIT B(N);
    REP(i, N){
        B.set(i+1, S[i]);

    }

    vector<int> ans;
    vector<int> v_l, v_r;
    ll mode, l, r;
    char c;
    REP(i, Q){
        cin >> mode;
        if (mode == 1) {
            cin >> l >> c;
            B.update(l, S[l-1], c);
            S[l - 1] = c;
            }

        else {
            cin >> l >> r;
            v_l = B.sum(l-1);
            v_r = B.sum(r);
            int tmp = 0;
            REP(i, 27) if (v_r[i] - v_l[i] > 0) tmp++;
            ans.push_back(tmp);
        }
    }

    REP(i, ans.size()) cout << ans[i] << endl;
    return 0;
}



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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    long long ans = 0, cnt = 0;
    for(int i = 0; i < s.length(); i++){
        if(s[i] == 'S') cnt++;
        else{
            if(cnt > 0) cnt--;
            else ans++;
        }
    }
    ans += cnt;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 720
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

dd = [(1,0),(0,1),(-1,0),(0,-1)]
h,w = inpl()
cy,cx = inpl()
gy,gx = inpl()
cy,cx,gy,gx = cy-1,cx-1,gy-1,gx-1
s = [input() for _ in range(h)]
res = [[INF] * w for _ in range(h)]
res[cy][cx] = 0
seen = set()
q = deque([(cy,cx)])
while q:
    oy,ox = q.popleft()
    if (oy,ox) in seen: continue
    seen.add((oy,ox))
    for dy,dx in dd:
        ny = oy+dy; nx = ox+dx
        if 0 <= ny < h and 0 <= nx < w and s[ny][nx] == '.':
            if res[ny][nx] > res[oy][ox]:
                res[ny][nx] = res[oy][ox]
                q.appendleft((ny,nx))
        for dy in range(-2,3):
            for dx in range(-2,3):
                ny = oy+dy; nx = ox+dx
                if 0 <= ny < h and 0 <= nx < w and s[ny][nx] == '.':
                    if res[ny][nx] > res[oy][ox] + 1:
                        res[ny][nx] = res[oy][ox] + 1
                        q.append((ny,nx))
ans = res[gy][gx]
print(-1 if ans  == INF else ans)

Measured memory_bytes: 197080
#include <cstdio>
#define N 999999
unsigned char p[((N+1)/2+7)/8];
int main() {
	int i,j,s,n=3;
	for(i=0;n<=(N/2);i++,n+=2)
		if(!(p[i/8]&(1<<(i%8))))
			for(j=i+n;j<((N+1)/2);j+=n)p[j/8]|=(1<<(j%8));
	while(scanf("%d",&n)!=EOF) {
		if(n<2){printf("0\n");continue;}
		if(n==2){printf("1\n");continue;}
		for(i=3,j=0,s=1;i<=n;i+=2,j++)
			s+=!(p[j/8]&(1<<(j%8)));
		printf("%d\n",s);
	}
}

Measured memory_bytes: 1096
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n;
int dp[101010];

int main(){
	cin >> n;
	
	for(int i = 0; i < 101010; i++) dp[i] = INF;
	priority_queue<P,vector<P>, greater<P>> q;
	q.push(P(1,1));
	while(!q.empty()){
		P p = q.top();
		q.pop();
		i64 sc = p.first, now = p.second;
		if(dp[now] <= sc) continue;
		dp[now] = sc;
		if(now == 0) break;
		int nx = (now+1)%n;
		q.push(P(sc+1, nx));
		nx = (now*10)%n;
		q.push(P(sc, nx));
	}
	
	cout << dp[0] << endl;
	
	return 0;
}

Measured memory_bytes: 2804
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
const int UF_MAX_N = 101020;

int uf_parant[UF_MAX_N];
int uf_rank[UF_MAX_N];
int uf_group_size[UF_MAX_N];

void init(int n)
{
    for (int i = 0; i < n; i++)
    {
        uf_parant[i] = i;
        uf_rank[i] = 0;
        uf_group_size[i] = 1;
    }
}

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

int get_size(int x)
{
    x = find(x);
    return uf_group_size[x];
}

void unite(int x, int y)
{
    x = find(x);
    y = find(y);
    if (x == y)
        return;

    if (uf_rank[x] < uf_rank[y])
    {
        uf_parant[x] = y;
        uf_group_size[y] += uf_group_size[x];
    }
    else
    {
        uf_parant[y] = x;
        uf_group_size[x] += uf_group_size[y];
        if (uf_rank[x] == uf_rank[y])
            uf_rank[x]++;
    }
}

bool same(int x, int y)
{
    return find(x) == find(y);
}

int N, M, K;
int A[101010], B[101010];
int C[101010], D[101010];
vector<int> Fr[101010];
vector<int> Bl[101010];
bool used[101010];
int cnt_f;

void reset_used()
{
    rep(i, 0, 101000)
    {
        used[i] = false;
    }
}

void cnt_friends(int n, int start)
{
    if (used[n])
    {
        return;
    }

    used[n] = true;
    if (n != start)
    {
        for (auto e : Bl[start])
        {
            if (e == n)
            {
                return;
            }
        }
        cnt_f++;
    }

    for (auto e : Fr[n])
    {
        cnt_friends(e, start);
    }
}

int main()
{
    init(101010);
    cin >> N >> M >> K;
    rep(i, 0, M)
    {
        cin >> A[i] >> B[i];
        Fr[A[i]].push_back(B[i]);
        Fr[B[i]].push_back(A[i]);
        unite(A[i], B[i]);
    }
    rep(i, 0, K)
    {
        cin >> C[i] >> D[i];
        Bl[C[i]].push_back(D[i]);
        Bl[D[i]].push_back(C[i]);
    }

    repe(i, 1, N)
    {
        int fr_size = get_size(i) - 1;
        for (auto e : Fr[i])
        {
            if (same(i, e))
            {
                fr_size--;
            }
        }
        for (auto e : Bl[i])
        {
            if (same(i, e))
            {
                fr_size--;
            }
        }
        cout << fr_size;
        if (i != N)
        {
            cout << " ";
        }
    }
}


Measured memory_bytes: 14584
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int a, b, w;
	int ans=0;
	cin >> w >> a >> b;
	if (abs(a-b)>=w) {
		ans = abs(a - b) - w;
	}
	else {
		ans = 0;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import itertools as it

def li():
    return [int(x) for x in input().split()]

N, K = li()
P = [0] + li()
C = [0] + li()

def get_cycle(start_i):
    cycle = []
    i = start_i
    while True:
        i = P[i]
        if i == start_i:
            break
        cycle.append(i)
    cycle.append(start_i)
    return cycle

max_scores = []
for start_i in range(1,N+1):
    cycle = get_cycle(start_i)
    # 累積和
    scores = list(it.accumulate([0]+[C[i] for i in cycle]))
    cycle_len = len(cycle)
    score_per_cycle = scores[cycle_len]
    # 1cycle以下の場合は全て調べればよし
    if K <= len(cycle):
        max_score = max(scores[1:K+1])
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがマイナスならサイクルを回らないのがハイスコア
    if score_per_cycle <= 0:
        max_score = max(scores[1:])
        max_scores.append(max_score)
        continue
    # 1サイクルごとのスコアがプラスなら限界までサイクルを回るのがハイスコア
    # ラスト1cycleのスコアを調べる
    scores_last_cycle = []
    for move in range(K-cycle_len+1, K+1):
        # 何周したか
        loop_cnt = move // cycle_len
        # あまり
        rest_move = move % cycle_len
        # スコア = 1周ごとのスコア * 何周したか + あまり
        score = loop_cnt * score_per_cycle + scores[rest_move]
        scores_last_cycle.append(score)

    max_scores.append(max(scores_last_cycle))

print(max(max_scores))



Measured memory_bytes: 158372
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main(void){
  int x, a, b;
  cin >> x >> a >> b;
  if(b - a <= 0){
    cout << "delicious";
  } else if(b - a <= x){
    cout << "safe";
  } else {
    cout << "dangerous";
  }
}
        

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

using namespace std;

typedef long long int LL;
typedef pair<int,int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector< VI > VVI;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr<<name<<" : "<<arg1<<endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
  const char* comma=strchr(names+1,',');
  cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define trace(...)
#endif
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
float  inf=std::numeric_limits<double>::infinity();
LL INF=std::numeric_limits<LL>::max();
int P[11],C[11];
int solve(int mask,int n,int G){
  int score=0,q=0,v;
  for(int i=0;i<n;i++) 
    if((mask>>i)&1) score+=((i+1)*P[i])+C[i],q+=P[i];
  while(score<G && n>0){
    n--;
    if((mask>>(n))&1) continue;
    n++;
    v=min((G-score)/n+(((G-score)%n)!=0),P[n-1]);
    score+=v*n,q+=v;
    if(v==P[n-1]) score+=C[n-1];
    n--;
  }
//  trace(score,q,mask);
  if(score>=G) return q;
  return -1;
}
int main(){
  int d,g; si(d);si(g);g/=100;
  for(int i=0;i<d;i++) 
    si(P[i]),si(C[i]),C[i]/=100;
  int ans=100*d,c;
  for(int i=0;i<(1<<d);i++)
    if((c=solve(i,d,g))>0) ans=min(ans,c);
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
using namespace std;
int main(void){
    int a,b;
    cin >> a;
    cin >> b;
    int d = a / b;
    int r = a % b;
    double f = double(a) / double(b);
    cout << d;
    cout << " ";
    cout << r;
    cout << " ";
    cout << fixed << setprecision(5) << f;
    cout << endl;
}


Measured memory_bytes: 3268
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author ZYCSwing
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = in.nextInt();
            int e = in.nextInt();
            int f = in.nextInt();

            int res = 0, sugar = 0;

            for (int va = 0; va <= f; va += 100 * a) {
                for (int vb = 0; va + vb <= f; vb += 100 * b) {
                    int water = va + vb;
                    int upper = water / 100 * e;
                    for (int vc = 0; water + vc <= f && vc <= upper; vc += c) {
                        for (int vd = 0; water + vc + vd <= f && vc + vd <= upper; vd += d) {
                            if (sugar == 0) {
                                sugar = vc + vd;
                                res = water + sugar;
                            } else {
                                if ((vc + vd) * res > sugar * (water + vc + vd)) {
                                    sugar = vc + vd;
                                    res = water + sugar;
                                }
                            }
                        }
                    }
                }
            }

            System.out.println(res + " " + sugar);
        }

    }
}



Measured memory_bytes: 21844