akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define MAXN	5005
#define MAXM	205
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
struct info {long long value, home; };
bool operator < (info a, info b) {return a.value < b.value; }
int n, m, pre[MAXN], nxt[MAXN];
long long ans[MAXN][MAXN];
long long dist[MAXN], a[MAXN][MAXM];
info tmp[MAXN];
int main() {
	//freopen("F.in", "r", stdin);
	read(n), read(m);
	for (int i = 2; i <= n; i++) {
		read(dist[i]);
		dist[i] += dist[i - 1];
	}
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= m; j++)
		read(a[i][j]);
	for (int j = 1; j <= m; j++) {
		nxt[0] = 1; pre[n + 1] = n;
		for (int i = 1; i <= n; i++) {
			pre[i] = i - 1;
			nxt[i] = i + 1;
			tmp[i] = (info) {a[i][j], i};
		}
		sort(tmp + 1, tmp + n + 1);
		for (int i = 1; i <= n; i++) {
			int t = tmp[i].home;
			ans[t][pre[t] + 1] += tmp[i].value;
			ans[t][t + 1] -= tmp[i].value;
			ans[nxt[t]][pre[t] + 1] -= tmp[i].value;
			ans[nxt[t]][t + 1] += tmp[i].value;
			nxt[pre[t]] = nxt[t];
			pre[nxt[t]] = pre[t];
		}
	}
	for (int i = 1; i <= n; i++)
	for (int j = 1; j <= n; j++)
		ans[i][j] += ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1];
	long long finalans = 0;
	for (int i = 1; i <= n; i++)
	for (int j = i; j <= n; j++)
		finalans = max(finalans, ans[j][i] - dist[j] + dist[i]);
	cout << finalans << endl;
	return 0;
}

Measured memory_bytes: 204032
#include <iostream>
#include <cstdio>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a%b);}
int main() {
	int n; ll x, ans;
	cin >> n >> ans;
	for (int i = 1; i < n; i++) {
		cin >> x;
		ans = ans/gcd(ans, x)*x;
	}
	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 256
//-------All power is within you,you can do Anything and Everything.---------//
 
    #include <bits/stdc++.h>
    using namespace std;
  
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ M $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//

    #define pb push_back
    #define MP make_pair
    #define F first
    #define S second
    #define int long long
    #define fo(i,a,b) for(int i=a;i<b;i++)
    #define rfo(i,b,a) for(int i=b;i>=a;i--)
    #define deb(x) cout<<#x<<" "<<x<<endl;
    #define mem( a, val ) memset(a, val, sizeof( a ) )
    #define deci( x ) cout<<fixed<<setprecision( x );
    #define bitcount( x ) __builtin_popcountll( x )
 
    
    typedef vector<int> vi;
    typedef pair<int,int> pi; 
    
    const int MOD =  1000000007 ;
    const int MAX = 1e5 + 7;
    const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
    const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};

//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ V $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//  
    
    int i,j,k,t,n,q,l,r,mid;
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ F $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
    
    int dp[MAX];
    int wt;
    int v,w;
    
    int max_self(int &a,int b)
    {
        a=max(a,b);
    }
    void solve()
    {
        cin>>n>>wt;
        fo(i,0,n)
        {
            cin>>w>>v;
            // deb(w)
            rfo(weight_already,wt-w,0)
            {
                max_self(dp[weight_already+w],dp[weight_already]+v);
            }
        }
        int answer(0);
        fo(i,0,wt+1)
        max_self(answer,dp[i]);
    	cout<<answer<<endl;
    }
    
//*$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$*//
//                          GAME STARTS FROM HERE                            //

    int32_t main() 
      {
      	
      	// int start,stop=clock();
        // cout<<"time:"<<(stop-start)/double(CLOCKS_PER_SEC)*1000<<endl;
      	ios_base::sync_with_stdio(0);
      	cin.tie(NULL);
      	
      	// cin>>t;while(t--)
      	solve();
      	
    	return 0;
      }

Measured memory_bytes: 1024
# -*- coding: utf-8 -*-

S2 = input()
T = input()

# TをS2に当て込める位置の数ループ
for i in range(len(S2)-len(T)+1):
    # S2の後ろから、Tの文字数分切り出し
    tmpS = S2[len(S2)-len(T)-i:len(S2)-i]
    
    # Tの文字数分ループ
    for j in range(len(T)):
        # 対象の文字か?と一致しなければbreak
        if tmpS[j] != T[j] and tmpS[j] !=  "?":
            break
        # 最後まで条件を満たしたら出力準備
        if j == len(T) - 1:
            # 元のS2の該当箇所にTを当て込む
            S = S2[:len(S2)-len(T)-i] + T + S2[len(S2)-i:]
            # 残った?は全部a(辞書順最小がいいから)
            S = S.replace("?", "a")
            print(S)
            exit()
# 最後まで条件を満たす箇所がなければこっち
print("UNRESTORABLE")

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

int main(){
    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> sum(102);

    for(int i = 0; i < n; i++){
        cin >> x[i];
    }
    
    for(int p = 0; p <= 101; p++){
        for(int i = 0; i < n; i++){
            sum[p] += ((x[i] - p) * (x[i] - p));
        }
    }
    sort(sum.begin(), sum.end());
    cout << sum[0] << endl;
}



Measured memory_bytes: 3624
#include <iostream>
#include <climits>
#include <algorithm>
#include <queue>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <array>
#include <memory>

#define IN(a,b) (a.find(b) != a.end())
#define p(a,b) make_pair(a,b)
#define readVec(a) for (int __i = 0; __i<(int)a.size();__i++){cin>>a[__i];}

// jimjam

template<typename T>
void pMin(T &a, T b) {if (b<a){a=b;}}
template<typename T>
void pMax(T &a, T b) {if (b>a){a=b;}}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c);
template<typename A, typename B>
std::ostream& operator<<(std::ostream& os, const std::pair<A,B>& c) {std::cout << "(" << c.first << ", " << c.second << ")";return os;}
template<typename T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& c) {
	if (c.size() == 0) {os << "{}"; return os;}
	os << "{" << c[0];
	for (int64_t i = 1; i < (int)c.size(); i++) {os <<", "<<c[i];}
	os << "}";
	return os;
}

using namespace std;

#define MAXN 200005
vector<int> adj[MAXN];
bool seen[MAXN];

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

	int n, m; cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int a, b; cin >> a >> b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	for (int i = 1; i <= n; i++) {
		int cAns=0;
		if (!seen[i]) {
			queue<int> bfs;
			seen[i]=true;
			bfs.push(i);
			while (bfs.size()) {
				int curr = bfs.front();
				cAns++;
				bfs.pop();
				for (int i: adj[curr]) {
					if (!seen[i]) {
						seen[i]=true;
						bfs.push(i);
					}
				}
			}
		}
		pMax(ans,cAns);
	}
	cout << ans << endl;
	return 0;
}




Measured memory_bytes: 15224
N, T = map(int,input().split())
t = list(map(int,input().split()))
ruiseki = 0
start = 0
for i in range(N-1):
    if t[i+1]-start <= T: #ある人が押してから次の人が押すまでの時間がT以下のとき、その区間では流れ続けてる
        ruiseki += t[i+1]-start
    else:
        ruiseki += T
    start = t[i+1]
print(str(ruiseki+T))

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

MOD = 10 ** 9 + 7

class Factorial:
    def __init__(self, n, mod):
        self.f = [1]
        self.mod = mod
        for j in range(1, n + 1):
            self.f.append(self.f[-1] * j % mod)
        self.i = [pow(self.f[-1], mod - 2, mod)]
        for j in range(n, 0, -1):
            self.i.append(self.i[-1] * j % mod)
        self.i.reverse()
    def factorial(self, j):
        return self.f[j]
    def ifactorial(self, j):
        return self.i[j]
    def comb(self, n, k):
        return self.f[n] * self.i[n - k] % self.mod * self.i[k] % self.mod if n >= k else 0

N = int(input())


C = Factorial(N + 1, MOD)

G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    G[a].append(b)
    G[b].append(a)

order = []
order_append = order.append

stack = [(0, -1)]
stack_pop = stack.pop
stack_append = stack.append

while stack:
    tmp = stack_pop()
    order_append(tmp)
    for next_ in G[tmp[0]]:
        if next_ == tmp[1]:
            continue
        stack_append((next_, tmp[0]))
    
size = [1] * N
dp = [1] * N

# print (order)
for c, p in order[::-1]:
    if c == 0:
        break
    size[p] += size[c]

for c, p in order[::-1]:
    dp[c] = (dp[c] * C.factorial(size[c] - 1)) % MOD
    if c == 0:
        break
    # dp[c] = (dp[c] * C.factorial(size[c] - 1)) % MOD
    dp[p] = (dp[p] * dp[c] % MOD) * C.ifactorial(size[c]) % MOD

# print (dp)
dp2 = [0] * N
dp2[0] = dp[0]

for c, p in order[1::]:
    tmp = (dp2[p] * C.factorial(N - 1 - size[c]) % MOD) * C.factorial(size[c]) % MOD
    red = (tmp * C.ifactorial(N - 1) % MOD) * pow(dp[c], MOD - 2, MOD) % MOD

    size_red = N - size[c]
    tmp = (dp[c] * red % MOD) * C.factorial(N - 1) % MOD
    dp2[c] = (tmp * C.ifactorial(size[c] - 1) % MOD) * C.ifactorial(size_red) % MOD


print (*dp2, sep = '\n')

Measured memory_bytes: 87832
#include<iostream>
#define rep(i,n) for(int i=0;i<n;++i)
using namespace std;

int main() {
    int N, K, x, y, ans = 0;
    cin >> N >> K;
    int K2 = K + K, sum[K2+1][K2+1] = {};
    rep(i, N) {
        char c;
        cin >> x >> y >> c;
        if (c == 'W') y += K;
        x %= K2;
        y %= K2;
        sum[x+1][y+1]++;
    }
    rep(y, K2) {
        rep(x, K2) {
            sum[y+1][x+1] += sum[y+1][x] + sum[y][x+1] - sum[y][x];
        }
    }
    rep(y, K + 1) {
        rep(x, K + 1) {
            int tmp = sum[y][x] - sum[y][0] - sum[0][x] + sum[0][0];
            tmp += sum[y][K2] - sum[y][x+K] - sum[0][K2] + sum[0][x+K];
            tmp += sum[y+K][x+K] - sum[y+K][x] - sum[y][x+K] + sum[y][x];
            tmp += sum[K2][x] - sum[K2][0] - sum[y+K][x] + sum[y+K][0];
            tmp += sum[K2][K2] - sum[K2][x+K] - sum[y+K][K2] + sum[y+K][x+K];
            tmp = max(tmp, N - tmp);
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;

class Program
{
    static void Main(string[] args)
    {
        var x = int.Parse(Console.ReadLine());
        bool f = false;
        while (!f)
        {
            f = IsPrime(x);
            x++;
        }
        Console.WriteLine(--x);
    }

    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

        double sqrtNum = Math.Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                // 素数ではない
                return false;
            }
        }

        // 素数である
        return true;
    }
}

Measured memory_bytes: 27420
#include<cstdio>
#include<algorithm>
#include<functional>
#include<cstring>
using namespace std;
int main(void)
{
	int v[1000],n,i;
	double s;
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&v[i]);
	sort(v,v+n);
	s=(double)(v[0]+v[1])/2.0;
	for(i=2;i<n;i++)	{
		s=(s+(double)v[i])/2.0;
	}
	printf("%lf\n",s);
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int dp[50];

int fib(int n){
    if(n==0 || n==1)
        return dp[n]=1;
    if(dp[n] != -1)
        return dp[n];
    return dp[n]=fib(n-1)+fib(n-2);
}

int main(void){
    int n,i;
    for(i=0;i<50;i++)
        dp[i]=-1;
    scanf("%d",&n);
    printf("%d\n",fib(n));
    return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
    int N,K,ans=1;
    cin>>N>>K;
    REP(i,N){
        if(2*ans<=ans+K)ans=2*ans;
        else ans+=K;
    }
    cout<<ans<<endl;
}

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

namespace ABC
{
    struct Robot
    {
        public int s;
        public int t;
    }
    class ProgramB
    {
        static void Main(string[] args)
        {
            var n = long.Parse(Console.ReadLine());
            var robo = new List<Robot>();
            for (var i = 0; i < n; i++)
            {
                var inputs = Console.ReadLine().Split(" ");
                var x = int.Parse(inputs[0]);
                var l = int.Parse(inputs[1]);

                robo.Add(new Robot() { s = x - l, t = x + l });
            }

            robo.Sort((a, b) => a.t - b.t);

            var result = 1;
            var prev = 0;

            for (var i = 1; i < n; i++)
            {
                var r = robo[i];
                var p = robo[prev];
                if (p.t <= r.s && p.s <= r.t)
                {
                    result++;
                    prev = i;
                }
            }

            Console.WriteLine(result);
        }
    }
}


Measured memory_bytes: 48196
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cstdio>
#include <random>

#define fol(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    int x,a,b;
    cin >> x >> a >>b;
    abs(x-a) > abs(x-b) ? cout << "B" <<endl : cout << "A" <<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string w;
    cin >> w;
    map<char, int> cnt;
    for (auto &c : w) {
        cnt[c]++;
    }
    for (auto &p : cnt) {
        if (p.second % 2 != 0) {
            cout << "No"
                 << "\n";
            return 0;
        }
    }
    cout << "Yes"
         << "\n";
    return 0;
}

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

typedef long long ll;

int main() {
  multiset<int> st;
  int q; scanf("%d", &q);
  for(int i=0; i<q; i++){
    int query, x;
    scanf("%d %d", &query, &x);
    if(query==0){
      st.insert(x);
      printf("%d\n", st.size());
    }
    else if(query==1){
      printf("%d\n", st.count(x));
    }
    else if(query==2){
      st.erase(x);
    }
    else {
      int y; scanf("%d", &y);
      auto itrLower = st.lower_bound(x);
      auto itrUpper = st.upper_bound(y);

      while(itrLower != itrUpper){
        printf("%d\n", *itrLower);
        itrLower++;
      }
    }
  }
}


Measured memory_bytes: 12444
input = gets.split.map(&:to_i)
takahashi_hp = input[0]
takahashi_atk = input[1]
aoki_hp = input[2]
aoki_atk = input[3]

is_takahashi_next = true

while(takahashi_hp > 0 && aoki_hp > 0) do
  if is_takahashi_next
    is_takahashi_next = !is_takahashi_next
    aoki_hp -= takahashi_atk
    next
  else
    is_takahashi_next = !is_takahashi_next
    takahashi_hp -= aoki_atk
    next
  end
end

puts takahashi_hp <= 0 ? 'No' : 'Yes'

Measured memory_bytes: 14320
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return [LIST() for _ in range(n)]
def NSTR(n): return [input() for _ in range(n)]


INF = float("inf")
MOD = 10**9 + 7


def main():
    N = INT()
    C = input()

    count = 0
    head = 0
    tail = N-1
    while head < tail:
        # 頭からWを探す。Rである限り進む
        while head < N and C[head] == "R":
            head += 1
        # 後ろからRを探す。Wである限り戻る
        while 0 <= tail and C[tail] == "W":
            tail -= 1
        # 順序が逆転したら終わり
        if head > tail:
            break
        # 入れ替える操作
        count += 1
        head += 1
        tail -= 1
    print(count)

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9412
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF INT_MAX
#define LINF 1LL<<60

struct SegTree {
	int N;
	ll init_v = 0;
	vector<ll> node;

	SegTree(int _N) {
		N = 1;
		while (N < _N) N *= 2;
		node.resize(2 * N - 1, init_v);
	}

	void update(int k, ll val) {
		k += N - 1;
		node[k] += val;
		while (k) {
			k = (k - 1) / 2;
			//node[k] = node[2 * k + 1] + node[2 * k + 2];
			node[k] += val;
		}
	}
	ll query(int a, int b, int k, int l, int r) {
		if (r <= a || b <= l) return init_v;
		if (a <= l && r <= b) return node[k];
		else {
			ll vl = query(a, b, 2 * k + 1, l, (l + r) / 2);
			ll vr = query(a, b, 2 * k + 2, (l + r) / 2, r);
			return vl + vr;
		}
	}
	ll rsq(int a, int b) { return query(a, b, 0, 0, N); }
};

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, q; cin >> n >> q;
	SegTree ST(n);
	for (int i = 0; i < q; i++) {
		int com, x, y; cin >> com >> x >> y;
		if (com == 0) {
			x--;
			ST.update(x, y);
		}
		else {
			x--; y--;
			cout << ST.rsq(x, y+1) << endl;
		}
	}
}

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

int main() {
  int A,B;
  cin >> A >> B;
  if(A>=13){
    cout << B << endl;
  }
  else if(A<=12 && A>=6){
    cout << B/2 << endl;
  }
  else if(A<=5) {
    cout << 0 << endl;
  }
}


Measured memory_bytes: 256
n, m = map(int,input().split())

ab = [list(map(int,input().split()))for _ in range(n)]


ab.sort( key = lambda a:a[0] )

cost = 0
for i in range(n):
    abi = ab[i]
    if m >= abi[1]:
        cost += abi[0]*abi[1]
        m -= abi[1]
    else:
        cost += m * abi[0]
        m = 0


print(cost)

Measured memory_bytes: 29024
# ABC142E - Get Everything
import sys
input = sys.stdin.readline

def main():
    chmin = lambda x, y: x if x <= y else y
    N, M = map(int, input().split())
    p, INF = 1 << N, 1 << 60
    # bitDP of minimum cost to buy the subset of items represented by binary
    dp = [INF] * p
    dp[0] = 0
    for _ in range(M):
        a, _ = map(int, input().split())
        x = sum(1 << (i - 1) for i in map(int, input().split()))
        for y in range(p):
            dp[x | y] = chmin(dp[x | y], dp[y] + a)
    ans = dp[-1] if dp[-1] != INF else -1
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
import java.util.Scanner;

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

		while(true){
			int n=sc.nextInt();
			int p=sc.nextInt();
			if(n==0) break;

			int i=0;
			int[] a=new int[n];
			while(true){
				if(p>0){ p--; a[i]++; }
				else{ p+=a[i]; a[i]=0; }

				if(p==0){
					boolean end=true;
					for(int j=0;j<n;j++) if(i!=j && a[j]!=0) end=false;
					if(end) break;
				}

				i=(i+1)%n;
			}
			System.out.println(i);
		}

		return;
	}
}

Measured memory_bytes: 20448
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
#include<sstream>
#include<complex>
#include<functional>
#include<vector>
#include<map>
#include<queue>
#include<deque>
#include<stack>
#include<set>

using namespace std;
#define endl '\n'
#define eb emplace_back
#define fst first
#define scd second
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define YES(n) cout << ((n) ? "YES" : "NO" ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No" ) << endl

constexpr int MOD = 1000000007;

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

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }

// value
ll W, H;
ll x, y;

void solve() {

	cin >> W >> H >> x >> y;

	double ans;
	int flag = (x == W / 2.0) && (y == H / 2.0);

	ans = W * H / 2.0;

	printf("%.12f %d\n", ans, flag);


	return;

}

int main() {

	//cin.tie(0);
	//ios::sync_with_stdio(false);

	solve();

	return 0;

}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

  long int a[n+1], b[n];
  for(int i = 0; i < n+1; i++) cin >> a[i];
  for(int i = 0; i < n; i++) cin >> b[i];

  long long int ans = 0;
  for(int i = 0; i < n; i++) {
    if(a[i] <= b[i]) {
      ans += a[i];
      if(a[i+1] >= b[i] - a[i]) {
        a[i+1] -= b[i] - a[i];
        ans += b[i] - a[i];
      }else {
        ans += a[i+1];
        a[i+1] = 0;
      }
    }else {
      ans += b[i];
    }
  }
  // if(a[n+1] <= b[n]) ans += a[n+1];
  // else ans += b[n];

  cout << ans << endl;
}


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

using namespace std;

int main()
{
 	int n, a, b;
  	string s;
  	cin >> n >> a >> b >> s;
  	int cnta = 0, cntb = 0;
  	for(int i = 0; i < n; i ++){
        if(s[i] == 'a' && a + b > 0){
              cout << "Yes\n"; (a > 0 ? a : b) --;
        }
        else if(s[i] == 'b' && b > 0){
              cout << "Yes\n"; b --;
        }
        else{
              cout << "No\n";
        }
    }
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;

int getPoints(int days, int input[days][3]) {

  // init 2d dp table - row is day number and
  // column is cumulative happiness for each day/activity
  int dp[days][3];

  // base case
  dp[0][0] = input[0][0];
  dp[0][1] = input[0][1];
  dp[0][2] = input[0][2];

  for (int i = 1; i < days; i++) {
    dp[i][0] = max((dp[i-1][1] + input[i][0]), 
                   (dp[i-1][2] + input[i][0]));
    dp[i][1] = max((dp[i-1][0] + input[i][1]), 
                   (dp[i-1][2] + input[i][1]));
    dp[i][2] = max((dp[i-1][0] + input[i][2]), 
                   (dp[i-1][1] + input[i][2]));
  }

  int maxPoints = -1;
  for (int i = 0; i < 3; i++) {
    maxPoints = max(maxPoints, dp[days-1][i]);
  }
  
  return maxPoints;
}

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

  int input[numDays][3];

  for (int i = 0; i < numDays; i++) {
    for (int j = 0; j < 3; j++) {
      cin >> input[i][j];
    }
  }

  int happiness = getPoints(numDays, input);
  cout << happiness;

  return 0;
}

Measured memory_bytes: 5504
n = int(input())
d,x = map(int, input().split())
a = [int(input()) for _ in range(n)]
c = 1
ans = x
for i in a:
  for j in range(1, d+1):
    if i*j+1 <= d:
      c += 1
    else:
      ans += c
      c = 1
      break
print(ans)

Measured memory_bytes: 9188
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
using namespace std;
const int MAXN = 100005;
const int MAXE = 200005;
const int NIL = -1;
typedef long long ll;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int dx[4] = { -1, 0, 1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const char dir[4] = { 'u', 'r', 'd', 'l' };
struct Puzzle {
	int Sudoku[3][3];
	int space;
	string path;
	bool operator<(const Puzzle& p) const
	{
		for (int i = 0; i < 3; ++i)
			for (int j = 0; j < 3; ++j)
				if (Sudoku[i][j] == p.Sudoku[i][j])
					continue;
				else
					return Sudoku[i][j] < p.Sudoku[i][j];
		return false;
	}
};

bool ok(const Puzzle &p)
{
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
			if (p.Sudoku[i][j] != i * 3 + j + 1)
				return false;
	return true;
}

string bfs(Puzzle s)
{
	queue<Puzzle> q;
	map<Puzzle, bool> vis;
	Puzzle u, v;
	s.path = "";
	q.push(s);
	vis[s] = true;
	while (!q.empty())
	{
		u = q.front();
		q.pop();
		if (ok(u))
			return u.path;
		int x = (u.space - 1) / 3;
		int y = (u.space - 1) % 3;
		//cout << "space == " << u.space << " x == " << x << " y == " << y << endl;
		for (int i = 0; i < 4; ++i)
		{
			int tx = x + dx[i];
			int ty = y + dy[i];
			if (tx < 0 || ty < 0 || tx >= 3 || ty >= 3)
				continue;
			v = u;
			swap(v.Sudoku[x][y], v.Sudoku[tx][ty]);
			v.space = tx * 3 + ty + 1;
			if (!vis[v])
			{
				vis[v] = true;
				v.path += dir[i];
				q.push(v);
			}
		}
	}
	return "unsolvable";
}


int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	Puzzle s;
	for (int i = 0; i < 3; ++i)
		for (int j = 0; j < 3; ++j)
		{
			cin >> s.Sudoku[i][j];
			if (s.Sudoku[i][j] == 0)
				s.Sudoku[i][j] = 9, s.space = i * 3 + j + 1;
		}
	cout << bfs(s).size() << endl;
	return 0;
}

Measured memory_bytes: 30672
#include <bits/stdc++.h>
#define FOR(v, a, b) for(int v = (int)(a); v < (int)(b); ++v)
#define FORE(v, a, b) for(int v = (int)(a); v <= (int)(b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define RS resize
#define CLR clear
#define PB push_back
#define ALL(x) (x).begin(), (x).end()
#define C complex
#define CI complex< int >
#define CD complex< double >
using namespace std;

void split(string str, char chr, vector< string > *res){
	stringstream ss(str);
	string itm;
	while(getline(ss, itm, chr)){
		(*res).PB(itm);
	}
}


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int w, h, x, y, cnt;
	vector< vector< char > > field;
	stack< CI > st;
	
	while(cin >> w >> h , w){
		field.RS(h);
		REP(i, h){
			field[i].RS(w);
			REP(j, w){
				cin >> field[i][j];
				if(field[i][j] == '@'){
					x = j;
					y = i;
					field[i][j] = '.';
				}
			}
		}
		
		st.push(CI(x, y));
		cnt = 0;
		
		while(!st.empty()){
			complex< int > cur = st.top();
			st.pop();
			
			if(field[cur.imag()][cur.real()] != '.') continue;
			
			field[cur.imag()][cur.real()] = '#';
			++cnt;
			
			if(cur.imag() > 0){
				if(field[cur.imag() - 1][cur.real()] == '.'){
					st.push(cur + CI(0, -1));
				}
			}
			if(cur.imag() < h - 1){
				if(field[cur.imag() + 1][cur.real()] == '.'){
					st.push(cur + CI(0, 1));
				}
			}
			if(cur.real() > 0){
				if(field[cur.imag()][cur.real() - 1] == '.'){
					st.push(cur + CI(-1, 0));
				}
			}
			if(cur.real() < w - 1){
				if(field[cur.imag()][cur.real() + 1] == '.'){
					st.push(cur + CI(1, 0));
				}
			}			
		}
		
		cout << cnt << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ld long double
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using P=pair<long long,long long>;
#define rep(i,n) for(long long i=0; i<(long long)n; i++)
#define req(i,n) for(long long i=n-1; i>=0; i--)
#define range(i,a,b) for(long long i=a; i<b; i++)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((long long)(x).size())
#define COUT(x) cout << x << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define onBoard(y,x) (y>=0 && y<h && x>=0 && x<w)
#define pri_que priority_queue
#define vint vector<int>
#define vvint vector<vector<int>>
#define vi vector<int>
#define vvi vector<vector<int>>
#define vs vector<string>
#define vvc vector<vector<char>>
#define vc vector<char>
#define vp vector<pair<int,int>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define show(x) cout<<#x<<"="<<x<<endl;
#define SUM(x) accumulate(x.begin(),x.end(),0)
#define MAX(x) *max_element(x.begin(),x.end())
#define MIN(x) *min_element(x.begin(),x.end())
#define couty cout<<"Yes"<<endl
#define coutn cout<<"No"<<endl
#define coutY cout<<"YES"<<endl
#define coutN cout<<"NO"<<endl
#define yn(x) cout<<(x?"Yes":"No")<<endl
#define YN(x) cout<<(x?"YES":"NO")<<endl
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a, long long b){return a/gcd(a,b)*b;}
const long long dx[8]={1,0,-1,0,1,-1,-1,1};
const long long dy[8]={0,1,0,-1,1,1,-1,-1};
const long long INF = 1e15;
const long long MOD = 1e9+7;

int modpow(int a, int n, int mod) {
    int res=1;
    while(n>0) {
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

int modinv(int a,int mod){
    return modpow(a,mod-2,mod);
}


int cmod(int n, int m, int mod){
    int ret=1;
    for(int i=n-m+1; i<=n; i++){
        ret*=i; ret%=mod;
    }
    for(int i=1; i<=m; i++){
        ret*=modinv(i,mod);
        ret%=MOD;
    }
    return ret;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(15);

    int n,b; cin>>n>>b; int r=n-b;

    for(int k=1; k<=b; k++){
        int res=1;
        res*=cmod(r+1,k,MOD); res%=MOD;
        res*=cmod(b-1,k-1,MOD); res%=MOD;
        cout<<res<<endl;
    }
}

Measured memory_bytes: 3616
n = gets.to_i
arr =gets.chomp.split(' ').map(&:to_i).sort_by{|i| -i}.push(0)
a = 0
b = 0
k = 0
while 2 * k < n
  a += arr[2*k]
  b += arr[2*k+1]
  k += 1
end
puts a - b

Measured memory_bytes: 14328
#include<stdio.h>

int main(int argc,const char * argv[])
{
    int H,W,i,j;
    while ("1") {
        scanf("%d %d", &H, &W);
        if (W==0 && H==0)break;
        for (i=0;H>i;i++) {
            for (j=0;W>j;j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2068
#include<bits/stdc++.h>
#define M 1000000007
using namespace std;
typedef long long int ll;

int main()
{
  int a,b;
  cin>>a>>b;
  int arr[b];
  int sum=0;
  for(int i=0;i<b;i++)
  {
      cin>>arr[i];
      sum+=arr[i];
  }
  if(sum>a)
    cout<<-1<<endl;
  else
    cout<<a-sum<<endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
long long d[3030][3030];
int main()
{
    int n;
    cin >> n;
    for (int i=1 ; i<=n ; i++)
        cin >> d[i][i];
    for (int i=1 ; i<=n ; i++)
        for (int j=i-1 ; j>0 ; j--)
            d[i][j] = max(d[i][i] - d[i-1][j] , d[j][j] - d[i][j+1]);
    cout << d[n][1];
    return 0;
}

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

using namespace std;
#define int unsigned long long

int n,a,b,c,d;
map<int,int> dp;
vector<pair<int,int> > v;
int DP(int m){
	if(m==0) return 0;
	if(m==1) return d;
	if(m==2) return min(d,a)+d;
	if(dp[m]) return dp[m];
	int res=d*m;
	int tmp=m%2;
	res=min(res,min(DP(m/2)+a+tmp*d,DP(m/2+1)+a+(2-tmp)*d));
	tmp=m%3;
	res=min(res,min(DP(m/3)+b+tmp*d,DP(m/3+1)+b+(3-tmp)*d));
	tmp=m%5;
	res=min(res,min(DP(m/5)+c+tmp*d,DP(m/5+1)+c+(5-tmp)*d));
	return dp[m]=res;
}
signed main(){
	v.push_back({a,2});
	v.push_back({b,3});
	v.push_back({c,5});
	int T;
	cin>>T;
	while(T--){	
		cin>>n>>a>>b>>c>>d;
		dp.clear();
		cout<<DP(n)<<'\n';
	}
	return 0;
}
/*
5
11 1 2 4 8
11 1 2 2 8
32 10 8 5 4
29384293847243 454353412 332423423 934923490 1
900000000000000000 332423423 454353412 934923490 987654321
*/

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



int main(){
	
	int n, k;
	cin >> n >> k;
	vector<int> a(200001);
	for(int i = 0; i < n; i++)
	{	
		int j;
		cin >> j;
		a[j]++;
	}
	sort(a.begin(), a.end(), greater<int>());
	int ans = 0;
	for(int i = k; i < (int)a.size(); i++)
	{
		ans+= a[i];
		if(a[i] == 0) break;
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long

using namespace std;

bool is_YYMM(int n) {
  int yy = n / 100;
  int mm = n % 100;

  if (mm >= 1 && mm <= 12) {
    return true;
  }
  return false;
}

bool is_MMYY(int n) {
  int mm = n / 100;
  int yy = n % 100;

  if (mm >= 1 && mm <= 12) {
    return true;
  }
  return false;
}

int main() {
  int n;
  scanf("%d", &n);

  bool a = is_YYMM(n);
  bool b = is_MMYY(n);

  if (a && b) {
    cout << "AMBIGUOUS" << endl;
  } else if (a) {
    cout << "YYMM" << endl;
  } else if (b) {
    cout << "MMYY" << endl;
  } else {
    cout << "NA" << endl;
  }
}

// YYMM, MMYY, AMBIGUOUS, NA のうち正しいものを出力せよ。


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	1e+5 + 7;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e9 + 7;


// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, x, k, p;
string s, t;
ld w;

// <------------- Implement Functions Here ----------> //

// <------------- Start of main() -------------------> //

void MAIN() {
	ll mx = 0,mn = 1e12;
	cin >> n >> x;
	vll a(n);
	for (ll i = 0; i < n; i++) {
		cin >> x;
		mn = min(mn,x);
		a[i] = x - mn;
		mx = max(mx,a[i]);
	}
	ll cou = 0;
	for(ll i=0;i<n;i++) cou += (a[i]==mx);
	if(mx == 0 )cou = 0;
	cout << cou;
}

int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {
		MAIN();
	}
	return 0;
}

Measured memory_bytes: 3972
import math
import sys

sys.setrecursionlimit(100000000)
# 動的計画法とmemo化で解く。
N, X = map(int, input().split())
S = list(map(int, input().split()))
S.sort(reverse=True)


def memoize(f):  # メモ化関数
    table = [{} for _ in range(N+1)]

    def func(i, key):
        if key not in table[i]:
            table[i][key] = f(i, key)
        return table[i][key]
    return func


@memoize
def dfs(i, x):
    if i == N:
        return x
    else:
        return dfs(i+1, x % S[i]) + dfs(i+1, x) * (N-i-1)


print(dfs(0, X) % (10**9+7))


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

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n,k;
    cin>>n>>k;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n-k;i++){
        if(a[i] < a[i+k]){
            cout<<"Yes\n";
        }
        else{
            cout<<"No\n";
        }
    }

    return 0;
}


Measured memory_bytes: 5212
#include<bits/stdc++.h>
#define int long long int
#define mod 998244353 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int32_t main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output1.txt","w", stdout);
    #endif
    IOS;
    string a,b;
    cin>>a>>b;
    int ans=999999;
    for (int i = 0; i <= a.size()-b.size(); ++i)
    {
        string c;
        int cn=0;
        c=a.substr(i,b.size());
        for (int j = 0; j < b.size(); ++j)
        {
            if (c[j]!=b[j])
            {
                cn++;
            }
        }
        ans=min(cn,ans);
    }
    cout<<ans;
    #ifndef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif
    return 0;
}       

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

int main(){
int a;
int b;
int c;
int d;
int e;
int f;
while(cin>>d>>e){
a=d;
b=e;
while(1){
c=a%b;
a=b;
b=c;
if(b==0){break;}
}
f=d/a*e;
cout << a <<" ";
cout << f <<endl;}}

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

int main() {
    int k,s; cin >> k >> s;

    int count = 0;
    for(int x = 0; x <= k; x++) {
        for(int y = 0; y <= k; y++) {
            if (s-x-y <= k && s-x-y >= 0) count++;
        }
    }
    cout << count << endl;
}

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

int N, M;
int A[1 << 19];
int C[1 << 19];

bool solve(int border) {
	for (int i = 0; i <= 4 * N; i++) C[i] = 0;
	for (int i = 0; i < 2 * N; i++) {
		int pos1 = lower_bound(A, A + 4 * N, M - A[i]) - A;
		int pos2 = lower_bound(A, A + 4 * N, (M + border + 1) - A[i]) - A;
		if (pos2 <= 2 * N) {
			C[i + pos1] += 1;
			C[i + pos2] -= 1;
		}
		else {
			C[i + pos1] += 1;
			C[i + 2 * N] -= 1;
			C[i + 0] += 1;
			C[i + (pos2 - 2 * N)] -= 1;
		}
	}
	for (int i = 1; i <= 4 * N; i++) C[i] += C[i - 1];

	for (int i = 0; i <= 2 * N; i += 2) {
		int r1 = 0; if (i != 0) r1 = C[i - 1];
		int r2 = 0; if (i != 2 * N) r2 = C[2 * N + i - 1];
		if (r1 == i && r2 == (2 * N - i)) return true;
	}
	return false;
}

int main() {
	cin >> N >> M;
	for (int i = 0; i < 2 * N; i++) cin >> A[i];
	sort(A, A + 2 * N);
	for (int i = 0; i < 2 * N; i++) A[i + 2 * N] = A[i] + M;
	
	int cl = 0, cr = M, cm, minx = (1 << 30);
	for (int i = 0; i < 30; i++) {
		cm = (cl + cr) / 2;
		if (solve(cm) == true) { cr = cm; minx = min(minx, cm); }
		else { cl = cm; }
	}

	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 6748
#include <iostream>

using namespace std;

typedef long long ll;
const int MAX_N = 15;
const int MAX_S = 1110;
const int MAX_ADD = 110;
int n, s;
ll memo[MAX_ADD][MAX_N][MAX_S];

ll rec(ll add, ll num, ll sum)
{
    if (memo[add][num][sum] >= 0)
        return memo[add][num][sum];

    if (num == n && sum == s)
        return 1;
    if (add > 100 || sum > s || num > n)
        return 0;

    ll res = 0;
    res += rec(add + 1, num, sum);
    res += rec(add + 1, num + 1, sum + add);

    return memo[add][num][sum] = res;
}

int main()
{
    while (cin >> n >> s, n || s) {
        for (int i = 0; i < MAX_ADD; i++)
            for (int j = 0; j < MAX_N; j++)
                for (int k = 0; k < MAX_S; k++)
                    memo[i][j][k] = -1;

        cout << rec(0, 0, 0) << endl;
    }

    return 0;
}

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

using namespace std;

int n;
long long dp[200002][5];

int c1(int a){
    if(a%2) return 0;
    else return 1;
}
int c2(int a){
    if(a == 0) return 2;
    else if(a%2) return 1;
    else return 0;
}
void solve(){
    int i;
    long long j;
    string str;
    cin >> n;
    vector<int> a(n);
    for(i = 0;i < n;i++) cin >> a[i];
    a.push_back(0);
    for(i = 0;i < a.size();i++){
        dp[i+1][0] = dp[i][0]+a[i];
        j = min(dp[i][0],dp[i][1]);
        dp[i+1][1] = j+c2(a[i]);
        j = min(j,dp[i][2]);
        dp[i+1][2] = j+c1(a[i]);
        j = min(j,dp[i][3]);
        dp[i+1][3] = j+c2(a[i]);
        j = min(j,dp[i][4]);
        dp[i+1][4] = j+a[i];
    }
    long long ans = 0;
    cout << dp[n+1][4] << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 8816
#!/usr/bin/env pypy3
# n,m = map(int,sys.stdin.readline().split())
# a = list(map(int,sys.stdin.readline().split()))
# a = [sys.stdin.readline() for s in range(n)]
# s = sys.stdin.readline().rstrip()
# n = int(sys.stdin.readline())
# d = collections.defaultdict(list)
import math
from functools import reduce
import sys
sys.setrecursionlimit(15000)

n = int(sys.stdin.readline())
sum = 0
def gcd(*numbers):
    return reduce(math.gcd, numbers)
for a in range(1,n+1):
    for b in range(1,n+1):
        for c in range(1,n+1):
            sum += gcd(a,b,c)
print(sum)

Measured memory_bytes: 74704
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        frag=True
        for y in range(m):
            for x in range(m):
                if b[y][x]!=a[i+y][j+x]:
                    frag=False
        if frag==True:
            print("Yes")
            exit()
print("No")

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

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

			String in = br.readLine();
			String chr[] = in.split(" ");
			int n = Integer.parseInt(chr[0]);
			int i = Integer.parseInt(chr[1]);
			 System.out.println(n-i+1);
		}
	}
}

Measured memory_bytes: 25376
#include <iostream>
#include <vector>
#include <string>

using  namespace std;

void a()
{
    string s;
    cin >> s;
    if(s.size() < 4)
    {
        cout << "No" << endl;
    }else{
        if(s.substr(0, 4) == "YAKI")
        {
            cout << "Yes" << endl;
        } else{
            cout << "No" << endl;
        }
    }
    return;
}

void b()
{
    int n, m, k;
    cin >> n >> m >> k;
    if(k % n == 0){
        cout << "Yes" << endl;
        return;
    }
    if(k % m == 0)
    {
        cout << "Yes" << endl;
        return;
    }
    for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            int count = i * n + (m - i) * j - j * i;
            if(count == k)
            {
                cout << "Yes" << endl;
                return;
            }
        }
    }
    cout << "No" << endl;
    return;
}

void c()
{

}
int main() {
    b();
    return 0;
}


Measured memory_bytes: 256
/*suri_kumkaran*/

#include <bits/stdc++.h>

using namespace std;

#define UB upper_bound
#define LB lower_bound
#define BS binary_search
#define MP make_pair
#define EB emplace_back
#define endl "\n"
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define F first
#define S second
#define ALL(a) (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int long long

typedef long long int64;
typedef vector<int> VI64;
typedef vector<pair<int,int>> VII64;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;

int32_t main()
{
	IOS;
	int T=1;
	//cin>>T;
	while(T--)
	{
		int n;
		cin>>n;
		int ans=(n/500)*1000;
		n%=500;
		ans+=(n/5)*5;
		cout<<ans;
	}

	return 0;
}

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

using namespace std;

#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr(names + 1, ',');
	std::cerr.write(names, comma - names) << " = " << arg1;
	ZZ(comma, args...);
}

#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define endl '\n'
#define int long long

int a, b, c, d;

int lcm(int a, int b)
{
	return (a*b) / (__gcd(a, b));
}

int solve(int x)
{
	return (x - x/c - x/d + x/lcm(c, d));
}

signed main()
{
	IOS;
	cin >> a >> b >> c >> d;
	cout << solve(b) - solve(a-1) << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma warning(disable:4996)
using namespace std;
using ll = long long;
int search(string s) {
	int i;
	int num = 0;

	for (i = 0; i<s.size(); i++) {
		if (s[i] == 'C') {
			num++;
		}
	}
	return num;
}
int oomoji(string s) {
	int count = 0;
	for (int i = 0; i < s.size(); i++) {
		if ((s[i] >= 'A') && (s[i] <= 'Z'))count++;
	}
	return count;
}
int main() {
	string s;
	cin >> s;
	int nagasa = s.size();
	if (s[0] == 'A') {
		string subs = s.substr(2, nagasa - 3);
		if (search(subs) == 1) {
			if (oomoji(s) == 2) {
				cout << "AC" << endl;
			}
			else cout << "WA" << endl;
		}
		else cout << "WA" << endl;
	}
	else cout<<"WA"<<endl;
}
//he\llohell\o


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

string S;

int main() {
    cin >> S;

    map<char, int> mp;
    bool f = false;
    for (int i = 0; i < S.length(); i++) {
        mp[S[i]]++;
        if (mp[S[i]] > 1) {
            f = true;
            break;
        }
    }

    if (f) cout << "no" << endl;
    else cout << "yes" << endl;

    return 0;
}


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

int main()
{
	long long X; cin >> X;

	double balance = 100;

	for(int i = 1; ; i++) {
		double interest = balance * 1 / 100.0;
		balance += interest;
		balance = (long long)balance;
		if(balance >= X) {
			cout << i << endl;
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 3632
def solve(string):
    n, k, *td = map(int, string.split())
    td = sorted([(t, d) for t, d in zip(td[::2], td[1::2])], key=lambda x: x[1], reverse=True)
    max_variety = len(set([c[0] for c in td]))
    choice = td[:k]
    r = []
    variety = set([])
    base = 0
    for _c in choice:
        base += _c[1]
        if _c[0] in variety:
            r.append(_c[1])
        else:
            variety.add(_c[0])
    base += len(variety)**2
    i = k
    ans = [base]
    while len(variety) < min(max_variety, k):
        while td[i][0] in variety:
            i += 1
        variety.add(td[i][0])
        ans.append(ans[-1] - r.pop() + td[i][1] + 2 * len(variety) - 1)
    return str(max(ans))


if __name__ == '__main__':
    n, m = map(int, input().split())
    print(solve('{} {}\n'.format(n, m) + '\n'.join([input() for _ in range(n)])))


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

#define INF 1e+9
#define MAX_V 400001

struct edge {
  int to;
  int cost;
};

using P = pair<int, int>; // <最短距離, 頂点の番号>

int V;                  // ノード数
vector<edge> G[MAX_V];  // グラフ
int d[MAX_V];           // sから各頂点までの距離
int frm[MAX_V];

/**
 * @fn ダイクストラ
 * @brief 上記変数'd'に各始点から各終点までの距離格納
 * @param (s) 始点ノード
 */
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d+V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while ( !que.empty() ) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) { continue; }

    for ( int i = 0; i < G[v].size(); i++ ) {
      edge e = G[v][i];
      if ( d[e.to] > d[v] + e.cost ) {
        d[e.to] = d[v] + e.cost;
        frm[e.to] = v;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int m;
  cin >> V >> m;
  for ( int i = 0; i < m; i++ ) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    edge ea, eb;
    ea.to = b; ea.cost = 1;
    eb.to = a; eb.cost = 1;
    G[a].push_back(ea);
    G[b].push_back(eb);
  }

  dijkstra(0);

  cout << "Yes" << endl;
  for ( int i = 1; i < V; i++ ) {
    cout << frm[i]+1 << endl;
  }
  return 0;
}


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

using namespace std;

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

    vector<int> v(n);
    for (int i = 0; i < n; ++i)
        cin >> v[i];
    vector<int> c(n);
    for (int i = 0; i < n; ++i)
        cin >> c[i];

    int max_value = 0;
    for (int i = 0; i < n; ++i) {
        if (v[i] > c[i])
            max_value += v[i] - c[i];
    }
    cout << max_value << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str;
    long long pos;
    long long not_one=0;
    cin>>str;
    cin>>pos;
    pos--;

    while(not_one<str.size()&&str[not_one]=='1'){
        not_one++;
    }

    if(pos<not_one){
        cout<<'1'<<endl;
    }else{
        cout<<str[not_one]<<endl;
    }
    return(0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
	      Scanner sc = new Scanner(System.in);
	      String S = sc.next();
	      sc.close();
	      
	      int price = 700;
	      
	      for(int i = 0; i < 3; i++) {
	    	  	if(S.charAt(i) == 'o') {
	    	  		price += 100;
	    	  	}
	      }
	      
	      System.out.println(price);
	      System.exit(0);
	    }

}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	cin>>n;
	cin>>a;
	int ans=a;
	REP(i, n-1){
		cin>>a;
		ans=gcd(ans, a);
	}
	cout<<ans<<'\n';
	return 0;
}


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

int k;
string s;

int main(){
    int a,b;
    cin >> k >> a >> b;
    for(int i=a;i<=b;i++){
        if(i%k==0) {cout << "OK" << endl; return 0;}
    }
    cout << "NG" << endl;

}

Measured memory_bytes: 3616