akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define ll long long
using namespace std;

const ll P = 1000000007;
const long long INF = 1LL << 60;
int gcd(int a, int b) { return b != 0 ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

int main()
{
  cout << fixed << setprecision(10);
  ll N;
  cin >> N;
  ll count = 0;
  vector<ll> A(N),B(N);
  rep(i,N) cin >> A[i] >> B[i];
  for(int i=N-1;i>-1;i--)
  {
    A[i] += count;
    if(A[i]%B[i]!=0)
    {
      count += B[i] - A[i]%B[i];
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 4832
N = int(input())
S = [0]*(N+1)
T = [0]*(N+1)
flag = -1
ans = 0

for i in range(1,N+1):
    S[i],T[i] = input().split()
X = input()
for i in range(1,N+1):
    if X == S[i]:
        flag = 1
        continue
    if flag == 1:
        ans += int(T[i])
print(ans)


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int a,b;

signed main() {
    cin >> a >> b;
    if (!((a+b)%2)) cout << (a+b)/2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}




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

int main() {
  int N, X;
  cin >> N >> X;
  vector<int> x(N);
  rep(i, N) cin >> x[i], x[i] = abs(x[i] - X);
  int g = x[0];
  rep(i, N) g = __gcd(g, x[i]);
  cout << g << endl;
  return 0;
}


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

#define sz(x) static_cast<int>((x).size())
#define all(x) (x).begin(), (x).end()

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

template<class T> bool cmn(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool cmx(T &a, T b) { return a < b ? (a = b, true) : false; }

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, x, y;
	cin >> n >> k >> x >> y;
	ll ans = 0;
	for(int i = 1; i <= n; ++i) {
		if(i > k) ans += y;
		else ans += x;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include<string.h>
int main(void)
{
	int c,b,r=0;
	char d[10];
	char a[100];
	scanf("%s %d",&d,&b);
	for(c=0;c<b;c++){
		scanf("%s",a);
		strncat(a,a,10);
		if((strstr(a,d))!=NULL){
			r++;
		}
	}
	printf("%d\n",r);
	return 0;
}


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

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

	int i = 1;
	
	while (1) {
		int x = i;
		if (x % 3 == 0) {
			cout << " " << i;
		}
		else {
			while (1) {
				if (x % 10 == 3) {
					cout << " " << i;
					break;
				}
				x /= 10;
				if (x == 0) break;
			}
		}
		if (++i > N) break;
	}
	cout << endl;
}


Measured memory_bytes: 3088
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int mm=1000000007;
int i,j,k,n,m,ans,f[2101][2101],s[2101][2101];
int main(){
	scanf("%d%d",&n,&m);memset(f,0,sizeof(f));
	for (i=2;i<=n;i++) f[1][i]=1,s[1][i]=i-1;
	for (i=2;i<m;i++){
		for (j=2;j<=n-i+1;j++){
			if (n-j-i+2>0) f[i][j]=f[i-1][j];else f[i][j]=0;
			f[i][j]=(f[i][j]+s[i-1][n]-s[i-1][j])%mm;f[i][j]=(f[i][j]+mm)%mm;
		}
		for (j=2,s[i][1]=0;j<=n;j++) s[i][j]=(s[i][j-1]+f[i][j])%mm;
	}
	for (ans=((m==1)?1:s[m-1][n]),i=1;i<n-m;i++) ans=ans*2%mm;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 33792
#include <iostream>

int main() {
    std::string N;
    std::cin >> N;
    int A = N[0] - '0';
    int B = N[1] - '0';
    int C = N[2] - '0';
    int D = N[3] - '0';

    if (A + B + C + D == 7) {
        std::cout << A << '+' << B << '+' << C << '+' << D << "=7" << std::endl;
    } else if (A + B + C - D == 7) {
        std::cout << A << '+' << B << '+' << C << '-' << D << "=7" << std::endl;
    } else if (A + B - C + D == 7) {
        std::cout << A << '+' << B << '-' << C << '+' << D << "=7" << std::endl;
    } else if (A + B - C - D == 7) {
        std::cout << A << '+' << B << '-' << C << '-' << D << "=7" << std::endl;
    } else if (A - B + C + D == 7) {
        std::cout << A << '-' << B << '+' << C << '+' << D << "=7" << std::endl;
    } else if (A - B + C - D == 7) {
        std::cout << A << '-' << B << '+' << C << '-' << D << "=7" << std::endl;
    } else if (A - B - C + D == 7) {
        std::cout << A << '-' << B << '-' << C << '+' << D << "=7" << std::endl;
    } else if (A - B - C - D == 7) {
        std::cout << A << '-' << B << '-' << C << '-' << D << "=7" << std::endl;
    }
}


Measured memory_bytes: 256
s=input().rstrip().split(' ')
W=int(s[0])
H=int(s[1])
x=int(s[2])
y=int(s[3])
r=int(s[4])
cx=W-r
cy=H-r
if cx>=x & x>=r:
    if cy>=y & y>=r:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 7688
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main() {
    int n,m;
    cin>>n>>m;
    int h[n];
    rep(i,n) cin>>h[i];
    vector<vector<int>> G(n);
    rep(i,m){
        int a,b;
        cin>>a>>b;
        a--,b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    int ans=0;
    rep(i,n){
        bool ok=true;
        for(int j=0;j<G[i].size();j++){
            if(h[i]<=h[G[i][j]]) ok=false;
        }
        if(ok){
            ans++;
            //cout<<i<<endl;
        }
    }

    cout<<ans<<endl;
}



Measured memory_bytes: 8800
import java.util.*;
import java.math.*;
import java.io.*;

class Main
{
	
	public static void main(String[] args)
	
	{
		new Main().run();
	}
	
	void run(){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int sz=0;
		while((1L<<sz)<=N)++sz;
		int[][] a=new int[N][N];
		for(int i=0;i<N;++i)for(int j=0;j<N;++j)a[i][j]=-1;
		for(int shift=0;shift<sz;++shift){
			for(int i=0;i<N;++i){
				for(int j=0;j<N;++j){
					if((((i>>shift)%2)^((j>>shift))%2)==0)continue;
					if(a[i][j]!=-1)continue;
					a[i][j]=shift+1;
					a[j][i]=shift+1;
				}
			}
		}
		for(int i=0;i<N;++i){
			for(int j=i+1;j<N;++j){
				System.out.print(a[i][j]+(j==N-1?"\n":" "));
			}
		}
		
	}
	
	
	void tr(Object...objects){
		System.out.println(Arrays.deepToString(objects));
	}
}


Measured memory_bytes: 43444
#include<iostream>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<map>
#include<numeric>
#include<stack>
#include<queue>
#include<functional>
#include<cassert>
#include<set>
#include<time.h>
#include<cmath>
#include<functional>
#include<cassert>
#define rep(a,b) for(int a=0;a<b;++a)
#define REP(a,b,c,d) for(int a=b;a<c;a+=d)
#define yes cout<<"Yes"<<endl
#define no cout<<"No"<<endl
#define mod 1000000007
using namespace std;
using ll = long long;
using p_i = pair<int, int>;
int main() {
    int N,H,W;cin>>N>>H>>W;
    vector<int> A(N),B(N);
    int ans=0;
    rep(i,N){
        cin>>A[i]>>B[i];
        ans+=min(A[i]/H,B[i]/W);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "";
            if (sS[0] == "ABC") { sOut = sS[0].Replace('B', 'R'); }
            else { sOut = sS[0].Replace('R', 'B'); }

            // 出力
            System.Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 25704
s=[]
yoko=[]
ans="Yes"
for i in range(3):
  a, b, c=map(int, input().split())
  s.append([a,b,c])
  yoko.append([a-b, b-c, c-a])
if yoko[0]!=yoko[1] or yoko[1]!=yoko[2]:
  ans="No"
tate=[]
for i in range(3):
  tate.append([s[i][0]-s[i][1], s[i][1]-s[i][2], s[i][2]-s[i][0]])
if tate[0]!=tate[1] or tate[1]!=tate[2]:
  ans="No"
print(ans)
  

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

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

using ipair = pair<int,int>;

int INF = 1e9+7;

using ipair = pair<int,int>;
bool operator>(const ipair a,const ipair b){return a.first > b.first;}


int main(){

  string S;
  cin >> S;

  vector<int> split_idxs; // RL
  vector<int> target_idxs; // LR
  rep(i, S.size()){
    if(i==0) continue;
    if(S[i] == 'R' && S[i-1] == 'L'){
      split_idxs.push_back(i);
    }
    if(S[i] == 'L' && S[i-1] == 'R'){
      target_idxs.push_back(i);
    }
  } 
  split_idxs.push_back(S.size());

  // rep(i, split_idxs.size()) cout << " " << split_idxs[i];
  // cout << endl;
  // rep(i, split_idxs.size()) cout << " " << target_idxs[i];
  // cout << endl;

  int current_idx = 0;
  vector<ipair> even_odd_cnts;

  rep(i, target_idxs.size()){
    // cout << "=========" << endl;
    // cout << "iter:" << i << endl;
    // cout << "current_idx:" << current_idx << endl;
    int target_idx = target_idxs[i];
    int split_idx = split_idxs[i];

    int even_cnt = 0;
    int odd_cnt = 0;

    int r_length = target_idx - current_idx;
    odd_cnt += ((r_length%2==1)?r_length/2+1: r_length/2); 
    even_cnt += r_length/2;
    // cout << "r_even_cnt:" << ceil(r_length/2) << endl;
    // cout << "r_odd_cnt:" << r_length/2 << endl;

    int l_length = split_idx - target_idx;
    even_cnt += ((l_length%2==1)? l_length/2+1: l_length/2);
    odd_cnt += l_length/2;

    // cout << "target_idx:" << target_idx << endl;
    // cout << "split_idx:" << split_idx << endl;
    // cout << "l_length:" << l_length << endl;
    // cout << "r_length:" << r_length << endl;
    // cout << "even:" << even_cnt << endl;
    // cout << "odd:" << odd_cnt << endl;

    even_odd_cnts.push_back(make_pair(even_cnt, odd_cnt));
    current_idx = split_idx;
  }

  vector<int> ans_vect(S.size(), 0);

  // cout << "even_odd_cnts:" << even_odd_cnts.size() << endl;

  rep(i, even_odd_cnts.size()){
    ans_vect[target_idxs[i]] = even_odd_cnts[i].first;
    ans_vect[target_idxs[i]-1] = even_odd_cnts[i].second;
  }

  rep(i, ans_vect.size()){
    if(i) cout << " ";
    cout << ans_vect[i];
  }

  cout << endl;

  return 0;
}

Measured memory_bytes: 1976
#include <vector>
#include <iostream>
#include <set>
#include <cstdio>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <ctime>
#include <algorithm>
#include <tuple>
#include <algorithm>
#include <limits>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;

#include <algorithm>
#include <limits>
#include <cstring>
#include <array>

bool solve(int n) {
    vector<char> v;
    while (n) {
        v.push_back(n%10);
        n /= 10;
    }
    for (int i = 0; i < v.size()/2; i++) {
        if (v[i] != v[v.size()-1-i]) return false;
    }
    return true;
}

int main() {
    int n;
    cin >> n;
    int r = 10000000;
    for (int i = 0; i <= 10001; i++) {
        if (solve(i)) {
            if (abs(n-i) < abs(n-r)) {
                r = i;
            }
        }
    }
    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
int main()
{
    using ll = long long;

  ll n, k;
    cin >> n >> k;
    ll ans;
    for(ll i = k+1; i <= n; i++)
    {
        ll a = (n / i) * (i - k);
        int c = n % i - k + 1;
        if(k == 0) c--;
        int b = max(0, c);
        ans += a + b;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int K, N;
  cin>>K>>N;
  vector<int> house(N,0);
  vector<int> diff(N,0);
  for(int i=0; i<N; i++){
    cin>>house.at(i);
  }
  for(int i=0; i<N-1; i++){
    diff.at(i)=house.at(i+1)-house.at(i);
  }
  diff.at(N-1)=house.at(0)+K-house.at(N-1);
  sort(diff.begin(), diff.end());
  int ans=K-diff.at(N-1);
  cout<<ans<<endl;
}

Measured memory_bytes: 4724
def solve(a, b, c, k):
    if k <= a:
        return k
    elif k <= a + b:
        return a
    else:
        return a - (k - (a + b))

if __name__ == '__main__':
    a, b, c, k = [int(arg) for arg in input().split()]
    print(solve(a, b, c, k))

Measured memory_bytes: 9176
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    String N = sc.nextLine();
    
    int num = 0;
    
    for(int i = 0; i < N.length(); ++i) {
      num += Character.getNumericValue(N.charAt(i));
    }
    
    System.out.println(num % 9 == 0 ? "Yes" : "No");
  }
}

Measured memory_bytes: 41368
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30

// #define MAX 100010

#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

long long int fact[3000];

void pre()
{
    fact[0]=1;
    fact[1]=1;
    for(int i=2;i<2005;i++)
    {
        fact[i]= (fact[i-1]*i)%MOD;
    }
}

long long int poww(long long int a,long long int b)
{
    if(b==0)
        return 1;
    long long int x = poww(a,b/2)%MOD;
    if(b%2==0)
    {
        return (x*x)%MOD;
    }
    else
    {
        return (((x*x)%MOD)*a)%MOD;
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    #endif
    int a;
    cin>>a;
    if(a<1200)
        cout<<"ABC";
    else
        cout<<"ARC";
    cout<<endl;

    return 0;
}

Measured memory_bytes: 256
def BubbleSort(N, A):
    for i in range(N):
        flag = True
        while flag:
            flag = False
            for j in range(1, N):
                if int(A[j][1]) < int(A[j - 1][1]):
                    A[j], A[j - 1] = A[j - 1], A[j]
                    flag = True


def SelectionSort(N, A):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(A[j][1]) < int(A[minj][1]):
                minj = j
        A[i], A[minj] = A[minj], A[i]


def trace(A):
    for i in range(len(A)):
        print(A[i], end='')
        if i != len(A) - 1:
            print(' ', end='')
    print('')


N = int(input())
A = [str(i) for i in input().split()]


A1 = A.copy()

BubbleSort(N, A)
trace(A)
print('Stable')

SelectionSort(N, A1)
trace(A1)

same = True
for i in range(N):
    if A[i] != A1[i]:
        same = False
if same:
    print('Stable')
else:
    print('Not stable')



Measured memory_bytes: 5632
// dile a la jardinera que traigo flores

#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define sz(x) int(x.size())
#define all(v) (v).begin(),(v).end()
#define trace(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define FER(i,a,b) for(int i = int(a); i < int(b); ++i)
#define IFR(i,a,b) for(int i = int(a); i >= int(b); i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;

const int N=1e5+5;
int mm[N];

int main(){	
	fastio;
	int n;cin>>n;
	FER(i,0,n)cin>>mm[i];
	int mx=-1,c=0;
	FER(i,0,n){
		if(mm[i]>=mx){
			c++;
			mx=mm[i];
		}
	}
	cout<<c<<endl;
	return 0;
}


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

int main() {
  string s;
  int i = 0;
  int count = 0;
  cin >> s;
  while (i < s.length() - i - 1){
    if(s[i] != s[s.length() - 1 - i]) count++;
    i++;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
a,b,k = map(int, input().split())

for _ in range(k//2):
    if a%2: a-=1
    b += a//2
    a -= a//2

    if b%2: b-=1
    a += b//2
    b -= b//2

if k%2:
    if a%2: a-=1
    b += a//2
    a -= a//2
    


print(a,b)


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

int main(){

    // omajinai
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    // omajinai

    ll n;
    cin >> n;
    vector<ll> a(n);
    for(ll i = 0;i < n;i ++){
        cin >> a.at(i);
    }

    ll sum = 0;
    for(ll i = 0;i < n;i ++){
        sum += a.at(i);
    }

    ll b = sum;
    ll c = 0;
    ll ans = 100000000000000;

    for(ll i = 0;i < n-1;i ++){
        b -= a.at(i);
        c += a.at(i);
        ans = min(ans,abs(b-c));
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
// "include" {{{
#include <deque>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
// }}}
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define int long long
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

int gcd(int a,int b){return b ? gcd(b,a%b) : a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,a,b;
	cin >> n >> a >> b;
	cout << ((abs(a - b)  % 2 == 1) ? "Borys\n" : "Alice\n") << '\n';
	return 0;
}


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

//#define errOut(s) { std::cerr << "LINE:" << __LINE__ << " " << #s << " = " << s << std::endl; }
#define errOut(s)

int64_t calc(int64_t n, int64_t m) {
    if (n == 1 && m == 1) {
        return 1;
    }
    if (n == 1) {
        return m - 2;
    }
    if (m == 1) {
        return n - 2;
    }
    if (n == 2) {
        return 0;
    }
    if (m == 2) {
        return 0;
    }

    return (n - 2) * (m - 2);
}

int main() {
    int64_t n, m;
    std::cin >> n >> m;
    std::cout << calc(n, m) << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
#define P pair<int,int>
#define LP pair<LL,LL>
int N, A, B;
int main(){
    cin >> N >> A >> B;
    cout << min(A, B) << " " << max(0, A + B - N) << endl;
    return 0;
}

Measured memory_bytes: 256
import math

def main():
    # tt = int(input())
    
    tt = 1
    for _ in range(0, tt):
        n = int(input())
        
        arr = input().split(' ')
        arr = sorted(arr)
        mult = 1
        for i in range(0, n):
            mult *= int(arr[i])

            if mult > 10**18:
                mult = -1
                break

        print(mult)

if __name__ == '__main__':
    main()

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

int main() {
  int A , B , C , D;
  cin >> A>>B>>C>>D;

  if (A+B < C+D) {
    cout << "Right" << endl;
  }
  if (A+B > C+D) {
    cout << "Left" << endl;
  }
  if (A+B == C+D) {
    cout << "Balanced" << endl;
  }
}





Measured memory_bytes: 256
#include <iostream>

using namespace std;
#define ll long long

int main() {
ll n;
cin>>n;
ll sum=0;
for(ll i=1;i<=n;i++)
{
    ll t=n/i;
    sum+=((t*(t+1))/2)*i;
    
    
}
    cout<<sum<<endl;
    
    
    
    return 0;
}

Measured memory_bytes: 3584
#include <cmath>
#include <cstdio>
#include <vector>
#include <list>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stack>
#include <fstream>
#include <queue>
#include <iomanip>
#include <iterator>
#include <map>
#include <unordered_map>
#include <set>
#define fast ios_base::sync_with_stdio(false)
#define mxn (ll)(2e5+5)
#define mod (ll)(1e9+7)
#define mod1 (ll)(998244353)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define vvi vector<vi >
#define pi pair<ll,ll>
#define vvpi vector<vector<pi > >
#define vpi vector<pi >
#define vppi vector<pair<ll,pi > >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define fs first
#define se second
#define crz(v,n) v.clear(),v.resize(n+1,0)
#define print(v) for(ll it=0;it<v.size();it++) cout<<v[it]<<" ";cout<<endl
#define printp(v) for(ll it=0;it<v.size();it++) cout<<v[it].first<<" "<<v[it].second<<endl
using namespace std;
int v[mxn],k,n;
bool check(int x){
	int s=0;
	for(int i=0;i<n;i++) s+=(v[i]/x-(v[i]%x==0));
	return s<=k;
}
int main(){
	cin>>n>>k;for(int i=0;i<n;i++) cin>>v[i];
	int l=1,r=1e9+5,mid,c=0;
	while(c++<35){
		mid=(l+r)/2;
		if(check(mid)) r=mid; else l=mid;
	}cout<<r<<endl;
}


Measured memory_bytes: 4268
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}


int main(){
  string s;
  cin >> s;
  string t="";
  bool a=0;
  FOR(i,s.size()-1){
    if(s[i]=='B' && s[i+1]=='C'){
      t+='D';
      if(i+1==s.size()-1){
        a=1;
      }
      i++;
    }else{
      t+=s[i];
    }
  }
  if(!a){
    t+=s[s.size()-1];
  }

  ll cnta=0,cntd=0,cc=-1,cnt=0,ans=0;

  FOR(i,t.size()){
    if(t[i]=='B' || t[i]=='C'){
      ans+=cntd-(cc+1+cc+cnt)*cnt/2;
      cc=i;
      cnt=0;
      cnta=0;
      cntd=0;
      
    }else{
      if(t[i]=='A'){
        cnta+=i;
      }else{
        cntd+=i;
        cnt++;
      }
      
    }
  }
  ans+=cntd-(cc+1+cc+cnt)*cnt/2;
  
  cout << ans << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i <(n) ; ++i)
#define PI 3.14159265
#define pb push_back
#define pr pair<int,int>
using namespace std;
using ll = long long;
// using mod = 1000000000 + 7;
void self_max(int &a,int b){
	a = max(a,b);
}

void self_min(int &a,int b){
	a = min(a,b);
}
int main(){
	int count = 1;
	int n;
	while(true){
		cin >> n;
		if(n == 0) break;
		cout << "Case " << count << ": " << n << endl;
		count++;
	}

	return 0;
}



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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

string str;
int cnt;

int main(){
    cin >> str;
    rep(i,str.size()) if (str[i] == 'p') cnt++;
    cout << str.size()/2-cnt << endl;
}
































Measured memory_bytes: 512
// 課題3_4 AtCoder Beginner Contest 144 B - 81
// nk777
 
#include <stdio.h>
 
int main(void){
    // 整数Nを格納n,カウンタi, 結果格納result
    int n, i, result = 0;
 
    // nを受け取る
    scanf("%d", &n);

    for (i = 1; i < 10; i++)
    {
        // iの段を調べる
        // n/iの商が整数で1以上9以下
        if (n % i == 0 && 0 < n / i && n / i < 10)
        {
            result = 1;
            break;
        }
    }
    if (result == 1)
    {
        printf("Yes\n");
    }
    else
    {
        printf("No\n");
    }
    
    return 0;
}

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

# dp[i][j] = i個目とi - 1個目に対して、j(True:反転させた, False:元のまま)の状態でのi個目までの最大値

dp = [[0] * 2 for i in range(N)]

dp[0][False] = None
dp[0][True] = None
dp[1][False] = A[0] + A[1]
dp[1][True] = (A[0] + A[1]) * (-1)

for i in range(2, len(dp)):
  dp[i][False] = max(dp[i - 1][False] + A[i], dp[i - 1][True] + A[i])
  dp[i][True] = max(dp[i - 1][False] - A[i - 1] * 2 - A[i], dp[i - 1][True] + A[i - 1] * 2 - A[i])

print(max(dp[N - 1][False], dp[N - 1][True]))

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

int main(){
	string s;
	
	cin>>s;
	
	int y=(s[5]-'0')*10+s[6]-'0';
	
	if(y<=4){
		cout<<"Heisei"<<endl;
	}else{
		cout<<"TBD"<<endl;
	}
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    int64_t A[N];
    for(int i = 0; i < N; i++) {
        cin >> A[i];
    }
    int64_t ret = 0;
    int64_t diff = 0;
    for(int i = 1; i < N; i++) {
        diff = A[i - 1] - A[i];
        if(0 <= diff) {
            A[i] += diff;
            ret += diff;
        }
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 5096
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#define rep(i,n) for (long long i=0; i < (n); ++i)
#define rep2(i,n,m) for(long long i=n;i<=m;i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main(){
int a,b,c, x,y ;
cin >>a>>b>>c>>x>>y ;
int ans=0 ;
if(x>=y)
ans=c*y*2+a*(x-y) ;
else
ans =c*x*2+b*(y-x) ;
int zen= c*2*max(x,y) ;
cout <<min(zen,min((a*x+b*y),ans )) <<endl ;
     return 0;
}

Measured memory_bytes: 256
package main
import (
	"fmt"
)
func main(){
	var n, temp, m int64
	fmt.Scan(&n)
	m=n
	temp=0
	for n!=0{
		temp+=n%10
		n/=10
	}
	if m%temp==0{
		fmt.Println("Yes")
	}else{
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
import sys
sys.setrecursionlimit(99999999)


[n,m]=list(map(int,input().split()))
friends=[]
for i in range(m):
    friends.append(list(map(int,input().split())))

tomodachi=[[]for i in range(n)]

for i in range(m):
    tomodachi[friends[i][0]-1].append(friends[i][1]-1)
    tomodachi[friends[i][1]-1].append(friends[i][0]-1)

for i in range(n):
    tomodachi[i]=list(set(tomodachi[i]))

namelist=[1 for i in range(n)]
teams=[]

def haba(x,kari,tomodachi,namelist):
    for i in range(len(tomodachi[x])):
        if namelist[tomodachi[x][i]]==1:#生き残っているなら
            kari.append(tomodachi[x][i])
            namelist[tomodachi[x][i]]=0#殺す
            haba(tomodachi[x][i],kari,tomodachi,namelist)
    return(kari)
            


for i in range(n):
    if namelist[i]==1:
        teams.append(list(set(haba(i,[i],tomodachi,namelist))))

saidai=0

for i in range(len(teams)):
    if saidai<len(teams[i]):
        saidai=len(teams[i])

ans=saidai

print(ans)

Measured memory_bytes: 263064
import java.util.*

fun main(args:Array<String>){
    val (n,m) = readLine()!!.split(" ").map{it.toInt()}
    val a = (1 .. m).map{readLine()!!.toInt()}
    var dp = LongArray(n + 1)
    dp[0] = 1
    var j = 0
    val mod = 1000000007
    for(i in 1 .. n){
        if(j < m && a[j] == i){
            j++
        }
        else{
            dp[i] = (dp[i - 1] + if(i >= 2) dp[i - 2] else 0L) % mod
        }
    }
    println(dp[n])
}


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

int main() {
	int n,m;
	cin >> n >> m;
	vector<int> a(m),b(m);
	rep(i,m) {
		cin >> a[i] >> b[i];
		a[i]--;
		b[i]--;
	}
	dsu d(n);
	rep(i,m)
		d.merge(a[i],b[i]);
	vector<vector<int>> lst;
	lst = d.groups();
	cout << lst.size() -1 << endl;
	return 0;
}


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

islands = [0 for i in range(n)]

for i in range(m):
  a, b = map(int, input().split())
  
  if a == 1:
    if islands[b-1] == 2:
      print('POSSIBLE')
      break
    islands[b-1] = 1
  if b == n:
    if islands[a-1] == 1:
      print('POSSIBLE')
      break
    islands[a-1] = 2
    
  if i == m-1:
    print('IMPOSSIBLE')

Measured memory_bytes: 4656
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 2000001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,
q,q1,q2,q3,q4,r,s,t,u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

void solve(){
  m=7;c=1;
  L ten=10;
  if(n%2==0)c=5e6+1;
  while(c<=5e6){
    if(m%n==0){
      break;
    }
    m=m%n;
    m=(m+(7*ten))%n;
    ten=(ten*10)%n;
    c++;
  }
  if(c>5e6)printf("-1\n");
  else printf("%lld\n",c);
}
int main()
{
    scanf("%lld",&n);
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3804
require 'set'
N, M = gets.split.map(&:to_i)
a_set = Set.new(M.times.map { gets.to_i })
MOD = 10 ** 9 + 7

dp = Array.new(N + 10) { 0 }
dp[0] = 1
(0..(N - 1)).each do |i|
  next if a_set.include?(i)
  unless a_set.include?(i + 1)
    dp[i + 1] = (dp[i + 1] + dp[i]) % MOD
  end
  unless a_set.include?(i + 2)
    dp[i + 2] = (dp[i + 2] + dp[i]) % MOD
  end
end
puts dp[N]


Measured memory_bytes: 9980
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  int n; cin >> n;
  vector<int> result (n, 0);
  for (int i = 0; i < n-1; i++) {
    int x; cin >> x;
    result[x-1]++;
  }
  for (int x : result) cout << x << '\n';
  return 0;
}



Measured memory_bytes: 4004
import math
a, b, h, m = [int(i) for i in input().split()]
h_rad = (h + m / 60) / 12
m_rad = m / 60
t = abs(h_rad - m_rad)
rad = min(t, 1-t) * 2 * math.pi
c2 = a*a + b*b - 2 * a * b * math.cos(rad)
print(math.sqrt(c2))

Measured memory_bytes: 9504
#define FILEIO(a) freopen(a".in","r",stdin);freopen(a".out","w",stdout);
#include <stdio.h>

const int N=200005;

int n,x[N];
int ne=1,h[N]; struct edge{int to,x;}e[2*N];
inline void ins(int s,int t) {
	e[++ne].to=t; e[ne].x=h[s]; h[s]=ne;
}

int fa[N],f[N],g[N]; char ans[N];
void dfs(int u) {
	for(int i=h[u];i;i=e[i].x) {
		int v=e[i].to;
		if(v==fa[u]) continue;
		fa[v]=u; dfs(v);
		if(x[u]>x[v]&&!f[v]) ++f[u];
	}
}
void dfs2(int u) {
	ans[u]=g[u]||f[u];
	for(int i=h[u];i;i=e[i].x) {
		int v=e[i].to;
		if(v==fa[u]) continue;
		g[v]=x[v]>x[u]&&!(f[u]-(x[u]>x[v]&&!f[v])+g[u]);
		dfs2(v);
	}
//	printf("%d: f=%d g=%d\n",u,f[u],g[u]);
}

int main() {
	int a,b;
	scanf("%d",&n);
	for(int i=1;i<=n;++i) scanf("%d",x+i);
	for(int i=1;i<n;++i) {
		scanf("%d%d",&a,&b);
		ins(a,b); ins(b,a);
	}
	fa[1]=0; dfs(1);
	g[0]=0; dfs2(1);
	for(int i=1;i<=n;++i) {
		if(ans[i]) printf("%d ",i);
	}
	return 0;
}

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


int main(){

    int n, d; cin >> n >> d;
    int cnt =0;
    while(n--)
    {
        int x, y; cin >> x >> y;
        if(sqrt(pow(x, 2)+pow(y,2))<=d)
        {
            cnt++;
        }
    }
    cout << cnt;
    return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    string s;
    cin >> s;
    int n = s.length();

    int ans = 0;
    rep(i, n/2) {
        if (s[i] != s[n-i-1]) ans++;
    }

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

Measured memory_bytes: 256
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

import itertools
a=int(input())
A=[]
for i in range(a):
    A.append(str(i+1))

li=list(itertools.combinations_with_replacement(A, 3))
s = 0
for lis in li:
    a = int(lis[0])
    b = int(lis[1])
    c = int(lis[2])
    
    if math.gcd(b,c) == 1:
        gcd1 = 1
    else:
        gcd1 = gcd(a,b,c)
    
    if a==b and b==c:
        s = s + gcd1
    elif a==b or b==c:
        s = s + 3*gcd1
    else:
        s = s + 6*gcd1
print(s)

Measured memory_bytes: 105968
#include<cstdio>
#include<iostream>
#include<map>
#include<queue>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;

int a[2005];

int main(){
	int n,x,y,ans;
	cin >> n >> x >> y;
	for(int i = 1;i <= n;i++) cin >> a[i];
	if(n > 1) ans = max(abs(a[n] - a[n - 1]),abs(a[n] - y));
	else ans = abs(a[n] - y);
	cout << ans;
}

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

int main() {
	int n,x=1;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		if(a[i]%2==0)
		{
			if(a[i]%3!=0 && a[i]%5!=0)
			x=0;
		}
	}
	if(x)
	cout<<"APPROVED";
	else
	cout<<"DENIED";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
int f[101000],size[101000],n;
int h[101000],nxt[201000],to[201000],K=0,cost[201000],len[201000];
void ins(int u,int v,int c){nxt[++K]=h[u];h[u]=K;to[K]=v;cost[K]=c;}
void dfs(int x,int fa)
{
	size[x]=1;
	for(int i=h[x];i;i=nxt[i])
	{
		if(to[i]==fa)continue;len[to[i]]=cost[i];dfs(to[i],x);
		size[x]+=size[to[i]];f[x]=max(f[x],size[to[i]]);
	}
	f[x]=max(f[x],n-size[x]);
}
int main()
{
	scanf("%d",&n);long long ans=0;
	for(int i=1;i<n;i++)
	{
		int u,v,c;scanf("%d%d%d",&u,&v,&c);
		ins(u,v,c);ins(v,u,c);
	}
	dfs(1,0);int k1,k2,Min=2e9;
	for(int i=1;i<=n;i++)
	{
		if(f[i]<Min)k1=i,k2=0,Min=f[i];else if(f[i]==Min)k2=i;
		ans+=1ll*min(size[i],n-size[i])*len[i];
	}ans*=2;
	if(!k2)
	{
		Min=2e9;
		for(int i=h[k1];i;i=nxt[i])Min=min(Min,cost[i]);
		printf("%lld",ans-Min);
	}
	else
	{
		for(int i=h[k1];i;i=nxt[i])if(to[i]==k2)return 0*printf("%lld",ans-cost[i]);
	}
	return 0;
}

Measured memory_bytes: 8192
N = int(input())
A = list(map(int, input().split()))
count = 1
Flag = None

for i in range(1, N):
    if A[i-1] == A[i]:
        pass
    elif Flag == None:
        Flag = (A[i-1] < A[i])
    elif Flag == (A[i-1] < A[i]):
        pass
    else:
        count += 1
        Flag = None

print(count)

Measured memory_bytes: 15020
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 11 01:27:46 2020

@author: liang
"""

N, M = map(int,input().split())
L = list()
R = list()
for i in range(M):
    l, r = map(int,input().split())
    L.append(l)
    R.append(r)

ans = min(R) - max(L) + 1
if ans < 0:
    ans = 0
print(ans)

Measured memory_bytes: 16860
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
 
#define mod 1000000007
int n,m,l,r,x,ans=0;
vector<pair<int,int> > v[305];
int f[305][305][305];
 
inline bool check(int r,int g,int b){
    int k=max(r,max(g,b));
    for(int i=0;i<v[k].size();i++){
        int cnt=0;
        int l=v[k][i].first,x=v[k][i].second;
        if(r>=l)cnt++;
        if(g>=l)cnt++;
        if(b>=l)cnt++;
        if(cnt!=x)return false;
    }
    return true;
}
 
inline void add(int &x,const int &y){
    x+=y;if(x>=mod)x-=mod;
}
 
int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++){
        scanf("%d%d%d",&l,&r,&x);
        v[r].push_back(make_pair(l,x));
    }
    f[0][0][0]=1;
    register int r,g,b;
    for(r=0;r<=n;r++)
    for(g=0;g<=n;g++)
    for(b=0;b<=n;b++){
        if(f[r][g][b]==0)continue;
        if(!check(r,g,b)){
            f[r][g][b]=0;
            continue;
        }
        int k=max(r,max(g,b));
        add(f[k+1][g][b],f[r][g][b]);
        add(f[r][k+1][b],f[r][g][b]);
        add(f[r][g][k+1],f[r][g][b]);
        if(k==n)add(ans,f[r][g][b]);
    }
    printf("%d",ans);
}

Measured memory_bytes: 110848
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define print(x) cout << (x) << endl;
#define printa(x, n) for(ll i = 0; i < n; i++) {cout << (x[i]) << " ";} cout << endl;
#define printd(x) printf("%.12f\n", ans);
#define Yes() cout << "Yes" << endl;
#define No() cout << "No" << endl;
#define YES() cout << "YES" << endl;
#define NO() cout << "NO" << endl;
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using Pll = pair<ll, ll>;
using P = pair<int, int>;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

int main(void) {

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

    int n;
    cin >> n;

    if (n % 2 == 0) cout << (n / 2) * (n / 2)<< endl;
    else cout << (n / 2 + 1) * (n / 2) << endl;

    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++)
using ll = long long;
int mod = 1000000000+7;

int main(){

	ll a;
	long double b;
	cin>>a>>b;

	ll ans=a*b;
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 3732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
template <class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main() {
    ll A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;

    vector<ll> amounts;
    {
        ll n = min(X, Y);
        ll amount = n * C * 2;
        ll diff = X - Y;
        if (diff > 0) {
            amount += A * diff;
        } else {
            amount += B * -diff;
        }
        amounts.push_back(amount);
    }

    {
        ll n = max(X, Y);
        amounts.push_back(n * C * 2);
    }
    { amounts.push_back(A * X + B * Y); }

    sort(amounts.begin(), amounts.end());
    cout << amounts[0] << endl;
    return 0;
}

Measured memory_bytes: 3616
/*
[abc137] E - Coins Respawn
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 2500;
const int MAX_M = 5000;
const int INF = 1e9;

const int MAX_V = MAX_N;

int N, M, P;
int A[MAX_M], B[MAX_M], C[MAX_M];
vector<int> g[2][MAX_N];
bool visited[2][MAX_N];

int d[MAX_V];

void dfs(int r, int v) {
    if (visited[r][v]) {
        return;
    }
    visited[r][v] = true;

    for (int to : g[r][v]) {
        dfs(r, to);
    }
}

bool bellman_ford(int s, int V, int E) {
    fill(d, d + N, INF);
    d[s] = 0;
    for (int i = 0; i < V; i++) {
        for (int j = 0; j < E; j++) {
            if (d[A[j]] < INF && d[B[j]] > d[A[j]] + C[j]) {
                d[B[j]] = d[A[j]] + C[j];
                if (i == V - 1 && visited[0][B[j]] && visited[1][B[j]]) {
                    return true;
                }
            }
        }
    }
    return false;
}

ll solve() {
    for (int i = 0; i < M; i++) {
        C[i] = -(C[i] - P);
        g[0][A[i]].push_back(B[i]);
        g[1][B[i]].push_back(A[i]);
    }

    dfs(0, 0);
    dfs(1, N - 1);

    if (bellman_ford(0, N, M)) {
        return -1;
    }

    return max(0, -d[N - 1]);
}

int main() {
    cin >> N >> M >> P;
    for (int i = 0; i < M; i++) {
        cin >> A[i] >> B[i] >> C[i];
        A[i]--, B[i]--;
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 640
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		// 入力
		final int a,b, h;
		try(Scanner scan = new Scanner(System.in)) {
			a = scan.nextInt();
			b = scan.nextInt();
			h = scan.nextInt();
		}
		//面積が整数になることは保障されている。
		int result = (a + b) * h / 2;
		
		// 出力
		try (PrintWriter out = new PrintWriter(System.out)) {
			out.println(result);
		}

	}

}


Measured memory_bytes: 10056
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

  string s;
  cin >> s;

  int n = s.length();

  ll dp[n + 1];
  dp[0] = 1;
  dp[1] = 3;
  for(int i = 2; i <= n; i++){
    dp[i] = (3 * dp[i - 1]) % MOD;
  }

  ll sum = 1;
  for(int i = n - 1; i >= 0; i--){
    if(s[i] == '1') sum = (dp[n - i - 1] + 2 * sum) % MOD;
  }

  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 1344
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;

namespace AtCoder_Beginner_Contest_128
{
    class Program
    {
        public struct Pair
        {
            public string S;
            public long P;
            public long Num;
            public Pair(string s, long p, long num) { S = s; P = p;Num = num; }
        }
        static public int[] SIn() { return ReadLine().Split().Select(int.Parse).ToArray(); }
        static public string[] SInS() { return ReadLine().Split().ToArray(); }
        static void Main(string[] args)
        {
            var NM = SIn();
            var N = NM[0];
            var M = NM[1];
            var ki = new int[11];
            var sij = new int[11, 11];

            for (var i = 0; i < M; ++i)
            {
                var ksi = SIn();
                ki[i] = ksi[0];
                for (var j = 1; j <= ksi[0]; ++j)
                {
                    sij[i, j - 1] = ksi[j];
                }
            }
            var pi = SIn();
            var cnt = 0;
            for (var i = 0; i < Math.Pow(2,N); ++i)
            {
                var ibit = i;
                var sw = new int[10];
                for (var j = 0; j < 10; ++j)
                {
                    if ((ibit & 1) != 0)
                        sw[j] = 1;
                    ibit = ibit >> 1;
                }
                var flg = true;
                for (var j = 0; j < M; ++j)
                {
                    var sum = 0;
                    for (var k = 0; k < ki[j]; ++k)
                    {
                        sum += sw[sij[j, k] - 1];
                    }
                    if (sum % 2 != pi[j])
                    {
                        flg = false;
                        break;
                    }
                }
                if (flg) ++cnt;
            }
            WriteLine(cnt);
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using Edge = pair<int,int>;
using Graph = vector<vector<Edge>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
// ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main() {
  ll h,w; cin >> h >> w;
  if(h==1 || w==1) {
    cout << 1 << endl;
    return 0;
  }

  if(h*w%2==1){
    cout << h * w / 2 + 1 << "\n";
  } else {
    cout << h*w/2 << "\n";
  }
    

}


Measured memory_bytes: 256
card = []       #リスト型の変数カードを定義する。
for i in range(3):      #変数カードに三列のリスト型の数字を三行文加える。
    card.append(list(map(int,input().split())))

N = int(input())        #呼ばれる数字の数を指定する。

result = [[0,0,0],[0,0,0],[0,0,0]]      #変数resultを定義する。
for _ in range(N):      #以下の動作をN回繰り返す。
    b = int(input())        #数字を読み上げる。
    for i in range(3):      #bがAijと対応していた場合、変数resultのAijと同じ位置に1を代入する。
        for j in range(3):
            if b == card[i][j]:
                result[i][j] = 1

judge = "No"        #以下の条件に当てはまらなければNoと表示する

for i in range(3):      #横のビンゴの確認
    if result[i][0] * result[i][1] * result[i][2] == 1:
        judge = "Yes"

for i in range(3):      #縦のビンゴの確認
    if result[0][i] * result[1][i] * result[2][i] == 1:
        judge = "Yes"

if result[0][0] * result[1][1] * result[2][2] == 1:     #斜めのビンゴの確認
    judge = "Yes"

if result[0][2] * result[1][1] * result[2][0] == 1:     #斜めのビンゴの確認
    judge = "Yes"

print(judge)    

Measured memory_bytes: 3064