akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define l long
#define mk make_pair
#define pb push_back
#define in insert
#define se second
#define fi first
#define mod 1000000007
#define inf 100000000000000000
#define watch(x) cout << (#x) << " is " << (x) << "\n"
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pii pair<string,ll>
using namespace std;
const int N = 100005; 
ll factorialNumInverse[N + 1]; 
  
ll naturalNumInverse[N + 1]; 
  
ll fact[N + 1]; 
  
void InverseofNumber(ll p) 
{ 
    naturalNumInverse[0] = naturalNumInverse[1] = 1; 
    for (int i = 2; i <= N; i++) 
        naturalNumInverse[i] = naturalNumInverse[p % i] * (p - p / i) % p; 
} 
void InverseofFactorial(ll p) 
{ 
    factorialNumInverse[0] = factorialNumInverse[1] = 1; 
    for (int i = 2; i <= N; i++) 
        factorialNumInverse[i] = (naturalNumInverse[i] * factorialNumInverse[i - 1]) % p; 
} 
void factorial(ll p) 
{ 
    fact[0] = 1; 
    for (int i = 1; i <= N; i++) { 
        fact[i] = (fact[i - 1] * i) % p; 
    } 
} 
  
ll ncr(ll N, ll R, ll p) 
{ 
	if(R > N) return 0;
	if(R==0) return 0;
    ll ans = ((fact[N] * factorialNumInverse[R]) 
              % p * factorialNumInverse[N - R]) 
             % p; 
    return ans; 
} 
int main()
{
    fast;
    
    ll p = 1000000007; 
    InverseofNumber(p); 
    InverseofFactorial(p); 
    factorial(p);
    ll n,k,i,j,ms = 0,mis = 0,ans=0;
    cin>>n>>k;
    vector<ll> a(n+1);
    a[0] = -inf;
    for(i=1;i<=n;i++) cin>>a[i];
    sort(a.begin(),a.end());
    for(i=k;i<=n;i++)
    {
    	ans  = (ans + a[i]%mod * ncr(i-1,k-1,mod)%mod)%mod; 
    }
    for(i=1;i<=n-k+1;i++)
    {
    	ans  = (ans - a[i]%mod * ncr(n-i,k-1,mod)%mod)%mod;  
    	ans = (ans + mod)%mod;
    }
    cout<<ans;
}
    


Measured memory_bytes: 3328
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int main(){
    int N;
    cin >> N;
    string S;
    cin >> S;
    string ans;
    for(int i = 0; i < S.size(); i++){
        ans.push_back((S[i] - 'A' + N) % 26 + 'A');
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 256
#ワーシャルフロイド法
def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d


##############################
n,m = map(int,input().split()) 

d = [[float("inf")]*n for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
edge=[]
for i in range(m):
    x,y,c = map(int,input().split())
    x-=1
    y-=1
    edge.append((x,y,c))
    d[x][y] = c
    d[y][x] = c
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
d=warshall_floyd(d)
ans=0
for x,y,c in edge:
    if d[x][y]<c:
        ans+=1
print(ans)

Measured memory_bytes: 9288
#include <bits/stdc++.h>
using namespace std;
int main() {
  int h,w;
  cin >> h >> w;
  vector<vector<char>> table(h,vector<char>(w));
  for (int i=0; i<h; i++) {
    for (int j=0; j<w; j++) {
      cin >> table.at(i).at(j);
    }
  }
  for (int i=0; i<h; i++) {
    for (int j=0; j<2; j++) {
      for (int k=0; k<w; k++) {
        cout << table.at(i).at(k);
      }
      cout << endl;
    }
  }
}

Measured memory_bytes: 256
# 隣接行列知らないと書けない、あるいは隣接リスト, BFS, union find
# まずは隣接リストでdfs、グローバル変数どうする？
N, M = map(int, input().split())
AB = [list(map(int, input().split())) for _ in range(M)]

def dfs(v):
    # 連結かどうか確かめる
    visited[v] = True
    for v2 in con_list[v]:
        if visited[v2] == True: continue
        else: dfs(v2)

ans = 0
for i in range(M):
    graph = AB[:i] + AB[i+1:]
    # 隣接リスト: 0~N-1に置き換え
    con_list = [[] for _ in range(N)]
    for edge in graph:
        con_list[edge[0]-1].append(edge[1]-1)
        con_list[edge[1]-1].append(edge[0]-1)
    # global visited
    visited = [False] * N
    dfs(0)
    if not all(visited):
        ans += 1
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<vector>
#include<set>
#include<iomanip>
#include<cmath>
using namespace std;
typedef long long ll;
typedef long long int llint;
typedef pair<ll, ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 101000
#define MAP 110
#define initial_value -1
#define MAX_T 1001
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define INF (1 << 29) //536870912
const long double PI = acos(-1);
const ll DEP = 1e18;
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
int main(){
    int N,y; cin >> N >> y;
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= N; j++){
            int num = N-i-j;
            if(num < 0) continue;
            if(i*10000 + j*5000 + num*1000 == y){
                cout << i << " " << j << " " << num << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
}

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

int main(){
  long long x,f = 100,count=0;
  cin >> x;
  while(f < x){
    f *= 1.01;
    count += 1;
  }
  cout << count << endl;
}


Measured memory_bytes: 3620
#include <iostream>
#include <typeinfo>
#include <cstring>
#include <utility>
#include <vector>
#include <bitset>
#include <cmath>
#include <algorithm>
#include <queue>
using namespace std;


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

    vector<vector<int>> data(N);

    int boss;
    for (int i = 1; i < N; i++) {
        cin >> boss;
        data[boss - 1].push_back(i);
    }

    for (int i = 0; i < N; i++) {
        cout << data[i].size() << endl;
    }
    return 0;
}


Measured memory_bytes: 14020
from bisect import bisect_left

N = int(input())
L = list(map(int, input().split()))
L.sort()
ans = 0
for ia, a in enumerate(L):
    for ib, b in enumerate(L[ia+1:], ia):
        ans += bisect_left(L, a+b) - ib - 2

print(ans)


Measured memory_bytes: 45148
#include <iostream>
#include <string>
#include <algorithm>
#include <utility>

using namespace std;

#define REP(var, count) for(int var=0; var<count; var++)

int DP[110][10010]; //N???????????§????????????????¨?w

int main(void) {
	
	int N, W;
	cin >> N >> W;
	
	REP(i, N) {
		int v, w;
		cin >> v >> w;
		
		REP(c, W+1) {
			if ( c < w ) {
				// ????????????????????????
				DP[i+1][c] = DP[i][c];
			} else {
				DP[i+1][c] = max( DP[i][c-w] + v, DP[i][c] );
			}
		}
	}
	
	int ret = 0;
	REP(c, W+1) {
		ret = max(ret, DP[N][c]);
	}
	
	cout << ret << endl;
}

Measured memory_bytes: 6972
package main
 
import (
  "fmt"
  "strconv"
)
 
func main() {
  
  var str string
  fmt.Scan(&str)
  var m [4]int
  for i := 0; i < 4; i++ {
    m[i],_ = strconv.Atoi(string(str[i]))
  }
  
  //+,-を格納
  var s [3]string
  
  //全パターン試して正解を見つけたら終了
  for i := 0; i < 8; i++ {
    ans := m[0]
    for j := 0; j < 3; j++ {
      p := i & (1<<(uint(j))) 
      if p == 0 {
        s[j] = "-"
        ans -= m[j+1]
      } else {
        s[j] = "+"
        ans += m[j+1]
      }
    }
    if ans == 7 { 
      fmt.Printf("%d%s%d%s%d%s%d=7", m[0], s[0], m[1], s[1], m[2], s[2], m[3])
      break
    }
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))

template <typename T>
class RSQ{
public:
	vector<T> dat;
	int n;
	RSQ(int n0,T initdata){
		initsize(n0,initdata);
	}
	void initsize(int n0, T initdata){
		int k=1;
		while(1){
			if(n0<=k){
				n=k;
				dat.resize(2*n-1);
				for(int i=0;i<2*n-1;i++)dat[i]=initdata;
				break;
			}
			k*=2;
		}
	}

	void add(int i,int x){
		i += n-1;
		dat[i] += x;
		while(i>0){
			i = (i-1) / 2;
			dat[i] = dat[i*2+1]+dat[i*2+2];
		}
	}

	T query0(int a,int b,int k,int l,int r){// [a,b)
		if(r<=a || b<=l)return 0;
		if(a<=l && r<=b)return dat[k];
		else{
			int vl = query0(a,b,k*2+1,l,(l+r)/2);
			int vr = query0(a,b,k*2+2,(l+r)/2,r);
			return vl+vr;
		}
	}

	T query(int a,int b){ // [a,b)
		return query0(a,b,0,0,n);
	}
};

int main(){
	int n,q;
	cin >> n >> q;
	RSQ<int> rsq(n+1,0);
	FOR(i,0,q){
		int com,x,y;
		cin >> com >> x >> y;
		if(com){
			cout << rsq.query(x,y+1) << endl;
		}else{
			rsq.add(x,y);
		}
	}
}



Measured memory_bytes: 3792
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let mut fib = vec![1; n + 1];
    for i in 2..n + 1 {
        fib[i] = fib[i - 1] + fib[i - 2];
    }
    println!("{}", fib[n]);
}



Measured memory_bytes: 5032
#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct robot {
    intmax_t X;
    intmax_t L;
};

int compare(const void *a, const void *b)
{
    if ((((struct robot *)a)->X + ((struct robot *)a)->L) < (((struct robot *)b)->X + ((struct robot *)b)->L))
        return -1;
    if ((((struct robot *)a)->X + ((struct robot *)a)->L) > (((struct robot *)b)->X + ((struct robot *)b)->L))
        return 1;
    return 0;
}

int main(void)
{
    intmax_t N;
    struct robot robot[100000] = {};
    intmax_t ans = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd%jd", &robot[i].X, &robot[i].L);
    }

    qsort(robot, N, sizeof(struct robot), compare);

    intmax_t e = robot[0].X + robot[0].L;
    ans = 1;
    for (size_t i = 1; i < N; i++) {
        if (e > (robot[i].X - robot[i].L))
            continue;
        ans++;
        e = robot[i].X + robot[i].L;
    }

    printf("%jd\n", ans);

    return 0;
}


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

main(){
    map<char, int> M;

    M[' '] = 0;
    M['I'] = 1;
    M['V'] = 5;
    M['X'] = 10;
    M['L'] = 50;
    M['C'] = 100;
    M['D'] = 500;
    M['M'] = 1000;

    string line;
    while( cin >> line ){
	line += ' ';
	int sum = 0;
	for ( int i = 0; i < line.size()-1; i++ ){
	    if ( M[line[i]] < M[line[i+1]] ){
		sum -= M[line[i]]; 
	    } else {
		sum += M[line[i]]; 
	    }
	}
	cout << sum << endl;
    }
}

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    cout << fixed << setprecision(15);
    ll N, M;
    cin >> N >> M;
    
    vector<bool> A(N+1, true);
    vector<ll> dp(N+1, 0);

    REP(i, M){
        int a;
        cin >> a;
        A[a] = false;
    }
    dp[0] = 1;
    for(ll i=1; i<=N; i++){
        if(A[i] == false){
            dp[i] = 0;
            continue;
        }
        if(i == 1){
            dp[1] = 1;
        }
        else{
            dp[i] = (dp[i-1] + dp[i-2]) % MOD;
        }
    }
    cout << dp[N] << endl;
    return 0;
}

Measured memory_bytes: 1024
#
# abc070 b
#
import sys
from io import StringIO
import unittest


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)

    def test_入力例_1(self):
        input = """0 75 25 100"""
        output = """50"""
        self.assertIO(input, output)

    def test_入力例_2(self):
        input = """0 33 66 99"""
        output = """0"""
        self.assertIO(input, output)

    def test_入力例_3(self):
        input = """10 90 20 80"""
        output = """60"""
        self.assertIO(input, output)


def resolve():
    A, B, C, D = map(int, input().split())

    if A > C:
        A, C = C, A
        B, D = D, B

    if B < D:
        print(max(0, B-C))
    else:
        print(D-C)


if __name__ == "__main__":
    # unittest.main()
    resolve()


Measured memory_bytes: 16332
#include <bits/stdc++.h>
#include <climits>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define srep(i, begin, end) for (__typeof(end) i = begin; i != end; i++)
#define si(x) int x = scanInt();
#define sll(x) LL x = scanLong();
#define sci(x) int x; scanf("%d", &x);
#define scll(x) LL x; scanf("%lld", &x);
#define pi(x) printf("%d ", x)
#define pll(x) printf("%lld ", x)
#define nl printf("\n")
#define clr(a) memset(a, 0, sizeof(a))
#define PB push_back
#define MP make_pair
using namespace std;
typedef unsigned int UI; // 32 bit integer
typedef long int LI; // 32 bit integer
typedef unsigned long int ULI; // 32 bit unsigned integer
typedef long long int LL; // 64 bit integer
typedef unsigned long long int ULL; // 64 bit unsigned integer
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef deque<int> DI;
typedef deque<LL> DLL;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
const LL MOD = 1e9+7;

/* Fast I/O */
inline int scanInt() {
	int n = 0;
	char ch = getchar();
	int sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(int)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

inline LL scanLong() {
	LL n = 0;
	char ch = getchar();
	LL sign = 1;
	while(ch < '0' || ch > '9') {
		if(ch == '-')	sign = -1;
		ch = getchar();
	}
	while(ch >= '0' && ch <= '9') {
		n = (n<<1)+(n<<3)+(LL)(ch-'0');
		ch = getchar();
	}
	return n*sign;
}

int main() {
	sll(n);
	LL wgts[n];
	rep(i, 0, n)	wgts[i] = scanLong() + (i > 0 ? wgts[i-1] : 0);
	LL minDiff = LONG_MAX;
	rep(i, 0, n-1) {
		LL diff = abs(2 * wgts[i] - wgts[n-1]);
		if(diff < minDiff)	minDiff = diff;
	}
	pll(minDiff); nl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,sum,coin=0;
	while(1){
		scanf("%d",&n);
		if(n==0)
			break;

		sum=1000-n;
		if(sum>=500){
			sum-=500;
			coin++;
		}
		while(sum>=100){
			sum-=100;
			coin++;
		}

		if(sum>=50){
			sum-=50;
			coin++;
		}

		while(sum>=10){
			sum-=10;
			coin++;
		}

		if(sum>=5){
			sum-=5;
			coin++;
		}

		while(sum!=0){
			sum-=1;
			coin++;
		}

		printf("%d\n",coin);
		coin=0;
	}
	return 0;
}

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


int main() {
  int n,k;
  cin >> n >> k;
  int h[n]={};
  for(int i=0;i<n;i++){
    cin >> h[i];
  }
  sort(h,h+n);
  int min1 = pow(10,9);
  for(int i=0;i<n-k+1;i++){
    min1 = min(min1,h[k+i-1]-h[i]);
  }
  cout << min1 << endl;
}


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

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

int main() {
    int n; cin >> n;
    string s; cin >> s;
    int x = 0;
    int ans = 0;
    rep(i,n){
        if(s[i] == 'I') x++;
        else x--;
        ans = max(ans,x);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class C
{
	static void Main()
	{
		Func<int[]> read = () => Console.ReadLine().Split().Select(int.Parse).ToArray();
		var h = read();
		var t = read();

		int r = 0, tl = 0;
		for (int i = 0; i < h[0]; i++)
		{
			var tp = t[i] + h[1];
			r += tp - Math.Max(tl, t[i]);
			tl = tp;
		}
		Console.WriteLine(r);
	}
}


Measured memory_bytes: 26720
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<cctype>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
using namespace std;
#define int long long
const int inf=0x3f3f3f3f, mod=998244353, N=1000005;
int fac[N], inv[N];

inline int read()
{
    int x=0,f=1; char ch=getchar();
    for (; ch<'0' || ch>'9'; ch=getchar()) if (ch=='-') f=-1;
    for (; ch>='0' && ch<='9'; ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
    return x*f;
}

int power(int x, int t)
{
    int res=1;
    while (t)
    {
        if (t&1) (res*=x)%=mod;
        (x*=x)%=mod; t>>=1;
    }
    return res;
}

int C(const int &n, const int &m){return (fac[n]*inv[m]%mod)*inv[n-m]%mod;}
int invC(const int &n, const int &m){return (inv[n]*fac[m]%mod)*fac[n-m]%mod;}

signed main()
{
    int n=read(), m=read(), k=min(n, m), ans=0; fac[0]=1;
    for (int i=1; i<=N; i++) fac[i]=(fac[i-1]*i)%mod;
    inv[N]=power(fac[N], mod-2);
    for (int i=N-1; i>=0; i--) inv[i]=(inv[i+1]*(i+1))%mod;
    for (int i=1; i<=k; i++) (ans+=C(2*i, i)*C(n+m-2*i, n-i))%=mod;
    (ans*=(invC(n+m, n)*inv[2]%mod))%=mod;
    printf("%d\n",(ans+max(n, m))%mod);
    return 0;
}


Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int64_t n, m, k, ans = 0;
    cin >> n >> m >> k;
    vector<int64_t> a(n+1), b(m+1);
    for(int i = 1; i < n + 1; i++){
        cin >> a[i];
        if(i>=2)a[i]+=a[i-1];
        // printf("a[%lu]=%lu\n", i, a[i]);
    }
    for(int i = 1; i < m + 1; i++){
        cin >> b[i];
        if(i>=2)b[i]+=b[i-1];
        // printf("b[%lu]=%lu\n", i, b[i]);
    }
    // partial_sum(begin(a), end(a), begin(a));
    // partial_sum(begin(b), end(b), begin(b));
    for(int64_t i = 0; i < n + 1; i++){
        int64_t l = k - a[i];
        if(l < 0) break;
        int64_t j = upper_bound(begin(b), end(b), l) - begin(b) - 1;
        ans = max(ans, i + j);
    }
    cout << ans << endl;
    return 0;
}

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

long long attack(long long h){
	if (h==1) return 1;
	else return 1 + 2*attack(h/2);
}
int main(){
	
	long long n,a,b;
	cin >> n >> a >> b;
	long long whole, rest;
	whole = n/(a+b);
	rest = min(n - whole*(a+b),a);
	cout << whole*a + rest;
	
}



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



int main(){

   ll x;
   cin>>x;
   ll ans = 0;

   ll x1 = x/500;
   ans+=(x1*1000);
   x-=(x1*500);
   ll x2 = x/5;
   ans+=(x2*5);
   cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000 + 10;
const int M = 1000000007;
const double PI = atan(1) * 4;
const int oo = 1000000000;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
#define pb push_back 
#define all(c) (c).begin(),(c).end()


int main(){
	ll x,lo=0,hi=1e9,md,bst=1e9;
	cin>>x;
	while(hi>=lo){
		md=(hi+lo)/2;
		if(md*(md+1)/2>=x){
			bst=min(bst,md);
			hi=md-1;
		}else
			lo=md+1;
	}
	cout<<bst<<endl;
}




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

using namespace std;

typedef long long LL;

class UnionFind{
public:
  UnionFind(int aN)
  {
    init(aN);
  }

  void init(int aN)
  {
    par.clear(); cnt.clear();
    par.resize(aN); cnt.resize(aN);
    for (size_t i = 0; i < aN; i++) {
      par[i] = i;
      cnt[i] = 1;
    }
  }

  int find(int aX)
  {
    if(aX == par[aX]) return aX;
    else return par[aX] = find(par[aX]);
  }

  bool same(int aX, int aY)
  {
    return find(aX) == find(aY);
  }

  int size(int aX)
  {
    return cnt[find(aX)];
  }

  void unite(int aX, int aY)
  {
    aX = find(aX);
    aY = find(aY);
    if(aX == aY) return;

    par[aX] = aY;
    cnt[aY] += cnt[aX];
  }
private:
  vector<int> par;
  vector<int> cnt;
};


#define MAX_N 200005
#define MAX_K 100005
#define MAX_L 100005

int N, K, L;
int P[MAX_K], Q[MAX_K];
int R[MAX_L], S[MAX_L];

void input()
{
  cin >> N >> K >> L;
  for (int i = 0; i < K; i++) {
    scanf("%d %d", &P[i], &Q[i]);
    P[i]--; Q[i]--;
  }
  for (int i = 0; i < L; i++) {
    scanf("%d %d", &R[i], &S[i]);
    R[i]--; S[i]--;
  }
}

int main()
{
  input();
  UnionFind uf1(N), uf2(N);

  for (int i = 0; i < K; i++) {
    uf1.unite(P[i], Q[i]);
  }
  for (int i = 0; i < L; i++) {
    uf2.unite(R[i], S[i]);
  }

  map<pair<int, int>, int> Map;
  for (int i = 0; i < N; i++) {
    Map[make_pair(uf1.find(i), uf2.find(i))]++;
  }

  for (int i = 0; i < N; i++) {
    cout << Map[make_pair(uf1.find(i), uf2.find(i))];
    if(i < N-1) cout << " ";
  }
  cout << endl;


  return 0;
}


Measured memory_bytes: 16640
from collections import deque
k=int(input())
deq=deque(range(1,10))
append=deq.append
popleft=deq.popleft
for _ in range(k):
	c=popleft()
	if c%10==0:
		append(c*10)
		append(c*10+1)
	elif c%10==9:
		append(c*10+8)
		append(c*10+9)
	else:
		append(c*10+c%10-1)
		append(c*10+c%10)
		append(c*10+c%10+1)
print(c)


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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

const ll MAXV = 17;

ll dist[MAXV][MAXV]{};
ll dp[(1ll<<MAXV)][MAXV]{};

int main(int argc, char **argv)
{
	ll V, E;
	cin >> V >> E;
	REP(i, V)REP(j, V) dist[i][j] = INF;
	REP(i, E)
	{
		ll a, b, d; cin >> a >> b >> d;;
		dist[a][b] = d;
	}

	ll SMAX = (1ll<<V);
	REP(bits, SMAX) REP(v, V) dp[bits][v] = INF;
	dp[0][0] = 0;

	REP(bits, SMAX)
	{
		REP(s, V)
		{
			REP(g, V)
			{
				// s to g
				if (!(bits & (1ll<<g)))
				{
					ll tmp = bits|(1ll<<g);
					dp[tmp][g] = min(dp[tmp][g],
									 dp[bits][s]+dist[s][g]);
				}
			}
		}
	}

	ll res = dp[SMAX-1][0];
	std::cout << (res == INF ? -1 : res)<< std::endl;
}



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

int main(){
    int h, w, i;
    string s;
    cin >> h >> w;
    for(i=0; i<w+2; i++){
        cout << '#';
    }
    cout << '\n';
    for(i=0; i<h; i++){
        cout << '#';
        cin >> s;
        cout << s;
        cout << "#\n";
    }
    for(i=0; i<w+2; i++){
        cout << '#';
    }
    return 0;
}

Measured memory_bytes: 256
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}


fn main(){
    let line: i32 = read_as_vec()[0];

    let left = line/100;
    let right = line%100;

    if (left == 0 || 12 < left) && (right == 0 || 12 < right){
        println!("NA");
    }else if (0 < left && left < 13) && (0 < right && right < 13){
        println!("AMBIGUOUS");
    }else if (0 < left && left < 13) && (right == 0 || 12 < right){
        println!("MMYY");
    }else if (left == 0 || 12 < left) && (0 < right && right < 13){
        println!("YYMM");
    }
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <set>
#include <map>

using namespace std;

int N;
int L[2000];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }
    sort(L, L+N);
    long ans = 0;
    for(int i = 0; i < N; i++){
        for(int j = i+1; j < N; j++){
            int *p = lower_bound(L, L+N, L[i]+L[j]);
            ans += p-(L+j)-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#encoding:utf-8 No.0206 2014.11.10
while true
  trip_expense = gets.chomp.to_i
  if trip_expense == 0
    break
  end

  money = []
  12.times do |i|
    money[i] = gets.chomp.split.map{|n| n.to_i}
  end

  term = 0
  savings = 0
  while true
    if term <= 11
      savings += money[term][0] - money[term][1]
      if savings >= trip_expense
        puts term + 1
        break
      end
      term += 1
    else
      puts "NA"
      break
    end
  end
end

Measured memory_bytes: 6100
#include<stdio.h>

int main(void)
{
  int H,W,h,w,n,m,k,a;
  scanf("%d%d%d%d",&H,&W,&h,&w);
  n=H*W;
  m=h*W;
  k=(H-h)*w;
  a=n-(k+m);
  printf("%d\n",a);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	int a, b;
	long long k[1005][5], ans = 0;
	cin >> a >> b;
	for (int i = 0; i < a; ++i) {
		for (int j = 0; j < 3; ++j) {
			cin >> k[i][j];
		}
	}
	for (int i = 0; i < 8; ++i) {
		long long sum = 0, v[100005] = {};
		for (int j = 0; j < a; ++j) {
			for (int kk = 0; kk < 3; ++kk) {
				if (i / (1 << kk) % 2 == 0) v[j] += k[j][kk];
				else v[j] -= k[j][kk];
			}
		}
		sort(v, v + a);
		for (int j = a - 1; j >= a - b; --j) {
			sum += v[j];
		}

		ans = max(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1152
#pragma comment(linker, "/STACK:640000000")
#include <bits/stdc++.h>

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define ll long long
#define bit __builtin_popcountll
#define sqr(x) (x) * (x)
#define forit(it,S) for(__typeof((S).begin()) it = (S).begin(); it != (S).end(); it++)

using namespace std;

typedef pair<int, int> pii;

const double eps = 1e-9;
const double pi = acos(-1.0);

int main() {
	#ifdef LOCAL
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	int n, a, b; cin >> n >> a >> b;

	if (a + b - 1 > n || a * 1LL * b < n) {
		cout << -1 << endl;
		return 0;
	}

	vector<int> v(n);

	for (int i = 0; i < n; i++) v[i] = n - i;

	for (int i = 0; i < a; i++) {
		cout << v[a - 1 - i] << " ";
	}

	int nxt = a;

	for (int i = 1; i < b; i++) {
		int cnt = min(a, n - nxt - (b - i - 1));

		for (int j = nxt + cnt - 1; j >= nxt; j--) {
			cout << v[j] << " ";
		}

		nxt += cnt;
	}

	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <string>
#include <stdio.h>
using namespace std;

int main() {
	
	int w,h;
	int *tile;
	int tmp;
	int x,y;
	
	while(cin>>h>>w,w||h){
		tile = new int[w*h];
		x=y=0;
		
		for(int i=0;i<w*h;++i){
			tmp = getchar();
			if(tmp == '\n'){--i;continue;}
			tile[i] = tmp;
		}
		
		while(1){
			
			if(tile[x+y*w] == 0){
				cout<<"LOOP"<<endl;
				break;
			}
			
			if(tile[x+y*w] == '.'){
				cout<<x<<" "<<y<<endl;
				break;
			}
			
			tmp = tile[x+y*w];
			
			tile[x+y*w] = 0;
			
			
			switch(tmp){
				
				case '>':
				++x;
				break;
				
				case '<':
				--x;
				break;
				
				case '^':
				--y;
				break;
				
				case 'v':
				++y;
				break;
			}
		}
	}

	delete[]tile;
	
	return 0;
}

Measured memory_bytes: 1272
from collections import deque

def solve(xs):
    ans = 0
    s = 0
    n = 0
    queue = deque()
    for a in xs:
        if s + a != s ^ a:
            while s + a != s ^ a:
                s -= queue.popleft()
                n -= 1
        s += a
        queue.append(a)
        n += 1
        ans += n
    return ans

if __name__ == "__main__":
    n = int(input())
    xs = [int(s) for s in input().split()]

    print(solve(xs))


Measured memory_bytes: 24036
#include <stdio.h>

#define M 10000
#define N 500
int main(void){
  int n,q,i,j,S[M],T[N],res = 0;
  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&T[i]);
    for(j = 0 ; j < n ; j++){
      if(T[i] == S[j]){
        res++;
        break;
      }
    }
  }
  printf("%d\n",res);
  return 0;
}


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

dp = [False] * (x + 1)
dp[0] = True

for j in range(100, x + 1):
    for t in range(100, 105 + 1):
        if j - t >= 0:
            dp[j] = dp[j] or dp[j - t]

print(1 if dp[x] else 0)


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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; int Q; cin >> S >> Q;
    int direct=0;
    string front="",back="";
    for (;Q--;){
        int T; cin >> T;
        if (T==1) direct^=1;
        else {
            int F; char C; cin >> F >> C; --F;
            F^=direct;
            if (F) back+=C;
            else front+=C;
        }
    }
    reverse(front.begin(),front.end());
    S=front+S+back;
    if (direct) reverse(S.begin(),S.end());
    cout << S << '\n';
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 0x1fffffffffffffff;
template<class T, class U> bool chmax(T& a, const U& b){ if(a < b){ a = b; return 1; } return 0; }

int main(){
    ll n;
    cin >> n;
    vector<ll> a(n);
    for(auto& i : a) cin >> i;
    const ll skip = 1 + n % 2; // 取る 取らない 取る 取らない ... を貪欲にやっていくと 1 + n % 2 個余って、 1 + n % 2 回飛ばせることがわかる
    vector<vector<ll>> dp(n + 2, vector<ll>(skip + 1, -INF)); // dp[i][j] := A[0, i) を j 要素無視して1つ飛びに取ったときの最大値
    dp[0][0] = 0;
    for(ll i = 0; i <= n; i++) for(ll j = 0; j <= skip; j++){
        if(j < skip) chmax(dp[i + 1][j + 1], dp[i][j]);
        if(i < n) chmax(dp[i + 2][j], dp[i][j] + a[i]); // 1個選んだら1個選ばないのもセット
    }
    cout << dp[n + 1][skip] << endl; // なので floor(n / 2) * 2 + skip == n + 1 に答えが入る
}


Measured memory_bytes: 15548
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		ArrayList<Point> reds = new ArrayList<Point>();
		for (int i = 0; i < n; i++) {
			reds.add(new Point(sc.nextInt(), sc.nextInt()));
		}
		ArrayList<Point> blues = new ArrayList<Point>();
		for (int i = 0; i < n; i++) {
			blues.add(new Point(sc.nextInt(), sc.nextInt()));
		}
		Collections.sort(reds, new Comparator<Point>(){
		public int compare(Point p1, Point p2){
			return p2.y - p1.y;
		}
		});
		Collections.sort(blues, new Comparator<Point>(){
		public int compare(Point p1, Point p2) {
			return p1.x - p2.x;
		}
		});
		int count = 0;
		for (Point b : blues) {
			Point x = null;
			for (Point r : reds) {
				if (r.isMatch(b)) {
					x = r;
					count++;
					break;
				}
			}
			if (x != null) {
				reds.remove(reds.indexOf(x));
			}
		}
		System.out.println(count);
		
	}
	
	public static class Point {
		public int x;
		public int y;
		
		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}
		
		public Point() {
			this(0, 0);
		}
		
		public boolean isMatch(Point p) {
			return (x < p.x && y < p.y);
		}
		
	}
}


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

#define REP(i, n, N) for(ll i=(n); i<(N); i++)
#define RREP(i, n, N) for(ll i=(N-1); i>=n; i--)
#define CK(n, a, b) ((a)<=(n)&&(n)<(b))
#define ALL(v) (v).begin(),(v).end()
#define MCP(a, b) memcpy(b,a,sizeof(b))
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
#define v2(T) vector<vector<T>>
typedef long long ll;
using namespace std;
const ll mod = 1e9+7;
const ll inf = 1e18;

ll N;
ll H,W;
ll sy, sx;
string S, T;
ll l, r, u, d;
string solve(){
	l = r = sx;
	u = d = sy;
	REP(i,0,N){
		if(S[i]=='L'){
			l--;
			if(l==0){
				return "NO";
			}
		}else if(S[i]=='R'){
			r++;
			if(r==W+1){
				return "NO";
			}
		}else if(S[i]=='U'){
			u--;
			if(u==0){
				return "NO";
			}
		}else if(S[i]=='D'){
			d++;
			if(d==H+1){
				return "NO";
			}
		}

		if(T[i]=='L'){
			r = max(1LL,r-1);
		}else if(T[i]=='R'){
			l = min(W, l+1);
		}else if(T[i]=='U'){
			d = max(1LL,d-1);
		}else if(T[i]=='D'){
			u = min(H, u+1);
		}
	}

	return "YES";
}
int main() {
	cin >> H >> W >> N;
	cin >> sy >> sx;
	cin >> S >> T;
	p(solve());
	return 0;
}


Measured memory_bytes: 776
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列
using namespace std;

typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 1000000007 //10^9+7
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

int main(void){
    int n;
    cin >> n;
    set<string> s;
    REP(i, n) {
        string str;
        cin >> str;
        s.insert(str);
    }
    cout << s.size() << endl;
    
    return 0;
}

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

using namespace std;

const double inf = 1<<25;

int n, r[15];
double dp[1<<12][12];

double solve(int bit, int l)
{
  if(bit == (1<<n)-1) return r[l];
  double &ret = dp[bit][l];
  if(ret != -1.0) return ret;
  ret = inf;
  for(int i = 0; i < n; i++) {
    if(((bit >> i) & 1)) continue;
    ret = min(ret, solve(bit | (1<<i), i) + sqrt((r[l]+r[i])*(r[l]+r[i]) - (r[l]-r[i])*(r[l]-r[i])));
  }
  return ret;
}

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

  int W;
  while(cin >> W) {
    string in;
    cin.ignore();    
    getline(cin, in);
    stringstream ss(in);
    n = 0;
    while(ss >> r[n]) n++;
    double mn = inf;
    for(int i = 0; i < n; i++) {
      fill(dp[0], dp[1<<12], -1.0);
      mn = min(mn, solve(1<<i, i) + r[i]);
    }
    //cout << mn << endl;    
    if(mn <= W) puts("OK");
    else puts("NA");
  }
  
  return 0;
}

Measured memory_bytes: 3508
N = int(input())
S = input()
ss = [s == 'W' for s in S]

def mul(a, b):
    return (a * b) % (10**9 + 7)

ans = 1
num = 0
for s in ss:
    if num % 2 == s:
        num += 1
    else:
        ans = mul(ans, num)
        num -= 1

if num > 0:
    ans = 0

for i in range(2, N + 1):
    ans = mul(ans, i)

print(ans)

Measured memory_bytes: 53600
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n; cin >> n;
	VI p(n); REP(i, n)cin >> p[i];
	int ans = 0, m = INF;
	REP(i, n) {
		if (p[i] <= m) {
			ans++;
			m = p[i];
		}
	}
	cout << ans;
}

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

int main(){

  int n,a=1;
  string w[100]={};
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>w[i];  
  }

  for(int i=0;i<n-1;i++){
    if(w[i][w[i].size()-1]!=w[i+1][0]) a=0;
  }
  //  cout<<a<<endl;
  
  for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
      if(w[i]==w[j]) a=0;
    }
  }
  
  if(a==1) cout<<"Yes"<<endl;
  else if(a==0) cout<<"No"<<endl;

    return 0;
}
 

Measured memory_bytes: 256
let h, w, n = Scanf.scanf " %d %d %d" @@ fun a b c -> a, b, c
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let ans, c = Array.make_matrix h w 0, ref 0
let rec f i = if a_s.(i) = 0 then f (i + 1) else (a_s.(i) <- a_s.(i) - 1; i)
let _ = for i = 0 to h - 1 do for j = 0 to w - 1 do c := f !c; ans.(i).(if i mod 2 = 1 then w - 1 - j else j) <- !c + 1 done done; Array.(iter (fun cs -> to_list cs |> List.map string_of_int |> String.concat " " |> print_endline) ans)

Measured memory_bytes: 2688
a=input().rstrip().split(" ")
b=input().rstrip().split(" ")

c=[]

for i in range(int(a[0])):
  c.append(int(b[i]))

d=sorted(c)

S=0

for j in range(int(a[0])-int(a[1])):
  S += d[j]

print(S)

Measured memory_bytes: 28664
"""Boot-camp-for-Beginners_Easy013_A_Candy-Distribution-Again_30-August-2020.py"""

A, B, C = map(int, input().split())
a, b, c = A, B, C
i = 0
while True:
    if (A % 2 == 0 and B % 2 == 0 and C % 2 == 0):
        i += 1
        a, b, c = A, B, C
        A = (b+c)/2
        B = (c+a)/2
        C = (a+b)/2
 #       print(A,B,C)
        if(A == a and B == b and C == c):
            print(-1)
            break
    else:
        print(i)
        break
        if(A == a and B == b and C == c):
            print(-1)
            break


Measured memory_bytes: 9152
n = int(input())
a = input()
b = input()
c = input()
cnt = 0
for i in range(n):
    if a[i] == b[i] == c[i]:
        continue
    if a[i] == b[i] or b[i] == c[i] or c[i] == a[i]:
        cnt += 1
    else:
        cnt +=2
print(cnt)

Measured memory_bytes: 3064
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

n=int(input())
D=list(map(int,input().split()))
for i in range(n-1):
    for j in range(i+1,n):
        ans+=D[i]*D[j]
print(ans)

Measured memory_bytes: 38512
#include<stdio.h>
int main(void)
{
 int a,b,c;
 scanf("%d",&a);
 scanf("%d",&b);
 scanf("%d",&c);
 if(a < b && b < c){
  printf("Yes\n");
  }
 else{
  printf("No\n");
 }
 return 0;
}

Measured memory_bytes: 580
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func getNextUint64(scanner *bufio.Scanner) uint64 {
	i, _ := strconv.ParseUint(getNextString(scanner), 10, 64)
	return i
}

func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}

func main() {
	fp := os.Stdin
	wfp := os.Stdout
	cnt := 0

	if os.Getenv("MASPY") == "ますピ" {
		fp, _ = os.Open(os.Getenv("BEET_THE_HARMONY_OF_PERFECT"))
		cnt = 2
	}
	if os.Getenv("MASPYPY") == "ますピッピ" {
		wfp, _ = os.Create(os.Getenv("NGTKANA_IS_GENIUS10"))
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(wfp)
	solve(scanner, writer)
	for i := 0; i < cnt; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
	writer.Flush()
}

func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	s := getNextString(scanner)
	n := len(s)
	for i := 0; i < n; i++ {
		fmt.Fprint(writer, "x")
	}
	fmt.Fprintln(writer, "")
}


Measured memory_bytes: 640
K=int(input())
u12 = [i for i in range(1,10)]
ans = 0
for i in range(K):
    if ans <=11:
        ans += 1
        continue
    flg = True
    l = len(str(ans))
    for j in range(l-1,-1,-1):
        if 0<j<l-1:
            x,y,z = map(int,str(ans)[j-1:j+2])
            if y!=9 and abs(x-(y+1))<=1 and abs((y+1)-z)<=1:
                ans = int(str(ans)[:j]+''.join([str(max(0,y+1-i)) for i in range(l-j)]))
                flg = False
                break
        elif j==0:
            x,y = map(int,str(ans)[:2])
            if x != 9 and abs(x+1-y) <=1:
                ans = int(''.join([str(max(0,x+1-i))for i in range(l)]))
                flg = False
                break
        else:
            x,y = map(int,str(ans)[-2:])
            if y != 9 and abs(x-(y+1))<=1:
                ans += 1
                flg = False
                break
    if flg:
        ans = 10**l
print(ans)


Measured memory_bytes: 3064
#include <stdio.h>
#define rep(i, l, r) for (int i = l; i < r; i++)
#define max(a,b) (a > b ? a : b)
#define MAX 100001

int main(void) {
  int n;
  scanf("%d", &n);
  int v[MAX];
  rep(i, 0, n)
    scanf("%d", &v[i]);
  
  /* 最頻値を数える */
  int mode1[MAX] = {0};
  int mode2[MAX] = {0};
  // 奇数列
  for (int i = 0; i < n; i += 2)
    mode1[v[i]]++;
  // 偶数列
  for (int i = 1; i < n; i += 2)
    mode2[v[i]]++;

  int max1[2] = {0}, next1 = 0;  // max[頻度][数], 2番目の頻値
  int max2[2] = {0}, next2 = 0; 
  rep(i, 0, MAX) {
    if (mode1[i] > max1[0]) {
      next1 = max1[0];
      max1[0] = mode1[i];
      max1[1] = i;
    } else if (mode1[i] > next1) {
      next1 = mode1[i];
    }
  }
  rep(i, 0, MAX) {
    if (mode2[i] > max2[0]) {
      next2 = max2[0];
      max2[0] = mode2[i];
      max2[1] = i;
    } else if (mode2[i] > next2) {
      next2 = mode2[i];
    }
  }
  
  int ans;
  if (max1[1] == max2[1]) {
    // if (next1 > next2) 
    //   ans = n - next1 - max2[0];
    // else
    //   ans = n - next2 - max1[0]; 
    ans = n - max(next1 + max2[0], next2 + max1[0]);
  } else
    ans = n - max1[0] - max2[0];
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>

using namespace std;

int main(){
    int N, W;
    while(cin >> N >> W){
        vector<int> v(N), w(N);
        for(int i=0;i<N;i++) cin >> v[i] >> w[i];
        vector<int> dp(W+1, 0);
        for(int i=0;i<N;i++){
            for(int j=0;j<=W-w[i];j++) dp[j+w[i]] = max(dp[j+w[i]], dp[j] + v[i]);
        }
        cout << dp.back() << endl;
    }
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxx = 1e5 + 7;
const ll Inf = 1ll << 60;
int n;
ll m;
ll a[maxx];

int main() {
	while(cin >> n >> m) {
		ll ans = 0;
		for(int i = 1; i <= n; i++) cin >> a[i];
		for(int i = 1; i <= n - 1; i++) {
			ll tmp = a[i] + a[i + 1];
			if(tmp <= m) continue;
			else {
				tmp -= m;
				ans += tmp;
				if(a[i + 1] >= tmp) a[i + 1] -= tmp;
				else a[i + 1] = 0;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1024
//1????????????????£??????£?¶?????????????????????£????????????
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int n, w, h;
int x, y; char f;
int l[1000], r[1000];	//[l, r]

int toId(int px, int py) {
	if (py == 0) return px;
	if (px == w) return w + py;
	if (py == h) return w + h + (w - px);
	return 2 * w + h + (h - py);
}

int lay(int id, int x, int y) {
	int dist;
	int dx[4] = {1, -1, -1, 1};
	int dy[4] = {1, 1, -1, -1};
	
	if (dx[id] == 1) dist = w - x; else dist = x;
	if (dy[id] == 1) dist = min(dist, h - y); else dist = min(dist, y);
	
	int px = x + dist * dx[id];
	int py = y + dist * dy[id];
	return toId(px, py);
}

int main() {
	int i, j;
	
	cin >> n >> w >> h;
	for (i = 0; i < n; i++) {
		cin >> x >> y >> f;
		
		if (f == 'N') {
			l[i] = lay(1, x, y);
			r[i] = lay(0, x, y);
		}
		if (f == 'E') {
			l[i] = lay(0, x, y);
			r[i] = lay(3, x, y);
		}
		if (f == 'S') {
			l[i] = lay(3, x, y);
			r[i] = lay(2, x, y);
		}
		if (f == 'W') {
			l[i] = lay(2, x, y);
			r[i] = lay(1, x, y);
		}
		swap(l[i], r[i]);	//???????¨???????????????????????????????????????§, [???->?£?, ???->?£?]??¨????????????????????????
		if (r[i] < l[i]) {
			r[i] += 2 * w + 2 * h;
		}
	}
	
	typedef pair<int, int> P;
	P p[1000];
	for (i = 0; i < n; i++) p[i] = P(l[i], r[i]);
	sort(p, p + n);
	
	int ans = 114514;
	for (i = 0; i < n; i++) {
		int rMin = p[i].second;
		int ret = 0;
		for (j = 1; j < n; j++) {
			int pl;
			
			if (i + j < n) {
				pl = p[i + j].first;
			}
			else {
				pl = p[i + j - n].first + 2 * w + 2 * h;
			}
			
			if (pl > rMin) {
				ret++;
				rMin = 11451419;
			}
			rMin = min(rMin, p[(i + j) % n].second + (i + j >= n) * (2 * w + 2 * h));
		}
		ret++;
		ans = min(ans, ret);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3136
def smaller(x, y):
	if x < y:
		return x
	return y

N = int(input())
K = int(input())
X = int(input())
Y = int(input())
sum = 0
for i in range(0, smaller(N, K)):
	sum += X
for i in range(K, N):
	sum += Y
print(sum)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  map<char, vector<int>> mp;
  rep(i, s.size()){
    mp[s.at(i)].push_back(i);
  }
  ll ans = 0, index = -1;
  for(char c : t){
    if(mp[c].size() == 0){
      cout << -1 << endl;
      return 0;
    }
    auto itr = upper_bound(ALL(mp[c]), index);
    if(itr == mp[c].end()){
      ans += s.size()-index-1;
      index = -1;
      itr = mp[c].begin();
    }
    ans += (*itr-index);
    index = *itr;
    // cerr << ans << endl;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4264
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
#define ll long long
#define endl '\n'
#define pi 3.14159265
int main()
{
    IOS;
    ll n,k;
    cin>>n>>k;
    vector<ll> v(100001);
    vector<ll> tmp;
    for(ll i=1;i<=n;i++)
    {
        ll x;
        cin>>x;
        tmp.push_back(x);
        v[x]=1;
    }
    ll dp[k+1];
    dp[0]=2;
    dp[1]=1;
    if(v[1]==0)
        dp[1]=2;
    for(ll i=2;i<=k;i++)
    {
        ll ch=0;
        for(ll j=0;j<n;j++)
        {
            if(i-tmp[j]<0)
                break;
            if(dp[i-tmp[j]]==2)
            {
                ch=1;
                break;
            }
        }
        if(ch)
            dp[i]=1;
        else
            dp[i]=2;
    }       
    if(dp[k]==1)
        cout<<"First";
    else
        cout<<"Second";
}

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

int zh (string x){
	int s=0;
	
	for(int i=0; i<x.size(); i++)
		s= s*10 + (x[i]-'0');
	
	return s;
} 

int main(){
	string x,y;
	cin>>x>>y;
	int s;
	x=x+y;
	s=zh(x);
	if(int(sqrt(s))==sqrt(s)) 
		cout<<"Yes";
	else 
		cout<<"No"<<endl;
	return 0;
}


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

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v, n) sort(v, v+n)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define ddvi vector<vector<int>>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
// ここに処理を記述

string S, T;

cin >> S >> T;

cout << T + S << "\n";

return 0;
}

Measured memory_bytes: 256