akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
	string S;
	cin >> S;
	int L = S.size();
	vector<int> ans(L, 0);
	vector<int> D_L(L, 0), D_R(L, 0);
	
	int d = 0;
	rep(i ,L) {
		d++;
		if(S[i] == 'R') d = 0;
		if(S[i] == 'L') D_R[i] = d; 
	}
	d = 0;
	for(int i = L-1; i >= 0; i--){
		d++;
		if(S[i] == 'L') d = 0;
		if(S[i] == 'R') D_L[i] = d;
	}

	for(int i = 0; i < L; i++){
		if(S[i] == 'R') {
			if(D_L[i] % 2) ans[i + D_L[i] - 1]++;
			else ans[i + D_L[i]]++;
		} else if(S[i] == 'L') {
			if(D_R[i] % 2) ans[i - D_R[i] + 1]++;
			else ans[i - D_R[i]]++;
		}
	}

	rep(i ,L){
		cout << ans[i] << " \n"[i == L-1];
	}
}


Measured memory_bytes: 1792
using System;

namespace ABC168A
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = Console.ReadLine();
            var ans = "";

            switch (N[^1])
            {
                case '2':
                case '4':
                case '5':
                case '7':
                case '9':
                    ans = "hon";
                    break;
                case '0':
                case '1':
                case '6':
                case '8':
                    ans = "pon";
                    break;
                case '3':
                        ans = "bon";
                    break;
                default:
                    break;
            }

            Console.WriteLine(ans);
        }
    }
}


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

int main(){
  int n;
  cin >> n;
  long long l1=2,l2=1,l3;
  
  if(n==1){
    cout << 1 << endl;
  }else{
    for(int i=0; i<n-1; i++){
      l3 = l1 + l2;
      l1 = l2;
      l2 = l3;
    }
    cout << l3 << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  cin >> N >> M;
  vector<int>vec(N, 0);
  for (int i=0; i < 2*M; i++){
  int a;
  cin >> a;  
    for (int j=0; j < N; j++){
  if (a == j+1 ){
  vec.at(j) = vec.at(j) + 1;
  }
  }
  }
  for (int i=0; i < N; i++){
    cout << vec.at(i) << endl;
  }

}
 

Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    ll ans = 0;
    ll cnt = n / (a + b);
    ans += cnt * a;
    n -= cnt * (a + b);
    ans += min(n, a);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
n, m = map(int, raw_input().split())
ma = []
num = 0
for i in range(n):
    x = []
    x = map(int, raw_input().split())
    ma.append(x[1:])
ma = sum(ma,[])
for mb in list(set(ma)):
    if ma.count(mb) == n:
        num+=1
print(num)

Measured memory_bytes: 2692
//Bismillahirrahmanirrahim
//█▀█─█──█──█▀█─█─█
//█▄█─█──█──█▄█─█▄█
//█─█─█▄─█▄─█─█─█─█

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx2")

#include <bits/stdc++.h>

using namespace std;

typedef long long lo;
typedef pair< lo,lo > PII;

#define fi first
#define se second
#define mp make_pair
#define int long long
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=1;i<=n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)

const lo inf = 1000000000000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 100002;
const lo mod = 1000000007;

int n,m,b[li],a[li],k,flag,t,dp[102][li];
int cev;
string s;
vector<int> v;

inline int add(int x,int y){
	if(x+y>=mod)return x+y-mod;
	return x+y;
}

main(void){
	//~ memset(dp,-1,sizeof(dp));
	scanf("%lld %lld",&n,&k);
	FOR{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++){
		cev=0;
		for(int j=1;j<=a[i];j++){
			cev=add(cev,dp[i-1][j]);
			dp[i][j]=add(cev,1);
		}
		for(int j=a[i]+1;j<=k;j++){
			cev=add(cev,mod-dp[i-1][j-a[i]-1]);
			cev=add(cev,dp[i-1][j]);
			//~ cout<<cev<<endl;
			dp[i][j]=cev;
		}
		
	}
	dp[n][0]=1;
	printf("%lld\n",dp[n][k]);
	return 0;
}



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

using namespace std;

int main()
{
	string s1, s2, s3;
	cin >> s1 >> s2 >> s3;

	cout << (char)toupper(s1[0]) << (char)toupper(s2[0]) << (char)toupper(s3[0]) << endl;
}


Measured memory_bytes: 3616
#include<iostream>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double PI = 3.14159265358979;
const double E = 2.718281828459045;
const double root2 = sqrt(2);
typedef pair<int, int> P;
typedef unsigned int ui;
int main(){
	string s;
	cin >> s;
	int n = s.length();
	int l = 0; int r = n - 1;
	int count = 0; bool f = true;
	while (r > l) {
		if (s[l] == 'x'&&s[r] == 'x') {
			l++; r--;
		}
		else if (s[l] != 'x'&&s[r] == 'x') {
			r--; count++;
		}
		else if (s[l] == 'x'&&s[r] != 'x') {
			l++; count++;
		}
		else {
			if (s[l] != s[r]) {
				f = false; break;
			}
			l++; r--;
		}
	}
	if (f)cout << count << endl;
	else cout << -1 << endl;
	char nyaa;
	cin >> nyaa;
	return 0;
}

Measured memory_bytes: 512
'''
in
-----
6 15
6 5
5 6
6 4
6 6
3 5
7 2
'''
'''
out
-----
17
'''
N, M = map(int, input().split())
dp = [[0]*(M+1) for _ in range(N+1)]

for i in range(1, N+1):
    W,V = map(int, input().split())
    for j in range(0,M+1):
        dp[i][j] = max(dp[i][j], dp[i-1][j])
        if j - W >= 0:
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-W] + V)

'''
for i in range(0,N+1):
    for j in range(1, M+1):
        print(dp[i][j])
    print('')
'''

print(max(dp[-1]))


Measured memory_bytes: 152220
#include<bits/stdc++.h>
using namespace std;
int main()
{
 int n,c=0;
 cin>>n;
 string s;
 cin>>s;
 if(n%2==0)
 {
  for(int i=0;i<(n/2);i++)
  {
   if(s[i]==s[i+(n/2)])
     c++;
   else
     break;
  }
 }
  if((2*c)==n)
    cout<<"Yes";
  else 
    cout<<"No";
 return 0;
}


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

int main()
{
	int N;
	cin >> N;
	int Ncopy = N;
	int sum = 0;
	while (N > 0) {
		sum += N % 10;
		N /= 10;
	}
	if (Ncopy % sum == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

// https://atcoder.jp/contests/abc160/tasks/abc1160_b
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		sc.close();


		int[] array = {1000,100,50,10,5,0};
		int[] money = {500,100,50,10,5,1};
		int ans = 0;

		for(int i=0;i<money.length;i++) {
			int tmp = s/money[i];
			s = s - tmp*money[i];
			ans = ans + tmp*array[i];
		}

		System.out.println(ans);


	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
int main(){
    int N;
    std::string s;
    std::cin >> N >> s;
    long long ans = 0;
    for(int i = 0; i <= 9; i++){
        for(int j = 0; j <= 9; j++){
            for(int k = 0; k <= 9; k++){
                int u = 0;
                for(int l = 0; l < N; l++){
                    if(u == 0 && s[l] == '0' + i){
                        u++;
                        continue;
                    } 
                    if(u == 1 && s[l] == '0' + j){
                        u++;
                        continue;
                    }
                    if(u == 2 && s[l] == '0' + k){
                        u++;
                        break;
                    }
                }
                if(u == 3) ans++;
            }
        }
    }
    std::cout << ans << std::endl;
}

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

const int MAXN=500005;
const long MOD=(long)(1e9+7);
vector<int> adj[MAXN];
vector<pair<int,int>> G[MAXN];

Int N,M,K;
Int B,C,H,W;
Int X,Y,Z;
vector<Int> A;

Int ceilS(Int x,Int y){
    return (x+y-1)/y;
}
using D=long double;

Int perform(Int x){
    return (x*(x+1))/2LL;
}

int main()
{
        cin>>N>>X;
        A.resize(N);
        for(auto &x:A) cin>>x;
        Int sum=accumulate(A.begin(),A.end(),0LL);
        
        Int least=1e13;
        for(auto x:A) least=min(least,x);
        
        X-=sum;
        if(X<0) X=0;
        Int rem=X/least;
        
        cout<<N+rem<<"\n";
}

Measured memory_bytes: 26976
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int n, l, t, g;
int x[100010], w[100010];
pii goal[100010];
int idx[100010];

int calc(int dist) {
    if(2 * t < dist) return 0;
    int rem = 2 * t - dist;
    return rem / l + 1;
}

signed main() {
    cin >> n >> l >> t;
    rep(i,0,n) {
        cin >> x[i] >> w[i];
        int temp;
        if(w[i] == 1) {
            temp = (x[i] + t) % l;
            goal[i] = pii(temp, i);
        }
        if(w[i] == 2) {
            temp = (x[i] - (t%l) + l) % l;
            goal[i] = pii(temp, -i);
        }
    }
    sort(goal, goal+n);
    int cnt = 0;
    rep(i,1,n) {
        if(w[0] == w[i]) continue;
        else if(w[0] == 1) cnt += calc(x[i] - x[0]);
        else if(w[0] == 2) cnt -= calc(x[0] + l - x[i]);
    }
    if(cnt > 0) cnt %= n;
    int p = 0;
    while(goal[p].second != 0) p++;
    rep(i,0,n) {
        int d = (p - cnt + n) % n + i;
        cout << goal[d%n].first << endl;
    }
    return 0;
}

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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a==b && b == c) cout << "1" << endl;
  else if(a!=b && b != c && c != a) cout << "3" << endl;
  else cout << "2" << endl;

}

Measured memory_bytes: 256
def main():
    n = int(input())
    t, a = map(int, input().split())
    h = [int(i) for i in input().split()]
    ans = solve(n, t, a, h)
    print(ans)


def solve(n, t, a, h):
    ans = 0
    abstemp = abs(a - (t - h[0] * 0.006))
    for i in range(1, n):
        temptmp = abs(a - (t - h[i] * 0.006))
        if temptmp < abstemp:
            ans = i
            abstemp = temptmp
    return ans + 1


if __name__ == '__main__':
    main()

Measured memory_bytes: 3188
#include "bits/stdc++.h"
// #include "boost/math/common_factor.hpp" // gcd, lcm
using namespace std;

// #define int long long

signed main(void) {
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  int n;
  int s;
  array<int, 1000000> a;
  cin >> s;

  for (auto it = a.begin(); it < a.end(); ++it) {
    ++num;
    if (it == a.begin())
      *it = s;
    else
      if (*(it - 1) % 2 == 0)
        *it = *(it - 1) / 2;
      else
        *it = 3 * *(it - 1) + 1;
    
    if (find(a.begin(), it, *it) != it)
      break;
  }

  cout << num << endl;
  return 0;
}


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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
struct BIT {
	int n;
	std::vector<int> data;
	BIT (int n) : n(n) {
		data.resize(n + 1);
	}
	void add(int i, int val) {
		for (i++; i <= n; i += i & -i) data[i] += val;
	}
	int sum(int r) {
		int res = 0;
		for (; r; r -= r & -r) res += data[r];
		return res;
	}
};

int main() {
	int n = ri();
	int q = ri();
	int a[n];
	for (auto &i : a) i = ri();
	
	std::vector<std::pair<int, int> > index(n);
	for (int i = 0; i < n; i++) index[i] = {a[i], i};
	std::sort(index.begin(), index.end());
	
	std::vector<int> add[n + 1];
	
	int all = 0;
	for (int i = 0; i < n; ) {
		int j = i;
		while (j < n && index[j].first == index[i].first) j++;
		
		int last = 0;
		for (int k = i; k <= j; k++) {
			int cur = k == j ? n : index[k].second;
			add[last].push_back(last << 1);
			add[last].push_back(cur << 1 | 1);
			add[cur].push_back(last << 1 | 1);
			add[cur].push_back(cur << 1);
			last = cur + 1;
		}
		i = j;
		all++;
	}
	
	std::vector<std::pair<int, int> > qs[n];
	for (int i = 0; i < q; i++) {
		int l = ri() - 1;
		int r = ri() - 1;
		qs[l].push_back({r, i});
	}
	BIT tree(n + 1);
	int res[q];
	for (int i = 0; i < n; i++) {
		for (auto j : add[i]) tree.add(j >> 1, (j & 1) ? -1 : 1);
		for (auto j : qs[i]) res[j.second] = all - tree.sum(j.first + 1);
	}
	for (auto i : res) printf("%d\n", i);
	
	return 0;
}


Measured memory_bytes: 70332
#include <iostream>
#include <limits.h>
using namespace std;

int main(void){
	int n, i, min = INT_MAX, max = 1;
	int a;

	cin >> n;
	for(i = 0; i < n; i++) {
		cin >> a;
		if(a < min)
			min = a;
		if(max < a)
			max = a;
	}
	cout << max - min << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int Y = stdIn.nextInt();
		
		for(int i = 0; i <= N; i++) {
			for(int j = 0; j <= N-i; j++) {
				if(10000*i+5000*j+1000*(N-i-j) == Y) {
					System.out.println(i+ " " +j+ " "+ (N-i-j));
					System.exit(0);
				}
			}
		}
		System.out.println("-1 -1 -1");

	}

}

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

int main() {
  ll N, res = 1;
  int mod = 1000000007;
  cin >> N;
  vector<int> A(N);
  vector<int> freq(N + 1, 0);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  freq[0] = 3;
  for (int a : A) {
    int p = min(3 - freq[a + 1], freq[a]);
    res = (res * p) % mod;
    freq[a + 1]++;
    freq[a]--;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
def gcd( x, y ):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors
  
A, B, K = map(int, input().split())
N = gcd(A, B)
print(make_divisors(N)[-K])

Measured memory_bytes: 3060
//@formatter:off
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < int(n); ++i)
#define rrep(i,n) for (int i = int(n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = int(s); i < int(n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vvd vector<vector<double>>
#define vs vector<string>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<P>
#define vvp vector<vector<P>>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==int(v.size()-1)?"":","); return os<<']'; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << '\n'; }
void YES(bool b) { cout << (b ? "YES" : "NO") << '\n'; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;
//@formatter:on

class unionfind {
    int n;
    vector<int> par, rank;
public:
    unionfind(int n) : n(n), par(n, -1), rank(n, 0) {}
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool same(int x, int y) { return root(x) == root(y); };
    
    bool merge(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) rank[x]++;
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) { return -par[root(x)]; };
    
    bool connected() {
        rep(i, n - 1) if (!same(i, i + 1)) return false;
        return true;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    vi x(n), y(n);
    rep(i, n) cin >> x[i] >> y[i];
    vi ord(n);
    iota(all(ord), 0);
    sort(all(ord), [&](int i, int j) { return x[i] < x[j]; });
    vi ans(n);
    vi mn(n, y[ord[0]]);
    rep(i, n - 1) mn[i + 1] = min(mn[i], y[ord[i + 1]]);
    vi mx(n, y[ord[n - 1]]);
    rrep(i, n - 1) mx[i] = max(mx[i + 1], y[ord[i]]);
    vb v(n - 1);
    rep(i, n - 1) v[i] = mn[i] > mx[i + 1];
    unionfind uf(n);
    rep(i, n - 1) {
        if (!v[i]) uf.merge(ord[i], ord[i + 1]);
    }
    rep(i, n) {
        cout << uf.size(i) << endl;
    }
}

Measured memory_bytes: 9540
#import numpy as np
#import functools
#import operator
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as comb_with
#from itertools import permutations as perm
#import collections as C #most_common
#import math


#N = int(input())
A,B,C,K= map(int,input().split())
#P = list(map(int,input().split()))
#S= str(input())

if K%2==0:
    ans = A-B
else:
    ans = B-A
    
if ans>10**18:
    print('Unfair')
else:
    print(ans)


Measured memory_bytes: 9096
#include <iostream>
#include <vector>
using namespace std;
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) { vec.resize(len); for (auto &v : vec) ndarray(v, args...); }

constexpr int MOD = 1000000007;

int main()
{
    int N, J = 0, K = 0, L = 0;
    cin >> N;

    vector<int> st(N * 2 + 1);
    REP(_, N)
    {
        int A, B;
        cin >> A >> B;
        if (A < 0 and B > 0) st[B] = 1, K++;
        else if (A > 0 and B < 0) st[A] = 1, K++;
        else if (A > 0 and B > 0) st[A] = st[B] = 2, L++;
        else J++;
    }

    vector<vector<int>> dp[2];
    REP(d, 2) ndarray(dp[d], N - L + 1, K + 1);
    dp[0][0][0] = 1;

    int G = 0, H = 0, t = 0;

    REP(i, 2 * N)
    {
        int s = st[2 * N - i];
        if (s == 2) continue;
        else if (s)
        {
            REP(j, N - L + 1) IREP(k, K + 1)
            {
                dp[t][j][k] = (j < N - L ? dp[t][j + 1][k] : 0) + (k ? dp[t][j][k - 1] : 0);
                if (dp[t][j][k] >= MOD) dp[t][j][k] -= MOD;
            }
            H++;
        }
        else
        {
            dp[!t].assign(N - L + 1, vector<int>(K + 1));
            REP(j, N - L + 1) REP(k, K + 1) if (dp[t][j][k])
            {
                int pa2 = G + H - j - k - (H - k) * 2;
                if (j < N - L) (dp[!t][j + 1][k] += dp[t][j][k]) %= MOD;
                if (j) (dp[!t][j - 1][k] += dp[t][j][k] * (long long int)(J - pa2 / 2) % MOD) %= MOD;
                if (k) (dp[!t][j][k - 1] += dp[t][j][k] * (long long int)k % MOD) %= MOD;
            }
            G++;
            t = !t;
        }
    }
    cout << dp[t][0][0] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <functional>

using namespace std;


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

    int m;scanf("%d",&m);
    
    printf("%d\n",48-m);



    return 0;
}


Measured memory_bytes: 764
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ0002
{
    class Program
    {
        private static void Main(string[] args)
        {
            for (;;)
            {
                var inputStr = Console.ReadLine();
                if (inputStr == null) break;
                

                var q = inputStr.Split(' ');
                var i = q.Sum(s => Convert.ToInt32(s));

                Console.WriteLine(i.ToString().Length);
            }
        }
    }
}

Measured memory_bytes: 5856
#include<iostream>
#include<vector>
#include<string>
#include <cassert>
#include <numeric>
 
using namespace std;
 
int main(void){

  int K;
  long long sum = 0;
  cin >> K;
  
  for(int i = 1;i <= K; i++){
   for(int j = 1; j <= K; j++){
    for(int k = 1; k <= K; k++){
      int tmp;
      tmp = gcd(i,j);
      tmp = gcd(tmp,k);
      sum += tmp;
    }
   }
  }
  
  

  cout << sum;
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    if(n==1){
        cout << "Hello World" << endl;
    }
    else if (n==2){
        int a,b;
        cin >> a >> b;
        cout << a + b << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;
using llong = long long;

int main() {
  llong a, b, k;
  cin >> a >> b >> k;

  llong ra, rb;
  if (a >= k) {
    ra = a - k;
    rb = b;
  } else if (a + b >= k) {
    ra = 0;
    rb = b - (k - a);
  } else {
    ra = 0;
    rb = 0;
  }
  cout << ra << " " << rb;

  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define per(i,n) for (int i = n - 1; i >= 0; --i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline T intceil(T a, T b) { return (a + (b - 1)) / b; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
const long long MOD = 1e9+7;
#define precout() cout << std::fixed << std::setprecision(20);
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
const int dy[4] = { 0, 1, 0, -1 };
const int dx[4] = { 1, 0, -1, 0 };
static const long double pi = acos(-1.0);
typedef complex<ld> cd;

template<typename T> map<T, int> prime_factorize(T N) {
  map<T, int> res;
  for (T a = 2; a * a <= N; ++a) {
    if (N % a != 0) continue;
    T ex = 0;

    while (N % a == 0) {
      ++ex;
      N /= a;
    }

    res[a] = ex;
  }

  if (N != 1) res[N] = 1;
  return res;
}

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

  ll n; cin >> n;
  auto facts = prime_factorize(n);
  int ans = 0;
  for(auto&f:facts) {
    int e = 1;
    while(f.second >= e) {
      f.second -= e;
      ++ans;
      ++e;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3668
#include <iostream>

int main() {
	int N, T;
	std::cin >> N >> T;

	int ans = 0;
	int fin = 0;

	for (int i = 0; i < N; i++) {
		int t;
		std::cin >> t;
		int pre = fin;
		if (fin < t) {
			pre = t;
		}
		fin = t + T;
		ans += fin - pre;
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <bitset>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef long long LL;

typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

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

//constant
//--------------------------------------------
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
const LL MOD = 1e9+7; 
int n;
//vector <vector<int>> x(20, vector<int> (20)), y(20,vector<int> (20));
/*int counter_1 (int x) {
    if(x == 0) return 0;
    return counter_1(x >> 1) + (x & 1);
}*/

//int Counter(int x)
int main(){
    LL h , n, cnt=0;
    cin >> h >> n;
   VL a(n);
   REP(i, n){
       cin >> a[i];
       cnt+=a[i];
   }
   if(h>cnt) cout << "No" << endl;
   else cout << "Yes" << endl;
   
   
}

    



Measured memory_bytes: 1024
import sys,heapq
input = sys.stdin.readline


def main():
    mod = 10**9+7
    n = int(input())
    edge = [[] for _ in [0]*n]
    for i in range(n-1):
        a,b = map(int,input().split())
        edge[a-1].append(b-1)
        edge[b-1].append(a-1)
    
    #root
    p = -1
    ma = -1
    for i in range(n):
        if len(edge[i]) > ma:
            p = i
            ma = len(edge[i])

    #parent
    par = [-2]*n
    par[p] = -1
    order = []
    tank = [p]
    while tank:
        x = tank.pop()
        order.append(x)
        for elt in edge[x]:
            if par[elt] == -2:
                par[elt] = x
                tank.append(elt)
        

    #size
    size = [1]*n    
    for i in range(n-1,0,-1):
        now = order[i]
        size[par[now]] += size[now]
    
    se_N1 = pow(2,n-1,mod)

    res = 0
    for i in range(n):
        if size[i] == 1:
            continue
        #size list
        Q = []
        for elt in edge[i]:
            if elt == par[i]:
                Q.append(n-size[i])
            else:
                Q.append(size[elt])
        res = (res + se_N1)%mod
        cpm = 1
        for e in Q:
            cpm = (cpm + pow(2,e,mod) - 1)%mod
        res = (res-cpm)%mod

    print(res*pow(2,n*(mod-2),mod)%mod) 

    





if __name__ == '__main__':
    main()

Measured memory_bytes: 93816
/*
*         ****FOX****
*/
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <limits>
//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#include <utility>
#include <list>
#include <cstdio>
#include<forward_list>
#include<algorithm>
#include<string>
#define Omar_Hafez ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pi 3.1415926536
#define ll long long
#define ull unsigned long long
#define lli long long int
using namespace std;
int main()
{
    Omar_Hafez
    int n,sum=0,x; cin >> n; 
    for (int i = 1; i <= n; i++)
    {
        cin >> x;
        if ((i % 2 != 0 )&&( x % 2 != 0)) sum++;
    }
    return cout<<sum,0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int A,B,C,X,Y;

int main(){
	cin >> A >> B >> C >> X >> Y;
	int ans = 1.5e9;
	repp(i,0,max(X,Y)+1){
		ans = min(ans , max(0,X-i)*A+max(0,Y-i)*B+C*2*i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#define Lens 105
using namespace std;
int a[Lens];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++)
	{
		cin >> a[i];
	}
	for (int i = 0; i < N; i++)
	{
		int j = i;
		while (j > 0)
		{
			if (a[j] < a[j - 1])
			{
				swap(a[j], a[j - 1]);
				j--;
			}

			else
				break;
		}
		for (int s = 0; s < N; s++)
		{
			if (s > 0)
				cout << ' ';
			cout << a[s];
			
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf =1 << 30;
const ll mod=1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b,const ll &mod) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b,const ll &mod) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b,const ll &mod) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b,const ll &mod) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
random_device rd;
mt19937 mt(rd());
uniform_int_distribution<int> dice(1,6);
uniform_real_distribution<double> score(0.0,10.0);

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

    int n, m; cin >> n >> m;
    vector<vi> G(n);
    rep(i, m){
        int a, b; cin >> a >> b;
        a--, b--;
        G[a].emplace_back(b);
    }
    int S, T; cin >> S >> T; S--, T--;

    using Elem = tuple<int, int>;
    queue<Elem> q;
    Elem s = Elem(S, 0), t = Elem(T, 0);
    q.push(s);

    const int M = 3;
    vector<vi> min_dist(n, vi(M, inf));
    min_dist[S][0] = 0;

    int res = -1;
    while(q.size()){
        Elem cur = q.front(); q.pop();
        int v, md; tie(v, md) = cur;

        if(cur == t){
            res = min_dist[v][md] / 3;
            break;
        }
        
        int nmd = (md + 1) % M;
        for(auto& nv : G[v]){
            Elem nxt = Elem(nv, nmd);
            if(chmin(min_dist[nv][nmd], min_dist[v][md] + 1)){
                q.push(nxt);
            }
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 11264
// Tazoe

#include <iostream>
using namespace std;

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

	int cnt[6] = {0};

	for(int i=0; i<n; i++){
		double h;
		cin >> h;

		if(h<165.0){
			cnt[0]++;
		}
		else if(h<170.0){
			cnt[1]++;
		}
		else if(h<175.0){
			cnt[2]++;
		}
		else if(h<180.0){
			cnt[3]++;
		}
		else if(h<185.0){
			cnt[4]++;
		}
		else{
			cnt[5]++;
		}
	}

	for(int i=0; i<6; i++){
		cout << i+1 << ':';
		for(int j=0; j<cnt[i]; j++){
			cout << '*';
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <stdio.h>
#include <set>

using namespace std;

#define dirmax 8

int l[2];
int dir[8][2] = { {0,1}, {1,0}, {-1,0}, {0,-1}, {1,1}, {-1,1}, {1,-1}, {-1,-1} };
string ans;

void search( set<string> *v, int pos[2] , char ch[10][20]){

	for(int i = 0; i < dirmax; i++) {
		string str;
		int cpos[] = { pos[0], pos[1] };

		str += ch[pos[0]][pos[1]];

		while( 1 ) {
			for(int j = 0; j < 2; j++) {
				cpos[j] += dir[i][j];
				if( cpos[j] < 0 ) cpos[j] = l[j] - 1;
				if( cpos[j] >= l[j] ) cpos[j] = 0;
			}
			if( cpos[0] == pos[0] && cpos[1] == pos[1] ) break;

			str += ch[cpos[0]][cpos[1]];
			
			if( v->find(str) != v->end() ) {
 				if( ( str.length() > ans.length() ) || ( str.length() == ans.length() && str < ans ) ) {
					ans = str;
				}
			} else 
				v->insert(str);
		}
	}
}

int main(void){
	while(1){
		cin >> l[0] >> l[1];
		if( l[0] == 0 && l[1] == 0 ) break;

		char donut[10][20];
		int pos[2];
		ans = "";

		set< string > strs;

		//入力を取得する
		for(int i = 0; i < l[0]; i++)
			cin >> donut[i];

		
		for(pos[0] = 0; pos[0] < l[0]; pos[0]++)
			for(pos[1] = 0; pos[1] < l[1]; pos[1]++)
				search( &strs, pos, donut );

		if(ans == "") 
			cout << 0 << endl;
		else 
			cout << ans << endl;
	}

	return 0;
}

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

int main() {
  string s;
  cin >>s;
  string ans="AC";
  
  if (s.at(0) != 'A') ans="WA";

  int count=0;
  for (int i=1; i<s.size(); ++i) {
    if (islower(s.at(i))) ++count;
  }
  if (count != s.size()-2) ans="WA";
  
  int count_C=0;
  if (ans=="AC") {
    for (int i=2; i<s.size()-1; ++i) {
      if (s.at(i)=='C') ++count_C;
    }
    if (count_C != 1) ans="WA";
  }
      
  
  cout << ans << endl ;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
   public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
     int n = sc.nextInt();
     int []a = new int[n];
     int []c = new int[9];
     int cn = 0;
     int min = 0; int max = 0;
     for(int i=0; i<n; i++) {
    	a[i] = sc.nextInt(); 
     }
     for(int i=0; i<9; i++) {
     	c[i] = 0; 
      }
 	
	sc.close();
	for(int i=0; i<n; i++) {
      if(1<=a[i]&&a[i]<=399) {c[0]++;}
      if(400<=a[i]&&a[i]<=799) {c[1]++;}
      if(800<=a[i]&&a[i]<=1199) {c[2]++;}
      if(1200<=a[i]&&a[i]<=1599) {c[3]++;}
      if(1600<=a[i]&&a[i]<=1999) {c[4]++;}
      if(2000<=a[i]&&a[i]<=2399) {c[5]++;}
      if(2400<=a[i]&&a[i]<=2799) {c[6]++;}
      if(2800<=a[i]&&a[i]<=3199) {c[7]++;}
      if(3200<=a[i]) {c[8]++;}
      }
	for(int i=0; i<8; i++) {
     	if(c[i] != 0) {cn++;} 
      }
	
	if(cn!=0) {min=cn;}
	if(cn==0) {min=1;}
	
	
	
	 max=cn+c[8];
    
   
	System.out.println(min+" "+max);
   }

}

Measured memory_bytes: 21716
#include <stdio.h>

int n, r[100], c[100];
int DP[100][100];

int min(int a, int b){
  if (a > b) {
    return b;
  } else {
    return a;
  }
}

int main(){
  int a, b, i, j, k;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d %d", &r[i], &c[i]);
    DP[i][i] = 0;
  }
  
  for (i = 1; i < n; i++) {
    for (j = 0; j < n - i; j++) {
      a = r[j] * c[i + j] * c[j] + DP[j][j] + DP[j + 1][i + j];
      for (k = j + 1; k < i + j; k++) {
        b = r[j] * c[i + j] * c[k] + DP[j][k] + DP[k + 1][i + j];
        a = min(a, b);
      }
      DP[j][i + j] = a;
    }
  }
  
  printf("%d\n", DP[0][n - 1]);
  return 0;
}

Measured memory_bytes: 636
n = int(input())
a = list(map(int,input().split()))

kazu = {}

for i in range(len(a)):
  if a[i] not in kazu:
    kazu[a[i]]=1
  else:
    kazu[a[i]]+=1

ans = 0
for i in kazu:
  if i > kazu[i]:
    ans +=kazu[i]
  elif i< kazu[i]:
    ans += kazu[i]-i
print(ans)

Measured memory_bytes: 17780
import java.util.*;
 
public class Main {
	
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	String in = sc.next();
    	int A = in.charAt(0) - '0';
    	int B = in.charAt(1) - '0';
    	int C = in.charAt(2) - '0';
    	int D = in.charAt(3) - '0';
    	List<String> op = new ArrayList<>();
    	for (int i = 1; i < Math.pow(2, 3); i++) {
    		String opr = Integer.toString(i, 2);
    		if (opr.length() == 1) {
    			opr = "0" + "0" + opr;
    		} else if (opr.length() == 2) {
    			opr = "0" + opr;
    		}
    		op.add(opr.replace('1', '+').replace('0', '-'));
    	}
    	for (String s : op) {
    		int num = 0;
    		if (s.charAt(0) == '+') {
    			num = A + B;
    		} else {
    			num = A - B;
    		}
    		if (s.charAt(1) == '+') {
    			num += C;
    		} else {
    			num -= C;
    		}
    		if (s.charAt(2) == '+') {
    			num += D;
    		} else {
    			num -= D;
    		}
    		if (num == 7) {
    			System.out.println("" + A + s.charAt(0) + B + s.charAt(1) + C + s.charAt(2) + D + "=7");
    			System.exit(0);
    		}
    	}
    }
}

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

vector<vector<int>> G(100010);
vector<int> dist1(100010,0);
vector<int> distN(100010,0);
vector<bool> used1(100010,false);
vector<bool> usedN(100010,false);

void dfs(int n,vector<int> &dist,vector<bool> &used){
  used[n]=true;
  for (int i=0;i<G[n].size();i++){
    int v=G[n][i];
    if (!used[v]){
      dist[v]=dist[n]+1;
      dfs(v,dist,used);
    }
  }
}

int main(){
  int N;
  cin >> N;
  for (int i=0;i<N-1;i++){
    int a,b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs(0,dist1,used1);
  dfs(N-1,distN,usedN);
  int count1=0,count2=0;
  for (int i=0;i<N;i++){
    if (dist1[i]<=distN[i]){
      count1++;
    }
    else {
      count2++;
    }
  }
  if (count1>count2){
    cout << "Fennec" << endl;
  }
  else {
    cout << "Snuke" << endl;
  }
}

Measured memory_bytes: 12800
x,k,d = map(int,input().split())
v = abs(abs(x)//d)
w = abs(x)%d
if v >=k:
    print(abs(abs(x)-k*d))
else:
    k-=v
    if k%2:
        print(abs(w-d))
    else:
        print(w)

Measured memory_bytes: 61832
n=int(input())
A=list(map(int,input().split()))
for i in range(1,n):
    A[i]+=A[i-1]

ans=1000000
for i in range(n-1):
    if abs(A[n-1]-2*A[i])<ans:
        ans=abs(A[n-1]-2*A[i])
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define show(x) cerr << #x << " = " << (x) << endl
using namespace std;
struct Term
{
    using Ptr = shared_ptr<Term>;
    Term(const int rep, const vector<Ptr>& child, const int unit, const string& s) : rep{rep}, child{child}, unit{unit}, s{s} {}
    int rep;
    vector<Ptr> child;
    int unit;
    string s;
};
using Ptr = Term::Ptr;
string S;
string::iterator c;
Ptr parse()
{
    if (not isdigit(*c)) {
        string s;
        for (; 'A' <= *c and *c <= 'Z'; c++) { s.push_back(*c); }
        return make_shared<Term>(1, vector<Ptr>{}, (int)s.size(), s);
    }
    string d;
    for (; isdigit(*c); c++) { d.push_back(*c); }
    const int D = d == "" ? 1 : stoi(d);
    Ptr ans = make_shared<Term>(D, vector<Ptr>{}, 0, "");
    bool hasb = false;
    if (*c == '(') { hasb = true, c++; }
    if (not hasb) { return (ans->unit = 1, ans->s = string(1, *c), c++, ans); }
    for (; *c != ')';) {
        const auto p = parse();
        ans->child.push_back(p);
        ans->unit = min(ans->unit + (p->unit) * (p->rep), 1000001);
    }
    c++;
    return ans;
}
string toString(const Ptr p)
{
    if (p->child.empty()) { return p->s; }
    string s = to_string(p->rep) + "(";
    for (const auto& c : p->child) { s += toString(c); }
    s += ")";
    return s;
}
int main()
{
    while (true) {
        int N;
        cin >> S >> N;
        if (S == "0" and N == 0) { break; }
        S = "1(" + S + ")";
        c = S.begin();
        const Ptr root = parse();
//        show(toString(root));
        if (N >= root->unit * root->rep) {
            cout << 0 << endl;
            continue;
        }
        Ptr p = root;
        while (true) {
            if (p->child.empty()) {
                cout << p->s[N] << endl;
                break;
            } else {
                for (const auto& c : p->child) {
                    if (N >= c->rep * c->unit) {
                        N -= c->rep * c->unit;
                    } else {
                        N %= c->unit;
                        p = c;
                        break;
                    }
                }
            }
        }
    }
    return 0;
}



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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin >> n >> k;
	vector <int> H(n);
	for(int i=0;i<n;i++) cin >> H[i];
	sort(H.rbegin(),H.rend());
	long long ans=0;
	for(int i=k;i<H.size();i++){
		ans += (long long)H[i];
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main()
{

int a[10000], min, max, n, i;
long long sum = 0;
scanf("%d", &n);//1以上が入力されるものとします
for(i = 0; i < n; i++){
scanf("%d", &a[i]);
sum += a[i];
}
max = min = a[0];//とりあえず最初の要素をセットしておく
for(i = 1; i < n; i++){//2番目以降の要素と比較
if(a[i] > max)max = a[i];
if(a[i] < min)min = a[i];
}
printf("%d %d %lld\n", min, max, sum);

return 0;
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
#define endl ("\n")
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ms memset
#define MOD 1000000007
#define fast ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
#define fr(i,n) for(i=0;i<n;i++)
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>	vi;
typedef vector<ll>	vl;
typedef vector<pii>	vpii;
typedef vector<pl>	vpl;
typedef vector<vi>	vvi;
typedef vector<vl>	vvl;
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
 
ll expo (ll x, ll y) {ll res = 1; while (y) {if (y & 1)res = res * x; res %= MOD; y = y >> 1; x = x * x; x %= MOD;} return res;}
bool sum[101][100001];
ll cost[101][100001];
ll A[101][2];
ll fun(ll ind,ll val)
{
    if(val==0)
    return 0;
    if(ind==0)
    return INT_MAX;
    if(cost[ind][val]!=-1)
    return cost[ind][val];
   // cout<<ind<<' '<<val<<endl;
    if(A[ind][1]<=val)
    return cost[ind][val]= min(A[ind][0]+fun(ind-1,val-A[ind][1]),fun(ind-1,val));
    return cost[ind][val]=fun(ind-1,val);
} 

void solve()
{   
   ll i,j;
   ll n,wt;
   cin>>n>>wt;
   for(i=1;i<=n;i++)
   cin>>A[i][0]>>A[i][1];
   for(i=0;i<=100000;i++)
    sum[0][i]=false;
   for(i=0;i<=n;i++)
   sum[i][0]=true;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=100000;j++)
        {
            cost[i][j]=-1;
            if(A[i][1]<=j)            
                sum[i][j]=sum[i-1][j]||sum[i-1][j-A[i][1]];
            else
                sum[i][j]=sum[i-1][j];

        }
    }
    for(i=100000;i>=0;i--)
    {
        if(sum[n][i])
        {
            if(fun(n,i)<=wt)
            {
                cout<<i<<endl;
                return;
            }
        }
    }

 
}
int main() 
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);
#endif
    fast;
    // Fuck Ratings, I'm in Love with Experience. 
    int t = 1;
    //cin >> t;
    while(t--) {
      solve();
    }
    return 0;
}
 

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

int main(void)
{
	char str[1024];
	int i, j, n, len;
	
	scanf("%d ", &n);
	for (i = 0; i < n; i++){
		gets(str);
		
		len = strlen(str);
		
		for (j = 0; j < len - 5; j++){
			if (strncmp(&str[j], "Hoshino", 7) == 0){
				str[j + 6] = 'a';
			}
		}
		
		puts(str);
	}
	
	return (0);
}

Measured memory_bytes: 580
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<functional>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using namespace std;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e14;
typedef std::pair<ll,ll> P;
struct edge{ int to,cost; };
#define VMAX 100000
//bool cmp(P a,P b){ return a.second < b.second;}
	ll N,M,K,X,Y,ans=0;
	ll A;
	ll B;
	ll C;
	priority_queue<P> Q;
	priority_queue<ll> T;
	priority_queue<ll,vector<ll>,greater<ll>> R;
    string S;



int main(){
	std::ios_base::sync_with_stdio(false);
    cin>>X>>Y>>A>>B>>C;
	REP(i,A){
		int a;cin>>a;Q.push({a,1});
	}
	REP(i,B){
		int a;cin>>a;Q.push({a,2});
	}
	REP(i,C){
		int a;cin>>a;T.push(a);
	}
	bool f=true;int x=0,y=0;
	while(f){
		if(Q.top().second==1){
			if(x<X){
				x++;
				R.push(Q.top().first);
			}
			Q.pop();
		}
		if(Q.top().second==2){
			if(y<Y){
				y++;
				R.push(Q.top().first);
			}
			Q.pop();
		}
		// DEB(x)DEB(y)END
		if(x>=X&&y>=Y)f=false;
	}
	f=true;
	while(T.top()>R.top()&&!T.empty()){
		DEB(T.top())DEB(R.top())
		R.pop();
		R.push(T.top());
		T.pop();
		TF(!T.empty())END
	}
	while(!R.empty()){
		ans+=R.top();
		R.pop();

	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 8428