akhauriyash/Code-Regression huggingface dataset:
import java.util.HashSet;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int integerX = sc.nextInt();  //元の整数
		int youso = sc.nextInt();  //整数列の要素数
		HashSet<Integer> list = new HashSet<Integer>();  //整数列を入れるリスト

		//配列を入力
		for(int i=0 ; i<youso ; i++) {
			list.add(sc.nextInt());
		}

		int i = integerX-1;
		int j = integerX+1;

		if(list.isEmpty() || list.contains(integerX) != true) {
			System.out.println(integerX);
			return;
		}

		for(;;) {
			if(list.contains(i)) {
				i--;
			}
			else{
				System.out.println(i);
				return;
			}

			if(list.contains(j)) {
				j++;
			}
			else {
				System.out.println(j);
				return;
			}
		}
	}
}

Measured memory_bytes: 27260
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int A, B, C;
int K;

signed main(){
    cin >> A >> B >> C;
    cin >> K;
    while(K > 0 && A >= B){
        B *= 2;
        K--;
    }
    while(K > 0 && B >= C){
        C *= 2;
        K--;
    }
    if(A < B && B < C) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main(){
  string S;
  cin >> S;
  int N = S.size();
  int dif_S0 = 0;
  int dif_S1 = 0;
  
  for(int i = 0; i < N; i++){
    if(i % 2 == 0){
      if(S.at(i) == '1'){
        dif_S0++;
      }
    } else {
      if(S.at(i) == '0'){
        dif_S0++;
      }
    }
  }
  for(int i = 0; i < N; i++){
    if(i % 2 == 0){
      if(S.at(i) == '0'){
        dif_S1++;
      }
    } else {
      if(S.at(i) == '1'){
        dif_S1++;
      }
    }
  }
  
  cout << min(dif_S0, dif_S1) << endl;
}


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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))




int main(void)
{
	//変数の宣言
	int n;
	int f[110][10];
	int p[110][10];
	int mise[110];
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	int count=0;
	int sum=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	//データの読み込み
	
	scanf("%d",&n);
	
	for(i=0;i<n;i++){
		for(j=0;j<10;j++){
			scanf("%d",&f[i][j]);
		}
	}
	
	for(i=0;i<n;i++){
		for(j=0;j<=10;j++){
			scanf("%d",&p[i][j]);
		}
	}
	
	
//	for(i=0;i<n;i++){
//		for(j=0;j<=10;j++){
//			printf("%d ",p[i][j]);
//		}
//		printf("\n");
//	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	ans=-100000000000;
	for(i=1;i<1024;i++){
		for(j=0;j<n;j++){
			mise[j]=0;
		}
		sum=0;
		
		for(j=0;j<10;j++){
			if(i&(1<<j)){
				for(k=0;k<n;k++){
					mise[k]=mise[k]+f[k][j];
//					printf("f[0][%d]=%d\n",j,f[0][j]);
				}
			}
		}
		
		for(j=0;j<n;j++){
			sum=sum+p[j][mise[j]];
		}
		if(ans<sum) ans=sum;
//		printf("i=%d,mise[0]=%d,mise[1]=%d,sum=%d\n",i,mise[0],mise[1],sum);
	}
	
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%lld",ans);
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



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

int main(){
    ll n,t;
    cin>>n>>t;
    ll x,y;
    ll min=1001;
    rep(i,n){
        cin>>x>>y;
        if(y<=t){
            min=std::min(min,x);
        }
    }
    if(min==1001)cout<<"TLE"<<endl;
    else cout<<min<<endl;
}



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

int main() {
  int n;
  cin >> n;
  vector<int> a(n), b(n);
  for (auto&& w : a) cin >> w;
  int sn = 0, en = n - 1;
  for (int j = n - 1; j >= 0; j -= 2) {
    b[sn] = a[j];
    if (j == 0) break;
    b[en] = a[j - 1];
    en--;
    sn++;
  }
  for (auto&& w : b) cout << w << endl;
}


Measured memory_bytes: 3712
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

Measured memory_bytes: 3636
N = int(input())
S = input()
l = 0
r = 0
for i in range(N):
  if S[i] == ')':
    if r > 0:
      r-=1
    else:
      l+=1
  else:
    r+=1
for _ in range(l):
  print('(', end='')
print(S, end='')
for _ in range(r):
  print(')', end='')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define int long long
#define MOD 1000000007
#define endl "\n"
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define vvi vector<vi>
#define endl "\n"
using namespace std;
void solve1();
void solve()
{
    int t;cin>>t;
    while(t--)
    {
        solve1();
    }
}
signed main()
{
    solve1();
}
void solve1()
{
    int n,k;cin>>n>>k;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);int ans=0;
    for(int i=0;i<k;i++)
    {
        ans+=arr[i];
    }
    cout<<ans<<endl;
}


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

int main() {
  int n;
  string s;
  for (cin >> n; n > 0; n--) {
    cin >> s;
    if (s == "Y") {
      n = -1;
      break;
    }
  }
  if (n == 0) cout << "Three" << endl;
  else cout << "Four" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <list>
#include <string>
#include <unordered_map>
#include <limits>
#include <map>
#include <set>
#include <algorithm>
#include <queue>

using namespace std;

typedef long long ll;

//int main() {
//    map<set<int>, int> m;
//    int n, k;
//    cin >> n >> k;
//
//}

int main() {
    ios::sync_with_stdio(false);
    ll n, r = 0, g = 0, b = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            r++;
            continue;
        }
        if (s[i] == 'G') {
            g++;
            continue;
        }
        if (s[i] == 'B') {
            b++;
        }
    }
    ll p = r * g * b;
    for (int i = 0; i < n; ++i) {
        for (int d = 1; 2 * d < n; d++) {
            if (i + 2 * d < n && s[i + d] != s[i] && s[i] != s[i + d + d] && s[i + d] != s[i + d + d]) {
                p--;
            }
        }
    }
    cout << p << endl;
}

Measured memory_bytes: 3604
//package Atcoder;
import java.util.*;
import java.io.*;
public class Main
{
	static final int mod=(int)1e9+7;
	static final int inf=(int)1e9;
	static final long INF=(long)1e18;
	public static void main(String[] args)
	{
		FastScanner fs=new FastScanner();
		int n=fs.nextInt(),cnt=0;
		int arr[]=new int[n];
		int pref[]=new int[n];
		for(int i=0;i<n;i++)
		{
			arr[i]=fs.nextInt();
			if(i==0)
				pref[i]=arr[i];
			else
				pref[i]=Math.min(pref[i-1],arr[i]);
		}
		for(int i=0;i<n;i++)
		{
			if(arr[i]==pref[i])
				cnt++;
		}
		System.out.println(cnt);
	}
}
class FastScanner 
{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() 
		{
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
			
		}
		
		long pow(long x,long n)
		{
			long res=1;
			while(n>0)
			{
			   	if(n%2!=0)
			   	{
			   		res=(res*x);n--;
			   	}
			   	else
			   	{
			   		x=(x*x);n/=2;
			   	}
			}
			return res;
		}
		int gcd(int a,int b)
		{
			if(b==0)
			{
				return a;
			}
			return gcd(b,a%b);
		}
		long longgcd(long a,long b)
		{
			if(b==0)
			{
				return a;
			}
			return longgcd(b,a%b);
		}
		int[] sort(int arr[])
		{
			ArrayList<Integer> list = new ArrayList<Integer>();
			for(int i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		char[] charsort(char arr[])
	        {
	    	ArrayList<Character> list = new ArrayList<>();
	    	for(char c:arr)list.add(c);
	    	Collections.sort(list);
	    	for(int i=0;i<list.size();i++)
	    	{
	    		arr[i]=list.get(i);
	    	}
	    	return arr;
	        }
		long[] longsort(long arr[])
		{
			ArrayList<Long> list = new ArrayList<Long>();
			for(long i:arr)list.add(i);
			Collections.sort(list);
			for(int i=0;i<arr.length;i++)
			{
				arr[i]=list.get(i);
			}
			return arr;
		}
		public int nextInt() 
		{
			return Integer.parseInt(next());
		}
		public int[] readArray(int n)
		{
			int[] arr=new int[n];
			for (int i=0; i<n; i++) arr[i]=nextInt();
			return arr;
		}	
		public long nextLong()
		{
			return Long.parseLong(next());
		}
		public long[] longreadArray(int n) 
		{
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
}

Measured memory_bytes: 55304
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */


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

    int n, k; cin >> n >> k;
    int R, S, P; cin >> R >> S >> P;
    map<char, int> mp;
    map<int, int> score;
    score[0] = R; score[1] = S; score[2] = P;
    mp['r'] = 3; mp['p'] = 2; mp['s'] = 1;
    vector<vector<int>> dp(n+5, vector<int>(3, 0));
    string t; cin >> t;
    
    rep(i, n) rep(j, 3) {
        if (i<k) dp[i+1][j] = (j+1 == mp[t[i]]? score[j]:0);
        else {
            rep(l, 3) if (j!=l) {
                chmax(dp[i+1][j], dp[i+1-k][l] + (j+1 == mp[t[i]]? score[j]:0));
            }
        }
    }
    ll ans = 0;
    repr(i, n-k+1, n+1) {
        int maxv = 0;
        rep(j, 3) chmax(maxv, dp[i][j]);
        ans += maxv;
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 6016
#include<iostream>
#include<deque>
#include<set>
using namespace std;

int main(){
	while(true){
		int n;
		deque< set<int> > x,y;
		set<int> inst;
		inst.insert(0);
		x.push_back(inst);
		y.push_back(inst);
		cin>>n;
		if(n==0)break;
		for(int i=1;i<n;i++){
			int tgt,dir;
			cin>>tgt>>dir;
			if(dir==0){
				if(x[0].find(tgt)!=x[0].end()){
					set<int> ins;
					ins.insert(i);
					x.push_front(ins);
				}else{
					for(int j=1;j<x.size();j++){
						if(x[j].find(tgt)!=x[j].end()){
							x[j-1].insert(i);
							break;
						}
					}
				}
			}else if(dir==2){
				if(x[x.size()-1].find(tgt)!=x[x.size()-1].end()){
					set<int> ins;
					ins.insert(i);
					x.push_back(ins);
				}else{
					for(int j=0;j<x.size()-1;j++){
						if(x[j].find(tgt)!=x[j].end()){
							x[j+1].insert(i);
							break;
						}
					}
				}
			}else{
				for(int j=0;j<x.size();j++){
					if(x[j].find(tgt)!=x[j].end()){
						x[j].insert(i);
					}
				}
			}
			if(dir==1){
				if(y[0].find(tgt)!=y[0].end()){
					set<int> ins;
					ins.insert(i);
					y.push_front(ins);
				}else{
					for(int j=1;j<y.size();j++){
						if(y[j].find(tgt)!=y[j].end()){
							y[j-1].insert(i);
							break;
						}
					}
				}
			}else if(dir==3){
				if(y[y.size()-1].find(tgt)!=y[y.size()-1].end()){
					set<int> ins;
					ins.insert(i);
					y.push_back(ins);
				}else{
					for(int j=0;j<y.size()-1;j++){
						if(y[j].find(tgt)!=y[j].end()){
							y[j+1].insert(i);
							break;
						}
					}
				}
			}else{
				for(int j=0;j<y.size();j++){
					if(y[j].find(tgt)!=y[j].end()){
						y[j].insert(i);
					}
				}
			}
		}
		cout<<x.size()<<' '<<y.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1248
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  int b;
  int c;
  int d;
  int e;
  cin >> a >> b >> c >> d >> e;
  string f;
  cin >> f;
  int ans = 0;
  for(int i = 0;i < a;i++){
    if(i >= b){
      if(f.at(i) == f.at(i-b)){f.at(i) = 'z';
        continue;}
    }
    if(f.at(i) == 'r'){ans += e;}
    else if(f.at(i) == 's'){ans += c;}
    else{ans += d;}
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

int main(){
	int kosuu, max_num, time;
	int cur_num, cur_time;

	cin >> kosuu >> max_num >> time;

	cur_num = max_num;
	cur_time = time;

	while(cur_num<kosuu){
		cur_num += max_num;
		cur_time += time;
	}

	cout << cur_time << endl;
	return 0;
}

Measured memory_bytes: 3528
#include <stdio.h>
int main(void) {
	int a;
	scanf("%d",&a);
	int b;
	scanf("%d",&b);
	int c;
	scanf("%d",&c);
	int d;
	scanf("%d",&d);
	int p;
	scanf("%d",&p);
	int x,y;
	x=a*p;
	if(p<=c){
		y=b;
	}
	else{
		y=b+(p-c)*d;
	}
	if(x<y){
		printf("%d\n",x);
	}
	else{
		printf("%d\n",y);
	}
	return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
const int mod=1e9+7;
typedef long long ll;
const int N=2e5+5;
int main()
{
	// std::ios::sync_with_stdio(false);std::cin.tie(0);std::cout.tie(0);
	// freopen("a.in","r",stdin);
	// int T;scanf("%d",&T);while(T--){
	ll n,p;std::cin>>n>>p;
	std::string s;std::cin>>s;
	if(p==2||p==5)
	{
		ll ans=0;
		for(int i=0;i<n;i++) if((s[i]-'0')%p==0) ans+=i+1;
		printf("%lld\n",ans);
		return 0;
	}
	ll ans = 0;
	std::map<ll,ll>mp;
	ll cnt = 0;
	mp[0] = 1;
	ll bas = 1;
	for(int i = s.size() - 1; i >= 0; i--){
		ans = (ans + (s[i] - '0') * bas)%p;
		cnt += mp[ans]++;
		bas = bas * 10 % p;
	}
	std::cout<<cnt<<'\n';
	// }
	return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
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 <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    vint C(N);
    vvint A = make_v<int>(N, M);
    for (size_t i = 0; i < N; i++)
    {
        cin >> C[i];
        for (size_t j = 0; j < M; j++)
        {
            cin >> A[i][j];
        }
    }
    int ans = INT_MAX;
    for (int bit = 0; bit < (1 << N); bit++)
    {
        vint sum(M);
        int nedan = 0;
        for (int i = 0; i < N; i++)
        {

            if (bit & (1 << i))
            {
                nedan += C[i];
                for (int j = 0; j < M; j++)
                {
                    sum[j] += A[i][j];
                }
            }
        }
        bool ok = true;
        for (size_t i = 0; i < M; i++)
        {
            if (sum[i] < X)
                ok = false;
        }
        if (ok)
        {
            chmin(ans, nedan);
        }
    }
    if (ans != INT_MAX)
        cout << ans;
    else
        cout << -1;
    return 0;
}

Measured memory_bytes: 3652
n = int(input())
s = input()

min_ = n
A = [0] * n
for i in range(n):
  if s[i] == "W":
    A[i] = A[i-1] + 1
  else:
    A[i] = A[i-1]

val = (n-1 - (A[-1] - A[0]))
min_ = min(min_, val)
for i in range(1, n):
  val = A[i-1] + (n-1 - i - (A[-1] - A[i]))
  min_ = min(val, min_)
print(min_)


Measured memory_bytes: 44504
M,K = map(int,input().split())

if pow(2,M) <= K or (M,K) == (0,1) or (M,K) == (1,1):
    print(-1)
elif (M,K) == (0,0):
    print("0 0")
elif (M,K) == (1,0):
    print("0 0 1 1")
else:
    ans = [str(i) for i in range(pow(2,M)) if i != K]
    ans = ans + [str(K)] + ans[::-1] + [str(K)]
    print(" ".join(ans))

Measured memory_bytes: 17032
#include<iostream>
#include<string>

using namespace std;
int main(void){
  int N, sum = 0;
  int l[1000], r[1000];
  cin >> N;
  for(int i = 0; i < N; i++){
    cin >> l[i] >> r[i];
  }
  for(int i = 0; i < N; i++){
    sum += r[i] - l[i] + 1;
  }
  cout << sum << endl;
  return 0;
}

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

int main()
{
	int x,a;
	for(;;){
		cin>>x;
		if(x==0)
			break;
		for(a=0;x!=0;x/=10){
			a+=x%10;
			}
		cout<<a<<endl;
	}
	return 0;
}
*/

#include<iostream>
#include<string>

using namespace std;

int main()
{
	string ch;
	int ans = 0;

	while(1){
		cin>>ch;
		if(ch == "0")break;

		for(int i=0;i<ch.size();i++){
			ans +=ch[i]-'0';
		}
		cout<<ans<<endl;
		ans=0;
	}
	return 0;
}

Measured memory_bytes: 1188
#include "bits/stdc++.h"

typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define max3(x, y, z) max(x, max(y, z))
#define min3(x, y, z) min(x, min(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif

using namespace std;
int main() {
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;

	if (a == 0)cout << 1;
	if (b == 0)cout << 2;
	if (c == 0)cout << 3;
	if (d == 0)cout << 4;
	if (e == 0)cout << 5;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
rep(i,N) {
  cin >> list[i];
}
//配列(スタックとしても使える)
vector<int> list;
list.at(i)
vector<vector<int>> list(10, vector<int>(10));
//ソート クイックだからO(NlogN)
sort(all(list));
sort(all(list), greater<int>());

//配列の内容表示
dout << "====listの内容====\n";
for (int edp = 0; edp < N; edp++) dout << list[edp] << endl;
dout << "====ここまで====\n";


//配列の最小最大(Nは要素数)
*min_element(all(c))
*max_element(all(c))

//a[0]からa[N]を逆順にする(計算量はO(N))
reverse(all(a));
//listの末尾に要素を追加
list.push_back(10);
//listの末尾から要素を削除
list.pop_back();
//空ですか？
list.empty()



//キュー(待ち行列)
//定義
queue<int> a;
//追加
a.push(x);
//取る
a.pop();
//チェック
a.front()
//サイズ
a.size()
//空ですか
a.empty()



//優先度付きキュー※全部計算量がO(NlogN)あるので注意
// int 型の要素を持ち、最も小さい値を取り出す形の priority_queue を定義
priority_queue<int, vector<int>, greater<int>> Q1;
// double 型の要素を持ち、最も大きい値を取り出す形の priority_queueを定義
priority_queue<double, vector<double>, less<double>> Q2;
//追加
a.push(x);
//取る
a.pop();
//一番小さいの教えて下さい
a.top()
//サイズ
a.size()
//空ですか
a.empty()



//部分文字列
//添字3から5文字
s.substr(3,5)
//添字3から全部
s.substr(3)

//入れ替え
swap(a,b);



// int 型の番地に string 型の変数を記録する場合（2^31 要素の string型配列と同じような感じ）
map<int, string> mp;
for (auto itr =mp.begin(); itr != mp.end(); itr++) {
	//順番にマップを眺める。itr->firstでキー、itr->secondがバリュー
}

//ソート済みのaの中で初めてx以上になるインデックスを返す
lower_bound(all(a), x) - a

//next_permutation
do {
  //ここにパーテーションがくる
} while (next_permutation(s.begin(), s.end()));

//set
set<int> hoge;
hoge.insert(50);  //hogeに挿入。重複は無視される。
hoge.insert(20);  //内部は小さい順に並ぶ
hoge.erase(50);   //hogeから消し去る。
//40以上である最小の要素を指すイテレーターを返す。
//もちろんそんなものはないからEndが出力される
auto itr1 = Set.lower_bound(40);
if (itr1 == Set.end()) cout << "End" << endl;
else cout << (*itr1) << endl;

//pair
//たくさんつくる
vector<pair<int,string>> hoge(10);
//参照
hoge[0].first
sort(all(hoge), greater<pair<int, string>>());




*/


Measured memory_bytes: 3608
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<58;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int x;

int main(){
	cin>>x;
	cout<<x/30<<' ';
	x%=30;
	cout<<x*2<<endl;
}

Measured memory_bytes: 3112
#include<iostream>

const int MAX = 50001;
using namespace std;

int main(void){
	int i = 3;
	int n = 0;
	int ps[MAX];
	
	for(int i = 0; i < MAX; i++){
		ps[i] = 1;
	}
	for(int i = 2; i < MAX; i++){
		if( ps[i] ){
			for(int j = 2; i * j < MAX; j++){
				ps[i * j] = 0;
			}
		}
	}

	while( 1 ){
		int n;
		int cnt = 0;
		
		cin >> n;
		if( n == 0 ) break;

		if( n % 2 == 1 ){
			if( ps[n - 2] ) cnt++;
		}else{
			for(int i = 2; i <= n / 2; i++){
				if( ps[i] && ps[n - i] ) cnt++;
			}
		}

		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1064
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace AtCoder
{
	public class Program
	{
		static void Main()
		{
			var abk = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
			int a = abk[0];
			int b = abk[1];
			int k = abk[2];

			var set = new HashSet<int>();
			for (int i = 0; i < k; i++) {
				if (a + i <= b) {
					set.Add(a + i);
				}
			}

			for (int i = 0; i < k; i++) {
				if (b - i >= a) {
					set.Add(b - i);
				}
			}

			var ans = set.ToArray().OrderBy(x => x).ToArray();
			Console.WriteLine(string.Join(Environment.NewLine, ans));
		}
	}
}

Measured memory_bytes: 13652
#include <bits/stdc++.h>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define f first
#define s second
 
#define pb push_back
#define pp pop_back
#define mp make_pair
 
#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()
#define clr(a,v) memset(a, v, sizeof(a))
 
#define rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)
#define reflex ios_base::sync_with_stdio(false)
 
#define nl '\n'
#define ioi exit(0);
 
 
#define PI 3.14159265
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
 
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int N= (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
//const int mod = 1000000007;
const ll linf = (ll)1e18 + 7;
 
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1,1,2,2,1,-1,-2,-2};
const int ky[] = {2,2,1,-1,-2,-2,-1,1};
 
//const int mod = 998244353;
 
struct dsu{
	int parent[N];
	int cont;
	void make_set(int n){
		for(int i = 1; i <= n; i++)
			parent[i] = i;
		cont = n;
	}
	
	int find_set(int v){
		if(v == parent[v])
			return v;
		return find_set(parent[v]);
	}
	
	void union_sets(int a, int b){
		a = find_set(a);
		b = find_set(b);
		if(a != b){
			parent[b] = a;
			cont--;
		}
	}
};
 
 

bool v[4];
int main()
{
	clr(v,false);
	int a, b; cin>> a >> b;
	v[a] = true; v[b] = true;
	for(int i = 1; i <= 3; i++){
		if(v[i] == false){
			cout<<i;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#pragma region head
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define test(s) \
  if (!(s))     \
    cout << "Line " << __LINE__ << ": [" << #s << "] is false" << endl;
#define int long long
typedef long long ll;
#define double long double
typedef double ld;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;
const double PI = acos(-1.0);

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}
#pragma endregion

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

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

  vector<int> cnt(N + 1);
  repp(i, 1, N) {
    for (int j = i; j <= N; j += i) {
      cnt[j]++;
    }
  }

  int ans = 0;
  repp(i, 1, N) {
    ans += cnt[i] * i;
  }
  cout << ans << endl;
}

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

 int main() {
  int n;
  cin >> n;
  
  vector<long long> h(n);
  rep(i,n) {
   cin >> h.at(i);
   }
   
   vector<int> a;
   
  int count = 0;
   rep(i,n - 1) {
    if(h.at(i) >= h.at(i + 1)) {
     count++;
     }
     else {
     a.push_back(count);
     count = 0;
      }
     }
     a.push_back(count);
     
     int ans = 0;
     for(int i = 0; i < a.size(); i++) {
     ans = max(ans,a.at(i));
      } 
      cout << ans;
 }

Measured memory_bytes: 4468
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication
{
    class Program
    {
        static void Main()
        {
            new Solution().answer();
        }
    }
    class Solution
    {
        string N;
        int NL,NR,T;
        public Solution()
        {
            N = Console.ReadLine().ToString();
            NL = Convert.ToInt32(N.Substring(0, 1));
            NR = Convert.ToInt32(N.Substring(1, 1));
        }

        public void answer()
        {
            T = (NL / 9) + (NR / 9);
            if (T < 1)
            {
                Console.WriteLine("No");
            }
            else {
                Console.WriteLine("Yes");
            }
        }
    }
}


Measured memory_bytes: 11220
#include<iostream>
#include<algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX],n;
    
    cin >> n;
    
    for(int i=0;i<n;i++) cin >> R[i];
    
    int maxv = -2000000000;
    int minv = R[0];
    
    for(int i=1;i<n;i++){
        maxv=max(maxv,R[i]-minv);
        minv=min(minv,R[i]);
    }
    cout << maxv << endl;
    return 0;
    
    
}


Measured memory_bytes: 3880
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
#define mod 1000000007
#define MOD 1000000037
#define mod1 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define INF 2e9


int main()
{
    fastio;
    int a[5];
    for(int i=0;i<5;i++)
        cin >> a[i];
    for(int i=0;i<5;i++)
    {
        if(a[i]==0)
        {
            cout << i+1 << endl;
            break;
        }
    }
}

Measured memory_bytes: 3648
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input(): return sys.stdin.readline().rstrip()

def main():
    N,K,C=map(int,input().split())
    S=list(map(int,input().replace('o','1').replace('x','0')))
    T=[0]*(N+1)
    l0=[]
    l1=[]
    r0=-INF
    r1=-INF
    for i in range(N):
        if len(l0)<K and i>r0 and S[i]==1:
            l0.append(i)
            r0=i+C
        if len(l1)<K and i>r1 and S[N-1-i]==1:
            l1.append(N-1-i)
            r1=i+C
    l1.reverse()
    ans=[]
    for i in range(K):
        if l0[i]==l1[i]:
            ans.append(l0[i])
    ans.sort()
    for x in ans:
        print(x+1)
    
    

if __name__ == '__main__':
    main()


Measured memory_bytes: 73720
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
string s,t;
ll n,m;
string tmp;
string garb;
set<string> ans;
string getstr(ll strt)
{
        string ret = s;
        ll cnt = 0;
        for(ll i=0;i<m;i++)
        {
                ll ind = strt + i;
                if(ret[ind] == t[cnt] || ret[ind] == '?'){
                        ret[ind] = t[cnt];
                        cnt++;
                }else{
                        return garb;
                }
        }
        for(ll i=0;i<n;i++){
                if(ret[i] == '?'){
                        ret[i] = 'a';
                }
        }
        return ret;
}
int main()
{
        cin >> s >> t;
        garb = "$$$";
        n = s.length();
        m = t.length();
        if(m > n){
                cout << "UNRESTORABLE\n"; return 0;
        }
        for(ll i=0;i + m - 1 <= n - 1;i++)
        {
               // cout << "trap\n";
                tmp = getstr(i);
                if(tmp == garb){
                        continue;
                }
                ans.insert(tmp);
        }
        if(ans.size() == 0){
                cout << "UNRESTORABLE\n"; return 0;
        }else{
                cout << *ans.begin() << endl;
        }
        return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#define mop 1000000007
using namespace std;

int main() {
   

    string s,t;
    string par,mins;
    mins = "";
    for (int i=0;i<100;i++){
        mins += "z";
    }
    int flag = 0;
    cin >> s >> t;
    for (int i=0;i<s.length();i++){
        for (int j=0;j<t.length();j++){
            par = "";
            if(s[i] == t[j] or s[i] == '?'){
                for (int k=0;k<t.length();k++){
                    if((s[i-j+k] != t[k] and s[i-j+k] != '?') or i-j+k >= s.length()){
                        goto Next;
                    }
                }
                for (int k=0;k<s.length();k++){
                    if(i-j <= k and k < i-j+t.length()){
                        par += t[k-i+j];
                    }else if (s[k] == '?'){
                        par += "a";
                    }else{
                        par += s[k];
                    }
                }
                if(mins > par){
                    mins = par;
                    flag = 1;
                }
            }
            Next:
            ;
        }
    }
    if(flag == 0){
        cout << "UNRESTORABLE" << endl;
    }else{
        cout << mins << endl;
    }

}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	static final int BALL_NUM = 10;
	int[] ball;
	void run(){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0;i < n;i++){
			//????????????????????????
			ball = new int[BALL_NUM];
			for(int j = 0;j < BALL_NUM;j++)
				ball[j] = scan.nextInt();
			String result = solve()?"YES":"NO";
			System.out.println(result);
		}
	}
	boolean solve(){
		int b = 0,c = 0;
		for(int i = 0;i < BALL_NUM;i++){
			if(c >= ball[i])return false;
			if(b < ball[i]){
				b = ball[i];
			}else{
				c = ball[i];
			}
		}
		return true;
	}

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

Measured memory_bytes: 26300
import java.awt.geom.*;
import java.io.*;
import java.util.*;

public class Main{
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			long n = sc.nextInt();
			if(n == 0) break;
			int res = solve(n);
			System.out.println(res);
		}
	}

	private int solve(long n) {
		int count = 0;
		while(n != 1){
			if(n % 2 == 0){
				n = n / 2;
			}
			else{
				n = 3 * n + 1;
			}
			count++;
		}
		return count;
	}

	private void debug(Object... o) { System.out.println("debug = " + Arrays.deepToString(o)); }

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

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

int main() {
  int N,M;
  cin >> N >> M;
  M*=2;
  vector<int> ve(M);
  vector<int> vec(N+1);
  for (int i=0; i<M; i++) {
    cin >> ve.at(i);
  }
  for (int i=0; i<M; i++) {
    for (int j=1;j<=N; j++) {
      if (ve.at(i)==j) {
        vec.at(j)+=1;
        break;
      }
    }
  }
  for (int i=1; i<=N; i++) {
    cout << vec.at(i) << endl;
  }
}


Measured memory_bytes: 256
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define CLR(a) memset((a), 0 ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main() {
	LL N, H, W;
	cin >> N >> H >> W;

	/*VI A, B;
	A.resize(N);
	B.resize(N);*/

	int count = 0;
	LL A, B;
	REP(i, N) {
		//cin >> A[i] >> B[i];
		cin >> A >> B;
		if (H <= A && W <= B) {
			count++;
		}
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 256
h, _ = gets.chomp.split(' ').map(&:to_i)
map = []
10.times { map << gets.chomp.split(' ').map(&:to_i) }
10.times do |k|
  10.times do |i|
    10.times do |j|
      map[i][j] = [map[i][j], map[i][k] + map[k][j]].min
    end
  end
end
arr = []
h.times { arr << gets.chomp.split(' ').map(&:to_i) }
count = 0
arr.each do |i|
  i.each do |j|
    next if j == -1 || j == 1
    count += map[j][1]
  end
end
puts count

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

int main(){
    int N;
    cin >> N;
    int p[N+1];
    int q[N+1];
    rep2(i, 1, N+1){
        cin >> p[i];
        q[p[i]] = i;
    }
    long long L1[N+1], L2[N+1], R1[N+1], R2[N+1];
    multiset<int> s;
    s.insert(0);
    s.insert(0);
    s.insert(N+1);
    s.insert(N+1);
    for(int i = N; i > 0; i--){
        s.insert(q[i]);
        set<int>::iterator ite1, ite2;;
        ite1 = s.find(q[i]);
        ite2 = s.find(q[i]);
        ite1--;
        L1[i] = *ite1;
        ite2++;
        R1[i] = *ite2;
        ite1--;
        L2[i] = *ite1;
        ite2++;
        R2[i] = *ite2;
    }
    long long cnt[N+1];
    long long ans;
    rep2(i, 1, N+1){
        cnt[i] = (R2[i] - R1[i]) * (q[i] - L1[i]) + (L1[i] - L2[i]) * (R1[i] - q[i]);
        ans += i*cnt[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 9600
#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 L,R,d;
  cin >> L >> R >> d;
  int count = 0;
  for(int i = L; i <= R; i++){
    if(i % d == 0)count++;
  }
  cout << count << endl;
  
}

Measured memory_bytes: 3632
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))


INF = float("inf")
MOD = 10**9 + 7

class Combination(object):
    def __init__(self, N, mod=MOD):
        fac, finv, inv = [0] * (N + 1), [0] * (N + 1), [0] * (N + 1)
        fac[:2] = 1, 1
        finv[:2] = 1, 1
        inv[1] = 1
        for i in range(2, N + 1):
            fac[i] = fac[i - 1] * i % mod
            inv[i] = -inv[mod % i] * (mod // i) % mod
            finv[i] = finv[i - 1] * inv[i] % mod
        self.N = N
        self.MOD = mod
        self.fac = fac
        self.finv = finv
        self.inv = inv

    def __call__(self, n, k):
        return self.C(n, k)

    def C(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        fac = self.fac
        finv = self.finv
        mod = self.MOD
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

    def P(self, n, k):
        if n < k:
            return 0
        if n < 0 or k < 0:
            return 0
        return self.fac[n] * self.finv[n - k]


def main():
    N, M = MAP()
    ans = 0

    cmb = Combination(M)

    sign = +1
    for i in range(N+1):
        ans += sign * cmb.P(M-i, N-i) * cmb(N, i)
        ans %= MOD
        sign *= -1
    ans *= cmb.P(M, N)
    ans %= MOD
    print(ans)
    return


if __name__ == '__main__':
    main()


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

int main() {
    long long l,r,n,mod=998244353,k,maxi1,maxi2;
    cin>>n>>k;
    vector<long long>a;
    vector<pair<long long,long long> > pr(k);
    for(int i=0;i<k;i++) {
        cin>>pr[i].first>>pr[i].second;
        // for(int j=l;j<=r;j++) a.push_back(j);
    }
    // sort(a.begin(), a.end());
    vector<long long> dp(n+1,0);
    vector<long long> cumdp(n+1,0);
    dp[1]=1;
    cumdp[1]=1;
    for(int i=2;i<n+1;i++) {
       for(int j=0;j<k;j++) {
           maxi1 = i-pr[j].second-1;
           if(maxi1<0) maxi1 = 0;
            maxi2 = i-pr[j].first;
           if(maxi2<0) maxi2 = 0;
           dp[i] = ((dp[i] + cumdp[maxi2])%mod - cumdp[maxi1]+mod)%mod;
       }
    //    cout<<dp[i]<<endl;
       cumdp[i]=(cumdp[i-1]+dp[i])%mod;
    }
    cout<<dp[n]<<endl;
 
    return 0;
}

Measured memory_bytes: 6408
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
using namespace std;
const int N=200000,M=1000000500;
int i,j,n;
int a[N+5],now,sum,num,l,r,mid,top;
int z[N*100][2];
bool bz;
int read()
{
	int x=0;char s=getchar();
	while ((s<'0')||(s>'9')) s=getchar();
	while ((s>='0')&&(s<='9')) x=x*10+(s-'0'),s=getchar();
	return x;
}
bool dg(int x)
{
	num=0;now=0;bz=true;
	int i;
	top=0;
	fo(i,1,n)
	{
		if (a[i]<=now)
		{
			if (x==0) return false;
			bz=false;
			while (z[top][0]>a[i]) top--;
			if (z[top][0]<a[i]){top++;z[top][0]=a[i];z[top][1]=1;}
			else
			{
				while (top){
					if (z[top][1]<x)
					{
						z[top][1]++;
						bz=true;break;
					}
					if ((z[top][0]>1)&&(z[top][0]!=z[top-1][0]+1))
					{
						z[top][0]=z[top][0]-1;z[top][1]=1;
						bz=true;break;
					}
					top--;
				}
				if (!bz) return false;
			}
		}
		now=a[i];
		while (z[top][0]>now) top--;
	}
	return true;
}
int main()
{
	n=read();
	fo(i,1,n)a[i]=read();
	l=0;r=1000000;
	while (l<=r)
	{
		mid=(l+r)/2;
		if (dg(mid)){sum=mid;r=mid-1;}
		else l=mid+1;
	}
	printf("%d\n",sum+1);
	return 0;
}

Measured memory_bytes: 2376
#include <bits/stdc++.h>
#include<math.h>
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

int main() {
  int s;
  cin>>s; 
  int a=s/500*1000;
  int b=(s-s/500*500)/5*5;
  
    cout<<a+b<<endl;
  

}







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

#define rep(X,N) for(ll X = 0LL; X < (N); X++)
#define ALL(V) (V).begin(),(V).end()

using namespace std;
typedef long long ll;

const double PI = 3.1415926535897932384626;
const ll MODN = 1000000007;
const ll MODN2 = 998244353;
const double EPS = 1e-10;

int main(){

    int n;
    cin >> n;

    vector<ll> f(n + 1, 1);

    for(int i = 2; i <= n ; i++){
        for(int j = i; j < n + 1; j = j + i){
            f[j]++;
        }
    }

    ll ans = 0;

    for(ll i = 1; i <= n; i++){
        //cerr << i << " " << f[i] << endl;
        ans += i * f[i];
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 81392
x = int(input())

a = 0
b = 0

while True:
        
    for i in range(a+1):
        b = i
        s = -i
        
        if a**5 - b**5 == x:
            print(a,b)
            exit()
        
        if a**5 - s**5 == x:
            print(a,s)
            exit()
            
    a += 1

Measured memory_bytes: 9212
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ExplicitForAll #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE Unsafe #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE FlexibleContexts #-}

import Data.Bits
import Data.List
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as BSL
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IMS
import Data.IntSet (IntSet)
import qualified Data.IntSet as IS
import qualified Data.Sequence as Seq
import Data.Sequence (Seq)
import qualified Data.Array.IArray as A
import qualified Data.Array.MArray.Safe as A
import qualified Data.Array.MArray as A
import Data.Array (Array)
import Data.Array.Unboxed (UArray)
import Data.Array.IArray (IArray)
import Data.Array.MArray.Safe (MArray)
import Data.Array.IO.Safe (IOArray, IOUArray)
import Data.Array.ST.Safe (STArray, STUArray, runSTArray, runSTUArray)
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import Control.Monad
import Control.Monad.ST
-- import Control.Monad.ST.Safe
import Control.Applicative
import Data.Maybe
import Data.Tuple
import Data.Ord
import Control.Monad.State.Strict
import Data.Int
import System.IO
import Data.Function
import Control.Monad.Primitive
import qualified Data.Vector.Primitive.Mutable as VPM
import qualified Data.Vector.Generic.Mutable as VGM
import Data.STRef
import Data.IORef

main :: IO ()
main = do
  [n,q] <- map read . words <$> getLine :: IO [Int]
  as <- VU.unfoldrN n (BS.readInt . BS.dropWhile (==' ')) <$> BS.getLine
  let asum = VU.scanl' (+) 0 as
      aIntSum = VU.map fst $ VU.scanl' (\(!x,!y) a -> (y+a,x)) (0,0) as
  xs <- VU.unfoldrN q (BSL.readInt . BSL.dropWhile (<'!')) <$> BSL.getContents
  VU.forM_ xs $ \x ->
    print (query n as asum aIntSum x :: Int)

query n as asum aIntSum x
  = asum VU.! n - asum VU.! (n-divpt) + aIntSum VU.! (max 0 $ n-divpt*2)
  where
    -- How many entries >= x can takahashi take?
    divpt = (gone+1) `shiftR` 1
    -- How many cards are taken before all cards >= x are gone?
    gone = gone_binSearch 0 $ n+1
    gone_binSearch :: Int -> Int -> Int
    gone_binSearch !ok !ng -- at least ok cards are taken; ng cards are never.
      | ng - ok <= 1 = ok
      | as VU.! (n - (mid+1) `shiftR` 1) - x >= x - as VU.! (n - mid)
        = gone_binSearch mid ng
      | otherwise = gone_binSearch ok mid
      where
        mid = (ok + ng) `shiftR` 1


Measured memory_bytes: 7420
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define REP(i,n) for(int i=1;i<=(n);++i)
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
#define pb push_back

using ll = long long;
using namespace std;
using pint = pair<int,int>;
using pll = pair<ll,ll>;
const int INFint = 2e9+1;
const ll INFll = 2e18+1;
ll MOD=1e9+7;

ll gcd(ll a, ll b) { return __gcd(a,b); } //最大公約数
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; } //最大公倍数

// aのn乗をMODで割りながら計算する
ll modpow(ll a, ll n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % MOD;
    a = a * a % MOD;
    n >>= 1; // right shift
  }
  return res;
}

// MODを法としたaの逆元を計算する
ll modinv(ll a) {
  return modpow(a, MOD - 2);
}
vector<ll> a;
void dfs(ll i,int cnt){
  if (cnt >= 12) return;
  a.push_back(i); 
  dfs(i*10+i%10,cnt+1);
  if(i % 10 == 0){
    dfs(i*10 + 1,cnt+1);
  }else if(i % 10 == 9){
    dfs(i * 10 +8,cnt+1);
  }else{
    dfs(i*10 + i%10+1,cnt+1);
    dfs(i*10 + i%10-1,cnt+1);
  }
}

int main(){
  ll K;
  cin>>K;
  for(int i(1);i<10;i++){
    dfs(i,1);
  }
  sort(a.begin(),a.end());
  cout << a[K-1] << endl;
  return 0;
}



Measured memory_bytes: 10476
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    String[] S = sc.nextLine().split(" ");
    int N = Integer.parseInt(S[0]);
    int A = Integer.parseInt(S[1]);
    
    int[] num = new int[N];
    int max = A;
    for(int i = 0; i < N; i++){
      num[i] = Integer.parseInt(sc.next());
      max = max < num[i] ? num[i] : max;
    }
    
    int M = N*max;
    long[][][] dp = new long[N+1][N+1][M+1];
    for(int i = 0; i <= N; i++){
      dp[i][0][0] = 1;
    }
    
    for(int i = 1; i <= N; i++){
      for(int j = 1; j <= i; j++){
        for(int k = 0; k <= M; k++){
          int z = num[i-1];
          if(z > k){
            dp[i][j][k] = dp[i-1][j][k];
          }else{
            dp[i][j][k] = dp[i-1][j][k] + dp[i-1][j-1][k-z];
          }
        }
      }
    }
    
    long ans = 0;
    for(int i = 1; i <= N; i++){
      ans += dp[N][i][i*A];
    }
    System.out.println(ans);
  }
}

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

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

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

  string n;
  cin >> n;

  rep(i, 3) {
    if (n.at(i) == '1') {
      n.at(i) = '9';
    } else if (n.at(i) == '9') {
      n.at(i) = '1';
    }
  }
  cout << n << endl;
  return 0;
}


Measured memory_bytes: 256