akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;
const ll MOD = 998244353;

template <typename T>
T pow(T a, ll n){
    T ans = 1;
    T tmp = a;
    for(int i = 0; i <= 60; i++){
        ll m = (ll)1 << i;
        if(m&n){
            ans *= tmp;
            ans %= MOD;
        }
        tmp *= tmp;
        tmp %= MOD;
    }
    return ans;
}

ll cnt[100000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int N;
    int d_max = 0;
    cin >> N;
    int A[100000];
    for(int i = 0; i < N; i++){
        cin >> A[i];
        d_max = max(d_max, A[i]);
        cnt[A[i]]++;
    }
    if(A[0] != 0){
        cout << 0 << endl;
        return 0;
    }
    if(cnt[0] >= 2){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for(int i = 1; i <= d_max; i++){
        if(cnt[i] == 0){
            cout << 0 << endl;
            return 0;
        }
        ll tmp = 1;
        ll q = pow<ll>(cnt[i-1], cnt[i]);
        //ll r = pow<ll>(2, (cnt[i]*(cnt[i]-1))/2);
        tmp = (q)%MOD;
        ans *= tmp;
        ans %= MOD;
        // cout << q << ' ' << r << endl;
        // cout << ans << endl;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <assert.h>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>

using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORIT(it, c) for (__typeof((c).begin())it = (c).begin(); it != (c).end(); it++)
#define MEMSET(v, h) memset((v), h, sizeof(v))

pair<int, int> card[10];
int calc(const int use, const int pv, const int pc, int target) {
  if (use == (1 << 9) - 1) { return 1; }
  int ret = 0;
  REP(i, 9) {
    if (use & (1 << i)) { continue; }
    int nv, nc;
    int nuse = use | (1 << i);
    if (__builtin_popcount(use) % 3 == 0) {
      nv = card[i].first;
      nc = card[i].second;
      ret |= calc(nuse, nv, nc, 0);
      ret |= calc(nuse, nv, nc, 1);
    } else if (target == 0) {
      nv = pv + 1;
      nc = pc;
      if (card[i].second != nc || card[i].first != nv) { continue; }
      ret |= calc(nuse, nv, nc, target);
    } else {
      nv = pv;
      nc = pc;
      if (card[i].second != nc || card[i].first != nv) { continue; }
      ret |= calc(nuse, nv, nc, target);
    }
    if (ret) { break; }
  }
  return ret;
}

int main() {
  int test;
  scanf("%d", &test);
  while (test--) {
    REP(i, 9) {
      scanf("%d", &card[i].first);
    }
    REP(i, 9) {
      char c;
      scanf(" %c", &c);
      card[i].second = c;
    }
    printf("%d\n", calc(0, -1, -1, -1));
  }
}

Measured memory_bytes: 0
// abc129_a
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) rep(i,v.size())cout<<" "<<v[i];cout<<endl<<endl;
#define show2d(v) rep(i,v.size()){rep(j,v[i].size())cout<<" "<<v[i][j];cout<<endl;}cout<<endl;
using namespace std;
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
  vi v(3);
  cin >> v.at(0) >> v.at(1) >> v.at(2);
  sort(v.begin(), v.end());
  cout << v.at(0) + v.at(1) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int ans = 0;

		int max = Math.max(A, C);
		int min = Math.min(B, D);

		if (B < C || D < A) {
			ans = 0;
		} else {
			ans = max - min;
		}

		System.out.println( Math.abs(ans) );
	}
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, m;
  cin >> n >> m;
  vector<long> v(m);
  rep(i, m) {
    long p, y;
    cin >> p >> y;
    v[i] = (p << 32) | y;
  }

  vector<long> sorted_v(v);
  sort(sorted_v.begin(), sorted_v.end());

  rep(i, m) {
    const long p = v[i] >> 32;
    auto it1 = lower_bound(sorted_v.begin(), sorted_v.end(), p << 32);
    auto it2 = lower_bound(sorted_v.begin(), sorted_v.end(), v[i]);
    auto d = distance(it1, it2);
    printf("%06ld%06ld\n", p, d + 1); 
  }
  return 0;
}


Measured memory_bytes: 3072
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String str = sc.next();
    if(str.charAt(3)==str.charAt(2) && str.charAt(4)==str.charAt(5)){
      System.out.println("Yes");  
    }else{
      System.out.println("No");  
    } 
    return;
  }
}

Measured memory_bytes: 21844
#[allow(unused_imports)]
use proconio::{fastout, input};

#[fastout]
fn main() {
    input!(n: usize, k: isize, q: isize, a: [usize; q]);

    let mut points = vec![0 as isize; n];
    for v in a {
        points[v - 1] += 1;
    }

    for v in points {
        if v + k - q > 0 {
            println!("{}", "Yes");
        } else {
            println!("{}", "No");
        }
    }
}


Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;

int main(){
 	int n;
 	cin >> n;
 	map<pair<string, int>, int> mp;
 	for (int i = 0; i < n; i++){
 		string s;
 		int temp;
 		cin >> s >> temp;
 		mp.insert(make_pair(make_pair(s, 100-temp), i+1));
 	}
 	for (auto x : mp){
 		cout << x.second << endl;
 	}
	return 0;
}


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

int main(){
    string s;
    cin>>s;
    int n=s.size();
    vector<int> v;
    int count = 0;
    char tmp = 'R';
    for(int i=0; i<n ; i++){
        if(tmp==s.at(i)) count++;
        else{
            tmp=s.at(i);
            v.push_back( count );
            count = 1;
        }
    }
    v.push_back( count );
    int t = 0 ;
    vector< int > ans( n + 1 );
    for(int i=0; i < v.size() ; i += 2){
        int left = v.at(i);
        int right = v.at( i + 1);
        int sum = left + right;
        t += left;
        if( (left%2)==1 ) ans.at(t)=(sum+1)/2;
        else ans.at(t)= sum/2;
        if( (right%2)==1 ) ans.at(t+1)=(sum+1)/2;
        else ans.at(t+1)= sum/2;
        t += right;
    }
    for(int i =1; i< n+1 ; i++){
        cout<<ans.at(i)<<" ";
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1528
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  std::string str;
  Solver() {
    S002 reader;
    reader >= str;
  }
  void solve() {
    for(long i = 0; i < 4; ++i) {
      putchar(str[i]);
    }
    putchar(' ');
    for(long i = 4; i < (long)str.size(); ++i) {
      putchar(str[i]);
    }
    putchar('\n');              
  }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

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

using namespace std;

int main(){
	for(int n_city,n_day,hiro_max,dup_max;scanf("%d%d%d%d",&n_city,&n_day,&hiro_max,&dup_max),n_city;){
		int profit[15][30],hiro[15][30];
		rep(i,n_city) rep(j,n_day) scanf("%d",profit[i]+j);
		rep(i,n_city) rep(j,n_day) scanf("%d",hiro[i]+j);

		int dp[31][51][16]={};
		rep(t,n_day){
			rep(i,hiro_max+1) rep(j,dup_max+1) {
				// CuðµÈ¢Æ«
				dp[t+1][i][j]=max(dp[t+1][i][j],dp[t][i][j]);

				// êÂÌ¬ÅÌÝCuð·éÆ«
				rep(p,n_city){
					if(profit[p][t]>0 && i+hiro[p][t]<=hiro_max)
						dp[t+1][i+hiro[p][t]][j]=max(dp[t+1][i+hiro[p][t]][j],dp[t][i][j]+profit[p][t]);
				}

				// ¡Ì¬ ( æÔ ) ÅCuð·éÆ«
				rep(r,n_city) rep(l,r) {
					bool ok=true;
					for(int p=l;p<=r;p++) if(profit[p][t]==0) ok=false;
					if(!ok) continue;

					int profit_sum=0,hiro_sum=0;
					for(int p=l;p<=r;p++){
						profit_sum+=profit[p][t];
						hiro_sum+=hiro[p][t];
					}

					if(i+hiro_sum<=hiro_max && j+1<=dup_max)
						dp[t+1][i+hiro_sum][j+1]=max(dp[t+1][i+hiro_sum][j+1],dp[t][i][j]+profit_sum);
				}
			}
		}

		int ans=0;
		rep(i,hiro_max+1) rep(j,dup_max+1) ans=max(ans,dp[n_day][i][j]);
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 872
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
using namespace std;

int main(){
    int a, b;
    char c;
    cin>>a>>c>>b;
    if(c=='+'){
        cout<<a+b<<endl;
    }
    else{
        cout<<a-b<<endl;
    }
    return 0;
}


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

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

killcount = 0
for i in range(N):
    if A[i] >= B[i]:
        killcount += B[i]
    else:
        killcount += A[i]
        B[i] -= A[i]
        if A[i+1] >= B[i]:
            killcount += B[i]
            A[i+1] -= B[i]
        else:
            killcount += A[i+1]
            A[i+1] = 0

print(killcount)


Measured memory_bytes: 18476
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    ll x, k, d;
    cin >> x >> k >> d;
    if (x < 0) x = -x;
    if (x / d > k) {
        cout << x - k * d << endl;
        return 0;
    }
    ll t = x % d;
    ll u = d - t;
    if (((x - t) / d) % 2 == k % 2)
        cout << t << endl;
    else
        cout << u << endl;
    return 0;
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in) ;
	public static void main(String[]args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		
		int k = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		
		if(a > k || b - a <=2) {
			System.out.println(k+1);
			return;
		}
		
		
		k = k - a + 1;
		
		
		long r = a + k %2;
		r += (long)k/2 *(long)(b-a);
		
		System.out.println(r);
		
	}
}


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

int main()
{
    int M, D;
    cin >> M >> D;
    int cnt = 0;
    for(int i = 1; i <= M; ++i) {
        for(int j = 2; j <= D/10; ++j) {
            for(int k = 2; (10*j+k) <= D && k <= 9; ++k) {
                if(j*k == i) ++cnt;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  string a,b;
  string s;
  int ss;
  cin >> a >> b;
  s = a+b;
  ss = stoi(s);
  for(int i=1;i<=316;i++){
    if(ss == i*i){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int i,j,k,n,m;
int main(){
	int x1,x2,x3;
	cin>>x1>>x2>>x3;
	if(x1+x2+x3>=22)cout<<"bust"<<endl;
	else cout<<"win"<<endl;
	return 0;
}

Measured memory_bytes: 256
# AOJ 0028 Mode Value
# Python3 2018.6.13 bal4u

import sys

cnt = [0]*101
while True:
	try:
		cnt[int(input())] += 1
	except EOFError:
		break
    	
max = max(cnt)
for i in range(101):
	if cnt[i] == max:
		print(i)


Measured memory_bytes: 5604
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    map<int, int> mp;
    int n = gi();
    int m = gi();
    int s = 0;
    mp[0] = 1;
    ll res = 0;
    for (int i = 0; i < n; i++) {
        s += gi();
        s %= m;
        res += mp[s];
        mp[s]++;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3200
#include <iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include <string>
#include <set>
#include <bitset>

using namespace std;
#define ff(i,n,m) for(int i=n;i<m;i++)
#define i64 int64_t
#define tos(x) to_string(x)

int main() {
	int n;
	cin >> n;
	int b = 0;
	int a = 0;
	int ba = 0;
	int pre = 0;
	ff(i, 0, n) {
		string s;
		cin >> s;
		if (s[0] == 'B') {
			if (s[s.size()-1] == 'A') {
				ba++;
			}
			else {
				b++;
			}
		}
		else if (s[s.size()-1] == 'A') {
			a++;
		}
		ff(j, 0, s.size()-1) {
			if (s[j] == 'A' && s[j + 1] == 'B') {
				pre++;
			}
		}
	}
  //cout<<"pre:"<<pre<<endl;
	//cout << "a:" << a << " b:" << b << " ba:" << ba << endl;
	int ans = 0;
	while (a>0&&b>0) {
		a--;
		b--;
		ans ++;
	}
	while (a > 0 && ba > 0) {
		a--;
      ba--;
		ans++;
	}
	while (ba > 0 && b > 0) {
		b--;
      ba--;
		ans++;
	}
	while (ba > 0) {
		if (ans == 0) {
			ans--;
		}
		ans += ba;
      ba = 0;
	}
	while (a > 0 && b > 0) {
		a--;
		b--;
		ans++;
	}
	ans += pre;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(20);
}

#define int ll

void solve() {
	int a, b, c, n;
	cin >> a >> b >> c >> n;
	int dx[6] = { 1,-1,0,0,0,0 };
	int dy[6] = { 0,0,1,-1,0,0 };
	int dz[6] = { 0,0,0,0,1,-1 };
	vector<tuple<int,int, int>> neko;
	set<tuple<int,int, int>> next;
	REP(i, n) {
		int a, b, c;
		cin >> a >> b >> c;
		neko.push_back(make_tuple(a, b, c));
	}
	int ans = a * b + b*c + a * c;
	ans *= 2LL;
	REP(i, n) {
		next.insert(neko[i]);
		int cnt = 0;
		REP(q, 6) {
					int x = dx[q] + get<0>(neko[i]);
					int y = dy[q] + get<1>(neko[i]);
					int z = dz[q] + get<2>(neko[i]);
					if (x >= 0 && x < a && y >= 0 && y < b && z >= 0 && z < c) {
						cnt += next.count(make_tuple(x, y, z));
					}
					else {
						cnt++;
					}
		}
		ans += 6 - 2 * cnt;
	}
	cout << ans << endl;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3312
import java.util.*;

class Main{
	private static final Scanner scan = new Scanner(System.in);

    public static void main(String args[]){

        while(scan.hasNext()){
            String line = scan.nextLine();
            for(int i = 0; i < 26; i++){
                String now="";
				StringBuffer sb = new StringBuffer();
                for(int j = 0; j < line.length(); j++){
					char cz = line.charAt(j);
					if(cz >= 'a' && cz <= 'z'){
                        sb.append((char)('a' + (cz - 'a' + i) % 26));
                    } else{
						sb.append(cz);
					}
                }
				now = sb.toString();
				boolean flag = false;
                for(int j = 0; j < now.length() - 2; j++){
					char cs = now.charAt(j);
					char cs1 = now.charAt(j + 1);
					char cs2 = now.charAt(j + 2);
                    if(cs == 't' && cs1 == 'h' && cs2 == 'e'){
						flag = true;
						break;
					}
                }
                for(int j = 0; j < now.length() - 3; j++){
					char cs = now.charAt(j);
					char cs1 = now.charAt(j + 1);
					char cs2 = now.charAt(j + 2);
					char cs3 = now.charAt(j + 3);
                    if(cs == 't' && cs1 == 'h'){
                        if(cs2 == 'i' && cs3 == 's'){
							flag = true;
							break;
						}
                        if(cs2 == 'a' && cs3 == 't'){
							flag = true;
							break;
						}
                    }
                }
                if(flag){
                    System.out.printf("%s\n", now);
                    break;
                }
            }
        }
    }
}

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

n,k = map(int,sys.stdin.readline().split())
dp = [0]*(k+1)
s = 0
#print("nk:",n,k)
l = 0
for x in range(1,k+1)[::-1]:
    dp[x] = pow(k//x,n,1000000007)
    j = 2
    #print(2*x,k+1,x)
    for j in range(2*x,k+1,x):
        #print("j",x,j,k,n)
        dp[x] -= dp[j]
    s = (s + (dp[x]*x))%1000000007
#return reduce(math.gcd, numbers)
#sum += gcd(a,b,c)
#print(sum(dp[n-1][j] for j in range(k)))
#print(dp)
print(s)

Measured memory_bytes: 69472
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <cstdio>
#define INF 100000000

using namespace std;
int dp[205][205] = { 0 }, t[205], a[205], b[205], c[205];
int main(){
	int d, n;
	cin >> d >> n;
	for (int i = 1; i <= d; i++) {
		cin >> t[i];
	}
	for (int j = 1; j <= n; j++) {
		cin >> a[j] >> b[j] >> c[j];
	}
	for (int i = 0; i < 201; i++) {
		for (int j = 0; j < 201; j++) {
			dp[i][j] = -1;
		}
	}
	for (int i = 1; i <= n; i++) {
		if (a[i] <= t[1] && t[1] <= b[i]) dp[1][i] = 0;
	}
	for (int i = 2; i <= d; i++) {
		for (int k = 1; k <= n; k++) {
			for (int j = 1; j <= n; j++) {
				if (a[j] <= t[i] && t[i] <= b[j]&&a[k]<=t[i-1]&&t[i-1]<=b[k]) {
					dp[i][j] = max(dp[i][j], dp[i - 1][k] + abs(c[k] - c[j]));
				}
			}
		}
	}
	int ans = -1;
	for (int i = 1; i <= n; i++) {
		if (ans < dp[d][i]) ans = dp[d][i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3264
#include <bits/stdc++.h>
  using namespace std;
  string reverseStr(string);

  int main() {
    string S, Sconcat, Scomp;
    int N;
    cin >> S;
    N = S.size();
    bool isKaibun = true;
    string answer;

/// 1. S は回文である。
/// 2. N を S の長さとするとき、S の 1 文字目から (N−1)/2 文字目まで(両端含む)からなる文字列は回文である。
/// 3. S の (N+3)/2 文字目から N 文字目まで(両端含む)からなる文字列は回文である。

    /// 条件1
    Scomp = S;
    reverse(Scomp.begin(), Scomp.end());
    if(Scomp != S){
      isKaibun = false;
    }

    /// 条件2
    Sconcat = S.substr(0, (N-1)/2);
    Scomp = Sconcat;
    reverse(Sconcat.begin(), Sconcat.end());
    if(Scomp != Sconcat){
      isKaibun = false;
    }

    /// 条件3
    Sconcat = S.substr((N+3)/2-1, N-(N+3)/2+1);
    Scomp = Sconcat;
    reverse(Sconcat.begin(), Sconcat.end());
    if(Scomp != Sconcat){
      isKaibun = false;
    }

    if(isKaibun){
      answer = "Yes";
    } else {
      answer = "No";
    }

    cout << answer << endl;
  }


Measured memory_bytes: 256
def I(): return int(input())
def S(): return input()
N = I()
S = S()
ans = 0
for i in range(1000):
    z = str(i).zfill(3)
    if S.find(z[0])==-1:
        continue
    S1 = S[S.find(z[0])+1:]
    if S1.find(z[1])==-1:
        continue
    S2 = S1[S1.find(z[1])+1:]
    if S2.find(z[2])==-1:
        continue
    ans += 1
print(ans)

Measured memory_bytes: 3188
def gcd(x, y):
    x = x % y
    if x == 0:
        return y
    return gcd(y, x)

def lcm(x, y):
    return x // gcd(x, y) * y
n = int(input())
a = list(map(int, input().split(' ')))
l = 1
for ai in a:
    l = lcm(l, ai)
mod = 1000000007
ans = 0
for ai in a:
    ans += l // ai
ans %= mod
print(ans)


Measured memory_bytes: 4084
#include<bits/stdc++.h>
#define ll long long

using namespace std;

int main(){
    string st;
    cin>>st;
    ll n,s,w,e;
    n=s=e=w=0;
    for(ll i=0;i<st.size();i++){
        if(st[i]=='N') n++;
        if(st[i]=='S') s++;
        if(st[i]=='E') e++;
        if(st[i]=='W') w++;
        
    }
    if(n>0 && s==0) cout<<"No\n";
    else if(s>0 && n==0) cout<<"No\n";
    else if(e>0 && w==0) cout<<"No\n";
    else if(w>0 && e==0) cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, begin, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int main()
{
    int N;
    cin >> N;
    vector<tuple<string, int, int>> t(N);
    rep(i, 0, N)
    {
        string s;
        int a;
        cin >> s >> a;
        t.at(i) = make_tuple(s, -a, i);
    }
    sort(all(t));
    rep(i, 0, N)
    {
        cout << get<2>(t.at(i)) + 1 << endl;
    }
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; ++i) {
    cin >> a[i];
  }

  int ans = 0;
  for (int i = 0; i < N; ++i) {
    while (a[i] % 2 == 0) {
      a[i] = a[i] / 2;
      ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
S = input()
ans = 0
for i in range(2**(len(S)-1)):
    s = S
    for j in range(len(S)-1):
        if (i>>j) & 1:
            s = s[:j-len(S)+1]+"+"+s[j-len(S)+1:]
    ans += sum(list(map(int, s.split("+"))))
print(ans)

Measured memory_bytes: 3064
from collections import deque
import sys
input = sys.stdin.readline

n, m = map(int, input().split())
roots = [[] for _ in range(n)]
signs = [-1 for _ in range(n)]

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

queue = deque([0])
signs[0] = 0

while queue:
    room = queue.popleft()
    for root in roots[room]:
        if signs[root] == -1:
            signs[root] = room
            queue.append(root)

print('Yes')
for i in signs[1:]:
    print(i + 1)


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

int main() {
int a,b;
cin>>a>>b;
int snow=0,bhigh=0;
for (int i = 1; i <= b-a; i++)
{
  bhigh+=i;
}

cout<<bhigh-b<<endl;


}


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

int main(){
  int MAX = 0, count = 0;
  string S;
  cin >> S;
  for(int i = 0; i < S.length(); i++){
  	for(int j = i; j < S.length(); j++){
      if(S[j] == 'A' || S[j] == 'C' || S[j] == 'G' || S[j] == 'T'){
        count++;
      }else {
      	break;
      }
    }
    MAX = max(MAX, count);
    count = 0;
  }
  cout << MAX << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String moji = sc.nextLine();
        boolean flag = false;

        String[] mojiretu = new String[moji.length()];

        for(int i = 0; i<moji.length();i++){
            String moji2 = String.valueOf(moji.charAt(i));
            mojiretu[i] = moji2;
        }

        if(mojiretu[2].equals(mojiretu[3]) && mojiretu[4].equals(mojiretu[5])){
            flag = true;
        }

        if(flag == true){
        System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
import java.util.*;
import java.math.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();

    long count = (b / x) - (a / x);

    if (a % x == 0) {
      System.out.println(count+1);
    } else {
      System.out.println(count);
    }

  }

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ld;
const lli INF = 1e9 + 100;
const lli INF64 = (1LL << 61) + 100;
const lli MOD = 1e9 + 7;
const lli MH1 = 1599614977, MH2 = 2034417103, MH3 = 1090250123, MH4 = 2024491871; 
lli bpow(lli baseee, lli exponenttt) {
	if(exponenttt < 0) return 0;
	lli res = 1;
	baseee %= MOD;
	while (exponenttt > 0) {
		if ((exponenttt & 1) == 1) res = (res*baseee) % MOD;
		baseee = (baseee*baseee) % MOD;
		exponenttt >>= 1;
	}
	return res;
}
lli multInverse(lli a) {//if_mod_is_prime
	return bpow(a, MOD - 2);
}
lli divm(lli a, lli b) {//if_mod_is_prime
	return (a * multInverse(b)) % MOD;
}
lli multm(lli a, lli b) {
	return (a * b) % MOD;
}
lli subm(lli a, lli b) {
	a += MOD;
	lli r = a - b;
	if(r >= MOD) return r - MOD;
	return r;
}
lli addm(lli a, lli b) {
	lli r = a + b;
	if(r >= MOD) return r - MOD;
	return r;
}
signed main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	int x, y;
	cin >> x >> y;
	if(y % 2 != 0) {
		cout << "No\n";
		return 0;
	}
	if(x * 4 < y) {
		cout << "No\n";
		return 0;
	}
	if(x * 2 > y) {
		cout << "No\n";
		return 0;
	}
	cout << "Yes\n";
	
	return 0;
}

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

int n, S[10010], q, key, cnt=0;

int search(){
  int i = 0, j = 0;
  S[n] = key;
  while(key != S[j]){
    j++;
    if(j == n) return 0;
  }
  return 1;
}

int main(){
  cin>>n;
  for(int i=0;i<n;i++) cin>>S[i];
  cin>>q;
  for(int i=0;i<q;i++){
    cin>>key;
    cnt += search();
  }
  cout<<cnt<<endl;
  return 0;
}



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

using namespace std;

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

    long int ans = 0;
    int a,b = 0;

    for(int i = 0; i < n; ++i){
        cin >> a;
        ans += (a - b >= 0 ? 0 : b - a);
        b = (b < a ? a : b);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
const ll MOD=1e9+7;

struct Val {
  LL num;
  LL dp;
};

int N;
int K;
Val vs[114][21414];
const int MM = 10014;

int main() {
  scanf("%d%d", &N, &K);
  
  vs[N+1][0].num = 1;
  vs[N+1][0].dp = 0;
  rreps(i, 1, N+1) {
    rep(j, MM+1) {
      rep(k, K+1) {
        auto &v = vs[i+1][j];
        if (k <= i && k+j >= i) {
          int t = (k+j)/i;
          if (j+t > MM) continue;
          auto &nv = vs[i][j+t];
          //printf("dp[%d][%d] <- dp[%d][%d]\n", i, j+t, i+1, j);
          //printf("dp : %lld += %lld\n", nv.dp, LL((k+j) % i) * v.num);
          //printf("num: %lld += %lld\n", nv.num, v.num);
          (nv.dp += v.dp) %= MOD;
          (nv.dp += LL((k+j) % i) * v.num) %= MOD;
          (nv.num += v.num) %= MOD;
        } else {
          auto &nv = vs[i][j];
          //printf("dp[%d][%d] <- dp[%d][%d]\n", i, j, i+1, j);
          //printf("dp : %lld += %lld\n", nv.dp, LL((k+j)) * v.num);
          //printf("num: %lld += %lld\n", nv.num, v.num);
          (nv.dp += v.dp) %= MOD;
          (nv.dp += LL(k+j) * v.num) %= MOD;
          (nv.num += v.num) %= MOD;
        }
      }
    }
  }

  /*rreps(i, 1, N+1) {
    printf("dp[%d]:", i);
    rep(j, N*2+1) {
      printf(" (%lld, %lld)", vs[i][j].num, vs[i][j].dp);
    }
    puts("");
  }*/

  LL ans = 0;
  rep(i, MM+1) {
    ans += vs[1][i].dp;
    ans %= MOD;
  }
  
  printf("%lld\n", ans);
}


Measured memory_bytes: 33920
#include <stdio.h>
#include <stdlib.h>
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
char field[8][9];

void printField() {
	int i;
	for (i = 0; i < 8; i++) {
		puts(field[i]);
	}
}

void bomb(int x, int y) {
	int i, j, nextX, nextY;
	field[y][x] = '0';
	for (i = 0; i < 4; i++) {
		for (j = 1; j <= 3; j++) {
			nextX = x + dx[i] * j;
			nextY = y + dy[i] * j;
			if (0 <= nextX && nextX < 8 && 0 <= nextY && nextY < 8 && field[nextY][nextX] == '1') {
				bomb(nextX, nextY);
			}
		}
	}
}

int main () {
	int n, x, y, i, j;
	scanf("%d", &n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < 8; j++) {
			scanf(" %s", (char*) &field[j]);
		}
		scanf("%d %d", &x, &y);
		bomb(x - 1, y - 1);
		printf("Data %d:\n", i + 1);
		printField();
	}
	return 0;
}

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

int N, M;
vector<int> visited;
vector<vector<int>> G;
int numVisited = 0;
int res = 0;

void dfs(int nowNode) {
    visited[nowNode] = 1;
    ++numVisited;
    if (numVisited == N)
        ++res;

    int next;
    rep (i, G[nowNode].size()) {
        next = G[nowNode][i];
        if (!visited[next])
            dfs(next);
    }

    visited[nowNode] = 0;
    --numVisited;
}

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

    cin >> N >> M;
    
    G = vector<vector<int>>(N);
    visited = vector<int>(N, 0);
    
    rep (i, M) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dfs(0);
    cout << res << "\n";
}

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

if n == 0:
    print(x)
    exit()
P = list(map(int, input().split()))

for s in range(-101, 110):
    if s not in P:
        ans = s
        break

for s in range(-101, 110):
    if s not in P:
        if abs(ans-x) > abs(s-x):
            ans = s
        elif abs(ans-x) == abs(s-x):
            ans = min(ans, s)

print(ans)


Measured memory_bytes: 9200
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <iostream>
using namespace std;
char s[10];
int main(){
	cin>>s+1;
	int a,b,c,d;
	a = s[1] - '0';
	b = s[2] - '0';
	c = s[3] - '0';
	d = s[4] - '0';
	if(a+b+c+d == 7)
		printf("%d+%d+%d+%d=7",a,b,c,d);
	else if(a+b+c-d == 7)
		printf("%d+%d+%d-%d=7",a,b,c,d);
	else if(a+b-c+d == 7)
		printf("%d+%d-%d+%d=7",a,b,c,d);
	else if(a-b+c+d == 7)
		printf("%d-%d+%d+%d=7",a,b,c,d);
	else if(a+b-c-d == 7) 
		printf("%d+%d-%d-%d=7",a,b,c,d);
	else if(a-b+c-d == 7)
		printf("%d-%d+%d-%d=7",a,b,c,d);
	else if(a-b-c+d == 7)
		printf("%d-%d-%d+%d=7",a,b,c,d);
	else if(a-b-c-d == 7) 
		printf("%d-%d-%d-%d=7",a,b,c,d);
	return 0;
}

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

using namespace std;
typedef long long ll;
#define int ll

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; }

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
const int MAX_N = 100010;

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

    double R;
    cin >> R;
    cout << R * 2.0 * 3.1415926535 << endl;

    return 0;
}


Measured memory_bytes: 3768
//                   ********** YATIN KWATRA **********

// AC BAKSHI RABBA

#include <bits/stdc++.h>
#define ll                      long long 
#define ld                      long double
#define ull                     unsigned long long 
#define FIO                     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl                    "\n"
#define fo(i,a,b)               for(int i = a; i<=b ; i++)
#define rfo(i,a,b)              for(int i = a; i>=b ; i--)
#define vii                     vector<int>
#define vll                     vector<ll>
#define pq                      priority_queue
#define uom                     unordered_map                
#define all(v)                  v.begin(),v.end()
#define mp                      make_pair
#define pb                      push_back
#define pob                     pop_back
#define ff                      first
#define ss                      second
#define pii                     pair<int,int> 
#define pll                     pair<long,long>
#define mll                     map<ll,ll>
#define mii                     map<int,int>
#define vvii                    vector<vii>
#define vvll                    vector<vll>
#define mod                     1000000007
#define pi                      3.1415926535897932384626433832795

using namespace std;

void INPUT() 
{  
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}

/*
    
   -> Check For Overflows
   -> Out of Bounds
   -> Initialisations of global arrays and variables
   -> Its not Always Complex, Try to simplify
   -> write it down and try to solve
   -> Have Faith in urself and in ur approach
   -> If it seems totally out of reach, switch to next :)
   -> And Come Back later, if possible 
*/





void solve()
{ 
        int n;
        cin >> n;
        
        string a = "AC";
        string b = "WA";
        string c = "TLE";
        string d = "RE";

        int c1,c2,c3,c4;
        c1 = c2 = c3  = c4 = 0;

        string s;

        while(n--)
        {
          cin >> s;

          if(s == a) c1++;
          else if(s == b) c2++;
          else if(s == c) c3++;
          else if(s == d) c4++;
        }

        cout << a << " x " << c1 << endl;
        cout << b << " x " << c2 << endl;
        cout << c << " x " << c3 << endl;
        cout << d << " x " << c4 << endl;

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


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
bool prime[10000001];
int main() {
    for(int i=3;i<3162;i+=2)if(!prime[i])for(int j=i*2;j<10000001;j+=i)prime[j]=1;
    int n;
    while(cin>>n,n){
        if(!(n%2))n--;
        while(prime[n]||prime[n-2]||prime[n-6]||prime[n-8])n-=2;
        cout<<n<<endl;
    }
}

Measured memory_bytes: 10928
#include <cstdio>

typedef long long ll;

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

inline bool solve(ll k, ll x, ll m, ll n) {
    if (x < k || k > n)
        return false;
    if (m >= k)
        return true;
    ll a = m - k, b = gcd(n, k), c = x % b;
    ll d = (a / b - 1) * b + c;
    while (d < a) d += b;
    return d >= 0;
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        ll a, b, c, d;
        scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
        puts(solve(b, a, c + 1, d) ? "Yes" : "No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REPZ(i, z, n) for(decltype(n) i = (z); i < (n); i++)
#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(all(v)))
#define MIN(v) (*min_element(all(v)))
#define INF 1000000000000 //1E+12
#define MOD 1000000007    //合同式の法

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<

typedef long long ll;
typedef unsigned long long ul;
// 1s間で可能なループ回数2E+8回
// intの最大値2147483647~2E+9
// long longの最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<> push_back
// 連想配列map<key,value> insert,
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 setprecision()
// to_string<->stoi
// stoll(longlong)
// stod(double)
// 大文字65-90(-32)
// 小文字97-122(+32)
using namespace std;
int main(){
  // faster
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n,m; cin >> n >> m;
  // 右から数字が何か入れる
  int d[]={-1,-1,-1};
  REP(i,m){
    int digit, value; cin >> digit >> value; 
    if((d[n-digit]!=-1 and d[n-digit]!=value) or (n!=1 and digit==1 and value==0)){
      cout << -1 << endl;
      return 0;
    }
    d[n-digit]=value;
  }
  if(n!=1 and d[n-1]==-1) d[n-1]=1;
  int res=0;
  int temp=1;
  REP(i,n){
    if(d[i]!=-1)res+=d[i]*temp;
    temp*=10;
  }
  cout << res << endl;
  return 0;
}


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

typedef long long ll;
const ll InF = 1e15;

int main() {
  ll N,K;
  cin>>N>>K;
  ll ans;
  if (K % 2 == 0) {
    ll ret1 = 0;
    ll ret2 = 0;
    for (ll i = 1; i <= N; i++) {
      if (i % K == 0) ret1++;
      if (i % K == K / 2) ret2++;
      ans = ret1 * ret1 * ret1 + ret2 * ret2 * ret2;
    }
  } else {
    ll ret = 0;
    for (ll i = 1; i <= N; i++) if (i % K == 0) ret++;
    ans = ret * ret * ret;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
       PROGRAM-ID. ABC044-A.
       DATA DIVISION.
       FILE SECTION.
       WORKING-STORAGE SECTION.
       77 N PIC 9(5).
       77 K PIC 9(5).
       77 X PIC 9(5).
       77 Y PIC 9(5).
       77 ANS PIC 9(9).
       77 ANSS PIC Z(9).

       PROCEDURE DIVISION.
       MAIN-PROCEDURE.
               ACCEPT N FROM SYSIN.
               ACCEPT K FROM SYSIN.
               ACCEPT X FROM SYSIN.
               ACCEPT Y FROM SYSIN.
               IF K < N THEN
                   COMPUTE ANS = K * X + (N - K) * Y
               ELSE
                   COMPUTE ANS = N * X
               END-IF.
               MOVE ANS TO ANSS.
               DISPLAY ANSS.
               STOP RUN.
       END PROGRAM ABC044-A.


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

int main() {
  long long n;
  cin >> n;
  vector<long long> t(n), a(n);
  for(int i = 0; i < n; i++) cin >> t.at(i) >> a.at(i);
  
  long long ta = 1;
  long long ao = 1;
  for(int i = 0; i < n; i++){
    long long k = max((t.at(i) - 1 + ta) / t.at(i), (a.at(i) - 1 + ao) / a.at(i));
    ta = t.at(i) * k;
    ao = a.at(i) * k;
  }
  
  cout << ta + ao << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
	long long a[200000],b[200000],temp;
int main()
{
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	if(n%2==0)
		{
			for(i=0,j=n/2;i<n;i+=2,j++)
			{
				b[j]=a[i];
			}
			for(i=n-1,j=0;i>0;i-=2,j++)
			{
				b[j]=a[i];
			}
			for(i=0;i<n;i++)
				printf("%lld ",b[i]);
		}
	else
	{
		for(i=0,j=(n-1)/2;i<n-1;i+=2,j++)
			{
				b[j]=a[i];
			}
		for(i=n-2,j=0;i>0;i-=2,j++)
			{
				b[j]=a[i];
			}
		b[n-1]=a[n-1];
		for(i=n-1;i>=0;i--)
		printf("%lld ",b[i]);
	}
	return 0;
}


Measured memory_bytes: 5248
h,*s=open(0)
h,w,k,*m=map(int,h.split())
b=w
while b:
 b-=1;r=0;t=j=w;d=[0]*h
 while j:
  i=c=0;j-=1
  while h-i:
   d[c]+=s[i][j]>'0';c+=b>>i&1;i+=1
   if max(d)>k:d=[0]*h;r+=1;t,j=j,j+(t>j);i=h
 m+=r+c,
print(min(m))

Measured memory_bytes: 44288
import numpy as np

s = input().split()

H = int(s[0])
W = int(s[1])
K = int(s[2])

m = np.zeros((H, W))

def make_list(n):
  r = []
  b = bin(n)[2:]
  for i in range(len(b)):
    if b[i] == "1":
      r.append(len(b) - i - 1)
  return r
    
for i in range(H):
  s = input()
  for j in range(W):
    if s[j] == "#":
      m[i, j] = 1

result = 0
for i in range(2**H):
  h = make_list(i)
  for j in range(2**W):
    w = make_list(j)
    M = np.delete(m, h, 0)
    M = np.delete(M, w, 1)
    if np.sum(M) == K:
      result += 1
      #print(h, w)
      
print(result)

Measured memory_bytes: 27152
import sys
s = input()
st=0
e=0
max=0
f=False
for i in range(len(s)):
    if s[i] == "A":
        st = i
        break

for i in reversed(range(len(s))):
    if s[i] == "Z":
        e = i
        break

print(e-st+1)

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

using namespace std;

typedef long long ll;

#define newline cout<<"\n"
#define deb(x) cout<<#x<<" "<<x<<endl;

template<typename... T>
void read(T&... args){
    ((cin>>args), ...);
}

template<typename... T>
void write(T... args){
    ((cout<<args<<" "), ...);
}

void printarr(vector<int> &v){
    for(int x: v){
        cout<<x<<" ";
    }
    newline;
}

const int MOD = 1e9+7;
const int nax = 1e7+7;

string n;

int ans = 0;

void dfs(string s, int flag){
    // cout<<s<<endl;
    if((s<=n && s.length()<=n.length()) || (s.length() < n.length())){
        if(flag==0){
            int a=0,b=0,c=0;
            for(char x: s){
                if(x=='3'){
                    a++;
                }
                if(x=='5'){
                    b++;
                }
                if(x=='7'){
                    c++;
                }
            }
            if(min({a,b,c})>0){
                flag = 1;
            }
        }
        if(flag==1) {
            ans++;
            // cout<<s<<endl;
        }
        dfs(s+"3", flag);
        dfs(s+"5", flag);
        dfs(s+"7", flag);
    }
}

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

    dfs("", 0);

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

Measured memory_bytes: 3620
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# AGC028：A - Two Abbreviations
# import numpy as np
import fractions
def lcm(a,b): return abs(a * b) / fractions.gcd(a,b) if a and b else 0

def main():
    n, m = [int(i) for i in raw_input().strip().split(' ')]
    s = raw_input().strip()
    t = raw_input().strip()
    # l = np.lcm(n, m) # 45
    l = lcm(n, m) # 45
    n1 = l/n # 45/15 = 3
    m1 = l/m # 45/9 = 5
    # l1 = np.lcm(n1, m1) # lcm(3, 5) = 15
    l1 = lcm(n1, m1) # lcm(3, 5) = 15

    # d  n  s  u  s  r  a  y  u  k  u  a  i  i  a  
    # d    u    j    r    u    n    u    m    a    
    for i in range(l/l1):
        if s[i*m1] != t[i*n1]:
            print '-1'
            return
    print str(l)


if __name__ == '__main__':
    main()


Measured memory_bytes: 4776
#include <bits/stdc++.h>
using namespace std;
//Author: Ezio Sam
/* Shorthands */
#define ll long long
#define pb push_back 
#define mp make_pair
#define sp ": "
#define cs "Case "
#define fi first
#define sn second 
#define po(x) x*x
/* STL */
#define vi vector<int>v
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mem(a,n) memset(a, n, sizeof(a));
#define all(x) x.begin(),x.end()
#define sz(x)  (int)x.size()
#define mx(v)  *max_element(v.begin(),v.end())
#define mxa(a) *max_element(a, a.size())
#define r(a) reverse(a.begin(),a.end())
/* loops */
#define fr(i,n)   for(__typeof(n) i=0;i<(n);i++)
#define fn(i,n)   for(__typeof(n)i=1;i<=(n);i++)
#define fa(i,a,n) for(__typeof(a)i=(a);i<=(b);i++)
/*Special*/
#define Ezio ios::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
#define db(something)   cerr<<#something<<" - "<<something<<"\n";         
int main()
{
  
   Ezio
   /*Variables*/
   /*Code*/
   string s;
   cin>>s;
   cout<<((s=="ABC")?"ARC":"ABC")<<endl;
   return 0;
}
    

Measured memory_bytes: 3520
#include <stdio.h>          // printf(), getc()
#include <stdbool.h>

const char NUL = '\0';

bool
ope_line()
{
	char oline[101];
	char letter[6][5] = {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! "};

	int c = getchar();
	if (c == EOF)
		return false;

	if (c == '\n')
		return true;

	bool b_na = false;
	int ix = 0;
	while (c != '\n' && c != EOF)
	{
		int s = c - '1';

		c = getchar();
		if (c == '\n' || c == EOF)
		{
			b_na = true;
			break;
		}

		int t = c - '1';
		if (0 <= s && s <= 5 && 0 <= t && t <= 4)
			oline[ix++] = letter[s][t];
		else
			b_na = true;

		c = getchar();
	}

	if (b_na)
		printf("NA\n");
	else
	{
		oline[ix] = NUL;
		printf("%s\n", oline);
	}

	if (c == EOF)
		return false;

	return true;
}

int
main(int argc, char **argv)
{
	while (true)
	{
		if (!ope_line())
			break;
	}

	return 0;
}

Measured memory_bytes: 1664
def toll(n, x, tolls):
	rcount = 0
	lcount = 0
	for i in range(x, n):
		if i in tolls:
			rcount += 1
	for i in range(1, x):
		if i in tolls:
			lcount += 1
	return min(rcount, lcount)
n, m, x = map(int, input().split())
tolls = list(map(int, input().split()))
print(toll(n, x, tolls))

Measured memory_bytes: 9196
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <algorithm>
#include <map>
#include <numeric>
#include <cmath>
using namespace std;

int counter = 0;

bool sitigosanHantei(string num, long long int n) {

    if (stoll(num) > n) {
        return false;
    }

    bool seven = false;
    bool five = false;
    bool three = false;
    for (int i = 0; i < num.length(); i++) {
        if (num[i] == '7') {
            seven = true;
        } else if (num[i] == '5') {
            five = true;
        } else if (num[i] == '3') {
            three = true;
        }
    }
    if (seven && five && three) {
        return true;
    }
    return false;
}


void sitigosan(string num, long long int n) {

    if (num !=  "" && stoll(num) > n) {
        return ;
    }

    if (sitigosanHantei(num + "3", n)) {
        counter++;
    }
    if (sitigosanHantei(num + "5", n)) {
        counter++;
    }
    if (sitigosanHantei(num + "7", n)) {
        counter++;
    }
    sitigosan(num + "7", n);
    sitigosan(num + "5", n);
    sitigosan(num + "3", n);
    return;
}

int main()
{
    long long int n;
    cin >> n;
    sitigosan("", n);
    cout << counter << endl;
}


Measured memory_bytes: 256
n,y = map(int,input().split())
detect = False
# 0 ~ n までの繰り返し
for i in range(n+1):
    for j in range(n+1-i):
        k = n - i - j
        if 10000 * i + 5000 * j + 1000 * k == y and i + j + k == n:
            detect = True
            print(i,j,k)
            break
    if detect:
        break            
if not detect:
    print(-1,-1,-1)

Measured memory_bytes: 3060