akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

void AGC039B()
{
	int N;
	cin >> N;
	vvi graph(N);
	for (int i = 0; i < N; ++i)
	{
		string S;
		cin >> S;
		for (int j = 0; j < N; ++j)
		{
			if (S[j] == '1')
			{
				graph[i].push_back(j);
			}
		}
	}

	int maxDist = 0;
	for (int i = 0; i < N; ++i)
	{
		queue<int> qu;
		vi dist(N);
		vi used(N);
		qu.push(i);
		int d = 1;
		dist[i] = 1;
		used[i] = 1;
		while (!qu.empty())
		{
			int x = qu.front(); qu.pop();
			int e = dist[x] + 1;
			for (auto& y : graph[x])
			{
				if (!used[y])
				{
					dist[y] = e;
					used[y] = 1;
					qu.push(y);
					continue;
				}
				if (used[y] == 1 && (e - dist[y]) % 2 == 1)
				{
					cout << -1 << endl;
					return;
				}
			}
		}
		sort(dist.begin(), dist.end());
		maxDist = max(maxDist, dist.back());
	}
	cout << maxDist << endl;
}
int main()
{
	AGC039B();
	return 0;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
import sys

MOD = 1000000007  # type: int


def solve(N: int):
    t = pow(10,N,MOD)- pow(8,N,MOD)
    m = pow(10,N,MOD)- pow(9,N,MOD)
    print((2*m-t)%MOD)
    return


# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


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

const int N = 1e5 + 5;
vector<pair<ll, ll>>adj[N];
void solve() {
	ll n;
	cin >> n;
	vector<pair<ll, ll>>v(n);
	vector<bool>s(n, false);
	for (int i = 0; i < n; i++) {
		cin >> v[i].first >> v[i].second;
		if (v[i].first == v[i].second) {
			s[i] = true;
		}
	}
	bool f = false;
	for (int i = 0; i <= n - 3; i++) {
		if (s[i] && s[i + 1] && s[i + 2]) {
			cout << "Yes"; return;
		}
	}
	cout << "No";
}


int main() {
	int ntc = 1;
	while (ntc--) {
		solve();
	}
}

Measured memory_bytes: 5980
#include <stdio.h>

int main() {
  int X, A, B;
  scanf("%d %d %d", &X, &A, &B);

  int distA = (A < X) ? X - A : A - X;
  int distB = (B < X) ? X - B : B - X;
  (distA < distB) ? puts("A") : puts("B");
  return 0;
}

Measured memory_bytes: 1592
import java.util.*;

public class Main{
	public static void main(String[] args){
		//new Main().printHelloWorld();
		//System.out.println(new Main().ITP1_1_B(Integer.parseInt(new Scanner(System.in).next())));
		//new Main().ITP1_1_C();
		//new Main().ITP1_1_D();
		//new Main().ITP1_2_A();
		//new Main().ITP1_2_B();
		new Main().ITP1_2_C();
	}

	public void printHelloWorld(){
		System.out.println("Hello World");
	}

	public int ITP1_1_B(int x){
		return x*x*x;
	}

	public void ITP1_1_C(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println(a*b + " " + 2*(a+b));
	}

	public void ITP1_1_D(){
		int seconds = new Scanner(System.in).nextInt();
		System.out.println(seconds/3600 + ":" + (seconds%3600)/60 + ":" + (seconds%3600)%60);
	}

	public void ITP1_2_A(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println((a==b)?"a == b":(a > b)?"a > b":"a < b");
	}

	public void ITP1_2_B(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		System.out.println((a < b && b < c)?"Yes":"No");
	}

	public void ITP1_2_C(){
		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();
		for(int i=0;i<a.length-1;i++){
			for(int j=i+1;j<a.length;j++){
				if(a[i] > a[j]){
					int t=a[i];a[i]=a[j];a[j]=t;
				}
			}
		}
		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}
}

Measured memory_bytes: 26344
import itertools
import math
H,W =list(map(int,input().split(" ")))
N = int(input())
As =list(map(int,input().split(" ")))
color = 0
count = 0
ans = [ [0] * W  for _ in range(H)  ]
for h in range(H):
    if h %2 == 0:
        start = 0
        end = W
        step = 1
    else:
        start = W - 1
        end = -1
        step = -1
    for w in range(start,end,step):
        if count == As[color] :
            color += 1
            count = 0
        ans[h][w] = color + 1
        count += 1

for temp in ans:
    print(*temp)

Measured memory_bytes: 3956
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
    int n,k,i,sum=0;
 
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++)
    {
       
       cin>>a[i];
    }


    sort(a,a+n);

   for(i=0;i<k;i++)
   {
       sum += a[i];
   }


cout<<sum;


    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define debug_() cerr << "AAAAA" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;

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

int main()
{
    int a, b, q;
    cin >> a >> b >> q;
    vector<ll> s(a + 2);
    vector<ll> t(b + 2);
    s[0] = -100100100100;
    t[0] = -100100100100;
    s[a + 1] = 1001001001001;
    t[b + 1] = 1001001001001;
    for (int i = 0; i < a; i++)
    {
        cin >> s[i + 1];
    }
    for (int i = 0; i < b; i++)
    {
        cin >> t[i + 1];
    }
    // debug_vec(s);
    // debug_vec(t);

    for (int i = 0; i < q; i++)
    {
        ll x;
        cin >> x;
        auto u = lower_bound(s.begin(), s.end(), x);
        auto v = lower_bound(t.begin(), t.end(), *u);
        auto w = u - 1;
        auto z = lower_bound(t.begin(), t.end(), *w);
        // if (i == q - 1)
        // {
        //     cout << x << " " << *u << " " << *w << " " << *z << " " << *(z - 1) << endl;
        // }
        ll ans1 = min({abs(x - *u) + abs(*u - *v), abs(x - *u) + abs(*u - *(v - 1)),
                       abs(x - *w) + abs(*w - *z), abs(x - *w) + abs(*w - *(z - 1))});

        u = lower_bound(t.begin(), t.end(), x);
        v = lower_bound(s.begin(), s.end(), *u);
        w = u - 1;
        z = lower_bound(s.begin(), s.end(), *w);
        ll ans2 = min({abs(x - *u) + abs(*u - *v), abs(x - *u) + abs(*u - *(v - 1)), abs(x - *w) + abs(*w - *z), abs(x - *w) + abs(*w - *(z - 1))});

        cout << min(ans1, ans2) << endl;
    }

    return 0;
}


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

struct unionfind{
  vector<int> par;
  vector<int> size;
  unionfind(int n):par(n),size(n,1){
    rep(i,n)par.at(i)=i;
  }
  int root(int x){
    if(par[x]==x)return x;
    return root(par[x]);
  }
  void unit(int x,int y){
    x=root(x);y=root(y);
    if(x==y)return;
    if(size[par[x]]<size[par[y]])swap(x,y);
    size[x]+=size[y];
    par[y]=x;
  }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n,m;cin>>n>>m;
  unionfind uf(n);
  rep(i,m){
    int x,y,z;cin>>x>>y>>z;
    uf.unit(x,y);
  }
  set<int> st;
  rep(i,n)st.insert(uf.root(i));
  cout<<st.size()<<endl;
  return 0;
  }


Measured memory_bytes: 5760
import sys

a, b, c = [list(input()) for _ in range(3)]

def A():
    if a == []:
        print("A")
        sys.exit()
    else:
        p = a.pop(0)
        if p == "a":
            A()
        elif p == "b":
            B()
        else:
            C()
            
def B():
    if b == []:
        print("B")
        sys.exit()
    else:
        p = b.pop(0)
        if p == "a":
            A()
        elif p == "b":
            B()
        else:
            C()
            
def C():
    if c == []:
        print("C")
        sys.exit()
    else:
        p = c.pop(0)
        if p == "a":
            A()
        elif p == "b":
            B()
        else:
            C()
            
A()

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


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

    ll ans = 0;
    int next_w_pos = 0;
    rep(i, S.size()) {
        if (S[i] == 'W') {
            ans += i - next_w_pos;
            next_w_pos++;
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 640
s=input()
a=int(s[:2])
b=int(s[2:])
if 0 < a <= 12 and 0 < b <= 12:
  print('AMBIGUOUS')
elif 0 < a <= 12:
  print('MMYY')
elif 0 < b <= 12 :
  print('YYMM')
else :
  print('NA')
  

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define erep(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define INF 1e9
const int mod = 1e9+7;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
  int n,l;
  cin >> n >> l;
  vs s(n);
  rep(i, 0, n) cin >> s[i];
  sort(all(s));
  string ans = "";
  rep(i, 0, n) ans += s[i];
  cout << ans << endl;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))

def is_cuttable(N):
    n = 0
    for a in A:
        i = a // N
        if a % N == 0:
            i -= 1
        n += int(i)
        if n > K:
            return False
    return True

n_max = 10 ** 10
n_min = 0

while n_max - n_min > 1:
    n = (n_max + n_min) // 2
    if is_cuttable(n):
        n_max = n
    else:
        n_min = n
    
print(n_max)

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

int main() {
  vector<vector<int>> a(3,vector<int>(3));
  rep(i,3)rep(j,3)cin>>a[i][j];
  int n;cin>>n;
  rep(i,n){
    int b;cin>>b;
    rep(j,3)rep(k,3){
      if(b==a[j][k])a[j][k]=0;
    }
  }
  bool ans=false;
  rep(i,3){
    if(a[i][0]==0&&a[i][1]==0&&a[i][2]==0)ans=true;
  }
  rep(i,3){
    if(a[0][i]==0&&a[1][i]==0&&a[2][i]==0)ans=true;
  }
  if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0)ans=true;
  if(a[0][2]==0&&a[1][1]==0&&a[2][0]==0)ans=true;
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 3632
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
    	
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int N = sc.nextInt();
		long ans = 0;

		// Mapの宣言
        Map<String, Integer> mMap = new HashMap<String, Integer>();
		// Mapの宣言
        Map<String, Integer> mstr = new HashMap<String, Integer>();
        
		for (int i = 0; i < N;i ++ ){
			// 文字列の入力
			String str = sc.next();

			String[] strArray = str.split("");
			 
//			// ソートする
			Arrays.sort(strArray);
	        String work = "";
			for (int j = 0; j < strArray.length; j++) {
	        	work = work + strArray[j];
			}

	        if(mMap.containsKey(work)){
	        	mMap.put( work,mMap.get(work) + 1);
	        	ans = ans + mMap.get(work);
	        }else {
	        	mMap.put( work,0);
	        }
		}

//        Object[] mapkey = mMap.keySet().toArray();
//        for (Object nKey : mapkey)
//        {
//        	if(mMap.get(nKey)>1) {
//                ans = ans + ( Factorial(mMap.get(nKey)) / 2 * Factorial((mMap.get(nKey) - 2)) );
//        	}
//        }

		
		System.out.println(ans);

   		sc.close();
        return ;

    }
    
    static long Factorial (int i) {
    	if (i == 0) {return 1;}

    	if (i == 1) {
    		return 1;
    	}else {
    		return (i * Factorial(i-1));
    	}
    }
}



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

int main() {

  int a;
  int b;
  int c;
  
  cin >> a;

  b = a % 100 ;
  c = b % 10;
  
  cout << a / 100 + b / 10 + c / 1 << endl;
  
}

Measured memory_bytes: 256
N,P = map(int,input().split())
S = input()

if P in (2,5):
    ans = 0
    for i,c in enumerate(S):
        if int(c)%P==0:
            ans += i+1
    print(ans)
    exit()

mem = [0]
j = 1
for c in S[::-1]:
    mem.append((mem[-1] + int(c)*j) % P)
    j *= 10
    j %= P
from collections import Counter
ctr = Counter(mem)
ans = 0
for v in ctr.values():
    ans += v*(v-1)//2
print(ans)

Measured memory_bytes: 12032
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using P = pair<int,int>;
#define PI 3.141592653589793

double RadianToDegree(double radian){
  return radian * 180.0 / PI;
 }

int main()
{
  double a, b, x;
  cin >> a >> b >> x;
  if(x>=(a*a*b)/2.0){
    cout << fixed << setprecision(10) << RadianToDegree(atan((2.0*a*a*b-2.0*x)/(a*a*a))) << endl;
  }else{
    cout << fixed << setprecision(10) << RadianToDegree(atan((a*b*b)/(2.0*x))) << endl;
  }
}

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

int main() {
#define int long long
    int n;
    cin >> n;

    vector<double> dp(n+1);
    double p_heads,ans=0;
    dp[0]=1;
    for(int i=0;i<n;++i)
    {
        cin >> p_heads;
        for(int j=i+1;j>=0;--j)
        {
            if(j==0)
            {
                dp[j]=dp[j]*(1-p_heads);
            }
            else
            {
                dp[j]=dp[j-1]*p_heads + dp[j]*(1-p_heads);
            }
            
        }
    }

    for(int heads=0; heads<=n; heads++)
    {
        int tails=n-heads;
        if(heads>tails)
        {
            ans+=dp[heads];
        }
    }

    printf("%.10lf\n",ans);
}

Measured memory_bytes: 256
/**
 * @author Finn Lidbetter
 */
import java.util.*;
import java.io.*;
import java.awt.geom.*;

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

    int n = Integer.parseInt(br.readLine());
    String[] s = br.readLine().split(" ");
    long sum = 0;
    long[] partials = new long[n];
    for (int i=0; i<n; i++) {
      if (i==0)
        partials[i] = Long.parseLong(s[i]);
      else
        partials[i] = partials[i-1] + Long.parseLong(s[i]);
      
    }
    sum = partials[n-1];
    long minDiff = Long.MAX_VALUE;
    for (int i=0; i<n-1; i++) {
      long diff = Math.abs((sum-partials[i])-partials[i]);
      if (diff<minDiff)
        minDiff = diff;
    }
    System.out.println(minDiff);
  }
}


Measured memory_bytes: 48792
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define rep(i,n)for(int i=0;i<n;i++)
#define int long long
#define ggr getchar();getchar();return 0;
#define prique priority_queue
#define mod 1000000007
#define inf 1e15
using namespace std;
typedef pair<int, int>P;
void yes() { cout << "Yay!" << endl; }
void no() { cout << ":(" << endl; }
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y)* mod_pow(kai(y, y), mod - 2, mod) % mod;
}
struct edge { int to, cost; };
int n, a, b;
signed main() {
	cin >> n >> a >> b;
	n %= 12;
	if (n % 12 == 0)cout << a << " " << b << endl;
	else {
		for (int i = 0; i < n; i++) {
			if (i % 2 == 0)a = a - b;
			else b = a + b;
		}
		cout << a << " " << b << endl;
	}
	ggr
}



Measured memory_bytes: 3124
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#define INT long long
using namespace std;
INT n, a[100010], b[100010], k, ans;
int main()
{
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i = 0 ; i < n ; i++ ) cin>>a[i]>>b[i];
    for(int i = n-1 ; i >= 0 ; i-- )
    {
        INT x = (a[i]+ans)%b[i];
        if( x ) ans+=(b[i]-x);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1920
#include <cstdio>
#include <map>
#define LL long long
using namespace std;
const int N=200005;
int n,a[N];map<LL,LL>mp;
int main()
{
	scanf("%d",&n);
	mp[0]=1;LL sum=0,ans=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=(LL)a[i];ans+=mp[sum];
		mp[sum]++;
	} 
    printf("%lld",ans);
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    ll N, A, B;
    cin >> N >> A >> B;

    vector<ll> X(N);
    rep(i, N) cin >> X[i];

    ll ans = 0;
    rep(i, N - 1) {
        if ((X[i + 1] - X[i]) * A > B) ans += B;
        else ans += (X[i + 1] - X[i]) * A;
    }

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

Measured memory_bytes: 1024
#include<stdio.h>
int main()
{
	int n,i,j=0;
	char s[101],t[101],a[201];

	scanf("%d",&n);
	scanf("%s%s",s,t);
	for(i=0;i<n*2;i+=2){
		a[i]=s[j];
		a[i+1]=t[j];
		a[i+2]='\0';
		j++;
	}
	printf("%s\n",a);
	return 0;
}

Measured memory_bytes: 128
H,W = map(int,input().split())
l=[]
for i in range(H):
    l.append(list(input()))
for i in range(H):
    for count in range(2):
        for j in range(W):
            if j==W-1:
                print(l[i][j])
            else:
                print(l[i][j],end='')


Measured memory_bytes: 4596
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
    string s;
    string t;
    cin >> s;
    cin >> t;
    int count=0;
    if(s[0]==t[0]) count++;
    if(s[1]==t[1]) count++;
    if(s[2]==t[2]) count++;
    cout << count <<endl;
    return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#pragma warning(disable:4996)
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const int mod = 1000000007;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P>PP;
int a[100006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> a[i];
	set<int>S;
	rep(i, n)S.insert(a[i]);
	cout << S.size() << endl;
}


Measured memory_bytes: 8544
import std.stdio;
import std.algorithm;
import std.math;
import core.stdc.stdio;

int[int] compCoord(ref int[] data){
	data.sort;
	int[int] ret;
	int c=0;
	foreach(i,d;data){
		if((d in ret) is null){
			ret[d] = c;
			data[c++] = d;
		}
	}
	data = data[0..c];
	return ret;
}
void main(){
	while(1){

	int w,h;
	scanf("%d%d",&w,&h);
	if(h==0&&w==0)
		break;
	
	int n;
	scanf("%d",&n);
	int size=n*2+2;
	int[] xs = new int[size];
	int[] ys = new int[size];
	struct rect{
		int x1;
		int y1;
		int x2;
		int y2;
	}
	rect[] rs = new rect[n];
	for(int i=0;i<n;i++){
		scanf("%d%d%d%d",&rs[i].x1,&rs[i].y1,&rs[i].x2,&rs[i].y2);
		xs[i*2] = rs[i].x1;
		xs[i*2+1] = rs[i].x2;
		ys[i*2] = rs[i].y1;
		ys[i*2+1] = rs[i].y2;
	}
	xs[n*2] = 0;
	xs[n*2+1] = w;
	ys[n*2] = 0;
	ys[n*2+1] = h;
	
	int[int] xc = xs.compCoord;
	int[int] yc = ys.compCoord;
	
	int[] imos = new int[xs.length*ys.length];
	foreach(r;rs){
		int cx1 = xc[r.x1];
		int cy1 = yc[r.y1];
		int cx2 = xc[r.x2];
		int cy2 = yc[r.y2];
		imos[cy1*xs.length+cx1]++;
		imos[cy1*xs.length+cx2]--;
		imos[cy2*xs.length+cx1]--;
		imos[cy2*xs.length+cx2]++;
	}
	for(int i=0;i<ys.length;i++){
		int last=0;
		for(int j=0;j<xs.length;j++){
			imos[i*xs.length+j]+=last;
			last = imos[i*xs.length+j];
		}
	}
	for(int i=0;i<xs.length;i++){
		int last=0;
		for(int j=0;j<ys.length;j++){
			imos[i+j*xs.length]+=last;
			last = imos[i+j*xs.length];
		}
	}
	int ans=0;
	bool[] visited = new bool[xs.length*ys.length];
	int[] dx = [0,-1,0,1];
	int[] dy = [-1,0,1,0];
	int[2][] queue = new int[2][xs.length*ys.length];
	int BFS(int y,int x){
		if(visited[y*xs.length+x] || imos[y*xs.length+x] != 0)
			return 0;
		int qc=0;
		queue[qc++] = [y,x];
		visited[y*xs.length+x]=true;
		for(int i=0;i<qc;i++){
			int py = queue[i][0];
			int px = queue[i][1];
			for(int k=0;k<4;k++){
				int ny = py+dy[k];
				int nx = px+dx[k];
				if(0<=ny&&ny<ys.length&&ys[ny]<h&&0<=nx&&nx<xs.length&&xs[nx]<w){
					if(!visited[ny*xs.length+nx] && imos[ny*xs.length+nx] == 0){
						queue[qc++] = [ny,nx];
						visited[ny*xs.length+nx]=true;
					}
				}
			}
		}
		return 1;
	}
	for(int i=0;ys[i]<h;i++){
		for(int j=0;xs[j]<w;j++){
			ans += BFS(i,j);
		}
	}
	printf("%d\n",ans);
	
	}
}

Measured memory_bytes: 11004
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//xにはvectorなどのコンテナ
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x)) //最大値を求める
#define MIN(x) *min_element(ALL(x)) //最小値を求める
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
#define MOD 1000000007 //10^9+7:合同式の法
#define MAXR 100000 //10^5:配列の最大のrange(素数列挙などで使用)
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


using namespace std;

int main() {
   
   long long int N;
   cin >> N;
   vector<long long int> L;

   ll c;
   REP(i,N){
      cin >> c;
      L.PB(c);
   }
   sort(ALL(L));
   set<string> st;
   string T;
   int cnt=0;
   for(int i=0;i<N;i++){
      for(int j=i;j<N;j++){
         for(int k=j;k<N;k++){
            if(L[i]+L[j]>L[k] && L[k]+L[j]>L[i] && L[j]+L[k]>L[i] && L[j]!=L[k] && L[i]!=L[k] && L[i]!=L[j]){
               cnt++;
               st.insert(T);
            }
         }
      }
   }

   cout << cnt << endl;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1000000007
#define int int64_t

signed main(){
	char a,b;
	cin>>a>>b;
	int ans=1;
	if(a=='D')ans*=-1;
	if(b=='D')ans*=-1;
	if(ans==1)cout<<'H'<<endl;
	else cout<<'D'<<endl;
}

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

int main()
{
    int sum = 0, count=0;
    string str;
    cin >> str;

    for (int i = 0; i < str.size();  i++)
    {
        if (str.at(i) == 'A' || str.at(i) == 'T' || str.at(i) == 'G' || str.at(i) == 'C' ){
            count++;
        }
        else{
            count=0;
        }
        sum = max(count, sum);
    }


        cout << sum << endl;


}

Measured memory_bytes: 256
// Brijesh Panara (201601074)
// DAIICT (India)
#include <bits/stdc++.h>
#include <time.h>
using namespace std;

#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define FILL(a,b) memset((a),(b),sizeof((a)))
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<ll,vector<ll>,greater<ll> > 
#define maxQueue priority_queue<ll,vector<ll>,less<ll> > 

#define deb1(x) cout<<#x<<" : "<<x<<endl;
#define deb2(x,y) cout<<#x<<" : "<<x<<" "<<#y<<" : "<<y<<endl;
#define deb3(x,y,z) cout<<#x<<" : "<<x<<"   "<<#y<<" : "<<y<<"  "<<#z<<" : "<<z<<endl;

#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define READ freopen("input.txt","r",stdin);
#define WRITE freopen("output.txt","w",stdout);
#define RANDOM srand(time(NULL));

#define MOD 1000000007
#define NAX 1000005
#define INF LONG_LONG_MAX
#define MINF LONG_LONG_MIN


ll solve()
{
    ll x;
    cin>>x;

    ll item = x/100;
    ll rem = x-item*100;

    if(0<=rem && rem<=5*item)
        cout<<1<<"\n";
    else
        cout<<0<<"\n";

    return 0;
}


int main()
{
    FAST;
    
    ll t=1;
    // cin>>t;
    
    while(t--!=0)
    {
        ll stat = solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
long a,b,d,r=0;
double f;

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

d=a/b;
r=a%b;
f=(double)a/(double)b;

printf("%ld %ld %lf\n",d,r,f);
return 0;
}

Measured memory_bytes: 636
import math
N = int(input())
x = []
y = []
for i in range(N):
  xi, yi = map(float, input().split())
  x.append(xi)
  y.append(yi)

l = []
for i in range(N):
  for j in range(i, N):
    li = math.sqrt((x[i] - x[j]) ** 2 + (y[i] - y[j]) ** 2)
    l.append(li)

print(2 * sum(l) / N)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define owo ios_base::sync_with_stdio(0);cin.tie(0);
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define debug(...) fprintf(stderr, __VA_ARGS__),fflush(stderr)
#define time__(d) for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false);\
debug("%s time : %.4fs\n", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> PII;
typedef pair<int,int> pii;
typedef vector<vector<int>> vii;
typedef vector<vector<ll>> VII;
int main()
{
	int n;
	cin>>n;
	vector<ld>dp(n+1,0);
	dp[0] = 1;
	for(int i=0;i<n;i++)
	{
		ld p,q;
		cin>>p;
		q = 1-p;
		for(int j = i+1;j>=0;j--)dp[j] = (j == 0 ? 0:dp[j-1]*p)
		 + dp[j]*q;
	}
	ld ans = 0;
	for(int i=n/2+1;i<=n;i++)ans+=dp[i];
	cout<<fixed<<setprecision(15)<<ans;
}

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


// ABC125B - Resale
// https://atcoder.jp/contests/abc125/tasks/abc125_b
void ABC125B() {
	int N;
	cin >> N;

	vector<int> V(N);
	for (int i = 0; i < N; i++)
	{
		cin >> V[i];
	}

	vector<int> C(N);
	for (int i = 0; i < N; i++)
	{
		cin >> C[i];
		
	}

	///価値が0より大きいものを全部足す
	int ans = 0;
	for (int i = 0; i < N; i++)
	{
		int value = V[i] - C[i];
		if (value > 0) {
			ans += value;
		}
	}

	cout << ans << endl;
}


int main() {
	ABC125B();

	return 0;
}



Measured memory_bytes: 256
/*====Corycle====*/
#include<algorithm>
#include<iostream>
#include<iomanip>
#include<cstring>
#include<cstdlib>
#include<complex>
#include<cstdio>
#include<vector>
#include<cmath>
#include<ctime>
#include<stack>
#include<queue>
#include<map>
#define ll long long
using namespace std;
const int inf=0x3f3f3f3f;
const int Mod=1e9+7;
const int N=(1<<16)+5;
const int M=17;
int read(){
	int s=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){s=s*10+c-'0';c=getchar();}
	return s*f;
}
int n,m,Sta,Ans;
int a[M],f[2][N],fac[N],inv[N],num[N];
int mod(int x){return x>=Mod?x-Mod:x;}
void Prepare(){
	fac[0]=fac[1]=inv[0]=inv[1]=1;
	for(int i=2;i<N;i++)fac[i]=1ll*fac[i-1]*i%Mod;
	for(int i=2;i<N;i++)inv[i]=1ll*inv[Mod%i]*(Mod-Mod/i)%Mod;
	for(int i=2;i<N;i++)inv[i]=1ll*inv[i-1]*inv[i]%Mod;
}
int C(int n,int m){return n<m?0:1ll*fac[n]*inv[m]%Mod*inv[n-m]%Mod;}
int main(){
//	freopen("_.in","r",stdin);
//	freopen("_.out","w",stdout);
	n=read();m=read();Sta=(1<<n)-1;
	for(int i=1;i<=m;i++)a[i]=read();
	int t=0;f[t][0]=1;Prepare();
	for(int i=m;i>=1;i--){
		t^=1;
		memcpy(f[t],f[t^1],sizeof(f[t]));
		for(int S=0;S<=Sta;S++){
			for(int j=0;j<n;j++){
				if((S>>j)&1)continue;
				int T=S|(1<<j);
				f[t][T]=mod(f[t][T]+1ll*f[t^1][S]*fac[1<<j]%Mod*C((1<<n)-S-a[i],(1<<j)-1)%Mod);
			}
		}
	}
	for(int S=0;S<=Sta;S++){
		num[S]=num[S>>1]+(S&1);
		Ans=mod(Ans+1ll*(num[S]&1?Mod-1:1)*f[t][S]%Mod*fac[Sta-S]%Mod);
	}
	Ans=1ll*Ans*(1<<n)%Mod;
	printf("%d",Ans);
	return 0;
}

Measured memory_bytes: 5052
#include <bits/stdc++.h>
#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mod 1000000007
// #define mod 998244353
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a, b;
	cin>>a>>b;
	cout<<a*b;
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)
#define rrep(i, n) for(int i = ((int)n - 1); i >= 0; --i)

using ll = long long;
using ld =  long double;

const ll INF = 1e18;
const int Inf = 1e9;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;

int calc(ll x) {
    int res = 0;
    while (x % 2 == 0) {
        x /= 2;
        res++;
    }

    return res;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(0);
    int n;
    cin >> n;
    int res = 0;
    rep (i, n) {
        ll a;
        cin >> a;
        res += calc(a);
    }
    cout << res << endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    map<string, int> mp;
    rep(i, N) {
        string S;
        cin >> S;
        mp[S]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;

    return 0;
}

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

int main() {
	int s, w;
	cin >> s >> w;
	if (s <= w) cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}

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

int main(){
    ll n;
    cin>>n;
    cout<<(1000-n%1000)%1000<<endl;
    return 0;
}

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

using namespace std;

int main(void) {
	string s;
	cin >> s;
	int l = 0;
	int r = s.length() - 1;
	int result = 0;
	while(s[l] == 'x' && s[r] == 'x') {
		++l;
		--r;
	}
	while(s[l] == 'x') {
		++l;
		++result;
	}
	while(s[r] == 'x') {
		--r;
		++result;
	}
	while(l < r) {
		if(s[l] != s[r]) {
			cout << "-1\n";
			return 0;
		}
		do {
			++l;
			--r;
		} while(s[l] == 'x' && s[r] == 'x');
		while(s[l] == 'x') {
			++l;
			++result;
		}
		while(s[r] == 'x') {
			--r;
			++result;
		}
	}
	cout << result << '\n';
	return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
long long dp[105][100005];
int main()
{
    long long n,c,i,x,y,j;
     cin>>n>>c;
    vector <long long> v,w;
    for(i=0;i<n;++i)
    {
       cin>>x>>y;
       w.push_back(x);
       v.push_back(y);
    }
 for(i=0;i<=n;++i)
 {
    for(j=0;j<=c;++j)
    {
       if(i==0 || j==0)
         dp[i][j]=0;
      else if(w[i-1]<=j)
        dp[i][j]=max(v[i-1]+dp[i-1][j-w[i-1]],dp[i-1][j]);
      else
        dp[i][j]=dp[i-1][j];
    }
 }
 cout<<dp[n][c];
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;

template<class T>
void chmax(T &a, const T b) {
    if (b > a) a = b;
}

template<class T>
void chmin(T &a, const T b) {
    if (b < a) a = b;
}

namespace Math {
    ll modpow(ll b, ll p, ll m) {
        ll r = 1;
        for (; p; p >>= 1, b = b * b % m)
            if (p & 1)
                r = r * b % m;
        return r;
    }

    ll modinv(ll b, ll m) { return modpow(b, m - 2, m); }

    // Least significant bit.
    ll lsb(ll x) { return x & (-x); }

    template<class T>
    const T inf() { return 0; }

    template<>
    const ll inf<ll>() { return 0x3f3f3f3f3f3f3f3fll; }

    template<>
    const int inf<int>() { return 0x3f3f3f3f; }

    template<class T>
    T gcd(T a, T b) { return abs(__gcd(a, b)); }

    template<class T>
    T clamp(T n, T l, T r) { return n < l ? l : n > r ? r : n; }

    template<class T>
    T lcm(T a, T b) { return abs(a / gcd(a, b) * b); }

    template<class T>
    T sgn(T n) { return n == 0 ? 0 : n > 0 ? 1 : -1; }

    // Generic modular integer.
    template<int MOD, typename IntType = int>
    struct GModint {
        IntType val;

        GModint() : val(0) {}

        GModint(int v, bool safe = false) { val = safe ? v : ((v % MOD) + MOD) % MOD; }

        GModint(ll v, bool safe = false) { val = safe ? v : ((v % MOD) + MOD) % MOD; }

        explicit operator bool() const { return val != 0; }

        const bool operator==(const GModint &g) const { return val == g.val; }

        const bool operator!=(const GModint &g) const { return val != g.val; }

        const GModint operator+=(const GModint &g) { return *this = *this + g; }

        const GModint operator-=(const GModint &g) { return *this = *this - g; }

        const GModint operator*=(const GModint &g) { return *this = *this * g; }

        const GModint operator/=(const GModint &g) { return *this = *this / g; }

        const GModint operator^=(const GModint &g) { return *this = *this ^ g; }

        const GModint operator-() const { return GModint(val == 0 ? 0 : MOD - val, true); }

        const GModint operator+(const GModint &g) const {
            ll newval = val + g.val;
            if (newval >= MOD)
                newval -= MOD;
            return GModint(newval, true);
        }

        const GModint operator-(const GModint &g) const { return *this + (-g); }

        const GModint operator*(const GModint &g) const { return GModint(1ll * val * g.val); }

        const GModint operator/(const GModint &g) const { return *this * g.inv(); }

        template<class T>
        const GModint operator^(const T t) const { return GModint(modpow(val, t, MOD)); }

        const GModint inv() const { return GModint(modinv(val, MOD)); }
    };

    using Modint = GModint<1000000007>;
}

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

    ll h,w;
    cin >> h >> w;
    if (h==1||w==1){
        cout<< 1 <<endl;
    } else {
        cout << (h * w + 1) / 2 << endl;
    }
}


Measured memory_bytes: 256
n,c=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
ans=0
for i in range(2):
  for j in range(2):
    for k in range(2):
      arr=sorted(arr,reverse=True,key=lambda x:((-1)**i)*x[0]+((-1)**j)*x[1]+((-1)**k)*x[2])
      s1=0
      s2=0
      s3=0
      for l in range(c):
        s1+=arr[l][0]
        s2+=arr[l][1]
        s3+=arr[l][2]
      tmp=abs(s1)+abs(s2)+abs(s3)
      ans=max(ans,tmp)
print(ans)

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

int main() {
  int n;
  cin>>n;
  int s=0;
  for(int x=1; x<=n; x+=2){
    int k=0;
    for(int i=1; i<=n; i++){
      if (x%i==0) k+=1;
    }
    if (k==8) s+= 1;
  }
  cout << s;
}

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

int main() {
    int amax = 100000;
    int n; cin >> n;
    vector<int> a(amax + 1, 0);

    for(int i = 0; i < n; i++) {
        int inp; cin >> inp;
        a[inp]++;
    }

    int mx = -1;
    for(int i = 1; i < amax - 1; i++) {
       int m = a[i-1] + a[i] + a[i+1];
       mx = max(mx, m);
    }
    cout << mx << endl;
}


Measured memory_bytes: 1272
N,M=map(int,input().split())
H=list(map(int,input().split()))
G={i+1 for i in range(N)}
for _ in range(M):
  a,b=map(int,input().split())
  if H[a-1]>H[b-1]:
    G-={b}
  elif H[b-1]>H[a-1]:
    G-={a}
  else:
    G-={a,b}
print(len(G))

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


int main() {
    int N, Y;
    cin >> N >> Y;
    Y /= 1000;

    int x, y, z;
    for (int i = 0; i <= N; ++i) {
        for (int j = 0; j <= N; ++j) {
            int k = N - (i + j);
            if (Y == i*10 + j*5 + k && k >= 0) {
                x = i;
                y = j;
                z = k;
                cout << x << " " << y << " " << z << endl;
                return 0;
            } else {
                x = -1;
                y = -1;
                z = -1;

            }
        }
    }
    cout << x << " " << y << " " << z << endl;
}

Measured memory_bytes: 256
taro_point=0
hanako_point=0
n=int(input())
for i in range(n):
    taro_card,hanako_card=input().split()
    if taro_card>hanako_card:
        taro_point+=3
    elif taro_card<hanako_card:
        hanako_point+=3
    else:
        taro_point+=1
        hanako_point+=1
print(taro_point,hanako_point)


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

int main(void) {
	double stack[200];
	char temp[100];
	int stackptr=0;
	while(1) {
		if(scanf("%s",temp)==-1)break;
		if(strcmp(temp,"+")==0) {
			if(stackptr<2)return 1;
			stack[stackptr-2]+=stack[stackptr-1];
			stackptr--;
		} else if(strcmp(temp,"-")==0) {
			if(stackptr<2)return 1;
			stack[stackptr-2]-=stack[stackptr-1];
			stackptr--;
		} else if(strcmp(temp,"*")==0) {
			if(stackptr<2)return 1;
			stack[stackptr-2]*=stack[stackptr-1];
			stackptr--;
		} else if(strcmp(temp,"/")==0) {
			if(stackptr<2)return 1;
			if(stack[stackptr-1]==0)return 1;
			stack[stackptr-2]/=stack[stackptr-1];
			stackptr--;
		} else {
			stack[stackptr]=atof(temp);
			stackptr++;
		}
		if(getchar()=='\n') {
			if(stackptr!=1)return 1;
			printf("%f\n",stack[0]);
			stackptr=0;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    int N,temp;
    int V[51];
    int C[51];
    int S[51];

    cin >> N;

    for(int i = 0; i < N; i++)
    {
        cin >> V[i];
    }

    for(int i = 0; i < N; i++)
    {
        cin >> C[i];
    }

    for(int i = 0; i < N; i++)
    {
        S[i] = V[i] - C[i];
    }
    


    int ans =0;
    for(int i = 0; i < N; i++)
    {
        if(S[i]>0) ans += S[i]; 
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
def prepare(n, MOD):
    # 1! - n! の計算
    f = 1
    factorials = [1]  # 0!の分
    for m in range(1, n + 1):
        f *= m
        f %= MOD
        factorials.append(f)
    # n!^-1 の計算
    inv = pow(f, MOD - 2, MOD)
    # n!^-1 - 1!^-1 の計算
    invs = [1] * (n + 1)
    invs[n] = inv
    for m in range(n, 1, -1):
        inv *= m
        inv %= MOD
        invs[m - 1] = inv
     
    return factorials, invs

def combinations_count(n, r, factorials, invs):
    return (factorials[n] * invs[n-r] * invs[r]) % (10 ** 9 + 7)
 
n, k = map(int, input().split())
a = sorted(list(map(int, input().split())))

factorials, invs = prepare(n, 10 ** 9 + 7)

ans = 0
for i in range(n):
    if i <= n - k:
        ans -= a[i] * combinations_count(n-i-1, k-1, factorials, invs)
    
    if i >= k - 1:
        ans += a[i] * combinations_count(i, k-1, factorials, invs)
    
    ans = ans % (10 ** 9 + 7)
 
print(ans)

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

int main() {
  std::string input;
  std::cin >> input;
  int zeros = 0, ones = 0;
  for (auto s : input) {
    if (s == '0') zeros++;
    if (s == '1') ones++;
  }
  std::cout << std::min(zeros, ones) * 2 << std::endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define N 10
using namespace std;
int n,m,ans;
map<char,int> c;
set<char> ish;
bool used[N];
bool q[N];
string s;
int p[N];

void func(int x,int sum){
  if(x==m){
    if(!sum)ans++;
    return;
  }
  for(int i=0;i<10;i++){
    if(used[i])continue;
    if(!i&&q[x])continue;
    used[i]=true;
    func(x+1,sum+i*p[x]);
    used[i]=false;
  }
}

int main(){
  while(1){
    cin>>n;
    if(!n)break;
    for(int i=0;i<n;i++){
      cin>>s;
      for(int j=s.size()-1,k=1;j>=0;j--,k*=10){
	if(!j&&s.size()!=1)ish.insert(s[j]);
	if(c.find(s[j])==c.end())
	  if(i!=n-1)c[s[j]]=k;
	  else c[s[j]]=-k;
	else
	  if(i!=n-1)c[s[j]]+=k;
	  else c[s[j]]-=k;
      }
    }
    memset(q,0,sizeof(q));
    map<char,int>::iterator ite;
    int k=0;
    for(ite=c.begin();ite!=c.end();ite++,k++){
      p[k]=(*ite).second;
      if(ish.find((*ite).first)!=ish.end())
	q[k]=true;
    }
    m=c.size();
    ans=0;
    func(0,0);
    cout<<ans<<endl;
    ish.clear();
    c.clear();
  }
  return 0;
}

Measured memory_bytes: 2996
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>

#define M 100
#define N 100
#define SINGLE 1
#define ALL 2
#define INFTY 1<<28
#define MAX_HP 100001

using namespace std;

struct monster{
	int hp;
};

struct magic{
	int mp;
	int type;
	int damage;
};

void min_mp(int *min, int max_hp, const vector<magic> &vmag){
	int m = vmag.size();

	for(int i = 0; i < max_hp; ++i){
		min[i] = INFTY;
	}

	if( m == 0 )
		return ;

	int **dp = new int*[m];
	for(int i = 0; i < m; ++i){
		dp[i] = new int[max_hp];
	}
	
	for(int i = 0; i < m; ++i){
		for(int j = 0; j < max_hp; ++j){
			dp[i][j] = INFTY;
		}
	}
	
	dp[0][0] = 0;
	for(int i = 0; i < m; ++i){
		int mp = vmag[i].mp;
		int damage = vmag[i].damage;
		
		for(int j = 0; j < max_hp; ++j){
			if( dp[i][j] < INFTY ){
				if( i + 1 < m )
					dp[i+1][j] = std::min( dp[i+1][j], dp[i][j] );
				int &t = dp[i][std::min(j+damage,max_hp-1)];
				t = std::min( t, dp[i][j] + mp );
			}
		}
	}

	min[max_hp-1] = dp[m-1][max_hp-1];
	for(int i = max_hp-2; i >= 0; --i){
		min[i] = std::min( min[i+1], dp[m-1][i] );
	}

	for(int i = 0; i < m; ++i){
		delete [] dp[i];
	}
	delete [] dp;
}
int MagicSlayer(const vector<monster> &vmon, const vector<magic> &vmag){
	int ret = INFTY;
	vector<magic> vmag_single;
	vector<magic> vmag_all;
	int max_hp = 0;
	int min_mp_single[MAX_HP]={0,};
	int min_mp_all[MAX_HP]={0,};

	for(unsigned int i = 0; i < vmon.size(); ++i){
		max_hp = max( max_hp, vmon[i].hp );
	}
	++max_hp;

	for(unsigned int i = 0; i < vmag.size(); ++i){
		if( vmag[i].type == ALL )
			vmag_all.push_back( vmag[i] );
		else
			vmag_single.push_back( vmag[i] );
	}

	min_mp( min_mp_single, max_hp, vmag_single );
	min_mp( min_mp_all, max_hp, vmag_all );

	/*for(int i = 0; i < max_hp; ++i){
		if( i % 500 == 0 )
			cout << "DAMAGE: " << i << " MP: " << min_mp_single[i] << endl;
	}*/

	for(int i = 0; i < max_hp; ++i){
		int dam;
		int mp;

		if( min_mp_all[i] >= INFTY ){
			dam = 0;
			mp = 0;
		}else{
			dam = i;
			mp = min_mp_all[i];
		}

		for(unsigned int j = 0; j < vmon.size(); ++j){
			if( vmon[j].hp - dam > 0 ){
				int t = min_mp_single[ vmon[j].hp - dam ];
				if( t >= INFTY ){
					mp = INFTY;
					break;
				}else{
					mp += t;
				}
			}
		}

		ret = min( ret, mp );
	}

	return ret;
}

int main(){
	while(true){
		int n,m;
		vector<monster> vmonster;
		vector<magic> vmagic;
		
		scanf("%d", &n);
		if(n==0)break;
		for(int i=0;i<n;++i){
			monster t;
			
			scanf("%d", &t.hp);
			vmonster.push_back( t );
		}

		scanf("%d", &m);
		for(int i=0;i<m;++i){
			char stype[17]="";
			magic mag;

			scanf("%*s%d%s%d", &mag.mp, stype, &mag.damage);
			if(strcmp(stype,"All")==0)mag.type=ALL;
			else mag.type=SINGLE;
			vmagic.push_back( mag );
		}

		printf("%d\n", MagicSlayer( vmonster, vmagic ) );
	}
	return 0;
}

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

int array1[] = {1,3,5,7,8,10,12};
int array2[] = {4,6,9,11};

int hantei (int a, int b){
    switch(a){
        case 1:
        case 3:
        case 5:
        case 7:
        case 8:
        case 10:
        case 12:
            for(int i=0; i < 7; i++){
                if(b==array1[i]){
                    return 1;
                }
            }
            break;
        case 4:
        case 6:
        case 9:
        case 11:
            for(int i=0; i < 4; i++){
                if(b==array2[i]){
                    return 1;
                }
            }
            break;
        case 2:
            if(b==2){
                return 1;
            }
    }
    return 0;
}

int main (){
    int x, y;
    cin >> x >> y;
    if(hantei(x,y)==1){
        cout << "Yes"  << endl;
    }else if(hantei(x,y)==0){
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main(void){
   int D;
   scanf("%d",&D);
   if(D==22){
       printf("Christmas Eve Eve Eve");
   }else if(D==23){
       printf("Christmas Eve Eve");
   }else if(D==24){
       printf("Christmas Eve");
   }else if(D==25){
       printf("Christmas");
   }
    return 0;
    }

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
const int INF_INT = 2147483647;
const long long INF_LONG = 9223372036854775807;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
int main() {
  int n;  cin >> n;

  vector<ll> v(100);
  v[0] = 1;
  v[1] = 1;

  for (int i=2; i<=n; ++i) {
    v[i] = v[i-1] + v[i-2];
  }

  cout << v[n] << endl;
}


Measured memory_bytes: 3092
#include"bits/stdc++.h"
#include<cassert>
#define fr first
#define sc second
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 998244353;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int a[100005];
signed main() {
	int n, m; cin >> n >> m;
	priority_queue<PP>Q;
	rep(i, n) {
		cin >> a[i];
		Q.push(PP(a[i], P(0,i)));
	}
	rep(i, m) {
		PP p = Q.top();
		Q.pop();
		p.second.first++;
		if (p.first)p.first = a[p.second.second] / (1ll << p.second.first);
		Q.push(p);
	}
	int sum = 0;
	while(Q.size()) {
		sum += Q.top().first;
		Q.pop();
	}
	cout << sum << endl;
}

Measured memory_bytes: 5492
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
//    freopen("test.txt", "r", stdin);
    int a, b, c, x, y;
    cin >> a >> b >> c >> x >> y;
    int ret = x*a + y*b;
    ret = min(ret, max(x,y)*2*c);
    if (x > y) {
        ret = min(ret, 2*y*c + (x-y)*a);
    }
    else if (y > x) {
        ret = min(ret, 2*x*c + (y-x)*b);
    }
    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;

int main() {
	int N; cin >> N;
	int B[100], ans = 0;
	rep(i, N-1) {
		cin >> B[i];
	}
	ans += (B[0] + B[N - 2]);
	rep(i, N - 2) {
		ans += min(B[i], B[i + 1]);
	}
	cout << ans << endl;
		
}

Measured memory_bytes: 256