akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<math.h>
#include<string>
#include<algorithm>
#include<functional>
#include<vector>
#include<set>
#include<map>
#define INF 999999
#define EPS 1.0e-6

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;

int n;
int a[105000];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	ll ans = 1;
	int ope = 0;
	if (n % 2 == 0) {
		for (int i = 0; i < n; i++) {
			int k = 2 * (i / 2) + 1;
			if (a[i] != k) {
				ope++; break;
			}
			else {
				if (i % 2 == 0) {
					ans *= 2;
					ans = ans % 1000000007;
				}
			}
		}
	}
	if (n % 2 != 0) {
		if (a[0] != 0)ope++;
		for (int i = 1; i < n; i++) {
			int k;
			if (i % 2 == 0)k = i;
			else k = i + 1;
			if (a[i] != k) {
				ope++; break;
			}
			else {
				if (i % 2 == 0) {
					ans *= 2;
					ans = ans % 1000000007;
				}
			}
		}
	}
	if (ope != 0) {
		cout << 0 << endl;
		return 0;
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

int main(){
    string S,ss;
    long long int K,ans=0,a=1,b,n=0;
    bool all =true,first = true,kei=false,same;
    cin >> S;
    cin >> K;

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

    if(S[0] == S[S.size()-1]){
        same = true;
    }else{
        same = false;
    }

    if(all){
            cout << S.size()*K/2 << endl;
    }else{
        if(same){
            ss = S + S;
            for(int i=0;i<S.size()-1;i++){
                if(S[i] == S[i+1]){
                    a++;
                    if(i == S.size()-2){
                        kei = true;
                        ans += a/2;
                    }
                }else{
                    if(1<a && first){
                        ans += a/2;
                    }else if(1<a){
                        ans += a/2*K;
                    }
                    a = 1;
                    first = false;
                }
            }

            if(kei){
                a = 1;
                for(int i=S.size()-1;;i--){
                    if(ss[i] == ss[i-1]){
                        a++;
                    }else{
                        break;
                    }
                }
                for(int i=S.size()-1;;i++){
                    if(ss[i] == ss[i+1]){
                        a++;
                    }else{
                        break;
                    }
                }
                ans += a/2*(K-1);
            }
        }else{
            for(int i=0;i<S.size()-1;i++){
                if(S[i] == S[i+1]){
                    a++;
                    if(i == S.size()-2){
                        ans += a/2*K;
                    }
                }else{
                    if(1<a){
                        ans += a/2*K;
                    }
                    a = 1;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int N = sc.nextInt();
		int[] values = new int[N];
		int[] costs = new int[N];
		
		for(int i = 0; i < N; i++) values[i] = sc.nextInt();
		for(int i = 0; i < N; i++) costs[i] = sc.nextInt();
		
		int ans = 0;
		for(int i = 0; i < N; i++){
			int profit = values[i] - costs[i];
			if(profit > 0) ans += profit;
		}
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 25300
#include <iostream>
#include <string>

int main(void){
  	std::string s1, s2, s3;
  	//入力はスペースで分割される
  	std::cin >> s1 >> s2 >> s3;
  	std::cout << "A" << s2[0] << "C" << std::endl;
	return 0;
}

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

int main(void)
{
	int a, b, c, x, y;
	cin >> a >> b >> c >> x >> y;


	int minp = pow(10, 5)*5000*2+1;
	for (int i = 0; i <= max(x, y)*2; i+=2) {
		int a_num = x-i/2;
		int b_num = y-i/2;
		a_num = a_num < 0 ? 0 : a_num;
		b_num = b_num < 0 ? 0 : b_num;
		int price = a*a_num + b*b_num + c*i;
		if (price < minp)
			minp = price;
	}

	cout << minp << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a; cin >> a;
    int count = 0;
    for(int i = 0; i < 4; i++){
        if(a[i] == '+') count++;
        if(a[i] == '-') count--;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int seisuu = int.Parse(Console.ReadLine());
            string[] str1 = Console.ReadLine().Split(' ');
            int[] numbers1 = new int[str1.Length];
            int length = numbers1.Length;

            for (int i = 0; i < length; i++)
            {
                numbers1[i] = int.Parse(str1[i]);
            }

            int sum = 0;

            for (int i = 0; i < length; i++)
            {
                if (i == 0)
                {
                    sum += numbers1[i];
                    if (length == 1)
                    {
                        sum += numbers1[i];
                    }
                    else
                    {
                        sum += Math.Min(numbers1[i], numbers1[i + 1]);
                    }
                }
                else if (i == length - 1)
                {
                    sum += numbers1[i];
                }
                else
                {
                    sum += Math.Min(numbers1[i], numbers1[i + 1]);
                }
            }

            Console.WriteLine($"{sum}");
        }
    }
}


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

int main()
{
    unsigned long long m = 0;
    unsigned long long a = 0;
    unsigned long long r = 0;
    unsigned long long c = 0;
    unsigned long long h = 0;
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        string in;
        cin >> in;
        if(in[0] == 'M'){
            m++;
        }
        if(in[0] == 'A'){
            a++;
        }
        if(in[0] == 'R'){
            r++;
        }
        if(in[0] == 'C'){
            c++;
        }
        if(in[0] == 'H'){
            h++;
        }
    }
    unsigned long long answer =  m * (a * (r + c + h) + r * (c + h) + c * h) + a * (r * (c + h) + c * h) + r * c * h;
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<unordered_set>
#include<unordered_map>
#include<set>
#include<map>
#include<list>

using namespace std;

#define in(s) cin >> s
#define out(s) cout << s << endl
#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    while (true) {
        C -= B;
        if (C <= 0) {
            cout << "Yes";
            break;
        }
        A -= D;
        if (A <= 0) {
            cout << "No";
            break;
        }
    }

	return 0;
}


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

int main(){
    int a,b,c;
    int tmp,tmp2,tmp3;
    cin >> a >> b >> c;
    tmp = a;
    tmp2 = b;
    tmp3 = c;
    a = tmp3;
    b = tmp;
    c = tmp2;
    cout << a <<" "<< b <<" " <<c << endl;
    return 0;

}

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


int main(void){
    int N;
    string S;
    cin >> N >> S;
    for(int i = 0; i < S.size() - 1; i++){
      //cout << "start:" << S.size() << "," << i << endl;
      while(i < S.size() - 1){
      	//cout << "while:" << S.size() << S.at(1) << endl;
          if(S.at(i) == S.at(i + 1)){
            //cout << i << "," << S.size() << "," << S << ",erase"<<endl;
            S.erase(i, 1);
            //cout << i << "," << S.size() << "," << S << ",erase"<<endl;
          }
          else{
          	//cout << "break" << endl;
          	break;
          }
          //cout << S.size() << "," << S.size() - 2 << "," << i << endl;
      }    
    }

    cout << S.size() << endl;


}


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

#define PI acos(-1.0)

using namespace std;

double a, b, h, m;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "r", stdin);
#endif

    scanf("%lf%lf%lf%lf", &a, &b, &h, &m);
    double c1 = 360.0 * (m / 60);
    double c2 = 360.0 * (h / 12) + 30.0 * (m / 60.0);
    //cerr << c1 << ' ' <<c2 << endl;
    double temp = fabs(c1 - c2);
    temp = min(temp, 360.0 - temp);
    //cerr << "temp : " << temp << endl;
    temp = temp * PI / 180.0;
    double len = a * a + b * b - 2 * a * b * cos(temp);
    len = sqrt(len);
    printf("%.12f\n", len);

#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 4216
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        boolean[] c = new boolean[26];
        for (int i = 0; i < s.length(); i++) {
            char ssc = s.charAt(i);
            int pos = (int) ssc - 97;
            if (c[pos]) {
                System.out.println("no");
                return;
            } else {
                c[pos] = true;
            }

        }
        sc.close();
        System.out.println("yes");
    }
}

Measured memory_bytes: 21972
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


int main()
{
	string s, t;
	cin >> s >> t;
	cout << t + s << endl;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

char *demangle(const char *demangle)
{
    int status;
    return abi::__cxa_demangle(demangle, 0, 0, &status);
}
double dist(int i, int j, vector<pair<double, double>> vec)
{
    double dx = vec[i].first - vec[j].first;
    double dy = vec[i].second - vec[j].second;
    debug(dx);
    debug(dy);

    return pow(dx * dx + dy * dy, 0.5);
}

int main()
{

    int N;
    cin >> N;
    vector<int> P(N), Q(N);
    rep(i, N) cin >> P[i];
    rep(i, N) cin >> Q[i];

    int a, b;

    vector<int> A(N);
    rep(i, N) A[i] = i + 1;

    int cnt = 0;
    do
    {
        cnt++;
        bool ok_p = true;
        rep(i, N)
        {
            if (A[i] != P[i])
            {
                ok_p = false;
            }
        }

        bool ok_q = true;
        rep(i, N)
        {
            if (A[i] != Q[i])
            {
                ok_q = false;
            }
        }

        if (ok_p)
            a = cnt;
        if (ok_q)
            b = cnt;

    } while (next_permutation(all(A)));

    cout << abs(a - b) << endl;
    return 0;
}


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

public class Solution
{
    public static void Main()
    {
        var s = long.Parse(Console.ReadLine());

        const long e9 = 1000000000;
        if (s <= e9)
        {
            Console.WriteLine($"0 0 0 1 {s} 0");
            return;
        }
        if (s == 1000000000000000000)
        {
            Console.WriteLine($"0 0 0 {e9} {e9} 0");
            return;
        }


        // s = x1 * y2 - x2 * y1
        var y2 = e9;
        var x1 = (s / y2) + 1;
        var y1 = 1;
        var x2 = x1 * y2 - s;

        Console.WriteLine($"0 0 {x1} {y1} {x2} {y2}");
    }
}

Measured memory_bytes: 13268
N, M = map(int, input().split())
a = list(map(int, input().split()))

a.sort()

g = [0 for i in range(M-1)]

for i in range(M-1):
    g[i]=a[i+1]-a[i]
    
g.sort()
g.reverse()

print(sum(g[N-1:len(a)-1]))

Measured memory_bytes: 14096
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace ConsoleApp6
{
	class Program
	{
		static void Main(string[] args)
		{
			var s = Console.ReadLine();
			var p = Console.ReadLine();

			s += s;

			if (0 <= s.IndexOf(p))
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}

		}
	}
}



Measured memory_bytes: 18368
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		// スペース区切りの整数の入力
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();
		
		int min = 0;
		int max = 0;
		if ( a < c){
			min = c;
		}else{
			min = a;
		}
		if ( b < d){
			max = b;
		}else{
			max = d;
		}
		int ans = max - min;
		if ( ans > 0){
			System.out.println(ans);
		}else{
			System.out.println(0);
		}
	}
}


Measured memory_bytes: 21076
// Starting with the name of Allah

#include <bits/stdc++.h>
#define ll long long
#define nl endl
#define Nayon ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define gcd(a,b)         __gcd(a,b)
#define lcm(a,b)         (a/gcd(a,b))*b


using namespace std;




int main()
{
	Nayon;
	ll k,i,x,y;
	cin>>k;
	x=0;
	for(i=1;i<=k;i++){
		x=x*10+7;
		if(x%k==0){
			cout<<i<<nl;
			return 0;
		}
		x=x%k;
	}
	cout<<-1<<nl;
	return 0;
}


Measured memory_bytes: 3644
import numpy as np
def Main(N, S):
    num = [0]*3
    for c in S:
        if c == 'R':
            num[0] += 1
        elif c == 'G':
            num[1] += 1
        else:
            num[2] += 1
    ans = np.prod(num)
    sub = 0
    i = 0
    j = 1
    while(i-2 < N):
        while(i+2*j < N):
            a = i
            b = i+j
            c = i+2*j
            if S[a] != S[b] and S[a] != S[c] and S[b] != S[c]:
                sub += 1
            j += 1
        i += 1
        j = 1
    return ans - sub
        
    

def main():
    N = int(input())
    S = str(input())
    print(Main(N,S))

if __name__ == '__main__':
    main()

Measured memory_bytes: 26980
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()


int gcd(int a, int b) {
	if (b == 0)return a;
	return gcd(b, a % b);
}

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

	int n;
	cin >> n;
	vector<pair<long long, long long>> v;
	map<pair<long long, long long>, int> div;


	rep(i, n) {
		string s;
		cin >> s;

		long long a = 0, b = 0;

		auto p = s.find('.');
		if (p==string::npos) {
			a = atoi(s.c_str());
			b = 0;
		}
		else {
			a = atoi(s.c_str());

			int base = 1;
			rep(i, 9){
				if (p + 1 + i >= s.size())break;
				base *= 10;
				b += (s[p + 1 + i] - '0') * (1000000000 / base);
			}
		}
		
		long long c = a * 1000000000 + b;
		int c1 = 0, c2 = 0;
		while (c % 2 == 0) {
			c /= 2;
			c1++;
		}
		while (c % 5 == 0) {
			c /= 5;
			c2++;
		}
		v.emplace_back(c1, c2);
		++div[make_pair(c1, c2)];
	}

	long long ans = 0;
	for (auto p: v) {
		for (auto p2 : div) {
			if (p.first + p2.first.first >= 18 && p.second + p2.first.second >= 18) {
				ans += p2.second;
			}
		}
		if (p.first >= 9 && p.second >= 9) {
			ans--;
		}
	}

	cout << ans / 2 << endl;


	return 0;
}


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

cnt = 0
for i in range(n):
    for j in range(i+1, n):
        for k in range(j+1, n):
            if a[i] != a[j] and a[j] != a[k] and a[k] != a[i] and a[i] + a[j] > a[k]:
                cnt += 1

print(cnt)

Measured memory_bytes: 9168
/* 2020/03/17 Atcoder Beginner Contest 095 C - Half and Half */

#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main() {
    int a, b, c, x, y;
    long long cbuy1, cbuy2, ans1 = 0, ans2 = 0, ans = 0;
    cin >> a >> b >> c >> x >> y;
    if(a+b > c * 2) {
        cbuy1 = min(x, y);
        ans1 += c * cbuy1 * 2;
        ans1 += a * (x - cbuy1) + b * (y - cbuy1);
        cbuy2 = max(x, y);
        ans2 += c * cbuy2 * 2;
        ans = min(ans1, ans2);

    } else {
        ans += a * x + b * y;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

long long ncr(int n, int r) {
    if(r > n - r) r = n - r; // because C(n, r) == C(n, n - r)
    long long ans = 1;
    int i;

    for(i = 1; i <= r; i++) {
        ans *= n - r + i;
        ans /= i;
    }

    return ans;
}
ll mod(ll a,ll b,ll m){
    if(b==0)return 1;
    if(b%2==0){
        ll y =  mod(a,b/2,m);
        return (y*y)%m;
    }
    else{
        return ((a%m)*mod(a,b-1,m))%m;
    }
}

ll modinv(ll a,ll m){
return mod(a,m-2,m);
//works only for prime m.
//else calculate phi(m)-1.
}


//current value
int main()
{
    int n;
    int total_weight;
    cin>>n>>total_weight;
    vector<int>w(n+1),v(n+1),sum(n+1);
    int s=0;
    for(int i=1;i<=n;i++){
        cin>>w[i]>>v[i];s+=v[i];
        sum[i]=s;
    }
    //states of dp->what is important so far
    //total weight so far, item number
   //since total weight is large , we use value as a dimension
    int ans=0;
    ll dp[n+1][s+1];

   for(int i=0;i<=n;i++){
    for(int j=0;j<=s;j++){
    dp[i][j]=1e18L;
   }
   }

   dp[0][0]=0;
   for(int i=1;i<=n;i++){
    for(int j=0;j<=s;j++){
       dp[i][j]=min(dp[i][j],dp[i-1][j]);
       if(j-v[i]>=0){
        dp[i][j]=min(dp[i][j],dp[i-1][j-v[i]]+w[i]);
       }
    }
   }
   for(int i=1;i<=n;i++){
    for(int j=0;j<=s;j++){
        if(dp[i][j]<=total_weight)
            ans=max(ans,j);
    }
   }

cout<<ans;

    return 0;
}


Measured memory_bytes: 82460
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
    //*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int n;
        cin >> n;
        vector<int> v(n + 1);
        for (int i = 0; i < n + 1; i++) {
            cin >> v[i];
        }
        vector<int> b(n + 1);
        for (int i = 0; i < n; i++) cin >> b[i];
        b[n] = 0;

        ll ans = 0;
        //int ext = 0;
        for (int i = 0; i < n; i++) {
            ans += min(b[i], v[i]);
            int ext = max(0, b[i] - v[i]);
            ans += min(ext, v[i + 1]);
            v[i + 1] = max(0, v[i + 1] - ext);
        }
        cout << ans << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int dp[100005][3]={{}};
int main()
{
  int n,max1=0;
  int a[100005],b[100005],c[100005];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i]>>b[i]>>c[i];
  }
  dp[0][0]=a[0];
  dp[0][1]=b[0];
  dp[0][2]=c[0];
  for(int i=1;i<n;i++){
    dp[i][0]+=max(dp[i-1][1],dp[i-1][2])+a[i];
    dp[i][1]+=max(dp[i-1][0],dp[i-1][2])+b[i];
    dp[i][2]+=max(dp[i-1][0],dp[i-1][1])+c[i];
  }
  if(dp[n-1][1]>dp[n-1][2]){
    max1=dp[n-1][1];
  }
  else{
    max1=dp[n-1][2];
  }

  if(max1<dp[n-1][0]){
    max1=dp[n-1][0];
  }

  cout<<max1<<"\n";
  return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
int N;
  int cnt=0;
  int elm=0;
  cin >> N;
vector<int> d(N);
  for (int i=0;i<N;i++){
 
  cin >> d[i];
  }
  sort(d.begin(),d.end());
  for (int i=0;i<N;i++){
  if (d[i] > elm){
    cnt++;
    elm=d[i];
  }     
  }
  cout << cnt;
}
  

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	int ret=0;
	if(a%10==2)ret++;
	a/=10;
	if(a%10==2)ret++;
	a/=10;
	if(a%10==2)ret++;
	a/=10;
	if(a%10==2)ret++;
	a/=10;
	printf("%d\n",ret);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
using namespace std;
int n, t, a[305][305], b[305][305];
long long s;
int main() {
	int i, j, k;
	scanf("%d", &n);
	for(i=0; i<n; i++) for(j=0; j<n; j++) scanf("%d", &a[i][j]);
	for(k=0; k<n; k++) for(i=0; i<n; i++) for(j=0; j<n; j++) {
		t = a[i][k] + a[k][j];
		if(a[i][j]>t) {puts("-1"); return 0;}
		else if(a[i][j]==t && k!=i && k!=j) b[i][j] = 1;
	}
	for(i=0; i<n; i++) for(j=i+1; j<n; j++) s += a[i][j] * !b[i][j];
	cout<<s;
	return 0;
}

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

typedef long long ll;
typedef long double ld;

using namespace std;


void solve(){
    ll a, b, c;
    cin >> a >> b >> c;
    c = min(c, a + b + 1);
    cout << b + c << "\n";
}

signed main(){
    ll t = 1;
    srand(time(0));
    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef DEBUG
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen("input.txt", "r", stdin);
//        freopen("output.txt", "w", stdout);
    #endif
    while(t--){
        solve();
    }
}


Measured memory_bytes: 764
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int N){
    vector<int>S;
    rep(i,N)if(bit & (1<<i))S.push_back(i);
    return S;
}

int main(){
    int n;cin>>n;
    ll res = 1;
    int mod = INF+7;
    REP(i,1,n){
        res *= i;
        res %= mod;
    }
    cout<<res;
}



Measured memory_bytes: 256
#include <stdio.h>
#define N 101
#define X 298

void init(int [N][X]);

int main(void) {
    int n, x, tbl[N][X] = {{}};
    init(tbl);
    while(scanf("%d %d", &n, &x), n || x) {
        printf("%d\n", 0 < x && x < X ? tbl[n][x] : 0);
    }
    return 0;
}

void init(int tbl[N][X]) {
    int i, j, k;
    double v;
    for(i = 3; i < N; i++) {
        v = 1;
        for(j = i + 3; j <= ~-i * 3; j++) {
            for(k = i; k < N; k++) {
                tbl[k][j] += (int)v;
            }
            if(j < i * 2) {
                v += 0.5;
            } else {
                v -= 0.5;
            }
        }
    }
}

Measured memory_bytes: 724
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
int main(){
  ll a,b=0,c=0,d=0;cin>>a;
  rep(i,a){
    ll e,f,g;cin>>e>>f>>g;
    if(((e-b)-abs(c-f)-abs(d-g))%2!=0||((e-b)-abs(c-f)-abs(d-g))<0){
      cout<<"No";
      return 0;
    }
    b=e;
    c=f;
    d=g;
  }
  cout<<"Yes";
}



Measured memory_bytes: 27044
#include <iostream>
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;

int main()
{
    ll n,x,t; cin>>n>>x>>t;
    ll ans;
    if(n%x!=0){
        ans=(n/x+1)*t;
    }
    else ans=(n/x)*t;
    cout<<ans<<endl;

    return 0;
}


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

bool alpha[26] = {false};

int main(){
  string str;
  cin >> str;
  for(unsigned int i=0; i < str.length(); i++){
    alpha[str[i] - 'a'] = true;
  }
  
  for(int i = 0; i < 26; i++){
    if(!alpha[i]){
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }

  cout << "None" << endl;
  
  return 0;
}


Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static class Player implements Comparable<Player>{
		int number;
		int fish;
		
		Player(int number, int fish) {
			this.number = number;
			this.fish = fish;
		}

		public int compareTo(Player o) {
			return this.fish == o.fish ? this.number - o.number : o.fish - this.fish;
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		Player p[];
		int n;
		
		n = sc.nextInt();
		p = new Player[n];
		for (int i = 0; i < n; i++) {
			p[i] = new Player(sc.nextInt(), sc.nextInt());
		}
		Arrays.sort(p);
		System.out.println(p[0].number + " " + p[0].fish);
	}
}

Measured memory_bytes: 17200
[N,M] = [int(e) for e in input().split()]
s=[]
for i in range(M):
  s.append([int(e) for e in input().split()])

p=[int(e) for e in input().split()]

ans=0
for i in range(2**N):
  check=1
  for j in range(M):
    sum=0
    for c in range(s[j][0]):
      sum += (i//(2**(s[j][c+1]-1)))%2
    if (sum%2)!=p[j]:
      check = 0
  if check ==1:
    ans += 1
print(ans)
      

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	int a, b, c;
	cin >> a >> b >> c;
	string d[100];
	int sum = 0;
	for (int e = 0; e < a; e++)cin >> d[e];
	for (int f = 0; f < a; f++) {
		for (int g = 0; g < b; g++) {
			int s = 0;
			for (int h = 0; g+h < b&&h<c; h++) {
				if (d[f][g+h] == '.')s++;
			}
			if (s == c)sum++;
		}
	}
	for (int f = 0; f < b; f++) {
		for (int g = 0; g < a; g++) {
			int s = 0;
			for (int h = 0; g + h < a&&h<c; h++) {
				if (d[g+h][f] == '.')s++;
			}
			if (s == c)sum++;
		}
	}
	cout << sum << endl;
}

Measured memory_bytes: 3140
#include <cstdio>  
#include <algorithm>
using namespace std;  
int main() { 	
	char a,b,c;
	char d;
	scanf("%c", &a);
	if(a=='A'){
		a='T';
	}
	else if(a=='T'){
		a='A';
	}
	if(a=='C'){
		a='G';
	}
	else if(a=='G'){
		a='C';
	}
	printf("%c", a);
	
	
}






Measured memory_bytes: 128
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num_traits::clamp;
use ordered_float::OrderedFloat;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        a: usize, b: usize,
    }

    let mut ans = Vec::new();
    for i in 0..100 {
        let c = if i < 50 { '#' } else { '.' };
        ans.push(vec![c; 100]);
    }

    for i in 0..a-1 {
        let x = (i % 50) * 2;
        let y = (i / 50) * 2;
        ans[y][x] = '.';
    }
    for i in 0..b-1 {
        let x = (i % 50) * 2;
        let y = 99 - (i / 50) * 2;
        ans[y][x] = '#';
    }
    println!("100 100");
    for chars in ans {
        let s = chars.into_iter().collect::<String>();
        println!("{}", s);
    }
}


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

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; }

const long long INF = 1LL << 60;

int main(){
  int x, a, b;
  cin >> x >> a >> b;

  cout << (x-a) % b << endl;

  return 0;
}


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

int main(void)
{
  string s;
  cin >> s;
  string sun = "Sunny";
  string clo = "Cloudy";
  string rai = "Rainy";
  if(s == sun)
    cout << clo << endl;
  if(s == clo)
    cout << rai << endl;
  if(s == rai)
    cout << sun << endl;
}

Measured memory_bytes: 256
import sys
def input():
    return sys.stdin.readline()[:-1]

N = int(input())
D = []
for i in range(N):
    temp = [0, 0]
    temp[0], temp[1] = map(int, input().split())
    D.append(temp)

count = 0
for i in range(N-2):
    if D[i][0]==D[i][1] and D[i+1][0]==D[i+1][1] and D[i+2][0]==D[i+2][1]:
        count = 1
        break
    else:
        pass

if count == 0:
    print('No')
elif count == 1:
    print('Yes')



Measured memory_bytes: 9204
(function(input) {
  var p = input.replace(/\n$/, '').split('\n');
  var w = Number(p.shift());
  var n = Number(p.shift());
  var W = [];
  for (var i = 0; i < w; i++) {
    W.push(i);
  }

  for (var i = 0; i < n; i++) {
    var args = p[i].split(',').map(Number);
    var a = args[0];
    var b = args[1];
    var tmp = W[a - 1];
    W[a - 1] = W[b - 1];
    W[b - 1] = tmp;
  }
  console.log(W.map(function(e) { return e + 1; }).join('\n'));
})(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7644
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int[] a = new int[N];
    int max = 0;
    for (int i = 0; i < N; i++){
      a[i] = scanner.nextInt();
      max += a[i];
    }

    if (max % 10 != 0) {
      System.out.println(max);
      return;
    }

    Arrays.sort(a);
    for (int i = 0; i < N; i++) {
      if (a[i] % 10 != 0) {
        System.out.println(max - a[i]);
        return;
      }
    }
    System.out.println(0);
  }
}


Measured memory_bytes: 24148
def push(x):
    top[0] += 1
    stack[top[0]] = x
    return

def pop():
    top[0] -= 1
    return stack[top[0]+1] 

if __name__ == "__main__":
    stack = [0]*1000
    top = [0]
    for s in input().split():
        if s not in ("+","-","*"):
            push(int(s))
            continue
        a = pop()
        b = pop()
        if s == "+":
            push(b+a)
        elif s == "-":
            push(b-a)
        else:
            push(b*a)
    print(pop())


Measured memory_bytes: 5600
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int[] a = new int[5];
		for(int i = 0; i < 5; i++){
			a[i] = sc.nextInt();
		}
		if((a[2]+a[4]) > a[0] || (a[3]+a[4]) > a[1] ||
				(a[2]-a[4]) < 0 || (a[3]-a[4]) < 0)System.out.println("No");
		else System.out.println("Yes");
}
}

Measured memory_bytes: 17360
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<deque>
#include<cmath>
#include<iomanip>
#include<map>
#include<cstring>

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const ll LLINF = 1LL<<60;
/* -- template -- */

int main(){
    deque<int>dQ;
    int N; cin >> N;
    int a[N];rep(i, N)cin >> a[i];
    rep(i, N){
        if(i % 2){
            dQ.push_front(a[i]);
        }else{
            dQ.push_back(a[i]);
        }
    }
    if(N % 2 == 0)
        for_each(dQ.begin(), dQ.end(), [](int x){
            cout << x << ' ';
        });
    else
        for_each(dQ.rbegin(), dQ.rend(), [](int x){
            cout << x << ' ';
        });
}


Measured memory_bytes: 3840
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() -> usize {
    input! {
        n: usize,
        q: usize,
        s: chars,
        mut queries: [(chars, chars); q],
    }
    queries.reverse();
    let mut l = 0usize;
    let mut r = n - 1;
    for (t, d) in queries {
        let t = t[0];
        let d = d[0];
        if d == 'L' {
            if s[l] == t {
                l += 1;
            }
            if r < n - 1 && s[r + 1] == t {
                r += 1;
            }
        } else {
            if s[r] == t {
                r -= 1;
            }
            if l > 0 && s[l - 1] == t {
                l -= 1;
            }
        }
        if l == r {
            return 0;
        }
    }
    r - l + 1
}

fn main() {
    let ans = solve();
    println!("{}", ans);
}

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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define MT make_tuple
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, start_index, num)  (a).begin()+(start_index),(a).begin()+(num)

int main() {
	int n, k;
	cin >> n >> k;
	vector<int>a(n+1);
	FOR(i, 1, n) {
		cin >> a[i];
	}
	int ih = 1;
	int it = k;
	FOR(i, k + 1, n) {
		if (a[it + 1] > a[ih]) {
			ps(Yes)
		}
		else {
			ps(No)
		}
		ih++;
		it++;
	}
	return 0;
}

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b){
  return a/gcd(a,b) * b;
}
ll func2(ll n){
  ll res = 0;
  while(n%2 == 0){
    n /= 2;
    res++;
  }
  return res;
}

ll zyou(ll a,ll b){//a＾b
  ll res = 1;
  for(int i = 1;i<=b;i++){
    res *= a;
  }
  return res;
}
struct Edge{
  int to;
  int weight;
  Edge(int t, int w) : to(t),weight(w){ }
};

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

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}



bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

bool palin(string S){//回文判定
  int n = S.size();
  bool flag = true;
  if(n%2 == 0){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  else if(n%2 == 1){
    for(int i = 0;i<=n/2-1;i++){
      if(S[i] != S[n-i-1]){
        flag = false;
        break;
      }
    }
  }
  return flag;
}



int main(){
  int a,b,c;
  cin >> a >> b >> c;
  vector<int> v = {a,b,c};
  int sum = a + b + c;
  int m = max(a,max(b,c));
  if(m == sum-m) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define upperlimit 1000100
#define INF 1000000100
#define INFL 1000000000000000100
#define eps 1e-8
#define endl '\n'
#define sd(n) scanf("%d",&n)
#define slld(n) scanf("%lld",&n)
#define pd(n) printf("%d",n)
#define plld(n) printf("%lld",n)
#define pds(n) printf("%d ",n)
#define pllds(n) printf("%lld ",n)
#define pdn(n) printf("%d\n",n)
#define plldn(n) printf("%lld\n",n)
#define REP(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define pb push_back
#define pcc pair<char,char>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define tr(container,it) for(typeof(container.begin()) it=container.begin();it!=container.end();it++)
#define F first
#define S second
#define clr(a) memset(a,0,sizeof(a))
using namespace std;

ll gcd(ll n1,ll n2){
    if(!n1)return n2;
    if(!n2)return n1;
    if(n1%n2==0)return n2;
    return gcd(n2,n1%n2);
}
ll powmod(ll base,ll exponent){
    base%=mod;
    ll ans=1;
    while(exponent){
        if(exponent&1)ans=(ans*base)%mod;
        base=(base*base)%mod;
        exponent/=2;
    }
    ans%=mod;
    return ans;
}
ll lcm(ll a,ll b){
    ll g=gcd(a,b);
    a/=g;
    a*=b;
    return a;
}
ll arr[upperlimit+1];
int main()
{
    int n,i,j,k;
    ll answer=1;
    sd(n);
    for(i=1;i<=n;i++){
        slld(arr[i]);
        answer=lcm(answer,arr[i]);
    }
    plldn(answer);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _LIBCPP_DEBUG 0
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;
int INF = 1 << 30;


int main(void){

    ll K; cin>>K;
    queue<ll> Q;
    for (int i = 1; i < 10; ++i) {
        Q.push(i);
    }

    ll ans = 0;
    for (int i = 0; i < K; ++i) {
        ans = Q.front(); Q.pop();
        if(ans%10 != 0) Q.push(ans*10+(ans%10)-1);
        Q.push(ans*10+ans%10);
        if(ans%10 != 9) Q.push(ans*10+(ans%10)+1);
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1792
import heapq
def solve():
  n = int(input())
  a = list(int(i) for i in input().split())
  an = []
  a2n = a[n:2*n]
  a3n = []
  for i in range(n):
    heapq.heappush(an,a[i])
    heapq.heappush(a3n,-1*a[i+2*n])
  ta2n = a2n
  
  tmpsuman = sum(an)
  tmpsuma3n = -1*sum(a3n)
  
  suman = [tmpsuman]
  suma3n = [tmpsuma3n]
  
  for i in range(n):
    tmp = ta2n[i]
    tmpsuman += tmp
    heapq.heappush(an,tmp)
    tmpsuman -= heapq.heappop(an)
    
    suman.append(tmpsuman)
  for i in range(n):
    tmp = ta2n[n-i-1]
    tmpsuma3n += tmp
    heapq.heappush(a3n,-1*tmp)
    tmpsuma3n -= -1*heapq.heappop(a3n)
    suma3n.append(tmpsuma3n)

  ans = -10000000000000000
  for i in range(n+1):
    tmpans = suman[i]-suma3n[n-i]
    ans = max(ans,tmpans)
  print(ans)
solve()

Measured memory_bytes: 120104
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

import           Control.Monad.Writer
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

main = do
  BS.getLine
  a <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  b <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ solve $ Cities (map MonsterCount a) (map SavePower b)

solve :: Cities -> Int
solve cities = getSum killResult
  where
    (_, KillResult killResult) = runWriter $ killThemAll cities

newtype MonsterCount =
  MonsterCount Int

newtype SavePower =
  SavePower Int

newtype KillResult =
  KillResult (Sum Int)
  deriving (Monoid)

data Cities =
  Cities
    { monsterCounts :: [MonsterCount]
    , saverPowers   :: [SavePower]
    }

killThemAll :: Cities -> Writer KillResult ()
killThemAll Cities {saverPowers = []} = writer ((), KillResult $ Sum 0)
killThemAll cities = do
  cities1 <- firstSaverSaveFirstCity cities
  cities2 <- firstSaverSaveSecondCity cities1
  killThemAll $ restCities cities2
  where
    firstSaverSaveFirstCity :: Cities -> Writer KillResult Cities
    firstSaverSaveFirstCity Cities {monsterCounts = m:ms, saverPowers = s:ss} =
      writer (Cities (mAfter : ms) (sAfter : ss), killCount)
      where
        (mAfter, sAfter, killCount) = kill m s
    firstSaverSaveSecondCity :: Cities -> Writer KillResult Cities
    firstSaverSaveSecondCity Cities { monsterCounts = m1:m2:ms
                                    , saverPowers = s:ss
                                    } =
      writer (Cities (m1 : m2After : ms) (sAfter : ss), killCount)
      where
        (m2After, sAfter, killCount) = kill m2 s
    kill :: MonsterCount -> SavePower -> (MonsterCount, SavePower, KillResult)
    kill (MonsterCount mc) (SavePower sp) =
      ( MonsterCount (mc - killCount)
      , SavePower (sp - killCount)
      , KillResult $ Sum killCount)
      where
        killCount :: Int
        killCount = min mc sp
    restCities :: Cities -> Cities
    restCities Cities {monsterCounts = m:ms, saverPowers = s:ss} = Cities ms ss


Measured memory_bytes: 12284
#include <stdio.h>
 
int main(void){
    int x,i;
    int a[100] = {0};
    
    scanf("%d",&x);
    
    for(i = 0;i < x; i++){
        scanf("%d",&a[x - 1 - i]);
    }
    for(i = 0; i < x - 1 ; i++){
        printf("%d ",a[i]);
    }
    if(i == x - 1){
        printf("%d\n",a[i]);
    }
     
    return 0;
}
 

Measured memory_bytes: 1860
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define INF (1ll<<60)
#define mod 1000000007
#define P pair<ll,ll>
#define Graph vector<vector<ll>>
#define fi first
#define se second
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; }

int main(){
    ll n;cin>>n;
    map<P,ll> weight;
    Graph G(n);
    rep(i,n-1){
        ll u,v,w;cin>>u>>v>>w;
        u--;v--;
        G[u].push_back(v);
        G[v].push_back(u);
        weight[{u,v}]=w;
        weight[{v,u}]=w;
    }

    queue<ll> que;
    que.push(0);
    vector<ll> dist(n),ans(n);
    vector<bool> visit(n,false);

    while(que.size()){
        ll now=que.front();
        que.pop();
        visit[now]=true;

        for(auto next:G[now]){
            if(visit[next]==true) continue;
            dist[next]=dist[now]+weight[{now,next}];

            if(dist[next]%2==0) ans[next]=0;
            else ans[next]=1;

            que.push(next);
        }
    }

    rep(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

int main(void) {
	int i, possibility;
	int m[3][3];
	int diff1, diff2;
	char buf[128], *ch;

	for(i = 0; i < 3; i += 1) {
		fgets(buf, sizeof(buf), stdin);
		ch = strtok(buf, " ");
		m[i][0] = atoi(ch);
		ch = strtok(NULL, " ");
		m[i][1] = atoi(ch);
		ch = strtok(NULL, " ");
		m[i][2] = atoi(ch);
	}

	diff1 = m[0][0] - m[1][0];
	diff2 = m[0][0] - m[2][0];

	possibility = 1;
	if(diff1 != m[0][1] - m[1][1] || diff1 != m[0][2] - m[1][2]) {
		possibility = 0;
	}
	if(diff2 != m[0][1] - m[2][1] || diff2 != m[0][2] - m[2][2]) {
		possibility = 0;
	}
	
	if(possibility == 1) {
		printf("Yes\n");
	} else {
		printf("No\n");
	}

	return 0;
}


Measured memory_bytes: 1988
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
ll table[100010];
ll N, K;
ll powmod(ll x,ll n){
    if(n == 0)return 1;
    ll ans = powmod(x*x%MOD,n/2);
    if(n % 2)ans = ans * x % MOD;
    return ans;
}
ll divmod(ll a,ll b){
    return ((a%MOD) * (powmod(b,MOD-2)%MOD)) % MOD;
}
void combi(ll r){
    ll num = 1;
    table[r-1] = 1;
    for(ll i = r;i <= N;i++){
        num = divmod(i * num, (i - r + 1));
        table[i] = num;
    }
}
main(){
    
    cin >> N >> K;
    if(K == 1){
        cout << 0 << endl;
        return 0;
    }
    
    if (K > 2) {
        combi(K-1);
    }else{
        rep(i,0,N+1)table[i] = 1;
    }
    rep(i,0,N+1){
        //cout << i << "C" << K-2 << ":" << table[i] << endl;
    }
    
    vector<int> V(N);
    rep(i,0,N)cin >> V[i];
    sort(V.begin(), V.end());
    vector<ll> accum(N+1);
    rep(i,0,N)accum[i+1] = accum[i] + V[i];
    //rep(i,0,N+1)cout << accum[i] << endl;
    ll ans = 0;
    rep(i,K-1,N){
        ll l, r,sum;
        //かぶる
        if(i * 2 < N){
            r = accum[N] - accum[N-i];
            l = accum[i] - accum[0];
            sum = (r - l + MOD) % MOD;
            //cout << l << " " << r << endl;
            //cout << "a " << sum << endl;
        }else{
            int x = N - i;
            r = accum[N] - accum[N-x];
            l = accum[x] - accum[0];
            sum = (r - l + MOD) % MOD;
            //cout << l << " " << r << endl;
            //cout << "b " << sum << endl;
        }
        ll tmp = sum * table[i-1] % MOD;
        ans = (ans + tmp) % MOD;
        //cout << i << " " << ans << endl;
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
map<int, int> s,t;
int main() {
	int n, m;
	int k;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &k);
		s[k]++;
	}
	scanf("%d", &m);
	for (int i = 0; i < m; i++) {
		scanf("%d", &k);
		t[k]++;
		if (t[k] > s[k]) {
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}

Measured memory_bytes: 18944
#include<stdio.h>
#include<math.h>

int main(){
  int i,j,k=0;
  int N;
  scanf("%d",&N);
  long A[N];
  for(i=0;i<N;i++){
    scanf("%d ",&A[i]);
    while(A[i] % 2 == 0){
      k++;
      A[i] /= 2;
    }
  }
  printf("%d\n",k);
  return 0;
}

  


Measured memory_bytes: 256