akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
using namespace std;
using ll = long long;

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

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

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */
namespace detail {
    template<typename T, int N>
    auto make_vec(vector<int>& sizes, T const& x) {
        if constexpr (N == 1) {
            return vector(sizes[0], x);
        } else {
            int size = sizes[N-1];
            sizes.pop_back();
            return vector(size, make_vec<T, N-1>(sizes, x));
        }
    }
}
template<typename T, int N>
auto make_vec(int const(&sizes)[N], T const& x = T()) {
    vector<int> s(N);
    for (int i = 0; i < N; ++i) s[i] = sizes[N-i-1];
    return detail::make_vec<T, N>(s, x);
}

__attribute__((constructor))
void fast_io() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    int sum = 0;
    rep(i, n) sum += l[i];
    int mx = *max_element(l.begin(), l.end());
    sum -= mx;
    if (mx < sum) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}


Measured memory_bytes: 3620
import fractions
a, b, c, d =map(int, input().split())
lcm = (c//fractions.gcd(c, d))*d
cnt = (b-a+1)
c_cnt = (b//c) - ((a-1)//c)
d_cnt = (b//d) - ((a-1)//d)
lcm_cnt = (b//lcm) - ((a-1)//lcm)
print(cnt + lcm_cnt - c_cnt - d_cnt)

Measured memory_bytes: 5688
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const double PI = 4*atan(1);
const int INF = 0x3f3f3f3f;
const int MOD = 1e9+7;
const ll LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-9;
const string YES = "Possible";
const string NO = "Impossible";
#define pb push_back
#define mp make_pair
#define eb emplace_back

const int MAX_N = 2e6+10;
int N;
int d1[MAX_N],d2[MAX_N];

void solve()
{
	for(int i=2;i<N;++i){
		if(d1[i]==d2[i]&&d1[i-1]==d2[i-1]&&d1[i-2]==d2[i-2]){
			cout<<"Yes\n";
			return;
		}
	}
	cout<< "No\n";
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	cin >> N;
	for(int i=0;i<N;++i){
		cin >>d1[i]>>d2[i];
	}
	solve();
	return 0;
}


Measured memory_bytes: 3648
#include <cstdio>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

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

    while(--n >= 0){
        vector<int> x(10);
        for(int i=0; i<10; ++i){
            char c;
            cin >> c;
            if(isdigit(c))
                x[i] = c - '0';
            else if(c == 'A')
                x[i] = 11;
            else
                x[i] = 10;
        }

        int sum = 0;
        int ace = 0;
        for(int i=0; i<10; ++i){
            sum += x[i];
            if(x[i] == 11)
                ++ ace;
            if(sum > 21){
                if(ace){
                    sum -= 10;
                    -- ace;
                }
            }
            if(sum == 21 && i == 1){
                cout << "blackjack" << endl;
                break;
            }
            if(sum > 17 || (ace == 0 && sum > 16)){
                if(sum > 21)
                    cout << "bust" << endl;
                else
                    cout << sum << endl;
                break;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1192
use std::cmp::*;
use std::io::*;
fn main() {
    let mut s: String = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();

    let h: usize = itr.next().unwrap().parse().unwrap();
    let w: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();
    let g: Vec<Vec<char>> = (0..h)
        .map(|_| itr.next().unwrap().chars().collect())
        .collect();

    let mut ans = 0;

    for bit1 in 0..1 << h {
        for bit2 in 0..1 << w {
            let mut cnt = 0;
            for i in 0..h {
                if bit1 >> i & 1 == 1 {
                    continue;
                }
                for j in 0..w {
                    if bit2 >> j & 1 == 1 {
                        continue;
                    }
                    if g[i][j] == '#' {
                        cnt += 1;
                    }
                }
            }
            if cnt == k {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007

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

    	long long n,i,j,k,count=0,ans=0,l,r,x,y,mx=0,sum=0;
        cin>>n>>k;
        string s;
        if(k>=n)
        {
            cout<<"unsafe";
        }
        else
        cout<<"safe";


	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector< vector<int> > VVI;
typedef vector< vector<int> > VVL;
typedef pair<int,int> PII;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair

int main(){
  ll N,A,B;
  cin>>N>>A>>B;
  if((B-A)%2==0) cout<<(B-A)/2<<endl;
  else cout<<min(A,N-B+1)+(B-A)/2<<endl;
}

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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define int long long
#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>=0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

int  n;
int a[100000+5];
bool before[100000+5];
bool after[100000+5];
int cnt[100000+5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i,n) cin >> a[i];
    int ans=0;
    rep(i,n){
        if (before[i]) continue;
        int total=1;
        int now=i;
        vector<int> path;
        bool flag=false;
        while (true){
            if (after[now]) break;
            if (before[now] && !after[now]){
                flag=true;
                break;
            }
            before[now]=true;
            cnt[now]=total;
            path.pb(now);
            now=(now+a[now])%n;
            total++;
        }
        for (auto i: path) after[i]=true;
        if (flag) ans+=total-cnt[now];
    }
    cout << ans << endl;
}

Measured memory_bytes: 5352
//SoN
#include<iostream>
#include<cstring>
using namespace std;

int main()
{
	int sum;

	while(1){
		sum = 0;
	char y[1000];
		
	cin >> y;
	if(strcmp(y,"0")==0)
		break;
	for(int i = 0; i < strlen(y); i++)
		sum += y[i] - '0';
	
	
	cout << sum << endl;
	}
	return 0;
}


Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <string.h>
#include <vector>
#define int long long
using namespace std;

int32_t main()
{
	int n;
	cin>>n;
	int cnt1 = 0,cnt2 = 0;
	cnt1 = n/500;
	n -= cnt1*500;
	cnt2 = n/5;
	int ans = cnt1*1000 + cnt2*5;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define SORT(c) sort((c).begin(),(c).end())

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//sort(v.rbegin(), v.rend(), [](auto& x, auto& y){return x[1] < y[1];});
//cout << fixed << setprecision(10) << ans << defaultfloat << endl;
typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<double> Vd;
typedef vector<string> Vs;

int main() {
    int N,S,ans=1e6;
    
    string s;
    cin >> N >> s;
    Vi v(N,0);

    REP(i,N){
        if (i == 0 && s[N-1-i]=='#') {
            v[i]++;
        }
        else if (s[N-1-i]=='#') {
            v[i] = v[i-1]+1;
        }
        else if (i>0){
            v[i] = v[i-1];
        }
    }
    reverse(v.begin(),v.end());

    //for (auto i:v) cout << i << endl;

    REP(i,N) {
        ans = min(ans, v[0] - v[i] + N-i - v[i]);
        //cout << ans << endl;
    }
    ans = min(ans,v[0]);

    cout << ans << endl;
}

Measured memory_bytes: 1412
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
#define all(q) (q).begin(),(q).end()
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MODADD(ADD_X,ADD_Y)  (ADD_X+ADD_Y)%MOD;
#define MODSUB(SUB_X,SUB_Y)  (SUB_X-SUB_Y)+MOD)%MOD;
#define MODMUL(MUL_X,MUL_Y)  (MUL_X*MUL_Y)%MOD;
#define LCM(LCM_X,LCM_Y) (LCM_X*LCM_Y)/__gcd(LCM_X,LCM_Y);
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
int dx[]= {1,0,-1,0,1,-1,1,-1};
int dy[]= {0,1,0,-1,1,-1,-1,1};
int x[20],y[20],n;
double fact,sum;
double dist(double a,double b,double c,double d)
{
    double e=((a-c)*(a-c))+((b-d)*(b-d));
    return sqrt(e);
}
void recur(int used[],int last,double cur)
{
    int f=0;
    for(int i=1; i<=n; i++)
    {
        if(used[i]==0)
        {
            cur+=dist(x[i],y[i],x[last],y[last]);
            used[i]=1;
            recur(used,i,cur);
            used[i]=0;
            cur-=dist(x[i],y[i],x[last],y[last]);
            f=1;
        }
    }
    if(!f){
        sum+=cur;
    }
}
int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);
    cin>>n;
    fact=1;
    for(int i=1; i<=n; i++)
    {
        cin>>x[i]>>y[i];
        fact*=i;
    }
    int used[20]= {0};
    for(int i=1; i<=n; i++){
        used[i]=1;
        recur(used,i,0);
        used[i]=0;
    }
    cout<<setprecision(10)<<fixed<<(sum/fact)<<endl;
    return 0;
}


Measured memory_bytes: 3836
//  Created by Sengxian on 2017/6/24.
//  Copyright (c) 2017年 Sengxian. All rights reserved.
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
inline int readInt() {
	int n = 0, ch = getchar();
	while (!isdigit(ch)) ch = getchar();
	while (isdigit(ch)) n = n * 10 + ch - '0', ch = getchar();
	return n;
}

const int MAX_N = 100000 + 3;
int n;

struct Point {
	int x, y, id;
	
	void read() {
		x = readInt(), y = readInt();
	}
} pts[MAX_N];

inline bool cmp1(const Point &a, const Point &b) {
	return a.x < b.x;
}

inline bool cmp2(const Point &a, const Point &b) {
	return a.y < b.y;
}

struct DisjointSet {
	int fa[MAX_N];
	
	void init(int n) {
		for (int i = 0; i < n; ++i)
			fa[i] = i;
	}
	
	inline int find(int x) {
		return fa[x] == x ? x : fa[x] = find(fa[x]);
	}
	
	void unite(int x, int y) {
		x = find(x), y = find(y);
		fa[x] = y;
	}
	
	bool same(int x, int y) {
		return find(x) == find(y);
	}
} ds;

struct Edge {
	int from, to, cost;
	bool operator < (const Edge &e) const {
		return cost < e.cost;
	}
} edges[MAX_N * 2];

inline int calc(const Point &a, const Point &b) {
	return min(abs(a.x - b.x), abs(a.y - b.y));
}

int main() {
	n = readInt();
	for (int i = 0; i < n; ++i) pts[i].read(), pts[i].id = i;
	int cnt = 0;
	sort(pts, pts + n, cmp1);
	for (int i = 0; i < n - 1; ++i) edges[cnt].from = pts[i].id, edges[cnt].to = pts[i + 1].id, edges[cnt++].cost = calc(pts[i], pts[i + 1]);
	sort(pts, pts + n, cmp2);
	for (int i = 0; i < n - 1; ++i) edges[cnt].from = pts[i].id, edges[cnt].to = pts[i + 1].id, edges[cnt++].cost = calc(pts[i], pts[i + 1]);
	ds.init(n);
	sort(edges, edges + cnt);
	ll ans = 0;
	for (int i = 0; i < cnt; ++i) {
		Edge &e = edges[i];
		if (!ds.same(e.from, e.to)) {
			ds.unite(e.from, e.to);
			ans += e.cost;
		}
	}
	
	printf("%lld\n", ans);
	
	return 0;
}


Measured memory_bytes: 4224
H,W = map(int,input().split())
S = []
for _ in range(H):
  a = list(input())
  if a.count('.') < W: S.append(a)
S_t = list(map(list, zip(*S)))
S_re = []
for i in range(W):
  if S_t[i].count('.') < len(S): S_re.append(S_t[i])

S_tt = list(map(list, zip(*S_re)))
for i in S_tt:
  print(''.join(i))


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int y = sc.nextInt();
        int z = sc.nextInt();
        int work = 0;
        work = x ;
        x = y;
        y = work;
        work = x ;
        x = z;
        z = work;
        System.out.println(x + " " + y + " " + z);
        sc.close();


    }
}

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

int main(){
    string S; cin >> S;
    string T; cin >> T;
    int s = S.size();
    int t = T.size();
    vector<string> ans;
    for(int i = 0; i < s - t + 1; i++){
        string U = S;
        bool flag = false;
        //cout << i << endl;
        for(int j = 0; j < t; j++){
            
            if(U[i+j]==T[j] || U[i+j] == '?')U[i+j] = T[j];
            else {flag = true;break;}
        }
        //cout << i << endl;
        if(flag)continue;
        for(int j = 0; j < s; j++){
            if(U[j]=='?')U[j] = 'a';
        }
        ans.push_back(U);
    }
    if(ans.size()==0){
        cout << "UNRESTORABLE" << endl;
        return 0;
    }
    sort(ans.begin(),ans.end());
    cout << ans[0] << endl;
    return 0;
}


Measured memory_bytes: 3640
S=input()[::-1]
l=[0]*2019
a=1
d=0

# 問題はここ
# 順番に見ていって、角桁の数字のmod2019をとっている。
for s in S:
  d=d+int(s)*a
  l[d%2019]+=1
  a*=10
  a%=2019

# それぞれの組み合わせで、modの計算値が同じな組み合わせを計算している
ans=l[0]
for i in l:
  if i>=2:
    ans+=i*(i-1)//2
    
print(ans)


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

using namespace std;

int main() {
	int a, b;
	string s;
	cin >> a >> b;
	cin >> s;

	bool h = true;

	for (int i = 0; i < a; i++) {
		if (0 <= s[i] - '0' && s[i] - '0' <= 9) {

		}
		else {
			h = false;
		}
	}

	if (s[a] != '-') {
		h = false;
	}

	for (int i = a + 1; i < s.size(); i++) {
		if (0 <= s[i] - '0' && s[i] - '0' <= 9) {

		}
		else {
			h = false;
		}
	}

	if (h) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
W, H, x, y = map(int, input().split())

# 指定された点を通る直線で長方形を分割する
# 分割した小さい方の面積を最大化するのは、直線が長方形の中心を通るとき
# つまり、指定された点と長方形の中心を結ぶ線
# すると、長方形をちょうど半分に分割できる
gx = W / 2
gy = H / 2

# 任意の2点を結ぶ直線の引き方は1通りだが
# 任意の1点を通る直線は無数に引ける
# 従って、分割方法が複数あるかどうかは、指定された点が中心点かどうか
is_multi = 1 if (x, y) == (gx, gy) else 0

print(str(W * H / 2) + " " + str(is_multi))

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

int main(){
  int ans=0;
  string s;
  cin>>s;
  if(s.size()==1) cout<<ans;
  else{
  for(int i=0;i<=s.size()/2-1;i++){
    if(s[i]!=s[s.size()-i-1]) ans++;
  }
  cout<<ans;
  }
  return 0;
}


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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return 1;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
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);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}

int main(){
  int n;
  cin >> n;
  int ans = 0;
  REP(i, n+1){
    if(keta(i) % 2 == 1) ans++;
  }
  cout << ans << endl;
}


/*





















*/


Measured memory_bytes: 256
from time import *
from random import *
t=time()
T0,T1=2000,600
Tt=2000
D=int(input())
C=list(map(int,input().split()))
S=[list(map(int,input().split())) for i in range(D)]
X=[0]*26
XX=[0]*26
P=[]
for i in range(D):
  for j in range(26):
    X[j]+=C[j]
    XX[j]+=X[j]
  P.append([])
  for j in range(26):
    P[i].append(j)
  P[i].sort(reverse=True,key=lambda x:X[x]+S[i][x])
  XX[P[i][0]]-=X[P[i][0]]
  X[P[i][0]]=0
SC,SC2=0,0
for i in range(D):
  SC+=S[i][P[i][0]]
YY=[]
Y=[]
A,B=0,0
e=0
E=1
for i in range(50):
  e+=E
  E*=1/(i+1)
def f(x):
  global e,Tt
  if x>=0:
    return True
  else:
    return randrange(0,10000000)<=pow(e,x/Tt)
for l in range(12):
  for k in range(25):
    for i in range(D):
      SC2=SC
      YY=XX[:]
      Y=X[:]
      SC2-=S[i][P[i][0]]
      SC2+=S[i][P[i][k+1]]
      for j in range(26):
        Y[j]=0
      YY[P[i][0]],YY[P[i][k+1]]=0,0
      for j in range(D):
        if j==i:
          Z=P[j][k+1]
        else:
          Z=P[j][0]
        Y[P[i][0]]+=C[P[i][0]]
        Y[P[i][k+1]]+=C[P[i][k+1]]
        Y[Z]=0
        YY[P[i][0]]+=Y[P[i][0]]
        YY[P[i][k+1]]+=Y[P[i][k+1]]
      if f((SC2-sum(YY))-(SC-sum(XX))):
        P[i].insert(0,P[i][k+1])
        del P[i][k+2]
        XX=YY[:]
        SC=SC2
    for i in range(D-1):
      SC2=SC
      YY=XX[:]
      Y=X[:]
      A=i
      B=randrange(A+1,D)
      SC2-=S[A][P[A][0]]+S[B][P[B][0]]
      SC2+=S[A][P[B][0]]+S[B][P[A][0]]
      for j in range(26):
        Y[j]=0
      YY[P[A][0]],YY[P[B][0]]=0,0
      for j in range(D):
        if j==A:
          Z=P[B][0]
        elif j==B:
          Z=P[A][0]
        else:
          Z=P[j][0]
        Y[P[A][0]]+=C[P[A][0]]
        Y[P[B][0]]+=C[P[B][0]]
        Y[Z]=0
        YY[P[A][0]]+=Y[P[A][0]]
        YY[P[B][0]]+=Y[P[B][0]]
      if f((SC2-sum(YY))-(SC-sum(XX))):
        P[A],P[B]=P[B][:],P[A][:]
        XX=YY[:]
        SC=SC2
    Tt=pow(T0,1-(time()-t))*pow(T1,time()-t)
for i in range(D):
  print(P[i][0]+1)

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

pll A[105];
ll dp[105][10005];

int main() {
    ll N, W;
    cin >> N >> W;
    REP(i, N) {
        cin >> A[i].first >> A[i].second;
    }

    memset(dp, 0, sizeof(dp));
    REP(i, N) {
        REP(j, W + 1) {
            dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j]);
            if (j - A[i].second >= 0) {
                dp[i + 1][j] = std::max(dp[i + 1][j], dp[i][j - A[i].second] + A[i].first);
                dp[i + 1][j] = std::max(dp[i + 1][j], dp[i + 1][j - A[i].second] + A[i].first);
            }
        }
    }

    ll max = 0;
    REP(i, W + 1) {
        max = std::max(max, dp[N][i]);
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 11308
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
	// write your code here

        Scanner src = new Scanner(System.in);


        Map<String,Integer> map = new HashMap<String,Integer>();

        map.put("AC",0);
        map.put("WA",0);
        map.put("TLE",0);
        map.put("RE",0);
        int n = src.nextInt();

        src.nextLine();

        while(n-- >0){

            String res = src.nextLine();

            map.put(res,map.get(res)+1);

        }

        System.out.println("AC x "+map.get("AC"));

        System.out.println("WA x "+map.get("WA"));
        System.out.println("TLE x "+map.get("TLE"));
        System.out.println("RE x "+map.get("RE"));
    }
}

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

using namespace std;

typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int x, y;

  cin >> x >> y;

  int d = abs(abs(x) - abs(y));
  int ans = d + 2;

  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 2; ++j) {
      int cur = i + j + d;
      int a = x;
      if (i) {
        a = -a;
      }
      a += d;
      if (j)
        a = -a;
      if (a == y)
        ans = min(ans, cur);
    }

  cout << ans << endl;
}



Measured memory_bytes: 384
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

using namespace std;

long int gcm(long int p,long int q)
{
    if (p%q == 0){
        return q;
    }
    else{
        return gcm(q,p%q);
    }
}

int main()
{
    long int a,b;
    cin >> a >> b;
    if (b > a){
        swap(a,b);
    }
    
    cout << a*b/gcm(a,b) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
int pop();
void push(int );
int x[1000],top;
int main(){
  top=0;
  char c[100];
  int a,b;
  while(scanf("%s",c)!=EOF){
    if(c[0]=='+'){
      a=pop();
      b=pop();
      push(a+b);
    }
    else if(c[0]=='-'){
      b=pop();
      a=pop();   
      push(a-b);
    }
    else if(c[0]=='*'){
      a=pop();
      b=pop();
      push(a*b);
    }
    else{
      push(atoi(c));
    }
  }
  printf("%d\n",pop());
  return 0;
}
void push(int a){
  x[++top]=a;
}
int pop(){
  return x[top--];
}



Measured memory_bytes: 2740
#include <stdio.h>
int main()
{
    int a, b;
    int max;
    scanf("%d%d", &a, &b);
    max = a + b;
    if (max < a - b)
        max = a - b;
    if (max < a * b)
        max = a * b;
    printf("%d", max);
    return 0;
}

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

using namespace std;

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

  vector< vector<int> > x(n);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < d; ++j) {
      int xx;
      cin >> xx;
      x[i].push_back(xx);
    }
  }

  int ans = 0;
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j < n; ++j) {
      int tmp = 0;
      for (int k = 0; k < d; ++k) {
	tmp += pow(abs(x[i][k] - x[j][k]), 2);
      }
      int sq = sqrt(tmp);
      if (sq * sq == tmp) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <cmath>
#include <fstream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long ll;


int main(void){
    ll n;
    cin>>n;
    vector <ll> a(n+1);
    for(int i=1;i<=n+1;i++){
        for(int j=i;j<=n;j+=i){
            a[j]++;
        }
    }
    
    ll c=0;
    for(int i=1;i<=n;i+=2){
        if(a[i]==8)c++;
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <vector>
using namespace std;
int matrix[200][200];
int main() {
  int n; cin >> n;
  for (int i = 0; i < n; i++) {
    int u, k, v; cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v;
      matrix[u-1][v-1] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cout << matrix[i][j];
      if (j != n-1) {
        cout << " ";
      } else {
        cout << endl;
      }
    }
  }
}




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

int dp[305][305], dp1[305][305];
vector<pair<int, int> > laffey[305];
int n, m;
int mod=1000000007;
void add(int &x, int y)
{
    x+=y;
    if(x>mod) x-=mod;
}

signed main()
{
    cin>>n>>m;
    for(int i=1; i<=m; i++)
    {
        int u, v, cnt;
        cin>>u>>v>>cnt;
        laffey[v].push_back({u, cnt});
    }
    dp[0][0]=1;
    for(int i=1; i<=n; i++)
    {
        for(int j=0; j<i; j++)
        {
            for(int k=0; k<=j; k++)
            {
                dp1[k][j]=0;
                if(j==k&&j!=0) continue;
                if(j<i-1||i==1) add(dp1[k][j], dp[k][j]);
                else
                {
                    for(int l=0; l<i-1; l++)
                    {
                        if(l==k&&l!=0) continue;
                        add(dp1[k][j], dp[min(l, k)][max(l, k)]);
                    }
                }
                for(auto vl:laffey[i])
                {
                    if((j>=vl.first)+(k>=vl.first)+1!=vl.second) dp1[k][j]=0;
                }
                // if(i==2) cout<<j<<" "<<k<<endl;
            }
        }
        for(int j=0; j<i; j++)
        {
            for(int k=0; k<=j; k++)
            {
                dp[k][j]=dp1[k][j];
            }
        }
        // if(i==3)
        // {
        //     cout<<dp[1][2];
        //     return 0;
        // }
    }
    int ans=0, ans1=0;
    for(int i=0; i<n; i++)
    {
        for(int j=0; j<n; j++)
        {
            add(ans, dp[i][j]);
            if(j==0&&j==0) add(ans1, dp[i][j]);
        }
    }
    cout<<(mod*mod+6ll*ans-3ll*ans1)%mod;
}

Measured memory_bytes: 1664
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>

using namespace std;

int main(void){
    int A, B, C, X;
   

   cin >> A;
   cin >> B;
   cin >> C;
   cin >> X;

   int ans = 0;

   for(int i=0;i<=A;i++){
       for(int j=0;j<=B;j++){
           for(int k=0;k<=C;k++){
               if(500*i+100*j+50*k == X){
                   ans++;
               }
           }
       }
   }
   cout << ans << endl;
   return 0;
       
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int main(){
  ll h,w;
  cin >> h >> w;
  ll a[h][w];
  ll b[h][w];
  ll c[h][w];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> a[i][j];
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> b[i][j];
    }
  }
  bool dp[h][w][20000];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      c[i][j] = abs(b[i][j]-a[i][j]);
    }
  }
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<20000;k++) dp[i][j][k] = false;
    }
  }
  dp[0][0][c[0][0]] = true;
  int v;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      for(int k=0;k<20000;k++){
        if(!dp[i][j][k]) continue;
        if(i+1 < h){
          v = c[i+1][j];
          dp[i+1][j][k+v] = true;
          dp[i+1][j][abs(k-v)] = true;
        }
        if(j+1 < w){
          v = c[i][j+1];
          dp[i][j+1][k+v] = true;
          dp[i][j+1][abs(k-v)] = true;
        }
      }
    }
  }

  int ans;
  for(int k=0;k<20000;k++){
    if(dp[h-1][w-1][k]){
      ans = k;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 125440
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
	string S;

	cin >> S;
	bool f = false;
	for (int i = 0; i < 3; i++) {
		if (S[i] == S[i + 1]) {
			cout << "Bad\n";
			f = true;
			break;
		}
	}
	if (!f) {
		cout << "Good\n";
	}
	return 0;
}

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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

void solve(){
	ll a,b,n; cin >> a >> b >> n;
	ll x = -1;
	
	if(n<b){
		x = n;
	} else{
		ll off = n % b;
		x = n - off - 1;
	}
	cout << (a*x)/b - a * (x/b);
		
}

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








Measured memory_bytes: 3640
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#define ll long long
using namespace std;
int a[200010];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	int j=1;
	ll ans=0;
	ll xorsum=0,sum=0;
	for(int i=1;i<=n;i++)
	{
		for(;j<=n&&xorsum==sum;j++)
		{
			xorsum^=a[j];
			sum+=a[j];
		}
		if(sum!=xorsum) j--,xorsum^=a[j],sum-=a[j];
		int d=j-1;
	//	cout<<i<<' '<<d<<endl;
		ans+=(d-i+1);
		xorsum^=a[i];
		sum-=a[i];
	}
	cout<<ans;
	return 0;
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int N, M, K;
    cin >> N >> M >> K;
    vector<vector<int>> T(N, vector<int>(0));
    vector<vector<int>> B(N, vector<int>(0));
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--, b--;
        T[a].push_back(b);
        T[b].push_back(a);
    }
    rep(i, K) {
        int c, d;
        cin >> c >> d;
        c--, d--;
        B[c].push_back(d);
        B[d].push_back(c);
    }

    vector<int> color(N, -1);
    int col = 0;
    rep(i, N) {
        if (color[i] != -1) continue;
        queue<int> que;
        que.push(i);
        while (!que.empty()) {
            int cnode = que.front();
            que.pop();
            color[cnode] = col;
            for (auto nnode : T[cnode]) {
                if (color[nnode] == -1) que.push(nnode);
            }
        }
        col++;
    }
    d(col);
    dump(color);
    vector<int> NumColor(col, 0);
    rep(i, N) { NumColor[color[i]]++; }
    dump(NumColor);

    rep(i, N) {
        int ans = NumColor[color[i]] - T[i].size() - 1;
        int bre = 0;
        for (auto nnode : B[i]) {
            if (color[i] == color[nnode]) ans--;
        }
        cout << ans << " ";
    }
    return 0;
}

Measured memory_bytes: 12664
from collections import defaultdict
n,k=map(int,input().split())
a=list(map(int,input().split()))
cnt_dic=defaultdict(int)
for i in range(n):
  cnt_dic[a[i]]+=1
v=len(cnt_dic.keys())
cnt_dic=sorted(cnt_dic.values())
if v<=k:
  print(0)
else:
  print(sum(cnt_dic[0:v-k]))

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


void bfs(vector<ll> g[], bool vis[], ll dis[]){
    
    vis[1] = true;
    queue<ll> q;
    q.push(1);
    dis[1]=0;
    while(!q.empty()){
        ll curr = q.front();
        q.pop();
        // cout<<curr<<" ";
        for(int i : g[curr]){
            if(!vis[i]){
            vis[i] = true;
            dis[i] =  dis[curr]+1;
            q.push(i);
            }
        }
    }
    
}
void dfs(vector<ll> g[], bool vis[],ll u){
    vis[u]= true;
    for(int i:g[u]){
        if(!vis[i])
            dfs(g,vis,i);
    }
}

int main() {
     ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,m;
    cin>>n>>m;
    vector<ll> g[n+1];
    for(int i =0;i<m;i++){
        ll a,b;
        cin>>a>>b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    bool vis[n+1] = {false};
    dfs(g,vis,1);
    bool f= true;
    for(int i =1;i<n+1;i++){
        if(!vis[i]) {
            f = false;
            break;
        }
    }
    
    if(f)   cout<<"Yes"<<endl;
    else {cout<<"No";
        return 0;
    }
    ll dis[n+1];
    bool viss[n+1] = {false};
    for(int i =0;i<n+1;i++){
        dis[i] = n+1;
    }
    bfs(g,viss,dis);
    vector<ll> ans;
    for(int i =2;i<n+1;i++){
        if(dis[i]== 1)
            ans.push_back(1);
            
        else{
        for(int j : g[i]){
            if(dis[j] == dis[i]-1)
                {ans.push_back(j); break;}
                
        }
            
        }
    }
    for(ll i=0; i<n-1;i++){
        cout<<ans[i]<<endl;
    }
    
	return 0;
}

Measured memory_bytes: 15924
#include<iostream>
#include<string>
#include<algorithm>
#include<functional>
using namespace std;

int main() {
	int a, b, c, k;
	cin >> a >> b >> c >> k;
	if (a > b&&a > c) {
		for (int i = 0; i < k;i++) a *= 2;
		cout << a  + b + c << endl;
	}
	else if (b>c) {
		for (int i = 0; i < k;i++) b *= 2;
		cout << a + b + c << endl;
	}
	else {
		for (int i = 0; i < k;i++) c *= 2;
		cout << a + b + c << endl;
	}



	return 0;
}

Measured memory_bytes: 256
def main():
    n = int(input())
    num_list = []
    for _ in range(n):
        num_list.append(list(map(int,input().split())))

    num_list = sorted(num_list, key=lambda x: x[1])
        
    time = 0
    for i in range(n):
        time += num_list[i][0]
        if time > num_list[i][1]:
            print('No')
            exit()

    print('Yes')

if __name__ == '__main__':
    main()

Measured memory_bytes: 90072
n,d = map(int,input().split())
x = [[int(e) for e in input().split()] for _ in range(n)]
count = 0
for i in range(n):
  for j in range(i+1,n):
    kyori = 0
    for k in range(d):
      kyori += (x[i][k]-x[j][k])**2
    for h in range(1,kyori+1):
      if (h*h==kyori):
        count += 1
        break
print(count)


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int INF=100000000;
const int MOD=1000000007;

int main()
{
 int n, c;
 cin >> n;
 c=n;
 char s[n];
 cin >> s;
 for(int i=1;i<n;i++){
   if(s[i-1]==s[i]) c--;
 }
 cout << c;
 return 0;
}

Measured memory_bytes: 384
#include<stdio.h>

int search(int A[], int n, int key) {
	int i = 0;
	A[n] = key;
	while( A[i] != key ) i++;
	return (i != n);
}

int main(){
	int A[10000 + 1], n, i, q, sum = 0, key;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &key);
		if( search(A, n, key) ) sum++;
	}

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

	return 0;
}

Measured memory_bytes: 2772
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}void pr(){ln;}
template<class A,class...B>void pr(const A &a,const B&...b){cout<<a<<(sizeof...(b)?" ":"");pr(b...);}
template<class A>void PR(A a,ll n){rep(i,n)cout<<(i?" ":"")<<a[i];ln;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[8]={-1,0,1,0,-1,-1,1,1},dy[8]={0,1,0,-1,-1,1,1,-1};
typedef pair<ll,ll> P;

void Main() {
  ll x,k,d;
  cin >> x >> k >> d;
  if(x<0) x*=-1;
  ll c=x/d;
  x-=d*min(c,k);
  k-=min(c,k);
  if(k%2) x=abs(x-d);
  pr(x);
}

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


Measured memory_bytes: 3644
#include<stdio.h>
int main()
{
 int r,c,i,sum1,sum2,j,t;
 int h[101][101]={0};
 scanf("%d%d",&r,&c);

 for(i=1;i<=r;i++){
                   for(j=1;j<=c;j++){
                                     scanf("%d",&h[i][j]);
                                     }
                   }
 sum2=0;
 for(i=1;i<=r;i++){
                  sum1=0;
                  for(j=1;j<=c;j++){
                                    sum1+=h[i][j];
                                    printf("%d ",h[i][j]);
                                    }
                   sum2+=sum1;
                   printf("%d\n",sum1);
                   }

  for(i=1;i<=c;i++){
                  sum1=0;
                  for(j=1;j<=r;j++){
                                    sum1+=h[j][i];
                                    }
                   printf("%d ",sum1);
                   }

  printf("%d\n",sum2);
  return 0;

}       



Measured memory_bytes: 2108
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i


N, Q = map(int, input().split())
c = list(map(int, input().split()))

lr = []
for i in range(Q):
    l, r = map(int, input().split())
    lr.append([l, r, i])

lr.sort(key=lambda x: x[1])
# print("lr", lr)
rightest = [-1] * (N + 1)
current_q = 0
bit = Bit(N)
ans = [0] * Q

for i in range(N):
    if rightest[c[i]] != -1:
        bit.add(rightest[c[i]] + 1, -1)
    rightest[c[i]] = i
    bit.add(i + 1, 1)
    # print(bit.tree)

    while current_q < Q and lr[current_q][1] == i + 1:
        ans[lr[current_q][2]] = bit.sum(lr[current_q][1]) - bit.sum(lr[current_q][0] - 1)
        current_q += 1

for i in range(Q):
    print(ans[i])


Measured memory_bytes: 239116
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

sum = 0
for i in range(n):
    d = min(a[i], b[i])
    sum += d
    a[i] -= d
    b[i] -= d
    d = min(a[i+1], b[i])
    sum += d
    a[i+1] -= d
    b[i] -= d

print(sum)

Measured memory_bytes: 18624
/*|In The Name Of Allah|*/
//This Month Will Be Expert ISA
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5+5;

const int mod = 1e9+7;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 0; i+2 < n; i++){
        if(s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C'){
            ans ++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
K = STDIN.gets.to_i

def gcd(a, b, c)
  d = a.gcd(b)
  d.gcd(c)
end

sum = 0

1.upto(K) do |c|
  1.upto(K) do |b|
    1.upto(K) do |a|
      sum += gcd(a, b, c)
    end
  end
end

print sum


Measured memory_bytes: 14328
#include<bits/stdc++.h>
namespace lib
{
	#define ll long long
	#define ull unsigned long long
	#define rgi register int
	#define rgl register long long
	#define rgc register char
	const double pi=acos(-1); 
	using namespace std;
	class fastio
	{
		private:
			#define _NUMLEN 112
			char _num[_NUMLEN],_ch; int _f,_head; bool _useSTD;
		public:
			fastio() {_f=0,_head=0,_useSTD=0,SUF=_ch=' ';}
			char SUF;
			inline void ioSTD() {_useSTD=1; ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); }
			inline void gc(char & _c) {if(_useSTD)cin>>_c; else _c=getchar(); }
			inline void pc(char _c) {if(_useSTD)cout<<_c; else putchar(_c); }
			template<typename _T> inline fastio & operator - (_T & _x)
			{
				if(_useSTD)cin>>_x; else{
					_x=0; 
					while(!isdigit(_ch)) _f|=_ch=='-',gc(_ch); 
					while(isdigit(_ch)) _x=(_x<<1)+(_x<<3)+(_ch^48),gc(_ch); 
					_f&&(_x=-_x,_f=0); 
				}return *this; 
			}
			template<typename _T> inline fastio & operator + (_T _x)
			{
				if(_useSTD)cout<<_x<<SUF; else{
					_T _k; 
					if(_x==0) {pc('0'),pc(SUF);return *this;} if(_x<0) pc('-'),_x=-_x;
					while(_x>0) _k=_x/10,++_head,_num[_head]=(_x-(_k<<1)-(_k<<3))^48,_x=_k; while(_head>0) pc(_num[_head]),--_head;
					pc(SUF);
				}return *this; 
			}
			template<typename _T> inline fastio & operator >> (_T & _x) {cin>>_x;return *this;}
			template<typename _T> inline fastio & operator << (_T _x) {cout<<_x;return *this;}
			#define edn pc('\n')
	}io;
	inline void fileio(string _r,string _w) {if(_r[0]!='-')freopen(_r.c_str(),"r",stdin); if(_w[0]!='-')freopen(_w.c_str(),"w",stdout); }
	#define mem(_x,_set) memset(_x,_set,sizeof(_x))
}
using namespace lib;
// ----------------------------

// #define int ll
const int maxn=100004;
const int mod=998244353,inf=1000000007;

#define LL long long

signed main()
{
	int n, r;
	scanf("%d %d", &n, &r);
	if(n >= 10) printf("%d", r);
	else printf("%d", r + 100 * (10 - n));
	return 0;
}
// ----------------------------
// by imzzy


Measured memory_bytes: 256
import scala.io.StdIn

object Main{
  def main(agss: Array[String]): Unit ={
    val num = StdIn.readLine().split(" ").map(a => a.toInt)
    val A = num(0)
    val B = num(1)

    val result = (A - 1) * (B - 1)

    println(result)

  }
}

Measured memory_bytes: 25288
X = int(input())

point = 0
if X//500 > 0:
    s = X//500
    point += s*1000
    X = X - 500*s
if X//5 > 0:
    s = X//5
    point += s*5
    X = X - 5*s
if X//100 > 0:
    s = X//100
    X = X - 100*s
if X//50 > 0:
    s = X//50
    X = X - 50*s
if X//10 > 0:
    s = X//10
    X = X - 10*s
if X//1 > 0:
    s = X//1
    X = X - 1*s

print(point)

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

#define rep(i,n) for (int i = 0; i< (n); ++i)
#define vvec(m,n) vector<vector<int>> (int(m), vector<int>(n))
#define ALL(a) (a).begin(), (a).end()

using ll = long long;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c - max({a,b,c}) << endl;
}

Measured memory_bytes: 256
{
  const main = (input: string) => {
    const r = reader(input)
    const [T1, T2] = r.ns()
    const [A1, A2] = r.ns()
    const [B1, B2] = r.ns()
    let k = T1 * A1
    let k2 = T1 * B1
    let s = T2 * A2
    let s2 = T2 * B2
    if (k > k2) {
      k = k2 - k // -
      s = s2 - s // +
    } else {
      k = k - k2 // -
      s = s - s2 // +
    }
    // console.log({ k, s })
    if (k + s === 0) {
      console.log('infinity')
      // console.log('I cannot output `infinity` from TypeScript.')
      return
    }
    if (k + s < 0) {
      console.log(0)
      return
    }
    console.log(Math.floor(-k / (s + k)) * 2 + Number(-k % (s + k) !== 0))

    // Math.floor()
  }

  // const values = obj => Object.keys(obj).map(e => obj[e]);

  const reader = (str: string) => {
    const lines = str.trim().split('\n')
    const s = () => lines.shift() || ''
    const line = s
    const n = () => Number(s())

    const ss = () => s().split(' ')
    const ns = () => ss().map(Number)
    return { lines, line, s, n, ss, ns }
  }

  const getInput = () => require('fs').readFileSync('/dev/stdin', 'utf8')
  main(getInput())
}


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

using namespace std;

inline void quit(){ exit(0); }

typedef long long ll;

ll mpow(ll _x, ll _y, ll _mod){
    if(_y==0) return 1;
    if(_y==1) return _x%_mod;
    if(_y&1) return (mpow(_x, _y-1, _mod)*_x)%_mod;
    ll _tmp = mpow(_x, _y>>1, _mod);
    return (_tmp*_tmp)%_mod;
}

int n;
int board[1002][1002];
int num[1002][1002];
int degree[1000002];
vector<int> nextLink[1000002];
bool chk[1000002];
int cnt;
int visitCnt;
int days;

vector<pair<int, int> > v;
queue<int> que;
queue<int> que2;

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

    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            num[i][j] = num[j][i] = cnt++;
            v.push_back(make_pair(i, j));
        }
    }

    for(int i=1; i<=n; i++){
        for(int j=1; j<n; j++){
            scanf("%d", &board[i][j]);
            if(j!=1){
                nextLink[num[i][board[i][j-1]]].push_back(num[i][board[i][j]]);
                degree[num[i][board[i][j]]]++;
            }
        }
    }

    for(int i=0; i<cnt; i++){
        if(!degree[i]){
            chk[i] = 1;
            que.push(i);
        }
    }

    while(!que.empty()){
        days++;
        while(!que.empty()){
            int tmp = que.front();
            que.pop();
            visitCnt++;

            for(auto &x: nextLink[tmp]){
                degree[x]--;
                if(!degree[x]){
                    chk[x] = 1;
                    que2.push(x);
                }
            }
        }
        que = que2;
        while(!que2.empty()) que2.pop();
    }

    if(cnt != visitCnt) printf("-1");
    else printf("%d", days);
}


Measured memory_bytes: 55408
A, B, M = map(int, input().split())
a = list(map(int, input().split())) 
b = list(map(int, input().split())) 
c = [list(map(int, input().split())) for i in range(M)]
price = [a[int(c[i][0])-1] + b[int(c[i][1]-1)] - int(c[i][2]) for i in range(M)]
saiyasu = min(a) + min(b)
print(min(min(price),saiyasu))

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

using namespace std;

int main(){
	int N;
	int ening=0;

	cin>>N;
	vector <int> tokuten;
	while(ening<N){
		int out=0;
		int point=0;
		bool base[3]={false};
		while(out<3){
			string str;
			cin>>str;
			int runner=0;
			switch (str[1])
			{
			
			case 'I'://HIT
				if(base[2]){
					point++;
					base[2]=false;
				}
				for(int i=1;i>=0;i--){
					if(base[i]){
						base[i]=false;
						base[i+1]=true;
					}
				}
				base[0]=true;
				break;
			case 'O'://HOMERUN
				
				for(int i=0;i<3;i++){
					if(base[i]){
						runner++;
					}
					base[i]=false;
				}
				point+=++runner;
				break;
			case 'U'://OUT
				out++;
				break;
			}
		}
		cout<<point<<endl;
		ening++;
	}

	return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <ctime>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define fs first
#define sc second
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


int main(){
    int N, K; cin >> N >> K;
    vector<int> H(N);
    for(int &h:H){
        cin >> h;
    }
    vector<int> dp(N+K, INF);
    dp[0] = 0;

    for(int i=0; i<N; i++){
        for(int j=1; j<=K; j++){
            dp[i+j] = min(dp[i+j], dp[i]+abs(H[i+j] - H[i]));
        }
    }
    cout << dp[N-1] << endl;
    
    return 0;
}





Measured memory_bytes: 1024