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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
#define llINF 1000000000000000007
#define v(i) vector<i>
#define vv(i) vector<vector<i>>
// cin.eof() 入力個数の問題
// int num = atoi(string.c_str()); 文字列の整数変換

int main() {
ll n;
cin>>n;
ll ans = 1;

rep(i,n){
    ans = ans * (i+1) %INF;
}
cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 3584
A, B = map(int, input().split())

isOK = False
for i in range(1, 10001):
    a = i*0.08
    b = i*0.1
    if int(a) == A and B == int(b) :
        isOK = True
        print(i)
        break
if not isOK:
    print(-1)

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

int main(){
    int N;
    cin >> N;
    vector<vector<int> > vec(N - 1,vector<int>(3));
    rep(i,N - 1){
        rep(j,3){
            cin >> vec[i][j];
        }
    }
    rep(i,N - 1){
        int time = 0;
        for(int j = i; j < N - 1; j++){
            if (time <= vec[j][1]){
                time = vec[j][1] + vec[j][0];
            }
            else{
                if (time % vec[j][2] == 0){
                    time = time + vec[j][0];
                }
                else{
                    time = ((time / vec[j][2]) + 1) * vec[j][2] + vec[j][0];
                }
            }
        }
        cout << time << endl;
    }
    cout << 0 << endl;
}


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

using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);

	string s;
	cin >> s;
	
	string res = "";
	for(int i = 0; i < s.length(); i++) {
		if(s[i] == '0') res += '0';
		else if(s[i] == '1') res += '1';
		else if(s[i] == 'B') {
			if(res.length() != 0) {
				res = res.substr(0, res.length() - 1);
			}
		}
	}
	
	cout << res << endl;
	return 0;
}

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

int main() {
    int a[100],b[100],c[100];
	int n,sum=0;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++){
		cin>>b[i];
		sum+=b[i];
	}
	for(int i=1;i<n;i++)
		cin>>c[i];
	for(int i=1;i<n;i++){
		if(a[i]+1==a[i+1])
			sum+=c[a[i]];
	}
	cout<<sum;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <vector>
#include <algorithm>


using namespace std;



int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && a != c) {
        cout << "Yes" << endl;
    }else if (a == c && a != b) {
        cout << "Yes" << endl;
    }else if (b == c && a != c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
#include <string.h>
#include <vector>
//s#define rep(i, n) for (int i = 0; i < (n); i++)
#define MAX 10000

using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a; i<n; i++)
#define r0 return 0
#define INF (int)1e15
#define MOD 1000000007


int main(){

 string s;
  cin>>s;

  int64_t i,cnt=0,cnt2=0,n=s.length();
  string sea = "CF";
   int x = 0;
  for(i=0;i<n;i++){
     if(s[i] == sea[x]){
      x++; }

     if(x ==2){
      cout<<"Yes"<<endl;
      return 0; }
  }

      cout<<"No"<<endl;

 return 0;
 }

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

int main(){
  int a,b,c,d,e,t=0;
  cin>>a>>b>>c>>d>>e;
  if(a<0){t+=(-a*c)+d; a=0;}
  t+=(b-a)*e;
  cout<<t<<endl;
  
  return 0;
}



Measured memory_bytes: 3080
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示
const string YES = "Yes";
const string NO = "No";

void solve(std::string S){
  bool ansa=false,ansb=false;
  for (size_t i = 0; i < 3; i++) {
    if(S[i] == 'A')ansa=true;
    if(S[i] == 'B')ansb=true;
  }
  std::cout << (ansa&&ansb?"Yes":"No") << '\n';
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<typeinfo>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
	int N,C,K;
	cin >> N >> C >> K;
	vector<int> T(N);
	for(int i=0; i<N; i++){
		cin >> T.at(i);
	}
	
	sort(T.begin(), T.end());

	int cnt_bus=0;
	int cnt_num=0;
	int bus_time=0;//バスを待ち始める時間
	for(int i=0; i<N; i++){
		//バスからのとき、新しいバスつくる
		if(cnt_num==0){
			cnt_bus++;
			cnt_num++;
			bus_time=T.at(i);
		}else if(cnt_num==C){
			cnt_num=0;
			i--;
		}else{
			if(T.at(i)>bus_time+K){
				cnt_num=0;
				i--;
			}else{
				cnt_num++;
			}
		}
	}

	cout << cnt_bus << endl;
	return 0;
}

Measured memory_bytes: 640
// 2012/09/20 Tazoe

#include <iostream>
using namespace std;

int main()
{
	bool is_prime[10001];
	is_prime[0] = is_prime[1] = false;
	for(int i=2; i<=10000; i++)
		is_prime[i] = true;

	for(int i=2; i*i<=10000; i++)
		if(is_prime[i])
			for(int j=i+i; j<=10000; j+=i)
				is_prime[j] = false;

	while(true){
		int n;
		cin >> n;

		if(n==0)
			break;

		for(int i=n; i>=5; i--){
			if(is_prime[i]&&is_prime[i-2]){
				cout << i-2 << ' ' << i << '\n';
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 1168
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int k= 1;
        HashMap<String,Integer> hashMap = new HashMap<>();
        hashMap.put("SUN",7);
        hashMap.put("MON",6);
        hashMap.put("TUE",5);
        hashMap.put("WED",4);
        hashMap.put("THU",3);
        hashMap.put("FRI",2);
        hashMap.put("SAT",1);
        String s1;
        String s2;
        int a,b;
        double n;
        while(k-->0){
            a=0;
            s1=s.next();
            s2=s.next();
            for(int i=0;i<3;i++){
                if(s1.charAt(i)==s2.charAt(i))
                    a++;
            }
            System.out.println(a);
        }
    }

    private static int binary_search(
            int arr[], int l,
            int h, int x)
    {
        while (l <= h) {
            int mid = (l + h) / 2;
            if (arr[mid] <= x)
                l = mid + 1;
            else
                h = mid - 1;
        }
        return h;
    }
    static int gcd(int a, int b)
    {
        if(b==0) {
            return a;
        }
        return gcd(b,a%b);
    }
    private static boolean isPrime(int n) {
        if (n == 2)
            return true;
        else if ((n % 2 == 0 && n > 2) || n < 2)
            return false;
        else {
            for (int i = 3; i <= (int) Math.sqrt(n); i += 2) {
                if (n % i == 0)
                    return false;
            }
            return true;
        }


    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }

}

Measured memory_bytes: 27008
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		String str = sc.next();
		
		long sum = 0;
		
		for(int i=0; i<str.length(); i++) {
			sum += (str.charAt(i) - '0');
		}
		
		if(sum % 9 == 0) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
		
		sc.close();
	}

}


Measured memory_bytes: 40076
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

#define rep(i, n) for(int i = 0; i < n; i ++)
#define ALL(T) T.begin(), T.end()
#define mp make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;

const int INF = 1 << 24;


int main(void){
    int N;
    int S[200][2];
    int h,w;
    while(cin >> N,N){
        S[0][0]=0;
        S[0][1]=0;
        rep(i,N-1){
            int n,d;
            cin >> n >> d;
            S[i+1][0]=S[n][0];
            S[i+1][1]=S[n][1];
            if(d ==0)
                S[i+1][0]=S[n][0]-1;
            else  if(d==2)
                S[i+1][0]=S[n][0]+1;
            else if (d==1)
                S[i+1][1]=S[n][1]-1;
            else if(d==3) 
               S[i+1][1]=S[n][1]+1;                
            }
        int xmin=0,xmax=0,ymin=0,ymax=0;
        rep(i,N){
            if(S[i][0]>xmax)
                xmax=S[i][0];
            else if(xmin > S[i][0])
                xmin=S[i][0];
            if(S[i][1]>ymax)
                ymax=S[i][1];
            else if( ymin > S[i][1])
                ymin=S[i][1];
        }
            h=ymax-ymin+1;
            w=xmax-xmin+1;
        cout << w << ' '<< h <<  endl; 
        }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main() {
    int a,b,d,r;
    double f;

    scanf("%d %d",&a,&b);
    d=a/b;
    r= a%b;
    f=(double)a/(double)b;
    printf("%d %d %f\n",d,r,f);
    return 0;
} 


Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long n;
    cin>>n;
    long long ans = 0;
    if(n>=500){
        ans = (n/500)*1000;
        n%=500;
        ans+=n/5 * 5;
    }
    else{
        ans = n/5 * 5;
    }
    cout<<ans<<"\n";

}

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() {
    int N,M;
    cin >> N >> M;
    int ans = N*(N-1)/2 + M*(M-1)/2;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
int n;
cin >> n;
int a[n];
int b1,b2,b3;
b1=0;
b2=0;
b3=0;
for(int i=0;i<n;i++){
cin >> a[i];
if((a[i]%2)==1){
b1++;
}
else if((a[i]%4)==0){
b3++;
}
else{
b2++;
}
}
if((b1+b2)<b3){
cout <<"Yes";
}
else if((b1-1)<b3){
cout <<"Yes";
}
else if((b1==(b3+1))&&b2==0){
cout <<"Yes";
}
else{
cout <<"No";
}
return 0;
}

Measured memory_bytes: 640
import numpy as np

H, W, N = list(map(int, input().split()))

arr = np.ones((H,W), dtype=np.bool)

for i in range(N):
    x, y, a = list(map(int, input().split()))
    if a==1:
        arr[0:x,:]=False
    elif a==2:
        arr[x:,:]=False
    elif a==3:
        arr[:,0:y]=False
    else:
        arr[:,y:]=False
        
print(np.sum(arr))

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

int main(){
  int w,h,n;
  cin>>w>>h>>n;
  vector<int>x(n),y(n),a(n);
  int under_x=0,under_y=0;
  int over_x=w,over_y=h;
  
  rep(i,n)cin>>x[i]>>y[i]>>a[i];
  
  rep(i,n){
    if(a[i]==1 and under_x<x[i])under_x=x[i];
    if(a[i]==2 and over_x>x[i])over_x=x[i];
    if(a[i]==3 and under_y<y[i])under_y=y[i];
    if(a[i]==4 and over_y>y[i])over_y=y[i];
  }
  if(over_x-under_x<=0||over_y-under_y<=0){cout<<0<<endl;return 0;}
  cout<<(over_x-under_x)*(over_y-under_y)<<endl;
  return 0;
}

Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    int n;
    cin >> n;

    int ans = 0;
    vector <int> cnt(4, 0); // なし、-A, B-, B-A
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;

        int sz = s.size();
        for (int i = 0; i < sz - 1; i++) if (s[i] == 'A' && s[i+1] == 'B') ans++;

        if (s[0] == 'B' && s[sz-1] == 'A') {
            cnt[3]++;
        } else if (s[0] == 'B') {
            cnt[2]++;
        } else if (s[sz-1] == 'A') {
            cnt[1]++;
        } else {
            cnt[0]++;
        }
    }

    ans += min(cnt[1], cnt[2]);
    ans += cnt[3];
    if (cnt[1] == 0 && cnt[2] == 0 && cnt[3] > 0) ans--;

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

Measured memory_bytes: 888
unittest
{
	assert( [ "5", "3", "2", "4", "3", "5" ].parse.expand.solve == 7 );
	assert( [ "10", "123", "123", "123", "123", "123" ].parse.expand.solve == 5 );
	assert( [ "10000000007", "2", "3", "5", "7", "11" ].parse.expand.solve == 5000000008 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto n = input.front.to!( long );
	input.popFront;
	auto ts = new long[ 5 ];
	foreach( ref t; ts )
	{
		t = input.front.to!( long );
		input.popFront;
	}
	return tuple( n, ts );
}

auto solve( long n, long[] ts )
{
	auto mt = n;
	auto md = 0L;
	foreach( t; ts )
	{
		if( t < mt )
		{
			mt = t;
			md = ( n + t - 1 ) / t - 1;
		}
	}
	return ts.length + md;
}


Measured memory_bytes: 256
// ABC123_B
#include <iostream>
#include <string>
#include <vector>
#include <iterator>  // std::prev(iter, n) n 個分デクリメントしたイテレータ
#include <tuple>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <functional>  // std::greater<T>()
#include <utility>  // std::swap()
#include <numeric>  // accumulate(ALL(vec), 0)  0 は初期値
#include <bitset>  // static_cast<std::bitset<8>>
#include <sstream>  // std::stringstream
#include <cmath>
#include <climits>  // INT_MIN
#include <cctype>  // std::isdigit()
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;

#define REP(i, n) for (ll i=0; i < n; i++)  // 0 ~ n-1
#define MIN(vec) min_element(vec.begin(), vec.end())  // イテレータのため、値を取り出すときは * を先頭につける
#define MAX(vec) max_element(vec.begin(), vec.end())
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define SUM(vec) accumulate(vec.begin(), vec.end(), 0LL)  // 0 は初期値
#define pll pair<ll, ll>
#define F first
#define S second
const ll INF = 1LL<<60;  // 10^18（const int inf   = 1<<29;）

template <typename T>
T getDigit(T num) {
    if (num == 0) return 1;
    
    ll digits = 0;
    while (num != 0) {
        digits++;
        num /= 10;
    }
    return digits;
}

int main() {
    // input(sunippets: inpv, inpn, inps)
    vector<pair<ll, ll>> vec(5);
    REP(i, 5) {
        cin >> vec[i].S;
        vec[i].F = (vec[i].S%10 ? 10 - vec[i].S%10: 0);
    }
    sort(vec.begin(), vec.end(), greater<>());  // int big -> small
    
    // calculation
    ll res = vec[0].S;
    for (ll i = 1; i < 5; ++i) {
        res += vec[i].F + vec[i].S;
    }
    cout << res << "\n";
    
    return 0;
}

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

int main(){
    int n,k,r,s,p;
    string t;
    cin>>n>>k>>r>>s>>p>>t;

    int ans=0;
    for(int i=0;i<k;i++){
        vector<char> x;
        for(int j=i;j<n;j+=k){
            x.push_back(t[j]);
        }
        vector<vector<int>> dp(x.size()+1,vector<int>(3));
        for(int j=0;j<x.size();j++){
            if(x[j]=='r'){
                dp[j+1][0]=max(dp[j][1],dp[j][2])+p;
                dp[j+1][1]=max(dp[j][0],dp[j][2]);
                dp[j+1][2]=max(dp[j][0],dp[j][1]);
            }
            if(x[j]=='p'){
                dp[j+1][0]=max(dp[j][1],dp[j][2]);
                dp[j+1][1]=max(dp[j][0],dp[j][2])+s;
                dp[j+1][2]=max(dp[j][0],dp[j][1]);
            }
            if(x[j]=='s'){
                dp[j+1][0]=max(dp[j][1],dp[j][2]);
                dp[j+1][1]=max(dp[j][0],dp[j][2]);
                dp[j+1][2]=max(dp[j][0],dp[j][1])+r;
            }
        }
        ans+=max(dp[x.size()][0],max(dp[x.size()][1],dp[x.size()][2]));
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5888
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
 //Now sorting a vector looks like sort(all(vec)) 
//instead of sort(vec.begin(), vec.end()).

typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<string> vs;

#define ios                         ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fori(n) for(int i=0; i<int(n); i++)
#define cins(s) string s; cin>>s;
#define cini(i) int i; cin>>i;
#define cind(d) double d; cin>>d;
#define cinai(a, n) vi a(n); fori(n) { cin>>a[i]; }
#define cinas(s, n) vs s(n); fori(n) { cin>>s[i]; }
#define cinad(a, n) vd a(n); fori(n) { cin>>a[i]; }
#define watch(x) cout << (#x) << " is " << (x) << endl
#define see(x) cout << (x) << " ";
#define hh cout << "\n";
typedef long long int ll;
#define vll vector < ll > 
#define fo(i, n) for(i=0; i<n; i++)
#define Fo(i, k, n) for(i=k; i<n; i++)
int32_t main(){
    ios
   int a,b,c,d,i,s=0;
   cin>>a>>b>>c>>d;
   int arr[3]={a,b,c};
  fo(i,3)
  {
      if(d<=0)
      break;
      
      if(arr[i]<d)
      {
          d=d-arr[i];
          if(i==0)
          s=s+arr[i];
          else if(i==2)
          s=s-arr[i];
      }else if(arr[i]==d)
      {
          d=d-arr[i];
          if(i==0)
          s=s+arr[i];
          else if(i==2)
          s=s-arr[i];
          
          break;
          
      }else{
          
           if(i==0)
          s=s+d;
          else if(i==2)
          s=s-d;
          d=0;
          break;
      }
  }
  
  see(s)
   
} 	

Measured memory_bytes: 3588
import java.util.Scanner;
import java.util.*;

public class Main{
	  public static void main(String[] args) {
	      int a = 0,b=0;
	      Scanner sc = new Scanner(System.in);  
          
			a = sc.nextInt(); 
		    b = sc.nextInt();  
	      
	      if( a > 8 || b >8 ) System.out.println(":(");
	      else System.out.println("Yay!");
	  }
	}



Measured memory_bytes: 23892
#include<iostream>
#include<stdlib.h>

using namespace std;

int main(){
  int n,k;
  int sum1=0 , max = 0;
  int now = 0, nextdata, next;
  int* s;
  while(1){
    sum1 = 0;
    max = 0;
    cin >>n >>k;

    if(n == 0) break;

    s = (int*)malloc(sizeof(int) * k);

    int data;
    for(int i = 0; i<k; i++){
      cin >>data;
      s[i] = data;
      sum1 += data;
    }
    max = sum1;
    now = k-1;

    for(int i = 0; i<n-k; i++){
      cin >>data;
      if(now+1 == k) {
	next = 0;
	nextdata = s[0];
      } else{
	next = now + 1;
	nextdata = s[next];
      }

      sum1 = sum1- nextdata + data;
      if( sum1 > max) max = sum1;
      now = next;
      s[now] = data;
      /*for(int j = 0; j < k; j++){
	cout << s[j]<<" ";
      }
      cout << endl;*/
    }

    cout << max << endl;
    }
  return 0;
}
    

Measured memory_bytes: 1384
#include <iostream>
#include <vector>
#include <algorithm>

int main() {
  unsigned num_of_cake;
  unsigned kind_of_cake;
  std::cin >> num_of_cake >> kind_of_cake;
  std::vector<unsigned> cakes(kind_of_cake);
  for(auto &i : cakes) {
    std::cin >> i;
  }
  std::sort(cakes.rbegin(), cakes.rend());
  if (cakes.size() == 1) {
    std::cout << num_of_cake - 1;
    return 0;
  }
  long long diff = (long long) cakes[0] - (long long) cakes[1] - 1;
  for (size_t i = 2; i < cakes.size(); ++i) {
    diff -= cakes[i];
    if (diff <= 0) {
      std::cout << 0;
      return 0;
    }
  }
  std::cout << diff;
  return 0;
}

Measured memory_bytes: 384
n=int(input())
num=[]
a=[]
b=[]
for i in range(n):
    A,B=map(int,input().split())
    a.append(A)
    b.append(B)
    num.append([A,B,A+B])
ansa=sum(a)
ansb=sum(b)
num.sort(key=lambda x: x[2],reverse=True)
for i in range(n):
    if i%2==0:
        ansb-=num[i][1]
    else:
        ansa-=num[i][0]
print(ansa-ansb)


Measured memory_bytes: 100468
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.141592653589793238462643383279502884L
#define lli long long int
#define d double
#define mod 1000000007
#define mx 100001
using namespace std;
lli dp[401][401];//dp[l][r]->min cost to mashup from range i to j....
lli sum[401][401];
lli fun(vector<int>&vec,int l,int r){
	if(l>=r) return 0;
	if(r-l==1) return vec[l]+vec[r];
	if(dp[l][r]!=-1) return dp[l][r];
	lli ans=99999999999999999;
	for(int i=l;i<r;i++){
		ans=min(ans,fun(vec,l,i)+fun(vec,i+1,r)+sum[l][r]);
	}
	return dp[l][r]=ans;
}
int main() {
	FIO;
	int n;
	cin>>n;
	vector<int> vec(n);
	for(int i=0;i<n;i++) cin>>vec[i];
	memset(sum,0,sizeof(sum));
	for(int i=0;i<n;i++){
		for(int j=i;j<n;j++){
			for(int k=i;k<=j;k++) sum[i][j]+=vec[k];
		}
	}
	memset(dp,-1,sizeof(dp));
	lli ans=fun(vec,0,n-1);
	cout<<ans<<endl;
}

Measured memory_bytes: 2816
#include<stdio.h>
int main(void){
    int IR,DR,n;
    scanf("%d %d",&n,&DR);
    if(n>=1 && n<10){
        IR=(100)*(10-n)+DR;
    }
    if(n>=10){
        IR=DR;
    }

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


return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#if 1
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define stoi stoll
#else
#define MAX INT_MAX
#define MIN INT_MIN
#endif
#define INF MAX/2
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
const int NIL = -1;
const int MOD = 1000000007;
#define REP(i,n) for (int i=0; i < (n); ++i)
#define FOR(i,a,b) for (int i=(a); i < (b); ++i)
using namespace std;

int pow(int x, int n) {int res=1; while(n){if(n&1)res*=x;x*=x;n>>=1;} return res;}
int get_gcd(int a, int b) {while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b) {return a * b / get_gcd(a, b);}
bool chmin(int &a, int b) {if(a>b){a=b; return true;} else return false;}
bool chmax(int &a, int b) {if(a<b){a=b; return true;} else return false;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//-------------------------テンプレここまで-------------------------//

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

  int N;
  cin >> N;
  static int h[100000][3];
  REP(i,N) REP(j,3) cin >> h[i][j];

  // dp[i][j] ... i日目(1-index)にjを選んだ時の最大幸福度
  static int dp[100000][3];

  // 配るdp
  REP(i,N) {
    REP(j,3) {
      REP(k,2) {
        chmax(dp[i+1][(j+1+k)%3], dp[i][j]+h[i][(j+1+k)%3]);
      }
    }
  }

  cout << max(max(dp[N][0],dp[N][1]),dp[N][2]) << endl;

  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <queue> 
using namespace std;

int a[300010];
long long ls[300010], rs[300010];
long long sum[300010];

int main() {
	int n; cin >> n;
	for (int i = 1; i <= 3*n; i ++) cin >> a[i];
	memset(ls, 0, sizeof(ls));
	
	priority_queue <int, vector<int>, greater<int> > pq_small;
	long long sum = 0;
	for (int i = 1; i <= 3*n; i ++) {
		sum += a[i];
		pq_small.push(a[i]);
		while (pq_small.size() > n) {
			sum -= pq_small.top();
			pq_small.pop();
		}
		ls[i] = sum;
	}
	
	sum = 0;
	priority_queue <int> pq_big;
	memset(rs, 0, sizeof(rs));
	for (int i = 3*n; i > 0; i --) {
		sum += a[i];
		pq_big.push(a[i]);
		while (pq_big.size() > n) {
			sum -= pq_big.top();
			pq_big.pop();
		}
		rs[i] = sum;
	}
	
	long long ans = -1e18;
	for (int i = n; i <= 2*n; i ++) 
		ans = max(ans, ls[i] - rs[i+1]);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 7672
<?php
  const DIRS = "RDLU";
  $h[] = "000000";
  $v[] = "0000000";
  for($i=0;$i<4;$i++) {
      $h[] = "0".trim(fgets(STDIN))."0";
      $v[] = "0".trim(fgets(STDIN))."0";
  }
  $h[] = "0".trim(fgets(STDIN))."0";
  $v[] = $v[0];
  $h[] = $h[0];

  $p = array(2,1,0);
  $path = array('R');
  $stepx =  array(1,0,-1,0);
  $stepy = array(0,1,0,-1);

  function check($x,$y,$j,$v,$h) {
    return ($j==0 && $v[$y-1][$x]) || ($j==1 && $h[$y][$x]) ||
      ($j==2 && $v[$y][$x]) || ($j==3 && $h[$y][$x-1]);
  }

  while(!($p[0]==1 && $p[1]==1)) {
    for($i=0;$i<4;$i++) {
      $d = ($p[2]+$i)%4;
      if(check($p[0],$p[1],$d,$v,$h)==1) {
        $p[0] += $stepx[($d+3)%4];
        $p[1] += $stepy[($d+3)%4];
        $p[2] = ($d+3)%4;
        break;
      }
    }
    $path[] = DIRS[$p[2]];
  }

  echo implode('',$path).PHP_EOL;

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

int main () {
  double a,b,x;
  cin >> a >> b >> x;
  double h = 1.0*x/(a*a);
  if (b == h*2){
    cout << 45 << endl;
    return 0;
  }
  
  double A;
  if (b > h*2){
    A = atan(a*h*2/(b*b));
  }
  else {
    A = atan(a/(b*2-h*2));
  }
  double ans = 90 - A*180/M_PI;
  printf("%.8lf\n", ans);
}

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

int main()
{

	int N;

	scanf("%d", &N);

	if (N == 1)
	{
		printf("Yes\n");
		return 0;
	}

	for (int i = 1; i < N; i++)
	{
		if ((N%i)==0 && (N / i <= 9)&&(i<=9))
		{
			printf("Yes\n");
			return 0;
		}
	}


	printf("No\n");

	return 0;
}
	

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

#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = 
#define REVERSE(x) reverse(ALL(x))
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort(ALL(x), greater<>())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define SIZE(x) ll((x).size())
#define gcd __gcd
const int INF = 1001001001;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
template <typename T = int> inline T in(){
  T x; cin >> x; return x;}
template <typename T> inline void print(const T& x){
  cout << x << "\n";}
inline int lcm(int a, int b){
  return a / gcd(a, b) * b;}
bool is_prime(int n){
  if (n < 2) return false;
  FOR(i, 2, (int)(sqrt(n) + 1)){
    if (n % i == 0) return false;
  }
  return true;
}
signed main(){
  int A = in();
  int B = in();
  print(lcm(A, B));
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 100005;

void solve(){
	string s;
	cin >> s;
	cout << ((s[0] == '7' or s[1] == '7' or s[2] == '7') ? "Yes":"No") << '\n';

}

int main(){
	fastio;
	int t = 1;
	//cin >> t;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 3620
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
int n,m,x;
int a[15][15],c[15],ans=0x3f3f3f3f;
vector<bool>v;
void dfs(int y){
	if(y>n){
		int sum[15]={0},cnt=0;
		for(int i=0;i<n;++i){
			if(v[i]){
				cnt+=c[i+1];
				for(int j=1;j<=m;++j){
					sum[j]+=a[i+1][j];
				}
			}
		}
		bool flag=true;
		for(int j=1;j<=m;++j){
			if(sum[j]<x){
				flag=false;
				break;
			}
		}
		if(flag){
			ans=min(ans,cnt);
		}
		return;
	}
	v.push_back(false);
	dfs(y+1);
	v.pop_back();
	v.push_back(true);
	dfs(y+1);
	v.pop_back();
}
int main(){
	scanf("%d%d%d",&n,&m,&x);
	for(int i=1;i<=n;++i){
		scanf("%d",c+i);
		for(int j=1;j<=m;++j){
			scanf("%d",&a[i][j]);
		}
	}
	dfs(1);
	if(ans!=0x3f3f3f3f)printf("%d\n",ans);
	else printf("%d\n",-1);
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  int x=n;
  int arr[n];
  while(x--)
    cin>>arr[n-x-1];
  // dp[n]= min(dp[n-1] + abs(arr[n]-arr[n-1]) , dp[n-2]+ abs(arr[n]-arr[n-2])
  int dp[n];
  dp[0]=0;
  dp[1]= abs(arr[0]-arr[1]);
  for(int i=2; i<n; i++){
  	int a= dp[i-1]+ abs(arr[i]-arr[i-1]);
    int b= dp[i-2]+ abs(arr[i]-arr[i-2]);
    dp[i]= min(a,b);
  }
  cout<<dp[n-1];
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

template<typename T>//文字列の置換/Boost:replace_all()
T replace_str(T str, string target, string str_to) {
    string::size_type pos = 0;
    while (pos = str.find(target, pos), pos != string::npos) {
        str.replace(pos, target.length(), str_to);
        pos += str_to.length();
    }
    return str;
}


int main(){
    int n;cin >> n;
    vi h(n);
    vi dp(n+10);
    rep(i,n){
        cin >> h[i];
    }
    dp.assign(dp.size(),MINF);
    dp[0] = 0;
    for(int i=0;i<n;i++){
        chmin(dp[i+1],dp[i]+abs(h[i]-h[i+1]));
        chmin(dp[i+2],dp[i]+abs(h[i]-h[i+2]));
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define abs(a) max((a),-(a))
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repe(i,n) rep(i,(n)+1)
#define per(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define pere(i,n) rep(i,(n)+1)
#define all(x) (x).begin(),(x).end()
#define SP <<" "<<
#define RET return 0
#define MOD 1000000007
#define INF 1000000000000000000

typedef long long LL;
typedef long double LD;

int main(){
  int n,m,x,y;
  cin >> n >> m >> x >> y;
  int mx=x,my=y;
  int xx,yy;
  for(int i=0;i<n;i++){
    cin >> xx;
    mx=max(mx,xx);
  }
  for(int i=0;i<m;i++){
    cin >> xx;
    my=min(my,xx);
  }
  if(mx<my) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}


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

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

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <strings.h>
using namespace std;

int main()
{
char A[3];
int i,j;
cin>>A;
j=0;
for(i=0;i<3;i++){
    if(A[i]=='A'){
        j=j+1;
    }
}
if(j==0 ){
    cout<<"No";
}else if(j==3){
    cout<<"No";
}
else{
    cout<<"Yes";
}
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;
vector<int> fact;
vector<int> ifact;
vector<int> inv;
vector<int> pow2;
const int MOD = (1e9 + 7);
int add(int a, int b)
{
	a+=b;
	while(a>=MOD) a-=MOD;
	return a;
}
int mult(int a, int b)
{
	return (a*1LL*b)%MOD;
}
int modpow(int a, ll b)
{
	int r=1;
	while(b)
	{
		if(b&1) r=mult(r,a);
		a=mult(a,a);
		b>>=1;
	}
	return r;
}
int choose(int a, int b)
{
	if(a<b) return 0;
	if(b==0) return 1;
	if(a==b) return 1;
	return mult(fact[a],mult(ifact[b],ifact[a-b]));
}
int inverse(int a)
{
	return modpow(a,MOD-2);
}
void init(int _n)
{
	fact.clear(); ifact.clear(); inv.clear(); pow2.clear();
	fact.resize(_n+1);
	ifact.resize(_n+1);
	inv.resize(_n+1);
	pow2.resize(_n+1);
	pow2[0]=1;
	ifact[0]=1;
	fact[0]=1;
	for(int i=1;i<=_n;i++)
	{
		pow2[i]=add(pow2[i-1],pow2[i-1]);
		fact[i]=mult(fact[i-1],i);
		//ifact[i]=mult(ifact[i-1],inv[i]);
	}
	ifact[_n] = inverse(fact[_n]);
	for(int i=_n-1;i>=1;i--)
	{
		ifact[i] = mult(ifact[i + 1], i + 1);
	}
	for(int i=1;i<=_n;i++)
	{
		inv[i] = mult(fact[i-1],ifact[i]);
	}
}
int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll h,w,t; cin>>h>>w>>t;
	ll ga = __gcd(h,t);
	ll gb = __gcd(w,t);
	h/=ga; w/=gb;
	ll g = __gcd(h,w);
	cout<<modpow(add(add(add(modpow(2,h),modpow(2,w)),MOD-1),add(modpow(2,g),MOD-2)),ga*gb)<<'\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define vi vector<int>
#define pb push_back
using namespace std;
const int N=1e5+5;
const int M=1<<16+3;
int dp[M],n;
bool good[M];int ans;
int num[N],cnt[20],mask;
void init()
{
	for(int i=1;i<(1<<16);i++)
	{
		int sum=0;
		for(int j=1;j<16;j++)
			if((i>>j)&1)
				sum^=j;
		if(sum==0)
		{
			good[i]=true;
		}
	}
	return;
}//Accepted
 
int main()
{
	cin>>n;
	for(int i=1;i<n;i++)
	{
		int a,b,c;
		cin>>a>>b>>c;
		num[a]^=c;
		num[b]^=c;
	}//Accepted
	for(int i=0;i<n;i++)
		if(num[i])
			cnt[num[i]]++;
	for(int i=1;i<20;i++)
	{
		ans+=cnt[i]/2;
		cnt[i]%=2;
		if(cnt[i])
		{
			ans++;
			mask+=(1<<i);
		}
	}
	init();//Accetped
	for(int i=0;i<=mask;i++)
	{
		for(int j=i;j;j=(j-1)&i)
		{
			if(good[j])
			{
				dp[i]=max(dp[i],dp[i^j]+1);
			}
		}
	}
	cout<<ans-dp[mask]<<endl;
	return 0;
}

Measured memory_bytes: 896
#include<iostream>
#include<map>
#include<sstream>
#include<vector>
#include<algorithm>
using namespace std;

typedef pair<int,string> P;

int main(){
  int n;
  char k;
  string s;
  map<string,int> m;
  vector<P> v;

  while(cin >> n,n){
    cin.ignore();
    m.clear();
    v.clear();
    for(int i=0;i<n;i++){
      getline(cin,s);
      stringstream ss(s);
      while(ss >> s)m[s]++;
    }
    cin >> k;

    for(map<string,int>::iterator it = m.begin();it!=m.end();it++){
      string tmp = (*it).first;
      int hoge = (*it).second;
      if(tmp[0] == k){
	v.push_back(P(-1*hoge,tmp));
	if(v.size()>5){
	  sort(v.begin(),v.end());
	  v.pop_back();
	}
      }
    }

    if(v.empty())cout << "NA\n";
    else{
      sort(v.begin(),v.end());
      for(int i=0;i<(int)v.size()-1;i++)cout << v[i].second << " ";
      cout << v[(int)v.size()-1].second << endl;
    }
  }  
}

Measured memory_bytes: 956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,a[1000],sum=0;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];

    }
    sort(a,a+n);
    for(int i=0;i<k;i++){
        sum+=a[i];
    }
    cout << sum;
}


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

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

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

    sort(a.begin(), a.end());

    string res = "YES";
    for (int i = 1; i < n; i++) {
        if (a.at(i-1) == a.at(i)) res = "NO";
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4032
//#pragma GCC optimize("Ofast")   	//Comment optimisations for interactive problems (use endl)
//#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
 
using namespace std;
 
#define  fastio         ios:: sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);
#define  randomINIT     mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define  foo(i,a,n)     for(ll i = (a); i <= n; i++)
#define  frr(i,a,n)     for(ll i = (a); i >= n; i--)
#define  fo(i,n)        for(ll i = 0; i < n; i++)
#define  all(x)         (x).begin(),(x).end()
#define  mset(x,val)    memset(x,val,sizeof(x))
#define  newl           cout<<"\n"
#define  pb             push_back

#define  dline          cout<<"///REACHED///\n";
#define  deb1(x)        cout<<#x<<" = "<<x<<'\n';
#define  deb2(x,y)      cout<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define  deb3(x,y,z)    cout<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';
 
typedef  long long             ll;
typedef  long double           ld;
typedef  pair<ll,ll>           pll;
typedef  vector<ll>            vll;
typedef  vector<pll>           vpll;
 
const ll   MOD   =  1e+9+7;
const ll   INF   =  0x7f7f7f7f7f7f7f7f;
const int  INFi  =  0x7f7f7f7f;
const ll   MAXN  =  2e+3+500;
const ll   MAXN1  =  1e+6+8;

string P[100];

 
int main()
{		
 	int a, b, c, k;
 	cin >> a >> b >> c;
 	cin >> k;
 	int count = 0;

 	while(b<=a){
 		b*=2;
 		count++;
 	}

 	while(c<=b){
 		c*=2;
 		count++;
 	}

 	if(count<=k)
 		cout << "Yes" << endl;
 	else
 		cout << "No" << endl;


}

Measured memory_bytes: 3600
#include <stdio.h>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>
#include <numeric>
#include <cctype>


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; }
//constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1000000007;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;
const long double PI = acos((long double)(-1));

using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;


int dx[] = { 1,-1,0,0,0,0 };
int dy[] = { 0,0,1,-1,0,0 };
int dz[] = { 0,0,0,0,1,-1 };
int main()
{

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

	ll a, b, c, n; cin >> a >> b >> c >> n;
	ll res = (a * b + b * c + c * a) * 2;
	vector<tuple<ll, ll, ll>> vt(n);
	for (int i = 0; i < n; i++) {
		ll x, y, z; cin >> x >> y >> z;
		vt[i] = make_tuple(x, y, z);
	}
	sort(vt.begin(), vt.end());
	for (auto p : vt) {
		ll x, y, z; tie(x, y, z) = p;
		for (int i = 0; i < 6; i++) {
			ll nx = x + dx[i];
			ll ny = y + dy[i];
			ll nz = z + dz[i];
			bool ok = true;
			if (nx < 0 or nx >= a or ny < 0 or ny >= b or nz < 0 or nz >= c) res--;
			else if (!binary_search(vt.begin(), vt.end(), make_tuple(nx, ny, nz))) res++;
			
		}
	}
	cout << res << endl;
}



Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    ll N;
    cin >> N;
    vll A(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    bool ok = true;
    rep(i, N-1) {
        if(A[i] == A[i+1]) ok = false;
    }
    if(ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 1792
import scala.io.StdIn.{readInt,readLine}

object Main {
  def toBinaryString(d:Double,cnt:Int,s:String):String = {
    if(d==0D) "0"
    else if(cnt>4) "NA"
    else {
      val d2 = d*2D
      if(d2 == 1D) s+"1"
      else if(d2>1D) toBinaryString(d2-1D,cnt+1,s+"1")
      else toBinaryString(d2,cnt+1,s+"0")
    }
  }

  def main(args:Array[String]) = {
    Iterator.continually(readLine).takeWhile(_.trim.toDouble >= 0.0 ).foreach { s =>
      val d = s.trim.toDouble
      val d1 = d.toInt.toBinaryString
      val d2 = d-d.toInt
      val d2tob = toBinaryString(d2,0,"")

      if(d2tob=="NA") println("NA")
      else if(d2tob.length>4) println("NA")
      else if(d1.length>8) {
        println("NA")
      } else {
        println(("0"*(8-d1.length))+d1+"."+d2tob+("0"*(4-d2tob.length)))
      }
    }
  }
}

Measured memory_bytes: 45436
#include<bits/stdc++.h>
using namespace std;
#define MaxN 100003

int N;
int h[MaxN], f[MaxN];

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

int main() {
	N = Rd();
	for(register int i = 1; i <= N; ++i)
		h[i] = Rd();
	f[2] = abs(h[2] - h[1]);
	for(register int i = 3; i <= N; ++i)
		f[i] = min(f[i - 1] + abs(h[i] - h[i - 1]), f[i - 2] + abs(h[i] - h[i - 2]));
	cout << f[N] << endl;
	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include<unordered_map>
#define lli long long int
#define f first
using namespace std;


int main() {

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

	string s1, s2;
	cin >> s1 >> s2;
	int counter = 0;
	for (int i = 0; i < s1.size(); ++i) {
		if (s1[i] == s2[i])counter++;
	}
	cout << counter << '\n';
	return 0;
}

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

using namespace std;

void solve(){
	string s;
	int count=0,res=0;
	cin >> s;
	for(int i=0;i<s.length();i++){
		if(s[i]=='R'){
			if(count==0 || s[i]==s[i-1]){
				count++;
				res=max(res,count);
			}
			else 
				count=0;
		}
	}
	cout<<res<<"\n";
}

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

Measured memory_bytes: 3620
//2020.1.20
//s1270188 xxxmk2
//alds1_10b

#include<stdio.h>
#include<limits.h>
#define N 100

//global
int M[N+1][N+1], p[N+1], num;

//prototype
void matrix(void);

int main(){
  int i, j;

  //input
  scanf("%d",&num);
  for(i=0;i<num;i++) scanf("%d %d",&p[i],&j);
  p[i]=j;
  
  //count
  matrix();

  //output
  printf("%d\n",M[1][num]);
  
  return 0;
}


void matrix(void){
  int i, j, k, a, l;

  //reset M
  for(i=1;i<=num;i++) M[i][i]=0;
  
  for(l=2;l<=num;l++){
    for(i=1;i<=num-l+1;i++){

      j=i+l-1;
      M[i][j]=INT_MAX;
      for(k=i;k<j;k++){
	a=M[i][k]+M[k+1][j]+p[i-1]*p[j]*p[k];
	if(a<M[i][j]) M[i][j]=a;
      }
      
    }
  }
  
}



Measured memory_bytes: 2088
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws IOException {
        //System.setIn(Main.class.getClassLoader().getResourceAsStream("input"));
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n = sc.nextInt();
        sc.nextLine();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        long res = solve(a,n);
        System.out.println(res);
    }

    private static long solve(int[] a, int n) {
        long sum = 0L;
        for (int i = 0; i < n; i++) {
            sum+=(long)a[i];
        }
        long partial = 0L;
        long half = sum/2;
        long min = Long.MAX_VALUE;
        long closest = 0L;
        for (int i = 0; i < n; i++) {
            partial += (long)a[i];
            if (Math.abs(partial - half) <= min) {
                min = Math.abs(partial - half);
                closest = partial;
            }
        }
        return Math.abs(sum - closest - closest) ;
    }
}


Measured memory_bytes: 65236
#include<stdio.h>
int main(){
  int n,x,t;
  scanf("%d %d %d\n",&n,&x,&t);
  int time;
  int a,d;
  if(n<x) time = t;
  else{
    a = n/x;
    time = a*t;
    d = n%x;
    if(d!=0) time = time + t;
  }
  printf("%d\n",time);
  return 0;
}

Measured memory_bytes: 1712
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n; cin>>n;
  vector<int> h(n);
  for(int i=0; i<n; ++i) cin>>h[i];
  int cnt=0,left=0;
  while(left<n){
    while(h[left]==0) ++left;
    for(int i=left; h[i]&&i<n; ++i) --h[i];
    ++cnt;
  }
  cout<<cnt-1<<endl;
  return 0;
}

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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
#define int long long

signed main()
{
  int n; cin >> n;
  int sum = 0;
  vi v1(3*n);
  REP(i,3*n)
    cin >> v1[i];
  
sort(ALL(v1));
  
  for(int i = n; i < 3*n; i+=2){
   sum += v1[i];
  }
  
  cout << sum;
  return 0;
}

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

int main() {
    int n;
    vector<int> d(101, 0);

    cin >> n;
    for(int i = 0; i < n; i++) {
        int buff;
        cin >> buff;
        d[buff]++;
    }

    int sameCnt = 0;
    for(int i = 1; i < 101; i++) {
        if(d[i] != 0) {
            sameCnt += d[i] - 1;
        }
    }

    cout << n - sameCnt;

    return 0;
}

Measured memory_bytes: 256
while True:
    d = input()
    if d == '0':
        break
    D = list(d)
    A_t = 0
    B_t = 0
    for i in range(1,len(D)):
        if D[i] == "A":
            A_t += 1
        elif D[i] == "B":
            B_t += 1
    if A_t > B_t:
        A_t += 1
    elif A_t < B_t:
        B_t += 1
    print(A_t, B_t)


Measured memory_bytes: 5560
input_lines = input()
int_x = int(input_lines)
input_lines2 = input()
int_a = int(input_lines2)
input_lines3 = input()
int_b = int(input_lines3)
int_x = int_x - int_a
while True:
	if int_x >= int_b:
		int_x = int_x - int_b
	else:
		break

print(int_x)


Measured memory_bytes: 2940