akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <cstring>
#include <iomanip>
#include <bits/stdc++.h>

using namespace std;

int main(){
	int n{};
	cin>>n;
	int arr[n]{};
	for(int i{}; i<n; i++)cin>>arr[i];
	int cost[n]{};
	cost[0]=0;
	cost[1]=abs(arr[1]-arr[0]);
	int i{2};
	while(i<n){
		cost[i]=min(abs(arr[i]-arr[i-1]) + cost[i-1], abs(arr[i]-arr[i-2]) + cost[i-2]);
//		cout<<cost[i]<<endl;
		i++;
	}
	cout<<cost[n-1]<<endl;
}

Measured memory_bytes: 4400
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <queue>
#include <utility>
#include <algorithm>
#include <string>
using namespace std;

int main() {
  long long N, M;
  cin >> N >> M;
  vector <pair <long long, long long> > ab(N);
  for (int i = 0; i < N; i++) {
	  int a, b;
	  cin >> a >> b;
	  ab[i] = make_pair(a, b);
	}
  sort(ab.begin(), ab.end());
  long long ans = 0;
  for (int i = 0; i < N; i++) {
	  if (M > ab[i].second) {
		  ans += ab[i].first * ab[i].second;
		  M   -= ab[i].second;
		  continue;
		}
	  ans += ab[i].first * M;
	  break;
	}
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
//g++ -std=c++17 -Wshadow -Wall -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -g PROGRAM -o OUTPUT -DLOCAL -lasan -lubsan
#include <bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define alli(a, n, k) (a + k), (a + n + k)
#define FP(i, a, b, k) for (__typeof(a) i = a; i < b; i += k)
#define FS(i, a, b, k) for (__typeof(a) i = a; i > b; i -= k)
#define IT(it, a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); ++it)
#define eps 1e-6
#define pi 3.141592653589793
using namespace std;
using namespace __gnu_pbds;

template <class T>
inline T gcd(T x, T y)
{
    if (!y)
        return x;
    return gcd(y, x % y);
}
typedef vector<int> VII;
typedef vector<ll> VLL;
typedef pair<int, int> PII;
typedef vector<pair<int, int>> VPII;
typedef vector<pair<int, PII>> VPPI;
const int MOD = 1e9 + 7;
const int INF = 1e9;


inline ll modulo(ll a, ll m)
{
    return (a % m + m) % m;
}

inline ll modInverse(ll a, ll m)
{
    assert(__gcd(a, m) == 1);
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;

        m = a % m, a = t;
        t = y;

        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

inline ll modPow(ll x, ll y, ll m)
{ //x^y % m
    if (y == 0)
        return 1LL;
    else if (y == 1)
        return x;
    else
    {
        ll ans = modPow(x, y / 2, m) % m;
        if (y & 1)
        {
            return (((ans * ans) % m) * x) % m;
        }
        else
        {
            return (ans * ans) % m;
        }
    }
}

vector<string> split(char d,string s)
{
    stringstream ss(s);
    string t;
    vector<string> words;
    while(getline(ss,t,d))
    {
        words.pb(t);
    }

    return words;
}

int main(int argc, char *argv[])
{
#ifdef LOCAL
    auto start = chrono::high_resolution_clock::now();
#endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    ll a;
    cin >> a;
    ll b = a * a;
    ll c = a * a * a;
    ll f = a + b + c;

    cout << f;

#ifdef LOCAL
    auto end = chrono::high_resolution_clock::now();
    double time_taken =
        chrono::duration_cast<chrono::nanoseconds>(end - start).count();

    time_taken *= 1e-9;

    cerr << "\nTime taken by program is : " << fixed
         << time_taken << setprecision(9);
    cerr << " sec" << endl;
#endif
    return 0;
}


Measured memory_bytes: 3644
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<queue>
using namespace std;
#define int long  long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
typedef pair<int, int>P;
const int INF = 1e8;

signed main() {
	int N;
	cin >> N;
	int num = sqrt(N);
	cout << num * num;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  string s;int i;char ans;long long k;
  cin >> s >> k;ans = '1';
  for(i=0;i<s.size();i++){
    if (s[i] != '1'){
      ans = s[i];
      break;
    } else if (i == k-1) break;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import scala.io.StdIn._
import scala.math._
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val a,b ,c,d = sc.nextInt
  if(abs(c-a)<=d || (abs(b-a)<=d && abs(c-b)<=d)){
    print("Yes")
  }
  else{
    print("No")
  }
}

Measured memory_bytes: 25496
/*raghav0307 - Raghav Gupta*/

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

#define ff first
#define ss second
#define pb push_back
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define int ll

typedef long long ll;
typedef pair<int, int> pii;
typedef long double ld;

const int inf = 1e16;

signed main(){
	fast_io();
	int n, m, p;
	cin >> n >> m >> p;
	vector<pair<pii, int> > edges;
	vector<int> adj[n];
	vector<int> adj2[n];
	for(int i = 0; i < m; i++){
		int a, b, c;
		cin >> a >> b >> c;
		a--;	b--;	c -= p;
		edges.pb({{a,b}, c});
		adj[a].pb(b);
		adj2[b].pb(a);
	}
	int dist[n];
	for(int i = 0; i < n; i++)	dist[i] = inf;
	dist[0] = 0;
	int good[n];
	for(int i = 0; i < n; i++)	good[i] = 0;
	stack<int> s;
	bool visited[n];
	memset(visited, false, sizeof(visited));
	s.push(0);	visited[0] = true;
	while(!s.empty()){
		auto x = s.top();	s.pop();
		good[x]++;
		for(auto y : adj[x]){
			if(visited[y])	continue;
			visited[y] = true;
			s.push(y);
		}
	}
	memset(visited, false, sizeof(visited));
	s.push(n-1);	visited[n-1] = true;
	while(!s.empty()){
		auto x = s.top();	s.pop();
		good[x]++;
		for(auto y : adj2[x]){
			if(visited[y])	continue;
			visited[y] = true;
			s.push(y);
		}
	}
	// int pred[n];
	for(int i = 0; i < n; i++){
		for(auto x : edges){
			if(good[x.ff.ff] != 2)	continue;
			if(good[x.ff.ss] != 2)	continue;
			dist[x.ff.ss] = min(dist[x.ff.ss], dist[x.ff.ff] - x.ss);
			// if(dist[x.ff.ss] < dist[x.ff.ff] + x.ss){
			// 	dist[x.ff.ss] = dist[x.ff.ff] + x.ss;
			// 	pred[x.ff.ss] = x.ff.ff;
			// }
		}
	}
	int ans = dist[n-1];
	for(int i = 0; i < n; i++){
		for(auto x : edges){
			if(good[x.ff.ff] != 2)	continue;
			if(good[x.ff.ss] != 2)	continue;
			dist[x.ff.ss] = min(dist[x.ff.ss], dist[x.ff.ff] - x.ss);
			// if(dist[x.ff.ss] < dist[x.ff.ff] + x.ss){
			// 	dist[x.ff.ss] = dist[x.ff.ff] + x.ss;
			// 	pred[x.ff.ss] = x.ff.ff;
			// }
		}
	}
	// cout << ans << " " << dist[n-1] << "\n";
	if(dist[n-1] != ans){
		cout << "-1";	return 0;
	}
	cout << max(0ll, -dist[n-1]);
	return 0;
}

Measured memory_bytes: 768
n,k=map(int,input().split())
a=sorted(list(map(int,input().split())))
p=10**9+7

def fact(n,p):
    a=[[] for _ in range(n+1)]
    a[0]=1
    for i in range(n):
        a[i+1]=(a[i]*(i+1))%p
    return a
f=fact(n,p)
g=[]
for i in range(n+1):
    g.append(pow(f[i],-1,p))
def com(n,r):
    return f[n]*g[r]*g[n-r]
ans=0
for i in range(n-k+1):
    ans=ans+(a[-i-1]-a[i])*com(n-i-1,k-1)
print(ans%p)

Measured memory_bytes: 20792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#include<string>
#include<functional>
#define int long long
using namespace std;

int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}
signed main() {
	int a;
	while(scanf("%lld", &a),a){
	vector<int>V;
	for (int b = 1; b*b <= a; b++) {
		if (a%b == 0) {
			V.push_back(b);
			if (b != a / b) {
				V.push_back(a / b);
			}
		}
	}
	sort(V.begin(), V.end());
	int sum = 0;
	for (int i = 0; i < V.size(); i++) {
		for (int j = i; j < V.size(); j++) {
			if (V[i] / gcd(V[i], V[j])*V[j] == a)sum++;
		}
	}
	printf("%lld\n", sum);}
}

Measured memory_bytes: 3236
def main():
    N = int(input())
    H = list(map(int, input().split()))

    for i in range(N - 1, 0, -1):
        if H[i] == H[i - 1]:
            continue
        elif H[i] == H[i - 1] - 1:
            H[i - 1] -= 1
        elif H[i] < H[i - 1] - 1:
            print("No")
            return

    for i in range(N - 1):
        if H[i] > H[i + 1]:
            print("No")
            return

    print("Yes")

    return


if __name__ == "__main__":
    main()


Measured memory_bytes: 14228
import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    [a, b, c] <- fmap read . words <$> getLine :: IO [Int]
    if or [ a + b == c
          , b + c == a
          , c + a == b
          ]
        then putStrLn "Yes"
        else putStrLn "No"

Measured memory_bytes: 508
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte(){
        if(ptr < buflen){
            return true;
        }else{
            ptr = 0;
            try{
                buflen = in.read(buffer);
            }catch(IOException e){
                e.printStackTrace();
            }
            if(buflen <=0){
                return false;
            }
        }
        return true;
    }

    private int readByte(){
        if(hasNextByte())return buffer[ptr++];
        else return -1;
    }

    private static boolean isPrintableChar(int c){
        return 33<=c && c<=126;
    }
    public boolean hasNext(){
        while(hasNextByte() && !isPrintableChar(buffer[ptr]))ptr++;
        return hasNextByte();
    }

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

    public long nextLong(){
        if(!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if(b == '-'){
            minus = true;
            b = readByte();
        }
        if(b < '0' || '9' < b){
            throw new NumberFormatException();
        }
        while(true){
            if('0' <= b && b<='9'){
                n*=10;
                n+=b-'0';
            }else if(b==-1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt(){
        long nl = nextLong();
        if(nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDoutble(){return Double.parseDouble(next());}
}


class Main {
    public static void main(String[] args) {
        FastScanner fs = new FastScanner();

        int n = fs.nextInt();
        int W = fs.nextInt();
        int[] w = new int[n];
        int[] v = new int[n];
        int V = 0;
        for(int i=0;i<n;i++){
            w[i] = fs.nextInt();
            v[i] = fs.nextInt();
            V+=v[i];
        }
        
        int[][] dp = new int[n+1][V+1];
        for(int i=1;i<=V;i++)dp[0][i] = W+1;
        for(int i=0;i<n;i++){
            for(int j=1;j<=V;j++){
                if(j-v[i]>=0){
                    dp[i+1][j] = Math.min(dp[i][j],dp[i][j-v[i]]+w[i]);
                }else{
                    dp[i+1][j] = dp[i][j];
                }
            }
        }
        int ans = 0;
        for(int i=0;i<=V;i++){
            if(dp[n][i]<=W){
                ans = i;
            }
        }
        System.out.println(ans);
      System.out.flush();
    }
}

Measured memory_bytes: 80080
#include <stdio.h>

int main(void)
{
	int a, b, n;
	
	while (scanf("%d %d %d", &a, &b, &n) != EOF){
		int sum = 0;
		
		while (b <= a){
			a -= b;
		}
		while (n-- > 0){
			a *= 10;
			sum += a / b;
			a %= b;
		}
		
		printf("%d\n", sum);
	}
	
	return 0;
}

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

#define ll long long
using namespace std;

int main() {
    int n;
    string s;
    cin >> n >> s;
    ll mod = 1e9 + 7;
    vector<ll> count(26);
    for (int i = 0; i < n; i++)count[s[i] - 'a']++;
    ll ret = 1;
    for (int i = 0; i < 26; i++) {
        ret *= count[i] + 1;
        ret %= mod;
    }
    cout << ret - 1 << endl;
    return 0;
}

Measured memory_bytes: 512
/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n;
cin>>n;
ll arr[n];
for(int i=0;i<n;i++){
	cin>>arr[i];
}
ll ans=0;
for(int i=n-2;i>=0;i--){
    ans=(ans%MOD+(arr[i]%MOD*arr[i+1]%MOD)%MOD)%MOD;
    arr[i]=(arr[i]+arr[i+1])%MOD;
}
cout<<ans%MOD<<endl;
return 0;
}

Measured memory_bytes: 5204
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
template<class t,class ...A> inline void read(t &x,A &...a){
	read(x);read(a...);
}
template<class t> inline void write(t x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}

const int mod=998244353,N=305;
int nm,m,n,f[N][N][N],ans,sum[N],a[N],sum1[N][N][N],sum2[N][N][N];
char s[N];

signed main(){
	scanf("%s",s+1);read(m);
	n=strlen(s+1);s[++n]='0';
	for(int i=1;i<=n;i++){
		if(s[i]=='0') nm++;
		else a[nm+1]++;
	}
	for(int i=1;i<=nm;i++) sum[i]=sum[i-1]+a[i];
	m=min(m,sum[nm]);
	f[0][0][0]=1;
	for(int i=0;i<=nm;i++) 	for(int j=sum[i];j<=sum[nm];j++){
		int lim=min(j,sum[nm]-sum[i-1]);
		if(i) for(int k=0;k<=m;k++){
			int tp1=min({a[i],lim,j}),tp2=min({lim,a[i]+k,j});
			f[i][j][k]=(sum1[i-1][j][k]-(j>=tp1+1?sum1[i-1][j-tp1-1][k]:0)+mod)%mod;
			if(tp2>=a[i]+1) f[i][j][k]=((f[i][j][k]+(j>=a[i]+1&&k?sum2[i-1][j-a[i]-1][k-1]:0))%mod-(j>=tp2+1&&k>=tp2+1-a[i]?sum2[i-1][j-tp2-1][k-tp2-1+a[i]]:0)+mod)%mod;
		} 
		for(int k=0;k<=m;k++){
			sum1[i][j][k]=j?(sum1[i][j-1][k]+f[i][j][k])%mod:f[i][j][k];
			sum2[i][j][k]=j&&k?(sum2[i][j-1][k-1]+f[i][j][k])%mod:f[i][j][k];	
		}
	}
	for(int i=0;i<=m;i++) ans=(ans+f[nm][sum[nm]][i])%mod;
	write(ans);
}

Measured memory_bytes: 84584
#include <stdio.h>
#include <string.h>

int main(void){
   int n,i,j,r=0,tmp;
   scanf("%d",&n);

   char str[n][11];
   char *s1,*s2;
   for(i=0;i<n;i++)
      scanf("%s",str[i]);

   for(i=1;i<n-0;i++){
      tmp=strlen(str[i-1]);
      if(str[i-1][tmp-1]!=str[i][0]){r=-1;break;}

      for(j=0;j<i;j++){
         if(strcmp(str[i],str[j])==0){r=-2;break;}
      }
      if(r==-2) break;
   }

   if(r==0) printf("Yes\n");
   else printf("No\n");
   return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <map>

using ll = long long;

using namespace std;

int main() {
    string s;
    cin >> s;
    map<string, string> m{{"ABC", "ARC"}, {"ARC", "ABC"}};
    cout << m[s] << '\n';
    return 0;
}

Measured memory_bytes: 3632
from operator import mul

D=int(input())
clist=list(map(int,input().split()))
slist=[]
for i in range (D):
    s=list(map(int,input().split()))
    slist.append(s)
tlist=[]
for i in range(D):
    t=int(input())
    tlist.append(t)

# print(clist,slist,tlist)
# D=5
# clist=[86, 90, 69, 51, 2, 96, 71, 47, 88, 34, 45, 46, 89, 34, 31, 38, 97, 84, 41, 80, 14, 4, 50, 83, 7, 82]

# slist=[[19771, 12979, 18912, 10432, 10544, 12928, 13403, 3047, 10527, 9740, 8100, 92, 2856, 14730, 1396, 15905, 6534, 4650, 11469, 3628, 8433, 2994, 10899, 16396, 18355, 11424], [6674, 17707, 13855, 16407, 12232, 2886, 11908, 1705, 5000, 1537, 10440, 10711, 4917, 10770, 17272, 15364, 19277, 18094, 3929, 3705, 7169, 6159, 18683, 15410, 9092, 4570], [6878, 4239, 19925, 1799, 375, 9563, 3445, 5658, 19857, 11401, 6997, 6498, 19933, 3848, 2426, 2146, 19745, 16880, 17773, 18359, 3921, 14172, 16730, 11157, 5439, 256], [8633, 15862, 15303, 10749, 18499, 7792, 10317, 5901, 9395, 11433, 3514, 3959, 5202, 19850, 19469, 9790, 5653, 784, 18500, 10552, 17975, 16615, 7852, 197, 8471, 7452], [19855, 17918, 7990, 10572, 4333, 438, 9140, 9104, 12622, 4985, 12319, 4028, 19922, 12132, 16259, 17476, 2976, 547, 19195, 19830, 16285, 4806, 4471, 9457, 2864, 2192]]
# tlist=[1, 17, 13, 14, 13]
noheldsday=[0]*26

benefit=0

for i in range (D):
    _noheldsday=list(map(lambda x: x+1,noheldsday))
    _noheldsday[tlist[i]-1]=0
    unpleasant=list(map(mul,clist,_noheldsday))
    
    v=slist[i][tlist[i]-1]-sum(unpleasant)
    benefit+=v
    noheldsday=_noheldsday
    
    print(benefit)


Measured memory_bytes: 9468
# https://atcoder.jp/contests/abc128/tasks/abc128_c
# なんかかすかに解いた記憶あるな？

# load data
N, M = list(map(int, input().split()))
S = []
for _ in range(M):
    S.append(list(map(int, input().split()))[1:])
P = list(map(int, input().split()))


def is_on(i, S, p):
    # bit表現 i のときSのスイッチの個数とpでonか返す
    cnt = 0
    for j in S:
        if (i >> (j - 1)) % 2:  # j番目のスイッチオン
            cnt += 1
    return cnt % 2 == p


ans = 0
# bit 全探索
for i in range(1 << N):  # N桁のbit全探索
    # 以下iの全パターンについて
    flg = True
    for s, p in zip(S, P):
        if not is_on(i, s, p):
            flg = False
            break
    ans += flg
print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) { 
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int dp[3000+10][3000+10];

int main() {
  int ans = 0;
  int N; cin>>N;
  int T; cin>>T;
  vector<pint> data(N);
  REP(i, N) cin>>data[i].first>>data[i].second;
  sort(data.begin(), data.end());

  for(int i = 0; i < N; i++) {
    int A = data[i].first;
    int B = data[i].second;
    for(int t = 0; t < T; t++) {
      chmax(dp[i+1][t], dp[i][t]);
      int nt = t + A;
      int nv = dp[i][t] + B;
      chmax(ans, nv);
      if(nt > T) continue;
      chmax(dp[i+1][nt], nv);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 35584
import java.util.*;

import static java.lang.System.*;

// https://ja.wikipedia.org/wiki/%E3%83%88%E3%83%9D%E3%83%AD%E3%82%B8%E3%82%AB%E3%83%AB%E3%82%BD%E3%83%BC%E3%83%88
// O(N+M)
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();

        Map<Integer, List<Integer>> nodeToNodes = new HashMap<Integer, List<Integer>>();  //ノードから伸びるノードリスト
        for (int i = 0; i < N - 1 + M; i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();

            List<Integer> toNodes = new ArrayList<Integer>();
            if (nodeToNodes.containsKey(a)) {
                toNodes = nodeToNodes.get(a);
            }
            toNodes.add(b);
            nodeToNodes.put(a, toNodes);
        }

        // トポロジカルソートの準備
        Map<Integer, List<Integer>> nodesParents = new HashMap<Integer, List<Integer>>();  //ノードの親
        for(Map.Entry<Integer, List<Integer>> nodeToNode: nodeToNodes.entrySet()){
            int parent = nodeToNode.getKey();
            List<Integer> kids = nodeToNode.getValue();

            for(int k: kids){
                List<Integer> toParents = new ArrayList<Integer>();
                if (nodesParents.containsKey(k)) {
                    toParents = nodesParents.get(k);
                }
                toParents.add(parent);
                nodesParents.put(k, toParents);
            }
        }

        //for(Map.Entry<Integer, List<Integer>> nodeParents: nodesParents.entrySet()){
        //    int node = nodeParents.getKey();
        //    List<Integer> parents = nodeParents.getValue();

        //    out.println(node+"=>");
        //    for(int n: parents){
        //        out.print(n+",");
        //    }
        //    out.println();
        //}

        // 親がいない
        Queue<Integer> noParents  = new ArrayDeque<Integer>();
        for(int n = 1; n < N; n++){
            if (!nodesParents.containsKey(n)){
                noParents.add(n);
            }
        }

        // トポロジカルソート
        int[] answer = new int[N+1];
        Arrays.fill(answer, -1);

        while(!noParents.isEmpty()){
            int p = noParents.poll();
            if(answer[p] == -1){ answer[p] = 0; }

            //out.println(p);

            // 親から順番に特定する
            if(nodeToNodes.containsKey(p)) {
                List<Integer> toNodes = nodeToNodes.get(p);
                for (int toNode : toNodes) {
                    List<Integer> parents = nodesParents.get(toNode);
                    parents.remove(parents.indexOf(p));

                    // もし親がいないならキューに追加
                    if (parents.size() == 0) {
                        answer[toNode] = p;
                        noParents.add(toNode);
                        nodesParents.remove(nodesParents.remove(toNode));
                    } else {
                        nodesParents.put(toNode, parents);
                    }
                }
            }
        }

        for(int n = 1; n <= N; n++) {
            out.println(answer[n]);
        }
    }
}

Measured memory_bytes: 109176
#include <stdio.h>
 
int main(void) {

	// ??°????????\???????????°????????????????????\???
	double num1, num2;
	char symbol[1];
 
	// ??\?????????????¨??????¨??°???????¨????????????????
	while(1) {
		
		scanf("%lf %s %lf", &num1, symbol, &num2);

		if(symbol[0] == '?')
			break;
		
		if(symbol[0] == '+') {
			
			printf("%.f\n", num1 + num2);
			
		} else if(symbol[0] == '-') {
			
			printf("%.f\n", num1 - num2);
			
		} else if(symbol[0] == '*') {
			
			printf("%.f\n", num1 * num2);
			
		} else if(symbol[0] == '/') {
			
			printf("%d\n", (int)(num1 / num2));
			
		}
	}
 	return 0;
}

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

vector<vector<int>> to(50);

// toが連結であるか否かを判定
bool is_connected(int n) {
	int num_conn = 1;
	vector<bool> visited(n, false);
	queue<int> q;
	q.push(0);
	visited[0] = true;

	while(!q.empty()) {
		int v = q.front();
		q.pop();
		for (auto u : to[v]) {
			if (!visited[u]) {
				visited[u] = true;
				q.push(u);
				num_conn++;
			}
		}
	}

	if (num_conn == n) return true;
	else return false;
}

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> a(m), b(m);
	rep(i,m) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
		to[a[i]].push_back(b[i]);
		to[b[i]].push_back(a[i]);
	}
	int ans = 0;
	rep(i,m) {
		bool connected = true;
		//橋iをグラフから取り除く
		to[a[i]].erase(remove(to[a[i]].begin(), to[a[i]].end(), b[i]), to[a[i]].end());
		to[b[i]].erase(remove(to[b[i]].begin(), to[b[i]].end(), a[i]), to[b[i]].end());

		// 橋iを取り除いたときに連結か否かを判定し、非連結だったらansを1加算
		if (!is_connected(n)) ans++;

		//橋iをグラフに加える
		to[a[i]].push_back(b[i]);
		to[b[i]].push_back(a[i]);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
import math
import copy
from heapq import heappush, heappop, heapify
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
# sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def judge(g):
    n = len(g)
    bi = [-1] * n
    bi[0] = 0
    for cn in range(n):
        for i, row in enumerate(g):
            for j, column in enumerate(row):
                if column == "1":
                    if bi[i] == -1 and bi[j] == -1:
                        pass
                    elif bi[i] == -1:
                        bi[i] = bi[j] ^ 1
                    elif bi[j] == -1:
                        bi[j] = bi[i] ^ 1
                    else:
                        if bi[i] == bi[j]:
                            print(-1)
                            sys.exit()




def solve():
    n = getN()
    g = []
    for i in range(n):
        g.append([c for c in getS()])

    judge(g)

    costs = [[INF for i in range(n)] for j in range(n)]
    for i in range(n):
        costs[i][i] = 0

    for i, row in enumerate(g):
        for j, column in enumerate(row):
            if column == "1":
                costs[i][j] = 1

    V = n
    for k in range(V):
        for i in range(V):
            for j in range(V):
                if costs[i][k] != INF and costs[k][j] != INF:
                    costs[i][j] = min(costs[i][j], costs[i][k] + costs[k][j])

    ans = max([max(x) for x in costs])
    print(ans + 1)

def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 77260
#include <stdio.h>

int main() {

  int a,i,b,n;
  int max = -1;
  int sum[5] = {0};

  while(1) {

    for(i=0;i<5;i++) sum[i] = 0;

    max = -1;

   

    scanf("%d %d",&a,&b);

    if(a == 0 && b == 0) break;

    sum[0] = a + b;


    for(i=1;i<5;i++) {

      scanf("%d %d",&a ,&b);

      if(a == 0 && b == 0) break;

      sum[i] = a + b;

      if(sum[i] > max) {
	max = sum[i];
	n = i;
      }

    }

    if(sum[0] > max) {
      max = sum[0];
      n = 0;
    }

    
    if(n == 0) printf("A");
    else if(n == 1) printf("B");
    else if(n == 2) printf("C");
    else if(n == 3) printf("D");
    else if(n == 4) printf("E");

    printf(" %d\n", max);

  }

  return 0;

}



 

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define int long long int
 
#define pi pair<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define vp vector<pi>
#define vvp vector<vp>

int t=1,T;
int mod = 1e9+7;
const int INF = 1000000000;
 
//---------------------------------------------------------------------------
 
void print(vector<int> a){
    for(int x : a){
        cout << x <<' ';
    }
    cout << endl;
    return;
}
 
void print2d(vector<vector<int>> &v){
    for(int i=0;i<v.size();i++){
        for(int x:v[i]){
            cout << x <<' ';
        }
        cout <<endl;
    }
}
 
int power(int a, int b){
    if(b==0) return 1;
    int x = power(a, b/2);
    x = (x*x);
    return b&1 ? (x*a) : x;
}
 
void swap(int &n, int &m){
    n=n^m;
    m=n^m;
    n=n^m;
}
 
//---------------------------------------------------------------------------
void solve(){
    int n;cin >> n;
}
 
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n;cin >> n;
    cout << (n+1)%2 << "\n";
 
    return 0;
}
 
/*
set
map
erase
clear
stack
insert
count
queue
front
vector
begin
end
string
push_back
push
pop
pop_back
first
second
rbegin
rend
make_pair
*/

Measured memory_bytes: 3652
#include<cmath>
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
#define ALL(a) a.begin(), a.end()
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.sise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<int, int> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main(){
    int n;
    cin >> n;
    mint all=1;
    mint not0=1;
    mint not9=1;
    mint not09=1;
    rep(i,n){
        all*=10;
        not0*=9;
        not9*=9;
        not09*=8;
    }
    mint ans=all-not0-not9+not09;
    cout<<ans.x<<endl;
    return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
#define MAX 1e9+7
#define MIN -1e9-7
#define int long long
#define endl "\n"
#define max(x,y) (x>y)?x:y
#define min(x,y) (x<y)?x:y
#define s(n) scanf("%d",&n)
#define mem memset(a, 0, sizeof(a))
#define minimum(a)	*min_element(a.begin(), a.end())
#define maximum(a)	*max_element(a.begin(), a.end())
typedef vector<int> vi;
typedef vector<string> vs;


int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

int x;
cin>>x;
if(x>=400 and x<=599)
{
	cout<<8<<endl;
}
else if(x>=600 and x<=799)
{
	cout<<7<<endl;
}
else if(x>=800 and x<=999)
{
	cout<<6<<endl;
}
else if(x>=1000 and x<=1199)
{
	cout<<5<<endl;
}
else if(x>=1200 and x<=1399)
{
	cout<<4<<endl;
}
else if(x>=1400 and x<=1599)
{
	cout<<3<<endl;
}
else if(x>=1600 and x<=1799)
{
	cout<<2<<endl;
}
else 
{
	cout<<1<<endl;
}


return 0;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) return 0;
    
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++) {
      cin >> a.at(i);
      sum += a.at(i);
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (a.at(i) * n <= sum) ans++;
    }
    
    cout << ans << '\n';
  }
}


Measured memory_bytes: 3124
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll labs(ll x){
	if(x<0LL)return -x;
	return x;
}
ll x,y;

int main(void){
	scanf("%lld%lld",&x,&y);
	ll res;
	if(x==y){
		printf("0\n");
		return 0;
	}
	if(x>=0LL && x<y){
		res=y-x;
	}else if(x<y && x<0 && y<=0){
		res=y-x;
	}else if(x<y && x<0 && y>0){
		res=labs(labs(y)-labs(x))+1;
	}else if(y<x && y>0){
		res=2+labs(x-y);
	}else if(y<x && y==0){
		res=1+labs(x-y);
	}else if(y<x && y<0){
		if(x<0)res=labs(labs(x)-labs(y))+2;
		else res=labs(labs(x)-labs(y))+1;
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 256
/*complex関数...複素数
  conj関数...共役複素数
  imag関数...虚部を所得する＊虚部a+biとあらわされるとき、b（）虚数を差す
  base関数...メンバ変数をとして保持している、元のイテレータを所得する
  *イテレータ...プログラミング言語において配列やそれに類似する集合的データ構造の各要素に対する繰り返しの処理の抽象化
  オブジェクト化で現れる
*/
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;

//
int V,R;
vector<P> A;
vector< vector<double> > G;
double ans=0;

double calc_distance(int I,int J){
	P from=A[I];
	P to=A[J];
	P base=to-from;
	
	int left=0,right=0;
	for(int i=0;i<V;i++){
		if(i==I||i==J)continue;
		P p=conj(base)*(A[i]-from);
		if(p.imag()<0)left=1;
		if(p.imag()>0)right=1;
	}
	double res=abs(base);
	if(left==0||right==0){
		ans+=res;
		res=0;
	}
	return res;
}

int main(){
	//V...集落の数||R...道の数
	cin>>V>>R;
	A.resize(V);
	for(int i=0;i<V;i++){
		double x,y;
		//それぞれの集落のx座標y座標
		cin>>x>>y;
		//
		A[i]=P(x,y);
	}
	
	G.resize(V);
	for(int i=0;i<V;i++){
		G[i].resize(V,0.0);
	}
	
	for(int i=0;i<V;i++){
		for(int j=0;j<i;j++){
			double value=calc_distance(i,j);
			if(value==0.0)G[i][j]=G[j][i]=0;
			else G[i][j]=G[j][i]=1e9;
		}
	}
	
	for(int i=0;i<R;i++){
		int I,J;
		cin>>I>>J;
		I--;J--;
		if(G[I][J]==0)continue;
		double value=calc_distance(I,J);
		G[I][J]=value;
		G[J][I]=value;
	}
	
	vector<double> d(V,99999999.0);
	vector<int> visited(V,0);
	d[0]=0;
	
	while(1){
		int pos=-1;
		for(int i=0;i<V;i++)
			if(visited[i]==0)
				if(pos==-1||d[i]<d[pos])
					pos=i;
		if(pos==-1)break;
		visited[pos]=1;
		ans+=d[pos];
		for(int to=0;to<V;to++){
			d[to]=min(d[to],G[pos][to]);
		}
	}
	printf("%.10f\n",ans);
	return 0;
}


Measured memory_bytes: 3352
// {{{
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;
// }}}

using ll = long long;

#define sq(x) ((x)*(x))

int D, E;

int main() {
    while (true) {
        cin >> D >> E;
        if (D == 0 && E == 0) break;

        double ans = 1010101010;
        for (int d = 0; d <= D; ++d) {
            ans = min(ans, fabs(sqrt(sq(d) + sq(D-d)) - E));
        }

        cout << fixed << setprecision(10) << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3232
import itertools
n = int(input())
s = input()
ans = 0
wl = []
el = []
for ss in s:
    if ss == 'W':
        wl.append(1)
        el.append(0)
    else:
        wl.append(0)
        el.append(1)
el.reverse()
wll = list(itertools.accumulate(wl))
ell = list(itertools.accumulate(el))
ell.reverse()

INF = float("inf")
ans = INF

for i in range(0, n):
    ans = min(ans, abs(wll[i-1]+ell[i-1]))

print(ans-1)


Measured memory_bytes: 97688
def main():
    from collections import defaultdict
    d = defaultdict(list)
    n = int(input())
    for i in range(n):
        a = int(input())
        for _ in range(a):
            x, y = [int(x) for x in input().split()]
            d[i].append((x-1, y))

    ans = 0
    from itertools import product
    for ts in product([0, 1], repeat=n):
        if all([ts[x] == y for i in range(n) for x, y in d[i] if ts[i]==1]):
            ans = max(ans, sum(ts))
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define REP(i,n) for (ll i = 0, i##_len = (n); i < i##_len; i++)
#define ALL_OF(v) (v).begin(), (v).end()

int main() {

    ll n, m; cin >> n >> m;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<ll> as(n+1, 0);
    REP(i, n) as[i+1] += as[i] + a[i];

    // dp[i][j] := 最後の仕切りが位置iにあり区画が全部でj個のときの水の高さの総和
    vector<vector<ld>> dp(n+1, vector<ld>(m+1, -1e100L));

    dp[0][0] = 0.L;

    REP(i, n) {
        REP(j, i+1) {
            REP(k, m) {
                ld x = dp[j][k] + (ld)(as[i+1] - as[j]) / (i+1 - j);
                if (dp[i+1][k+1] < x) {
                    dp[i+1][k+1] = x;
                }
            }
        }
    }

    // REP(i, n+1) REP(j, m+1) cerr << dp[i][j] << " \n"[j==m];

    cout << fixed << setprecision(30) << *max_element(ALL_OF(dp.back())) << endl;

}


Measured memory_bytes: 6844
/**
SXR0aXAkI0JwbXptI3FhI3Z3I293bCNqY2IjUG0jMCNicG0jVHFkcXZvLyNCcG0jQW10bjBhY2phcWFicXZvLyNNYm16dml0MSNWdyNhdGN1am16I2tpdiNhbXF9bSNQcXUjVnd6I0F0bW14MSNQcWEjaXptI2l0dCNicHF2b2EjUXYjYnBtI3BtaWRtdmEjaXZsI3d2I21pemJwMSNFcHcjcWEjYnBtem0ja2l2I3F2Ym16a21sbSNRdiNQcWEjeHptYW12a20jbXtrbXhiI0lhI3BtI3htenVxYmJtYnBHI1BtI3N2d2VtYnAjRXBpYiMraXh4bWl6bWJwI2J3I1BxYSNrem1pYmN6bWEjSWEsI0ptbnd6bSN3eiNJbmJteiN3eiNKbXBxdmwjYnBtdTEjVnd6I2FwaXR0I2JwbXwja3d1eGlhYSNJY29wYiN3biNwcWEjc3Z3ZXRtbG9tI017a214YiNpYSNQbSNlcXR0bWJwMSNQcWEjYnB6d3ZtI2x3YnAjbXtibXZsI1dkbXojYnBtI3BtaWRtdmEjSXZsI3d2I21pemJwLyNpdmwjUG0jbm1tdG1icCNWdyNuaWJxb2NtI3F2I29jaXpscXZvI0l2bCN4em1hbXpkcXZvI2JwbXUvI053eiNQbSNxYSNicG0jVXdhYiNQcW9wMSNCcG0jQWN4em11bSMrcXYjb3R3enwsMQ==
*/
#include <bits/stdc++.h>

#define F first
#define S second
#define pb push_back
const long long MOD = 1e9 + 7;
const long long MAXN = 1e6 + 1;
using namespace std;

typedef long long ll;

long long readInt() {
  bool minus1 = false;
  long long result = 0;
  char ch;
  ch = getchar();
  while (true) {
    if (ch == '-') break;
    if (ch >= '0' && ch <= '9') break;
    ch = getchar();
  }
  if (ch == '-')
    minus1 = true;
  else
    result = ch - '0';
  while (true) {
    ch = getchar();
    if (ch < '0' || ch > '9') break;
    result = result * 10 + (ch - '0');
  }
  if (minus1)
    return -result;
  else
    return result;
}

multiset<int> s1;
multiset<int> s2;

int min_R_1;
int min_R_2;

int ans;
pair<int, int> a[MAXN];
int n;

int alp_salganda_newe(pair<int,int> x) {
	s1.erase(s1.find(x.S));
  	int res = 0;
	res = max(x.S - x.F + 1, 0) +
                      max(min((s1.size() > 0 ? (int)*s1.begin() : (int)MOD), min_R_2) - a[n].F + 1, 0);
	s1.insert(x.S);
	return res;
}


 main() {
  n = readInt();
  for (int i = 1; i <= n; i++) {
    a[i] = {readInt(), readInt()};
  }
  for (int i = 1; i <= n; i++) {
    s2.insert(a[i].S);
  }

  sort(a + 1, a + 1 + n);
  for (int i = 1; i < n; i++) {
    /// min(R) - max(L) + 1
    s2.erase(s2.find(a[i].S));
    s1.insert(a[i].S);
    
    min_R_1 = *s1.begin();
    min_R_2 = *s2.begin();
    
    ans = max(ans, max(min_R_1 - a[i].F + 1, 0) +
                       max(min_R_2 - a[n].F + 1, 0));
  	
  	ans = max(ans, alp_salganda_newe(a[i]));
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 5760
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var n int
	fmt.Scan(&n)
	sum := 0
	x := strconv.Itoa(n)
	for _, i := range x {
		y, _ := strconv.Atoi(string(i))
		sum += y
	}
	if n % sum == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

Measured memory_bytes: 512
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val n, m = sc.nextInt()
    val isAccepted = new Array[Boolean](n)
    isAccepted.map(_ -> false)
    val wa = new Array[Int](n)
    wa.map(_ -> 0)

    for (_ <- 0 until m) {
      val p = sc.nextInt()
      val s = sc.next()

      if (!isAccepted(p - 1)) {
        s match {
          case "AC" => isAccepted(p - 1) = true
          case "WA" => wa(p - 1) += 1
        }
      }
    }

    val ac = isAccepted.count(_ == true)
    val sumOfWa = isAccepted.zip(wa).foldLeft(0) {
      case (acc, (b, i)) => if (b) acc + i else acc
    }

    println(s"$ac $sumOfWa")

  }
  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


Measured memory_bytes: 67076
A, B, K = map(int, input().split())

if A > K:
    after_A = A - K
    after_K = 0
else:
    after_A = 0
    after_K = K - A

if B > after_K:
    after_B = B - after_K
    final_K = 0
else:
    after_B = 0
    final_K = after_K - B

print(after_A, after_B)

Measured memory_bytes: 9160
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
 
fn main(){

    let a:i32 = read();    
    let b:i32 = read();  
    
    if (b-a) % 2 == 0{
        println!("{}",a + ((b-a) / 2));
    }else{
        println!("IMPOSSIBLE");
    }
    
    
}

Measured memory_bytes: 4352
N = int(input())
*P, = map(float, input().split())
dp = [[0]*(N+1) for _ in range(N)]
dp[0][0] = 1 - P[0]; dp[0][1] = P[0]
for i in range(1, N):
    for j in range(i+2):
        dp[i][j] = dp[i-1][j] * (1 - P[i]) + dp[i-1][j-1] * P[i]
print(sum(dp[N-1][N//2 + 1:]))

Measured memory_bytes: 262280
a = int(input())
b = int(input())
c = int(input())
x = int(input())

i = 0
j = 0
k = 0
res = 0
cnt = 0

for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            res = 500*i + 100*j + 50*k
            if(res == x):
                cnt = cnt + 1

print(cnt)

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

void solve(void){
  ll n; cin >> n;
  vector<ll> h(n, 0);
  rep(n, i) cin >> h[i];

  vector<ll> dp(n+1, INF);
  dp[0] = 0;
  for(ll i = 1; i <= n; ++i) {
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
    dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
  }

  cout << dp[n-1] << endl;
} 

int main(void) {
  solve();
  return 0;
}


Measured memory_bytes: 4844
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <iostream>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> A(N);
    int min_flag = 0, min_abs = INT_MAX;
    ll sum = 0;
    REP(i, N) {
        cin >> A[i];
        sum += abs(A[i]);
        min_abs = min(min_abs, abs(A[i]));
        if (A[i] < 0)
            min_flag ^= 1;
    }
    if (min_flag) {
        cout << (sum - min_abs * 2) << "\n";
    } else
        cout << sum << "\n";
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN=100010;
int a,b,c,d,e,k;
inline int read(){
    int f=1,x=0;
    char ch=getchar();
    while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
    return f*x;
}
int main(){
    cin>>a>>b>>c>>d>>e>>k;
    if(e-a>k) cout<<":(";
    else cout<<"Yay!";
    return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    Map<Integer,Integer> a = new HashMap<Integer,Integer>();
    for(int i = 0; i < n; i++){
      int in = sc.nextInt();
      if(a.containsKey(in)){
        int temp = a.get(in) + 1;
        a.put(in,temp);
      }
      else{
        a.put(in,1);
      }
      }
      if(a.size() > k){
        List<Integer> count = new ArrayList<Integer>();
        for(int i:a.keySet()){
          int temp = a.get(i);
          count.add(temp);
        }
        Collections.sort(count);
        int ans = 0;
        int j = 0;
        for(int i = a.size(); i > k; i--){
          ans += count.get(j);
          j++;
        }
        System.out.println(ans);
      }
      else{
        System.out.println(0);
      }
    }
  }

Measured memory_bytes: 102168
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <cmath>
using namespace std;
int main() {
	char ar[10];
	cin>>ar;
	int a,b,c,d;
	a=ar[0]-'0';
	b=ar[1]-'0';
	c=ar[2]-'0';
	d=ar[3]-'0';
	for(int i=43; i<=45; i+=2) {
		for(int j=43; j<=45; j+=2) {
			for(int k=43; k<=45; k+=2) {
				int sum=a;
				if(i==43) {
					sum+=b;
				} else {
					sum-=b;
				}
				if(j==43) {
					sum+=c;
				} else {
					sum-=c;
				}
				if(k==43) {
					sum+=d;
				} else {
					sum-=d;
				}
				if(sum==7) {
					printf("%d%c%d%c%d%c%d=7",a,i,b,j,c,k,d);
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 256
from collections import defaultdict


def main():
    N = int(input())
    A = list(map(int, input().split()))
    cnt = defaultdict(int)
    total = 0
    for a in A:
        cnt[a] += 1
        total += a
    Q = int(input())
    for _ in range(Q):
        b, c = map(int, input().split())
        cnt[c] += cnt[b]
        total += (c-b) * cnt[b]
        cnt[b] = 0
        print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 94428
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;
static const int MAX = 200000;

int main()
{
	int x, t;
	cin >> x >> t;

	x -= t;
	if (x > 0)cout << x << endl;
	else cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    string S;
    cin >> S;
    
    ll K;
    cin >> K;

    bool can = true;
    for(int i = 0; i < S.size()-1; i++) {
        if (S[i] != S[i+1]) can = false;
    }

    if (S.size() == 1) {
        cout << K/2 << endl;
        return 0;
    }
    
    ll ans = 0;
    ll cnt = 1;
    for(int i = 0; i < S.size()-1; i++) {
        if (S[i] == S[i+1]) {
            cnt++;
        }
        if (S[i] != S[i+1] || i == S.size()-2) {
            ans += cnt / 2;
            cnt = 1;
        }
    }

    ll tmp = ans;

    ans *= K;

    // cout << ans << endl;
    

    ll tmp2 = 0;
    if (K >= 2) {
        if (S[0] == S[S.size()-1]) {
            S = S + S;
            for(int i = 0; i < S.size()-1; i++) {
                if (S[i] == S[i+1]) {
                    cnt++;
                }
                if (S[i] != S[i+1] || i == S.size()-2) {
                    tmp2 += cnt / 2;
                    cnt = 1;
                }
            }
            if (can)
                ans += ((tmp2+1) / 2 - tmp) * (K/2);
            else
                ans += ((tmp2+1) / 2 - tmp) * (K-1);
        }
    }

    // cout << S << endl;

    // cout << tmp << " " << tmp2 << endl;

    cout << ans << endl; 

    return 0;
}

Measured memory_bytes: 384