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

#define for_(i,a,b) for(int i=a;i<b;++i)
#define ALL(a) a.begin(),a.end()
#define INIT(a,b) memset(a,b,sizeof(a))
using lint = long long int;

class Combination {
private:
    const int N;
    const lint MOD;
    std::vector<lint> fact, inv;
    
    lint powmod(lint x, lint k) {
        lint res = 1;
        while (k) {
            if (k & 1) res = (res * x) % MOD;
            x = (x * x) % MOD;
            k >>= 1;
        }
        return res;
    }
    
    void precomputation() {
        fact[0] = fact[1] = 1;
        for (int i=2; i<=N; ++i) fact[i] = (fact[i-1] * i) % MOD;
        for (int i=0; i<=N; ++i) inv[i] = powmod(fact[i], MOD-2);
    }
    
public:
    Combination(int N, lint MOD) : N(N), MOD(MOD), fact(N + 1), inv(N + 1) {
        precomputation();
    }
    
    lint compute(int n, int k, bool duplicate = false) {
        if (duplicate) return compute(n+k-1, k);
        if (k == 0) return 1;
        if (n < k) return 0;
        lint res = fact[n];
        res = (res * inv[n-k]) % MOD;
        res = (res * inv[k]) % MOD;
        return res;
    }
};

lint powmod(lint x, lint k, lint MOD) {
	lint ret = 1;	
	while (k > 0) {
		if (k & 1) ret = (ret * x) % MOD;
        x = (x * x) % MOD;
		k >>= 1;
	}
	return ret;
}

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

    string S;
    cin >> S;

    int N = S.size();
    const lint MOD = lint(1e9) + 7;

    Combination comb(N + K, MOD);
    lint ans = 0;
    for_(i,0,K+1) {
        lint add = comb.compute(N, i, true);
        add = (add * powmod(25, i, MOD)) % MOD;
        add = (add * powmod(26, K - i, MOD)) % MOD;
        ans += add;
        ans %= MOD;
    }
    cout << ans << endl;
}

Measured memory_bytes: 35568
/* -----------------------------------------------------------------------------
	AtCoder Beginner Contest 140
	C - Maximal Value
	g++ bc140C.cpp

----------------------------------------------------------------------------- */
#include <cstdio>
#include <algorithm>

using namespace std;

#define MAX_N 101


/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;
int B[MAX_N];

int main () {

	int N;
	int sum = 0;

	// 個数の読込み
	scanf("%d", &N);
	// 数列 B
	for(int i = 1; i < N; i++) scanf("%d", B+i);
	
	//
	sum = B[1] + B[N-1];
	for(int i = 1;i <= N-2 ; i++) {
		sum += min(B[i], B[i+1]);
	}

	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000

int MOD=1000000007;
int modpow(int a,int x){
  if(a<0)a+=MOD;
  int ans=1;
  while(x>0){
    if(x&1) ans=ans*a%MOD;
      a=a*a%MOD;
      x>>=1;
  }
  return ans;
}

int gyaku(int n){
    return modpow(n,MOD-2);
}
////////////////////////////////////////////////////////////

signed main() {
  int x;
  cin>>x;
  rep(n,100000){
    if(x>=(n-1)*n/2+1&&x<=n*(n+1)/2){cout<<n<<endl;}
  }
}


Measured memory_bytes: 3572
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  map<int, int> C;
  cin >> N;
  rep(i, N) {
    int x;
    cin >> x;
    C[x]++;
  }
  long long s = 0;
  for (auto p : C) {
    if (p._2 >= p._1) s += p._2-p._1;
    else s += p._2;
  }
  cout << s <<"\n";
  return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;

class Main{




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		int[] a = new int[n];


		for(int i =0;i < n;i++){
			a[i] = sc.nextInt();
		}


		int f = 0;


		for(int i =0;i < n;i++){
			if(a[i] % 4 == 0){
				f++;		
			}
		}

		int t = 0;
		for(int i = 0;i < n;i++){
			if(a[i] % 4 != 0 && a[i] % 2 == 0){
				t ++;
			}
		}


		int odd = n-f-t;				//奇数

		if(odd <= f){
			System.out.println("Yes");
		}else{
			if(odd == f + 1 && t== 0){
				System.out.println("Yes");

			}else{

				System.out.println("No");
			}

		}

//
//
//		if((n-t) % 2 == 0){						//4で割り切れない偶数の個数が偶数こ
//
//			if(f >= (n-t)/2 ){
//				System.out.println("Yes");
//			}else{
//				System.out.println("No");
//
//			}
//		}else{
//			if(f >= ((n-t)/2)+1 ){
//				System.out.println("Yes");
//			}else{
//				System.out.println("No");
//
//			}


		
	}
}




Measured memory_bytes: 50156
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
inline ll read(){
	ll res=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=getchar();}
	while(ch>='0'&&ch<='9'){res=(res<<3)+(res<<1)+ch-'0';ch=getchar();}
	return res*f;
}
void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10|'0');
}
int a,b;
signed main(){
	a=read(),b=read();
	cout<<max(a-2*b,(ll)0)<<endl;
}


Measured memory_bytes: 256
<?php

fscanf(STDIN, "%d%d", $N,$T);
$town = fscanf(STDIN, str_repeat("%d", $N));

$min = PHP_INT_MAX;
$max = 0;
$max_count = 0;

foreach($town as $value){

    $min = min($value, $min);
    if($value - $min > $max){
        $max=$value-$min;
        $max_count = 1;
    }elseif($value-$min === $max){
        $max_count++;
    }

}

echo $max_count;

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

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 int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;

using namespace std;

int main() { 
    string S;
    cin >> S;
    if (S[0] == S[1] && S[1] == S[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0; 
}

Measured memory_bytes: 764
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;
//累乗(繰り返し2乗法)　aのb乗(mod)を求める。
long long int rui(long long int a, long long int b, long long mod) {
	if (b == 0) { return 1; }
	int memo[65] = {};
	long long int A[65] = {};
	long long int tmp = 1;
	for (int i = 0; i < 65; i++) {
		memo[i] = b % 2;
		b /= 2;
	}

	A[0] = a;
	A[0] %= mod;

	for (int i = 1; i < 65; i++) {
		A[i] = A[i - 1] * A[i - 1];
		A[i] %= mod;
	}
	for (int i = 0; i < 65; i++) {
		if (memo[i] == 1) {
			tmp *= A[i];
			tmp %= mod;
		}
	}
	tmp %= mod;
	return tmp;
}

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	long long int  s[200][200];
	//cout << fixed << setprecision(10);
	long long int n, m, k, a[200005] = {}, V[200001] = {}, R[200001], p[200001], res = 0;
	long long int sum = 0, two[20] = {1,2,4,8,16,32,64,128,256,512,1024,2048};
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> V[i];
	}

	for (int j = 1; j  <= min(k,n); j++) {

		long long int x[60], now = 0, cpk = k -  j;
		for (int q = 1; q <= j; q++) {
			x[now] = V[n - q + 1];
			now++;
		}
		now--;
		sort(x, x + now);
		long long int tmp = 0;
		for (int q = 0; q <= now; q++) {
			if (x[q] < 0 && cpk>0) {
				cpk--;
				continue;
			}
			else {
				tmp += x[q];
			}
		}
		if (res < tmp) { res = tmp; }
	}


	for (int j = 1; j <= min(k, n); j++) {

		long long int x[60], now = 0, cpk = k - j;
		for (int q = 1; q <= j; q++) {
			x[now] = V[q];
			now++;
		}
		now--;
		sort(x, x + now);
		long long int tmp = 0;
		for (int q = 0; q <= now; q++) {
			if (x[q] < 0 && cpk>0) {
				cpk--;
				continue;
			}
			else {
				tmp += x[q];
			}
		}
		if (res < tmp) { res = tmp; }
	}


	for (int i = 1; i <= min(k, n); i++) {
		for (int j = 1; j+i <= min(k, n); j++) {

			long long int x[60], now = 0,cpk=k-i-j;
			for (int q = 1; q <= j; q++) {
				x[now] = V[n-q+1];
				now++;
			}
			for (int q = 1; q <= i; q++) {
				x[now] = V[q];
				now++;
			}
			now--;
			sort(x, x + now);
			long long int tmp=0;
			for (int q = 0; q <=now; q++) {
				if (x[q] < 0 && cpk>0) {
					cpk--;
					continue;
				}
				else {
					tmp += x[q];
				}
			}
			if (res < tmp) { res = tmp; }
		}

	}
	cout << res;
}


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

int main() {
  ll N = 0, M = 0;
  cin >> N >> M;
  if(M % 2 == 1){
    cout << "No";
    return 0;
  }
  if(N * 4 >= M && N * 2 <= M){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}
    
    

Measured memory_bytes: 3644
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

bool check(vll &a,ll div,ll k){
	if(div==2){
		ll sum = 0 ;
		for(int i=0;i<a.size();i++) sum += (a.at(i)&1) ;
		return (sum/2<=k) ;
	}else{
		vll mn,mx ;
		ll mnsum=0,mxsum=0 ;
		for(int i=0;i<a.size();i++){
			ll d = a.at(i)%div ;
			if(d<=div/2){
				mn.emplace_back(d) ;
				mnsum += d ;
			}else{
				mx.emplace_back(div-d) ;
				mxsum += div-d ;
			}
		}
		if(mnsum<mxsum){
			ll res = mnsum ;
			mxsum -= mnsum ;
			mysort(mx) ;
			ll cnt = 0 ;
			for(int i=mx.size()-1;i>=0;i--){
				if(mxsum==cnt) break ;
				res += div-mx.at(i) ;
				cnt += div ;
			}
			return (res<=k) ;
		}else{
			ll res = mxsum ;
			mnsum -= mxsum ;
			mysort(mn) ;
			ll cnt = 0 ;
			for(int i=mn.size()-1;i>=0;i--){
				if(mnsum==cnt) break ;
				res += div-mn.at(i) ;
				cnt += div ;
			}
			return (res<=k) ;
		}
	}
}

int main(){
	ll n,k ;
	cin >> n >> k ;
	vll a(n) ;
	ll sum = 0 ;
	for(int i=0;i<n;i++){
		cin >> a.at(i) ;
		sum += a.at(i) ;
	}
	vll div ;
	for(ll i=1;i*i<=sum;i++){
		if(sum%i==0){
			div.push_back(i) ;
			div.push_back(sum/i) ;
		}
	}
	mysort(div) ; myrev(div) ;
	for(int i=0;i<div.size();i++){
		if(check(a,div.at(i),k)){
			cout << div.at(i) << endl ;
			return 0 ;
		}
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();


int main() {
	char c;
 	cin >> c;
 	c += 1;
  	cout << c << endl;

    return 0;
}



Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

// c++11
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>

#define mp make_pair
#define mt make_tuple
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
template <class T>
using max_priority_queue = priority_queue<T>;
template <class T>
using min_priority_queue = priority_queue<T, std::vector<T>, std::greater<T>>;

const int INF = 1 << 29;
const ll LL_INF = 1LL << 60;
const double EPS = 1e-9;
const ll MOD = 1000000007;

const int dx[] = {1, 0, -1, 0}, dy[] = {0, -1, 0, 1};
const int MAX_N = 200010;
int N;
vector<ll> A;
ll sum[MAX_N];
ll query(int l, int r)
{
  return sum[r] - sum[l - 1];
}

int calc(const int left, const int right)
{
  int l = left;
  int r = right;

  while (r - l > 1)
  {
    int med = (r + l) / 2;
    // cerr << "l = " << l << " r = " << r << " med = " << med << endl;
    ll sum_left = query(left, med);
    ll sum_right = query(med + 1, right);
    if (med < left)
    {
      l = med;
      continue;
    }
    if (med + 1 > right)
    {
      r = med;
      continue;
    }
    if (sum_left >= sum_right)
    {
      r = med;
    }
    else
    {
      l = med;
    }
  }
  ll res1 = abs(query(left, r) - query(r + 1, right));

  ll med = (l + r) / 2;
  ll res2 = abs(query(left, med) - query(med + 1, right));
  if (res1 > res2)
  {
    return med;
  }
  return r;
}

ll solve()
{
  ll result = LL_INF;
  for (int med_id = 2; med_id <= N - 2; med_id++)
  {
    int a = calc(1, med_id);
    int b = calc(med_id + 1, N);
    ll min_val = LL_INF;
    ll max_val = -LL_INF;

    ll P = query(1, a);
    min_val = min(min_val, P);
    max_val = max(max_val, P);

    ll Q = query(a + 1, med_id);
    min_val = min(min_val, Q);
    max_val = max(max_val, Q);

    ll R = query(med_id + 1, b);
    min_val = min(min_val, R);
    max_val = max(max_val, R);

    ll S = query(b + 1, N);
    min_val = min(min_val, S);
    max_val = max(max_val, S);

    result = min(result, abs(max_val - min_val));
    // cerr << med_id << " " << a << " " << b << endl;
    // cerr << P << " " << Q << " " << R << " " << S << " " << abs(max_val - min_val) << endl;
    // cerr << endl;
  }
  return result;
}
int main()
{
  cin >> N;
  A.resize(N);
  for (auto &val : A)
  {
    cin >> val;
  }
  for (int i = 1; i <= N; i++)
  {
    sum[i] = A[i - 1];
  }
  for (int i = 1; i < MAX_N - 1; i++)
  {
    sum[i] += sum[i - 1];
  }
  cout << solve() << endl;
  return 0;
}


Measured memory_bytes: 3328
import numpy as np

N = int(input())
A = []
A = np.array(list(map(int, input().split())))
Q = int(input())
B = []
C = []
for _ in range(Q):
    b,c = map(int, input().split())
    B.append(b)
    C.append(c)

m = max(max(A), max(B), max(C))+1
res = np.arange(m,dtype=int)
newA = np.zeros((m),dtype=int)


for a in A:
    newA[a] += 1

sum_r = np.dot(res,newA)


for i in range(Q):
    b = B[i]
    c = C[i]
    sum_r = sum_r - b*newA[b] + c*newA[b]
    print(sum_r)
    newA[c] += newA[b]
    newA[b] = 0

Measured memory_bytes: 38864
#include <stdio.h>

int main(void) {
	int a,b;
	char op;
	
	while(1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='?')break;
	
	switch(op){
		case '+':printf("%d\n",a+b);
		break;
		case '-':printf("%d\n",a-b);
		break;
		case '*':printf("%d\n",a*b);
		break;
		case '/':printf("%d\n",a/b);
		break;
	}
	}
	return 0;
}

Measured memory_bytes: 1824
using System; 
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
    static void Main(string[] args) {
        
        var D = int.Parse(Console.ReadLine());
        
        if(D == 25){
            Console.WriteLine("Christmas");
        }else if(D == 24){
            Console.WriteLine("Christmas Eve");
        }else if(D == 23){
            Console.WriteLine("Christmas Eve Eve");
        }else{
            Console.WriteLine("Christmas Eve Eve Eve");
        }
        
        
     }
     
}
     
     
                   
public class PriorityQueue<T> : IEnumerable<T> { private readonly List<T> _data = new List<T>(); private readonly IComparer<T> _comparer; private readonly bool _isDescending; public PriorityQueue(IComparer<T> comparer, bool isDescending = true) { _comparer = comparer; _isDescending = isDescending; } public PriorityQueue(Comparison<T> comparison, bool isDescending = true) : this(Comparer<T>.Create(comparison), isDescending) { } public PriorityQueue(bool isDescending = true) : this(Comparer<T>.Default, isDescending) { } public void Enqueue(T item) { _data.Add(item); var childIndex = _data.Count - 1; while (childIndex > 0) { var parentIndex = (childIndex - 1) / 2; if (Compare(_data[childIndex], _data[parentIndex]) >= 0) break; Swap(childIndex, parentIndex); childIndex = parentIndex; } } public T Dequeue() { var lastIndex = _data.Count - 1; var firstItem = _data[0]; _data[0] = _data[lastIndex]; _data.RemoveAt(lastIndex--); var parentIndex = 0; while (true) { var childIndex = parentIndex * 2 + 1; if (childIndex > lastIndex) break; var rightChild = childIndex + 1; if (rightChild <= lastIndex && Compare(_data[rightChild], _data[childIndex]) < 0) childIndex = rightChild; if (Compare(_data[parentIndex], _data[childIndex]) <= 0) break; Swap(parentIndex, childIndex); parentIndex = childIndex; } return firstItem; } public T Peek() { return _data[0]; } private void Swap(int a, int b) { var tmp = _data[a]; _data[a] = _data[b]; _data[b] = tmp; } private int Compare(T a, T b) { return _isDescending ? _comparer.Compare(b, a) : _comparer.Compare(a, b); } public int Count => _data.Count; public IEnumerator<T> GetEnumerator() { return _data.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); }


Measured memory_bytes: 11092
from datetime import datetime,timedelta

a=input().split()
a=[int(_) for _ in a]

t1=datetime(2000,1,1,a[0],a[1],0)
t2=datetime(2000,1,1,a[2],a[3],0)

delta=t2-t1
total_seconds=delta.seconds

ans=(total_seconds-a[4]*60)/60
print(int(ans))


Measured memory_bytes: 9436
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.TreeMap;
import java.util.Map;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    Map<String, Integer> map = new TreeMap<String, Integer>();
    for (int i = 0; i < num; i++) {
      String[] tmp = br.readLine().split(" ");
      String point = ("0".equals(tmp[1])) 
        ? "XXX" : String.valueOf(1000 - Integer.parseInt(tmp[1]));
      map.put(tmp[0] + point, i + 1);
    }
    for (String key : map.keySet()) {
      System.out.println(map.get(key));
    }
  }
}

Measured memory_bytes: 23380
#include <stdio.h>
int main(void) {
  int a, b, c;
  scanf("%d%d%d",&a,&b,&c);
  if( (a == 1 && b == 1) || (c == 1) ) {
    puts("Open");
  } else {
    puts("Close");
  }
  return(0);
}
      

Measured memory_bytes: 584
n=int(input())
a=sorted(list(map(int,input().split())),reverse=True)

def mid(a):
    if(a%2!=0):
        return (a+1)//2
    else:
        return a//2

ai=a[0]
temp=list(map(lambda x:abs(x-mid(ai)),a[1:]))
bi=a[temp.index(min(temp))+1]
print(str(ai)+" "+str(bi))

Measured memory_bytes: 14428
#include<iostream>

using namespace std;

int main()
{
	int n;
	cin>>n;
  int ctr = 0;
  	for(int a = 1; a < n; a++)
    {
      for (int b = 1; b < n; b++)
      {
        	int c = n - (a * b);
        	if(c <= 0)
            {
              break;
            }
        	ctr++;
      }
    }
  cout<<ctr;
}


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

int main() {
    int N;
    cin >> N;
    vector<int> A(N + 1);
    for (int i = 0; i < N + 1; i++)
        cin >> A[i];
    vector<int> B(N);
    for (int i = 0; i < N; i++)
        cin >> B[i];

    long long res = 0;
    for (int i = 0; i < N; i++) {
        res += min(A[i], B[i]);
        if (A[i] < B[i]) {
            int t = B[i] - A[i];
            res += min(A[i + 1], t);
            A[i + 1] = max(0, A[i + 1] - t);
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
while True:
	a,b,c=map(int,input().split())
	if a == -1 and b == -1 and c == -1:
		break
	elif a == -1 or b == -1:
		print("F")
	elif 80 <= a + b:
		print("A")
	elif 65 <= a + b:
		print("B")
	elif 50 <= a + b:
		print("C")
	elif 30 <= a + b:
		if c  < 50:
			print("D")
		else:
			print("C")
	else:
		print("F")



Measured memory_bytes: 5592
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end()
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

typedef pair<int,int> pii;
typedef long long ll;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int h,a;
	cin >> h >> a;
	cout << (h+a-1)/a << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
#define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 20;

ll n,a,b,ans;

inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}
	while (ch >= '0' && ch <= '9'){x = (x << 3) + (x << 1) + ch - '0';ch = getchar();}
	return x * f;
}

int main()
{
	n=read();
	a=n/500;
	n-=a*500;
	b=n/5;
	ans=a*1000+b*5;
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
// C++のテンプレート
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>

using namespace std;

int main(void){
    int N,sum=0;
    cin >> N;
    for(int i=1;i<=N;i++){
        sum+=i;
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
s = input()
stack = [s[0]]
for i in range(1,len(s)):
    if len(stack)==0:
        stack.append(s[i])
        continue
    else:
        cur_str = stack[-1]
        new_str = s[i]
        if cur_str+new_str=="ST":
            stack.pop()
        else:
            stack.append(new_str)
print(len(stack))


Measured memory_bytes: 4864
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		sc.close();
		long li2 = 2L;
		long ans = 1L;
		long tmp = 0L;
		for (i = 2; i <= n; i++) {
			tmp = ans + li2;
			li2 = ans;
			ans = tmp;
		}
		out.println(ans);
	}
}


Measured memory_bytes: 23892
#define N 100001 
long p[N],r[N],n,m,i,b[N],a[N][2],c,d;int f(int x){if(p[x]==x)return x;return f(p[x]);}int u(int x,int y){x=f(x);y=f(y);if(r[x]<r[y])p[x]=y;else p[y]=x;r[y]+=r[x];r[x]=r[y];}int main(){scanf("%ld%ld",&n,&m);for(i=0;i<m;i++)scanf("%d%d",a[i],&a[i][1]);b[m]=n*(n-1)/2;for(i=0;i<N;i++){p[i]=i;r[i]=1;};for(i=m-1;i>0;i--){c=a[i][0],d=a[i][1];if(f(c)==f(d))b[i]=b[i+1];else{b[i]=b[i+1]-r[f(c)]*r[f(d)];u(c,d);}}for(i=1;i<=m;i++)printf("%ld\n",b[i]);}

Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl
#define YORN(f) cout<<((f)?"YES":"NO")<<endl
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

string toUpper(string str) {
    std::transform(str.begin(), str.end(),str.begin(), ::toupper);
    return str;
}

int main()
{
    string a, b, c;
    cin >> a >> b >> c;
    a = toUpper(a);
    b = toUpper(b);
    c = toUpper(c);

    cout << a[0] << b[0] << c[0] << endl;
    return 0;
}

Measured memory_bytes: 3596
from sys import exit

S = input()

first = int(S[0] + S[1])
second = int(S[2] + S[3])

mm_first = True

mm_second = True

if 1 <= first <= 12:
    mm_first = True
else:
    mm_first = False

if 1 <= second <= 12:
    mm_second = True
else:
    mm_second = False

if mm_first and mm_second:
    print('AMBIGUOUS')
elif mm_first and not mm_second:
    print('MMYY')
elif not mm_first and mm_second:
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#define INF (1e9)
#define J 1999
#define N 50
using namespace std;
int main(){
  int n,c[N],dp[J],dn[J],C=0;
  while(1){
    cin>>n;
    if(!n) break;
    for(int i=0;i<n;i++) cin>>c[i];
    for(int i=0;i<J;i++) dp[i]=dn[i]=INF;
    sort(c,c+n);
    dp[0]=0;
    for(int i=0;i<n;i++)
      for(int j=1;j<J;j++)
	if(j>=c[i]) dp[j]=min(dp[j],dp[j-c[i]]+1);
    sort(c,c+n);
    reverse(c,c+n);
    for(int i=0;i<J;i++){
      int cnt=0,sum=i;
      for(int j=0;j<n;j++){
	cnt+=sum/c[j];
	sum%=c[j];
      }
      if(sum==0) dn[i]=cnt;
    }
    int flag=0;
    for(int i=1;i<J;i++){
      if(dp[i]==INF||dn[i]==INF){
	flag=1;
	break;
      }
      if(dp[i]!=dn[i]){
	flag=2;
	break;
      }
    }
    C++;
    cout<<"Case #"<<C<<": ";
    if(!flag) cout<<"OK"<<endl;
    else if(flag==1) cout<<"Cannot pay some amount"<<endl;
    else cout<<"Cannot use greedy algorithm"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG_ 
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

int main(void) {
    ll n;
    cin >> n;
    vector<char> c(2*n);
    vector<ll> a(2*n);
    REP(i, 2*n) cin >> c[i] >> a[i];

    vector<ll> bpos(n+1), wpos(n+1);
    REP(i, 2*n) {
        if(c[i] == 'W') wpos[a[i]] = i;
        else bpos[a[i]] = i;
    }

    vector<vector<ll>> bcnt(n+1, vector<ll>(2*n)), wcnt(n+1, vector<ll>(2*n));
    REP(i, 2*n) {
        if(c[i] == 'W') {
            FOR(j, a[i], n+1) wcnt[j][i]++;
        } else {
            FOR(j, a[i], n+1) bcnt[j][i]++;
        }
    }
    REP(i, n+1) FOR(j, 1, 2*n) {
        wcnt[i][j] += wcnt[i][j-1];
        bcnt[i][j] += bcnt[i][j-1];
    }
    // FOR(i, 1, n+1) dump(wcnt[i]);

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, INF));
    dp[0][0] = 0;
    REP(i, n+1) REP(j, n+1) {
        if(i+1<=n) {
            ll add = bpos[i+1] - bcnt[i][bpos[i+1]] - wcnt[j][bpos[i+1]];
            chmin(dp[i+1][j], dp[i][j] + add);
        }
        if(j+1<=n) {
            ll add = wpos[j+1] - bcnt[i][wpos[j+1]] - wcnt[j][wpos[j+1]];
            chmin(dp[i][j+1], dp[i][j] + add);
        }
    }
    cout << dp[n][n] << endl;

    return 0;
}

Measured memory_bytes: 156928
def min_cal(A):
    n=len(A)
    ls=[[0 for i in range(n)] for i in range(n)]
    for i in range(n):
        ls[i][i]=0
    for i in range(1,n):
        for j in range(n-i):
            ls[j][i+j]=min([ls[j][k]+ls[k+1][i+j]+A[k][1]*A[j][0]*A[i+j][1] for k in range(j,i+j)])
    return ls[0][n-1]

n=int(input())
Mats=[]
for i in range(n):
    Mats.append([int(i) for i in input().split()])

print(min_cal(Mats))


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

int main()
{
	int n,a[100005],i,x=0;
	
	cin>>n;
	
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=n-2;i>=0;i--){
		if(a[i]-a[i+1]>1){
			x=1;
			break;
		}
		else if(a[i]-a[i+1]==1){
			a[i]--;
		}
	}
	if(x==0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

Measured memory_bytes: 640
j;i;k;t;main(n){
int c[501],f[500],s[500];
for(scanf("%d",&n);k<n-1;k++)scanf("%d%d%d",&c[k],&s[k],&f[k]);
            
for(;i<n-1;i++){
	t=0;
	for(j=i;j<n-1;j++){
		if(t>s[j]) t=s[j]+c[j]+ceil( (double)(t-s[j])/f[j] )*f[j];
		else t=s[j]+c[j];
	}
	printf("%d\n",t);
}
printf("0");
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
main(){
    int N[3],num=3;
    cin >> N[0] >> N[1] >> N[2];
    sort(N,N+3);
    if(N[0]==N[1])num--;
    if(N[1]==N[2])num--;
    cout << num << endl;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a == b+c || b == a+c || c == a+b)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<deque>
#include<tuple>
#include<iomanip>
using namespace std;
#define endl               '\n'
#define gap                ' '
#define MAX                LLONG_MAX
#define MIN                LLONG_MIN
#define min3(a,b,c)        min(a, min(b, c))
#define max3(a,b,c)        max(a, max(b, c))
#define MOD                1000000007
#define PI                 3.1415926535897932384626433832795
#define nps                string::npos
#define int                int64_t
#define double             long double
#define vi                 vector<int>
#define di                 deque<int>
#define si                 set<int>
#define vpii               vector<pair<int,int>>
#define dpii               deque<pair<int,int>>
#define pi                 pair<int,int>
#define pub                push_back
#define puf                push_front
#define pob                pop_back
#define pof                pop_front
#define all(a)             (a).begin(),(a).end()
#define rall(a)            (a).rbegin(),(a).rend()
#define rep(i, s, n)       for(int i = s; i < n; ++i)
#define repe(i, s, n)      for(int i = s; i <= n; ++i)
#define repr(i, n, s)      for(int i = n; i >= s; --i)
#define read(a)            for(auto& x : a) cin >> x
#define speak(a)           for(auto x : a) cout << x << ' '
#define work(x, a)         for(auto& x : a)
//freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
int32_t main() {
    ios_base::sync_with_stdio (false);
    cin.tie (0);
    int n, c = 0;
    cin >> n;
    rep (i, 0, n) {
        int x;
        cin >> x;
        if (x % 2 == 1 and (i + 1) % 2 == 1) {
            c++;
        }
    }
    cout << c;
}


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

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

    for (int i = 0; i < 50000; ++i)
    {
        if (int(i * 1.08) == n)
        {
            cout << i << endl;
            break;
        }
        else if (i * 1.08 > n)
        {
            cout << ":(" << endl;
            break;
        }
    }
}

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

#define MIN(x, y) ((x) < (y) ? (x) : (y))
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#define ABS(x, y) ((x) > (y) ? ((x) - (y)) : ((y) - (x)))

#define DIVUP(x, y) (((x) + ((y) - 1)) / (y))
#define DIVOFF(x, y) (((x) + ((y) / 2)) / (y))
#define REMAINDER(x, y) ((x) % (y))

int main() {
  int N, H, W;
  scanf("%d", &N);
  scanf("%d", &H);
  scanf("%d", &W);

  printf("%d\n", (N - H + 1) * (N - W + 1));
  return 0;
}


Measured memory_bytes: 760
#include<bits/stdc++.h>
#define INF 999999
#define MAX_V 10000
using namespace std;

typedef struct edge{
  int to,cap,rev;
}edge;

int val[MAX_V];
vector<edge> G[MAX_V];
bool used[MAX_V];

bool gcd(int a,int b){
  int r=a%b;
  while(r>0){
    a=b;
    b=r;
    r=a%b;
  }
  if(b!=1)return true;
  else return false;
}

void makeG(int m,int n){
  memset(G,0,sizeof(G));
  int to;
  for(int i=0;i<m+n;i++){
    cin>>val[i];
  }
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++){
      if(gcd(val[i],val[m+j])==true){
	G[i].push_back((edge){m+j,1,G[m+j].size()});
	G[m+j].push_back((edge){i,0,G[i].size()-1});
      }
    }
  }
  val[m+n]=val[m+n+1]=1;
  for(int i=0;i<m;i++){
    G[m+n].push_back((edge){i,1,G[i].size()});
    G[i].push_back((edge){m+n,0,G[i].size()-1});
  }
  for(int i=m;i<m+n;i++){
    G[i].push_back((edge){m+n+1,1,G[m+n+1].size()});
    G[m+n+1].push_back((edge){i,0,G[i].size()-1});
  }
}

int dfs(int v,int t,int f){
  if(v==t)return f;
  used[v] = true;
  for(int i=0;i<G[v].size();i++){
    edge &e=G[v][i];
    if(!used[e.to] && e.cap > 0){
      int d=dfs(e.to,t,min(f,e.cap));
      if(d>0){
	e.cap-=d;
	G[e.to][e.rev].cap+=d;
	return d;
      }
    }
  }
  return 0;
}

int max_flow(int s,int t){
  int flow=0;
  for(;;){
    memset(used,0,sizeof(used));
    int f=dfs(s,t,INF);
    if(f==0)return flow;
    flow+=f;
  }
}

int main(){
  int m,n;
  while(cin>>m>>n,n){
    makeG(m,n);
    cout << max_flow(m+n,m+n+1) << endl;
  }
  return 0;
}

Measured memory_bytes: 61528
N,M = map(int,input().split())
AB = []
for i in range(M):
    a,b = map(int,input().split())
    AB.append((a,b))

AB.sort()

Ans = 0
l,r = 1,N
for ab in AB:
    a,b = ab
    if r <= a:
        Ans += 1
        l,r = a,b
    else:
        l = max(l,a)
        r = min(r,b)
else:
    Ans += 1

print(Ans)

Measured memory_bytes: 17012
n=int(input())
s=input()
W=[0]*(n+1) #Wについての累積和
E=[0]*(n+1) #Eについての累積和
e=0
w=0
for i in range(n):
    if s[i]=="W":
        w += 1
    else:
        e += 1
    
    W[i+1] = w
    E[i+1] = e
ans = 10**10
for i in range(n):
    tmp = W[i] + (E[n]-E[i+1])
    ans = min(ans,tmp)
print(ans)



Measured memory_bytes: 23484
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>


using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) { return n ? 1 + __builtin_popcount(n & (n - 1)) : 0; }
#endif

#define foreach(it, c) for (__typeof__((c).begin()) it=(c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))

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

template <class T> void max_swap(T& a, const T& b) { a = max(a, b); }
template <class T> void min_swap(T& a, const T& b) { a = min(a, b); }

typedef long long ll;
typedef pair<int, int> pint;

const double EPS = 1e-8;
const double PI = acos(-1.0);
const int dx[] = { 0, 1, 0, -1 };
const int dy[] = { 1, 0, -1, 0 };



int main()
{
	int n, m, c[32], x[21919];
	while (cin >> n >> m, n)
	{
		for (int i = 0; i < m; ++i)
			cin >> c[i];
		for (int i = 0; i < n; ++i)
			cin >> x[i];

		static ll dp[21919][256];
		const ll INF = 1LL << 55;
		for (int i = 0; i <= n; ++i)
			for (int j = 0; j <= 255; ++j)
				dp[i][j] = INF;

		dp[0][128] = 0;
		for (int i = 0; i < n; ++i)
		{
			for (int j = 0; j <= 255; ++j)
			{
				for (int k = 0; k < m; ++k)
				{
					int y = max(0, min(255, j + c[k]));
					int s = x[i] - y;
					min_swap(dp[i + 1][y], dp[i][j] + s * s);
				}
			}
		}
		cout << *min_element(dp[n], dp[n] + 256) << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            String ss = s.substring(i, i + 1);
            if (i != b - 1) {
                System.out.print(ss);
            } else {
                String tmp = ss.toLowerCase();
                System.out.print(tmp);
            }
        }
        System.out.println("");
        sc.close();
    }
}

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

int main(void){
  int box[3] = {1,0,0};
  char s,c,f;
  while(cin>>s>>c>>f){
    int w = box[s-'A'];
    box[s-'A']=box[f-'A'];
    box[f-'A']=w;
  }
  for(int i = 0 ; i < 3 ; i ++)
    if(box[i]==1)
      cout<<char(i+'A')<<endl;
  return 0;
}

Measured memory_bytes: 1132
#include <iostream>
using namespace std;
void a()
{
  int a, b, c;
  cin >> a >> b >> c;
  if (b / a >= c)
    cout << c;
  else
  {
    cout << b / a;
  }
}
void b()
{
  int a, b, k;
  cin >> a >> b >> k;
  int itr = 0;
  int ans = a;
  if (b < a)
    ans = b;
  ans++;
  while (itr != k)
  {
    ans--;
    if (a % ans == 0 && b % ans == 0)
      itr++;
  }
  cout << ans;
}
int main(void)
{
  b();
  //a();
}


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

namespace ABC
{
    class ProgramC
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var h = Console.ReadLine().Split(" ").Select(x => int.Parse(x)).ToList();
            var l = new int[n];

            var result = 0;
            for (var i = 0; i < n; i++)
            {
                while (l[i] < h[i])
                {
                    result++;
                    var count = i;
                    while (count < n && l[count] < h[count])
                    {
                        l[count]++;
                        count++;
                    }
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 28328
A = int(input())
B = [int(x) for x in input().split()]
count = 1
tanking = 0
ans = 0
flag = False
for i in range(A):
    if B[i] == count:
        count += 1
        ans += tanking
        tanking = 0
        flag = True
    else: 
        tanking += 1
        if i == A-1:
            ans+= tanking

if not flag:print("-1")
else : print(ans)





Measured memory_bytes: 26012
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) begin(x), end(x)
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;
constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;
template <typename T> constexpr bool chmax(T &a, const T &b) {
    if(a >= b) return false;
    a = b;
    return true;
}
template <typename T> constexpr bool chmin(T &a, const T &b) {
    if(a <= b) return false;
    a = b;
    return true;
}

/*-------------------------------------------*/

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

    int s, w;
    cin >> s >> w;
    puts((s <= w ? "unsafe" : "safe"));

    return 0;
}

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
//const ll MOD = 1000000007;
const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'

// 1825

int main() {
  int n, m;
  cin >> n >> m;
  vii s(m);
  rep (i, m) {
    int k;
    cin >> k;
    s[i].resize(k);
    rep (j, k) {
      cin >> s[i][j];
      s[i][j]--;
    }
  }

  vi p(m);
  rep (i, m) cin >> p[i];

  int ans = 0;
  rep (i, (1 << n)) {
    bool flag = true;
    rep (j, m) {
      int cnt = 0;
      rep (k, s[j].size()) {
        int ss = s[j][k];
        if (i & (1 << ss)) cnt++;
      }
      if (cnt % 2 != p[j]) flag = false;
    }
    ans += flag;
  }
  cout << ans << endl;
}




Measured memory_bytes: 256
s = s=input()
left = int(s[:2])
right = int(s[2:])

if left > 0 and left <= 12:
    if right > 0 and right <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
elif right > 0 and right <= 12:
    print('YYMM')
else:
    print('NA')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9+7;

int main(){
	
	int x; cin>>x;
	if(x>2000) {
		cout << 1 << endl;
		return 0;
	}
	else{
		int a=100, b=105;
		for(int i=1; i<=20; i++){
			if(a*i<=x&&x<=b*i){
				cout << 1 << endl;
				return 0;
			}
		}
	}
	cout << 0 << endl;
	
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n, a[100], ans = 0;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    for (int i = 0; i < n; ++i) {
        for (int j = n - 1; j > i; --j) {
            if (a[j - 1] > a[j]) {
                swap(a[j - 1], a[j]);
                ans++;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << a[i];
        if (i < n - 1)
            cout << " ";
    }
    cout << endl << ans << endl;

    return 0;
}


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

int main() {
	int n;
	string s, t;
	cin >> n >> s >> t;
	int ans = (int)(s.size() + t.size());
	rep(i, n) {
		bool ok = true;
		rep(j, n - i) {
			if (s[i + j] != t[j]) ok = false;
		}
		if (ok) {
			ans = 2 * i + (n - i);
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define max(a, b) (a > b ? a : b)
#define min(a, b) (a < b ? a : b)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())

// https://atcoder.jp/contests/abc137/submissions/6847236

int p;
const ll INF = 1e18; // O(|V||E|)
int MAX_V = 3000;
vector<ll> d(2501, INF); // 0からの時間
int n, e, r; // 頂点、辺、スタート
bool bell(int n, vector<vector<pii> > edge, int s) {
    d[s] = 0;
    
    rep(cnt, 2 * MAX_V) {
        
        rep(from, n) {
            if (d[from] == INF) continue;
            rep(j, SZ(edge[from])) {
                int to = edge[from][j].F;
                int cost = edge[from][j].S;
                
                if (d[to] > d[from] + cost) {
                   
                    d[to] = d[from] + cost;
                    if (cnt >= MAX_V - 1) {
                        d[to] = -INF;
                        if (to == n - 1) return 0;
                    }
                }
            }
        }
        
    }
    
    return 1;
    
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> e >> p;
    
    vector<vector<pii> > edge(n);
    rep(i, e) {
        int s, t, d;
        cin >> s >> t >> d;
        s--; t--;
        d = d - p;
        edge[s].eb(t, -d);
    }
    
    if (bell(n, edge, r) == 0) {
        out(-1);
    } else {
        out(max(0LL, -d[n - 1]));
    }
    
}


Measured memory_bytes: 512
import java.util.*;



import java.io.*;
public class Main {

	public static void main(String[] args) {
	FastScanner sc=new FastScanner();
	int n=sc.nextInt();
	int a[]=sc.readArray(n);
	if(n<=1)
		System.out.println("0");
	else {
		int dp[]=new int[n];
		dp[0]=0;
		dp[1]=Math.abs(a[1]-a[0]);
		
		for(int i=2;i<n;i++)
		{
			dp[i]=Math.min(dp[i-1]+Math.abs(a[i]-a[i-1]), dp[i-2]+Math.abs(a[i]-a[i-2]));
		}
		System.out.println(dp[n-1]);
		
	}

	}
	static class FastScanner{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		int [] readArray(int n) {
			int a[]=new int[n];
			for(int i=0;i<n;i++) a[i]=nextInt();
			return a;
		}
		
		
	}
	

}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int m = Integer.parseInt(sc.next());
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int temp = Integer.parseInt(sc.next());
            a[i] = temp;
            sum += temp;
        }
        Arrays.sort(a);
        for (int i = n - 1; i >= n - m; i--) {
            if (a[i] < sum * 1.0 / (4 * m)) {
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}

Measured memory_bytes: 23124
import numpy as np

n, m, k = map(int, input().split(" "))

flag = 0
for i in range(n + 1):
    for j in range(m + 1):
        if(i * m - i * j + j * n - i * j == k):
            flag = 1
        if(n * m - (i * m - i * j + j * n - i * j) == k):
            flag = 1

if(flag == 1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 16780
N=int(input())
keta=len(str(N))
num=10**keta-1
for i in range(10):
	if num<=N:
		ls=list(str(num))
		ans=0
		for j in range(len(ls)):
			ans+=int(ls[j])
		print(ans)
		exit(0)
	else:
		num-=10**(keta-1)


Measured memory_bytes: 3060