akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  ll a;
  string b;
  cin >> a >> b;
  b.erase(1,1);
  cout << a*stoi(b)/100 << endl;
}

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

char a[10];
int main(){
	cin >> a;

	for(int i = 0;i < 4;i++)
		a[i] -= '0';

	for(int i = 0;i < (1 << 3);i++) {
		int sum = a[0];

		for(int j = 0;j < 3;j++) {
			if(i & (1 << j)) {
				sum += a[j + 1];
			}else {
				sum -= a[j + 1];
			}
		}

		if(sum == 7) {
			cout << (int)a[0];
			for(int j = 0;j < 3;j++) {
				if(i & (1 << j)) {
					cout << '+';
				}else 
					cout << '-';
				cout << (int)a[j + 1];
			}
			cout << '=' << 7 << endl;
			break;
		}
	}
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#define N_MAX 50
#define DATE_MAX 100

int main(void)
{
    char free_members[DATE_MAX];
    int n, q, m, i, meeting_date, meeting_members;

    while(scanf("%d %d", &n, &q), n + q)
    {
        for(i = 0; i < DATE_MAX; i++)
            free_members[i] = 0;

        while(n--)
        {
            scanf("%d", &m);
            while(m--)
            {
                scanf("%d", &i);
                free_members[i]++;
            }
        }

        for(meeting_date = meeting_members = i = 0; i < DATE_MAX; i++)
            if(free_members[i] >= q && free_members[i] > meeting_members)
                meeting_date = i, meeting_members = free_members[i];

        printf("%d\n", meeting_date);
    }

    return 0;
}

Measured memory_bytes: 600
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


###############################################################################


def main():
    k = intin()

    odd = (k + 1) // 2
    even = k // 2

    print(odd * even)


if __name__ == '__main__':
    main()


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string sa, sb, sc;
    cin >> sa;
    cin >> sb;
    cin >> sc;
    int index_a = 0;
    int index_b, index_c = 0;
    char c = sa[0];
    char turn = 'a';
    while(true) {
        if(turn=='a') {
            if(index_a==sa.length()) {
                cout << "A" << endl;
                break;
            } else {
                turn = sa[index_a++];
            }
        }else if(turn=='b'){
            if(index_b==sb.length()) {
                cout << "B" << endl;
                break;
            } else {
                turn = sb[index_b++];
            }
        }else if(turn=='c') {
            if(index_c==sc.length()) {
                cout << "C" << endl;
                break;
            } else {
                turn = sc[index_c++];
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
void solve(int N, int M){
    vector<int> V(M);
    rep(i,0,N){
        int a,b;
        cin >> a >> b;
        a--;
        V[a] = max(V[a], b);
    }
    int sum = 0;
    rep(i,0,M)sum += V[i];
    cout << sum << endl;
}
main(){
    int N,M;
    cin >> N >> M;
    while(N){
        solve(N,M);
        cin >> N >> M;
    }
}


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

int N;
string S;
//# . 
int dp[200009][2];

void solve()
{
	memset(dp,0x3f,sizeof(dp));
	if(S[0] == '#'){
		dp[0][1] = 0;
		dp[0][0] = 1;
	}else{
		dp[0][1] = 1;
		dp[0][0] = 0;
	}
	for(int i=1;i<N;++i){
		if(S[i] == '#'){
			dp[i][1] = min(dp[i-1][0],dp[i-1][1]);
			dp[i][0] = dp[i-1][0]+1;
		}else{
			dp[i][1] = min(dp[i-1][0],dp[i-1][1])+1;
			dp[i][0] = dp[i-1][0];
		}
	}
	cout << min(dp[N-1][0],dp[N-1][1]) << '\n';
}

int main()
{
	cin >> N >> S;
	solve();
	return 0;
}

Measured memory_bytes: 2180
N, cnt;
char s[55];
main(){
	scanf("%d%s", &N, s);
	for(int i=0; i<N; i++){
		cnt += s[i]=='A' && s[i+1]=='B' && s[i+2]=='C';
	}
	printf("%d\n", cnt);
	return 0;
}

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

mod = 1000000007
ans = 1
rgb = [0, 0, 0]
for num in a:
    ans = (ans * rgb.count(num)) % mod
    if ans == 0:
        break
    index = rgb.index(num)
    rgb[index] += 1
print(ans)

Measured memory_bytes: 13964
import sys
input = sys.stdin.readline

n = int(input())
A = tuple(int(x) for x in input().split())
_ = int(input())
M = tuple(int(x) for x in input().split())

S = set()
def Check(i, s):
    if i == n:
        S.add(s)
        return
    Check(i + 1, s + A[i])
    Check(i + 1, s)

Check(0, 0)

for m in M:
    if m in S:
        print('yes')
    else:
        print('no')


Measured memory_bytes: 5672
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <math.h>
#include <cmath>
#include <iomanip>
#include <set>
#include <vector>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cassert>

using namespace std;
using ll = long long;

#define nl "\n"
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define trav(x) for(auto& i: x)

int cnt, cnt1;
string s;

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

	int a, b;
	cin >> a >> b;
	cout << a * b;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;
using edge=pair<pair<int,int>,int>;
using P=pair<int,edge>;
#define me(x,y,z) make_pair(make_pair((x),(y)),(z))
#define x first.first
#define y first.second
#define z second
const int INF=1<<29;
int d[32][32][4];
int V,E;

int w,h;
int s[32][32];
int c[3];
//O(E*logV)
void dijkstra(){
  priority_queue<P,vector<P>,greater<P>> que;
  REP(i,32)REP(j,32)REP(k,4)d[i][j][k]=INF;
  REP(i,4){
    d[1][1][i]=s[1][1]==i?0:c[i];
    que.push(P(d[1][1][i],me(1,1,i)));
  }
  while(!que.empty()){
    P p=que.top();que.pop();
    edge v=p.second;
    if(v.z==0)v.x++;
    if(v.z==1)v.y++;
    if(v.z==2)v.x--;
    if(v.z==3)v.y--;
    if((v.x<1)||(v.x>w)||(v.y<1)||(v.y>h))
      continue;
    REP(i,4){//i=new meirei
      int cost=i==s[v.y][v.x]?p.first:p.first+c[i];
      if(d[v.y][v.x][(v.z+i)%4]<=cost)continue;
      d[v.y][v.x][(v.z+i)%4]=cost;
      que.push(P(d[v.y][v.x][(v.z+i)%4],me(v.x,v.y,(v.z+i)%4)));
    }
  }
  cout<<min({d[h-1][w][1],d[h][w-1][0]})<<endl;
}

int main(){ _;
  while(cin>>w>>h,(w|h)!=0){
    REP(i,h)REP(j,w)cin>>s[i+1][j+1];
    REP(i,4)cin>>c[i];
    dijkstra();
  }
}

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n),b(n,0),c(n,0);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b.begin(),b.end());
    
    for(int i = 0; i < n; i++){
        cout << (a[i] < b[n / 2] ? b[n / 2] : b[n / 2 - 1]) << "\n";
    }

}

Measured memory_bytes: 4480
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' '); 
            int a = Int32.Parse(input[0]);
            int b = Int32.Parse(input[1]);

            int cnt = 0;

            if(a > b)
            {
                cnt += a;
                a--;
            }
            else
            {
                cnt += b;
                b--;
            }
            
            if(a > b)
            {
                cnt += a;
                a--;
            }
            else
            {
                cnt += b;
                b--;
            }

            Console.WriteLine(cnt);
        }      
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
		String S = scanner.next();
		String a = S.substring(0, S.length()-1);

		while(a.length()>0) {
			if(a.length()%2==0) {
				String[] z = new String[2];
				z[0] = S.substring(0, a.length()/2);
				z[1] = S.substring(a.length()/2, a.length());

				if(z[0].equals(z[1])) {
					System.out.println(a.length());
					break;
				}
			}
			a = a.substring(0, a.length()-1);
		}
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   for(int i=0;i<(n);++i)
#define SORT(c)    sort((c).begin(),(c).end())
#define CLR(a)     memset((&a), 0 ,sizeof(a))//clear memory
#define dump(x)    cerr << #x << " = " << (x) << endl;//debug
#define debug(x)   cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define EPS        1e-10//sample:if((double)>=(double)+EPS)
//cin,cout release
//std::cin.tie(0);
//ios::sync_with_stdio(false);

using namespace std;
int c[10000][10000]={};
int lcs(string s1,string s2){
  int m=s1.length(),n=s2.length(),maxl=0;
  s1=' '+s1;s2=' '+s2;
  rep(i,1000)rep(j,1000)c[i][j]=0;
  for(int i=1;i<=m;i++){
    for(int j=1;j<=n;j++){
      if(s1[i]==s2[j])c[i][j]=c[i-1][j-1]+1;
      else c[i][j]=max(c[i-1][j],c[i][j-1]);
      maxl=max(maxl,c[i][j]);
    }
  }
  return maxl;
}
int main(){
  string str1,str2;
  int n;
  cin>>n;
  rep(i,n){
    cin>>str1>>str2;
    cout<<lcs(str1,str2)<<endl;
  }
  return 0;
}


Measured memory_bytes: 11124
// C.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <iostream>
#include<vector>
using namespace std;


vector<int> IntegerToVector(int bit, int N) {
    vector<int> S;
    for (int i = 0; i < N; ++i) {
        if (bit & (1 << i)) {
            S.push_back(i);
        }
    }
    return S;
}
int s[10][10];
int main()
{
    int n, m,k,key;
    int p[10];
    
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> k;
        for (int j = 0; j < k; j++) {
            cin >> key;
            s[i][key - 1] = 1;
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> p[i];
    }
    vector<int>a(n);
    int sum = 0;
  
    for (int bit = 0; bit < (1 << n); bit++) {
        vector<int> S = IntegerToVector(bit, n);
        bool ok = true;

     
            for (int i = 0; i < m; i++) {
                int gou = 0;
                for (int j : S) {
                    if (s[i][j] == 1)gou++;
                }
                
                if (gou % 2 != p[i]) {
                    ok = false;
                    break;
                }
                
            }
            if (ok)sum++;
        

    }
    cout << sum << endl;



}



Measured memory_bytes: 3588
#include <stdio.h>

int selectionSort(int A[], int N) {
    int i,j,t,sw =0,minj;
    for(i=0;i<N-1; i++) {
        minj = i;
        for(j=i;j < N; j++) {
            if(A[j] < A[minj]) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if(i != minj) sw++;
    }
    return sw;
} 

int main() {
    int A[100], N, i, sw;
    
    scanf("%d", &N);
    for(i =0;i<N;i++) scanf("%d", &A[i]);
    
    sw = selectionSort(A, N);
    
    for(i = 0; i < N;i++) {
        if(i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n",sw);
    
    return 0;
}


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

int main(){
    int N;
    string s,t;
    cin >> N >> s >> t;
    for(int i=0;i<N;i++){
        cout <<s[i] << t[i];
    }
    cout << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
import java.util.Scanner;

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

        int D = sc.nextInt();
        int N = sc.nextInt();

        System.out.println(solve(D, N));

        sc.close();
    }

    static int solve(int D, int N) {
        int result = (N == 100) ? 101 : N;
        for (int i = 0; i < D; ++i) {
            result *= 100;
        }

        return result;
    }
}

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

int selectionSort(int a[], int n){
    int minj, count = 0;
    for(int i = 0; i < n; i++){
        minj = i;
        for(int j = i; j < n; j++){
            if(a[j] < a[minj])
                minj = j;
        }
        swap(a[i],a[minj]);
        if(i != minj)
            count++;
    }
    return count;
}

int main(){
    int n, count, a[1000];
    cin >> n;
    for(int i = 0; i < n;i++){
        cin >> a[i];
    }
    count = selectionSort(a,n);

    for(int i = 0; i < n; i++){
        cout << a[i];
        if(i != n -1)
            cout << " ";
    }
    cout << endl << count << endl;
}


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

int main(void){
    int a,b;
    cin >> a >> b;
    int ans = 0;
    for(int i=a; i<=b; i++){
        vector<int> v(5);
        int n = i;
        int d = 1e4, j = 0;
        while(d > 0){
            v.at(j) = n/d;
            n -= v.at(j)*d;
            d /= 10;
            j++;
        }
        if(v.at(0) == v.at(4) && v.at(1) == v.at(3)){
            ans++;
        }
    }
    cout << ans <<endl;
    return 0;
}

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

int main(){
	double a, b, c, d, e, f;
	double x, y;
	
	while((scanf("%lf", &a)) != EOF){
		scanf("%lf%lf%lf%lf%lf", &b, &c, &d, &e, &f);
		
		x = (c * e - f * b) / (a * e - d * b);
		y = (c * d - f * a) / (b * d - e * a);
		
		if(x == -0.0) x = 0;
		if(y == -0.0) y = 0;
		printf("%.3f %.3f\n", x, y);
	}
	
	return 0;
}

Measured memory_bytes: 1080
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    int a, b;
    cin >> a >> b;
        if (a <= b) cout << a << endl;
        else cout << a - 1 << endl;
    

}



    

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
 
using vd=vector<double>;
using vvd=vector<vd>;
 
 
int main(){
    int h,w;
    cin>>h>>w;
    vvi f(h+2,vi(w+2,1));
    vvi walk(h+2,vi(w+2,0));
    int gy,gx,y=0,x=0,v=0;
    range(i,1,h+1)range(j,1,w+1){
        char c;
        cin>>c;
        switch(c){
            case 'G': gy=i,gx=j,f[i][j]=0; break;
            case '.': f[i][j]=0;break;
            case '#': break;
            case '^': y=i,x=j,v=0,f[i][j]=0; break;
            case '>': y=i,x=j,v=1,f[i][j]=0; break;
            case 'v': y=i,x=j,v=2,f[i][j]=0; break;
            case '<': y=i,x=j,v=3,f[i][j]=0; break;
        }
    }
    walk[y][x]=1;
    rep(loop,2650){
        vvi vec={{-1,0},{0,1},{1,0},{0,-1}};
        if(f[y+vec[(v+1)%4][0]][x+vec[(v+1)%4][1]]==0){ //右手が道なら右に曲がって前に進む
            //cout<<"hoge";
            v=(v+1)%4;
            y+=vec[v][0], x+=vec[v][1];
            walk[y][x]=1;
        }else if(f[y+vec[v][0]][x+vec[v][1]]==1){ //（右が壁で、）正面が壁なら左に回る
            //cout<<"fuga";
            v=(v+3)%4;
        }else{ //そうでないならまえに進む
            //cout<<"zako";
            y+=vec[v][0],x+=vec[v][1];
            walk[y][x]=1;
        }
        if(y==gy&&x==gx){
            break;
        }
        // cout<<y<<","<<x<<","<<v<<endl;
        // rep(i,h+2){
        //     rep(j,w+2){
        //         if(i==y&&j==x){
        //             cout<<"^>v<"[v];
        //         }else{
        //             cout<<".#"[f[i][j]];
        //         }
        //     }
        //     cout<<endl;
        // }
    }
    if(y==gy&&x==gx){
        int ans=0;
        rep(i,h+2)rep(j,w+2)ans+=walk[i][j];
        cout<<ans<<endl;
    }else cout<<-1<<endl;
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n, m, x;
  cin >> n >> m >> x;

  vector<ll> a(n);
  for (ll i = 0; i < m; ++i) {
    ll ai;
    cin >> ai;
    ai--;
    a[ai] = 1;
  }

  ll ans = 1e18;
  ll cost = 0;
  for (ll i = 0; i < x; ++i) {
    cost += a[i];
  }
  ans = min(ans, cost);

  cost = 0;
  for (ll i = x; i < n; ++i) {
    cost += a[i];
  }
  ans = min(ans, cost);

  cout << ans << endl;

  return 0;
}

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



int main() {
    int N, index, judge=0, count=0;
    double T, A;
    long double min=LLONG_MAX, value;
    
    cin >> N >> T >> A;
    
    rep(i,N) {
      cin >> value;
      if(abs(A-(T-value*0.006))<min) {
        min = abs(A-(T-value*0.006));
        index = i+1;
      }
    }
    
    cout << index << endl;
    
      
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

ll rep_pow(ll a, ll b){//繰り返し2乗法
    if(b==0) return 1;
    else if(b%2==0){
        ll memo = rep_pow(a, b/2);
        return memo*memo%mod;
    }else{
        return rep_pow(a, b-1)*a%mod;
    }
}
ll nCr(ll n, ll r){//mod逆元　nCr
    ll ret=1;
    rep(i,r){
        ret *= n-i;//分子
        ret %= mod;
        ret *=rep_pow(r-i, mod-2);//mod逆元
        ret %= mod;
    }
    return ret;
}
ll gcd(ll a, ll b){if(b==0) return a; return gcd(b, a%b);}
bool isPrime(int x){
    if(x==1) return false;
    else if(x==2) return true;
    else if(x%2==0) return false;
    for(int i=3;i<=sqrt(x);i+=2){
        if(x%i==0){
            return false;
        }
    }
    return true;
}

int main(){
    fast_io

    int k, n;
    cin>>k>>n;
    vector<int> A;
    rep(i,n){
        int x; cin>>x;
        A.push_back(x);
    }
    int ans=0;
    vector<int> l;
    rep(i,n-1){
        l.push_back(A[i+1]-A[i]);
    }
    l.push_back(k-(A[n-1]-A[0]));
    sort(l.begin(), l.end());
    rep(i,n-1){
        ans+=l[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 2548
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		String s=sc.next();
		int depth=0;
		int mindepth=0;
		for(int i=0;i<n;i++) {
			if(s.charAt(i)=='(') {
				depth++;
			}
			else {
				depth--;
			}
			if(mindepth>depth) {
				mindepth=depth;
			}
		}
		
		StringBuilder ans=new StringBuilder();
		for(int i=mindepth; i<0;i++) {
			ans.append('(');
		}
		ans.append(s);
		for (int i=0;i<depth-mindepth;i++) {
			ans.append(')');
		}
		System.out.println(ans);
	}

}


Measured memory_bytes: 20948
#include <iostream>
#include <cmath>
using namespace std;
typedef long long int lli;

int main(){
    while(1){
        lli n;
        cin >> n;
        if(n==0) break;
        
        lli ans = 2*n*n +8*n;
        n /= 2;
        lli sqrtn = ceil(sqrt(n));
        ans -= (n-sqrtn)*(n-sqrtn) *8;
        for(lli i=1; i<sqrtn; i++){
            ans -= ( n -(n+i-1)/i ) *16;
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 2984
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#define eb(i,j) emplace_back((i),(j))
#include <bits/stdc++.h>
using namespace std;
//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;
const int mod = 1000000009;

int n,p,a;
ll dp[2][51];

int main(){
    I(n); I(p);
    dp[0][0] = 1;
    REP(i,n){
        I(a); a&=1;
        if(a){
            dp[0][i+1] = dp[0][i] + dp[1][i];
            dp[1][i+1] = dp[0][i] + dp[1][i];
        } else {
            dp[0][i+1] = dp[0][i] * 2;
            dp[1][i+1] = dp[1][i] * 2;
        }
    }
    cout << dp[p][n] << endl;
}

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

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

    vector<int> v(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        v[a-1]++;
        v[b-1]++;
    }

    for (int i = 0; i < n; i++) {
        cout << v[i] << endl;
    }

    return 0;
}

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


int main() {
  string s, t, k;
  cin >> s;
  int n, m, l;
  n = s.size();
  t = s.substr((n + 1) / 2);
  m = t.size();
  l = m / 2;
  k = s.substr(0, m);
  
  bool ans = true;
  
  if(k != t){
    ans = false;
  }
  
  
  
  for(int i = 0; i < m; i++){
    if(t[i] != t[m - 1 - i]){
      ans = false;
    }
  }

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

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

int main(){
    int N;
    cin >> N;
    int a[100000];
    for(int i=0;i<N;i++)
        cin >> a[i];
    //4の倍数・偶数サーチ
    int four = 0, two = 0, odd = 0;
    for(int i=0;i<N;i++){
        if(a[i]%4 == 0)
            four++;
        else if(a[i]%2 == 0)
            two++;
        else
            odd++;
    }
    //許容される奇数の数は？
    if(two != 0){
        if(odd <= four)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }else{
        if((odd-1) <= four)
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
    
    return 0;
}

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

					#define sqr(x) (x)*(x)
					using namespace std;
					int n, a[222], k, t = 1e9;
					int main()
					{
						cin >> n;
						for(int i = 1; i <= n; i++)
							cin >> a[i];
						for(int i = 1; i <= 100; i++)
						{
							for(int j = 1; j <= n; j++)
								k += sqr(i-a[j]);
							t = min(t, k);
							k = 0;
						}
						cout << t;
					}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

using ll = int64_t;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1'001'001'001;
const ll INFL = (1LL<<60);
const double eps = (1e-9);

const int mod = 1000000007;

vector<int> createEratos(int n)
{
  vector<int> isprime(n+1, 1);
  isprime[0] = 0;
  isprime[1] = 0;

  for (int i = 2; i * i <= n; i++) {
    if (isprime[i]) {
      int j = i + i;
      while (j <= n) {
        isprime[j] = 0;
        j = j + i;
      }
    }
  }
  return isprime;
}

set<int> createPrimeList(int n)
{
  vector<int> eratos = createEratos(n);
  set<int> result;
  for (int i = 1; i <=n; i++) {
    if (eratos[i]) {
      result.insert(i);
    }
  }
  return result;
}

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

  set<int> primes = createPrimeList(100000);
  vector<int> like_number;
  for (auto& v : primes) {
    if (v == 2) continue;
    if (primes.count((v+1)/2) != 0) like_number.push_back(v);
  }

  vector<int> s(100001, 0);
  auto itr = like_number.begin();
  for (int i = 1; i <= 100000; i++) {
    s[i] = s[i-1];
    if (*itr == i) {
      s[i]++;
      itr++;
    }
  }

  int q;
  cin >> q;
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    cout << s[r] - s[l-1] << endl;
  }

  return 0;
}


Measured memory_bytes: 1528
# AOJ 1602: ICPC Calculator
# Python3 2018.7.13 bal4u

def calc(lvl, idx):
	c = e[idx][lvl]
	if c.isdigit(): return [int(c), idx+1]
	lvl, idx = lvl+1, idx+1
	x = 0 if c == '+' else 1
	while idx < len(e):
		f = i = 0
		while i < len(e[idx]) and i < lvl:
			if e[idx][i] != '.': break
			i += 1
		if i < lvl: break
		if e[idx][i].isdigit(): y, f = int(e[idx][i]), 1
		else: y, idx = calc(lvl, idx)
		x = x+y if c == '+' else x*y
		if f: idx += 1
	return [x, idx]

while True:
	n = int(input())
	if n == 0: break
	e = [list(input()) for i in range(n)]
	print(calc(0, 0)[0])



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

int d;
vector<int> c;
vector< vector<int> > s;

int satisfaction(const vector<int>& t) {
  vector<int> last(26, -1);
  int ans = 0;
  for (int i = 0; i < (int) t.size(); i++) {
    ans += s[i][t[i]];
    last[t[i]] = i;
    for (int j = 0; j < 26; j++) {
      ans -= c[j] * (i - last[j]);
    }
  }
  return ans;
}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int myrand(int l, int r) {
  return uniform_int_distribution<int>(l, r)(rng);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  
  srand(time(nullptr));
  cin >> d;
  c.resize(26);
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
  }
  s.assign(d, vector<int>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  vector<int> t;
  for (int i = 0; i < d; i++) {
    vector<int> tmp = t;
    vector<int> best = {-1};
    for (int j = 0; j < 26; j++) {
      tmp.push_back(j);
      if (best[0] == -1 || satisfaction(tmp) > satisfaction(best)) {
        best = tmp;
      }
      tmp.pop_back();
    }
    swap(t, best);
  }
  for (int i = 0; i < 20000; i++) {
    int pos = myrand(0, d - 1), x = myrand(0, 25);
    vector<int> tmp = t;
    tmp[pos] = x;
    if (satisfaction(tmp) > satisfaction(t)) {
      swap(t, tmp);
    } 
  }
  for (auto& x : t) {
    cout << x + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 3804
#include<cstdio>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdlib>

using namespace std;

int main(void) {
	int ha, wa, h, w;

	cin >> ha >> wa >> h >> w;

	cout << (ha - h)*(wa - w) << "\n";

	return 0;
}

Measured memory_bytes: 256
// Linear_Search.cs

using System;
using System.Collections.Generic;

class Linear_Search {
	public static void Main() {

		int n = int.Parse(Console.ReadLine());
		int[] s = new int[n];
		string str = Console.ReadLine();
		string[] num = str.Split();

		for(int i = 0; i < n; i++) {
			s[i] = int.Parse(num[i]);
		}

		int m = int.Parse(Console.ReadLine());
		string str_s = Console.ReadLine();
		string[] num_s = str_s.Split();
		int[] search = new int[m];
		for(int i = 0; i < m; i++) {
			search[i] = int.Parse(num_s[i]);
		}

		int count = 0;

		for(int j = 0; j < m; j++) {
			for(int i = 0; i < n; i++) {
				if(s[i] == search[j]) {
					count++;
					break;
				}
			}
		}

		Console.WriteLine(count);

	}
}

Measured memory_bytes: 9376
import sys
input = sys.stdin.readline

S = input().strip()
a = ['A', 'T', 'G', 'C']

ans = 0
j = []
for i in range(len(S)):
  j = i
  count = 0
  while True:
    ans = max(ans, count)
    if j >= len(S):
      break
    if S[j] in a:
      count += 1
      j += 1
    else:
      break
  
print(ans)

Measured memory_bytes: 3064
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;

import java.util.*;

public class Main {
    long MOD = (long) 1e9 + 7;

    InputStream in;
    OutputStream out;

    public Main() {
        this(System.in, System.out);
    }

    public Main(InputStream in, OutputStream out) {
        this.in = in;
        this.out = out;
    }

    int n;
    int[] hs;
    Edge[] g;

    void run() {
        Scanner sc = new Scanner(this.in);
        PrintWriter out = new PrintWriter(this.out);

        // write your code
        int n = sc.nextInt(), m = sc.nextInt();
        int[] hs = new int[n];
        g = new Edge[n];
        for (int i = 0; i < n; i++) {
            hs[i] = sc.nextInt();
            g[i] = new Edge();
        }

        for (int i = 0; i < m; i++) {
            int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
            g[a].add(b);
            g[b].add(a);
        }

        int cnt = 0;
        for (int i = 0; i < n; i++) {
            boolean ok = true;
            for (int next: g[i]) {
                if (hs[next] >= hs[i]) {
                    ok = false;
                }
            }
            if (ok) cnt++;
        }
        out.println(cnt);

        out.flush();
    }

    class Edge extends ArrayList<Integer> {}

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}

Measured memory_bytes: 71376
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int N,M;
  cin>>N;
  vector<string> blue(N);
  for (int i=0;i<N;i++){
    cin >>blue.at(i);
  }
  cin >>M;
  vector<string> red(M);
  for (int i=0;i<M;i++){
    cin >>red.at(i);
  }
  int sum=0;
  for (int i=0; i<N;i++){
    int count=0;
    for (int x=i;x<N;x++){
      if(blue.at(i)==blue.at(x)){
        count++;
      }
    }
    for (int x=0;x<M;x++){
      if (blue.at(i) == red.at(x)){
        count--;
      }
    }
    if (count>sum){
      sum= count;
    }
  }
  cout <<sum <<endl;
}

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

#define sz(x) int(x.size())
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 2e5 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 2019;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin); freopen(Task".out", "w", stdout);
  int n; cin >> n;
  vector<int> a(n+1);
  for (int i = 1; i <= n; ++i){
    cin >> a[i];
  }
  vector<int> cnt(n, 0);
  ll ans = 0;
  for (int i = 1; i <= n; ++i){
    if (i - a[i] >= 2 && i - a[i] <= n - 1) ans = ans + cnt[i-a[i]];
    if (i + a[i] >= 2 && i + a[i] <= n - 1) cnt[i+a[i]]++;
  }
  cout << ans;
}



Measured memory_bytes: 4744
#include<bits/stdc++.h>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int main()
{
    int a,v,b,c,d,e,f=0,r,i,j;
    cin>>a;
    for(i=a;i<(a*5);i++)
    {
        f=0;
        for(j=2;j<i;j++)
        {
            if(i%j==0)
            {
                f++;
                break;
            }
        }
        if(f==0)
        { cout<<i<<endl;
        break;

        }

    }
}


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

int main() {
    for (int i=0; i<10000;i++) {
        int a;
        cin >> a;
        if (a!=0) cout << "Case"<< " "<< i+1 <<": "<< a << endl;
        else break;
        
    }
}


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

int main(){
  int a,N,b,s;
  cin >> a>>N;
  for(int i=0;i<N;i++){
    cin >> b;
    s=s+b;
  }
  if(a>s)cout <<"No"<<endl;
  else{
  cout << "Yes" << endl;
  }

}


Measured memory_bytes: 256
#include<stdio.h>

int main() {

  int a, b, c, d;

  scanf("%d%d%d%d", &a, &b, &c, &d);

  if (a == b) {
    if (c == d) {
      printf("yes\n");
      return 0;
    }

    printf("no\n");
    return 0;
  } else if (a == c) {
    if (b == d) {
      printf("yes\n");
      return 0;
    }

    printf("no\n");
    return 0;
  } else if (a == d) {
    if (b == c) {
      printf("yes\n");
      return 0;
    }

    printf("no\n");
    return 0;
  }

  printf("no\n");
  return 0;


}



Measured memory_bytes: 2092
#include <stdio.h>                                                              
                                                                                
int main(){                                                                     
  int A,B;                                                                      
  scanf("%d%d",&A,&B);                                                          
                                                                                
  if(A+B>9){                                                                    
    printf("error\n");                                                          
  }else{                                                                        
    printf("%d",A+B);                                                           
  }                                                                             
  return 0;                                                                     
}                      

Measured memory_bytes: 128
M=998244353;N=gets.to_i;v=$<.map{|e|Complex(*e.split.map(&:to_i))};h={};r=2**N%M-N-1;N.times{|i|(i+1...N).map{|j|h[x=[i,j]]&&next;(j+1...N).map{|k|((v[j]-v[k]).conj*(v[i]-v[k])).imag.abs<1e-9&&x<<k};x.size.times{|a|(a+1...x.size).map{|b|r=(r-2**(b+~a))%M;h[[x[a],x[b]]]=1}}}};p r%M

Measured memory_bytes: 5116
n=int(input())
ans=[]

for i in range(n):
    s=input()
    s=list(s)
    if i == 0:
        ans=s
    else:
        memo=[]
        for l in s:
            if l in ans:
                indexnumber = ans.index(l)
                p = ans.pop(indexnumber)
                memo.append(p)  
        ans=memo

ans.sort()
print(''.join(map(str,ans)))

Measured memory_bytes: 38896
x,y=map(int,input().split())
ans=0
if x==1:
    ans+=300000
if x==2:
    ans+=200000
if x==3:
    ans+=100000
if y==1:
    ans+=300000
if y==2:
    ans+=200000
if y==3:
    ans+=100000
if x==1 and y==1:
    ans+=400000
print(ans)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define double long double
#define low lower_bound
#define upp upper_bound
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define Rep(i,n) for (int i = (int)(n); i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define rever(vec) reverse(all(vec));
#define cend printf("\n");
#define prique(T) priority_queue<T, vector<T>, greater<T>>
#define prique2(T) priority_queue<T>

#define yes printf("Yes\n")
#define Yes printf("YES\n")
#define no printf("No\n")
#define No printf("NO\n")

struct edge { int to, cost; };
using P = pair<int, int>;
using PP = pair<P, int>;
using D = pair<double, double>;
//const long long mod = 998244353;
const long long mod = 1e9 + 7, inf = 3e18;
const string sp = " ";
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = max(a, b);
		return true;
	}
	return false;
}
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = min(a, b);
		return true;
	}
	return false;
}

int modpow(int x, int n) {
	int ans = 1;
	while (n > 0) {
		if (n & 1) {
			ans *= x;
			if (mod <= ans) ans %= mod;
		}
		x *= x;
		if (mod <= x) x %= mod;
		n >>= 1;
	}
	return ans;
}

int fact[1000000];
void f_init(int n) {
	if (1000000 <= n) return;
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= n; ++i) {
		fact[i] *= fact[i - 1];
		if (mod <= fact[i]) fact[i] %= mod;
	}
	return;
}

int comb(int n, int r) {
	if (n < r) return 0;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod * modpow(fact[r], mod - 2);
	if (ans < 0) return ans + mod;
	return ans;
}

int perm(int n, int r) {
	if (n < r) return 0;
	if (n - r < r) r = n - r;
	int ans = fact[n] * modpow(fact[n - r], mod - 2) % mod;
	if (ans < 0) return ans + mod;
	return ans;
}

int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

bool pri(int p) {
	for (int i = 2; i * i <= p; ++i) if (p % i == 0) return false;
	return p > 1;
}

map<int, int> factring(int n) {
	map<int, int>ans;
	for (int i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			n /= i;
			++ans[i];
		}
	}
	if (n != 1) ++ans[n];
	return ans;
}

int n;
vector<int>v;
void dfs(int x) {
	if (x > n) return;
	rep(i, 3) {
		v.push_back(x * 10 + i * 2 + 3);
		dfs(x * 10 + i * 2 + 3);
	}
	return;
}
signed main() {
	cin >> n;
	dfs(0);
	for (int& i : v) {
		string s = to_string(i);
		int n = s.size();
		int a, b, c;
		a = b = c = 0;
		rep(i, n) {
			if (s[i] == '3') a++;
			else if (s[i] == '5') b++;
			else c++;
		}
		if (a * b * c) continue;
		i = inf;
	}
	sort(all(v));
	cout << upp(all(v), n) - v.begin();
}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int mod_pow(int x, int y) {
    if (y == 0) return 1;
    if (y == 1) return x;
    int a = mod_pow(x, y / 2);
    if (y & 1) return a * a % 2019 * x % 2019;
    else return a * a % 2019;
}

int main() {
    string S;
    cin >> S;
    
    vector<int> T(S.size() + 1, 0);
    for (int i = (int)S.size(); i > 0; --i) {
        T[i - 1] = (T[i] + (S[i - 1] - '0') * mod_pow(10, (int)S.size() - i)) % 2019;
    }
    vector<long long> cnt(2019, 0);
    rep(i, S.size() + 1) ++cnt[T[i]];
    long long ans = 0;
    rep(i, 2019) ans += cnt[i] * (cnt[i] - 1) / 2;
    cout << ans << endl;
    return 0;
}


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

// DAME:
int main() {
    ll n, k;
    cin >> n >> k;
    if(k & 1){
        ll ans = n/k;
        cout << ans*ans*ans << endl;
    }else{
        ll ans1 = n/k;
        ll ans2 = (n+k/2)/k;
        cout << ans1*ans1*ans1 + ans2*ans2*ans2 << endl;
    }

    return 0;
}

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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << s1[0] << s2[0] << s3[0] << endl;
    return 0;
}


Measured memory_bytes: 384
A=list(int(input())for i in range(5))
ans=0
num=0
com=0
for a in A:
    if a%10==0:
        ans+=a
    else:
        tmp=10-a%10
        ans+=(a//10+1)*10
        if com<tmp:
            com=tmp
            num=a
if num==0:
    print(ans)
else:
    ans-=(num//10+1)*10
    ans+=num
    print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <sstream>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

inline bool eq(char c1, char c2) {
  return (c1 == c2) || (c1 == '?') || (c2 == '?');
}

vector<bool> preprocess(const string &s, const string &t)
{
  vector<bool> flags(s.size() + 1, true);

  N_TIMES(i, s.size() + 1) {
    N_TIMES(j, t.size()) {
      if (i + j >= s.size()) { break; }

      if (!eq(s[i + j], t[j])) {
        flags[i] = false;
        break;
      }
    }
  }

  return flags;
}

uint64_t search(const string &a, const string &b, const string &c)
{
  vector<bool> ab = preprocess(a, b), bc = preprocess(b, c), ac = preprocess(a, c);

  uint64_t min_len = 1e+8;
  N_TIMES(i, a.size() + 1) { // i ; diff pos between a and b
    if (!ab[i]) { continue; }

    for (uint64_t j = i; j < a.size() + b.size() + 2; ++j) { // j ; diff pos between a and c
      if (j < (a.size() + 1) && !ac[j]) { continue; }

      uint64_t k = j - i;
      if (k < (b.size() + 1) && !bc[k]) { continue; }

      uint64_t most_right = max(a.size(), max(i + b.size(), j + c.size()));
      min_len = min(min_len, most_right);
    }
  }

  return min_len;
}

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

  vector<uint64_t> candidates = {
    search(a, b, c),
    search(a, c, b),
    search(b, c, a),
    search(b, a, c),
    search(c, a, b),
    search(c, b, a)
  };

  uint64_t ans = *min_element(candidates.begin(), candidates.end());
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
class dice:
    state={"now":6,"N":5,"S":2,"W":4,"E":3,"behind":1}
    writtenval={}
    def __init__(self):
        self.writtenval=[-1]+[int(item) for item in input().split()]

    def chState(self):
        state=self.state
        for order in input():
            if order == "N":
                newstate = {"now": state["N"],
                            "N": state["behind"],
                            "S": state["now"],
                            "W": state["W"],
                            "E":state["E"],
                            "behind":state["S"]
                            }
                state=newstate
            elif order == "S":
                newstate = {"now": state["S"],
                            "N": state["now"],
                            "S": state["behind"],
                            "W": state["W"],
                            "E":state["E"],
                            "behind":state["N"]
                            }
                state=newstate
            elif order == "W":
                newstate = {"now": state["W"],
                            "N": state["N"],
                            "S": state["S"],
                            "W": state["behind"],
                            "E":state["now"],
                            "behind":state["E"]
                            }
                state=newstate
            elif order == "E":
                newstate = {"now": state["E"],
                            "N": state["N"],
                            "S": state["S"],
                            "W": state["now"],
                            "E":state["behind"],
                            "behind":state["W"]
                            }
                state = newstate
        self.state=state

dice_ = dice()
dice_.chState()
print(dice_.writtenval[dice_.state["behind"]])


Measured memory_bytes: 5616