akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve(n,m,q):
    if q == 0:
        if n == 1:
            print("0"*m)
        else:
            print("?"*m)
        return
    ans = ["?"]*m
    f = defaultdict(lambda : "?")
    for i in range(10):
        f[i] = str(i)
    alp = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    for i in range(len(alp)):
        f[i+10] = alp[i]
    s = [[int(x,2) for x in input().split()] for i in range(q)]
    for i in range(q-1):
        s[i+1][0] ^= s[i][0]
    M = (1<<m)-1
    for i in range(n):
        bi = 1<<(n-i-1)
        k = M
        for a,b in s:
            if not a&bi:
                k &= (M-b)
            else:
                k &= b
        for j in range(m):
            if k&(1<<j):
                if ans[-1-j] != "?":
                    ans[-1-j] = 37
                else:
                    ans[-1-j] = i
    ans = [f[i] for i in ans]
    print(*ans,sep = "")
    return

#Solve
if __name__ == "__main__":
    while 1:
        n,m,q = LI()
        if n == 0:
            break
        solve(n,m,q)



Measured memory_bytes: 8656
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.cin();
    let xs: Vec<usize> = sc.vec(n);

    let mut sum: i128 = 0;
    let mut bucket = vec![0i128; 100005];
    for &x in xs.iter() {
        bucket[x] += 1;
        sum += x as i128;
    }

    let q: usize = sc.cin();
    for _ in 0..q {
        let b: usize = sc.cin();
        let c: usize = sc.cin();
        let mount = bucket[b];
        sum -= mount * b as i128;
        bucket[c] += mount;
        bucket[b] = 0;
        sum += mount * c as i128;
        put!(sum);
    }
}

use std::collections::VecDeque;
use std::io::{self, Write};
use std::str::FromStr;

struct Scanner {
    stdin: io::Stdin,
    buffer: VecDeque<String>,
}
impl Scanner {
    fn new() -> Self {
        Scanner {
            stdin: io::stdin(),
            buffer: VecDeque::new(),
        }
    }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.is_empty() {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> {
        self.cin::<String>().chars().collect()
    }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.cin()).collect()
    }
}


Measured memory_bytes: 8952
#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

int dx[4] = {1,0,-1,0};
int dy[4] = {0,-1,0,1};

int ret;
int xg, yg;

void dfs(int f[][22], int xx, int yy, int depth){
    int next;
    int pos;
    //cerr << xx << " " << yy << " " << depth << endl;
    //cin >> pos;
    if(depth == 10) return;

    for(int i=0;i<4;i++){ //for 4 directions
        for(int j=1;;j++){
            next = f[xx+dx[i]*j][yy+dy[i]*j];
            if(next == -1){
                break;
            }else if(next == 0){
                //do nothing
            }else if(next == 1){
                if(j != 1){
                    //break a block
                    f[xx+dx[i]*j][yy+dy[i]*j] = 0;
                    dfs(f, xx+dx[i]*(j-1), yy+dy[i]*(j-1),depth+1);
                    //regenerate block
                    f[xx+dx[i]*j][yy+dy[i]*j] = 1;
                    break;
                }else{
                    break;
                }
            }else if(next == 3){
                ret = min(ret, depth+1);
                break;
            }
        }
    }
}

int main(){
    int w,h;
    int f[22][22];
    int xs,ys;
    while(cin >> w >> h){
        if((w|h) == 0) break;
        ret = 11;
        memset(f, -1, sizeof(f));
        for(int i=1;i<=h;i++){
            for(int j=1;j<=w;j++){
                cin >> f[j][i];
                if(f[j][i] == 2){
                    xs = j;
                    ys = i;
                    f[j][i] = 0;
                }
                if(f[j][i] == 3){
                    xg = j;
                    yg = i;
                }
            }
        }

        dfs(f,xs,ys,0);
        if(ret == 11){
            cout << -1 << endl;
        }else{
            cout << ret << endl;
        }
    }
}

Measured memory_bytes: 868
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,D;
	scan(N>>D);
	int ans=N/(2*D+1)+(N%(2*D+1)!=0);
	prin(ans);
	return 0;
}


Measured memory_bytes: 256
N=int(input())
a=[int(input())-1 for i in range(N)]

#押したボタンリスト
d=[0]*N
d[0]=1
ans=0
light_sw = 0
while 1:
  light_sw = a[light_sw]
  if d[light_sw]==0:
    d[light_sw]=1
  else:
    print(-1)
    exit()
  ans+=1
  if light_sw == 1:
    print(ans)
    exit()


Measured memory_bytes: 7852
#include <bits/stdc++.h>
int main()
{
  int N,M;std::cin>>N>>M;
  std::vector<std::vector<int>> W(M+1);
  for (int i=0;i<N;i++){
    int A,B;std::cin>>A>>B;
    if(A<=M){W[A].push_back(B);}
  }
  std::priority_queue<int> Q;
  int ans =0;
  for(int i=0;i<=M;i++){
    for(const int b:W[i]){Q.push(b);}
    if(not Q.empty()){ans+=Q.top(),Q.pop();}
  }
  std::cout<<ans<<std::endl;
}


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

int main()
{
  	map<int,int> visited;
  	int n=0;
  	cin>>n;
  	vector<int> lights(n+4,0);
  	for(int i=0 ; i<n ; ++i)
    {
    	cin>>lights[i];
    	--lights[i];
    }
  	int ans=0;
    queue<int> q;
  	q.push(0);
  	while(!q.empty())
    {   
        int front=q.front();
      	if(visited[front])
        break;
      	visited[front]=1;
      	if(front==1)
       	break;
      	++ans;
      	q.push(lights[front]);
    	q.pop();
    }
  	if(visited[1])
  	cout<<ans<<endl;
  	else
    cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 5376
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	static long rec(int i,long[]dp,long[] h) {
		
		//DPの値が更新されていたら、そのままリターン
		if(dp[i] < Long.MAX_VALUE) {
			return dp[i];
		}
		
		if(i == 0) {
			return 0;
		}
		
		// i-1,i-2 それぞれ試す
		long res = Long.MAX_VALUE;
		
		res = Math.min(rec(i-1,dp,h)+Math.abs(h[i]-h[i-1]),res);
		if(i>1) res = Math.min(rec(i-2,dp,h)+Math.abs(h[i]-h[i-2]),res); 
				
		return dp[i] = res;
		
	}

	public static void main(String[] args) {
		Scanner stdIn  = new Scanner(System.in);
		
		int n = stdIn.nextInt();
		long[] h = new long[100010];
		long[] dp = new long[100010];
		
		for(int i = 0; i < n; i++) {
			h[i] = stdIn.nextLong();
		}
		
		Arrays.fill(dp,Long.MAX_VALUE);
		
		
		System.out.println(rec(n-1,dp,h));
		
		
	}

}


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

#define crap ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define CN cout<<"No\n"
#define CY cout<<"Yes\n"

using namespace std;
using ll = long long;
void solve()
{
    int d,t,x; cin>>d>>t>>x;
    if(t*x>=d) CY;
    else CN;
}
int main()
{
    crap;
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r", stdin) ;
        freopen("output.txt","w", stdout) ;
        freopen("error.txt","w", stderr) ;
    #endif
    int t;t=1;
 //  cin>>t;
    while(t--)
        {solve();}
    return 0;
}

Measured memory_bytes: 3636
#include <stdio.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 1000000000000000000
#define MAX_INT 9223372036854775807

void debug(char * string, long long int target) {
  printf("%s", string);
  printf("%lld", target);
  printf("%c", '\n');
}

int main() {
  int N;
  scanf("%d", &N);

  long long output = 1;
  long long A;
  short isOverflow = 0;
  rep(i, N) {
    scanf("%lld", &A);
    if (A == 0) {
      output = 0;
      break;
    }
    /* printf("output: %lld\n", output); */
    /* printf("MAX / output: %.5f\n", (double)MAX / (double)output); */
    /* printf("A: %lld\n\n", A); */
    // 1e18を今までの積のトータルで割った値が次の入力値以下であれば続投
    if (MAX / output < A) {
      output = 1; // overflow させるのも嫌だしなんとなく1にしておく。
      // break; // break してはいけない。あくまで 64bit 整数の範囲を超えないかどうかのチェックしただけ
      // 全ての積の結果をみないと、後で0が来るパターンに対応できない。
      isOverflow = 1;
    }
    output *= A;
  }
  if (output == 0) {
  } else {
    if (isOverflow == 1) {
      output = -1;
    }
  }

  printf("%lld\n", output);
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define INF 2000000000
typedef long long int ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
#define getbit(n,i) (((n)&(1<<(i)))!=0)
#define setbit0(n,i) ((n)&(~(1<<(i))))
#define setbit1(n,i) ((n)(1<<(i)))
#define togglebit(n,i) ((n)^(1<<(i)))
#define lastone(n) ((n)&(-(n)))
#define read freopen("debug\\in.txt","r",stdin)
#define write freopen("debug\\out.txt","w",stdout)
#define fi first
#define se second
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("d",&a,&b)
#define PI (acos(-1))
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod (1000000007)
#define asz 500005
#define t int t;scanf("%d",&t);for(int v=1;v<=t;v++)
#define loop_arr(i,a,b) for(int i=a;i<b;i++)
#define loop_norm(i,a,b) for(int i=a;i<=b;i++)
#define minheap priority_queue<int,vector<int>,greater<int> >
#define maaheap priority_queue<int>
#define pb push_back
#define newl "\n"
ll BIGMOD ( ll a, ll p, ll m )
{
    ll result = 1;
    ll x = a;

    while ( p )
    {
        if ( p & 1 ) //p is odd
        {
            result = ( result * x ) % m;
        }
        x = ( x * x ) % m;
        p = p >> 1;
    }

    return result;
}

bool isPrime(int n)
{
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;

    for (int i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;

    return true;
}

void SieveOfEratosthenes(int n)
{
    bool prime[n+1];
    memset(prime, true, sizeof(prime));

    for (int p=2; p*p<=n; p++)
    {

        if (prime[p] == true)
        {
            for (int i=p*p; i<=n; i += p)
                prime[i] = false;
        }
    }
}
ll arr[105][2];
ll mem[105][100005];
int n,w;
ll knapsack(int i,int W )
{
    if(i==n)
    {
       return 0;
    }
    if(W==0) return 0;
    if(mem[i][W]!=-1) return mem[i][W];
    ll res1=-1,res2=-1;
   if(W>=arr[i][0])  res1=arr[i][1]+knapsack(i+1,W-arr[i][0]);
     res2=knapsack(i+1,W);
     return mem[i][W]=max(res1,res2);

}

int main()
{
   //fastread;
   //int n;
   cin>>n>>w;
   loop_arr(i,0,n)
   {
       cin>>arr[i][0]>>arr[i][1];
   }
   for(int i=0;i<n;i++)
   {
       for(int j=0;j<=w;j++) mem[i][j]=-1;
   }
   ll res=knapsack(0,w);
   cout<<res<<newl;

  return 0;
}


Measured memory_bytes: 80128
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String x= "abcdefghijklmnopqrstuvwxyz";
        int[] cnt=new int[26];
        
        while(sc.hasNext()){
            String s=sc.nextLine();
            s=s.toLowerCase();
            
            for(int i=0;i<x.length();i++){
                for(int j=0;j<s.length();j++){
                  if(x.charAt(i)==(s.charAt(j))){
                     cnt[i]++;
                }
            }
          }
        }
        for(int i=0;i<x.length();i++)
            System.out.println(x.charAt(i)+" : "+cnt[i]);
        sc.close();          
    }
}


Measured memory_bytes: 26260
/*
Problem

Category
全探索：順列全探索

URL:
https://atcoder.jp/contests/abc150/tasks/abc150_c

考察:


Date: 2020/04/11
*/

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long

/* ==== declarations ====== */
// functions
void solve();
void getInput();

// global variables
int N;
vector<int> P, Q;


/* ======================== */

signed main(){
    getInput();
    solve();
    return 0;
}

void getInput() {
    cin>>N;
    P = vector<int>(N, 0);
    Q = vector<int>(N, 0);
    for(int i=0; i<N; ++i) {
        cin>>P[i];
    }
    for(int i=0; i<N; ++i) {
        cin>>Q[i];
    }
    
}


void solve() {
    vector<int> indices; for(int i=0; i<N; ++i) indices.push_back(i+1);
    int cnt=0;
    int p, q;
    do {
        if (indices == P) {
            p = cnt;
        }
        if (indices == Q) {
            q = cnt;
        }
        cnt++;
    } while(next_permutation(indices.begin(), indices.end()));

    cout<<abs(p-q)<<endl;
    
}






Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <climits>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <string.h>
#include <iomanip>
#include <ctype.h>

#define ll          long long int
#define ull         unsigned long long int
#define pb          push_back
#define pii         pair<int,int>
#define F           first
#define S           second
#define vi          vector<int>
#define vli          vector<ll>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define M_PI        3.14159265358979323846
#define mp          make_pair
#define sz(x)       (int)x.size()
//#define hell        1000000007
#define matrix      vector<vector<ll>>
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define eps 0.000000001
#define all(a)      (a).begin(),(a).end()
const long long INF = (long long) 1e7+1;
const long long mod = (long long) 998244353;
const long long hell = (long long) 1000000007;

using namespace std;
#include <stdio.h>

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y%2) res=(x*res);
    x=(x*x);
    y=y/2;
  }
  return res;
}

ll modinv(ll x){
  return power(x,hell-2);
}

void solve();


void fastIO() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}

int main(){
   fastIO();
    solve();
}
//void sieve();
ll pw(ll k,ll x);
ll gcd(ll x,ll y);
/*
void sieve(){

  for(int i=2;i<=500000;i++){
    if(prime[i]==true){
      for(int j=i*i;j<=500000;j+=i)
      prime[j]=false;
    }
  }

}*/


bool comp(pair<int,int> a,pair<int,int> b){
  if(a.F!=b.F)
  return (a.F<b.F);
  else
  return a.S<b.S;
}

void solve(){
  int test;
  //cin>>test;
  test=1;
  while(test--){
    ll a,b;
    cin>>a>>b;
    ll g=gcd(a,b);
    ll ans=(a*b)/g;
    cout<<ans;
  }
}




/*bool issafe(int x,int y){
  return (x>=0 && y>=0 && x<n && y<m);
}*/

///Before submit=>
///    *check for integer overflow,array bounds
///    *check for n=1

ll gcd(ll x,ll y){
  if(x==0)
  return y;
  else
  return gcd(y%x,x);
}


ll pw(ll k,ll x){
  if(x==0)
  return 1;
  if(x&1)
  return ((pw(k,x-1))*k);
  else
  return ((pw(k,x/2))*(pw(k,x/2)));
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << endl
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
int dx8[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy8[8] = {0, 1, 0, -1, 1, 1, -1, -1};
int dx4[4] = {1, 0, -1, 0};
int dy4[4] = {0, 1, 0, -1};
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;}
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){ fill((T*)array, (T*)(array+N), val); }
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;
const double EPS = 1e-9;



int main()
{
    int N, M; cin >> N >> M;
    vector<int> v[100001];
    for (int i=0; i<N; i++) {
        int A, B; cin >> A >> B;
      	v[A].push_back(B);
    }
  
    int ans = 0;
    priority_queue<int> pq;
    for (int i=1; i<=M; i++)
    {
        for (auto e : v[i]) {
            pq.push(e);
            };
    
   	if (! pq.empty()) {
         
          ans += pq.top();
          pq.pop();
         
        }
    }
 
    cout << ans << endl;
}

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


int main(void){
	string str;
	cin>>str;
	int len=str.size();
	for(int i=0;i<len-1;){
		if(str[i]=='S'&&str[i+1]=='T'){
			int temp=i;
			str.erase(i,2);
			if(temp>0)
				i=temp-1;
			else
				i=temp;
			len=str.size();
		}
		else i++;
	}
	cout<<str.size()<<endl;

	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
#define si(n) scanf("%d",&n);
#define PI acos(-1.0)
#define sl(n) scanf("%lld",&n);
#define sf(n) scanf("%lf",&n);
#define ss(n) scanf("%s",n);
#define for0(i,n) for(ll i=0;i<n;i++)
#define for1(i,n) for(ll i=1;i<=n;i++)
#define forc(i,j,n) for(ll i=j;i<n;i++)
#define pb push_back
#define sor(n) sort(n.begin(),n.end())
#define sorcmp(n) sort(n.begin(),n.end(),cmp)
#define rev(n) reverse(n.begin(),n.end())
#define pi(x)  printf("%d",x);
#define pl(x)  printf("%lld",x);
#define pf(x)  printf("%.10lf",x);
#define ps(x)  printf("%s",x);
#define en() printf("\n");
#define random_shuffle(r...)random_shuffle(r,[](int _){return rand()%_;})
#define SQR(a) (a)*(a)
#define sp(x) fixed<<setprecision(x)
#define mod 1000000007
#define endl '\n'
#define pii pair<int,int>
#define pll pair<ll,ll>
#define bug cout<<"Here"<<endl
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);}
template <typename T> T POW(T B,T P){ if(P==0) return 1; if(P&1) return B*POW(B,P-1);  else return SQR(POW(B,P/2));}
ll powmod(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%mod;a = a*a%mod;b >>= 1;}return ans;}

int main(){
fastio();



       ll n;
       cin>>n;
       ll temp=n/1000;
       if(n%1000)
       {
           temp++;
       }
       ll now=temp*1000;
       cout<<now-n<<endl;








return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[11], t[11], u[11];
	int a, b;

	scanf("%s%s", s, t);
	scanf("%d%d", &a, &b);
	scanf("%s", u);

	if (strncmp(s, u, 11) == 0)
	{
		a--;
	}
	else
	{
		b--;
	}

	printf("%d %d\n", a, b);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

    string s, t, u;
    int a, b;

    cin >> s >> t >> a >> b >> u;

    if(u==s) --a;
    if(u==t) --b;
    cout << a << " " << b << endl;

    return 0;
}

Measured memory_bytes: 256
fun main(args:Array<String>) {
	val n = readLine()!!.toInt()
	val p = (1..n).map{ readLine()!!.split(" ").map{it.toInt()} }
	var (t,x,y)= listOf(0,0,0)
	p.forEach {
		val (dt,dx,dy)= listOf(it[0]-t,Math.abs(it[1]-x),Math.abs(it[2]-y))
		if( dt%2!=(dx+dy)%2 || dt<dx+dy){
			println("No")
			return
		}else{
			t=it[0]; x=it[1]; y=it[2]
		}
	}
	println("Yes")
}

Measured memory_bytes: 60152
n=int(input())
s=list(input())
count=[0]*n
count[0]=s[1:].count('E')
for i in range(1, n):
    count[i]=count[i-1]
    if s[i-1]=='W':
        count[i]+=1
    if s[i]=='E':
        count[i]-=1
print(min(count))
    

Measured memory_bytes: 17444
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {

	char okada[55][55];
	int a = 0,b = 0, c=0,h=0,w=0;
	std::cin >> h >> w;
	int koritu = 0;
	
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			std::cin >> okada[i][j];
		
			}
		}
	
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			
				if (okada[i][j] == '#'&&okada[i - 1][j] != '#'&&okada[i + 1][j] != '#'&&okada[i][j - 1] != '#'&&okada[i][j + 1] != '#') {
					koritu++;
				}
			
		}
	}
	if (koritu!=0) {
		std::cout << "No" << std::endl;
	}
	else {
		std::cout << "Yes" << std::endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
 long long n,sum=0,i,N;
  
  scanf("%lld",&n);
  
  for(i=1;i*i<=n;i++){
  	if(n%i==0){
     N=n/i-1;
    if(N>i){
    sum=sum+N;
    }
  }
  }
  printf("%lld",sum);
  
  return 0;
}


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

#define times(n, i)      uptil(0, n, i)
#define rtimes(n, i)     downto((n) - 1, 0, i)
#define upto(f, t, i)    for(int _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(int _##i = (t), i = (f); i <  _##i; i++)
#define downto(f, t, i)  for(int _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(int _##i = (t), i = (f); i >  _##i; i--)
typedef long double LD;
#define long long long

#if defined(EBUG) && !defined(ONLINE_JUDGE)
#define debug true
#define ln << endl
#else
#define debug false
#define ln << '\n'
#endif
#define tb << '\t'
#define sp << ' '

#define lam [&]


signed main() { // long: 64bit
    if(!debug) {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }

    long K; scanf("%lld", &K);

    int N = 50;
    cout << N ln;
    long a = 49 + K / 50 - K % 50;
    times(N, i) {
        cout << (i < K % 50 ? a + 51 : a) sp;
    }

    return 0;
}


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

int main(){
  int N, X, T;
  cin >> N >> X >> T;
  
  if (N % X == 0){
    cout << T * (N / X) << endl;
  }
  else{
    cout << T * (N / X + 1) << endl;
  }
}


Measured memory_bytes: 3624
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m = inpl()
a = inpl()
g = a[0]
for i in range(1,n):
    g = fractions.gcd(g,a[i])
if max(a) >= m and m % g == 0:
    print('POSSIBLE')
else:
    print('IMPOSSIBLE')

Measured memory_bytes: 84332
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

vector<int> make_table(int n, int m) {
    vector<int> table(n);
    table[0] = 1;

    FOR(i, 1, n) table[i] = table[i-1] * 10 % m;

    return table;
}

int main() {
    constexpr int mod = 1e9 + 7, m = 13;
    string s; cin >> s;
    const int n = s.length();

    reverse(s.begin(), s.end());

    auto dp = make_v(n+1, m, 0LL);
    dp[0][0] = 1;

    auto table = make_table(n, m);

    REP(i, n)REP(j, m) {
        if(s[i] == '?') REP(k, 10) {
            (dp[i+1][(k * table[i] + j) % m] += dp[i][j]) %= mod;
        } else {
            int k = s[i] - '0';
            (dp[i+1][(k * table[i] + j) % m] += dp[i][j]) %= mod;
        }
    }

    cout << dp[n][5] << endl;
    
    return 0;
}


Measured memory_bytes: 14080
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <string>

#define INF 1000000000000000
#define MAX 100010
#define ll long long
#define P pair<ll,ll>
using namespace std;

vector<pair<ll,ll>> G[MAX],H[MAX];
long long d[MAX],s,t,y[MAX],snu[MAX],ans[MAX];
bool used[MAX];
priority_queue<P,vector<P>,greater<P>> que;
ll V,E;

void dijkstra(int s){
	for(int i=0;i<V;i++){
		d[i] = INF*100;
		used[i] = false;
	}
	que.push({0,s});
	while(!que.empty()){
		P p = que.top();
		que.pop();
		ll x = p.second;
		if(used[x]) continue;
		used[x] = true; d[x] = p.first;
		for(P e: G[x]){
			if(d[e.first]>d[x]+e.second){
				que.push({d[x]+e.second,e.first});
			}
		}
	}
}

void dijkstra2(int s){
	for(int i=0;i<V;i++){
		d[i] = INF*100;
		used[i] = false;
	}
	que.push({0,s});
	while(!que.empty()){
		P p = que.top();
		que.pop();
		ll x = p.second;
		if(used[x]) continue;
		used[x] = true; d[x] = p.first;
		for(P e: H[x]){
			if(d[e.first]>d[x]+e.second){
				que.push({d[x]+e.second,e.first});
			}
		}
	}
}

int main(){
	cin >> V >> E >> s >> t;
	s--; t--;
	int i;
	for(i=0;i<E;i++){
		ll u,v,a,b;
		cin >> u >> v >> a >> b;
		u--; v--;
		G[u].push_back({v,a});
		G[v].push_back({u,a});
		H[u].push_back({v,b});
		H[v].push_back({u,b});
	}
	
	dijkstra(s);
	for(i=0;i<V;i++){
		y[i] = d[i];
	}
	
	dijkstra2(t);
	for(i=0;i<V;i++){
		snu[i] = d[i];
	}
	ans[V] = INF*1000;
	for(i=V-1;i>=0;i--){
		ans[i] = min(ans[i+1],y[i]+snu[i]);
	}
	
	for(i=0;i<V;i++){
		cout << INF - ans[i] << endl;
	}
}

Measured memory_bytes: 20600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    ll sum = a[n - 1], ind = n - 2;
    n -= 2;
    bool one = 1, two = 1;
    while(n) {
        if(one) {one = 0; sum += a[ind]; n--;}
        else if(two) {two = 0; sum += a[ind]; n--;}
        else {one = 1; two = 1; ind--;}
    }
    cout << sum << "\n";
}       

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 5200
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

def draw_cross(line, end, pos, left):
    if left:
        if pos < 1 or line[pos-1]:
            return False
        elif pos > 1 and line[pos-2]:
            return False
        elif pos < end and line[pos]:
            return False
        line[pos-1] = 1
        return pos

    if pos >= end or line[pos]:
        return False
    elif pos < end-1 and line[pos+1]:
        return False
    elif pos > 0 and line[pos-1]:
        return False
    line[pos] = 1
    return pos + 1

def run(start, side, add, left):
    end = len(side[0])
    pos = start - 1
    add -= 1
    cross = 0

    for step, line in enumerate(side):
        line = line[:]
        if add == step:
            cross = draw_cross(line, end, pos, left)
            if not cross:
                return (False, False)

        if pos > 0 and line[pos-1]:
            pos -= 1
        elif pos < end and line[pos]:
            pos += 1
    return (cross, pos + 1)

while True:
    n = int(stdin.readline())
    if not n:
        break
    start = int(stdin.readline())
    hit = int(stdin.readline())
    num_step = int(stdin.readline())
    side = []
    for i in range(num_step):
        side.append([int(s) for s in stdin.readline().rstrip()])

    cross, goal = run(start, side, 0, True)
    if goal == hit:
        print(0)
        continue
    for step in range(1, num_step+1):
        cross, goal = run(start, side, step, left=True)
        if goal == hit:
            print(step, cross)
            break
        cross, goal = run(start, side, step, left=False)
        if goal == hit:
            print(step, cross)
            break
    else:
        print(1)

Measured memory_bytes: 4348
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
 
using namespace std;
 
 
int main(void) {
 
    int n, a;
    int max = -1000000, min = 1000000;
    long int sum = 0;
 
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        if (a > max)
            max = a;
        if (a < min)
            min = a;
        sum += a;
    }
 
    cout << min << " " << max << " " << sum << endl;
 
    return 0;
}

Measured memory_bytes: 3080
#include <stdio.h>

int main()
{
    int a, b, x;
    scanf("%d %d", &a, &b);
    x = a + b;
    if (x < a - b)
    {
        x = a - b;
    }
    if (x < a * b)
    {
        x = a * b;
    }
    printf("%d", x);
    return 0;
}

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

int main()
{
    int K;
    cin >> K;
    int d[K+1]; //modK = 0,1,2,....,K-1
    fill(d, d + K, 1e9); 
    d[1] = 1;
    deque<int> que;
    que.push_back(1);
    while(!que.empty()) {
        int p = que.front(); que.pop_front();
        if(d[(p+1)%K] > d[p] + 1) {
            d[(p+1)%K] = d[p] + 1; que.push_back((p+1)%K);
        }
        if(d[(p*10)%K] > d[p]) {
            d[(p*10)%K] = d[p]; que.push_front((p*10)%K);
        }
        /*
        for(int i = 0; i < K; ++i) {
            cout << d[i] << " ";
        }
        cout << endl;
        */
    }
    cout << d[0] << endl;
    return 0;
}

Measured memory_bytes: 896
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); } bool DEBUG = 0; 
void log(A ...)(lazy A a){ if(DEBUG) print(a); }
void print(){ writeln(""); } void print(T)(T t){ writeln(t); } void print(T, A ...)(T t, A a){ write(t, " "), print(a); }
string unsplit(T)(T xs){ return xs.array.to!(string[]).join(" "); }
string scan(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T scan(T)(){ return scan.to!T; } T[] scan(T)(int n){ return n.iota.map!(i => scan!T()).array; }
T lowerTo(T)(ref T x, T y){ if(x > y) x = y; return x; } T raiseTo(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
  long d = scan!long, t = scan!long, s = scan!long;
  if(t * s >= d) "Yes".writeln;
  else "No".writeln;
}


Measured memory_bytes: 3316
N = int(input())
H = list(map(int, input().split()))
k = 0
m = 0
for i in range(N):
    if k < m:
        k = m
    if i != N - 1 and H[i] >= H[i+1]:
        m += 1
    else:
        m =0
print(k)


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

int main()
{
  int houses[4][3][10];
  for (int i=0; i<4; i++){ for (int j=0; j<3; j++){ for (int k=0; k<10; k++)
  {
     houses[i][j][k] = 0;
  }}}
  int n;
  cin >> n;
  int b,f,r,v;
  for (int i=0; i<n; i++)
  {
    cin >> b >> f >> r >> v;
    houses[b-1][f-1][r-1] += v;
  }
  for (int i=0; i<4; i++)
  {
    for (int j=0; j<3; j++)
    {
      for (int k=0; k<10; k++)
      {
        cout << ' ' << houses[i][j][k] << flush;
      }
      cout << endl;
    }
    if ( i == 3) return 0;
    cout << "####################" << endl;
  }
}

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

int main(){
  int q;
  cin>>q;
  while(q--){
    string X,Y;
    cin>>X>>Y;
    vector<vector<int> > v(X.size()+1,vector<int>(Y.size()+1,0));
    for(int i=0;i<X.size();i++){
      for(int j=0;j<Y.size();j++){
	if(X[i] == Y[j]){
	  v[i+1][j+1] = v[i][j]+1;
	}else{
	  v[i+1][j+1] = max(v[i+1][j],v[i][j+1]);
	}
      }
    }
    cout<<v[X.size()][Y.size()]<<endl;
  }
  return 0;
}

Measured memory_bytes: 5036
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  string s;
  int al[27]={};
  int c=0;
  cin>>s;
  for(int i=0;i<s.size();i++){
    al[s[i]-96]++;
  }
  for(int i=1;i<=26;i++){
    if(al[i]%2!=0){
      c++;
      break;
    }
  }
  if(c==0){
    cout<<"Yes"<<"\n";
  }
  else{
    cout<<"No"<<"\n";
  }
  return 0;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  string s;cin>>s;
  cout<<string(s.size(),'x')<<endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

ll N, X;

struct Test {
    ll b, l, u;
    Test(int b = 0, int l = 0, int u = 0) : b(b), l(l), u(u) {}

    ll score() const {
        return u * (X - b) + l * b;
    }

    bool operator>(const Test &t) const {
        return score() > t.score();
    }
};

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

    vector<Test> tests(N);
    for (auto& t : tests) {
        cin >> t.b >> t.l >> t.u;
    }
    sort(tests.begin(), tests.end(), greater<Test>());

    ll ok = N * X, ng = -1;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        ll n = mid / X;
        ll R = mid % X;
        
        ll score = 0;
        for (int i = 0; i < N; ++i) {
            if (i < n) {
                score += tests[i].u * (X - tests[i].b);
            } else {
                score -= tests[i].l * tests[i].b;
            }
        }
        
        bool judge = (score >= 0);
        
        if (R > 0) {
            for (int r = 0; r < N; r++) {
                ll nscore = score;
                if (r < n) {
                    nscore -= tests[r].score();
                    nscore += tests[r].l * min(tests[r].b, R) + tests[r].u * max(0LL, R - tests[r].b);
                    nscore += tests[n].score();
                } else {
                    nscore += tests[r].l * min(tests[r].b, R) + tests[r].u * max(0LL, R - tests[r].b);
                }
                if (nscore >= 0) judge = true;
            }
        }

        (judge ? ok : ng) = mid;
    }

    cout << ok << endl;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

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

    int n;
    string s;
    cin >> n >> s;
    deque<char> ans;
    for(int i = 0; i < n; ++i)  ans.push_back(s[i]);
    int cnt = 0;
    for(int i = 0; i < n; ++i){
        if(s[i] == '(') ++cnt;
        else    cnt = max(cnt - 1, 0);
    }
    for(int i = 0; i < cnt; ++i)    ans.push_back(')');
    cnt = 0;
    for(int i = n - 1; i >= 0; --i){
        if(s[i] == ')') ++cnt;
        else    cnt = max(cnt - 1, 0);
    }
    for(int i = 0; i < cnt; ++i)    ans.push_front('(');
    while(!ans.empty()){
        cout << ans.front();
        ans.pop_front();
    }
    cout << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS  = 1e-9;

int dp[1<<6][110];
int m, n, k, d;
vector<pii> g[110]; // [0,m):??±???????±?, [m,m+n):??????????????????, m+n:??????, m+n+1:?????????
int c[6];

int input() {
	char ch;
	int num;
	scanf(" %c", &ch);
	if (ch == 'H') return m + n;
	if (ch == 'D') return m + n + 1;
	scanf("%d", &num);
	
	int res = num - 1;
	if (ch == 'L') res += m;
	return res;
}

int main() {
	while (cin >> m >> n >> k >> d, m || n || k || d) {
		REP(i, m) scanf("%d", c + i);
		
		REP(i, m + n + 2) g[i].clear();
		
		REP(i, d) {
			int u = input();
			int v = input();
			int e; scanf("%d", &e);
			
			g[u].push_back(pii(v, e * k));
			g[v].push_back(pii(u, e * k));
		}
		
		
		fill(dp[0], dp[1<<m], INF);
		priority_queue<pip, vector<pip>, greater<pip> > pq;
		pq.push(pip(0, pii(0, m + n)));
		dp[0][m + n] = 0;
		
		while (!pq.empty()) {
			pip now = pq.top(); pq.pop();
			
			int s = now.se.fi;
			int u = now.se.se;
			
			REP(i, g[u].size()) {
				int v = g[u][i].fi;
				int nc = now.fi + g[u][i].se;
				
				if (v < m && s >> v & 1) continue;
				int ns = s;
				if (v < m) ns |= 1<<v;
				
				if (!chmin(dp[ns][v], nc)) continue;
				pq.push(pip(nc, pii(ns, v)));
			}
		}
		
		int ans = INF;
		REP(i, 1 << m) if (dp[i][n + m + 1] != INF) {
			int sum = 0;
			REP(j, m) if (i >> j & 1) sum += c[j];
			chmin(ans, dp[i][n + m + 1] - sum);
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3180
package main

import (
	"fmt"
	"strconv"
	"strings"
)

func main() {
	var k, x int
	fmt.Scan(&k, &x)

	ans := make([]string, k*2-1)
	for i := 0; i < k*2-1; i++ {
		ans[i] = strconv.Itoa(x - (k - 1) + i)
	}

	fmt.Println(strings.Join(ans, " "))
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef pair<int,int> P;

int n;
int check[10000];
int a[1000];

int main(){
	cin >> n;
	rep(i,n) cin >> a[i];
	rep(i,n){
		int x = a[i];
		check[x] = 1;
		for(int j = 1; j < 3; j++){
			if(i+j >= n) break;
			x *= 10;
			x += a[i+j];
			check[x] = 1;
		}
	}
	rep(i,10000){
		if(check[i] == 0){
			cout << i << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 1176
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())
f = [a,b,c,d,e]

for i in range(5):
	for j in range(i+1,5):
		if abs(f[i]-f[j]) > k:
			print (":(")
			exit()
print ("Yay!")

Measured memory_bytes: 3064
#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 rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
const ll MOD2 = 998244353;
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    cin >> N;
    int a[N];
    rep(i, N) cin >> a[i];
    vector<int> vec;
    rep(i, N){
        int j = 0;
        while(i+j+1 < N && a[i] == a[i+j+1]) j++;
        if(j) vec.pb(j+1);
        i += j;
    }
    int ans = 0;
    for(auto &e: vec){
        ans += e/2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,j,k,c[11],d[10][10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    int f[10][10]={0};
    for(j=0;j<9;j++){
      for(k=0;k<10;k++)c[k]=0;
      for(k=0;k<9;k++){
	scanf("%d",&d[j][k]);
	c[d[j][k]]++;
      }
      for(k=0;k<9;k++){
	if(c[d[j][k]]>1)f[j][k]=1;
      }	
    }
    for(k=0;k<9;k++){
      for(j=0;j<10;j++)c[j]=0;
      for(j=0;j<9;j++){
	c[d[j][k]]++;
      }
      for(j=0;j<9;j++){//printf("%d ",c[d[j][k]]);
	if(c[d[j][k]]>1)f[j][k]=1;
      }//printf("\n");
    }
    for(j=0;j<9;j++){
      for(k=0;k<10;k++)c[k]=0;
      for(k=0;k<9;k++){
	c[d[(j/3)*3+k/3][(j%3)*3+k%3]]++;
      }
      for(k=0;k<9;k++){
	if(c[d[(j/3)*3+k/3][(j%3)*3+k%3]]>1)f[(j/3)*3+k/3][(j%3)*3+k%3]=1;
      }	
    }
    if(i)printf("\n");
    for(j=0;j<9;j++){
      for(k=0;k<9;k++){
	if(f[j][k])printf("*");
	else       printf(" ");
	printf("%d",d[j][k]);
      }
      printf("\n");
    } 
  }  
  return 0;
}

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

int main(){
    ll n;
    cin >> n;
    ll ans = n*(n-1)/2;
    cout << ans << endl; 
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static final long MOD = 1000_000_007L;

    public static void main(String[] args) {
	int N = Integer.parseInt(scan.next());
	int[] A = new int[N];
	for (int i = 0; i < N; i++) {
	    A[i] = Integer.parseInt(scan.next());
	}

	int[] count = new int[N];
	if(N % 2 == 0) {
	    for (int i = 0; i < N; i++) {
		if(i % 2 == 1) count[i] = 2;
	    }
	} else {
	    for (int i = 0; i < N; i++) {
		if(i % 2 == 0) count[i] = 2;
	    }
	    count[0] = 1;
	}

	for (int i = 0; i < N; i++) {
	    count[A[i]]--;
	    if(count[A[i]] < 0) {
		System.out.println(0);
		return;
	    }
	}

	System.out.println(pow(2, N/2));
	scan.close();
    }

    public static long pow(long x, long n) {
	if(n == 0) return 1;

	long x2 = pow(x, n/2);
	long ans = (n % 2 == 0 ? 1 : x);
	return ans * x2 % MOD * x2 % MOD;
    }
}


Measured memory_bytes: 48752
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<cmath>
#include <map>
#include <set>
#include <iostream>

using namespace std;



int main()
{
	long long n;
	long long d;
	cin >> n >> d;
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		long long x, y;
		cin >> x >> y;
		if ((x*x+y*y)<= d*d) ans++;
	}
	cout << ans;
}



Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
using pii = pair<int, int>;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};
int main() {
    int n, k; cin >> n >> k;
    int v[n]; rep(i, n) cin >> v[i];
    int ans = 0;
    rep(l, k + 1) { //左から取り出す
        rep(r, k - l + 1) {
            if (l + r > n) continue;
            int d = k - l - r; //取り除ける回数 上のfor文からd >= 0
            int now = 0;
            vector<int> s; //取り出したものの集合
            rep(i, l) { //左から取り出す
                now += v[i];
                s.push_back(v[i]);
            }
            rrep(i, n - r, n) { //右から取り出す この書き方good
                now += v[i];
                s.push_back(v[i]);
            }
            sort(s.begin(), s.end());
            rep(i, d) {
                if (i >= s.size()) break;
                if (s[i] > 0) break;
                now -= s[i];
            }
            chmax(ans, now);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	int k, s;
	cin >> k >> s;
	int ans = 0;

	for (int i = 0; i <= k; i++) {
		for (int j = 0; j <= k; j++) {
			int z = s - i - j;
			if (0 <= z && z <= k)ans++;
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256