akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python
# -*- coding: utf-8 -*-


import sys


def counting_sort(A, max_occurance):
    result = [0] * array_length
    count_list = [0] * max_occurance

    for j in range(array_length):
        count_list[A[j]] += 1
    # print('1', C[:array_length])

    for i in range(1, max_occurance):
        count_list[i] += count_list[i - 1]
    # print('2', C[:array_length])

    for m in array[::-1]:
        result[count_list[m] - 1] = m
        count_list[m] -= 1

    return result


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    array_length = int(_input[0])
    array = list(map(int, _input[1].split()))
    # assert len(array) == array_length
    max_elem = int(1e4)
    result = counting_sort(A=array, max_occurance=max_elem)
    print(*result)

Measured memory_bytes: 221040
/* 
 * File:   main.cpp
 * Author: administrator
 *
 * Created on 2011å¹´8æ20æ¥, ä¸å4:32
 */

#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <map>
#include <set>
#include <math.h>
#define M 100000
using namespace std;
long long even[M];
long long odd[M];

/*
 * 
 */
long long gcd(long long n, long long m) {
    while (m) {
        long long t = n % m;
        n = m;
        m = t;
    }
    return n;
}

int main(int argc, char** argv) {
    int n, i, j;
    long long x, A, a, B;
    while (scanf("%d", &n), n) {
        int cnte = 0, cnto = 0;
        n = n * (n + 1) / 2;
        for (i = 0; i < n; i++) {
            scanf("%lld", &x);
            if (x % 2 == 1)odd[cnto++] = x;
            else even[cnte++] = x;
        }
        sort(even, even + cnte);
        sort(odd, odd + cnto);
        long long g;
        A = even[cnte - 1];
        a = even[cnte - 2];
        B = odd[cnto - 1];
        g = gcd(A, B);
        A /= g, B /= g;
        a /= B;
        g = A*a;
        g = (long long) sqrt(g * 1.0);
        cout << g << endl;
        for (i = 0; i < cnte - 1; i++)
            cout << even[i] / g << " ";
        cout << even[i] / g << endl;
    }
    return 0;
}

Measured memory_bytes: 1144
from itertools import combinations as c
from itertools import chain

S=list("AKIHABARA") #0,4,6,8
l=[0,4,6,8]
o=set()

for k in chain(c(l,2),c(l,3),c(l,4)):
  b=[j if not i in k else "" for i,j in enumerate(S)]
  o.add("".join(b))
o.add("AKIHABARA")

s=input()
if s in o:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 3064
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

typedef pair<int,int> P;
typedef long long ll;

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")



/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main() { 
  long long H;cin>>H;
  long long ans = 0;
  long long nw = 1;
  while(H){
    ans += nw;
    H/=2;
    nw*=2;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
//using P = pair<int,int>;
//pow(x,n)
//cout << fixed << setprecision(桁数);
//string = to_string(数値)
//int = stoi(文字列)
//(int)(char-'0')
//string = itoa(int)
//円周率: M_PI

int main() {
    int a, b, c, d; cin >> a >> b >> c >> d;
    int taka, aoki;
    taka =c/b;
    if(c%b!=0)  taka+=1;
    aoki = a/d;
    if(a%d!=0) aoki+=1;

    if(taka<=aoki) cout << "Yes" << endl;
    else cout << "No" << endl;
}





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

int main(){
    string s;
    cin >> s;
    long ans = stol(s);
    int tot_plus = s.length()-1;
    for(int n=1;n<s.length();n++){
        for(int i=0;i<s.length()+1-n;i++){
            long num = stol(s.substr(i,n));
            if(i==0 || i == s.length()-n){
                ans += num*(pow(2,tot_plus-n));
            }else{
                ans += num*(pow(2,tot_plus-n-1));
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 256
n,k = map(int,input().split())
if n % k ==0:
    print(0)
else:
    l = [n]
    p = n//k
    c = n-(p*k)
    half = k//2
    while c > half:
        c = abs(c-k)
    l.append(c)
    print(min(l))

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


vector<int> Zalgorithm(string s){
    int n = s.size();
    vector<int> res(n);
    res[0] = n;
    int i = 1,j = 0;
    while(i < n){
        while(i+j < n && s[j] == s[i+j]) j++;
        res[i] = j;
        if(j == 0){
            i++;
            continue;
        }
        int k = 1;
        while(i+k < n && k+res[k] < j){
            res[i+k] = res[k];
            k++;
        }
        i += k;
        j -= k;
    }
    return res;
}

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    rep(i,N){
        string t = S.substr(i,N-i);
        vector<int> z = Zalgorithm(t);
        int m = z.size();
        repr(j,1,m){
            ans = max(ans,min(z[j],j));
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
  	ios::sync_with_stdio(false);
    int n, k;
  	ll a[200005] = {}, z = 0;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], a[i] -= k, a[i] += a[i - 1];
  	ordered_set<pair<ll, int>> s;
  	s.insert({0, 0});
  	for (int i = 1; i <= n; i++) {
    	z += s.order_of_key({a[i] + 1, -1});
      	s.insert({a[i], i});
    }
  	cout << z;
}



Measured memory_bytes: 14336
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	rdr := NewReader(10000)
	a := ReadLine(rdr)
	b := ReadLine(rdr)
	c := ReadLine(rdr)

	fmt.Println(a[0:1] + b[1:2] + c[2:3])
}

type Reader struct {
	rdr  *bufio.Reader
	size int
}

func NewReader(size int) *Reader {
	return &Reader{
		bufio.NewReaderSize(os.Stdin, size),
		size,
	}
}

func ReadLine(r *Reader) string {
	buf := make([]byte, 0, r.size)
	for {
		line, isPrefix, err := r.rdr.ReadLine()
		if err != nil {
			panic(err)
		}
		buf = append(buf, line...)
		if !isPrefix {
			break
		}
	}
	return string(buf)
}


Measured memory_bytes: 640
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    (;;$n:expr) => {
        {
            (0..$n).map(|_| scan!()).collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, l) = scan!(i64, i64);
    println!(
        "{}",
        if l >= 0 {
            (l + 1..l + n).sum::<i64>()
        } else if l + n - 1 < 0 {
            (l..l + n - 1).sum::<i64>()
        } else {
            (l..l + n).sum::<i64>()
        }
    )
}


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

#define mx 500008

#define pii pair<int,int>
#define pi acos(-1.0)
#define pb push_back
#define ss second
#define ff first
typedef long long int ll;
///adjacent move
int fx[4]={0,+1,0,-1};
int fy[4]={+1,0,-1,0};
///knight
ll prime[mx];

vector<pii>v[mx];
int main()
{
    int t=1;

    while(t--){
        ll n;
        cin>>n;
        if(n<30) cout<<"No"<<endl;
        else cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 15324
N = int(input())
S = input()
array = list(S)
leftW = None
rightR = None
for i in range(N):
    if array[i] == 'W':
        leftW = i
        break
for i in range(N):
    j = N-i-1
    if array[j] == 'R':
        rightR = j
        break
if leftW == None or rightR == None:
    print(0)
    exit()
counter = 0
while leftW < rightR:
    array[leftW] = 'R'
    array[rightR] = 'W'
    for i in range(leftW, N):
        if array[i] == 'W':
            leftW = i
            break
    for i in range(rightR):
        j = rightR - i
        if array[j] == 'R':
            rightR = j
            break
    counter += 1

print(counter)

Measured memory_bytes: 77896
#include <stdio.h>

int main(void) {
  int i,dice[6],subdice[6],z;
  char direciton;
  for(i = 0; i < 6; i++){
    scanf("%d",&dice[i]);
    subdice[i] = dice[i];
  }
  i = 0;
  while(z != '\n')z = getchar();

  while(1){
    direciton = getchar();
    if(direciton == '\n')break;
    switch(direciton){
      case 'N':
      dice[0] = subdice[1];
      dice[1] = subdice[5];
      dice[5] = subdice[4];
      dice[4] = subdice[0];
      for(i = 0; i < 6; i++)subdice[i] = dice[i];
      break;

      case 'S':
      dice[0] = subdice[4];
      dice[1] = subdice[0];
      dice[5] = subdice[1];
      dice[4] = subdice[5];
      for(i = 0; i < 6; i++)subdice[i] = dice[i];
      break;

      case 'E':
      dice[0] = subdice[3];
      dice[2] = subdice[0];
      dice[5] = subdice[2];
      dice[3] = subdice[5];
      for(i = 0; i < 6; i++)subdice[i] = dice[i];
      break;

      case 'W':
      dice[0] = subdice[2];
      dice[2] = subdice[5];
      dice[5] = subdice[3];
      dice[3] = subdice[0];
      for(i = 0; i < 6; i++)subdice[i] = dice[i];
      break;
    }
  }
  printf("%d\n",dice[0]);
  return 0;
}


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

const int mo=int(1e9+7);
int n,m,p[200010],id[200010],ans;
vector <int> son[200010],f[200010],g[200010],s,tim;

int qpow(int a,int b)
{
	int x=a;  a=1;
	while (b)
		{
			if (b&1)  a=1LL*a*x%mo;
			x=1LL*x*x%mo,b>>=1;
		}
	return a;
}

void dfs(int x)
{
	int hs=-1,ID;
	for (auto y:son[x])
		{
			dfs(y);
			if ((hs<0)||(f[id[y]].size()>f[id[hs]].size()))  hs=y;
		}
	if (hs<0)
		{
			id[x]=++m,f[m].push_back(1),g[m].push_back(1);
			return;
		}
	ID=id[x]=id[hs];
	for (auto y:son[x])
		if (y!=hs)
			{
				int d=f[ID].size()-f[id[y]].size();
				for (int i=0; i<f[id[y]].size(); i++)
					{
						if (tim[i+d]!=x)
							s[i+d]=(qpow(2,g[ID][i+d])+mo-f[ID][i+d])%mo,tim[i+d]=x;
						f[ID][i+d]=1LL*f[ID][i+d]*(qpow(2,g[id[y]][i])+mo-f[id[y]][i])%mo;
						f[ID][i+d]=(f[ID][i+d]+1LL*s[i+d]*f[id[y]][i])%mo;
						g[ID][i+d]+=g[id[y]][i];
						s[i+d]=1LL*s[i+d]*(qpow(2,g[id[y]][i])+mo-f[id[y]][i])%mo;
					}
			}
	f[id[x]].push_back(1),g[id[x]].push_back(1);
}

void work()
{
	scanf("%d",&n),s.resize(n+1),tim.resize(n+1,-1);
	for (int i=1; i<=n; i++)
		scanf("%d",&p[i]),son[p[i]].push_back(i);
	dfs(0);
	for (int i=0; i<f[id[0]].size(); i++)
		ans=(ans+1LL*f[id[0]][i]*qpow(2,n+1-g[id[0]][i]))%mo;
	printf("%d",ans);
}

int main()
{
	work();
	return 0;
}


Measured memory_bytes: 53620
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
typedef vector<ll> vec;
const int MAX_N=2e5;
const ll MOD=1e9+7;
int N,dep[MAX_N+1];

vector<int> G[MAX_N+1];

deque<vec> dp[MAX_N+1];

void dfs(int v,int p){
	for(auto e:G[v]){
		if (e!=p){
			dfs(e,v);
		}
	}
	bool f=false;
	int dma=-1;
	for(auto e:G[v]){
		if (e!=p){
			if (!f){
				dp[v].swap(dp[e]);
				f=true;
			}else{
				int sz=min(dp[v].size(),dp[e].size());
				if ((int)dp[v].size()==sz){
					dp[v].swap(dp[e]);
				}
				auto ite1=dp[v].begin(),ite2=dp[e].begin();
				REP(i,sz){
					vec tem(3);
					REP(a,3){
						REP(b,3){
							tem[min(a+b,2)]+=(*ite1)[a]*(*ite2)[b];
							tem[min(a+b,2)]%=MOD;
						}
					}
					*ite1=tem;
					ite1++;
					ite2++;
				}
				if(sz>dma){
					dma=sz;
				}
			}
		}
	}
	if (dma!=-1){
		auto ite=dp[v].begin();
		REP(i,dma){
			(*ite)[0]+=(*ite)[2];
			(*ite)[0]%=MOD;
			(*ite)[2]=0;
			ite++;
		}
	}
	dp[v].push_front(vec{1,1,0});
}

void caldep(int v,int d,int p){
	for(auto e:G[v]){
		if (e!=p){
			caldep(e,d+1,v);
		}
	}
	dep[d]++;
}
ll mpw(ll n,int m){
	ll ret=1;
	while(m){
		if (m&1){
			ret*=n;
			ret%=MOD;
		}
		n*=n;
		n%=MOD;
		m>>=1;
	}
	return ret;
}

int main(){
	cin>>N;
	REP(i,N){
		int p;
		cin>>p;
		G[p].push_back(i+1);
		G[i+1].push_back(p);
	}
	dfs(0,-1);
	ll ans=0;
	caldep(0,0,-1);
	int d=dp[0].size();
	auto ite=dp[0].begin();
	REP(i,d){
		ans+=(*ite)[1]*mpw(2,N+1-dep[i]);
		ans%=MOD;
		ite++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 249588
//package BeginnerContest148;

import java.util.*;
import java.io.*;

public class Main {

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

    public static void main(String[] args) throws IOException {
        FastReader sc = new FastReader();
        PrintWriter pw = new PrintWriter(System.out);
        long a = sc.nextLong();
        long b = sc.nextLong();
        pw.println(b*a/gcd(a,b));
        pw.close();

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21204
N  = int(input())
T, A = [int(i) for i in input().split()]
H_list = [int(i) for i in input().split()]

ans = float('inf')
res_idx = 0

for i in range(N):  
    tmp = T - H_list[i]*0.006
    diff = abs(tmp - A)
    if diff < ans:
        ans = diff
        res_idx = i + 1
        
print(res_idx)

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

int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

int main(void){
    int K,S,cnt=0;

    scanf("%d %d%*c",&K,&S);
    for(int X=0; X<=K; X++){
        int M=S-X;
        //Y+Z = M
        if(M >= 0 && M<= K)
            cnt += M+1;
        else if(M > K && M <= 2*K)
            cnt += M+1 - 2*( M-K );
        else
            cnt+= 0;
    }
    printf("%d\n",cnt);
}

Measured memory_bytes: 128
#include<iostream>
#include<cmath>
using namespace std;
bool hw[1405][1405];
long long dp[1405][1405];
int main()
{
	long long h;
	long long w;
	cin>>h>>w;
	for(long long i=1;i<=h;i++)
	{
		for(long long j=1;j<=w;j++)
		{
			cin>>hw[i][j];
		}
	}
	for(long long i=1;i<=h;i++)
	{
		for(long long j=1;j<=w;j++)
		{
			if(hw[i][j]==0)
				dp[i][j]=1;
			else
				dp[i][j]=0;
		}
	}
	for(long long i=2;i<=h;i++)
	{
		for(long long j=2;j<=w;j++)
		{
			if(hw[i][j]==0)
				dp[i][j]=min(dp[i-1][j],min(dp[i][j-1],dp[i-1][j-1]))+1;
			else
				dp[i][j]=0;
		}
	}
	long long maxx=0;
	for(long long i=1;i<=h;i++)
	{
		for(long long j=1;j<=w;j++)
		{
			
				maxx=max(dp[i][j],maxx);
			
		}
	}
	cout<<maxx*maxx<<endl;
	return 0;
} 


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

int main(){
    ll n,q;
    cin >> n;
    ll a[n];
    map<ll, ll> mp;
    ll sum = 0;
    for(int i=0;i<n;i++){
        cin >> a[i];
        mp[a[i]]++;
        sum += a[i];
    }
    cin >> q;
    ll b[q];
    ll c[q];
    for(int i=0;i<q;i++){
        cin >> b[i] >> c[i];
    }

    for(int i=0;i<q;i++){
        sum += (c[i]-b[i])*mp[b[i]];
        mp[c[i]] += mp[b[i]];
        mp[b[i]] = 0;
        cout << sum  << endl;
    }
}

Measured memory_bytes: 11888
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int n = sc.nextInt();
		int a[] = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}
		Arrays.sort(a);
		System.out.println(a[n - 1] - a[0]);
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = -100100100;
typedef pair<int,int> P;

int main(){
    int n,m;
    cin >> n >> m;
    vector<P> d(m);
    rep(i,m)cin >> d[i].first >> d[i].second;
    int mini, maxi;
    mini = INF;
    maxi = -1*INF;
    rep(i,m){
        mini = max(mini,d[i].first);
        maxi = min(maxi, d[i].second);
    }
    if(maxi - mini <0){
        cout << 0 << endl;
        return 0;
    }else{
        cout << maxi - mini +1 << endl;
        return 0;
    }
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int x;

int main()
{
	cin>>x;
	repn(i,1000)
	{
		if(x*i%360==0)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3596
n = int(input())
L = list(int(input()) for _ in range(n))
SL = sorted(L)
first_max = SL[-1]
second_max = SL[-2]
for l in L:
  if (l != first_max):
    print(first_max)
  elif (l == first_max):
    print(second_max)

Measured memory_bytes: 19144
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include <cassert>
    #include <cmath>

    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<int,int>;


    int main(){
      int a,b;cin>>a>>b;
      if(a+b<10)cout<<a+b;
      else cout<<"error";
    }
    


Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	
	public static boolean sosuu(int s) {
		for(int i=2; i*i<=s; i++) {
			if(s%i == 0) return false;
		}
		return true;
	}
	
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)) {
			while(sc.hasNext()) {
				int n = sc.nextInt();
				if(n == 0) break;
				
				int count = 0;
				for(int i=n+1; i<=2*n; i++) {
					if(sosuu(i)) count++;
				}
				System.out.println(count);
			}
		}
	}
}



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

// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
using namespace std;


typedef long long int ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

#define St first
#define Nd second
#define Pb push_back
#define Mp make_pair
#define print_pair(p) cout<<p.St<<" "<<p.Nd
#define endl "\n"

#define REP(i,a,b) for(int i = a; i <= b; i++)
#define REV(i,a,b) for(int i = a; i >= b; i--)

#define AritSum(a,d,n) ((n)*(2*(a)+((n)-1)*(d)))/2
#define Log(base, num) log2(num)/log2(base)


// ************* MAIN *******************

string s;
void solve() {
    cin>>s;
    for (char &c : s) {
        if (c=='?') c='D';
    }
    cout << s << endl;
}
/*
g++ -std=c++14 -Wall -Wextra -O2 Test.cpp -o Test
*/
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int T=1;
    // cin>>T;
    for (int t = 1; t <= T; t++) {
        // cout << "Case #" << t << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 3784
#include <bits/stdc++.h>
#define INF 1000000000000000001
#define ll long long
#define pll pair<ll, ll>
using namespace std;

ll N;
vector<vector<bool>> ans;
vector<vector<char>> board;
void start_check(ll a, ll b)
{
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < N; ++j)
    {
      if (board.at(a + i).at(b + j) == board.at(a + j).at(b + i))
      {
        continue;
      }
      else
      {
        ans.at(a).at(b) = false;
        ll bad_num = min(i, j);
        for (ll k = 0; k < bad_num + 1; ++k)
        {
          if (a + k >= N || b + k >= N)
          {
            break;
          }
          ans.at(a + k).at(b + k) = false;
        }
        return;
      }
    }
  }
}

void check(ll a, ll b)
{
  for (ll i = 0; i < N - 1; ++i)
  {
    if (board.at(a + i).at(b + N - 1) == board.at(a + N - 1).at(b + i))
    {
      continue;
    }
    for (ll j = 0; j < i + 1; ++j)
    {
      ans.at(a + j).at(b + j) = false;
    }
    return;
  }
  return;
}

int main()
{
  cin >> N;
  board = vector<vector<char>>(2 * N - 1, vector<char>(2 * N - 1));
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < N; ++j)
    {
      char s;
      cin >> s;
      board.at(i).at(j) = s;
      if (i + N < 2 * N - 1)
      {
        board.at(i + N).at(j) = s;
        if (j + N < 2 * N - 1)
        {
          board.at(i + N).at(j + N) = s;
        }
      }
      if (j + N < 2 * N - 1)
      {
        board.at(i).at(j + N) = s;
      }
    }
  }
  ans = vector<vector<bool>>(N, vector<bool>(N, true));
  // start_check(0, 0, ans, board);
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < N; ++j)
    {
      if (!ans.at(i).at(j))
      {
        continue;
      }
      if (i == 0 || j == 0)
      {
        start_check(i, j);
      }
      else if (ans.at(i - 1).at(j - 1))
      {
        check(i, j);
      }
      else
      {
        start_check(i, j);
      }
    }
  }
  // for (ll i = 0; i < N; ++i)
  // {
  //   for (ll j = 0; j < N; ++j)
  //   {
  //     if (ans.at(i).at(j))
  //     {
  //       cout << 1;
  //     }
  //     else
  //     {
  //       cout << 0;
  //     }
  //   }
  //   cout << endl;
  // }
  //
  //
  // for (ll i = 0; i < 2 * N - 1; ++i)
  // {
  //   for (ll j = 0; j < 2 * N - 1; ++j)
  //   {
  //     cout << board.at(i).at(j);
  //   }
  //   cout << endl;
  // }
  ll cnt = 0;
  for (ll i = 0; i < N; ++i)
  {
    for (ll j = 0; j < N; ++j)
    {
      if (ans.at(i).at(j))
      {
        cnt += 1;
      }
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
#define debug(x) cout << #x << " = " << x << '\n'
#define debug_arr(a , n) for(ll i = 0 ; i < n ; i++)cout << a[i] << " "
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define vi vector<ll>
#define vll vector<ll> 
#define inf 1000000000
#define mod 1000000007

const ll max_n = 1e5 + 9;

typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
ll power(ll a , ll b)
{
    ll prod = 1;
    while(b)
    {
        if(b&1)
        prod = (prod*a)%mod;
        a = (a*a)%mod;
        b >>= 1;
    }
    return prod;
}

ll n;
vi a[max_n];
ll dp[max_n][2];   // 0 -> black   1 -> white

void dfs(ll s , ll p = -1){
    ll prod1 = 1 , prod2 = 1;
    for(auto it : a[s]){
        if(it != p){
            dfs(it , s);
            prod1 = (prod1 * dp[it][1])%mod;
            prod2 = (prod2 * (dp[it][1] + dp[it][0])%mod)%mod;
        }
    }
    dp[s][0] = prod1;
    dp[s][1] = prod2;
}
int main()
{
    cin >> n;
    for(ll i = 0 ; i < n-1 ; i++){
        ll x , y;
        cin >> x >> y;
        a[x].pb(y);
        a[y].pb(x);
    }

    dfs(1);
    cout << (dp[1][0] + dp[1][1])%mod << endl;
    return 0;
}

Measured memory_bytes: 14208
fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    var a = false
    var b = false
    var cnt = 0

    s.forEach {
        if (it == 'A' && !b) {
            a = true
        } else if (it == 'B' && a && !b) {
            b = true
        } else if (it == 'C' && a && b) {
            cnt++
            a = false
            b = false
        } else {
            a = false
            b = false
        }
    }

    println(cnt)
}


Measured memory_bytes: 31856
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;
int c[10][1005];
const int INF = 1001001001;

void test_case(){
	int h,w,k; cin >> h >> w >> k;
	vector<string> s(h);
	for(int i = 0 ; i < h ; i++){
		cin >> s[i];
	}
	int ans = INF;
	for(int div = 0;div < (1 <<(h-1));div++){
		int g = 0;
		vector<int> id(h);
		for(int i = 0 ; i < h ; i++){
			id[i] = g;
			if(div >> i & 1) 
					g++;
		}
		++g;
		for(int i = 0 ; i < g ; i++){
			for(int j = 0;j < w ; j++){
				c[i][j] = 0;
			}
		}
		for(int i = 0 ; i < h ; i++){
			for(int j = 0 ; j < w ; j++){
				c[id[i]][j] += (s[i][j]-'0');
			}
		}
		int num = g - 1;
		vector<int> now(g);
		auto add = [&](int j){
			for(int i = 0 ; i < g ; i++){
				now[i] += c[i][j];
			}
			for(int i = 0 ; i < g ; i++)
				if(now[i] > k)
					return false;
			return true;
		};
		for(int j = 0 ; j < w ; j++){
			if(!add(j)){
				num++;
				now = vector<int>(g);
				if(!add(j)){
					num = INF;
					break;
				}
			}
		}
		ans = min(ans,num);
	}
	cout<<ans<<"\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3676
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,int> PP;
typedef tuple<ll,ll,ll> T;
const long long INF = 1LL<<60;
const int MOD = 1000000000+7;
#define rev(s) (string((s).rbegin(), (s).rend()))
template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };
// cout << fixed << setprecision(10) << ans << endl;
// *min_element(c + l, c + r) *max_element(c + l, c + r)
// int dx[8]={1,1,0,-1,-1,-1,0,1};
// int dy[8]={0,1,1,1,0,-1,-1,-1};
// int dx[4]={1,0,-1,0};
// int dy[4]={0,1,0,-1};
// struct Edge {
//   int to, id;
//   Edge(int to, int id): to(to), id(id) {}
// };


int main() {
  int H,N;cin>>H>>N;
  vector<int> a(N),b(N);
  rep(i,N) cin>>a[i]>>b[i];
  vector<ll> dp(H+10010,INF);
  dp[0] = 0;
  rep(i,N) {
    rep(j,H+1) {
      chmin(dp[j+a[i]],dp[j]+b[i]);
    }
  }
  ll ans = INF;
  for(int i = H;i<(int)dp.size();i++) {
    chmin(ans,dp[i]);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
#define MAX 5000
#define MOD 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);	
	string s;
	cin>>s;
	int ans = 0;
	bool ok = false;
	for(int i=0;i<3;++i)
	{
		if(ok)	
		{
			if(s[i]!='R')
				break;
			++ans;
		}
		else if(s[i]=='R')
			ans = 1, ok = true;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3648
import java.util.*;

public class  Main {

	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		
		int a[]=new int[3];
		for(int i=0;i<3;i++)
			a[i]=input.nextInt();
		Arrays.sort(a);
		if(a[1]-a[0]==a[2]-a[1])
			System.out.println("YES");
		else
			System.out.println("NO");
			
		
	}
}

Measured memory_bytes: 21844
#include <iostream>

using namespace std;

int N;
long long int x, a[100005];

int main(void) {

	cin >> N >> x;
	for (int i = 1; i <= N; i++) { cin >> a[i]; }

	long long int ans = 0;

	if (a[1] > x) { ans += a[1] - x; a[1] = x; }

	for (int i = 2; i <= N; i++) {
		if (a[i - 1] + a[i] > x) { ans += a[i - 1] + a[i] - x; a[i] = x - a[i - 1]; }
	}

	cout << ans << endl;
	//system("pause");
	return 0;
}

Measured memory_bytes: 1024
def main():
    N, A, B = map(int, input().split())
    s = input().strip()

    in_ = 0
    out_ = 0
    for i in range(N):
        if s[i] == "a":
            if in_ + out_ < A + B:
                print("Yes")
                in_ += 1
            else:
                print("No")
        elif s[i] == "b":
            if in_ + out_ < A + B and out_ < B:
                print("Yes")
                out_ += 1
            else:
                print("No")
        else:
            print("No")

if __name__ == "__main__":
    main()

Measured memory_bytes: 4016
#include<stdio.h>
int main(){
  int a[200000];
  int b,i,j;
  int minv,maxv=0;
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&a[i]);
  }
  minv=a[0];
  maxv=10*10*10*10*10*10*10*10*10*(-1);
  for(j=1;j<b;j++){
    if(maxv < a[j]-minv){
      maxv=a[j]-minv;
    }
    if(minv > a[j]){
      minv=a[j];
    }
  }
  printf("%d\n",maxv);
}


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

int main() {
	int n,m;
	cin>>n>>m;
	int card1[2*n+1],card2[2*n+1];
	for(int i=1; i<=2*n; i++)
		card1[i]=i;
	for(int i=1; i<=m; i++){
		int shu;
		cin>>shu;
		if(shu==0){
			for(int j=1; j<=n; j++)
				card2[2*j-1]=card1[j];
			for(int j=n+1; j<=2*n; j++)
				card2[(j-n)*2]=card1[j];
			for(int j=1; j<=2*n; j++)
				card1[j]=card2[j];
		}
		else{
			for(int j=shu+1; j<=2*n; j++)
				card2[j-shu]=card1[j];
			for(int j=1; j<=shu; j++)
				card2[2*n-shu+j]=card1[j];
			for(int j=1; j<=2*n; j++)
				card1[j]=card2[j];
		}
	}
	for(int i=1; i<=2*n; i++)
		cout<<card1[i]<<endl;
	return 0;
}

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

int main(){
  double w,h,n,a,b,c;
  cin>>w>>h>>n;
  double xl,xr,yu,yd;
  xl=0;
  xr=w;
  yu=h;
  yd=0;

  for(int i=0;i<n;i++){
    cin>>a>>b>>c;
    if(c==1 and xl<a){
      xl=a;
    } 
    else if(c==2 and xr>a){
      xr=a;
    }
    else if(c==3 and yd<b){
      yd=b;
    }
    else if(c==4 and yu>b){
      yu=b;
    }
    
    if((xr-xl)<=0 or (yu-yd)<=0){
		cout<<0;
     	break;
    }
  }
  if((xr-xl)>0 and (yu-yd)>0){
    cout<<(xr-xl)*(yu-yd);
  }
  
  
}


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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int n; cin >> n;
	unordered_map<string, int> freq;
	while (n--) {
		string s; cin >> s;
		freq[s]++;
	}
	int maxLen = 0;
	for (auto i: freq) {
		maxLen = max(i.second, maxLen);
	}
	vector<string> longest;
	for (auto i: freq) {
		if (i.second == maxLen) {
			longest.push_back(i.first);
		}
	}
	sort(longest.begin(), longest.end());
	for (auto i: longest) {
		cout << i << "\n";
	}
}



Measured memory_bytes: 25284
#include <iostream>

using namespace std;

int main()
{
    int n,cont=0;
    cin>>n;
    char c;
    string s,ss;
    cin>>s;
    for(int i=0;i<n-2;i++)
    {
        ss="";
        for(int j=0;j<3;j++)
            ss+=s[i+j];
        if(ss=="ABC")
            cont++;
    }
    cout<<cont<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    int ss,gg;
    cin>>s;
    for(int i=0;i<s.size();i++){
        if(s[i]=='A'){
            ss=i;
            break;
        }
    }
    for(int i=0;i<s.size();i++){
        if(s[s.size()-i-1]=='Z'){
            gg=s.size()-i-1;
            break;
        }
    }
    cout<<gg-ss+1<<endl;
}


Measured memory_bytes: 640
//2020-05-02 22:59:23
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
const int SIZE = 200000;
vector<vector<int>> A;
void make_A(int depth, vector<int> v, const int MAX, const int MAX_D){
    if (depth == MAX_D) {
        A.push_back(v);
        return;
    }
    for (int i = (*(v.end()-1)); i <= MAX; i++)
    {
        vector<int> vi = v;
        vi.push_back(i);
        make_A(depth+1, vi, MAX, MAX_D);
    }
    
}
int main() {
    cin.tie(nullptr); ios::sync_with_stdio(false);
    int N, M, Q; cin >> N >> M >> Q;
    struct query
    {
        int a, b, c, d;
        query(int a, int b, int c, int d) : a(a),b(b),c(c),d(d){}
    };
    vector<query> querys;
    for (int i = 0; i < Q; i++){
        int a, b, c, d;
        cin >> a >> b >> c >> d;
        querys.push_back(query(a, b, c, d));
    }
    vector<int> v_s;v_s.push_back(1);
    make_A(1, v_s, M, N);
    int ans = 0;
    for (int i = 0; i < A.size(); i++)
    {
        int score = 0;
        for (int j = 0; j < Q; j++)
        {
            if ((A[i][querys[j].b-1] - A[i][querys[j].a-1]) == querys[j].c)
                score += querys[j].d;
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
}

Measured memory_bytes: 6544
/**
 * @brief : c++ code for AtCoder
 * @author: rk222
 * @created: 2019.05.05 02:37:26
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */
int h, w;
int field[1010][1010];
queue<P> que;
char c;

int main() {
    scanf("%d%d", &h, &w);
    rep(i, h) rep(j, w) {
        scanf(" %c", &c);
        if (c == '#') {
            field[i][j] = 0;
            que.push(P(i, j));
        } else {
            field[i][j] = -1;
        }
    }

    while (!que.empty()) {
        int r = que.front().fr;
        int c = que.front().sc;
        que.pop();
        int dist = field[r][c];
        rep(i, 4) {
            int nr = r + dir_4[i][0];
            int nc = c + dir_4[i][1];
            if (!(0 <= nr && nr < h && 0 <= nc && nc < w))
                continue;
            if (field[nr][nc] != -1)
                continue;
            field[nr][nc] = dist + 1;
            que.push(P(nr, nc));
        }
    }

    int ret = 0;
    rep(i, h) rep(j, w) ret = max(ret, field[i][j]);

    printf("%d\n", ret);

    /* --------------------------------- */
    return 0;
}

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

int main(){
  long long N;
  cin >> N;
  long long sum=0;
  
  for(long long i=1;i<N+1;i++){
    if(i%3!=0&&i%5!=0){
      sum=sum+i;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 3684
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <tuple>
#include <climits>
#include <sstream>
using namespace std;

long long int a[1001], b[1001], c[1001];
int x, y, z, k;

//a*b*c, index
priority_queue<pair<long long int, long long int>> q;
set<long long int> s;

vector<long long int> res;

int main()
{
    cin >> x >> y >> z >> k;

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

    sort(a, a + x, greater<long long int>());
    sort(b, b + y, greater<long long int>());
    sort(c, c + z, greater<long long int>());

    q.push(make_pair(a[0] + b[0] + c[0], 0));
    s.insert(0);

    for (int i = 1; i <= k; i++)
    {
        pair<long long int, long long int> tmp;
        //一番大きいやつを結果に格納
        tmp = q.top();
        q.pop();
        //res.push_back(tmp.first);
        cout << tmp.first << endl;

        long long int ida, idb, idc;
        ida = (tmp.second / 10000 / 10000) % 10000;
        idb = (tmp.second / 10000) % 10000;
        idc = tmp.second % 10000;

        if (ida + 1 <= x - 1)
        {
            long long int id = (ida + 1) * 10000 * 10000 + idb * 10000 + idc;
            if (s.find(id) == s.end())
            {
                s.insert(id);
                q.push(make_pair(a[ida + 1] + b[idb] + c[idc], id));
            }
        }

        if (idb + 1 <= y - 1)
        {
            long long int id = ida * 10000 * 10000 + (idb + 1) * 10000 + idc;
            if (s.find(id) == s.end())
            {
                s.insert(id);
                q.push(make_pair(a[ida] + b[idb + 1] + c[idc], id));
            }
        }

        if (idc + 1 <= z - 1)
        {
            long long int id = ida * 10000 * 10000 + idb * 10000 + (idc + 1);
            if (s.find(id) == s.end())
            {
                s.insert(id);
                q.push(make_pair(a[ida] + b[idb] + c[idc + 1], id));
            }
        }
    }
}

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

typedef long double     lf;

using namespace std;

const lf EPS = 1e-9;

struct pt {
  lf x, y;
  pt( ) { }
  pt( lf x, lf y ) : x( x ), y ( y ) { }
};

inline lf x( pt P ) { return P.x; }
inline lf y( pt P ) { return P.y; }

istream& operator >> ( istream& in, pt& p ) {
  lf x,y; in >> x >> y;
  p = pt(x,y); return in;
}

ostream& operator << ( ostream& out, const pt& p ) {
  out << double(p.x) << " " << double(p.y);
  return out;
}

pt operator + ( const pt& A, const pt& B ) {
  return pt( x(A)+x(B), y(A)+y(B) );
}

pt operator - ( const pt& A, const pt& B ) {
  return pt( x(A)-x(B), y(A)-y(B) );
}


pt operator * ( const lf& B, const pt& A ) {
  return pt( x(A)*B, y(A)*B );
}

pt operator * ( const pt& A, const lf& B ) {
  return pt( x(A)*B, y(A)*B  );
}

inline lf dot( pt A, pt B ) {
  return x(A)*x(B) + y(A)*y(B);
}

inline lf norm( pt A ) {
  return x(A)*x(A) + y(A)*y(A);
}

inline lf abs( pt A ) {
  return sqrt( norm(A) );
}

inline lf dist ( pt A, pt B ) { return abs( B - A ); }

lf distToLine (pt p, pt A, pt B, pt &c) {
  lf u = dot( p-A , B-A ) / norm( B-A );
  c = A + u*( B-A );
  return dist( p , c );
}

pt refPoint(pt X, pt A, pt B) {
  pt aux; distToLine(X, A, B, aux);
  return X + lf(2.0)*(aux-X);
}

inline bool same ( lf a, lf b ) {
  return a+EPS > b && b+EPS > a;
}

inline lf cross( pt A, pt B ) {
  return x(A)*y(B) - y(A)*x(B);
}

///CHANGE
// 0  for collineal points ( angle = 0 )
// 1  for angle BAX counter clockwise
// -1 for angle BAX clockwise
inline int ccw (pt X, pt A, pt B) {
  lf c = cross( B-A, X-A );
  if( same( c, 0.0 ) ) { return 0; }
  if( c > EPS ) { return 1; }
  return -1;
}

///CHANGE
inline bool segContains ( pt X, pt A, pt B) {
  if ( !same ( 0, cross ( A-X, B-X ) ) ) return 0;
  return ( dot ( A-X, B-X ) < EPS );
}

inline bool parallel( pt A, pt B, pt C, pt D ) {
  return same ( 0, cross( B-A, D-C ) );
}

///NEW
inline bool ortho( pt A, pt B, pt C, pt D ) {
  return same ( 0, dot( B-A, D-C ) );
}

inline bool samePt ( pt A, pt B ) {
  return same ( x(A), x(B) ) && same ( y(A), y(B) );
}

pt linesIntersection ( pt A, pt B, pt C, pt D ) {
  lf x = cross ( C, D-C ) - cross ( A, D-C );
  x /= cross ( B-A, D-C );
  return A + x*(B-A);
}

inline bool collinearSegsIntersects ( pt A, pt B, pt C, pt D ) {
  return segContains(A,C,D) || segContains(B,C,D)
      || segContains(C,A,B) || segContains(D,A,B);
}

bool segmentsIntersect(pt A, pt B, pt C, pt D) {
  if( samePt(A,B) )
    return segContains( A, C, D );
  if( samePt(C,D) )
    return segContains( C, A, B );
  if( parallel(A,B,C,D) )
    return collinearSegsIntersects( A,B,C,D );
  pt aux = linesIntersection(A,B,C,D);
  return segContains(aux,A,B) && segContains(aux,C,D);
}

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

int n;

int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);

  cin >> n;
  for( int i = 0; i < n; ++i ) {
    pt A,B,C,D;
    cin >> A >> B >> C >> D;
    if( segmentsIntersect( A, B, C, D ) ) {
      cout << linesIntersection( A,B,C,D ) << '\n';
    }
    else {
      assert(false);
    }
  }
}

Measured memory_bytes: 3304
#define rep(i, n) for (int i = 0; i < (n); ++i)

#include <iostream>
#include <iomanip>
#include <math.h>

using namespace std;

const int INF = 1001001001;
// 10^ vector: 可変長配列
int main()
{
  long double a, b, ans;

  cin >> a >> b;

  cout << fixed << setprecision(0) <<floor(a*b) <<endl;

  return 0;
}

Measured memory_bytes: 3800
X, K, D = map(int, input().split())
num = abs(X) // D
if num >= K and X >= 0:
  print(abs(X - K*D))
elif num >= K and X < 0:
  print(abs(X + K*D))
elif num < K and X >= 0:
  rest = K - num
  print(abs(X - num*D - D*(rest%2)))
else:
  rest = K - num
  print(abs(X + num*D + D*(rest%2)))

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

using namespace std;

#define SPEED ios::sync_with_stdio(0),cin.tie(0);

const int N = 100005;
int n, a[N];

int main() 
{
    SPEED
    string s;
    cin >> s;
    while (true)
    {
        bool b = 1;
        for (int i = 1; i < s.size(); i++)
        {
            if (s[i] != s[i - 1]) b = 0;
        }
        if (b) break;
        int x = stoi(s);
        x++;
        s = to_string(x);
    }
    cout << s;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define BUGAVOID(x) x
#define rep(...) BUGAVOID(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define sz(c) (int)(c.size())
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T, class U>using vp = vector<pair<T, U>>;
template<class T>using vv = vector<vector<T>>; template<class T, class U>using vvp = vv<pair<T, U>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MAX = 1e5 + 5, MOD = 1e9 + 7;
constexpr ll LINF = 1ll << 60; constexpr double EPS = 1e-6;
constexpr int dy[4] = { 0,1,0,-1 }, dx[4] = { 1,0,-1,0 };
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

int N;
string S;

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

    for (int sw = 0; sw < 4; ++sw) {
        vector<bool> ans(N, false);
        ans[0] = sw & 1;
        ans[1] = sw & 2;
        
        bool ans_last = ans[0] ^ ans[1] ^ (S[0] == 'x');

        rep(i, 1, N - 1) {
            ans[i + 1] = ans[i] ^ ans[i - 1] ^ (S[i] == 'x');
        }
        
        if (ans_last == ans[N - 1] && (ans[N - 1] ^ (S[N - 1] == 'x')) == (ans[N - 2] ^ ans[0])) {
            rep(i, N) {
                if (ans[i]) {
                    cout << 'W';
                }
                else {
                    cout << 'S';
                }
            }
            write("");
            return 0;
        }
    }
    write(-1);
}

Measured memory_bytes: 592
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    # dp[i] = min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2])
    N = read_int()
    h = read_ints()
    dp = [0, abs(h[1]-h[0])]
    for i in range(2, N):
        dp.append(min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]))
    return dp[-1]


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 13924