akhauriyash/Code-Regression huggingface dataset:
/*===================*\
|ID : harryPotter_421  |
|      LANG: C++       |
\*====================*/
#include <iostream>
#include<bits/stdc++.h>
#define lli long long int
#define ld long double
#define pb push_back
#define M 1000000007
#define ld long double
#define f(j,m,n) for(lli j=m;j<n;j++)
#define harry ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;


int main()
   {harry
    lli n;
    cin>>n;
    ld arr[n+1];
    for(lli i=1;i<=n;i++)
        cin>>arr[i];
    ld dp[n+1][n+1];
    memset(dp,0,sizeof(dp));
    dp[1][1]=arr[1];
    dp[1][0]=1-arr[1];
    ld sum=0.0;
    for(int i=2;i<=n;i++)
        {for(int j=0;j<=i;j++)
             {dp[i][j]=dp[i-1][j]*(1.0-arr[i]);
              if(j>=1)
               dp[i][j]+=dp[i-1][j-1]*arr[i];

             }

        }
    for(int i=n;i>n/2;i--)
        sum+=dp[n][i];
    cout<<fixed<<setprecision(10)<<sum;
    }

















Measured memory_bytes: 140928
while 1:
    n,w = map(int,raw_input().split())
    if n == 0: break
    v = [0]*11
    m = 0
    for i in range(n):
        p = int(raw_input())/w
        v[p] += 1
        m = max(m,p)
    ans = 0.01
    for i in range(m):
        ans += (v[i]*1.0/max(v))*(1-i*1.0/m)
    print ans

Measured memory_bytes: 4252
#include<bits/stdc++.h>
using namespace std;
int main(){
  int t;
  cin>>t;
  	int x=0,w=0,r=0,a=0;
  while(t--){
  	string s;
  	cin>>s;
  
  	if(s=="TLE")
  	x++;
  	else if (s=="AC")
  	a++;
  	else if(s=="WA")
  	w++;
  	else if (s=="RE")
  	r++;
  }
  cout<<"AC x "<<a<<endl;
   cout<<"WA x "<<w<<endl;
    cout<<"TLE x "<<x<<endl;
     cout<<"RE x "<<r<<endl;
     
return 0;
}

Measured memory_bytes: 3628
#include <iostream>

int main() {
    int A, B, K;

    std::cin >> K;
    std::cin >> A >> B;

    for(int i = A; i <= B; i++) {
        if(i % K == 0) {
            std::cout << "OK" << std::endl;
            return 0;
        }
    }

    std::cout << "NG" << std::endl;

    return 0;
}


Measured memory_bytes: 3584
#include <iostream>
#include <cctype>
#include <string>
using namespace std;

int main()
{
    string W, t;
    int n = 0;

    cin >> W;

    while (cin >> t && t != "END_OF_TEXT") {
        for (char &c : t)
            c = tolower(c);
        if (t == W)
            n++;
    }

    cout << n << endl;

    return 0;
}


Measured memory_bytes: 3192
#include <iostream>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 3e2+17;
LL dis[MAXN][MAXN],n;
bool can[MAXN][MAXN];
LL func()
{
	LL ret = 0;
	for (int k = 0; k < n; ++k)
		for (int i = 0; i < n; ++i)
			for (int j = i+1; j < n; ++j)
			{
				if(dis[i][j]>dis[i][k]+dis[k][j]) return -1;
				if(dis[i][j]==dis[i][k]+dis[k][j]&&k!=j&&k!=i)
					can[i][j] = true;
			}
	for (int i = 0; i < n; ++i)
		for (int j = i+1; j < n; ++j)
			if(!can[i][j])
				ret += dis[i][j];
	return ret;
}
int main(int argc ,char const *argv[])
{
	#ifdef noob
	freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
	#endif
	cin>>n;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
		{
			can[i][j] = false;
			cin>>dis[i][j];
		}
	cout<<func()<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>

#include<cmath>
#include<string>
#include <algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;

string lpad(string l,int s,int n){
    string temp = to_string(n);
    string res = "";
    int loop = s - temp.size();
    while(loop--) res+=l;

    return res+temp;
}

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

    string res;
    if(b=="A") res = "T" ;
    if(b=="T") res = "A" ;
    if(b=="G") res = "C" ;
    if(b=="C") res = "G" ;

    p(res)
}

Measured memory_bytes: 256
N=int(input())
B=list(map(int,input().split()))
ans=list()
ans.append(B[0])
for i in range(1,N-1):
	if B[i]>B[i-1]:
		ans.append(B[i-1])
	else:
		ans.append(B[i])
ans.append(B[-1])
print(sum(ans))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x,y,z,k;
    cin >> x >> y >> z >> k;
    long long int a[x],b[y],c[z],d[3000002];
    for(int i=0;i<x;i++)cin >> a[i];
    for(int i=0;i<y;i++)cin >> b[i];
    for(int i=0;i<z;i++)cin >> c[i];
    int count=0;
    //if(x*y*z<=3000){
    //    for(int i=0;i<x;i++)for(int j=0;j<y;j++)for(int l=0;l<z;l++){
    //        d[count]=-a[i]-b[j]-c[l];
    //        count++;
    //    }
    //    sort(d,d+x*y*z);
    //}
    //else{
        long long int e[x*y];
        for(int i=0;i<x;i++)for(int j=0;j<y;j++){
            e[count]=-a[i]-b[j];
            count++;
        }
        sort(e,e+count);
        int count2=0;
        for(int i=0;i<k;i++)for(int l=0;l<z;l++){
            d[count2]=e[i]-c[l];
            count2++;
        }
        sort(d,d+count2);
    //}
    for(int i=0;i<k;i++)cout << -d[i] << endl;
}

Measured memory_bytes: 31488
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
#define rep1(i,n) for(int i=1;i<=int(n);++i)
#define lb(s,x) (lower_bound(all(s),x)-s.begin())
#define ub(s,x) (upper_bound(all(s),x)-s.begin())
#define uniq(a) a.erase(unique(all(a)),a.end())
#define bit(k) (1LL<<(k))
const int INF = 1e9;

#define debug(x) cerr<<(#x)<<": "<<(x)<<endl
template<class T,class U>
ostream& operator<<(ostream& o, const pair<T,U> &p){
    o<<"("<<p.first<<", "<<p.second<<")";
    return o;
}
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }


int main(void){
    int n,k;
    string s;
    cin >> n >> k >> s;
    s[k-1] = tolower(s[k-1]);
    cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String line;
        while (!(line = br.readLine()).equals("0")) {
            int n = Integer.parseInt(line);

            // 累積和配列を用いたアルゴリズムO(n^2)
            int[] s = new int[n + 1];
            for (int i = 1; i <= n; i++) {
                s[i] = Integer.parseInt(br.readLine()) + s[i - 1];
            }
            
            int sum = Integer.MIN_VALUE;
            
            for (int l = 0; l <= n-1; l++) {
                for (int r = l+1; r <= n; r++) {
                    sum = Math.max(sum, s[r] - s[l]);
                }
            }

            System.out.println(sum);
        }

    }
}


Measured memory_bytes: 29464
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
/*
int main(){
    int n,x,y;
    cin>>n>>x>>y;
    x--;
    y--;

    vector<int> cnt(n,0);
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            cnt[min(abs(j-i),min(abs(x-i)+1+abs(j-y),abs(y-i)+1+abs(j-x)))]++;
        }
    }
    for(int i=1;i<n;i++) cout<<cnt[i]<<endl;
}
*/

int main(){
    int n,x,y;
    cin>>n>>x>>y;
    x--;
    y--;
    vector<int> ans(n,0);

    for(int i=0;i<n;i++){
        vector<int> d(n,1e9);
        queue<int> q;
        auto push=[&](int v,int r){
            if(d[v]!=1e9) return;
            d[v]=r;
            q.push(v);
        };
        push(i,0);
        while(!q.empty()){
            int v=q.front();
            q.pop();
            if(v-1>=0) push(v-1,d[v]+1);
            if(v+1<n) push(v+1,d[v]+1);
            if(v==x) push(y,d[v]+1);
            if(v==y) push(x,d[v]+1);
        }
        for(int i=0;i<n;i++) ans[d[i]]++;
    }
    for(int i=1;i<n;i++) cout<<ans[i]/2<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cout << #x << " = " << (x) << endl;
using Graph = vector<vector<int> >;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//#define int long long

void solve() {
	int n, a, b; cin >> n >> a >> b;
    string s; cin >> s;
    int ab = a + b;
    rep(i, n) {
        if(s[i] == 'a' && ab > 0) {
            -- ab;
            cout << "Yes" << endl;
        } else if(s[i] == 'b' && ab > 0 && b > 0) {
            -- b; -- ab;
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//init();
	solve();
	//cout << "finish" << endl;
    return 0;
}

Measured memory_bytes: 848
n, y = map(int, input().split())

if n*10000 == y:
  print(n, 0, 0)
elif n*10000 < y:
  print(-1, -1, -1)
else:
  flag = 0
  #sub = n*10000 - y
  for a in range(y//10000+1):
    b_c = n-a
    for b in range(b_c+1):
      c = b_c-b
      if y == a*10000 + b*5000 + c*1000:
        print(a, b, c)
        flag = 1
        break
    if flag == 1:
      break
  if flag == 0:
    print(-1, -1, -1)

Measured memory_bytes: 9136
import sys
from collections import deque
input = sys.stdin.readline


def main():
    n,k = map(int,input().split())
    s = list(input())

    #tank: '0...0'と'1...1'の塊の数リスト
    #ex. 0001011ならtank = [3,1,1,2] (0が3つ,1が1つ,0が2つ,1が2つ)
    tank = []
    cnt = 1
    for i in range(1,n):
        if s[i] != s[i-1]:
            tank.append(cnt)
            cnt = 0
        cnt += 1
        if i == n-1:
            tank.append(cnt)
    #p:tankの長さ
    p = len(tank)

    #全部1にできてしまう場合
    if s[0] == '0' and (p+1)//2 <= k:
        print(n)
        exit()
    if p//2 <= k and s[0] == '1':
        print(n)
        exit()

    
    ans = 0
    #res:tank[j]が1...1の右端の時の解
    res = 0
    if s[0] == '0':
        for j in range(2*k):
            res += tank[j]
        ans = res
        for j in range(2*k,p):
            if j == 2*k:
                res -= tank[0]
            elif j%2 == 0:
                res= res - tank[j-2*k] -tank[j-2*k-1]
            res += tank[j]
            ans = max(ans,res)

    else:
        for j in range(2*k+1):
            res += tank[j]
        ans = res
        for j in range(2*k+1,p):
            if j % 2 == 1:
                res = res- tank[j-2*k-1]-tank[j-2*k]
            res += tank[j]
            ans = max(ans,res)

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 5028
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    String a = sc.next();
    String b = sc.next();
    String c = sc.next();

    if ((a.charAt(a.length() - 1) == b.charAt(0)) && (b.charAt(b.length() - 1) == c.charAt(0))) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 35588
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    auto S = sread();
    long[string] D;
    foreach (i; 0 .. N)
    {
        auto K = D.keys;
        foreach (key; K)
        {
            if (key.length == 3)
                continue;
            D[key ~ S[i]] = 1;
        }
        D[S[i .. i + 1]] = 1;
    }
    writeln(D.keys.filter!"a.length == 3"().map!"1"().sum());
}


Measured memory_bytes: 8712
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <math.h>
#include <stdlib.h>
#include <algorithm>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

using Graph = vector<vector<pair<int, int>>>;

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

//INT_MAX	2,147,483,647 = 2*1.0e9

vector<int> paint;

void dfs(Graph& _g, int _v, int _p, int _c){
  paint[_v] = _c;

  for(auto np : _g[_v]){
    int nv = np.first;
    int nw = np.second;
    if(nv == _p) continue;

    if(nw%2 ==0){
      dfs(_g, nv, _v, _c);
    } else {
      dfs(_g, nv, _v, 1-_c);
    }
  }
}


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

  Graph g(N);
  for(int i = 0; i < N-1; i++){
    int u, v, w; cin >> u >> v >> w;
    u--; v--;
    g[u].push_back(make_pair(v, w));
    g[v].push_back(make_pair(u, w));
  }
  
  paint.assign(N, -1);

  dfs(g, 1, -1, 0);

  for(int i = 0; i < N; i++){
    cout << paint[i] << endl;
  }

  return 0;
}



Measured memory_bytes: 9984
#include<bits/stdc++.h>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define mp make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
bool f[4];
int main(){
	int a,b;
	cin>>a>>b;
	f[a]=f[b]=true;
	rep(i,3)
	if(!f[i+1])
	cout<<i+1;
	re 0;
}


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

using namespace std;
int N, M;
vector<int> h, w;

int sum(vector<int>& v, int i, int j) {
  int res = 0;
  for (int k = i; k <= j; k++) res += v[k];
  return res;
}

void makeWidthMap(map<int, int>& result, vector<int> v) {
  for (int i = 0; i < v.size(); ++i) {
    for (int j = i; j < v.size(); ++j) {
      result[sum(v, i, j)]++;
    }
  }   
}

int solve() {
  map<int, int> x, y;
  makeWidthMap(y, h);
  makeWidthMap(x, w);

  int count = 0;
  for (auto p : x) {
    auto key = p.first;
    count += p.second * y[key];
  }

  return count;
}

int main() {
  while(cin >> N >> M, N | M) {
    h = vector<int>(N);
    w = vector<int>(M);
    rep(i, N) cin >> h[i];
    rep(i, M) cin >> w[i];
    
    cout << solve() << endl;
  }
  return 0;
}


Measured memory_bytes: 33984
n = int(input())
ans = 0


def num2alpha(num):
    if num <= 26:
        return chr(96+num)
    elif num % 26 == 0:
        return num2alpha(num//26-1)+chr(122)
    else:
        return num2alpha(num//26)+chr(96+num % 26)


print(num2alpha(n))

Measured memory_bytes: 9176
#include <iostream>
#include <string>
using namespace std;
int main(){
  int M, N;
  int tmp=0,ans=0;
  cin >> N >> M;
  char A[N+1][N+1], B[M+1][M+1];
  for(int i=1;i<=N;i++){
    for(int j=1;j<=N;j++){
      cin >> A[i][j];
    }
  }
  for(int i=1;i<=M;i++){
    for(int j=1;j<=M;j++){
      cin >> B[i][j];
    }
  }
  
  for(int i=1;i<=N-M+1;i++){
    for(int j=1;j<=N-M+1;j++){
      tmp = 1;
      for(int k=1;k<=M;k++){
        for(int l=1;l<=M;l++){
          if(A[i+k-1][j+l-1] == B[k][l]){
          }else tmp = 0;          
        }
      }
      if(tmp == 1)ans = 1;
    }
  }
  
  if(ans == 1)cout << "Yes" << endl;
  else cout << "No" << endl;      
  return 0;
}


Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)

a=[]

n.times do
  a << gets.split.map(&:to_i)
end

b=[]
m.times do
  b << gets.to_i
end

a.each do |l|
  puts l.zip(b).inject(0){|s,i| s + i[0]*i[1]}
end

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

int main()
{
  int n;
  cin>>n;
  int flag=0,cnt=0;
  while(n--)
  {
    int x,y;
    cin>>x>>y;
    if(x==y)
    {
      cnt++;
      if(cnt==3)
        flag=1;
    }
    else
      cnt=0;
  }
  if(flag==1)
    cout<<"Yes\n";
  else
    cout<<"No\n";
  return 0;
}
    

Measured memory_bytes: 3128
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)

int main() {
    int n,c,m,ans=0;
    scanf("%d %d %d", &n,&m,&c);
    int b[m];
    int a[n][m];
    REP(i,m) scanf("%d",&b[i]);
    REP(i,n) REP(j,m) scanf("%d",&a[i][j]);
    REP(i,n) {
        int tmp =c;
        REP(j,m) {
            tmp+=a[i][j]*b[j];
        }
        if(tmp>0) ans++;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
import math
Num = 1000000007
N,K = map(int,input().split())

def conbinations_count(n, r):
    if n<0 or r<0 or n-r<0:
        return 0
    else:
        return math.factorial(n) // (math.factorial(n - r)*math.factorial(r))


for i in range(1,K+1):
    tmp = conbinations_count(N-K+1,i)*conbinations_count(K-1,i-1)
    print(tmp%Num)

Measured memory_bytes: 3316
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[200001];
	long long int i, j;
	long long int num1=0,num2=0;
	long long int max = 0;
	long long int length;
	scanf("%s", s);
	length = strlen(s);
	for (i = 0; i<length-1; i++)
	{
		if (s[i] == 'A') 
		{
			num1 = i;
			break;
		}
	}
	for (j = length - 1; j >= 0; j--)
	{
		if (s[j] == 'Z')
		{
			num2 = j;
			break;
		}
	}
	max = num2 - num1 + 1;
    printf("%lld\n", max);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize ("O2,unroll-loops")
//#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef pair<ll, ll> pll;
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
#define debugp(x) cerr<<#x<<"= {"<<(x.first)<<", "<<(x.second)<<"}"<<endl;
#define debug2(x, y) cerr<<"{"<<#x<<", "<<#y<<"} = {"<<(x)<<", "<<(y)<<"}"<<endl;
#define debugv(v) {cerr<<#v<<" : ";for (auto x:v) cerr<<x<<' ';cerr<<endl;}
#define all(x) x.begin(), x.end()
#define pb push_back
#define kill(x) return cout<<x<<'\n', 0;

const ld eps=1e-7;
const int inf=1000000010;
const ll INF=10000000000000010LL;
const int mod=1000000007;
const int MAXN=(1<<18), N=51, LOG=18;

ll n, m, k, u, v, x, y, S, T, ST, a, b, ans;
int A[N];
ll C[N][N];
int cnt[N], ted[MAXN];

void SOS(short* A){
	for (int j=0; j<LOG; j++)
		for (int i=0; i<MAXN; i++)
			if (i&(1<<j)) A[i]+=A[i^(1<<j)];
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	for (int i=0; i<N; i++){
		C[i][0]=C[i][i]=1;
		for (int j=1; j<i; j++) C[i][j]=C[i-1][j] + C[i-1][j-1];
	}
	cin>>n>>k>>S>>T;
	if ((S|T)!=T) kill(0)
	ST=S^T;
	for (int i=1; i<=n; i++){
		cin>>A[i];
		if ((A[i]|T)!=T || (A[i]&S)!=S){
			n--;
			i--;
			continue ;
		}
		A[i]&=ST;
	}
	for (int i=1; i<=k; i++) ans+=C[n][i];
	for (int mask=1; mask<MAXN; mask++) if ((mask|ST)==ST){
		memset(cnt, 0, sizeof(cnt));
		for (int i=1; i<=n; i++) ted[A[i]&mask]++;
		
		for (int sub=mask; sub; sub=(sub-1)&mask) cnt[ted[sub]]++;
		cnt[ted[0]]++;
		
//		debug(mask)
//		for (int bad=0; bad<=n; bad++) debug2(bad, cnt[bad])
		
		ll sum=0;
		for (int bad=0; bad<=n; bad++){
			for (int i=1; i<=k; i++) sum+=C[bad][i]*cnt[bad];
		}
//		debug2(mask, sum)
//		cerr<<'\n';
		
		if (__builtin_popcount(mask)&1) sum*=-1;
		ans+=sum;
		
		for (int i=1; i<=n; i++) ted[A[i]&mask]--;
	}
	cout<<ans<<'\n';
	
	return 0;
}


Measured memory_bytes: 4716
#include<iostream>
#include<algorithm>
#include<functional>
#include <string>
#include<iomanip>
#include<cstdio>
#include<math.h>
#include<stack>
#include<queue>
#include<cstring>
#include<vector>
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define EREP(i,n) for(int i=(n-1);i>=0;--i)
#define D(n,retu) REP(i,n){cin>>retu[i];}
#define mod 1000000007
#define MIN -93193111451418101
#define INF 931931114518101
using namespace std;
typedef long long int ll;
template<typename T>
void fill_all(T& arr, const T& v) {
	arr = v;
}
template<typename T, typename ARR>
void fill_all(ARR& arr, const T& v) {
	for (auto& i : arr) { fill_all(i, v); }
}
#define MAX_NUM 50
long long comb[MAX_NUM + 1][MAX_NUM + 1];

static void calc_comb()
{
	for (uint32_t i = 0; i <= MAX_NUM; i++) {
		for (uint32_t j = 0; j <= i; j++) {
			if ((j == 0) || (i == j)) {
				comb[i][j] = 1;
			}
			else {
				comb[i][j] = comb[i - 1][j - 1] + comb[i - 1][j];
			}
		}
	}
}

//------------------変数-----------------------//
vector<vector<ll>> way(2001), money(2001);
ll maxa = 0, moto = 0;
ll d[2001][2001];
queue <ll>q;
ll bitmax = 0;
//-------------------関数----------------------//

int main() {
	ll n, m; cin >> n >> m;
	fill_all(d, (ll)INF);
	vector<tuple<ll, ll, ll>> t;
	REP(i, n) { d[i][i] = 0; }
	REP(i, m) {
		ll a, b, c; cin >> a >> b >> c; a--, b--; if (a > b) { swap(a, b); }
		d[a][b] = c;
		d[b][a] = c;
		tuple <ll, ll, ll> tt = make_tuple(a, b, c);
		t.push_back(tt);
	}
	REP(k, n) {
		REP(i, n) {
			REP(j, n) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
	ll cnt = 0;
	ll s = t.size();
	REP(i, s) {
		tuple<ll, ll, ll>tt = t[i];
		if (get<2>(tt) > d[get<0>(tt)][get<1>(tt)]) {
			cnt++;
		}
	}
	cout << cnt << endl;
}

Measured memory_bytes: 31616
# F - Xor Shift

from itertools import chain

N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
assert len(a) == N and len(b) == N

# 直前の要素とのxor (循環)
a_xor = [a[i] ^ a[(i + 1) % N] for i in range(N)]
# 直前の要素とのxor (先頭を除く)
b_xor = [b[i] ^ b[i + 1] for i in range(N - 1)]

# (k,x)が解 ⇔ a_xor[k:]がb_xorと一致, x = b[0] XOR a[k]

def kmp_search(T, P):
    m = len(P)
    matches = []
    pi = compute_prefix_func(P)
    q = 0  # number of characters matched
    for i, t in enumerate(T):
        while q > 0 and P[q] != t:
            q = pi[q]  # next character does not match
        if P[q] == t:
            q += 1     # next character matches
        if q == m:
            matches.append(i - (m - 1))
            q = pi[q]  # look for the next match
    return matches

def compute_prefix_func(P):
    m = len(P)
    pi = [0] * (m + 1)
    k = 0
    for q in range(1, m):
        while k > 0 and P[k] != P[q]:
            k = pi[k]
        if P[k] == P[q]:
            k += 1
        pi[q + 1] = k
    return pi

    # pi : {1,2,...,m} -> {0,1,...,m-1}
    # pi[q] = max {k : k < q and P[:q].endswith(P[:k])}

for k in kmp_search(chain(a_xor, a_xor), b_xor):
    if k < N:
        x = b[0] ^ a[k]
        print(k, x)


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

int main(int argc, char const *argv[])
{
    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;

    int a, b, c;
    int total = 0;
    for (a=0; a<=A; a++)
        for (b=0; b<=B; b++)
            for (c=0; c<=C; c++)
                if (500*a+100*b+50*c == X) total++;

    cout << total << endl;

    return 0;
}


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();
        char[] S = sc.next().toCharArray();
        char[] AL = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
        for(int i = 0; i < S.length; i++) S[i] = (char)(AL[(S[i] - 'A' + n) % AL.length]);
        System.out.println(S);
    }
}


Measured memory_bytes: 21844
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        
        int[] count=new int['z'];
        for(int i:count){
            i=0;
        }
       while(sc.hasNext()){
           
           String s=sc.next();
           s=s.toLowerCase();
           char[] c=s.toCharArray();
           
           
           for(char a:c){
               
              count[a-1]++;
           }
       }
        
    for(int i='a';i<='z';i++){
        
        System.out.println((char) i+" : "+count[i-1]);
    }
        
       
        
       
    }
}



Measured memory_bytes: 26168
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;

/*BigInteger
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/rational.hpp>
namespace xxx = boost::multiprecision;
using Bint = xxx::cpp_int;
using Real = xxx::number<xxx::cpp_dec_float<1024>>;
*/

#define int long long
#define pb(x) push_back(x)
#define m0(x) memset((x), 0LL, sizeof(x))
#define mm(x) memset((x), -1LL, sizeof(x))

//container
#define ALL(x) (x).begin(), (x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#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 UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define PERM(c) \
  sort(ALL(c)); \
  for (bool c##p = 1; c##p; c##p = next_permutation(ALL(c)))

// debug
#define GET_VAR_NAME(variable) #variable
#define test(x) cout << GET_VAR_NAME(x) << " = " << x << endl;

// bit_macro
#define Bit(n) (1LL << (n))
#define Bitset(a, b) (a) |= (1LL << (b))
#define Bitunset(a, b) (a) &= ~(1LL << (b))
#define Bitcheck(a, b) ((((a) >> (b)) & 1LL) == 1LL)
#define Bitcount(a) __builtin_popcountll((a))

//typedef
typedef long long lint;
typedef unsigned long long ull;
typedef complex<long double> Complex;
typedef pair<int, int> P;
typedef tuple<int, int, int> TP;
typedef vector<int> vec;
typedef vector<vec> mat;

//constant
constexpr int INF = (int)1e18;
constexpr int MOD = (int)1e9 + 7;
constexpr double PI = (double)acos(-1);
constexpr double EPS = (double)1e-10;
constexpr int dx[] = {-1, 0, 0, 1, 0, -1, -1, 1, 1};
constexpr int dy[] = {0, -1, 1, 0, 0, 1, -1, 1, -1};

//
template <typename T>
void chmax(T &a, T b) { a = max(a, b); }
template <typename T>
void chmin(T &a, T b) { a = min(a, b); }
//
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();
}

//
struct Accelerate_Cin {
  Accelerate_Cin() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
  };
} Accelerate_Cin;

int N, K;
signed main() {
  cin >> N >> K;

  double ans = 0;
  for (int i = 1; i <= N; i++) {
    double s = 1.0 / N;
    int tmp = i;
    while (tmp < K) {
      tmp *= 2;
      s /= 2.0;
    }
    ans += s;
  }

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


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <functional>
#include <cassert>
#include <utility>
#include <stack>
#include <queue>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a, b)*b;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;
int a[100100],b[100100],c[100100];

int main(){
	cin>>n;
	REP(i,n)
		cin>>a[i];
	sort(a,a+n);
	REP(i,n)
		cin>>b[i];
	sort(b,b+n);
	REP(i,n)
		cin>>c[i];
	sort(c,c+n);
	ll ans=0;
	REP(i,n)
		ans+=(lower_bound(a,a+n,b[i])-begin(a))*(n-(upper_bound(c,c+n,b[i])-begin(c)));
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408
using System;

namespace ITP1 {
	class Program {
		public static void Main() {
			int input;
			int caseNo = 1;
			while (true) {
				input = int.Parse(Console.ReadLine());
				if (input != 0) Console.WriteLine("Case " + caseNo++ + ": " + input);
				else break;
			}
		}
	}
}



Measured memory_bytes: 9368
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

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

void run(void){
  int n;
  scanf("%d",&n);
  int l[200];
  int i;
  for(i=0;i<2*n;i++) scanf("%d",l+i);
  qsort(l,2*n,sizeof(int),cmp);
  int ans=0;
  for(i=0;i<2*n;i+=2) ans+=l[i];
  printf("%d\n",ans);
}

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

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<pair<ll,ll>> vp;
#define rep(i,n) for(ll i = 0; i < ll(n); i++)
#define reep(i,n) for(ll i = n; i >-1; i--)
#define deb(variable) cout<<#variable<<"="<<variable<<endl
#define MMOD(i) ((i%MOD)+MOD)%MOD;
#define vec(i,j) vector<vector<ll>>(i,vector<ll>(j,0))
const ll INF=99999999999999999;
const ll MOD=1000000007;
const ll MAX_N=500010;
ll a,b,c,d,e,x,y,z,k,m,n,l,q,t,ans=0;
vl v,v1,v2,kaijo,gysku;//v1,v
vp p,p2,pa;
ll solve(void){
    a=0;
}
int main(){
    cin>>n;
 
    
    cout<<(n-2)*180<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, L;
  cin >> N >> L;
  int sum = 0;
  int min_abs = 1000;
  int value;
  for (int i = 0; i < N; i++) {
    sum += L + i;
    if (abs(L + i) < min_abs) {
      min_abs = abs(L + i);
      value = L + i;
    }
  }
  cout << sum - value << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define ull unsigned long long
#define ld long double
#define pii pair <int, int>
#define pll pair <ll, ll>
#define pci pair <char, int>
#define pld pair <ld, ld>
#define ppld pair <pld, pld>
#define ppll pair <pll, pll>
#define pldl pair <ld, ll>
#define vll vector <ll>
#define vvll vector <vll>
#define vpll vector <pll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define mll map <ll, ll>
#define fastmap gp_hash_table
#define cd complex <double>
#define vcd vector <cd>
#define PI 3.14159265358979
#pragma 03
using namespace std;
using namespace __gnu_pbds;
// chctxdy
ll mod = 1e9 + 7;
mll m;
ll n;
ll calc(ll x){
	if (m.count(x)) return m[x]; if (x == 0) return m[x] = 1; if (x == 1) return m[x] = 2;
	return m[x] = ((calc(x / 2) + calc((x - 1) / 2)) % mod + calc((x - 2) / 2)) % mod;
}
int main(){
    cin >> n; cout << calc(n);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[101];
	int k,len,i;
	scanf("%d %s",&k,s);
	len=strlen(s);
	if(len<=k){
		printf("%s\n",s);
	}
	else{
		for(i=0;i<k;i++){
			printf("%c",s[i]);
		}
		printf("...\n");
	}
	return 0;
}
	
	

Measured memory_bytes: 1624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define rng(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define pb push_back
#define eb emplace_back
#define bg begin()
#define ed end()
#define all(x) x.bg,x.ed

int main() {
  ll n, k;
  //string s;
  cin >> n >> k;
  cout << min(n % k, -(n % k - k)) << endl;
}

Measured memory_bytes: 256
def main():
	n,q = map(int,input().split())
	rt = [[] for _ in range(n)]
	point = [0 for _ in range(n)]
	used = [False for _ in range(n)]
	ans = [0 for _ in range(n)]
	for _ in range(n-1):
		temp, temp2 = map(int, input().split())
		temp -= 1
		temp2 -= 1
		rt[temp2] = rt[temp2] + [temp]
	for _ in range(q):
		temp, temp2 = map(int,input().split())
		temp -= 1
		point[temp] += temp2
	def u(x):
		for i in rt[x]:
			if not(used[i]):
				ref = u(i)
				ans[x] += ref
			else:
				ans[x] += ans[i]
		ans[x] += point[x]
		used[x] = True
		return ans[x]
	for i in range(n):
		ref = u(i)
		print(str(ans[i]) + ("\n" if i == n-1 else " "), end= "")

main()

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL<<30)
#define LLINF (1LL<<60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

#define MAX_N 200000

class UnionFind {
private:
  // 親と木の深さ
  int par[MAX_N];
  int rank[MAX_N];
  int s[MAX_N];
public:
  void init(int n);
  int find(int x);
  void unite(int x, int y);
  bool same(int x, int y);
  int size(int n);
};

// 要素数nで初期化
void UnionFind::init (int n) {
  for(int i=0; i<n; i++) {
    par[i] = i;
    rank[i] = 0;
    s[i] = 1;
  }
}

// 要素xの親を求める
int UnionFind::find(int x) {
  if(par[x] == x) return x;
  else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void UnionFind::unite(int x, int y) {
  // xとyの親
  x = find(x);
  y = find(y);
  if(x == y) return;

  // yのほうが深さが深い　xの親はyの親
  if(rank[x] < rank[y]) {
    par[x] = y;
    s[y] = s[x] + s[y];
  }
  else {
    par[y] = x;
    s[x] = s[x] + s[y];
    if( rank[x] == rank[y] ) rank[x]++;
  }
}

// xとyが同じ集合に属するか
bool UnionFind::same(int x, int y) { return find(x) == find(y);}

int UnionFind::size(int n) {return s[find(n)];}

UnionFind b;
VI a[100010];
signed main(void)
{
  int n, m;
  cin >> n >> m;
  REP(i, n) {
    int k;
    cin >> k;
    REP(j, k) {
      int l;
      cin >> l;
      a[l].push_back(i);
    }
  }

  b.init(n+5);
  FOR(i, 1, m+1) {
    //cout << "i:" << i << endl;
    REP(j, a[i].size()-1) {
      //cout << a[i][j] << " " << a[i][j+1] << endl;
      b.unite(a[i][j], a[i][j+1]);
    }
  }
  //REP(i, n) cout << b.size(i) << " "; cout << endl;
  if(b.size(0) == n) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 6272
#include <bits/stdc++.h>
#include <stdio.h>
#include <ios>     
#include <iomanip> 

using namespace std;
#define inputInt(a) int a; cin >> a; 
#define inputInt2(a,b) int a; int b; cin >> a >> b; 
#define inputInt3(a,b,c) int a; int b; int c; cin >> a >> b >> c;
#define inputLong(a) long a;cin >> a; 
#define inputIntArray(a,N) int a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputLongArray(a,N) long a[N];for(int i=0;i<N;i++){cin >> a[i];}
#define inputIntArray2(a,b,N) int a[N]; int b[N]; for(int i=0;i<N;i++){cin >> a[i] >> b[i];}
#define output(answer) cout << answer << endl;
#define fN(i,N)    for(int i=0; i<N; i++)
#define fSE(i,s,e) for(int i=s; i<=e; i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main()
{
  //input
  int N, L;
  cin >> N >> L;

  //main
  int sum = (L + L+N-1)*N/2;
  
  int minabs = 1e9;
  int eaten = 0;
  for(int i=0; i<N; i++){
    if(chmin(minabs, abs(L+i))){
      eaten = L+i; 
    }
  }
  
  // output
  cout << sum-eaten << endl;
  
  return 0;
}

Measured memory_bytes: 256
a,b,c,d,e,f,v,w,s,t;I(x,y){float o,p,q;a-=x,b-=y;c-=x,d-=y;e-=x,f-=y;o=1.*a*d-1.*b*c;p=1.*c*f-1.*d*e;q=1.*e*b-1.*f*a;return o*p>0&&p*q>0;}main(i){scanf("%*d");for(;~scanf("%d%d%d%d%d%d%d%d%d%d",&a,&b,&c,&d,&e,&f,&v,&w,&s,&t);){i=I(v,w);puts(i^I(s-v,t-w)?"OK":"NG");}}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int X[1000000], LL[1000000];
void margesort(int a[], int a_len, int left, int right);

int main() {

	int n;
	cin >> n;
	int i;
	for (i = 0; i < n; i++) {
		cin >> X[i] >> LL[i];
		X[i] = X[i] + LL[i];
	}
	margesort(X, n, 0, n - 1);
	int rcounter = 1;
	
	int rightmost = X[0];

	for (i = 1; i < n; i++) {
		if (X[i] - 2 * LL[i] >= rightmost) {
			rightmost = X[i];
			rcounter++;
		}
	}

	cout << rcounter << endl;
	return 0;
	//A
	/*
	int h, w, n;
	cin >> h;
	cin >> w;
	cin >> n;

	int max;
	if (h > w) {
		max = h;
	}
	else { max = w; }
	if (n % max == 0) {
		cout << n / max << endl;
	}
	else {
		cout << (n - (n % max)) / max + 1 << endl;
	}
	return 0;*/

}



int temp[1000000];
int tempb[1000000];

void margesort(int a[], int a_len, int left, int right)
{
	int i, j, mid, L, R;

	if (right <= left)
		return;

	mid = (left + right) / 2;
	margesort(a, mid, left, mid);
	margesort(a, a_len - mid, mid + 1, right);

	for (i = left; i <= mid; i++){
		temp[i] = a[i];
		tempb[i] = LL[i];
	}
	for (i = mid + 1, j = right; i <= right; i++, j--) {
		temp[i] = a[j];
		tempb[i] = LL[j];
	}

	L = left;
	R = right;

	for (i = left; i <= right; i++)
	{
		if (temp[L] <= temp[R])
		{
			a[i] = temp[L];
			LL[i] = tempb[L];
			L++;
		}
		else
		{
			a[i] = temp[R];
			LL[i] = tempb[R];
			R--;
		}
	}
}



Measured memory_bytes: 10880
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <complex>
 
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <cstdio>
#include <cstring>
 
#define REP(i,e) for(int i=0;i<(int)(e);i++)
#define FOR(i,b,e) for(int i=(int)(b);i<(int)(e);i++)
#define ALL(c) (c).begin(), (c).end()
#define EACH(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define RALL(c) (c).rbegin(), (c).rend()
#define ALLA(a,n) ((a)+0), ((a)+n)
 
using namespace std;
 
typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef vector<string> vstring;
typedef vector<double> vdouble;
 
template<class T>void pp(T v,int n){ REP(i,n)cout<<v[i]<< ' ' ; cout << endl; }
template<class T>void pp(T v){ EACH(it,v) cout << *it << ' ' ; cout << endl;  }
template<class T>T& ls(T& a,T b){ if(b<a) a=b; return a; }
template<class T>T& gs(T& a,T b){ if(b>a) a=b; return a; }
inline ll to_i(const string& s){ll n;sscanf(s.c_str(),"%lld",&n);return n;}
inline string to_s(ll n){char buf[32];sprintf(buf,"%lld",n);return string(buf);}

inline void write_bool(bool b, const string &tval, const string &fval) {
  cout << (b ? tval : fval) << endl;
} 
inline void YESNO(bool b) { return write_bool(b, "YES", "NO"); }
inline void YesNo(bool b) { return write_bool(b, "Yes", "No"); }
inline void yesno(bool b) { return write_bool(b, "yes", "no"); }

int main() {
  int n;
  while (cin >> n) {
    vint a(n+1), b(n);
    REP(i,n+1) cin >> a[i];
    REP(i,n) cin >> b[i];

    ll result = 0;
    for (int i = n-1; i >= 0; --i) {
      int t = min(b[i], a[i+1]);
      result += t; b[i] -= t; a[i+1] -= t;

      t = min(b[i], a[i]);
      result += t; b[i] -= t; a[i] -= t;
    }

    cout << result << endl;
  }
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int a[3],b[3][3],c[3][3];
int main(){
    for(int i=0;i<3;++i){
        for(int j=0;j<3;++j){
            cin>>c[i][j];
        }
    }
    for(a[0]=0;a[0]<=100;++a[0]){
        for(a[1]=0;a[1]<=100;++a[1]){
            for(a[2]=0;a[2]<=100;++a[2]){
                for(int i=0;i<3;++i){
                    for(int j=0;j<3;++j){
                        b[j][i]=c[i][j]-a[i];
                    }
                }
                bool ok=true;
                for(int i=0;i<3;++i){
                    for(int j=1;j<3;++j){
                        if(b[i][j]!=b[i][0]){
                            ok=false;
                        }
                    }
                }
                if(ok){
                    cout<<"Yes"<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <utility>
typedef long long ll;
using namespace std;

int main(){
  ll i,j,k,n,m;
  string s;
  cin >> n >> k;
  cin >> s;
  s[k-1]-='A'-'a';
  cout << s<< endl;;
  return 0;
}


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

using namespace std;
const int MXN = 1e5 + 5;

int h[MXN];
int dp[MXN];

int main(){
    int n , m;
    scanf("%d %d",&n,&m);
    for(int i = 1 ; i <= n ; i++){
        scanf("%d",&h[i]);
    }
    fill(dp , dp + MXN , (int)1e9 + 7);
    dp[1] = 0;
    for(int i = 2 ; i <= n ; i++){
        for(int j = i - 1 ; j >= max(1 , i - m) ; j--){
            dp[i] = min(dp[i] , dp[j] + abs(h[i] - h[j]));
        }
    }
    // for(int i = 1 ; i <= n ; i++){
    //     printf("%d ",dp[i]);
    // }
    printf("%d",dp[n]);
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;
using ll = long long;

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)

int main(){
    int n;
    ll c;
    cin >> n >> c;
    
    vector<ll> x(n),v(n);
    vector<ll> left(n),right(n);
    vector<ll> g_left(n),g_right(n);
    ll ans = 0;

    rep(i,n){
        cin >> x[i] >> v[i];
    }
    right[0] = v[0];
    reps(i,1,n){
        right[i] += (v[i] + right[i-1]);
    }
    left[n-1] = v[n-1];
    for(int j = n-2; j >= 0; j--){
        left[j] += (v[j]  + left[j+1]);
    }

    g_right[0] = max(g_right[0],v[0] - x[0]);
    reps(i,1,n){
        g_right[i] = max(g_right[i-1], right[i] - x[i]);
    }

    if(v[n-1] - (c-x[n-1]) > 0) g_left[n-1] = v[n-1] - (c- x[n-1]);
    for(int j = n-2; j >= 0; j--){
        g_left[j] = max(g_left[j+1] , left[j] - (c- x[j]) );
    }

    rep(i,n){
        ans = max(ans,g_right[i]);
        ans = max(ans,g_left[i]);
    }

    rep(i,n-1){
        if(ans < right[i] + g_left[i+1] - 2* x[i]){
            ans = max(ans,right[i] + g_left[i+1] - 2* x[i]);
        }
    }

    for(int j = n-1; j > 0; j--){
        if(ans < max(ans,left[j] + g_right[j-1] - 2*(c- x[j]) )){
            ans = max(ans,left[j] + g_right[j-1] - 2*(c- x[j]) );
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
char buf[10000000],out[11];
sz;
cnt[60];
main()
{
	read(0,buf,10000000);
	while(buf[sz++]>='0');
	long N=0;
	for(;buf[sz]>='0';N++)
	{
		long A=0;
		for(;;)
		{
			char k=buf[sz++];
			if(k<'0')break;
			A=A*10+k-'0';
		}
		for(int i=0;A;i++)
		{
			cnt[i]+=A&1;
			A>>=1;
		}
	}
	int ans=0;
	for(int i=59;i>=0;i--)
	{
		ans=(ans*2+(N-cnt[i])*cnt[i])%1000000007;
	}
	int outsz=10;
	do{
		out[--outsz]=ans%10+'0';
	}while(ans/=10);
	write(1,out+outsz,10-outsz);
}

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

// chmin, chmax関数

template<typename T, typename U, typename Comp=less<>>
bool chmax(T& xmax, const U& x, Comp comp={}) {
    if(comp(xmax, x)) {
        xmax = x;
        return true;
    }
    return false;
}

template<typename T, typename U, typename Comp=less<>>
bool chmin(T& xmin, const U& x, Comp comp={}) {
    if(comp(x, xmin)) {
        xmin = x;
        return true;
    }
    return false;
}


int main(){
    int a,b,c,d,e,f;
    cin >> a >> b >> c >> d >> e >> f;
    a *= 100; b *= 100;

    double max_conc = 0.0;
    int SUM = 0, SUGAR = 0;

    rep(s, 32){
        rep(t, 32){
            int water = s*a + t*b;
            int max_sugar = water * e / 100;
            
            if(water > f || water == 0) continue;

            int sugar = 0;
            int max_u = max_sugar / c;
            rep(u, max_u + 1){
                sugar = u * c;
                if(water + sugar > f) continue;

                int v = min(f - water - sugar, max_sugar - u*c) / d;
                sugar += v * d;
            
                double conc = (double)(100 * sugar) / (double)(water + sugar);
                if(chmax(max_conc, conc)){
                    SUM = water + sugar;
                    SUGAR = sugar;
                }
            }
        }
    }

    if(SUM == 0) SUM = a;

    cout << SUM << " " << SUGAR << endl;

    return 0;
}

Measured memory_bytes: 256
#include<algorithm>
#include<iostream>
#include<vector>
using namespace std;
#define REP(i, a,b) for(i=a;i<b;i++) 
#define output(x) cout<<x<<endl;

int par[100001];

void init(int n) {
	for (int i = 0; i < n; i++) {
		par[i] = i;
	}
}
//木の根を求める
int root(int x) {
	if (par[x] == x)
		return x;
	else {
		return par[x] = root(par[x]);
	}
}
//find
bool same(int x, int y) {
	return root(x) == root(y);

}
//union
void unite(int x, int y) {
	x = root(x);
	y = root(y);
	if (x == y) return;
	par[x] = y;
}

int main()
{
	int N, M,i,j,k,ans;
	ans = 0;
	cin >> N >> M;
	vector<int>p(N);
	vector<int>x(M);
	vector<int>y(M);
	REP(i, 0, N) {
		cin >> p[i];
	}
	init(N);
	REP(i, 0, M) {
		cin >> x[i] >> y[i];
		unite(x[i], y[i]);
	}
	REP(i, 0, N) {
		if (same(p[i], i + 1))
			ans++;
	}
	output(ans);

    return 0;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(signed i=0;i<n;++i)
#define repi(n) rep(i,n)
#define int long long
#define str string
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define yn(b) cout<<((b)?"Yes":"No")<<endl
#define YN(b) cout<<((b)?"YES":"NO")<<endl
#define call(a) for(auto t:a)cout<<t<<" ";cout<<endl
#define ENDL printf("\n");
#define debg(a) cout<<#a<<":"<<a<<endl;
#define SORT(a) sort(all(a));
#define INF 1LL<<60

signed main(){
  int n;
  cin>>n;
  vint a(n);
  repi(n)cin>>a[i];
  int res=0,odd=0,eve=0,even=0;
  repi(n){
    if(a[i]%4==0)eve++;
    else if(a[i]%2==0)even++;
    else odd++;
  }
  bool ans=(eve>=odd-1+(even>0)||odd==0);
  yn(ans);
  
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main() {
	int N,ans=0;
	cin >> N;
	map<int, int>U;
	vector<int>A(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> A.at(i);
		U[A.at(i)] = U[A.at(i)] + 1;
	}
	for (size_t i = 0; i < N; i++)
	{
		if (U[A.at(i)] && U[A.at(i)] - A.at(i) != 0) {
			if (U[A.at(i)] < A.at(i)) {
				ans += U[A.at(i)];
				U[A.at(i)] = 0;
			}
			else {
				ans += U[A.at(i)] - A.at(i);
				U[A.at(i)] = A.at(i);
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 5120
n,m = map(int,input().split())
s = []
c = []
ans = [1]
for i in range(n-1):
    ans.append("0")
ANS = ""

for i in range(m):
    S,C = map(int,input().split())
    s.append(S)
    c.append(C)
    
for i in range(m):
    ans[s[i]-1] = c[i]
    
    if i == m-1:
        for j in range(n):
            ANS += str(ans[j])
            
for i in range(m):
    if s[i] == 1 and c[i]==0 and n!=1:
        ANS = -1
    
    for j in range(m):
        if s[i] == s[j] and c[i] != c[j]:
            ANS = -1
            
if m == 0:
    if n == 1:
        ANS = 0
    else:
        ANS = "1"+"0"*(n-1)
            
print(ANS)

Measured memory_bytes: 3192
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		//    	File file = new File("src/in.txt");
		//    	Scanner sc = new Scanner(file);

		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		boolean res = false;

		for(int i=1;i<10;i++) {
			for(int j=1;j<10;j++) {
				if(i*j==N) {
					res = true;
				}
			}
		}
		if(res) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22996