akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;
int main () {

  int N,T,E,x[100],num=-1,a;

  cin >>N>>T>>E;
  
  for(int i=0 ; i < N ; i++){
    cin >>x[i];
    a=(T+E)%x[i];
    if( a <= 2*E ){
      num=i+1;
    }
  }
  
  cout <<num<<endl;
  
  return 0;
  
}

Measured memory_bytes: 1164
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int N = 2e5 + 5, MOD = 1e9 + 7;
int dist[N][3];
vector<int> adj[N];
int main(){

  memset(dist, -1 ,sizeof dist);

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

  for(int i = 0, u, v; i < m; i++){
    cin >> u >> v;
    adj[u].push_back(v);
//    adj[v].push_back(u);
  }

  int s, t;
  cin >> s >> t;

  queue<pair<int, int>> q;
  q.push(make_pair(s, 0));
  dist[s][0] = 0;
  while(q.size()){
    auto cur = q.front(); q.pop();
//    cout << cur.first << ' ' << cur.second << ' ' << dist[cur.first][cur.second] << '\n';
    for(auto v : adj[cur.first]){
      if(dist[v][(cur.second + 1)%3] == -1){
        dist[v][(cur.second + 1)%3] = dist[cur.first][cur.second] + 1;
        q.push(make_pair(v, (cur.second + 1) % 3));
      }
    }
  }

  if(dist[t][0] == -1)
    cout << -1 << '\n';
  else
    cout << dist[t][0] / 3 << '\n';


  return 0;
}


Measured memory_bytes: 10368
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------
ll N;

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

int main() {
  cin >> N;
  auto mp = prime_factor(N);
  ll ans = 0;
  for (auto e : mp) {
    ll v = e.second;
    int i = 0;
    while (v > i) {
      ++i;
      v -= i;
    }
    ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int> PI;

int n,m;
int b[15];
int p[15];
int to[2][15];	//完成系のビット列(2通りしかない！！)
int dp[1<<15];

queue<PI> que;
int bfs(){
	int i,x,tesu;
	PI now;
	
	x = 0;
	for( i = 0; i < n; i++ ){
		x += (1<<i)*b[i];
	}
	que.push( PI(x,0) );
	
	while(!que.empty() ){
		now = que.front();
		x = now.first;
		tesu = now.second;
		que.pop();
		
		if( dp[x] <= tesu )
			continue;
		dp[x] = tesu;
		//cout << x << " " << dp[x] << endl;
		//xの下位iビット目と下位i-1ビット目を交換
		for( i = 1; i < n; i++ ){
			int bi = (x>>i)%2;
			int bi_1 = (x>>(i-1))%2;
			int diff;
			if( bi == bi_1 )
				continue;
			else if( bi == 1 ){
				diff = ( ( 1<<(i-1) ) - (1<<i) );
			}
			else if( bi_1 == 1 ){
				diff =( -( 1<<(i-1) ) + (1<<i) );
			}
			que.push( PI( x + diff, tesu+1 ) );
		}
	}
	
	int t,u;
	t = 0;
	u = 0;
	for( i = 0; i < n; i++ ){
		t += to[0][i]<<i;
		u += to[1][i]<<i;
	}
	return min( dp[t], dp[u] );
}

int main(){
	int i,j;
	cin >> n >> m;
	
	for( i = 0; i < (1<<15); i++ )
		dp[i] = 1000000;
		
	for( i = 0; i < n; i++ )
		cin >> b[i];
	for( i = 0; i < m; i++ )
		cin >> p[i];
	
	int cor = 0;
	for( i = 0; i < m; i++ ){
		for( j = 0; j < p[i]; j++ ){
			to[0][cor] = i%2;
			to[1][cor++] = (i+1)%2;
		}
	}
	cout << bfs() << endl;
	return 0;
}

Measured memory_bytes: 1400
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] s = sc.next().toCharArray();
        int red = 0;
        int blue = 0;
        for(int i=0;i<s.length;i++){
            if(s[i]=='0'){
                red++;
            }else{
                blue++;
            }
        }
        System.out.println(2*Math.min(red,blue));
        sc.close();
    }
    
}

Measured memory_bytes: 26184
#include<bits/stdc++.h>
using namespace std;
const int INF=1001001001;
struct edge{
    int to,cost;
    edge(int a,int b):to(a),cost(b){}
};

int dp[1<<16][15];
int N,M;
vector<edge>G[15];

int solve(int s){
    fill_n(*dp,(1<<16)*15,INF);
    dp[0][s]=0;

    for(int i=0;i<(1<<N);i++){
        for(int j=0;j<N;j++){
            if(dp[i][j]==INF)continue;
            for(int k=0;k<G[j].size();k++){
                edge &e=G[j][k];
                if(i>>e.to&1)continue;
                dp[i|(1<<e.to)][e.to]=min(dp[i|(1<<e.to)][e.to],dp[i][j]+e.cost);
            }
        }
    }

    return dp[(1<<N)-1][s];
}

int main(){
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int a,b,c;cin>>a>>b>>c;
        G[a].push_back(edge(b,c));
    
    }

    int mi=INF;

    for(int i=0;i<N;i++)mi=min(mi,solve(i));

    if(mi==INF)cout<<-1<<endl;
    else cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 5040
n,k=gets.split.map &:to_i;s=gets.chomp.chars.map{|c|c==?A?0:1};f=i=0;((~s[i]+f)%2>0?s[i]=1-f :(s[n+i]=f^=1;i+=1);k-=1)while i<n&&k>0;puts k>0?['',[?B,?A][(~s[i]+f+k)%2]][n%2]+'BA'*(n/2):s[i,n].map{|c|[?B,?A][(~c+f)%2]}*''

Measured memory_bytes: 31868
N = int(input())

AC_counter = 0
WA_counter = 0
TLE_counter = 0
RE_counter = 0

for i in range(N):

    S = str(input())

    if S == 'AC':
        AC_counter += 1
    elif S == 'WA':
        WA_counter += 1
    elif S == 'TLE':
        TLE_counter += 1
    elif S == 'RE':
        RE_counter += 1


print('AC x ' + str(AC_counter))
print('WA x ' + str(WA_counter))
print('TLE x ' + str(TLE_counter))
print('RE x ' + str(RE_counter))


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

int main(){
  int x;
  cin >> x;
  int ans = 1;
  int j = 2;
  rep(i,x){
    j = i;
    while(i*j <= x){
      ans = max(ans,i*j);
      j *= i;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <cassert>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=(a%10/5)+(a%5), a/=10; return res;}

int main() {
  int n, k; cin>>n>>k;
  ll a[n]; for(int i=0;i<n;i++) cin>>a[i];
  for(int i=k;i<n;i++) {
    if (a[i-k] < a[i]) cout<<"Yes\n";
    else cout<<"No\n";
  }
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
int n_color[(int)1e5+1];
bool passed[(int)1e5+1];
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int, int> > V(N-1);
    vector<queue<int> > edges(N+1);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        V[i] = {a, b};
        edges[a].push(b);
        edges[b].push(a);
    }
    queue<int> current;
    current.push(1);
    int K = 0;
    passed[1] = true;
    map<long long, int> e_color;
    while (!current.empty()) {
        int a = current.front();
        int color = 1;
        while(!edges[a].empty()) {
            if (color == n_color[a]) color++;
            auto edge = edges[a].front();
            int b = edge;
            if (!passed[b]) {
                current.push(b);
                n_color[b] = color;
                e_color[(long long)min(a, b)*(N+1)+max(a, b)] = color;
                K = max(K, color);
                passed[b] = true;
                color++;
            }
            edges[a].pop();
        }
        current.pop();
    }
    printf("%d\n", K);
    for (auto v : V) {
        printf("%d\n", e_color[(long long)v.first*(N+1)+v.second]);
    }
    return 0;
}


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

using namespace std;

int main()
{
	string S;
	cin >> S;
	string before, after;
	for (int i = 0; i < 12; i++) {
		if (i < 4) {
			before.push_back(S.at(i));
		}
		else if (i >= 4) {
			after.push_back(S.at(i));
		}
		
	}
	cout << before << ' ' << after << endl;

    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.Integer.parseInt;

/**
 * Point Card
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int N, M;
		N = parseInt(line.substring(0, line.indexOf(' ')));
		M = parseInt(line.substring(line.indexOf(' ') + 1));

		int[] shortage = new int[M];

		for (int i = 0; i < M; i++) {
			line = br.readLine();
			int A = parseInt(line.substring(0, line.indexOf(' ')));
			shortage[i] = N > A ? N - A : 0;
		}

		Arrays.sort(shortage);

		int ans = 0;

		for (int i = 0; i < M - 1; i++) {
			ans += shortage[i];
		}

		System.out.println(ans);

	}
}

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

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

    vector<int> B(N - 1);
    rep(i, N - 1) {
        cin >> B[i];
    }
    reverse(B.begin(), B.end());

    int ans = 0;
    rep (i, N - 1) {
        if (i == 0){
            ans += B[i];
        } else {
            ans += min(B[i], B[i - 1]);
        }
    }
    ans += B[N - 2];

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


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

int main(){
  int n;
  int a[110];
  cin>>n;
  for (int i=0; i<n; ++i) cin>>a[i];
  
  bool flag = true;
  int counter = 0;
  
  for (int j=0; flag; j++){
    flag=false;
    for (int i=n-1; i>=j+1; i--){
      if (a[i]<a[i-1]){
        swap(a[i],a[i-1]);
        flag=true;
        counter++;
      }
    }
  }
  for (int i=0; i<n; ++i){
    if (i) cout << " ";
    cout<<a[i];
  }
  cout<<endl;
  cout<<counter<<endl;
}
      


Measured memory_bytes: 3092
#include<stdio.h>
#include<iostream>
#include<string>
#include<cassert>
#include<cmath>

using namespace std;

#define N 3
#define PN 9
#define LIMIT 100

static const int dx[4] = {0, -1, 0, 1};
static const int dy[4] = {1, 0, -1, 0};
static const char dir[4] = {'r', 'u', 'l', 'd'};

int MDT[PN][PN];

struct Puzzle{
  int f[PN], space, MD;
};

Puzzle state;
int limit;
int path[LIMIT];

int sumMD(Puzzle pzl){
  int sum = 0;
  for(int i=0 ; i<PN ; ++i){
    if(pzl.f[i] == PN) continue;
    sum += MDT[i][pzl.f[i]-1];
  }
  return sum;
}

bool isSolved(){
  for(int i=0 ; i<PN ; ++i) if(state.f[i] != i+1) return false;
  return true;
}

bool dfs(int depth, int prev){
  if(state.MD == 0) return true;
  if(depth + state.MD > limit) return false;

  int sx = state.space/N;
  int sy = state.space%N;
  Puzzle tmp;

  for(int r=0 ; r<4 ; ++r){
    int tx = sx + dx[r];
    int ty = sy + dy[r];
    if(tx<0 || ty<0|| tx>=N || ty >= N) continue;
    if(max(prev, r)-min(prev, r) == 2) continue;
    tmp = state;

    state.MD -= MDT[tx*N+ty][state.f[tx*N+ty]-1];
    state.MD += MDT[sx*N+sy][state.f[tx*N+ty]-1];
    swap(state.f[tx*N+ty], state.f[sx*N+sy]);
    state.space = tx*N+ty;
    if(dfs(depth+1, r)){
      path[depth] = r;
      return true;
    }
    state = tmp;
  }
  return false;
}

string iterative_deeping(Puzzle in){
  in.MD = sumMD(in);

  for(limit = in.MD ; limit<=LIMIT ; ++limit){
    state = in;
    if(dfs(0, -100)){
      string ans = "";
      for(int i=0 ; i<limit ; ++i) ans += dir[path[i]];
      return ans;
    }
  }
  return "unsolvable";
}

int main(){
  for(int i=0 ; i<PN ; ++i){
    for(int j=0 ; j<PN ; ++j){
      MDT[i][j] = abs(i/N - j/N) + abs(i%N - j%N);
    }
  }
  Puzzle in;
  for(int i=0 ; i<PN ; ++i){
    cin >> in.f[i];
    if(in.f[i] == 0){
      in.f[i] = PN;
      in.space = i;
    }
  }
  string ans = iterative_deeping(in);
  cout << ans.size() << endl;

  return 0;
}



Measured memory_bytes: 3216
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <iterator>
#include <cmath>
#include <set>
#include <deque> 
#include <string>


using namespace std;

long long a, b;

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

int main()
{
	scanf("%lld%lld", &a, &b);
	if (a < b) {
		long long temp = a;
		a = b;
		b = temp;
	}
	
	long long g = gcd(a, b);
	long long ans = a / g * b;
	
	printf("%lld\n", ans);
	
	

	return 0;
}


Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <algorithm>
#define N 200007
using namespace std;
typedef long long ll;

inline int rd() {
	int x = 0;
	bool f = 0;
	char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') f = 1;
		c = getchar();
	}
	while (isdigit(c)) {
		x = x * 10 + (c ^ 48);
		c = getchar();
	}
	return f ? -x : x;
}

int n, q, mnh, mnl, remh[N], reml[N];

int main() {
	n = rd();
	q = rd();
	ll b = 1ll * (n - 2) * (n - 2);
	mnh = mnl = n;
	for (int op, x; q; --q) {
		op = rd(); x = rd();
		if (op == 1) {
			if (x < mnl) {
				for (int i = x; i < mnl; ++i) reml[i] = mnh;
				mnl = x;
			}
			b -= reml[x] - 2;
		} else {
			if (x < mnh) {
				for (int i = x; i < mnh; ++i) remh[i] = mnl;
				mnh = x;
			}
			b -= remh[x] - 2;
		}
	}
	printf("%lld\n", b);
	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
 /////////////////////////////////////////////////////
const int V_MAX = 102;
bool adj[V_MAX][V_MAX];
int d[V_MAX] = {};

int main(){
	int n;SCD(n);
	FORq(i,1,n){
		int u,k; SCD2(u,k);
			FORq(j,1,k){
				int v; SCD(v);
				adj[u][v] = true;
			}
		
	}

	
	REP(i,V_MAX) {d[i] = -1;}
	
	queue<int> Q;
	Q.push(1);
	d[1] = 0;
	
	while(!Q.empty()){
		int now = Q.front(); 
		Q.pop();
		int v = d[now];
		FORq(i,1,n){
			if ((adj[now][i] == true) and (d[i] == -1)){
				d[i] = v+1;
				Q.push(i);
			}
		}
	}
	
	FORq(i,1,n){
		printf("%d %d\n",i,d[i]);
	}
	
	
}







Measured memory_bytes: 3220
N = int(input())
S = input()

cumdots = [0] * (N+1)

for i in range(N):
  cumdots[i+1] = cumdots[i] + (1 if S[i]=="." else 0)
  
#print(cumdots)

hands = N+1
for i in range(N):
  #i番目までをdot, i+1番目からsharpとする
  leftops = i - cumdots[i]
  rightops = cumdots[N] - cumdots[i+1]
  hands = min(hands, leftops + rightops)
  
print(hands)

Measured memory_bytes: 11144
import numpy as np
import math
import scipy as sp
import queue
import collections

MOD = 10 ** 9 + 7
INF = 10 ** 9

def main(kwargs):
    n = kwargs["n"]
    C = kwargs["C"]
    left = 0
    right = C.count("R")
    res = max([left, right])

    for i in range(n):
        if C[i] == "W":
            left += 1
        if C[i] == "R":
            right -= 1
        tmp = max([left, right])
        res = min(res, tmp)
    return res

if __name__ == "__main__":
    kwargs = {}

    cin = input().split()
    kwargs["n"] = [int(i) for i in cin][0]
    cin = input().split()[0]
    kwargs["C"] = [i for i in cin]

    cout = main(kwargs)
    print(cout)

Measured memory_bytes: 32760
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new
		// File("D:\\UserArea\\J0124567\\Downloads\\0536-input.txt"));

		while (scan.hasNext()) {

			int n = scan.nextInt();
			if (n == 0)
				break;
			int m = scan.nextInt();
			String s = scan.next();

			Str str = new Str(s);

			System.out.println(str.count(n));
		}

		scan.close();
		System.exit(0);
	}
}

class Str {
	String S;

	public Str(String s) {
		S = s;
	}

	public int count(int n) {
		int result = 0;
		int cur = 0;
		int i = 0;
		while (i <= S.length()) {
			if (i < S.length() - 2 && S.charAt(i) == 'I' && S.charAt(i + 1) == 'O' && S.charAt(i + 2) == 'I') {
				cur++;
				i += 2;
				continue;
			}
			if (cur >= n)
				result += (cur - n + 1);
			cur = 0;
			i++;
		}
		return result;
	}

}

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

#define getNum(i) scanf("%d", &(i))
#define MODULO 1000000007l
#define INF 10000000000000000l
#define FOR(i,j,k) for(int (i)=(j);(i)<=(k);(i)++)
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef long long ll;

int main() {

#ifdef CONTEST
    freopen("input.in", "r", stdin);
#endif
    IOS
    ll q, h, s, d, n;
    cin >> q >> h >> s >> d >> n;
    ll mnCst = min(4*q, min(2*h, s));
    if (d < 2*mnCst) {
        cout << (n/2)*d + (n%2)*mnCst << endl;
    } else {
        cout << n*mnCst << endl;
    }

}

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

struct Node{
  int key;
  Node *prev, *next;
};

Node *nil;

void init() {
  nil = (Node *)malloc(sizeof(Node));
  nil->next = nil;
  nil->prev = nil;
}

void insert_x(int x){
  // ノードの生成
  Node *node = (Node *)malloc(sizeof(Node));
  node->key = x;
  node->next = nil->next;
  nil->next = node;
  node->prev = nil;
  node->next->prev = node;
}

void delete_x(int x) {
  // key xの要素をリストから消去
  Node *node = nil;
  while (node->next != nil) {
    node = node->next;
    if (node->key == x) {
      // 繋ぎ変え
      node->prev->next = node->next;
      node->next->prev = node->prev;
      // メモリ解放
      free(node);
      break;
    }
  }
}

void deleteFirst() {
  // 先頭要素の削除
  Node *tmp = nil->next;
  nil->next->next->prev = nil;
  nil->next = nil->next->next;
  free(tmp);
}
void deleteLast() {
  Node *tmp = nil->prev;
  nil->prev->prev->next = nil;
  nil->prev = nil->prev->prev;
  free(tmp);
}

void printResult() {
  // nilから最後まで出力
  Node *node = nil;
  while (node->next != nil) {
    node = node->next;
    printf("%d", node->key);
    if (node->next == nil) printf("\n");
    else printf(" ");
  }
}


int main() {
  int n;
  scanf("%d", &n);
  init();
  for (int i=0; i<n; i++) {
    char c[20];
    int x;
    scanf("%s%d", c, &x);
    // commandの実行
    string s(c);
    if (s == "insert") insert_x(x);
    else if (s == "delete") delete_x(x);
    else if (s == "deleteFirst") deleteFirst();
    else if (s == "deleteLast") deleteLast();
  }
  // 結果の出力
  printResult();
}



Measured memory_bytes: 34424
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
work1=sorted([x[0] for x in l])
work2=sorted([x[1] for x in l])
if n%2==1 : 
    mmin=work1[n//2]
    mmax=work2[n//2]
else:
    mmin=work1[n//2]+work1[n//2-1]
    mmax=work2[n//2]+work2[n//2-1]
print(mmax-mmin+1)

Measured memory_bytes: 50956
//       Author: Mostafa Mounir Shehab
 
#include <bits/stdc++.h>
using namespace std;
 
#define PI  3.14159265  // PI = acos(-1)
#define EPS (1e-10)
#define endl "\n"
#define SZ(v) (int)(v.size())
typedef long long ll;
typedef long double ld;
//template <class Type>
 
 
void Fast(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL); cerr.tie(NULL);
}
 
inline int D(){
	int t;
	scanf("%d",&t);
	return t;
}
inline ll llD(){
	ll t;
	scanf("%lld",&t);
	return t;
}
 
 
ll MOD=1e9 + 7;
int OO=1e6;
const int N=1e5 + 1,M=1e3 + 1;
int arr[N];
int dp[N][M];
bool visit[N];

vector<int> primes;


vector<int> adj[N];

int n,m,k,cnt,SU,idx,len,MN,MX,T;
ll l,r,mid;
ll a,b,c,d;
vector<pair<int,pair<int,char>>> vec;
string str,t,ans;
bool flage;
deque<char> dq;


int main(){
	cin>>str;
	
	for(int i=0;i<SZ(str);++i)
		dq.push_back(str[i]);
	
	cin>>T;
	while(T--){
		int a,b;
		char c;
		cin>>a;
		if(a == 1)
			flage=!flage;
		if(a == 2){
			cin>>b>>c;

			if(!flage && b == 1)
				dq.push_front(c);
			else if(!flage && b == 2)
				dq.push_back(c);
			else if(flage && b == 1)
				dq.push_back(c);
			else if(flage && b == 2)
				dq.push_front(c);

			
		}

		
	}
	
	for(auto it=dq.begin();it != dq.end();it++)
		ans+=(*it);
	
	if(flage)
		reverse(ans.begin(),ans.end());
	
	cout<<ans<<endl;
	



}




Measured memory_bytes: 5508
a,b,m = map(int,input().split())

a_list =list(map(int,input().split()))
b_list =list(map(int,input().split()))
m_list =[list(map(int,input().split())) for _ in range(m)]


mini = min(a_list) + min(b_list)
for i in range(m):
  ai = m_list[i][0] - 1
  bi = m_list[i][1] - 1
  ci = m_list[i][2]

  temp = a_list[ai] + b_list[bi] - ci

  if temp < mini:
    mini = temp
print(mini)

Measured memory_bytes: 38564
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define CLR(x) memset(x,0,sizeof x)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 1000000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
//orz yht
using namespace std;
string i_s(int x){
	if(x==0)
	return "0";
	string ret="";
	while(x){
		ret=ret+(char)(x%10+'0');
		x/=10;
	}
	reverse(ret.begin(),ret.end());
	return ret;
}
string add(string a,string b){
	if(a=="")
	a="0";
	if(b=="")
	b="0";
	if(a.length()<b.length())
	swap(a,b);
	while(b.length()<a.length()){
		b='0'+b;
	}
	for(int i=0;i<a.length();i++){
		a[i]=a[i]+(b[i]-'0');
	}
	bool big=false;
	for(int i=a.length()-1;i>=0;i--){
		if(big){
			a[i]++;
		}
		big=false;
		if(a[i]>'9'){
			a[i]=a[i]-10;
			big=true;
		}
	}
	if(big)
	a='1'+a;
	return a;
}
string mul(string a,string b){
	vector<int> va,vb;
	if(a=="0" || b=="0")
	return "0";
	string ans;
	for(int i=0;i<a.length();i++){
		va.push_back(a[i]-'0');
	}
	for(int i=0;i<b.length();i++){
		vb.push_back(b[i]-'0');
	}
	reverse(va.begin(),va.end());
	reverse(vb.begin(),vb.end());
	vector<int> res;
	res.clear();
	res.resize(1005);
	for(int i=0;i<a.length();i++){
		for(int j=0;j<b.length();j++){
			res[i+j]+=(va[i]*vb[j]);
		}
	}
	for(int i=0;i<1005;i++){
		if(res[i]>9){
			res[i+1]+=(res[i]/10);
			res[i]%=10;
		}
	}
	for(int i=0;i<1005;i++){
		ans+=(res[i]+'0');
	}
	reverse(ans.begin(),ans.end());
	int k=0;
	while(ans[k]=='0'){
		k++;
	}
	ans=ans.substr(k);
	return ans;
}
bool is_prime(int n){
	if(n<2)
    return false;
    for(int i=2;i*i<=n;i++)
    if(n%i==0)
    return false;
    return true;
}
int n;
ll a[400];
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	cin>>n;
	int cnt=0;
	ll sol2;
	for(int sol=1;sol<=31;sol++){
		for(int i=2;i<=10;i++){
			sol2=pow(sol,i);
			a[cnt]=sol2;
			cnt++;
		}
	}
	sort(a,a+cnt);
	for(int i=0;i<=cnt;i++){
		//cout<<a[i]<<endl;
		if(a[i]>n){
			cout<<a[i-1];
			break;
		}
	}
	//system("pause");
	return 0;
}

Measured memory_bytes: 256
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
MOD = 1000000007
INF = float("inf")

sys.setrecursionlimit(1000000)

def main():
    N = I()
    L = sorted(LI())
    ans = 0

    for i in range(N):
        for j in range(i+1, N):
            a, b = L[i], L[j]
            # print(L[j+1:], abs(a - b), a+b, bisect_left(L[j+1:], abs(a - b)), bisect_left(L[j+1:], a + b))
            ans += bisect_left(L[j+1:], a + b) - bisect_left(L[j+1:], abs(a - b))

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 83504
/* Author rumoisen */
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <iomanip>
#include <numeric>
 
using namespace std;
 
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define INF (ll)1e18
#define MOD (ll)1e9 + 7
#define pb push_back

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> V;
typedef map<int, int> M;
using namespace std;
int main()
{
    int n,T,c[1100],t[1100];
    cin>>n>>T;
    for(int i=0;i<n;i++){
        cin>>c[i]>>t[i];
    }
    int sum=1e9;
    for(int i=0;i<n;i++){
        if(t[i]<=T&&c[i]<=sum)
        sum=c[i];
    }
    if(sum!=1e9)
    cout<<sum<<endl;
    else
    cout<<"TLE"<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    static public void main(String[] argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] t = new int[N+1];
        int[] x = new int[N+1];
        int[] y = new int[N+1];

        t[0] = 0; x[0] = 0; y[0] = 0;
        for(int i=1;i<=N;i++){
            t[i] = sc.nextInt();
            x[i] = sc.nextInt();
            y[i] = sc.nextInt();
        }

        for(int i=0;i<N;i++){
            int dist = Math.abs(x[i] - x[i+1]) + Math.abs(y[i] - y[i+1]);
            int intv = t[i+1] - t[i];

            if(dist > intv || (dist%2) != (intv%2)){
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
        return;
    }
}

Measured memory_bytes: 92976
#include<bits/stdc++.h>
using namespace std;
main(){
  long long a , b;
  cin >> a >> b;
  if(b - a >=2019){
    cout<<0;
    return 0;
  }
  a %=2019;
  b %=2019;
  if(a>b){
    b =a;
    a = b;
  }
  long long mn = 1e9+20;
  for(long long i = a ; i<b ; i++){
        for(long long j  = i+1 ; j<=b ; j++){
            mn = min(mn , (i*j) % 2019);
        }
  }
    cout <<mn;

}



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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in();
  int k = in();
  if(n%k == 0) {
    cout << 0 << endl;
    return 0;
  }
  int mod = n % k;
  cout << min(k-mod, n) << endl;
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdint.h>
#include <string.h>
#include <wchar.h>

int64_t sumList[200001];

int compare_int64(const void * a, const void * b) {
	int64_t sub = *((int64_t *)a) - *((int64_t *)b);
	return sub < 0 ? -1 : (sub == 0 ? 0 : 1);
}

int main(void) {
	uint32_t N;

	scanf("%"PRIu32"\n", &N);

	for (uint32_t idx = 0; idx < N + 1; idx++) {
		sumList[idx] = 0;
	}

	for (uint32_t idx = 0; idx < N; idx++) {
		int64_t tmp;
		scanf((idx != N - 1 ? "%"PRId64" " : "%"PRId64), &tmp);
		sumList[idx] = tmp + (idx != 0 ? sumList[idx - 1] : 0);
	}

	qsort(sumList, N + 1, sizeof(int64_t), compare_int64);

	int64_t prev = sumList[0];
	uint64_t sameSumCount = 1;
	uint64_t ans = 0;
	for (uint32_t idx = 1; idx < N + 1; idx++) {
		if (sumList[idx] == prev) {
			sameSumCount++;
		}
		if (sumList[idx] != prev || idx == N) {
			if (sameSumCount > 1) {
				ans += sameSumCount * (sameSumCount - 1) / 2;
			}

			prev = sumList[idx];
			sameSumCount = 1;
		}
	}

	printf("%"PRIu64, ans);

	return 0;
}


Measured memory_bytes: 3324
N = [int(x) for x in input()]
K = int(input())
dp = [[[0]*2 for j in range(K+1)] for i in range(len(N)+1)]
dp[0][0][1] = 1
for i in range(len(N)):
    dp[i+1][0][0] = 1
    if N[i] == 0:
        for k in range(1, K+1):
            dp[i+1][k][0] = dp[i][k][0]+dp[i][k-1][0]*9
            dp[i+1][k][1] = dp[i][k][1]
    else:
        for k in range(1, K+1):
            dp[i+1][k][0] = dp[i][k][0]+dp[i][k-1][0]*9+dp[i][k-1][1]*(N[i]-1)+dp[i][k][1]
        for k in range(K-1, -1, -1):
            if dp[i][k][1]:
                dp[i+1][k+1][1] = dp[i][k][1]
                break
print(dp[len(N)][K][0]+dp[len(N)][K][1])


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

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define F first
#define S second
#define INF 1 << 30

typedef pair<int, int> pi;
typedef pair<int, pi> pii;
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct P{
  int n, p;
  P(int n, int p):n(n),p(p){};
  bool operator<(const P& r)const{
    return p == r.p ? n > r.n : p < r.p;
  }
};

int m;

int solve(int *f, int n){
  int res = 0;
  //  printf("%d ", *f);
  if(*f == 1 || *f == 2){ res = n*2; (*f)--;}
  else if(*f == 3){ res = n*3; *f = 1;}
  else res = n;
  //  printf("%d\n", *f);
  return res;
}

int main(){
  while(scanf("%d", & m) && m){
    int a, b, sf, sum, n;
    priority_queue<P>q;
    rep(i, m){
      sf = sum = 0;
      scanf("%d", &n);
      rep(j, 9){
	//	printf("j: %d\n", j);
	//	printf("%d\n", sf);
	//	printf("%d\n", sum);
	scanf("%d", &a);
	sum += solve(&sf, a);
	if(a == 10){ sf += 2; continue;}


	scanf("%d", &b);
	sum += solve(&sf, b);
	if(a + b == 10){ sf += 1; continue;}

      }
      scanf("%d", &a);
      //      printf("sf:%d\n", sf);
      if(a == 10){
	sum += solve(&sf, a);
	sf += 2;
	//	printf("%d %d\n", sum, sf);
	scanf("%d", &a);
	sum += solve(&sf, a) - a;
	//	printf("%d %d\n", sum, sf);
	scanf("%d", &a);
	sum += a;
      }else{
	sum += solve(&sf, a);
	scanf("%d", &b);
	sum += solve(&sf, b);
	if(a + b == 10){
	  scanf("%d", &b);
	  sum += b;
	}
      }
      q.push(P(n, sum));
    }
    while(!q.empty()){
      P p = q.top(); q.pop();
      printf("%d %d\n", p.n, p.p);
    }
  }
  return 0;
}

Measured memory_bytes: 1192
use std::collections::HashMap;
use std::collections::HashSet;

use std::io::*;
use std::str::FromStr;
#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut ps = vec![vec![0, 0]; n];
    let mut sort_ps: Vec<HashMap<i64, Vec<usize>>> = vec![HashMap::new(); 2];
    for i in 0..n {
        let x = read::<i64>();
        let y = read::<i64>();
        ps[i] = vec![x, y];
        sort_ps[0].entry(x).or_insert(vec![]).push(i);
        sort_ps[1].entry(y).or_insert(vec![]).push(i);
    }
    let mut used = vec![false; n];
    let mut ans = 0;
    for i in 0..n {
        if used[i] {
            continue;
        }
        used[i] = true;
        let mut que = vec![(0, ps[i][0]), (1, ps[i][1])];
        let mut visit: HashSet<(usize, i64)> = HashSet::new();
        visit.insert((0, ps[i][0]));
        visit.insert((1, ps[i][1]));
        let mut cnts = vec![1, 1];
        while let Some((dir, pos)) = que.pop() {
            for &index in sort_ps[dir][&pos].iter() {
                used[index] = true;
                let ndir = dir ^ 1;
                let npos = ps[index][ndir];
                if visit.contains(&(ndir, npos)) {
                    continue;
                }
                // println!("{} {}", ndir, npos);
                visit.insert((ndir, npos));
                cnts[ndir] += 1;
                que.push((ndir, npos));
            }
        }
        // println!("{:?}", cnts);
        ans += cnts[0] * cnts[1];
    }
    ans -= n;
    println!("{}", ans);
}


Measured memory_bytes: 28248
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp {
	char name[100];
	int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
	Q[tail] = x;
	tail = (tail + 1) % LEN;
}

P dequeue() {
	P x = Q[head];
	head = (head + 1) % LEN;
	return x;
}

int min(int a, int b) { return a < b ? a : b; }

int main() {
	int elaps = 0, c;
	int i, q;
	P u;
	scanf("%d %d", &n, &q);

	for (i = 1; i <= n; i++) {
		scanf("%s", Q[i].name);
		scanf("%d", &Q[i].t);
	}

	head = 1; tail = n + 1;

	while (head != tail)
	{
		u = dequeue();
		c = min(q, u.t);
		u.t -= c;
		elaps += c;
		if (u.t > 0) enqueue(u);
		else
		{
			printf("%s %d\n", u.name, elaps);
		}
	}
	return 0;
}




Measured memory_bytes: 12012
# -*- coding: utf-8 -*-
import sys

a=input()
a_half=a[:len(a)//2:]
a_half_int=a[-(-len(a)//2)::]
a_half_int=a_half_int[::-1]
b=list(a_half)
c=list(a_half_int)
ans=0
for i in range(len(a)//2):
    if b[i] != c[i]:
        ans+=1

print(ans)

Measured memory_bytes: 3064
def geta(n=0)
  return $stdin.gets.to_i if n==0
  ar = []
  n.times do 
    ar << $stdin.gets.chomp.split
  end
  return ar.flatten(1) if n<=1
  return ar
end

def exchange(i,n)
  min = Float::INFINITY
  idx = 0
  i.step(n-1) do |j|
    if min > @ar[j]
      min = @ar[j]
      idx = j
    end
  end
  return 0 if idx==i
  @ar[i],@ar[idx] = @ar[idx],@ar[i]
  return 1
end

n = geta(0)
@ar = geta(1).map(&:to_i)

cnt = 0
0.step(n-1) do |i|
  cnt += exchange(i,n)
end

puts @ar.join(" ")
p cnt


Measured memory_bytes: 6884
#include<stdio.h>

int main(){
    int n , lim;
    scanf("%d %d",&n,&lim);
    int tall;
    int ans = 0;
    for(int i=0;i<n;i++){
        scanf("%d",&tall);
        if(tall>=lim){
            ans++;
        }
    }
    printf("%d",ans);
    return 0;    

}

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

int main() {
    string O, E;
    cin >> O;
    cin >> E;
    for(int i = 0; i < O.size(); i++) {
        cout << O[i];
        if(i < E.size()) {
            cout << E[i];
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <map>
#include <numeric>

using namespace std;

int main() {
  int X,Y,Z,K;
  cin>>X>>Y>>Z>>K;
  vector<long long>a(X+1),b(Y+1),c(Z+1);
  for(int i=0;i<X;i++)cin>>a[i];
  for(int i=0;i<Y;i++)cin>>b[i];
  for(int i=0;i<Z;i++)cin>>c[i];
  a[X]=-10000000000;
  b[Y]=-10000000000;
  c[Z]=-10000000000;
  sort(a.rbegin(),a.rend());
  sort(b.rbegin(),b.rend());
  sort(c.rbegin(),c.rend());

  long long max=a[0]+b[0]+c[0];
  cout<<max<<endl;
  vector<vector<int> >comb;
  vector<int> tmp(4,0);
  comb.push_back(tmp);

  for(int i=0;i<K-1;i++){
    vector<int> next(4,0);
    long long sum=0;
    for(auto& e : comb){
      int x=e[0],y=e[1],z=e[2],tmp=e[3];
      if(tmp==7)continue;
      if(tmp%2==0){
        if(sum<a[x+1]+b[y]+c[z]){
          sum=a[x+1]+b[y]+c[z];
          next[0]=x+1;
          next[1]=y;
          next[2]=z;
        }
      }
      if(tmp%4<=1){
        if(sum<a[x]+b[y+1]+c[z]){
          sum=a[x]+b[y+1]+c[z];
          next[0]=x;
          next[1]=y+1;
          next[2]=z;
        }
      }
      if(tmp<=3){
        if(sum<a[x]+b[y]+c[z+1]){
          sum=a[x]+b[y]+c[z+1];
          next[0]=x;
          next[1]=y;
          next[2]=z+1;
        }
      }
    }
    comb.push_back(next);
    for(auto& e : comb){
      int x=e[0],y=e[1],z=e[2];
      if(next[0]-1==x && next[1]==y && next[2]==z){
        if(e[3]%2==0)e[3]+=1;
      }
      if(next[0]==x && next[1]-1==y && next[2]==z){
        if(e[3]%4<=1)e[3]+=2;
      }
      if(next[0]==x && next[1]==y && next[2]-1==z){
        if(e[3]<=3)e[3]+=4;
      }
    }
    cout<<sum<<endl;
  }
}

Measured memory_bytes: 512
import java.util.Scanner;
import java.util.Formatter;
public class Main
{
	public static void main(String args[])
	{
		Scanner inp = new Scanner(System.in);
		int a, b;
		char op;
		while(true)
		{
			a = inp.nextInt();
			op = inp.next().charAt(0);
			b = inp.nextInt();
			if(op == '?')
				break;
			else {
				if(op == '+')
					System.out.println(a+b);
				if(op == '*')
					System.out.println(a*b);
				if(op == '/')
					System.out.println(a/b);
				if(op == '-')
					System.out.println(a-b);
			}
		}
	}
}

Measured memory_bytes: 26388
#include<bits/stdc++.h>
#define N 1000+10
#define ll long long int

using namespace std;
int main(){
	int h, w, current, last;
	ll table[2][N];
	string map;

	cin >> h >> w;

	//initial conditions
	for(int i=0;i<=w;i++){ table[0][i] = 0; table[1][i] = 0;}
	table[0][1] = 1LL;
	
	for(int i=1;i<=h;i++){
		current = i%2;
		last = (i+1)%2;
		cin >> map;
		for(int j = 1;j<=w;j++){
			table[current][j] = 0;	
			if(map[j-1]!='#'){
				table[current][j] = (table[last][j]+table[current][j-1])%((long long) 1e9+7);
			}
		}
	}

	cout << table[h%2][w] << '\n';
	return 0;
}

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

int main() {
  //宣言
  int N, M;
  vector<string> S, T;
  int count, ans = 0;
  
  
  //入力
  cin >> N;
  S = vector<string>(N);
  for(int i=0;i<N;i++){
  cin >> S.at(i);
  }
  cin >> M;
  T = vector<string>(M);
  for(int i=0;i<M;i++){
  cin >> T.at(i);
  }
  
  //処理
  for(int i=0;i<N;i++){
    //cout << I << endl;
    count = 0;
    for(int j=0;j<N;j++){
      if(S.at(i)==S.at(j))count++;
    }
    for(int j=0;j<M;j++){
      if(S.at(i)==T.at(j))count--;
    }
    ans = max(ans,count);
  }
  
  
  //出力
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
using ll = long long;

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

    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];

    ll sum = 0;
    for (int i = 0; i < n; ++i) sum += a[i];

    string ans = "No";
    if (h <= sum) ans = "Yes";

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int n,i,j,r,a[100100];
bool w;
int main() {
  scanf("%d",&n);
  for (i=0; i<n; i++) scanf("%d",&a[i]);
  for (i=0; i<n; i=j) {
    for (j=i; j<n && a[j]==a[i]; j++);
    i=j-1; r++;
    if (i+1==n) break;
    w=(a[i+1]>=a[i]);
    for (j=i+2; j<n && ((w && a[j]>=a[j-1]) || (!w && a[j]<=a[j-1])); j++);
  }
  printf("%d\n",r);
  return 0;
}



Measured memory_bytes: 640
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

fn main() {
    input! {
        n: chars,
    }

    if n.iter().filter(|&x| *x == '7').count() > 0 {
        print!("Yes");
    } else {
        print!("No");
    }
}


Measured memory_bytes: 2036
import fractions

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

left = [0]*(N+1)
right = [0]*(N+1)
for i in range(N):
    left[i+1] = (fractions.gcd(left[i],A[i]))
    right[N-i-1] = fractions.gcd(right[N-i],A[N-1-i])

ans = 0
for i in range(N):
    ans = max(ans,fractions.gcd(left[i],right[i+1]))
print(ans)

Measured memory_bytes: 16124
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;

const ll MOD = 1000000007;
const long double EPS = 1e-10;
const int dyx[4][2] = {
    { 0, 1}, {-1, 0}, {0,-1}, {1, 0}
};

int main() {
    std::ios::sync_with_stdio(0); cin.tie(0);
    int a[3], n, ans = 0;
    cin >> a[0] >> a[1] >> a[2] >> n;

    for(int i=0;i<=n;++i){
        for(int j=0;j<=n;++j) {
            int rest = (n - a[0]*i - a[1]*j);
            if(rest < 0 || rest % a[2]) continue;
            ++ans;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a

 #最小公倍数
def lcm(a,b):
    return a*b//gcd(a,b)

N=int(input())
A=list(map(int,input().split()))
a_lcm=A[0]
Mod=10**9+7

for i in range(1,N):
    a_lcm=lcm(a_lcm,A[i])

a_lcm%=Mod

result=0
for i in range(N):
    result+=a_lcm*pow(A[i],Mod-2,Mod)
print(result%1000000007)

Measured memory_bytes: 4084
N,K=map(int, input().split())
A=list(map(int, input().split()))
D,E=[],[]
zcnt,scnt,fcnt=0,0,0
for i in A:
  if i==0:
    zcnt+=1
    D.append(0)
  elif i>0:
    D.append(i)
    scnt+=1
  else:
    E.append(i)
    fcnt+=1
mod=10**9+7
ans=1
if K==N:
  for i in A:
    ans*=i
    ans%=mod
  print(ans)
  exit()
#マイナスを奇数個絶対かける→確実に答えはマイナス
if K%2==1 and max(A)<0:
  A=sorted(A)[::-1]
  for i in range(K):
    ans*=A[i]
    ans%=mod
  print(ans)
  exit()
#絶対0をかけなきゃいけない
if K>scnt+fcnt:
  print(0)
  exit()
D,E=sorted(D)[::-1],sorted(E)
#print(D,E)
ans=1
cnt=0
a,b=0,0
while K-cnt>1:
  if a+1<=len(D)-1 and b+1<=len(E)-1:
    d,e=D[a]*D[a+1],E[b]*E[b+1]
    if d>e:
      ans*=D[a]
      a+=1
      cnt+=1
      ans%=mod
    else:
      ans*=e
      b+=2    
      ans%=mod
      cnt+=2
  elif a+1<=len(D)-1:
    d=D[a]*D[a+1]
    ans*=D[a]
    a+=1
    cnt+=1
    ans%=mod
  elif b+1<=len(E)-1:
    e=E[b]*E[b+1]
    ans*=e
    b+=2
    cnt+=2
    ans%=mod

if K-cnt==1:
  Z=[]
  if a!=scnt:
    Z.append(D[a])
  if b!=fcnt:
    Z.append(E[-1])
  if 0 in A:
    Z.append(0)
  ans*=max(Z)
  ans%=mod
print(ans)


Measured memory_bytes: 31868