akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict

N = int(input())
sdict = defaultdict(int)
for i in range(N):
  sdict[input()] += 1

mx = 0
for key, val in sdict.items():
  mx = max(mx, val)

ls = []
for key, val in sdict.items():
  if val == mx:
    ls.append(key)

ls.sort()
for s in ls:
  print(s)

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
const int N = 1e4+50;
const ll oo = 1e18;
const ll mod = 1e9+7;


int main(){
    // 9opl.
    int n,i;
    cin>>n>>i;
    cout<<n-i+1<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]

use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
macro_rules! chmax {
    ($x:expr, $e:expr) => {
        $x = max($x, $e);
    };
}
macro_rules! chmin {
    ($x:expr, $e:expr) => {
        $x = min($x, $e);
    };
}

const INF: i64 = 1 << 60;

fn main() {
    input!{
        N: usize,
        K: usize,
        h: [i64; N],
    }
    let mut dp = vec![INF; N];
    dp[0] = 0;
    for i in 1..N {
        for k in 1..(K+1) {
            if i >= k {
                chmin!(dp[i], dp[i-k] + (h[i] - h[i-k]).abs());
            }
        }
    }
    println!("{}", dp[N-1]);
}


Measured memory_bytes: 6396
#include<iostream>
#include<vector>
#include<string>
#include<math.h>
#include<iomanip>
#include<algorithm>

using namespace std;

int main(){

    long long a,b=0,x=0;                    
  	cin>>a;
    while(a>0){
        a/=2;
        b+=1;
    }
    for(int i=0;i<b;i++){
        x+=pow(2,i);
    }
    cout<< x << endl;

}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<deque>
#include<list>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

string R = "IVXLCDM";
int r[7] = { 1,5,10,50,100,500,1000 };

int RtoA(string s) {
	int re = 0, si = s.size();
	if (si >= 2) {
		for (int i = 6; i >= 0; i--) {
			int a = s.find(R[i]);
			//cout << a << endl;
			if (a != -1) {
				//cout << RtoA(s.substr(0, a)) << " " << RtoA(s.substr(a + 1)) << endl;
				re = r[i] - RtoA(s.substr(0, a)) + RtoA(s.substr(a + 1));
				break;
			}
		}
	}
	else if (si == 1)
		re = r[R.find(s)];

	return re;
}

int main() {
	for (string s; cin >> s;)
		cout << RtoA(s) << endl;
	return 0;
}

Measured memory_bytes: 1196
// AOJ 0228
#include <iostream>
#include <string>

using namespace std;

int main()
{
	string data[10];
	data[0] = "0111111";
	data[1] = "0000110";
	data[2] = "1011011";
	data[3] = "1001111";
	data[4] = "1100110";
	data[5] = "1101101";
	data[6] = "1111101";
	data[7] = "0100111";
	data[8] = "1111111";
	data[9] = "1101111";

	int n;
	while (cin >> n){
		if (n == -1) break;
		string str = "";
		int a;
		cin >> a; cout << data[a] << endl;
		str = data[a];
		for (int i = 0; i < n - 1; i++){
			cin >> a;
			string out;
			for (int j = 0; j < 7; j++){
				if (str[j] != data[a][j]) out += '1';
				else out += '0';
			}
			cout << out << endl;
			str = data[a];
		}
	}

	return 0;
}

Measured memory_bytes: 1204
h,n=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(n)]
inf=float('inf')
dp=[inf]*(h+1)
# dp[i]:ダメージiを与えるための最小魔力
dp[0]=0
for a,b in ab:
  # a:ダメージ,b:魔力
  ndp=[inf]*(h+1)
  ndp[0]=0
  for i in range(1,h+1):
    ndp[i]=min(dp[i],ndp[max(0,i-a)]+b)
  dp=ndp
print(dp[h])

Measured memory_bytes: 91532
#include <stdio.h>
 
int main(void)
{
    int a[10000],n,i,max,min;
    long long int sum;

    scanf("%d %d",&n,&a[1]);

    max=a[1];
    min=a[1];
    sum=a[1];

    for(i=2;i<=n;i++){
        scanf("%d",&a[i]);
        if(max<a[i]){
            max=a[i];
        }
        if(min>a[i]){
            min=a[i];
        }
        sum=sum+a[i];
    }
    printf("%d %d %lld\n",min,max,sum);

    return 0;
}

Measured memory_bytes: 1860
n=int(input())
for i in range(1,3501):
  for j in range(1,3501):
    if 4*i*j-n*j-n*i>0 and i*j*n/(4*i*j-n*j-n*i)%1==0:
      print(i,j,int(i*j*n/(4*i*j-n*j-n*i)))
      exit()

Measured memory_bytes: 67220
from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
d = defaultdict(int)
for i in a:
    d[i] += 1
ans = 0
for v in d.values():
    ans += v * (v - 1) // 2
for i in a:
    v = d[i]
    print(ans - v * (v - 1) // 2 + (v - 1) * (v - 2) // 2)

Measured memory_bytes: 88012
N=int(input())
X=list(map(int,input().split()))
S=sorted(X)
l=S[int((N/2)-1)]
r=S[int(N/2)]
d=(l+r)/2
for i in range(N):
    if(X[i]>d):
        print(l)
    elif(X[i]<d):
        print(r)
    else:
        print(X[i])

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

int main(){
  int n;
  while(cin>>n&&n){
    if(n==2){
      int ans;cin>>ans;cout<<ans<<endl;continue;
    }
    int ans=0;
    for(int i=0;i<((n*(n-1))/2);++i){
      int tmp; cin>>tmp;
      ans+=tmp;
    }
    cout<<ans/(n-1)<<endl;
  }

  return EXIT_SUCCESS;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define MAX 60000


int main(void){
	int n;
	cin >> n;
	int p[MAX+10];

	for(int i = 0; i < MAX; i++){
		p[i] = 1;
	}
	p[0]=0; p[1]=0;
	for(int i = 2; i < sqrt(MAX); ++i){
		if(p[i]){
			for(int j = 2; j*i < MAX; ++j){
				p[j*i] = 0;
			}
		}
	}
	int i = 0, j = 0;
	vector<int> ans;
	while(true){
		++i;
		if(p[i]){
			if(i%5==1){
				ans.push_back(i);
				++j;
			}
		}
		if(j==n)break;
	}

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

	cout << endl;
	return 0;
}

Measured memory_bytes: 512
s = input()
a = 'keyence'
flag = 1

if s == a:
    print('YES')
    flag = 0

for i in range(1,len(s)-6):
    #iは取り除く文字列の長さ
    for j in range(len(s)-i+1):
        if s[0:j]+s[j+i:] == a:
            print('YES')
            flag = 0
            break

if flag == 1:
    print('NO')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
typedef long long ll;
int n;

int main(){
    bool sunny=false;
    int count=0;
    int ans=0;
    for(int i=0; i<3; i++){
        char c; cin >> c;
        if(c=='R'){
            count++;
            sunny=false;
        }else{
            if(sunny) continue;
            ans=count;
            count=0;
            sunny=true;
        }
    }
    cout << max(ans,count) << "\n";
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pl = pair<ll,ll>;
using pi = pair<int,int>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;

signed main(){
	//cout << fixed << setprecision(10);
    int n; cin >> n;
    string s; cin >> s;
    map<char ,ll> mp;
    ll a = 0 , b = 0, c = 0;
    rep(i,0,n){
        a += (s[i] == 'R');
        b += (s[i] == 'B');
        c += (s[i] == 'G');
    }
    ll ans = a * b * c;
    rep(i,0,n){
        ll cnt = 1;
        while(true){
            ll j = i + cnt;
            ll k = j + cnt;
            if(k >= n)break;
            if(s[i] != s[j] && s[j] != s[k] && s[i] != s[k])--ans;
            cnt++;
        }
    }
    cout << ans << endl;


	return 0;
}

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

int main()
{
    typedef long long ll;
    int N;
    cin >> N;
    map<string,int> paper;

    for(int i=0; i<N; i++)
    {
        string a;
        cin >> a;
        auto itr = paper.find(a);
        if(itr==paper.end())
        {
            paper[a] = 1;
        }else
        {
            paper.erase(itr);
        }
    }

    cout << paper.size() << endl;
    return 0;
}

Measured memory_bytes: 11364
#include <algorithm>
#include <bitset>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define ll long long
#define pb push_back
#define debug1(x) cerr << #x << " = " << x << '\n';
#define debug2(x, y) cerr << #x << " = " << x << "   " << #y << " = " << y << "\n";
#define _ ios_base::sync_with_stdio(0);cin.tie(NULL);

void solve() {
    ll n, x, t;
    cin >> n >> x >> t;
    ll num = (n/x);
    if(n%x != 0) num ++;
    cout << (num * t) << '\n';
}

int main() {_
    int t = 1;
//    cin >> t;
    for(int i = 1; i<=t; i++) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 3648
#include <stdio.h>

int main() {
  char a = getchar();
  if (a == 'A') printf("T\n");
  else if (a == 'T') printf("A\n");
  else if (a == 'C') printf("G\n");
  else if (a == 'G') printf("C\n");
  return 0;
}


Measured memory_bytes: 128
import java.io.*
import java.util.*

fun solve(N: Long, A: LongArray){
    A.withIndex().sortedBy{ it.value }.map{ it.index + 1 }.joinToString(separator=" ").let{ println(it) }

    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toLong()
    val A = LongArray(N.toInt())
    for (i in 0 until N.toInt()) {
        A[i] = sc.next().toLong()
    }
    solve(N, A)
}



Measured memory_bytes: 84128
#include <iostream>
#include <cmath>
#include <algorithm>

#define REP(i,n) for(int i = 0; i < (n); i++)
#define REPC(x,c) for(auto x:(c))
#define FOR(i, b, e) for(int i = (b); i < (e); i++)
#define vec vector<string>

using namespace std;


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


	int k2 = pow(2, k);
	int m = 0;
	m = max(a*k2 + b + c, a + b*k2 + c);
	m = max(m, a + b + c * k2);

	cout << m << endl;
}


Measured memory_bytes: 384
def priwa():
    print('WA')


# input
s = list(input())
# calc
if s[0] == 'A':
    s.pop(0)
    if s[0].islower() == True:
        s.pop(0)
        if s[0:len(s)-1].count('C') == 1:
            s.remove('C')
            for i in s:
                if i.islower() == False:
                    priwa()
                    exit()
            print('AC')
        else:
            priwa()
    else:
        priwa()
else:
    priwa()


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

int main()
{
  int N,M,b,n=0,b1[20],b2[20],b3[20],p[20],s1[20],s2[20];
  int c1=10000000,c2=10000000,c=0;
  cin>>N>>M;
  for(int i=0;i<N;i++){
    cin>>b;
    b1[i]=b2[i]=b;
    if(b==1)n++;
  }
  for(int i=0;i<M;i++)cin>>p[i];
  for(int i=1;i<M;i++)p[i]+=p[i-1];
  
  for(int i=0;i<p[0];i++)s1[i]=0;
  for(int i=1;i<M;i++){
    for(int j=p[i-1];j<p[i];j++)s1[j]=i%2;
  }
  for(int i=0;i<p[0];i++)s2[i]=1;
  for(int i=1;i<M;i++){
    for(int j=p[i-1];j<p[i];j++)s2[j]=(i+1)%2;
  }

  for(int i=0;i<N;i++)if(s1[i]==1)c++;
  if(c==n){
    c1=0;
    for(int i=0;i<N;i++){
      if(b1[i]!=s1[i]){
	for(int j=i+1;j<N;j++){
	  if(b1[j]==s1[i]){
	    for(int k=j;k>i;k--){
	      swap(b1[k-1],b1[k]);
	      c1++;
	    }
	    break;
	  }
	}
      }
    }
  }
  c=0;
  for(int i=0;i<N;i++)if(s2[i]==1)c++;
  if(c==n){
    c2=0;
    for(int i=0;i<N;i++){
      if(b2[i]!=s2[i]){
	for(int j=i+1;j<N;j++){
	  if(b2[j]==s2[i]){
	    for(int k=j;k>i;k--){
	      swap(b2[k-1],b2[k]);
	      c2++;
	    }
	    break;
	  }
	}
      }
    }
  }
  cout<<min(c1,c2)<<endl;
  return 0;
}

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



int main() {
  string s, t;
  cin >> s >> t;
  int ss = s.size();
  int ans=0;
  rep(i, ss){
    if(s[i] != t[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3912
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int n;
vector<vector<vector<double> > > dp;

double dfs(int x, int y, int z) {
    debug(x,y,z);
  if (dp[x][y][z] != -1) return dp[x][y][z];
  double res = 1.0 * n;
  if (x-1 >= 0) res += dfs(x-1,y,z) * x;
  if (y-1 >= 0 && x+1 <= n) res += dfs(x+1,y-1,z) * y; //xが増えまくったらyが負になるからスルーされる
  if (z-1 >= 0 && y+1 <= n) res += dfs(x,y+1,z-1) * z;
  res /= (x+y+z);
  dp[x][y][z] = res;
  return dp[x][y][z];
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  cin >> n;
  vector<int> a(n);
  vector<int> cnt(3,0);
  rep(i,n) {
    cin >> a[i];
    cnt[a[i]-1]++;
  }
  dp = vector<vector<vector<double> > >(n+5, vector<vector<double> >(n+5, vector<double>(n+5,-1)));
  dp[0][0][0] = 0;
  cout << dfs(cnt[0],cnt[1],cnt[2]) << endl;
  return 0;
}

Measured memory_bytes: 225664
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
#include <cctype>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

locale l = locale::classic();

int main(){
    int x,a;
    cin >> x >> a;
    if(x<a) cout << 0 << endl;
    else cout << 10 << endl;
}

Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline


def readstr():
    return input().strip()


def readint():
    return int(input())


def readnums():
    return map(int, input().split())


def readstrs():
    return input().split()


def main():
    A, B, H, M = readnums()
    d = min(0.5 * (H * 60 + M) - 6 * M, 360 - (0.5 * (H * 60 + M) - 6 * M))
    print(math.sqrt(A ** 2 + B ** 2 - 2 * A * B * math.cos(math.radians(d))))


if __name__ == "__main__":
    main()


Measured memory_bytes: 9520
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ta = [list(map(int, readline().split())) for _ in range(n)]
t, a = ta.pop(0)
for tt, aa in ta:
    v = max((t + tt - 1) // tt, (a + aa - 1) // aa)
    t = v * tt
    a = v * aa
print(t + a)


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=200005;
long long tree[N];
long long ans;
long long n,k;
struct node
{
    long long tot,id;
}sum[N];
long long lowbit(long long x)
{
    return x&(-x);
}
void modify(long long x)
{
    if (x==0)
    {
      tree[x]++;
      return;
    }
    while (x<=n)
    {
        tree[x]++;
        x+=lowbit(x);
    }
}
long long add(long long x)
{
    long long sum1=tree[0];
    while (x>0)
    {
        sum1+=tree[x];
        x-=lowbit(x);
    }
    return sum1;
}
bool cmp(node a,node b)
{
    if (a.tot==b.tot)
        return a.id < b.id;
    return a.tot < b.tot;
}
int main()
{
    scanf("%lld%lld",&n,&k); 
    sum[0].id=0;
    sum[0].tot=0;
    for (long long i=1;i<=n;i++)
    {
        long long x;
        scanf("%lld",&x);
        sum[i].tot=sum[i-1].tot+x-k;
        sum[i].id=i;
    }
   
    sort(sum,sum+1+n,cmp);
    ans = 0;
    for (long long i=0;i<=n;i++)
    {
       if (sum[i].id>0) ans+=add(sum[i].id-1);
       modify(sum[i].id);

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

Measured memory_bytes: 4992
N = int(input())
A = list(map(int, input().split()))

M = max(A)
m = min(A)
print(2*N-2)

if M+m >= 0:
  a = A.index(M)
  for i in range(N):
    if i != a:
      #A[i] += M
      print(a+1, i+1)
  for i in range(N-1):
    #A[i+1] += A[i]
    print(i+1, i+2)
else:
  a = A.index(m)
  for i in range(N):
    if i != a:
      print(a+1, i+1)
  for i in range(N, 1, -1):
    print(i, i-1)

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


ll mod = 1e9+7;

ll modpower(ll a, ll r){ //a^r
    ll x = 1;
    while (r > 0) {
        if (r & 1) x = x * a % mod;
        r >>= 1;
        a = a * a % mod;
    }
    return x;
}

ll modinv(ll a){
    return modpower(a, mod-2);
}


int main(){
    ll N, A, B, C;
    cin >> N >> A >> B >> C;
    A = (A*modinv(100))%mod;
    B = (B*modinv(100))%mod;
    C = (C*modinv(100))%mod;
    ll ans = 0;
    ll I1 = modpower(A, N) * modinv(modpower(mod+1-C, N+1)) % mod;
    ll I2 = modpower(B, N) * modinv(modpower(mod+1-C, N+1)) % mod;
    ll J1 = A*modinv(mod+1-C) % mod;
    ll J2 = B*modinv(mod+1-C) % mod;
    ll T = N;
    
    ans += I1*T%mod;
    for (int K = 1; K <= N-1; K++) {
        T = (T*(N+K)%mod)*modinv(K)%mod*J2%mod;
        ans += I1*T%mod;
    }
    
    
    T = N;
    ans += I2*T%mod;
    for (int K = 1; K <= N-1; K++) {
        T = (T*(N+K)%mod)*modinv(K)%mod*J1%mod;
        ans += I2*T%mod;
    }
    cout << ans%mod << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
using namespace std;
int main() {
    int n;
    cin>>n;
    string a,t;
    cin>>a>>t;
    string f;
    for(int i=0;i<n;i++) {
        f=f+a[i];
        f=f+t[i];
    }
    cout<<f<<endl;
    return 0;
}

Measured memory_bytes: 256
n=int(input())
p=[0]*(n+1)
for i in range(n):
    p[i],p[i+1]=map(int,input().split())

dp=[[10**10]*(n) for i in range(n)]    
#dp=[[0]*(n+1) for i in range(n+1)]    
    
#dp[0][1]=p[0]*p[1]*p[2]
dp[0][0]=0
for j in range(1,n):
    for i in range(j,-1,-1):
#        print("-------------i:",i,"j:",j)
        if j==i:
            dp[i][j]=0
#            print("i:",i,"j:",j,"k:",999)
        else:
#            for k in range(i+1,j):
            for k in range(j-1,i-1,-1):
#                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i-1]*p[k]*p[j])
                dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]+p[i]*p[k+1]*p[j+1])
#                print("i:",i,"j:",j,"k:",k)
#                print(dp[i][j],dp[i][k],dp[k+1][j],p[i-1]*p[k]+p[j])
print(dp[0][n-1])


Measured memory_bytes: 5652
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>
using ll = int_fast64_t;
using P = std::pair<ll,ll>;

#define REP(i,b,e) for(ll i=b; i<e; i++)
#define ALL(vec) vec.begin(),vec.end()
#define PRINT(vec) printf("[ ");for(auto &i:vec)printf("%ld ",i);puts("]");
#define SCAN(vec) for(auto &i:vec)scanf("%ld",&i)
#define fi first
#define se second


ll h, w, K;
ll val[3000][3000] = {};
ll dp[3000][3000][4] = {};

int main(){
	scanf("%ld %ld %ld", &h, &w, &K);
	
	REP(i, 0, K){
		ll r, c, v;
		scanf("%ld %ld %ld", &r, &c, &v);
		val[r-1][c-1] = v;
	}

	//REP(i, 0, h){PRINT(val[i]);}

	dp[0][0][1] = val[0][0];
	REP(i, 0, h){
		REP(j, 0, w){
			REP(k, 0, 4){
				if(i>=1) dp[i][j][0] = std::max(dp[i][j][0], dp[i-1][j][k]);
				if(j>=1) dp[i][j][k] = std::max(dp[i][j][k], dp[i][j-1][k]);
			
			}
			REP(k, 1, 4){
				if(j>=1) dp[i][j][k] = std::max(dp[i][j][k], dp[i][j-1][k-1]+val[i][j]);
			}
			REP(k, 1, 5){
				if(i>=1) dp[i][j][1] = std::max(dp[i][j][1], dp[i-1][j][k-1]+val[i][j]);
			}
		}
	}
	
	/*
	REP(i, 0, h){
		REP(j, 0, w){
			REP(k, 0, 4) printf("%ld ", dp[i][j][k]);
			printf("   ");
		}
		puts("");
	}
	*/

	ll ans = 0;
	REP(i, 0, 4){
		ans = std::max(ans, dp[h-1][w-1][i]);
	}
	printf("%ld\n", ans);
	return 0;
}



Measured memory_bytes: 355192
/**
 *    author:  otera    
**/
#include<iostream>
#include<string> 
#include<cstdio>
#include<cstring>
#include<vector>
#include<cmath>
#include<algorithm> 
#include<functional>
#include<iomanip>
#include<queue>
#include<deque>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

//#define int long long
typedef long long ll;
typedef unsigned long long ul;
typedef unsigned int ui;
typedef long double ld;
const int inf=1e9+7;
const ll INF=1LL<<60 ;
const ll mod=1e9+7 ;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<int, int> P;
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }

void solve() {
	int x, y; cin >> x >> y;
    int B = y - 2 * x, A = 4 * x - y;
    if(A >= 0 && B >= 0 && A % 2 == 0 && B % 2 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(10);
	//int t; cin >> t; rep(i, t)solve();
	solve();
    return 0;
}

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

int main(){
    string st;
    while(true){
        cin>>st;
        if(st=="0") break;
        int n=st.size();
        int sum=0;
        rep(i,n){
            sum+=st[i]-'0';
        }
        cout<<sum<<endl;
    }
    
}


Measured memory_bytes: 3092
from heapq import heappush, heappop
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations
import sys
import bisect
import string
#import math
#import time
#import random
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def StoI():
    return [ord(i)-97 for i in input()]
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
#ts=time.time()
#sys.setrecursionlimit(10**6)
input=sys.stdin.readline
show_flg=False
#show_flg=True

n,k=MI()
a=LI()

def slidmin(a,k):
    n=len(a)
    b=[0 for i in range(n-k+1)]
    q=deque()
    for i in range(k):
        while q and a[q[-1]]>=a[i]:
            q.pop()
        q.append(i)
    b[0]=a[q[0]]
    s=len(q)
    for i in range(k,n):
        while q and a[q[-1]]>=a[i]:
            q.pop()
            s-=1
        q.append(i)
        s+=1
        if q[0]<=i-k:
            q.popleft()
            s-=1
        b[i-k+1]=a[q[0]]
    return b

m=slidmin(a,k)
M=[-i for i in slidmin([-i for i in a],k)]
ans=1
p=-1
c=0
for i in range(k):
    if p<a[i]:
        c+=1
    else:
        c=1
    p=a[i]
fl=True if c==k else False

for i in range(n-k):
    if p<a[i+k]:
        c+=1
    else:
        c=1
    p=a[i+k]
    
    inc=1
    if c==k:
        if fl:
            inc=0
        fl=True
    if a[i]==m[i] and a[i+k]==M[i+1]:
        inc=0
    ans+=inc
print(ans)


Measured memory_bytes: 100944
#include<bits/stdc++.h>
using namespace std;
string st ;
stack < char > s ;
int main()
{
    	cin >>  st ;
        int l = st.size() ;
        for ( int i = 0 ; i < st.size(); i ++ )
	{
            if ( st[i] == 'T' )
	    {
                if ( !s.empty() )
		{
                    if ( s.top() == 'S' ){
                        l -= 2 ;
                        s.pop() ;
                    }
                }
		else
		s.push( st[i] ) ;
            }
	    else
		    s.push( st[i] ) ;
        }
        cout << l << endl ;
    return 0 ;
}

Measured memory_bytes: 640
from collections import OrderedDict
result = OrderedDict()
N, K = map(int, input().split())
for i in range(N):
    a,b = map(int, input().split())
    if a in result:
        result[a] += b
    else:
        result[a] = b
result = sorted(result.items())
for k,v in result:
    if K > v:
        K -= v
    else:
        print(k)
        exit()

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

int main()
{
	int A, B, M;
	int ans;
	int t, tx, ty, tc;
	int min;
	int minA = MAX_N;
	int minB = MAX_N;
	cin >> A >> B >> M;
	int a[A];
	int b[B];
	// int x[M];
	// int y[M];
	// int c[M];
	int x, y, c;
	rep(i, A)
	{
		cin >> a[i];
		if(minA>a[i])
			minA = a[i];
		// cout << a[i];
	}
	rep(i, B)
	{
		cin >> b[i];
		if(minB>b[i])
			minB = b[i];
		// cout << b[i];
	}
	min = minA + minB;
	rep(i, M)
	{
		cin >> x >> y >> c;
		// cout <<a[x-1]<<endl;
		ans = a[x - 1] + b[y - 1] - c;
		// cout << i << ":" << ans<<endl;
		if (min > ans)
			min = ans;
	}
	printf("%d", min);

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
const int M = 1e5+10;
bool is[M];
int dp[M];
main(){
	is[1]=1;
	for(int i=2;i<M;i++)
		if(!is[i])
			for(int j=2*i;j<M;j+=i)
				is[j]=1;
	for(int i=1;i<M;i++){
		int ok=(i%2)*(!is[i]&!is[(i+1)/2]);
	//	cout<<ok<<" "<<is[i]<<endl;
		dp[i]=ok+dp[i-1];
	}
	int q;cin>>q;
	while(q--){
		int l,r;cin>>l>>r;
		cout<<dp[r]-dp[l-1]<<endl;
	}
}

Measured memory_bytes: 1152
import Data.List
import qualified Data.Map as Map

f::Int->Int->[Int]
f 0 _=[]
f n k=(n `mod` k):f (n-1) k

f2 ::Int->[[Int]]->[(Int,Int)]
f2 _ []=[]
f2 k (x:xs)=if (head x)*2 `mod` k==0 then ((k-(head x)) `mod` k,(length x)):f2 k xs else f2 k xs

f3 ::[[Int]]->[(Int,Int)]
f3 []=[]
f3 (x:xs)=(head x,length x):f3 xs

f4 :: [(Int,Int)]->[(Int,Int)]->Int
f4 [] _=0
f4 _ []=0
f4 ((x,x2):xs) ((y,y2):ys)
       |x<y=f4 xs ((y,y2):ys)
       |x>y=f4 ((x,x2):xs) ys
       |otherwise=x2^2*y2+f4 xs ((y,y2):ys) 
main = do
       a<-getLine
       let (n:k:[])=(map read . words) a::[Int]
           as=group $ sort $ f n k
           bs= Map.toList $ Map.fromListWith (+) $ f2 k as
           cs=f3 as
       print $ f4 bs cs

Measured memory_bytes: 25980
#!/usr/bin/env python3
import sys


def solve(S: str):
    print(S[0:3])
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)

if __name__ == '__main__':
    main()


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

using namespace std;

int main()
{
  int N, num[101];
  cin >> N;
  for(int i = 0; i < N; i++) cin >> num[i];

  long long dp[101][21] = {{0}};
  dp[0][num[0]] = 1;
  for(int i = 1; i < N-1; i++){
    for(int j = 0; j <= 20; j++){
      if(j - num[i] >= 0) dp[i][j - num[i]] += dp[i-1][j];
      if(j + num[i] <= 20) dp[i][j + num[i]] += dp[i-1][j];
    }
  }

  cout << dp[N-2][num[N-1]] << endl;
  
  return 0;
}

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

int main()
{
  int n, max = 0;
  map<string, int> s;
  cin >> n;
  for (int i = 0; i < n; i++)
  {
    string tmp;
    cin >> tmp;
    s[tmp]++;
  }
  for (auto &item : s)
  {
    if (max < item.second)
    {
      max = item.second;
    }
  }
  for (auto &item : s)
  {
    if (max == item.second)
    {
      cout << item.first << endl;
    }
  }
}


Measured memory_bytes: 25216
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T>void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T>void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U>bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U>bool isin(T el, U container) { return find(all(container), el) != container.end(); }
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<class T>bool even(T n) { return ! (n & 1); }
template<class T>bool odd(T n) { return n & 1; }
template<class T>ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T>ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
ll intpow(ll a,ll n){ll p=1;while(n){if(n&1)p*=a;a*=a;n>>=1;}return p;} 
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;

std::vector<std::pair<char, long long> > runlength(std::string str)
{
        std::vector<std::pair<char, long long> > enc;
        long long strsize = static_cast<long long>(str.size());

        char now = str[0];
        long long cnt = 0;
        for (long long i = 0; i < strsize; ++i) {
                if (str[i] == now) {
                        ++cnt;
                } else {
                        enc.push_back(std::pair<char, long long>(now, cnt));
                        now = str[i];
                        cnt = 1;
                }
        }
        enc.push_back(std::pair<char, long long>(now, cnt));
        return enc;
}

int main()
{
        string S;
        cin >> S;
        auto v = runlength(S);
        ll ans = 0;
        rep(i, 0, len(v)) {
                if (v[i].first == 'R') {
                        chmax(ans, v[i].second);
                }
        }
        cout << ans << endl;
}


Measured memory_bytes: 3596
G1 = [1,3,5,7,8,10,12]
G2 = [4,6,9,11]
G3 = [2]
X,Y = map(int,input().split())
if X in G1 and Y in G1:print('Yes')
elif X in G2 and Y in G2:print('Yes')
elif X in G3 and Y in G3:print('Yes')
else:print('No')

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

int f(bool turnTaro, vector<int>& A, int K, vector<vector<int>> &dp){
	if(K==0 and turnTaro)
      	// Taro loses as Jiro made K == 0
      	return 0;
 	else if(K==0 and !turnTaro)
      	// Taro wins as Taro made K==0
      	return 1;
  	else if(K<0 and turnTaro)
      	// Means Jiro Lost as he made K negative
      	return 1;
  	else if(K<0 and !turnTaro)
      	// Taro made K negative so he lost
      	return 0;
  	
  	if(dp[turnTaro][K]!=-1)
      	return dp[turnTaro][K];
  
  	int res;
  	if(turnTaro)
      	res = 0;
  	else
  		res = 1;
  
  	for(int i=0;i<A.size();i++) {
      	if(turnTaro)
	  		res = max(res, f(!turnTaro, A, K - A[i], dp));
      	else 
          	res = min(res, f(!turnTaro, A, K - A[i], dp));
    }
  
  	dp[turnTaro][K] = res;
  	return res;
}

int main() {
  	int N, K;
  	cin>>N>>K;
  	vector<int> A(N,0);
  	for(int i=0;i<N;i++)
      	cin>>A[i];
  	vector<vector<int>> dp(2, vector<int> (K+1, -1) );
  	// row 0 for Jiro's turn row 1 for taro's turn
  	dp[0][0] = 0;	// Player loses if zero stones and his turn
  	dp[1][0] = 0;
  
  	bool turnTaro=true;
  	if(f(turnTaro, A, K, dp) == 1)
      	cout<<"First";
  	else
      	cout<<"Second";
 	return 0; 
}

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

#define ll long long int

ll val[(1<<16)-1];
ll dp[(1<<16)-1];

void recur(ll i,const vector<ll>& vec,ll valn,ll mask,ll check){
	
	if(i==vec.size()){
		dp[mask]=max(dp[mask],valn+val[check]);
		return ;
	}
	
	recur(i+1,vec,valn,mask,check);
	recur(i+1,vec,valn,mask|(1<<vec[i]),check|(1<<vec[i]));
	return ;
}

int main(){
	ll n;
	cin>>n;
	ll arr[n+1][n+1];
	
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			cin>>arr[i][j];
		}
	}
	memset(dp,0,sizeof(dp));
	memset(val,0,sizeof(val));
	
	for(ll i=0;i<(1<<n);i++){
		dp[i]=-10000000000;
		for(ll j=0;j<n;j++){
			
			if((i&(1<<j))){
				for(ll k=0;k<n;k++){
					if((i&(1<<k))){
						val[i]+=arr[j][k];
					}
				}
			}
			
		}
	}
	dp[0]=0;
	for(ll i=0;i<(1<<n);i++){
		vector<ll>hell;
		for(ll j=0;j<n;j++){
			
			if(!(i&(1<<j))){
				hell.push_back(j);
			}
		}
		recur(0,hell,dp[i],i,0);
	}
	
	cout<<dp[(1<<n)-1]/2;
	
	
}

Measured memory_bytes: 1280
fun main() {
  val (N, K) = readInts()
  val S = readString().toMutableList()
  S[K - 1] = S[K - 1].toLowerCase()
  println(S.joinToString(""))
}

fun readString() = readLine()!!
fun readStrings() = readString().split(" ")
fun readInt() = readString().toInt()
fun readLong() = readString().toLong()
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }


Measured memory_bytes: 36320
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 62;

ll a[100001] = {};
ll b[100001] = {};
int main() {
	ll n; cin >> n;
	rep(i, 0, n) cin >> a[i] >> b[i];

	ll sum = 0;
	for (int i = n - 1; i >= 0; i--) {
		if (a[i] == 0)continue;
		a[i] += sum;

		if (a[i] <= b[i]) {
			sum += b[i] - a[i];
		}
		else {
			if (a[i] % b[i] != 0) {
				sum += b[i] * (a[i] / b[i] + 1) - a[i];
			}
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 1792
from collections import defaultdict,deque
H, W = map(int,input().split())
MAP = []
for _ in range(H):
    MAP.append(tuple(map(str,input())))

move = [[0,1],[0,-1],[1,0],[-1,0]]
MAX = 0 

def bfs(s):
    global MAX
    stack = deque([])
    stack.append(tuple(s))
    depth =dict()
    depth[tuple(s)] = 0
    while stack:
        v = stack.popleft()
        for m in move:
            a = tuple([v[0]+m[0], v[1] + m[1]])
            if a[0] < H and a[0] >=  0 and a[1] < W and a[1] >= 0:
                if MAP[a[0]][a[1]] == '.' and not a in depth:
                    stack.append(a)
                    depth[a] = depth[v] + 1

    for d in depth.values():
        MAX = max(MAX,d)


for i in range(0,H):
    for j in range(0,W):
        if MAP[i][j] == '.':
            bfs(tuple([i,j]))
print(MAX)

Measured memory_bytes: 3444
# coding: utf-8

N = int(input())
H = [int(h) for h in input().split()]

movecnt = []
cnt = 0
for i in range(N - 1):
    if (H[i] >= H[i + 1]):
        cnt += 1
    else:
        movecnt.append(cnt)
        cnt = 0
movecnt.append(cnt)

print(max(movecnt))


Measured memory_bytes: 14224
from sys import stdin
input=lambda : stdin.readline().strip()
from math import ceil,sqrt,factorial
def gcd(a,b):
	a,b=max(a,b),min(a,b)
	while a%b!=0:
		a,b=b,a%b
	return b
n=int(input())
su=0
for i in range(1,n+1):
	for j in range(1,n+1):
		a=gcd(i,j)
		for k in range(1,n+1):
			su+=gcd(a,k)
print(su)

Measured memory_bytes: 69016
#include <bits/stdc++.h>
#define REP(i, a, n) for (long long i = (a); i < (long long)(n); ++i)
#define REPC(i, a, n) for (long long i = (a); i <= (long long)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  int N;
  cin >> N;
  VEC<int> W(N);
  LL S1 = 0, S2 = 0;
  REP(i, 0, N) {
    cin >> W[i];
    S2 += W[i];
  }
  LL mi  = INT32_MAX;
  REP(i,0,N){
    S1+=W[i];
    S2-=W[i];
    mi= min(mi, abs(S1-S2));
  }
  cout<<mi<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

struct edge {
    int to, cost, num;
    edge(int t, int c, int n) : to(t), cost(c), num(n) {}
};

int N, M, L;
int A[10010], B[10010], D[10010], E[10010];
int dis[110][110];
vector<edge> G[110];

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

    while (cin >> N >> M >> L, N) {
        REP (i, 110) G[i].clear();
        REP (i, M) {
            cin >> A[i] >> B[i] >> D[i] >> E[i];
            A[i]--, B[i]--;
            G[A[i]].emplace_back(B[i], D[i], E[i]);
            G[B[i]].emplace_back(A[i], D[i], E[i]);
        }
        const int INF = 1 << 30;
        fill_n((int*)dis, 110 * 110, INF);
        dis[0][L] = 0;
        using P = tuple<int, int, int>;
        priority_queue<P, vector<P>, greater<P>> que;
        que.emplace(0, 0, L);
        while (!que.empty()) {
            int dd, v, c;
            tie(dd, v, c) = que.top(); que.pop();
            if (dis[v][c] < dd) continue;
            for (auto& e : G[v]) {
                if (e.cost <= c) {
                    if (dis[e.to][c - e.cost] > dis[v][c]) {
                        dis[e.to][c - e.cost] = dis[v][c];
                        que.emplace(dis[e.to][c - e.cost], e.to, c - e.cost);
                    }
                }
                if (dis[e.to][c] > dis[v][c] + e.num) {
                    dis[e.to][c] = dis[v][c] + e.num;
                    que.emplace(dis[e.to][c], e.to, c);
                }
            }
        }
        int ans = INF;
        REP (i, 110) ans = min(ans, dis[N - 1][i]);
        cout << ans << endl;
    }
}


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

int main(void) {
    int64_t N;
    int64_t pos;
    int64_t tmp;
    int64_t loopcnt;
    cin >> N;

    vector<int64_t> a(N);
    for(int i=0;i<N;i++) {
        cin >> a[i];
    }

    pos = a[0] - 1;
    loopcnt=1;
    for(;((loopcnt < N) && (pos >= 2));loopcnt++) {
//printf("pos:%ld a[%ld]:%ld\n", pos, pos, a[pos]);
        pos = a[pos] - 1;
    }

    if(pos == 1) {
        cout << loopcnt << "\n";
    } else {
        cout << "-1\n";
    }

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};
long double eps = 1e-6;
long double pi = acos(-1);

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    sort(a,a+n,greater<ll>());
    ll ans = a[0];
    ll now = n-2;
    for(int i=1;i<n;i++){
        if(now>=2){
            ans += 2*a[i];
            now -= 2;
        }
        else if(now >= 1){
            ans += a[i];
            now--;
        }
    }
    cout << ans << endl;


}

Measured memory_bytes: 5220
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	int x,y;cin>>x>>y;
	if(y%2==0 && y>=x*2 && y<=x*4) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ll long long
#define llu unsigned long long
#define ld long double
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 3.14159265
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define deb(x) cerr << ">> " << #x << " : " << x << "\n"
#define endl '\n'
#define ff first
#define ss second
#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) (a * b) / __gcd(a, b)
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define print(a) for(auto x : a) cout << x << " "; cout << endl;

using namespace std;

const ll inf = 1e18 + 42;

const ll M = 998244353;

ll power(ll x, ll y) {
	if (y == 0) return 1;
	if (y & 1) return (x * power(x, y - 1)) % MOD;
	ll t = power(x, y / 2);
	return (t * t) % MOD;
}

const ll MAX = 1e5 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void ahShitHereWeGoAgain()
{
	ll k;
	cin >> k;
	string s;
	cin >> s;
	if(s.size() > k)
	{
		for(ll i = 0; i < k; i++)
			cout << s[i];
		cout << "...\n";
	}
	else cout << s << endl;
}

int main()
{
	DESYNC	
	ll t = 1;
	// cin >> t;
	while (t--)
		ahShitHereWeGoAgain();
	return 0;
}



Measured memory_bytes: 3572
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iostream>

#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define contains(c, x) ((c).find(x) != (c).end())
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, (n))

using namespace std;

int a[101][101];
int dx[] = { -1, 1, 0, 0 };
int dy[] = { 0, 0, -1, 1 };
int main()
{
	int w, h, sx, sy, gx, gy, n;
	while (true) {
		cin >> w >> h;
		if (!(w | h)) break;
		cin >> sx >> sy >> gx >> gy >> n;
		sx--, sy--, gx--, gy--;
		int c, d, x, y;
		rep(k, n) {
			cin >> c >> d >> x >> y;
			if (d == 0) {
				REP(i, y-1, y+1) REP(j, x-1, x+3) a[i][j] = c;
			}
			else {
				REP(i, y-1, y+3) REP(j, x-1, x+1) a[i][j] = c;
			}
		}
		if (a[sy][sx] != a[gy][gx]) {
			puts("NG");
			continue;
		}

		bool f = false;
		queue<pair<int, int> > q;
		set<pair<int, int> > s;
		pair<int, int> start = mp(sy, sx);
		pair<int, int> goal = mp(gy, gx);
		q.push(start);
		s.insert(start);
		while (!q.empty()) {
			pair<int, int> t = q.front(); q.pop();
			if (t == goal) { f = true; break; }
			rep(i, 4) {
				int r = t.first + dy[i];
				int c = t.second + dx[i];
				if (r < 0 || r >= h || c < 0 || c >= w) continue;
				if (a[sy][sx] != a[r][c] || contains(s, mp(r, c))) continue;
				q.push(mp(r, c));
				s.insert(mp(r, c));
			}
		}
		puts((f ? "OK" : "NG"));
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<vector>
#include<deque>
#define PP std::pair<int,int>
int N[100010];
std::vector<PP> D[100010];
int K;
int main() {
	int K;
	std::cin >> K;
	for (int i = 0; i < K; i++) {
		N[i] = 1 << 30;
	}
	for (int i = 1; i < K; i++) {
		D[i].push_back({ (i + 1) % K,1 });
		D[i].push_back({ (i * 10) % K,0 });
	}
	std::deque<PP> q;
	q.push_front({ 1,1 });
	while (1) {
		PP p = q.front();
		q.pop_front();
		//std::cout << p.first << std::endl;
		if (p.first == 0) {
			std::cout << p.second << std::endl;
			return 0;
		}
		for (auto u : D[p.first]) {
			if (N[u.first] > p.second + u.second) {
				N[u.first] = p.second + u.second;
				if (u.second == 0) {
					q.push_front({ u.first,p.second });
				}
				else {
					q.push_back({ u.first,p.second + 1 });
				}
			}
		}
	}
}


Measured memory_bytes: 6528
N=int(input())
a=[0]*N
for i in range(N):
  a[i]=int(input())
count=0

#loopの定義→同じインデックスを使用したら
#loop=[]
loop=set()

tmp=1
while True:  
  tmp=a[tmp-1]
  count+=1
  if tmp==2:
    print(count)
    exit()
  if tmp-1 in loop:
    print(-1)
    exit()
  loop.add(tmp-1)
  

Measured memory_bytes: 16028
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try(Scanner scn = new Scanner(System.in)) {
            double x1 = scn.nextDouble();
            double y1 = scn.nextDouble();
            double x2 = scn.nextDouble();
            double y2 = scn.nextDouble();
            System.out.println(Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2)));
        }
    }
}

Measured memory_bytes: 27868