akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
//#include <iomanip>
using namespace std;

int main(){

	int H, W;

	while(1){
		cin >> H >> W;
		if(H == 0 && W == 0){
			break;
		}
		for(int i = 0; i < H; i++){
			if(i == 0 || i == H - 1){
				for(int j = 0; j < W; j++){
					cout << "#";
				}
			}else{
				cout << "#";
				for(int j = 1; j < W - 1; j++){
					cout << ".";
				}
				cout << "#";
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
<?php
$w = trim(fgets(STDIN));
$w = strtolower($w);
$count = 0;
while (true) {
    $t = trim(fgets(STDIN));
    if ($t == 'END_OF_TEXT') {
        break;
     }
    $t = strtolower($t);
    foreach (explode(' ', $t) as $word) {
        if ($word == $w) {
            ++$count;
        }
    }
}
echo $count. PHP_EOL;


Measured memory_bytes: 9244
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	int a, b, c, d = 0, t = 0, e;
	cin >> a;
	for (int h = 1; h <= a; h++) {
		cin >> b >> c;
		d = c - b + 1;
		t = d + t;
	}
	cout << t << "\n";
	cin >> e;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include<bits/stdc++.h>
#define ll long long
#define read freopen("input/test (4).txt","r",stdin)
#define write freopen("output/test (4).txt","w",stdout)
#define fr first
#define sc second
#include <sstream>
#define FIO std::ios_base::sync_with_stdio(false);
#define ii pair < int , int >
#define mp make_pair
using namespace std;

int main()
{
 string s;
 cin>>s;
 char a , b;
 a = s[0];
 int len = s.length();
 b = s[len-1];
 if(a == b)
 {
     int sum = len - 3;
     if(sum%2==1)
     {
         cout<<"First";
     }
     else
     {
         cout<<"Second";
     }
 }
 else
 {
     int sum = len - 2;
     if(sum%2==1)
     {
         cout<<"First";
     }
     else
     {
         cout<<"Second";
     }
 }
}
/// abacabc


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

int combi(int num) {
    if (num <= 1)
        return 0;
    return (num * (num - 1)) / 2;
}

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

    int n, m;
    cin >> n >> m;

    cout << combi(n) + combi(m) << endl;
    return 0;
}


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

int main() {
  string n;
  cin >> n;
  int ans = 0;
  int moveUp = 0;
  for(int i = n.length()-1; i >= 0; i--){
    int num = (int)n.at(i) -'0' + moveUp;
    if(num < 5){
      ans += num;
      moveUp = 0;
    }else if(num == 5){
      ans += num;
      int buf = (int)n[i-1] - '0';
      if(buf > 4){
        moveUp = 1;
      }else{
        moveUp = 0;
      }
    }else{
      ans += 10 - num;
      moveUp = 1;
    }
  }
  cout << ans + moveUp << endl;
}


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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int N, C, s, t, c; cin >> N >> C;
	vector <vector <pair<int,int>>> v(C);
	for (int i = 0; i < N; ++i){
		cin >> s >> t >> c;
		s *= 2; t *= 2; --c;
		v[c].emplace_back(s,t);
	}
	vector <int> ava(2e5 + 2), ava2(2e5+2);
	for (int i = 0; i < C; ++i){
		if (!v[i].empty()){
		sort(v[i].begin(),v[i].end());
		++ava[v[i][0].first-1];
		for (int j = 1; j < v[i].size(); ++j){
			if (v[i][j-1].second != v[i][j].first){
				--ava[v[i][j-1].second];
				++ava[v[i][j].first-1];
			}
		}
		--ava[v[i][v[i].size()-1].second];			
		}
	}
	for (int i = 1; i < ava.size(); ++i) ava[i] += ava[i-1];
	cout << *max_element(ava.begin(),ava.end()) << "\n";
	/*
	vector <pair<int,int>> sor;
	for (int i = 0; i < C; ++i){
		sort(v[i].begin(),v[i].end());
		vector <pair<int,int>> tmp;
		if (!v[i].empty()){
//			pair<int,int> p;
			int x = v[i][0].first;
			for (int j = 1; j < v[i].size(); ++j){
				if (v[i][j-1].second != v[i][j].first){
					tmp.emplace_back(x, v[i][j-1].second);
					x = v[i][j].first;
				}
			}
			tmp.emplace_back(x, v[i][v[i].size()-1].second);	
		}
//		cout << "Test " << i  << " " << tmp.size()<< "\n";
		for (auto i : tmp){
			sor.push_back(i);
		}	
	}
	sort(sor.begin(),sor.end());
//	for (auto i : sor){
//		cout << i.first <<  " " << i.second << "\n";
//	}
	int req = 1;
	multiset <int> free;
	for (int i = 0; i < sor.size(); ++i){
		if (free.empty()){
			free.insert(sor[i].second);
		}else{
			if (*free.begin() < sor[i].first){
				free.erase(free.begin());
				free.insert(sor[i].second);
			}else{
				++req;
				free.insert(sor[i].second);
			}
		}
	}
	cout << req << "\n";
*/	
	return 0;
}


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

int n;
int dfs(int th,int fi,int se,int now){
    if(now>n){return 0;}
    int ret = (th&&fi&&se);
    ret+=dfs(th+1,fi,se,now*10+3)+dfs(th,fi+1,se,now*10+5)+dfs(th,fi,se+1,now*10+7);
    return ret;
}

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin>>n;
    cout<<dfs(0,0,0,0)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    double  N;
    double  sum=0;
    cin>>N;
    for(int i=1;i<=N;i++)
{
    if(i%2==1) sum++;
}
cout  <<  fixed <<  setprecision(6) <<  sum/N  <<  endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define rep(i,j,k) for(i = j;i <= k;i++)

int main(){
  int a[4],b[4],hit,blow;

  while(scanf("%d%d%d%d",&a[0],&a[1],&a[2],&a[3]) != EOF){
    int i,j;
    hit = 0;
    blow = 0;
    scanf("%d%d%d%d",&b[0],&b[1],&b[2],&b[3]);

    rep(i,0,3){
      if(a[i] == b[i]) hit++;
    }

    rep(i,0,3){
      rep(j,0,3){
        if(a[i] == b[j]) blow++;
        }
    }
    blow = blow - hit;
    printf("%d %d\n",hit,blow);
  }
  return 0;
}

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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define out(S) cout<<(S)<<endl;
#define ShowAll(collection) for(auto i:collection){out(i);}
#define beginend(v) v.begin(),v.end()

using pii=pair<int,int>;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
template<typename T> void removeAt(vector<T>& v, int index) { v.erase(v.begin() + index); }

void solve(int n){
  bool box[n][31]{{false}};
  rep(i,n) {
    int f;
    cin >> f;
    rep(k,f) {
      int x;
      cin >> x;
      box[i][x]=true;
    }
  }
  ull dp[n];
  rep(i,n) dp[i] = 1ULL << i;

  for(int i=1;i<=30;++i){
    vector<bool> get(n,false);
    ull sub = 0ULL;
    rep(k,n){
      for(int m=k+1;m<n;++m) if(box[k][i]&&box[m][i]){
        get[k]=get[m]=true;
        sub|=dp[k]|dp[m];
      }
    }
    if(sub==(1ULL<<n)-1){
      cout << i<< endl;
      return;
    }
    rep(i,n) if(get[i]) dp[i]=sub;
  }
  cout << -1 << endl;
}

int main()
{
  int n;
  while(cin>>n,n){
    solve(n);
  }
  return 0;
}



Measured memory_bytes: 3068
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define RREP(i,a,b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  string s;
  cin >> s;
  int n = s.size();
  rep(i,n)cout << 'x';
  cout << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
}

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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  int ans = 0;
  rep(i,n){
    x -= a[i];
    if(x<0) break;
    ans++;
  }
  if(x>0) ans--;
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>	
#include<string>
#include<math.h>
#include  <vector>
using namespace std;
int main() {
	char S[20];
	int N = 0;
	int a[200000] = { 0 };
	int p = 0;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= N; i++) {
		if (a[i-1]==i) {
		}
		else {
			p++;
		}
	}
	if (p > 2) {
		cout << "NO";
	}
	else {
		cout << "YES";
	}
}


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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	llong N;
	vector<llong> l;

	cin >> N;
	l.resize(2*N);
	for(int i = 0; i < 2*N; i++)
		cin >> l[i];
	sort(BE(l));

	llong ans = 0;
	for(int i = 0; i < 2*N; i += 2)
		ans += l[i];

	cout << ans << endl;

	return 0;
}

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

int main(){
    int a,b;
    cin>>a>>b;
    cout<<(a*b)<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int cmbmod2(int n, int r){
    return n == (r | (n - r));
}

int calc(VI a){
    int n = a.size(), ret = 0;
    REP(i,n){
        if (cmbmod2(n - 1, i)) ret ^= a[i];
    }
    return ret;
}

int main(void){
    int n;
    string s;
    cin >> n >> s;
    VI a(n), cnt(3);
    REP(i,n){
        a[i] = (s[i] - '1');
        cnt[a[i]]++;
    }
    int ans = -1;
    if (cnt[1] == 0){
        REP(i,n) a[i] /= 2;
        ans = calc(a) * 2;
    }else{
        REP(i,n) a[i] %= 2;
        ans = calc(a);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9220
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
template<class T>bool chmax(T &a, const T &b) {
	if (a < b) { a = b; return 1; }
	return 0;
}
template<class T>bool chmin(T &a, const T &b) {
	if (a > b) { a = b; return 1; }
	return 0;
}

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

	int n;
	cin >> n;
	vi a = vi(n);
	int x = 0;
	REP(i, n) {
		cin >> a[i];
		x ^= a[i];
	}

	REP(i, n) {
		int ans = x^a[i];
		printf("%d%c", ans, i == n - 1 ? '\n' : ' ');
	}
}

Measured memory_bytes: 3984
n = int(input())


for i in range(1,7):
    if (n < 10**i):
        keta = i
        break

#print(keta)

rtn = 0

if (keta == 1):
    rtn += n
elif (keta > 1):
    rtn += 9

if (keta == 3):
    rtn += n - 99
elif (keta > 3):
    rtn += 900

if (keta == 5):
    rtn += n - 9999
if (keta > 5):
    rtn += 90000

print(rtn)

Measured memory_bytes: 3064
h,w = map(int,input().split())
a = w//2 + w%2
a2 = (w-1)//2 + (w-1)%2
if h == 1:
    res = 1
elif w == 1:
    res = 1
else:
    if h%2 == 0:
        res = a*(h//2) + a2*(h//2)
    else:
        res = a*((h//2)+1) + a2*(h//2)
print(res)

Measured memory_bytes: 38256
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int gu = scan.nextInt();
		int[] kati = new int[gu];

		for(int i=0;i<gu;i++) {
			kati[i] = scan.nextInt();
		}

		Arrays.sort(kati);
		double max = kati[0];
		for(int i=1;i<gu;i++) {
			max = (max+kati[i])/2;

		}
		System.out.println(max);

		scan.close();
	}

}


Measured memory_bytes: 27064
#include<stdio.h>
int main(void) {
	int a[1000], b[1000],l,d;
	int i = 0;
	char c[1000];
	while (1) {
		scanf("%d %c %d", &a[i], &c[i], &b[i]);
		if (c[i] == '?') {
			break;
		}
		i++;
	}
	for (l = 0; l < i; l++) {
		switch (c[l]) {
		case '+':
			d = a[l]+b[l];
			printf("%d\n", d);
			break;
		case '-':
			d = a[l] - b[l];
			printf("%d\n", d);
			break;
		case '*':
			d = a[l] * b[l];
			printf("%d\n", d);
			break;
		default:
			d = a[l] / b[l];
			printf("%d\n", d);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 2044
n = int(input())

if n % 7 == 0 or n % 4 == 0:
    print("Yes")
elif n >= 4 and n % 7 == 4:
    print("Yes")
elif n >= 8 and n % 7 == 1:
    print("Yes")
elif n >= 12 and n % 7 == 5:
    print("Yes")
elif n >= 16 and n % 7 == 2:
    print("Yes")
elif n >= 20 and n % 7 == 6:
    print("Yes")
elif n >= 24 and n % 7 == 3:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <limits>
#include <list>
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
#define pNO cout << "NO" << endl
#define pYES cout << "YES" << endl
#define endl "\n"
#define pi 3.14159265358979
using namespace std;
using ll = long long;

bool bysecond(const vi & lhs, const vi & rhs) {
    if (lhs[1] != rhs[1]) {
        return lhs[1] < rhs[1];
    }
    else {
    }
}
int main() {
    int N; cin >> N;
    vvi vec(N, vi(3));
    for (int i = 0; i < N; i++) {
        int x; cin >> x;
        x;
        vec[i] = { x,i,-1 };
    }
    sort(ALL(vec)); // sort by values x
    for (int i = 0; i < N; i++) {
        vec[i][2] = i;
    }
    int first_half = vec[N / 2 - 1][0];
    int second_half = vec[N / 2][0];
    sort(ALL(vec), bysecond);
    for (int i = 0; i < N; i++) {
        if (vec[i][2] < N / 2) {
            cout << second_half << endl;
        }
        else {
            cout << first_half << endl;
        }
    }
}

Measured memory_bytes: 14096
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{   
        int n;
        cin>>n;
        vector<int> losses(n);
        vector<int> cost(n);
        for(int i = 0 ; i < n ; i++)
        {
            cin>>losses[i];
        }
        cost[0] = 0;
        cost[1] = abs(losses[1] - losses[0]);
        for(int i = 2 ; i < n ; i++)
        {
            cost[i] =  min((cost[i-1] + abs(losses[i]-losses[i-1]) ) , (cost[i-2] + abs(losses[i]-losses[i-2]) ));
        }
        cout<<cost[n-1]<<endl;
        
}

Measured memory_bytes: 1024
from sys import stdin
N,M = [int(x) for x in stdin.readline().rstrip().split()]
data = []
for _ in range(M):
    data.append([int(x) for x in stdin.readline().rstrip().split()])
shima = set()

flag = False
for i in sorted(data):
    if i[0] == 1:
        shima.add(i[1])
    if (i[1] == N) and (i[0] in shima):
        flag = True
        break

if flag:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 44492
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define sz(x) (int)(x).size()

const int N = 100010;
ii b[N];
int n, m;

int main() {
  scanf("%d%d", &n, &m);
  int u, v;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &u, &v);
    b[i] = ii(u, v);
  }
  sort(b, b + m, [&](ii a, ii b) {
    return ii(a.second, a.first) < ii(b.second, b.first);
  });

  int last = b[0].second - 1, ans = 1;
  for (int i = 1; i < m; i++) {
    if (b[i].first <= last) continue;
    else { last = b[i].second - 1; ans++; }
  }
  printf("%d\n", ans);
}



Measured memory_bytes: 1024
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long [] a = new long[n+1];
		a[0] = 2;
		a[1] = 1;
		for(int i = 2; i <=n; i++) {
			a[i] = a[i-1] + a[i-2];
		}
		System.out.println(a[n]);
	}
}

Measured memory_bytes: 24020
a = gets.chomp.to_s
q = gets.to_i
queries = q.times.map { gets.chomp.split(" ").map(&:to_s) }
ans = [a]
# ans = a
rev = false
queries.each do |query|
  if query[0] == "1"
    rev = !rev
  else
    (query[1] == "1") ^ rev ? ans.unshift(query[2]) : ans << query[2]
    # (query[1] == "1") ^ rev ? ans = query[2] + ans : ans += query[2]
  end
end
puts rev ? ans.join.reverse : ans.join
# puts rev ? ans.reverse : ans

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

// int main()
// {
//   int64_t n, ans = 0, i = 357, ma = 999999999;
//   string s;
//   cin >> n;
//   ma = min(n, ma);
//   map<char, int> sft;

//   while (i <= ma)
//   {
//     map<char, int> sft;
//     s = to_string(i);

//     bool flag = 1;
//     int cnt = (int)s.size();

//     for (char c : s)
//     {
//       if (c != '7' and c != '5' and c != '3')
//       {
//         flag = 0;
//         i += (pow(10, cnt - 1));

//         break;
//       }
//       else
//       {
//         ++sft[c];
//       }
//       --cnt;
//     }
//     if (flag)
//     {
//       if (sft.count('7') and sft.count('5') and sft.count('3'))
//       {
//         ++ans;
//       }
//       ++i;
//     }
//   }

//   cout << ans << "\n";
// }

int64_t n;

void stf(int64_t cur, int use, int64_t &counter)
{
  if (cur > n)
    return;
  if (use == 0b111)
    ++counter;

  stf(cur * 10 + 7, use | 0b001, counter);
  stf(cur * 10 + 5, use | 0b010, counter);
  stf(cur * 10 + 3, use | 0b100, counter);
}

int main()
{
  int64_t ans = 0;
  cin >> n;
  stf(0, 0, ans);
  cout << ans << "\n";
}

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

a = []
b = []

c = []
d = []

for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)

for i in range(m):
    c_, d_ = map(int, input().split())
    c.append(c_)
    d.append(d_)



for i in range(n):
    buf = 1000000000
    ans = 0
    for j in range(m):
        cal = abs(a[i] - c[j]) + abs(b[i] - d[j])
        if cal < buf:
            buf = cal
            ans = j

        elif cal == buf:
            buf = cal
            ans = min(ans, j)

    print(ans + 1)
            


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

int main()
{
	string s;
	cin >> s;
	sort(s.begin(), s.end());

	if (s == "abc") {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}






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

int main(){
    int N;
    std::cin >> N;
    std::vector< int > A(N);
    std::vector< int > cnt(100001, 0);
    long long total = 0;
    for(int i=0; i<N; i++){
        std::cin >> A[i];
        cnt[A[i]]++;
        total += A[i];
    }
    int Q;
    std::cin >> Q;
    std::vector< int > B(Q);
    std::vector< int > C(Q);
    for(int i=0; i<Q; i++){
        std::cin >> B[i] >> C[i];
    }
    
    for(int i=0; i<Q; i++){
        int cnt_tmp = cnt[B[i]];
        long long chg = (C[i] - B[i]) * cnt_tmp;
        total += chg;
        cnt[B[i]] = 0;
        cnt[C[i]] += cnt_tmp;
        std::cout << total << std::endl;
    }
    
    return 0;
}



Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pii pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pi(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL)

int main() {
   ll r,d,x;
   cin>>r>>d>>x;
   for(int i=0;i<10;i++)
   {
   	cout<<r*x-d<<"\n";
   	x=r*x-d;
   }
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
    int h1,h2,m1,m2,k,study;
    scanf("%d %d %d %d %d",&h1,&m1,&h2,&m2,&k);
    study = (h2 * 60 + m2) - (h1 * 60 + m1) - k;
    printf("%d",study);
    return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
#define rep(i,a) for(int i=0;i<(int)(a);i++)
#define pb push_back
#define sz size()
using namespace std;
typedef vector<int> vi;

const int INF = 1e9;

struct edge{
  int from,to,cost,cap,rev;
  edge(int a,int b,int c,int d,int e)
    :from(a),to(b),cost(c),cap(d),rev(e){}
};

struct dinic{
  int n;
  vector< vector<edge> > graph;
  vi level,iter;

  dinic(int a=0):n(a){graph.resize(a);}

  void AddEdge(int s,int g,int c,int p){
    graph[s].pb( edge(s,g,c,p,graph[g].sz) );
    graph[g].pb( edge(g,s,-c,0,graph[s].sz-1) );
  }

  void DeleteEdge(int s, int g){
    int id = -1, rev = -1;
    rep(e,graph[s].sz){
      if(graph[s][e].to == g){
	id = e; rev = graph[s][e].rev;
      }
    }
    if(id<0)return;

    swap(graph[s][id],graph[s].back());
    swap(graph[g][rev],graph[g].back());
    graph[s][id].rev = rev;
    graph[g][rev].rev = id;
    graph[s].pop_back(); graph[g].pop_back();
  }

  void bfs(int s){
    level = vi(n,-1);
    level[s] = 0;
    queue<int> q; q.push(s);
    while(q.sz){
      int v = q.front(); q.pop();
      for(edge e: graph[v]){
	if(e.cap > 0 && level[e.to] < 0){
	  level[e.to] = level[v] + 1;
	  q.push(e.to);
	}
      }
    }
  }
  
  int dfs(int v, int t, int f){
    if(v==t)return f;
    for(int &i = iter[v];i<(int)graph[v].sz;i++){
      edge &e = graph[v][i];
      if(e.cap > 0 && level[v] < level[e.to]){
	int d = dfs(e.to,t,min(f,e.cap));
	if(d > 0){
	  e.cap -= d;
	  graph[e.to][e.rev].cap += d;
	  return d;
	}
      }
    }
    return 0;
  }
  
  int max_flow(int s, int t){
    int res = 0;
    for(;;){
      bfs(s);
      if(level[t]<0)return res;
      iter = vi(n,0);
      int f;
      while((f=dfs(s,t,INF))>0)res += f;
    }
  }
};

inline int min_path_cover(const vector<int> &a){
  int n = a.size();
  dinic d(2*n+2);

  rep(i,n)rep(j,n){
    if(i!=j && a[j] % a[i] == 0)d.AddEdge(i+1,n+j+1,1,1);
  }
  rep(i,n){
    d.AddEdge(0,i+1,1,1);
    d.AddEdge(n+i+1,2*n+1,1,1);
  }
  return n-d.max_flow(0,2*n+1);
}

int main(){
  int n;
  cin >> n;
  vi a(n);
  rep(i,n)cin >> a[i];

  //calc optimal
  int opt = min_path_cover(a);

  vi res, use(n,0);
  //calc lex_min
  rep(i,n){
    if(use[i])continue;
    vi tmp;
    for(int j=i+1;j<n;j++){
      if(!use[j] && a[j]%a[i] && a[i]%a[j])tmp.push_back(a[j]);
    }
    if(min_path_cover(tmp) == opt-1-(int)res.size()){
      res.push_back(i);
      for(int j=i+1;j<n;j++){
	if(a[j]%a[i]==0 || a[i]%a[j]==0)use[j] = 1;
      }
    }
  }
  
  rep(i,res.size()){
    cout << res[i]+1 << (i+1==(int)res.size()?"\n":" ");
  }
}

Measured memory_bytes: 1304
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main() {
	string S;
	cin >> S;

	string ans;
	if (S[S.size()-1] == 's') {
		ans = S + "es";
	} else {
		ans = S + "s";
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import math


N_MAX = 10**5

## fact[i] := iが素数なら1,でなければ0
fact = [1] * (N_MAX+1)
for i in range(2,N_MAX+1):
  if fact[i] == 0:
    continue
  
  for j in range(i*2, N_MAX+1, i):
    fact[j] = 0

## csum[i] := 3からiまでの素数の総数
## fact[i] と fact[(i+1)//2] の両方が素数なら1足す
csum = [0] * (N_MAX+1)
for i in range(3, N_MAX+1):
  if i%2 == 0:
    csum[i] = csum[i-1]
  else:
    csum[i] = csum[i-1] + (fact[i] & fact[(i+1)//2])

q = int(input())
ans = [0] * q
for i in range(q):
  l,r = map(int, input().split())
  ans[i] = csum[r] - csum[l-1]

for a in ans:
  print(a)

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

using namespace std;

typedef pair<int, int> P;

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

  int cnt = (n - 1) * (n - 2) / 2 - k;
  if (cnt < 0) {
    cout << -1 << endl;
    return 0;
  }

  vector<P> ans;
  for (int i = 0; i + 1 < n; i++) {
    ans.emplace_back(1, i + 2);
  }

  for (int i = 2; i + 1 <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (cnt == 0) continue;
      cnt--;
      ans.emplace_back(i, j);
    }
  }

  cout << ans.size() << endl;
  for (auto x : ans) {
    cout << x.first << " " << x.second << endl;
  }

  return 0;
}

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

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

    int n;
    cin >> n;

    vector<int> s(n);
    int min_num = 10000000;
    int sum = 0;
    rep(i,n) {
        cin >> s[i];
        if(s[i] % 10 != 0) min_num = min(min_num, s[i]);

        sum += s[i];
    }
    if(sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }
    if(min_num == 10000000) {
        cout << 0 << endl;
        return 0;
    }
    else {
        sum -= min_num;
        cout << sum << endl;
        return 0;
    }
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (ll i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
const long long MOD = 1e9 + 7;
const int MAX = 1000001;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(ll n, ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    ll N, K;
    cin >> N >> K;

    COMinit();
    ll ans = COM(N + N - 1, N - 1);

    repd(i, K + 1, N) {
        ans -= (COM(N - 1, i) * COM(N, i)) % MOD;
        if (ans < 0) ans += MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 23680
# ABC131D - Megalomania
import sys
input = sys.stdin.readline

from itertools import accumulate
from operator import itemgetter as get


def main():
    N = int(input())
    A = sorted([tuple(map(int, input().split())) for _ in range(N)], key=get(1))
    T, D = zip(*A)  # tasks, deadlines
    T = list(accumulate(T))
    flg = all(t <= d for t, d in zip(T, D))  # all tasks finish within each deadline?
    print("Yes" if flg else "No")


if __name__ == "__main__":
    main()

Measured memory_bytes: 46000
n =int(input())
vw = [(0,0)]  
for _ in range(n):
    vw.append(list(map(int,input().split())))

A  =10
N = min(1<<A,n+1)
memo = [None for _ in range(N)]
L = 10**5+1
memo[0] = [0]*L

for i in range(1,N):
    m = memo[i>>1][:]
    v,w = vw[i]    
    for j in range(L-1,w-1,-1):
        if m[j] < m[j-w]+v:
            m[j] = m[j-w]+v
    memo[i] = m

q = int(input())
ans_ = [0]*q
for _ in range(q):
    u,l = map(int,input().split())
 
    m = u.bit_length() - A
    if m<0: m=0
    dv = [0]*(1<<m)
    dw = [0]*(1<<m)
    for i in range(m):
        v,w = vw[u]
        for j in range(1<<i):
            dv[j+(1<<i)] = dv[j]+v
            dw[j+(1<<i)] = dw[j]+w
        u >>= 1
    
    ans = 0
    for v,w in zip(dv,dw):
        if w <= l:
            val = memo[u][l-w] + v
            if val > ans: ans = val
    ans_[_] = ans
print(*ans_,sep="\n")

Measured memory_bytes: 911052
#!/usr/bin/python

import sys

def main(argv):
    tokens = sys.stdin.readline().rstrip("\n").split(" ")

    while len(tokens) == 2:
        h, w = map(lambda x: int(x), tokens)

        c = []
        for i in xrange(0, h):
            c.append(sys.stdin.readline().rstrip("\n"))

        for i in xrange(1, 2 * h + 1):
            image = []
            for j in xrange(1, w + 1):
                image.append(c[(i + 1) / 2 - 1][j - 1])
            print "".join(image)

        tokens = sys.stdin.readline().rstrip("\n").split(" ")

if __name__ == "__main__":
    main(sys.argv)

Measured memory_bytes: 2692
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

//어떤 구간 a에서 x가 median이 될라면,
//자기를 기준으로 left에서 (작은거 큰거 비율)p개, right에서 q개일때
//p의 개수 * (-p)인 right에서의 q 개수
//https://www.acmicpc.net/problem/3013

//구간 a에서 x보다 같거나 큰 수를 1, 작은 수를 -1 해서 psum을 구해준다.
//자기보다 크거나 같은 수가 median이 되는 구간들을 구해야한다.
//psum[r] - psum[l] >= 0이 되게 해야한다. (0개가 남으면 딱 1 : 1 이라는 것이고 그럴 경우 m/2 +1 번째가 median이므로)
//psum[r] 은 1 ~ r 구간에서 x보다 같거나 큰 수의 남는 개수 (음수면 모자라는 개수)
//psum[r] - psum[l] 은 (l, r] 구간에서 x보다 크거나 같은 수의 남는 개수
//그렇게 한개씩 psum을 구하면서 자기보다 작거나 같은 psum의 개수를 누적해서 더해준다 (내가 매칭될 수 있는 l이므로)
const ll base = 100000;
ll N, arr[100001];
ll BIT[base * 2+2];
vector<ll> nums;

ll sum(int idx) {
	ll ret = 0;
	while (idx > 0) {
		ret += BIT[idx];
		idx -= (idx & -idx);
	}
	return ret;
}

void update(ll idx, ll val) {
	while (idx <= base * 2 + 1) {
		BIT[idx] += val;
		idx += (idx & -idx);
	}
}

ll solve(int x) {
	ll ret = 0, psum = 0;
	memset(BIT, 0, sizeof(BIT));

	update(base, 1);
	for (int i = 1; i <= N; ++i) {
		if (arr[i] >= x) psum++;
		else psum--;
		ret += sum(psum + base);
		update(psum + base,  1);
	}

	return ret;
}

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

	cin >> N;
	for (int i = 1; i <= N; ++i) {
		cin >> arr[i];
		nums.push_back(arr[i]);
	}

	sort(nums.begin(), nums.end());
	nums.resize(unique(nums.begin(), nums.end()) - nums.begin());

	for (int i = 1; i <= N; ++i) {
		arr[i] = lower_bound(nums.begin(), nums.end(), arr[i]) - nums.begin();
	}

	ll n = N*(N + 1) / 2;

	ll x = 0, y = nums.size() - 1, mid, res = -1;
	while (x <= y) {
		mid = (x + y) >> 1;

		if (solve(mid)*2 >= n) {
			//자기보다 크거나 같은 애들이 median이 되는 횟수가
			//median이 될 수 있는 수보다 크다면 mid를 키워야함
			x = mid + 1;
			res = nums[mid];
		}
		else {
			y = mid - 1;
		}
	}

	cout << res << '\n';
	return 0;
}

Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
    int data[100], n;
    
    scanf("%d", &n);
    for (int i = 0; i < n; i++) { 
        static int j = 0;
        scanf("%d", &data[j]);
        j++;
    }
    for (int k = n - 1; k >= 0; k--) {
        printf("%d", data[k]);
        if (k != 0) printf(" ");
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 1028
// <head>
    #include <bits/stdc++.h>
    #define rep(i,n) for(int i=0;i<(int)(n);i++)
    using namespace std;
    using ll = long long;
    const int INF = 1002003004;
    const ll LINF = 1002003004005006007ll;
    struct preprocess{preprocess()
    {cin.tie(nullptr);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}}____;
// </head>

// <library>
    
// </library>

bool match(char &c1, char &c2){
    return (c1==c2 || c1=='?' || c2 == '?');
}

int main(){
    string a,b,c; cin >> a >> b >> c;
    const int MX = 4005;
    const int bias = 30000;
    vector<bool> ab(MX+bias,true);
    vector<bool> bc(MX+bias,true);
    vector<bool> ac(MX+bias,true);
    int la = a.size(), lb = b.size(), lc = c.size();
    rep(i,la) rep(j,lb) if(!match(a[i],b[j])) ab[i-j+bias] = false;
    rep(i,la) rep(j,lc) if(!match(a[i],c[j])) ac[i-j+bias] = false;
    rep(i,lb) rep(j,lc) if(!match(b[i],c[j])) bc[i-j+bias] = false;
    int ans = INF;
    for (int i = -MX; i < MX; i++){
        for (int j = -MX; j < MX; j++){
            if(ab[i+bias]&&ac[j+bias]&&bc[j-i+bias]){
                int l = min(i,min(j,0));
                int r = max(i+lb,max(j+lc,la));
                ans = min(ans, r-l);
                
            }
            
        }
        
    }
    cout << ans << '\n';
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v)) os<<*i<<(i==end(v)-1?"":"\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
    is>>p.first>>p.second; return is; }
template <class T> bool chmax(T &a,const T &b) {if(a<b) {a=b;return 1;} return 0;}
template <class T> bool chmin(T &a,const T &b) {if(b<a) {a=b;return 1;} return 0;}
template <class T> using heap = priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int n,m;
    cin>>n>>m;
    int s=m*1900+(n-m)*100;
    int p=1;
    REP(i,m) p<<=1;
    cout<<s*p<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cstdlib>
#include <cmath>
typedef long long ll;

using namespace std;

int main(){
    int a, b,c,d;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }
        a -= d;
        if(a <= 0){
            cout << "No" << endl;
            return 0;
        }

    }
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int a[10020],b,c;
int main()
{
  scanf("%d %d",&b,&c);
  for(int i=1;i<=c;i++)
    scanf("%d",&a[i]);
  for(int i=1;i<=c;i++)
    b-=a[i];
  if(b<0)printf("-1");
  else if(b>=0)printf("%d",b);
  return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, n) for (int i = (a); i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define FOR(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

bool check(ll x, ll y) {
  ll sumx = 0, sumy = 0;
  ll xx = x, yy = y;
  while (xx > 0) {
    sumx += xx % 10;
    xx /= 10;
  }
  while (yy > 0) {
    sumy += yy % 10;
    yy /= 10;
  }

  return y * sumx - x * sumy >= 0;
}

ll f(ll x) {
  ll y = x + 1;
  vector<int> v;
  while (y > 0) {
    v.push_back(y % 10);
    y /= 10;
  }
  reverse(ALLOF(v));

  map<ll, bool> cand;
  for (int i = v.size(); i > 0; i--) {
    ll a = 0, b = 1, c;
    rep(j, i - 1) {
      a *= 10;
      a += v[j];
    }
    REP(j, i - 1, v.size()) {
      a *= 10;
      b *= 10;
    }
    b /= 10;
    c = b - 1;
    // cout << a << " " << b << " " << c << endl;
    REP(j, v[i - 1], 10) { cand[a + j * b + c] = 1; }
  }

  vector<ll> w;
  FOR(it, cand) w.push_back(it->first);

  rep(i, w.size()) {
    bool flg = true;
    REP(j, i + 1, w.size()) {
      if (!check(w[i], w[j])) flg = false;
    }
    if (flg) return w[i];
  }
  return -1;
}

int main() {
  //
  int K;
  cin >> K;

  ll x = 0;
  while (K > 0) {
    x = f(x);
    cout << x << endl;
    K--;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <deque>
#include <cstdio>
#include <set>
#include <map>
#include <bitset>
#include <stack>
#include <cctype>
using namespace std;
long long sum[200020];
long long a[200020];
int main() {
	int n;
	cin >> n;
	sum[0] = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		sum[i + 1] += a[i];
		sum[i + 1] += sum[i];
	}
	long long co = 0;
	long long ans = 1000000000007;
	for (int j = 0; j <= n; j++) {
		long long m = abs(sum[n] - sum[j] - co);
		if (ans > m) {
			ans = m;
		}
		co += a[j];
	}
	cout << ans << endl;
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <iostream>
#include <string>
#include <cstdlib>

using namespace std;

int largest(int x, int y, int z){
	if(x > y){
		if(x > z){
			return x;
		}
		else{
			return z;
		}
	}
	else{
		if(y > z){
			return y;
		}
		else{
			return z;
		}
	}
}

int main(){
	int A, B;
	cin >> A >> B;
	cout << largest(2*A-1, A+B, 2*B-1) << "\n";
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

/**
 * ワーシャルフロイド法
 * 隣接行列で受け取り、全頂点間最短経路を算出
 */
void warshall_floyd(Graph &graph) {
    int V = graph.size();
    for (int k = 0; k < V; ++k) {
        for (int i = 0; i < V; ++i) {
            for (int j = 0; j < V; ++j) {
                graph[i][j] = min(graph[i][j], graph[i][k] + graph[k][j]);
            }
        }
    }
}

void Main() {
    int N, M, R;
    cin >> N >> M >> R;
    vector<int> r_list(R);
    rep(i, R) cin >> r_list[i];

    Graph graph(N, vector<ll>(N, INF));
    rep(i, M) {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        graph[a][b] = c;
        graph[b][a] = c;
    }
    warshall_floyd(graph);

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

    ll ans = INF;
    do {
        int start = r_list[0] - 1;
        ll tmp = 0;
        rep2(i, 1, R) {
            tmp += graph[start][r_list[i] - 1];
            start = r_list[i] - 1;
        }
        ans = min(ans, tmp);
    } while ((next_permutation(r_list.begin(), r_list.end())));
    cout << ans << '\n';
}

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


Measured memory_bytes: 640
#include <iostream>

using namespace std;
int main() {
    int n,cnt;
    cin >> n;
    cnt = 0;
    for (int i=1; i<=n; i++) {
        int p;
        cin >> p;
        if (p!=i) cnt++;
    }
    if (cnt <= 2) {
        cout << "YES" << "\n";
    } else {
        cout << "NO" << "\n";
    }
}

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

int main() {
  int N;
  cin >> N;
  int j = 0;
  for (int i; i<N; i++){
    int x1, x2;
    cin >> x1 >> x2;
 //   cout << 'i' << ':' << i << endl;
	if (x1==x2) {
      j += 1;
 //     cout << j << endl;
    }
	if (x1!=x2) {
      j = 0;
//      cout << j << endl;
    }
    if (j==3) {
      cout << "Yes" << endl;
      break;
    }
    if (i==N-1) {
      if (j==3) {
        cout << "Yes" << endl;
        break;
      }
      if (j!=3) {
        cout << "No" << endl;
        break;
      }
    }

  }
}

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

using namespace std;

int main()
{
  int n;
  string s, t, ans;
  cin >> n >> s >> t;
  for (int i = 0;i < n;i++){
    ans += s[i];
    ans += t[i];
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String[] shop = {"A","B","C","D","E"};
		one:
		while (true) {
			int[] list = new int[5];
			int max = 0;
			for (int i = 0; i < list.length; i++) {
				String[] strings = sc.nextLine().split(" ");
				if (strings[0].equals("0") && strings[1].equals("0")) {
					break one;
				}
				int num = 0;
				num = Integer.parseInt(strings[0]) + Integer.parseInt(strings[1]);
				if (num > max) {
					max = num;
				}
				list[i] = num;
			}
			for (int i = 0; i < list.length; i++) {
				if(list[i] == max){
					System.out.println(shop[i] + " " + list[i]);
					break;
				}
			}

			
		}
	}
}

Measured memory_bytes: 28216
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    ll n, k;
    cin >> n >> k;
    ll ans = 0;
    if (k==0) {
        cout << n*n << endl;
        return 0;
    }
    for (ll i=k+1; i<=n; i++) {
        ll v = n/i;
        ll now = v*(i-k);
        v = n%i;
        if (v>0) {
            if (k==0) now += v;
            else now += max(0LL, v-k+1);
        }
        ans += now;
        //cout << now << endl;
    }
    
    
    
    
    cout << ans << endl;
    return 0;
}


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

int main () {
  int n, m;
  cin >> n >> m ;
 
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  
  int vote = 0;
  int cnt = 0;
  for (int i = 0; i < n; i++) {
    vote += a[i];
  }
  
  for (int i = 0; i < n; i++) {
    if (a[i] * 4 * m >= vote) {
      cnt++;
    }
  }
  
  if (cnt >= m) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        PrintStream out = new PrintStream(System.out);
        final int[] list = {0,1,3,1,2,1,2,1,1,2,1,2,1};
        int x, y;

        x = sc.nextInt();
        y = sc.nextInt();

        if(list[x] == list[y]) {
            out.println("Yes");
        } else {
            out.println("No");
        }
        
        
        sc.close();
    }
}

Measured memory_bytes: 21716
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
int main(void)
{
    int n,x,t=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&x);
        if(x%2==0&&x%3&&x%5)
            t=1;
    }
    if(t==0)
        printf("APPROVED\n");
    else
        printf("DENIED\n");
    return 0;
}


Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def f(S):
    res = 0
    for s in S:
        res += ord(s)-ord("0")
    return res
def main():
    S=ST()
    print(max(f(S),int(S[0])-1 + 9*(len(S)-1)))
if __name__ == '__main__':
    main()

Measured memory_bytes: 64620
#include <stdio.h>
#include <string.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, be = 1;
  char s[100010];
  scanf("%s", s);
  n = strlen(s);
  if(s[n - 1] == '1' || s[0] == '0') {
    printf("-1");
    return 0;
  }
  for(i = 0; i < n / 2; ++i) if((s[i] == '1' && s[n - i - 2] == '0') || (s[i] == '0' && s[n - i - 2] == '1')) {
    printf("-1");
    return 0;
  }
  for(i = (n - 1) / 2; i >= 0; --i) {
    if(s[i] == '1') {
      for(j = be + 1; j <= n - i; ++j) printf("%lld %lld\n", be, j);
      be = n - i;
    }
  }
  for(i = be + 1; i <= n; ++i) printf("%lld %lld\n", be, i);
  return 0;
}

Measured memory_bytes: 1280