akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
Int lim;
void fin(){
  cout<<"Error"<<endl;
  exit(0);
}

vector<Int> len({-1}), pos(26,0);
struct st{
  char c;
  Int v;
  st(char c):c(c),v(-1){}
};

const int D = 0;

st expr(string &s,Int &p);
st assign(string &s,Int &p);
st malloc(string &s,Int &p);
void free(string &s,Int &p);
st clone(string &s,Int &p);
st variable(string &s,Int &p);
Int number(string &s,Int &p);

void line(string &s,Int &p){
  if(s[0]=='f') free(s,p);
  else          expr(s,p);
}

st expr(string &s,Int &p){
  if(s[p]=='('){
    p++;
    st t=expr(s,p);
    if(D) assert(s[p]==')');
    p++;
    return t;
  }
  if(s[p]=='m'){
    return malloc(s,p);
  }
  if(s[p]=='c'){
    return clone(s,p);
  }
  if(p+1<(Int)s.size()&&isupper(s[p])&&s[p+1]=='='){
    return assign(s,p);
  }
  if(p+3<(Int)s.size()&&s[p]=='N'&&s[p+1]=='U'&&s[p+2]=='L'&&s[p+3]=='L'){
    return st('A'-1);
  }
  return variable(s,p);
}
st assign(string &s,Int &p){
  st t(s[p++]);
  if(D) assert(s[p]=='=');
  p++;
  t.v=expr(s,p).v;
  pos[t.c-'A']=t.v;
  return t;
}
st malloc(string &s,Int &p){
  if(D) assert(s[p]=='m');p++;
  if(D) assert(s[p]=='a');p++;
  if(D) assert(s[p]=='l');p++;
  if(D) assert(s[p]=='l');p++;
  if(D) assert(s[p]=='o');p++;
  if(D) assert(s[p]=='c');p++;
  if(D) assert(s[p]=='(');p++;
  Int res=number(s,p);
  if(D) assert(s[p]==')');p++;
  st t('A'-1);
  if(lim>=res){
    t.v=len.size();
    len.emplace_back(res);
    lim-=res;
  }else{
    t.v=-1;
  }
  return t;
}

void free(string &s,Int &p){
  if(D) assert(s[p]=='f');p++;
  if(D) assert(s[p]=='r');p++;
  if(D) assert(s[p]=='e');p++;
  if(D) assert(s[p]=='e');p++;
  if(D) assert(s[p]=='(');p++;
  st t=expr(s,p);
  if(D) assert(s[p]==')');p++;
  if(t.v<0) return;
  if(len[t.v]<0) fin();
  lim+=len[t.v];
  len[t.v]=-1;
}

st clone(string &s,Int &p){
  if(D) assert(s[p]=='c');p++;
  if(D) assert(s[p]=='l');p++;
  if(D) assert(s[p]=='o');p++;
  if(D) assert(s[p]=='n');p++;
  if(D) assert(s[p]=='e');p++;
  if(D) assert(s[p]=='(');p++;
  Int x=expr(s,p).v;
  if(D) assert(s[p]==')');p++;

  st t('A'-1);
  if(x<0) return t;
  Int res=len[x];
  if(res<0) fin();
  
  if(lim>=res){
    t.v=len.size();
    len.emplace_back(res);
    lim-=res;
  }else{
    t.v=-1;
  }
  
  return t;
  
}
st variable(string &s,Int &p){
  st t(s[p++]);
  t.v=pos[t.c-'A'];
  return t;
}
Int number(string &s,Int &p){
  Int res=0;
  while(isdigit(s[p]))
    res=res*10+(s[p++]-'0');
  return res;
}


signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin>>lim;
  string s;
  while(cin>>s){
    Int p=0;
    line(s,p);
  }
  
  Int ans=0;
  for(Int i=0;i<26;i++) if(~pos[i]) len[pos[i]]=0;
  for(Int x:len) if(x>0) ans+=x;
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 3244
import bisect

n = int(input())
a = list(map(int, input().split()))
a.sort()
k = len(a)
ok = [0] * k
for i in range(k):
    if i < k - 1 and a[i] == a[i + 1]:
        ok[i] = 1
        ok[i+1] = 1;
        continue

    times = 2
    while a[i] * times <= a[-1]:
        r = bisect.bisect_left(a, a[i] * times + 1)
        l = bisect.bisect_left(a, a[i] * times)
        if r != l:
            for idx in range(l, r):
                ok[idx] = 1
        times += 1
print(len([i for i in ok if i == 0]))
# print(ok) WAはどこ？


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

int main(){
	int n;
	cin >> n;
	vector<int> v(n);
	rep(i,n) cin >> v[i];
	sort(v.begin(),v.end());
	double ans = (v[0]+v[1])*0.5;
	if(n>=3){
		rep(i,n-2) ans = (ans+v[i+2])*0.5;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> c(h,vector<char>(w));
    rep(i,h){
        rep(j,w) cin >> c[i][j];
    }

 rep(i,h){
    rep(k,2){
        rep(j,w){
            cout << c[i][j] ;
        }
        cout << endl;
    }
}
return 0;
}

Measured memory_bytes: 256
n = gets.to_i
arr = gets.to_s.split.map(&:to_i)

max = arr.max
hash = {}
arr.each do |num|
  hash[num] = hash[num].nil? ? true : false
  (2..max).each do |i|
    if num * i > max
      break
    end
    hash[num * i] = false
  end
end

count = 0
hash.each do |_num, bool|
  count += 1 if bool
end
puts count

Measured memory_bytes: 69688
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 3005
using namespace std;
int n;
double p[M];
unordered_map<int, double> dp[M];
int main()
{
    scanf("%d", &n);
    REP(i,1,n) scanf("%lf", &p[i]);

    dp[1][1] = p[1];
    dp[1][-1] = 1.0 - p[1];
    REP(i,1,n-1) for (auto it:dp[i]) {
        int j = it.first;
        dp[i+1][j+1] += dp[i][j] * p[i+1];
        dp[i+1][j-1] += dp[i][j] * (1.0 - p[i+1]);
    }

    double ans = 0.0;
    for (auto it: dp[n]) if (it.first>=1) ans += dp[n][it.first];
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 197540
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		String t1 = scanner.next();
		String t2 = scanner.next();
		int m = t1.length()-1;
		boolean res = true;
		for (int i = 0; i <= m; i++) {
			if(t1.charAt(i)!=t2.charAt(m-i)){
				res = false;
			}
		}
		if(res) {
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

const int N = 1e5 + 2;

int n, k, w[101], v[101];
long long dp[N];

int main()
{
    cin >> n >> k;
    for (int i = 0; i < n; ++i)
    {
        cin >> w[i] >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        for (int weight_already = k - w[i]; weight_already >= 0; --weight_already) {
            dp[weight_already + w[i]] = max(dp[weight_already + w[i]], dp[weight_already] + v[i]);
        }
    }
    long long ans = 0;
    for (int i = 0; i <= k; ++i) {
        ans = max(ans, dp[i]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int W,H,x,y,r;
	
	cin >> W >> H >> x >> y >> r;
	
	if(x>=r && W-x>=r && H-y>=r && y>=r){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
}

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

#define M 1046527
#define L 14

char H[M][L]; 

int getChar(char ch){
  if ( ch == 'A')
                  return 1;
  else if ( ch == 'C')
                  return 2;
  else if ( ch == 'G')
                  return 3;
  else if ( ch == 'T')
                  return 4;
  else 
                  return 0;
}

long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ 
       return key % M; 
}

int h2(int key){ 
        return 1 + (key % (M-1)); 
}

int find(char str[]){
  long long key,i,h;
  key = getKey(str);
  for(i = 0; ;i++){
    h = (h1(key) + i * h2(key)) % M;
    if(strcmp(H[h],str) == 0)
              return 1;
    else if(strlen(H[h])==0) 
              return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key = getKey(str);
  for( i = 0;  ; i++){
      h = (h1(key) + i * h2(key)) % M;
      if(strcmp(H[h],str) == 0)
            return 1;
      else if(strlen(H[h]) == 0){
           strcpy(H[h],str);
           return 0;
    }
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ )
            H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s%s", com, str);
	
    if ( com[0] == 'i' ){
      insert(str);
    } 
    else {
       if (find(str)){
	  printf("yes\n");
      } 
     else {
	 printf("no\n");
      }
    }
  }

  return 0;
}





Measured memory_bytes: 17068
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i,j,s;
    while(scanf("%d",&n)==1)
    {
        int array[2*(n+1)];
        for(i=0; i<2*n; i++)
        {
            scanf("%d",&array[i]);
        }
        sort(array,array+i);
        s=0;
        for(j=0; j<2*n; j++)
        {
            if(j%2==0) s+=array[j];
        }
        printf("%d\n",s);
    }
    return 0;
}


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

int N,K,d;

int main() {
    cin>>N>>K;
    vector<int> a(N);
    for (int i=0; i<N; i++) {
        int d; cin>>d;
        for (int j=0; j<d; j++) {
            int temp; cin>>temp;
            a[temp-1]++;
        }
    }
    int ans=0;
    for (int i=0; i<N; i++){
        if (a[i]==0) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int k,a,b;
  scanf("%d",&k);
  scanf("%d %d",&a,&b);
  bool f = false;
  for(int i=a;i<=b;i++)
  {
    if(i%k == 0)
    {
      f = true;
      break;
    }
  }
  if(f)printf("OK\n");
  else printf("NG\n");
  
  return 0;
}

Measured memory_bytes: 3760
N, Y = map(int,input().split())
a = Y//10000
b = (Y-a*10000)//5000
c = (Y-a*10000-b*5000)//1000
d = Y//1000
if N<a+b+c or N>d:
  print('-1 -1 -1')
  exit()
else:
  check = False
  for i in range(1+a):
    for j in range(1+a-i):
      for k in range(1+a-i-j):
        for l in range(1+b):
          if 9*i+5*j+k+4*l == N-(a+b+c):
            print(a-i-j-k, b+j+2*k-l, c+10*i+j*5+l*5)
            check = True
            exit()
  if check == False: print('-1 -1 -1')

Measured memory_bytes: 42220
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;

vector<ll> uft;

ll search(ll w){
    if(uft[w]==w){return w;}
    return uft[w]=search(uft[w]);
}



int main(){
    ll n,q;
    cin>>n>>q;
    uft.resize(n);
    for(int i=0;i<n;i++){
        uft[i]=i;
    }
    while(q--){
        ll c;
        cin>>c;
        if(c){
            ll a,b;
            cin>>a>>b;
            if(search(a)==search(b)){cout<<1<<endl;}
            else{cout<<0<<endl;}
        }
        else{
            ll a,b;
            cin>>a>>b;
            uft[search(a)]=search(b);
        }
    }
    
    
    return 0;
}



Measured memory_bytes: 3220
S = input()
N = len(S)
non_x = []
s_notx = []
for i, s in enumerate(S):
    if s != 'x':
        non_x.append(i)
        s_notx.append(s)
s_notx = ''.join(s_notx)
if s_notx != s_notx[::-1]:
    print(-1)
    quit()
if not non_x:
    print(0)
    quit()
ans = 0
L = len(non_x)
if L % 2 == 0:
    left, right = L // 2 - 1, L // 2
else:
    left = right = L // 2
left, right = left - 1, right + 1
for i in range(left + 1):
    l, r = left - i, right + i
    ans += abs((non_x[l + 1] - non_x[l]) - (non_x[r] - non_x[r - 1]))
ans += abs(non_x[0] - (N - non_x[-1] - 1))
print(ans)


Measured memory_bytes: 7916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// Welcome to my source code!

int main() {
    int n, m;
    cin >> n >> m;
    pair<ll, ll> ab[n];
    for (int i = 0, a, b; i < n; i++) {
        cin >> a >> b;
        ab[i] = make_pair(a, b);
    }
    sort(ab, ab+n);
    ll purc = 0, i = 0, ans = 0;
    while (purc < m) {
        ans += min(m - purc, ab[i].second) * ab[i].first;
        purc += min(m - purc, ab[i].second);
        i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9+7;
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<int> VI;  // VI a(n);
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VVI;   // VVI a(n,vector<int>(m)) n * m 
typedef vector<VL> VVL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<int, int> > PS;
typedef long long ll;  //ll とdoubleは違う
template <class T>  // chmax(max, a);
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> //chmin(min,a)
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

ll max=-1000000000,min=1e9+1;

int main(){
    ll x,y,n,m,h,k,w,sum=0;
    string s,t;
    cin >> n >> k;
    VI d(k);
    char c[10] = {'0','1','2','3','4','5','6','7','8','9'};
    bool f2=true;
    x=n;
    rep(i,k){
        cin >> d[i];
	}

    while(1){
        s = to_string(x);
        for(int i=0; i < s.size();i++){
            for(int j=0; j < k; j++){
                if(s[i] == c[d[j]]){
                    f2 = false;
                    break;
                }
                else{
                    continue;
                }
            }
        }
        if(f2!=false){
            cout << x << endl;
            return 0;
        }
        x++;
        f2=true;
    }

}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(in);
int n=sc.nextInt();
String[] w=new String[n];
for (int i = 0; i < n; i++) {
    w[i]=sc.next();
}
HashSet<String> set=new HashSet<>();
set.add(w[0]);
for (int i = 1; i < n; i++) {
    set.add(w[i]);
    if(w[i].charAt(0)!=w[i-1].charAt(w[i-1].length()-1)){
        out.println("No");
       exit(0);
    }
}
  String ans;
if(set.size()==n){
    ans="Yes";
}else{
    ans="No";
}
  out.println(ans);
}}


Measured memory_bytes: 22996
n, m = gets.split.map(&:to_i)
cond = m.times.map {
  k, *ss = gets.split.map(&:to_i)
  ss.inject(0) {|acc, s| acc | (1 << (s - 1))}
}.zip(gets.split.map(&:to_i))

puts (2 ** n).times.map {|switches|
  cond.map {|c, p| (switches & c).to_s(2).count("1") % 2 == p}.all?
}.count(true)

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
typedef vector <int> ivector;
typedef set <int> iset;

int main(void){
	int n,q,tmp;
	iset S, T;

	cin >> n;
	for (int i=0; i<n; i++){
		cin >> tmp;
		S.insert(tmp);
	}

	cin >> q;
	for (int i=0; i<q; i++){
		cin >> tmp;
		T.insert(tmp);
	}

	ivector X(min(S.size(), T.size()));
	ivector::iterator it = set_intersection(S.begin(), S.end(), T.begin(), T.end(), X.begin());
	cout << it - X.begin() << endl;

	return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);

    for (int i = 0; i < n; ++i) {
        cin >> a.at(i);
    }

    for (int i = 0; i < n; ++i) {
        cin >> b.at(i);
    }

    for (int i = 0; i < n - 1; ++i) {
        cin >> c.at(i);
    }

    int ans = 0, temp = 0, cnt = 0;
    for (int i:a) {
        if (temp == 0) {
            temp = i;
            ans += b[i - 1];
        } else {
            ans += b[i - 1];
            if (a[cnt - 1] + 1 == a[cnt]) {
                ans += c[i - 1 - 1];
            }
        }
        cnt++;
    }

    cout << ans << endl;

}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define ssort(a) sort(a.begin(), a.end())
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  ll n;
  int x, m;
  cin >> n >> x >> m;
  vector<int> vec(m);
  vector<int> cycle;
  int pre, next=x;
  ll sum=0;
  bool flag=false;
  int ind;
  repo(i, m){
    if(vec[next]!=0){
      ind=vec[next]-1;
      break;
    }
    if(next==0){
      flag=true;
      break;
    }
    vec[next]=i;
    cycle.push_back(next);
    sum+=next;
    pre=next;
    next=(int)(((ll)next*next)%m);
  }
  int num=cycle.size()-ind;
  rep(i,ind){
    sum-=cycle[i];
  }
  ll ans=0;
  if(flag){
    ans+=sum;
  } else {
    rep(i,ind){
      ans+=cycle[i];

    }
    n-=ind;
    ans+=n/num*sum;
    int num2=n%num;
    for(int i=ind; i<ind+num2;i++){
      ans+=cycle[i];
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3876
from collections import deque 
n,k = map(int,input().split())
p = list(map(int,input().split()))
q = deque()
s = 0
m = 0
ans = 0
for i in range(len(p)):
  p[i]+=1
for j in range(n):
  s+=p[j]
  q.append(p[j])
  if len(q)>k:
    s-=q.popleft()
  if len(q)==k:
    m = max(m,s)
ans = m
ans/=2
print(ans)

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

#define loop(i,n) for(int i = 0;i < int(n);i++)
#define rloop(i,n) for(int i = int(n);i >= 0;i--)
#define range(i,a,b) for(int i = int(a);i <= int(b);i++)
#define SZ(c) int(c.size())
#define ALL(c) c.begin(), c.end()
#define RALL(c) c.rbegin(), c.rend()
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
#define sfi1(v) scanf("%d",&v)
#define sfi2(v1,v2) scanf("%d %d",&v1,&v2)
#define sfi3(v1,v2,v3) scanf("%d %d %d",&v1,&v2,&v3)
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
#define endl '\n'

typedef vector<int> vi;
typedef vector<pair<int,int> > vii;
typedef long long ll;
typedef pair<int, int> pii;



int main()
{

#ifndef ONLINE_JUDGE
	//freopen("in.in", "r", stdin);
	//freopen("out.in", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    int n , k;
    cin >> n >> k;
    vi v(n);
    for(int &x : v)cin >> x;
    sort(ALL(v));
    ll ans = 0;
    loop(i,k)ans += v[i];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3636
import java.util.Scanner;

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

    double a = sc.nextDouble();
    double b = sc.nextDouble();
    double x = sc.nextDouble();

    if(x >= a*a*b/2){
      System.out.println(Math.toDegrees(Math.atan(2*(a*a*b - x)/(a*a*a))));
    }else{
      System.out.println(Math.toDegrees(Math.atan(a*b*b/(2*x))));
    }

  }
}

Measured memory_bytes: 25300
#include <stdio.h>
#include <math.h>
typedef struct{
  double x;
  double y;
}POINT;

void koch(int,POINT,POINT);

int main(){
  POINT p1,p2;
  int n;

  scanf("%d",&n);

  p1.x=0;
  p1.y=0;
  p2.x=100;
  p2.y=0;

  printf("%f %f\n",p1.x,p2.y);
  koch(n,p1,p2);
  printf("%f %f\n",p2.x,p2.y);

  return 0;
}

void koch(int n,POINT p1,POINT p2){
  POINT s;
  POINT u;
  POINT t;
  double rad;

  if(n==0) return;

  rad=60.0*M_PI/180.0;
  s.x=(2.0*p1.x+1.0*p2.x)/3;
  s.y=(2.0*p1.y+1.0*p2.y)/3;
  t.x=(1.0*p1.x+2.0*p2.x)/3;
  t.y=(1.0*p1.y+2.0*p2.y)/3;
  u.x=(t.x-s.x)*cos(rad)-(t.y-s.y)*sin(rad)+s.x;
  u.y=(t.x-s.x)*sin(rad)+(t.y-s.y)*cos(rad)+s.y;

  koch(n-1,p1,s);
  printf("%f %f\n",s.x,s.y);
  koch(n-1,s,u);
  printf("%f %f\n",u.x,u.y);
  koch(n-1,u,t);
  printf("%f %f\n",t.x,t.y);
  koch(n-1,t,p2);
}



Measured memory_bytes: 2112
# Coins Respawn
import sys
sys.setrecursionlimit(10**7)
from collections import deque
N, M, P = map(int, input().split())
graph = []
d = deque()

# グラフの整形

from_1 = [[] for i in range(N+1)]
from_N = [[] for i in range(N+1)]

for _ in range(M):
    a, b, c = map(int, input().split())
    from_1[a].append(b)
    from_N[b].append(a)
    d.append((a, b, P-c))


accessible_1 = [False for i in range(N+1)]
accessible_N = [False for i in range(N+1)]


def dfs_1(s):
    accessible_1[s] = True
    for node in from_1[s]:
        if accessible_1[node] == False:
            dfs_1(node)


def dfs_N(s):
    accessible_N[s] = True
    for node in from_N[s]:
        if accessible_N[node] == False:
            dfs_N(node)


dfs_1(1)
dfs_N(N)

isok = [False for i in range(N+1)]
for i in range(N+1):
    if accessible_1[i] and accessible_N[i]:
        isok[i] = True


while d:
    p, q, weight = d.popleft()
    if isok[p] and isok[q]:
        graph.append((p, q, weight))

# ベルマンフォード


def bellman_ford(s,n):
    dist = [10**20 for i in range(n+1)]
    dist[s] = 0
    for i in range(1, n+1):
        flag = False
        for some in graph:
            a, b, d = some[0], some[1], some[2]
            newlen = dist[a]+d
            if newlen < dist[b]:
                flag = True
                dist[b] = newlen
        if not flag:
            break
        if i == n:
            return False
    return dist

K=bellman_ford(1,N)
if K==False:
     print(-1)
else:
    print(max(0,-K[N]))

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

string s;

int main(){

    cin >> s;
    if (s == "Sunny"){
        cout << "Cloudy" << endl;
    }
    else if (s == "Cloudy"){
        cout << "Rainy" << endl;
    }
    else{
        cout << "Sunny" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
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 n: usize = read();
    let a: Vec<usize> = (0..n).map(|_| read()).collect();
    let s = a.iter().fold(0, |s, i| s ^ i); 
    for i in 0..n{
        print!("{} ", s ^ a[i])
    }
}


Measured memory_bytes: 4092
N=int(input())
As=list(map(int,input().split()))
q=int(input())


num=[]
for i in range(100000+1):
    num.append(0)
for a in As:
    num[a]+=1

sum=0
for number,i in enumerate(num):
    sum+=number*i


for i in range(q):
    b,c=list(map(int,input().split()))
    sum+=(c-b)*num[b]
    num[c]+=num[b]
    num[b]=0
    print(sum)


Measured memory_bytes: 21060
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;

#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define bk back()
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(x,a) for (auto& x: a)

const int MX  = 2e5+5;
const int MOD = 1e9+7;
const ll  INF = 1061109567; // 4557430888798830399LL
const ld  EPS = 1e-9;
const ld  PI  = acos(-1);

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

template<class T> bool ckmin(T& a, const T& b) {
	return b < a ? a = b, 1 : 0;
}
template<class T> bool ckmax(T& a, const T& b) {
	return a < b ? a = b, 1 : 0;
}

// FILE I/O
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
    ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
    // cin.exceptions(cin.failbit);
    // throws exception when do smth illegal
    // ex. try to read letter into int
    if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

int32_t main() {

    setIO();

    int n; cin >> n;

    int res = 0;
    FOR(i,1,n+1) {
        int x; cin >> x;

        res += (i&1) && (x&1);
    }

    cout << res << "\n";
    
}   

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if ( A+B == C+D ) {
    cout << "Balanced" << endl;
  }
  
  else if ( A+B > C+D ) {
    cout << "Left" << endl;
  }
  
  else {
    cout << "Right" << endl;
  }
  
}

Measured memory_bytes: 3632
use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };

    let l: u64 = sc.read();
    let n: usize = sc.read();
    let x: Vec<u64> = sc.vec(n);
    let x2 = x.iter().rev().map(|&x| l - x).collect();

    let ans1 = solve(x, l);
    let ans2 = solve(x2, l);
    println!("{}", cmp::max(ans1, ans2));
}

fn solve(x: Vec<u64>, l: u64) -> u64 {
    let n = x.len();
    let mut left_sum = vec![0; n + 1];
    for i in 0..n {
        left_sum[i + 1] = left_sum[i] + x[i];
    }

    let mut right_sum = vec![0; n + 1];
    for i in 0..n {
        right_sum[i + 1] = right_sum[i] + l - x[n - 1 - i];
    }

    let mut ans = 0;
    for i in 0..n {
        let rest = n - i;
        let left = (rest + 1) / 2;
        let right = rest - left;
        let mut sum = right_sum[right] * 2 + (left_sum[left + i] - left_sum[i]) * 2;
        if left > right {
            sum -= x[left + i - 1];
        } else if right > 0 {
            sum -= l - x[n - right];
        }
        //        eprintln!("i={} sum={} left={} right={}", i, sum, left, right);
        //        eprintln!("{:?} {:?}", left_sum, right_sum);
        ans = cmp::max(ans, sum);
    }
    ans
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 12540
// J'aime
// Chemise Blanche

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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second

#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << __LINE__ << " > " << #x << " = " << (x) << endl

void MAIN() {
  string t = "CODEFESTIVAL2016";
  string s;
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != t[i]) ans++;
  }
  cout << ans << '\n';
}

signed main() {
#ifdef _DEBUG
  // freopen("in" , "r", stdin );
  // freopen("out", "w", stdout);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  ll ans = 1;
  while(ans * ans <= n) ++ans;
  ans--;
  cout << ans * ans << endl;

}


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

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(2 * N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
    A.at(N + i) = A.at(i) + K;
  }
  int ans = 100000000;
  for (int i = 0; i < N; i++) {
    ans = min(ans, A.at(i + N - 1) - A.at(i));
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void){
	int a,b;
	scanf("%d %d",&a,&b);
	if(a<b){
	printf("a < b\n",a,b);
	}else if(a>b){
	printf("a > b\n",a,b);
	}else{
	printf("a == b\n",a,b);
	}
	return 0;
}


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

int main(int argc, char **argv)
{
	int x,y,z,m;
	cin >> x >> y >> z;
	
	if ( x > y ){
		m = x ;
		x = y ;
		y = m ;
	}
	if ( y > z ){
		m = y ;
		y = z ;
		z = m ;
	}
	if ( x > y ){
		m = x ;
		x = y ;
		y = m ;
	}
	
	cout << x << " " << y << " " << z << endl;
	return 0;
}

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

int main() {
  int n, a, sum, high;
  cin >> n >> sum;
  high = sum;
  for (int i = 1; i < n; i++) {
    cin >> a;
    sum = sum + a;
    high = max(high, a);
  }
  cout << sum - high / 2 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
typedef long long ll;
int N, M;
int cnt = 0;
int count = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];

int main(void){
  int N, K;
  string S;
  cin >> N >> K;
  cin >> S;
  if(S[K - 1] == 'A'){
    S[K - 1] = 'a';
  }else if(S[K - 1] == 'B'){
    S[K - 1] = 'b';
  }else if(S[K - 1] = 'C'){
    S[K - 1] = 'c';
  }
  cout << S << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define MOD 1000000007
#define all(v) v.begin(),v.end()
#define pb push_back
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[200010];
struct edge{int to,cost;};
int gcd(int a,int b){
	if(b==0)return a;
	return gcd(b,a%b);
}
int lcm(int a,int b){
	return a/gcd(a,b)*b;
}
bool prime(int a){
	if(a==1)return false;
	for(int i=2;i*i<=a;i++){
		if(a%i==0)return false;
	}
	return true;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
	double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
	double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
	double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
	double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
	return tc*td<0&&ta*tb<0;
}
void init_fact(int n){
	kaijo[0]=1;
	for(int i=1;i<=n;i++){
		kaijo[i]=kaijo[i-1]*i;
		kaijo[i]%=MOD;
	}
}
int modpow(int a,int b){
	if(b==0)return 1;
	if(b%2)return modpow(a,b-1)*a%MOD;
	int memo=modpow(a,b/2);
	return memo*memo%MOD;
}
int comb(int a,int b){
	return kaijo[a]*modpow(kaijo[a-b],MOD-2)%MOD*modpow(kaijo[b],MOD-2)%MOD;
}
int inv(int x){
	x=modpow(x,MOD-2);
	return x;
}
int n;
signed main(){
	cin>>n;
	if(n%2==0)cout<<n/2-1<<endl;
	else cout<<n/2<<endl;
	return 0;
}


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

int main()
{
	int n,max=0;
	int vtmp, ctmp;
	int x=0, y=0;
	vector<int> v, c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> vtmp;
		v.push_back(vtmp);
		x += vtmp;
	}
	for (int i = 0; i < n; i++) {
		cin >> ctmp;
		c.push_back(ctmp);
		y += ctmp;
	}
	max = x - y;
	
	for (int i = 0; i < n; i++) {
		if (v[i]<c[i]) {
			max -= v[i] - c[i];
		}
	}
	cout << max << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define int long long
using namespace std;
signed main() {
	int n, k; cin >> n >> k;
	double ans = 0;
	for (int i = 1; i <= n; i++) {
		double d = (double)1 / n;
		int p = i;
		while (p < k) {
			p *= 2;
			d *= 0.5;
		}
		ans += d;
	}
	printf("%.10f\n", ans);
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<stdlib.h>

int main(){
	char S[11];
	int i, j, k, n, *s;
	unsigned long long *dp, sum, *tensq, *terms;
	scanf("%s", S);
	
	n = (int)strlen(S);
	s = (int *)malloc((unsigned int)n*sizeof(int));
	dp = (unsigned long long *)malloc((unsigned int)(n+1)*sizeof(unsigned long long));
	tensq = (unsigned long long *)malloc((unsigned int)(n)*sizeof(unsigned long long));
	terms = (unsigned long long *)malloc((unsigned int)(n)*sizeof(unsigned long long));
	for(i = 0; i < n; i++) s[i] = (int)(S[i]-'0');
	dp[0] = 0;
	tensq[0] = 1;
	for(i = 1; i < n; i++) tensq[i] = 10*tensq[i-1];
	terms[0] = terms[1] = 1;
	for(i = 2; i < n; i++) terms[i] = 2*terms[i-1];
	
	for(i = 0; i < n; i++){
		dp[i+1] = 0;
		for(j = 0; j <= i; j++){
			sum = 0;
			for(k = 0; k <= j; k++){
				sum += tensq[k]*(unsigned long long)s[i-k];
			}
			dp[i+1] += terms[i-j]*sum+dp[i-j];
		}
	}
	
	printf("%lu\n", dp[n]);
	
	return 0;
}


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

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main()
{
    // int data[] = {4, 2, 3, 6, 3, 2, 1, 3, 5, 7};
    int N;
    int i;
    int v[51];
    double half;
    double V[51];
    scanf("%d",&N);
    for(i=0;i<N;i++) scanf("%d",&v[i]);
    qsort(v, N, sizeof(int), compare_int);
    for(i=0;i<N;i++) V[i] = (double)v[i];
    for(i=0;i<N-1;i++){
        // V[i] = (double)v[i];
        half = (V[i] + V[i+1]) / 2.0;
        V[i+1] = half; 
    }
    printf("%lf\n",V[N-1]);
    return 0;
}

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

const int maxN = 3000;
double head_probabilities[maxN] = { 0.0};
double dp[maxN]; 

int main ()
{
    int n;
    cin >> n;
    // dp [i] = total pbility of getting i heads
    dp[0] = 1;
    for (int i = 0; i < n; ++i) {
        cin >> head_probabilities[i];
        for (int j = i + 1; j >= 0; --j) {
            // if (j - 1 >= )
            dp[j] = ((j == 0) ? 0 : dp[j - 1]) * head_probabilities[i] + dp[j] *(1 - head_probabilities[i]);
        }
    }
    double sum = 0;
    for(int i = 0; i <= n; ++i) {
        if (i > n - i) {
            sum += dp[i];
        }
        
        // cout << i << " " << dp[i] << endl;
    }
    
    cout << setprecision(9) << sum << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int a[100001],b[100001];
int main()
{
	int n,m,k;
	cin>>n>>m>>k;
	int small1=10000000,small2=100000000,ans=100000000;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(small1>a[i])
			small1=a[i];
	}
	for(int i=1;i<=m;i++)
	{
		cin>>b[i];
		if(small2>b[i])
			small2=b[i];
	}
	for(int i=1;i<=k;i++)
	{
		int d,e,f;
		cin>>d>>e>>f;
		if(a[d]+b[e]-f<ans)
			ans=a[d]+b[e]-f;
	}
	cout<<min(ans,small1+small2);
	return 0;
}

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

class Main {

  public static void main(String[] args) {
    final FastScanner sc = new FastScanner();
    final PrintWriter writer = new PrintWriter(System.out);
    int val = sc.nextInt() + sc.nextInt() + sc.nextInt();
    writer.println(val >= 22 ? "bust" : "win");
    writer.flush();
    writer.close();
  }

  // FastScanner --
  static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    public FastScanner() {
    }

    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 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 nextDouble() {
      return Double.parseDouble(next());
    }
  }
}

Measured memory_bytes: 23252
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
int main()
{
	int n,m=0;
	cin>>n;
	while(m<n)
	  m+=1000; 
	cout<<m-n<<endl; 
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M,R;
int r[114514];

const int INF=1001001001001001001ll;
int dist[222][222];

signed main(){
    cin>>N>>M>>R;
    rep(i,R)cin>>r[i],r[i]--;

    fill_n(*dist,222*222,INF);
    rep(i,N)dist[i][i]=0;
    rep(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--;b--;
        chmin(dist[a][b],c);
        chmin(dist[b][a],c);
    }
    rep(k,N)rep(i,N)rep(j,N)chmin(dist[i][j],dist[i][k]+dist[k][j]);

    sort(r,r+R);
    int ans=INF;
    do{
        int tmp=0;
        rep(i,R-1)tmp+=dist[r[i]][r[i+1]];
        chmin(ans,tmp);
    }while(next_permutation(r,r+R));
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    if (s == "AAA" || s == "BBB")
        cout << "No"
             << "\n";
    else
        cout << "Yes"
             << "\n";
    return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define reg register
typedef long long ll;
using namespace std;
const int MN=5005;
const int mod=1e9+7;
int to[MN<<1],nxt[MN<<1],h[MN],cnt;
inline void ins(int s,int t){
	to[++cnt]=t;nxt[cnt]=h[s];h[s]=cnt;
	to[++cnt]=s;nxt[cnt]=h[t];h[t]=cnt;
}
int n,f[MN][MN],g[MN],F[MN],siz[MN];
void dfs(int st,int fa=0){
	siz[st]=1;f[st][1]=1;
	for(reg int i=h[st];i;i=nxt[i])
		if(to[i]!=fa){
			dfs(to[i],st);
			for(reg int j=1;j<=siz[st];j++)F[j]=f[st][j],f[st][j]=0;
			for(reg int j=1;j<=siz[st];j++)
				for(reg int k=0;k<=siz[to[i]];k++)
					f[st][j+k]=(f[st][j+k]+1ll*F[j]*f[to[i]][k])%mod;
			siz[st]+=siz[to[i]];
		}
	for(reg int i=1;i<=siz[st];i++)
		f[st][0]=(f[st][0]-1ll*f[st][i]*g[i])%mod;
	f[st][0]=(f[st][0]+mod)%mod;
}
int main(){
	scanf("%d",&n);g[0]=1;
	for(reg int i=1,s,t;i<n;i++)
		scanf("%d%d",&s,&t),ins(s,t);
	for(reg int i=2;i<=n;i+=2)g[i]=1ll*g[i-2]*(i-1)%mod;
	dfs(1);printf("%d\n",mod-f[1][0]);
	return 0;
}

Measured memory_bytes: 97280
def main():
    N = int(input())
    T = list(map(int, input().split()))
    M = int(input())
    Px = [list(map(int, input().split())) for _ in range(M)]
    
    for x in range(M):
        t = 0
        for y in range(N):
            if y + 1 == Px[x][0]:
                t += Px[x][1]
            else:
                t += T[y]
        print(t)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define vpii vector<pair<int,int> >
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back   
#define PB pop_back
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 200005;
const int MOD = 998244353 ;




void solve(){
    int l = 400, r = 599, n, cnt = 8;
    cin>>n;
    while(1){
        if(n >= l && n <= r){
            cout<<cnt;
            return ;
        }
        l += 200;
        r += 200;
        cnt--;
    }
}

int32_t main() {
    fast
    int t;
    t = 1;
    //cin >> t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3648
package main

import (
	"fmt"
	"math"
)

const inf = math.MaxInt64 / 2

func chmin(a *int, b int) {
	if *a > b {
		*a = b
	}
}

func main() {
	var N, W int
	fmt.Scan(&N, &W)
	w, v, maxv := make([]int, N), make([]int, N), 0
	for i := range w {
		fmt.Scan(&w[i], &v[i])
		maxv += v[i]
	}

	dp := make([][]int, N+1)
	for i := range dp {
		dp[i] = make([]int, maxv+1)
		for j := range dp[i] {
			dp[i][j] = inf
		}
	}

	for i := 0; i < N; i++ {
		dp[i][0] = 0
		for sumV := 0; sumV <= maxv; sumV++ {
			if sumV-v[i] >= 0 {
				chmin(&dp[i+1][sumV], dp[i][sumV-v[i]]+w[i])
			}
			chmin(&dp[i+1][sumV], dp[i][sumV])
		}
	}

	ans := 0
	for sumV := 0; sumV <= maxv; sumV++ {
		if dp[N][sumV] <= W {
			ans = sumV
		}
	}

	fmt.Println(ans)
}


Measured memory_bytes: 82176
from collections import Counter

n = int(input())
c = []
for _ in range(n):
    line = list(input())
    c.append(Counter(line))

ansc = c[0]
for i in range(n-1):
    ansc = ansc & c[i+1]

for i in range(97, 97+26):
    if ansc[chr(i)] > 0:
        print(chr(i)*ansc[chr(i)], end="")

Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
string dp[10005];
int cost[200],n,m,arr[500];
string cmp(string x,string y)
{
    if(x.length()<y.length())
        return y;
    if(x.length()>y.length())
        return x;
    return max(x,y);
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cost[1]=2;
    cost[2]=5;
    cost[3]=5;
    cost[4]=4;
    cost[5]=5;
    cost[6]=6;
    cost[7]=3;
    cost[8]=7;
    cost[9]=6;
    string X="-";
    cin>>n>>m;
    for(int i=0; i<m; i++)
    {
        cin>>arr[i];
    }
    for(int i=0; i<=n; i++)
        dp[i]=X;
    dp[0]="";
    for(int i=0; i<=n; i++)
    {
        if(dp[i]==X)
            continue;
        for(int j=0; j<m; j++)
        {
            string z="0";
            z[0]+=arr[j];
            dp[i+cost[arr[j]]]=cmp(dp[i+cost[arr[j]]],dp[i]+z);
        }
    }
    cout<<dp[n]<<endl;





    return 0;
}


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

MOD = 998244353
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            self.tree[i] %= MOD
            i += i & -i

def main():
    n, k = map(int, input().split())
    lr = [list(map(int, input().split())) for _ in range(k)]
    bit = Bit(n + 1)
    bit.add(1, 1)
    for i in range(2, n + 2):
        for l, r in lr:
            plus = bit.sum(i - l) - bit.sum(i - r - 1)
            bit.add(i, plus)
    
    print((bit.sum(n) - bit.sum(n - 1)) % MOD)
    
main()

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

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

        public static void Solve()
        {
            var X = int.Parse(Console.ReadLine());
            Console.WriteLine(X >= 30 ? "Yes" : "No");
        }
    }
}


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

#define ff first
#define ss second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define check(x) cout << #x << " : " << (x) << endl
#define inf LLONG_MAX
#define all(v) v.begin(),v.end() 
#define allr(v) v.rbegin(),v.rend() 
//#define endl '\n'  
#define mod 998244353
typedef  long long ll; 
typedef  unsigned long long ull; 
//using u64 = uint64_t; 
//using u128 = __uint128_t;
typedef vector< ll > edge; 
typedef pair< ll , ll > mypair;
typedef priority_queue <ll> max_heap;
typedef priority_queue <ll, vector<ll>, greater<ll> > min_heap;
const ll N=2000+10;
int main()
{
	boost;
	string s;
	cin>>s;
	ll a,b;
	a=(s[0]-'0')*10+(s[1]-'0');
	b=(s[2]-'0')*10+(s[3]-'0');
	bool m=0,y=0;
	if(a>0  and a<=12) m=1;
	if(b>0 and b<=12) y=1;
	if( m and y) cout<<"AMBIGUOUS";
	else if (m) cout<<"MMYY";
	else if (y) cout<<"YYMM";
	else cout<<"NA";

	return 0;
}

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

#define INF (1 << 29)
#define rep2(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) rep2(i,0,n)
#define EPS 1e-10
#define MOD (1000000007LL)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

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

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n),t(n);
    rep(i,n) cin >> a[i];
    rep(i,n) cin >> t[i];
    vector<ll> lh(n,0),hh(n,1000000001);
    lh[0]=a[0];
    hh[0]=a[0];
    lh[n-1]=max(lh[n-1],t[n-1]);
    hh[n-1]=min(hh[n-1],t[n-1]);
    rep2(i,1,n){
        if(a[i-1]<a[i]){
            lh[i] = max(a[i],lh[i]);;
            hh[i] = min(a[i],hh[i]);
        } else {
            hh[i] = min(a[i],hh[i]);
            lh[i] = max(1LL,lh[i]);
        }
    }
    for(int i=n-2;i>=0;i--){
        if(t[i+1]<t[i]){
            lh[i] = max(t[i],lh[i]);;
            hh[i] = min(t[i],hh[i]);
        } else {
            hh[i] = min(t[i],hh[i]);
            lh[i] = max(1LL,lh[i]);
        }
    }
    ll ans=1;
    rep(i,n){
        ans *= max(hh[i]-lh[i]+1,0LL);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3456
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

void solve(void){
    int k, s;
    cin >> k >> s;
    int ans=0;
    Rep(max(0, s-2*k), min(s, k), x) {
        ans += min(k, s-x) - max(0, s-x-k) + 1;
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 256