akhauriyash/Code-Regression huggingface dataset:
#include <stdint.h>
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);
static const ll MOD = 1000000007;

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

ll calc_score(ll D, const vector<ll> &c, const vector<vector<ll>> &s, const vector<ll> &t) {
  vector<ll> last(26, 0);
  ll score = 0;
  REP(d, D) {
    ll i = t[d] - 1;
    score += s[d][i];
    last[i] = d + 1;
    REP(j, 26) {
      score -= c[j] * (d + 1 - last[j]);
    }
  }
  return score;
}

ll calc_diff(ll D, ll pre, ll next, const vector<ll> &c, const vector<vector<ll>> &s, ll d, const vector<ll> &t) {
  ll diff = s[d - 1][next] - s[d - 1][pre];
  {
    ll l = 0;
    FOR(i, 1, d) {
      if (t[i - 1] - 1 == next) {
        l = i;
      }
    }
    ll r = D + 1;
    FOR(i, d + 1, D + 1) {
      if (t[i - 1] - 1 == next) {
        r = i;
        break;
      }
    }
    ll x = r - d;
    ll y = d - l;
    diff += c[next] * x * y;
  }
  {
    ll l = 0;
    FOR(i, 1, d) {
      if (t[i - 1] - 1 == pre) {
        l = i;
      }
    }
    ll r = D + 1;
    FOR(i, d + 1, D + 1) {
      if (t[i - 1] - 1 == pre) {
        r = i;
        break;
      }
    }
    ll x = r - d;
    ll y = d - l;
    diff -= c[pre] * x * y;
  }
  return diff;
}

void solve(ll D, vector<ll> c, vector<vector<ll>> s, vector<ll> t) {
  ll score = calc_score(D, c, s, t);
  ll M;
  scanf("%lld", &M);
  REP(i, M) {
    ll d;
    scanf("%lld", &d);
    ll q;
    scanf("%lld", &q);
    ll pre = t[d - 1] - 1;
    ll next = q - 1;
    t[d - 1] = next + 1;

    score += calc_diff(D, pre, next, c, s, d, t);
    cout << score << endl;
  }
}

int main() {
  ll D;
  scanf("%lld", &D);
  vector<ll> c(26);
  for (int i = 0; i < 26; i++) {
    scanf("%lld", &c[i]);
  }
  vector<vector<ll>> s(D, vector<ll>(26));
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      scanf("%lld", &s[i][j]);
    }
  }
  vector<ll> t(D);
  for (int i = 0; i < D; i++) {
    scanf("%lld", &t[i]);
  }
  solve(D, move(c), move(s), move(t));
  return 0;
}


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

using namespace std;

int main()
{
	int x1, x2;
	while (cin >> x1 >> x2)
	{
		while (x2 > 0)
		{
			int tmp = x1 % x2;
			x1 = x2;
			x2 = tmp;
		}
		cout << x1 << endl;
	}
}

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

int main() {
	int a,b,c;
	cin>>a>>b>>c;
	if(a>b) {
		swap(a,b);
	}
	if(b>c) {
		swap(b,c);
	}
	if(a>b) {
		swap(a,b);
	}
	cout<<a<<" "<<b<<" "<<c<<endl;
	return 0;
}

Measured memory_bytes: 1164
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

import bisect

A.sort()
B.sort()
C.sort()

cnt = 0
for j in range(N):
    i = bisect.bisect_left(A, B[j])
    k = bisect.bisect_right(C, B[j])
    cnt += i *(N-k)

print(cnt)

Measured memory_bytes: 23248
def main():
    from collections import deque
    s = list(input())
    dq = deque()
    for i in s:
        dq.append(i)

    q = int(input())
    flag = True
    for _ in range(q):
        line = input().split(" ")
        if line[0] == "1":
            flag = not flag
        else:
            if line[1] == "1":
                if flag:
                    dq.appendleft(line[2])
                else:
                    dq.append(line[2])
            elif line[1] == "2":
                if flag:
                    dq.append(line[2])
                else:
                    dq.appendleft(line[2])
    if flag == False:
        dq.reverse()
    for i in list(dq):
        print(i,end="")
main()

Measured memory_bytes: 10856
s = input().split()
a, b, m = int(s[0]), int(s[1]), int(s[2])

a_list = [int(i) for i in input().split()]
b_list = [int(i) for i in input().split()]

ans = min(a_list) + min(b_list)

for i in range(m):
    ss = input().split()
    temp = a_list[int(ss[0])-1] + b_list[int(ss[1])-1] - int(ss[2])
    if ans > temp:
        ans = temp

print(ans)


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

int main(){
    const ll m=1000000000;
    ll S;
    cin>>S;
    ll t=S/m+1;
    ll a=t*m-S;
    if(S==1000000000000000000){
        cout<<0<<' '<<0<<' '<<m<<' '<<0<<' '<<0<<' '<<m;
    }
    else cout<<0<<' '<<0<<' '<<t<<' '<<1<<' '<<a<<' '<<m;
    return 0;

}

Measured memory_bytes: 256
//#pragma warning disable
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System;
using System.Numerics;
using System.Threading.Tasks;
using static System.Math;
using static System.Console;
class Z { static void Main() => new K(); }
class K
{
	int F() => int.Parse(ReadLine());
	long FL() => long.Parse(ReadLine());
	int[] G() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray();
	long[] GL() => ReadLine().Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).Select(long.Parse).ToArray();
	public const int MOD = 1000000007;
	public K()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	void Solve()
	{
		var I = G();
		var l = I[0] + I[1];
		var r = I[2] + I[3];
		WriteLine(l > r ? "Left" : l == r ? "Balanced" : "Right");
	}
}


Measured memory_bytes: 13268
#![allow(unused_imports)]
use itertools::Itertools;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
use superslice::*;

fn main() {
    input! {
        n: usize,
        a: [i64;n+1],
    }

    if n == 0 && a[0] == 1 {
        println!("1");
        return;
    } else if n == 0 {
        println!("-1");
        return;
    }

    let mut mx1 = vec![0; n + 2];
    for i in 0..n + 1 {
        mx1[i + 1] = mx1[i] + a[n - i];
    }
    mx1.reverse();

    let mut ans = 1;
    let mut bef = 1;

    for i in 1..n + 1 {
        let mx = (bef - a[i - 1]) * 2;
        let node_count = min(mx, mx1[i]);
        if node_count < a[i] {
            ans = -1;
            break;
        }
        ans += node_count;
        bef = node_count;
    }

    println!("{}", ans);
}


Measured memory_bytes: 4388
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

int sqrtb(int a) {
	int l = 1, u = (int)sqrt(a) + 10;
	while(u - l > 1) {
		int c = (l + u) / 2;
		if (c * c <= a) {
			l = c;
		} else {
			u = c;
		}
		// cout << l << "," << u << endl;
	}
	return l;
}

signed main(){
	int Q;
	cin >> Q;
	for(int i = 0; i < Q; ++i) {
		int A, B;
		cin >> A >> B;
		if(A > B) swap(A,B);
		if(B == 1) {
			cout << 0 << endl;
			continue;
		}
		int M = A * B - 1;
		int L = (int)sqrtb(M);
		// cout << L * L << "," << M << "," << (L + 1) * (L + 1);
		// cerr << L << "," << sqrt(M) << endl;
		int t = 2 * L - (M / L == L);
		if(A <= L) {
			--t;
		}
		cout << t << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define M 100000

long prime[M] = {};
int count = 0;

void solve()
{
    int flag[M] = {0};
    for (int i = 2; i < M + 1; i++)
    {
        if (flag[i] == 0)
        {
            prime[count] = i;
            count++;

            for (int j = i * 2; j <= M; j += i)
            {
                flag[j] = 1;
            }
        }
    }
}

int main(void)
{
    solve();
    while (1)
    {
        int m, a, b;
        scanf("%d %d %d", &m, &a, &b);
        if ((m | a | b) == 0)
            break;
        double rate = (double)a / b;
        long max = 0;
        long ans_i, ans_j;

        for (long i = 0; i <= count; i++)
        {
            if (prime[i] > m)
                break;
            for (long j = 0; j <= count; j++)
            {
                if (prime[i] * prime[j] <= m)
                {
                    double rate2 = (double)prime[i] / prime[j];

                    if (rate2 >= rate && rate2 <= 1)
                    {
                        if (max < prime[i] * prime[j])
                        {
                            ans_i = prime[i];
                            ans_j = prime[j];
                            max = prime[i] * prime[j];
                        }
                    }
                }
                else
                {
                    break;
                }
            }
        }
        printf("%ld %ld\n", ans_i, ans_j);
    }
}


Measured memory_bytes: 2244
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string.h>

using namespace std;
int dp[1001][1001];

void solve()
{
	int W;
	int count = 1;
	while(cin >> W, W)
	{
		int N;
		cin >> N;
		vector<int> w(N);
		vector<int> v(N);
		memset(dp, 0, sizeof(dp));
		for(int i = 0; i < N; ++i)
		{
			scanf("%d,%d", &v[i], &w[i]);
		}
		for(int i = 0; i < N; ++i)
		{
			for(int j = 0; j <= W; ++j)
			{
				if(j < w[i])
				{
					dp[i + 1][j] = dp[i][j];
				}
				else
				{
					dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
				}
			}
		}
		int pos = 0;
		for(int i = 0; i <= W; ++i)
		{
			if(dp[N][i] > dp[N][pos])
			{
				pos = i;
			}
		}
		cout << "Case " << count << ":" << endl;
		cout << dp[N][pos] << endl; 
		cout << pos << endl;
		++count;
	}
}

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

Measured memory_bytes: 5180
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		
		while(true){
			line = br.readLine();
			int num = Integer.valueOf(line);
			if(num == 0){
				break;
			}
			System.out.println(getNewNum2(num));
		}
	}
	
/*	private static long getNewNum(int target){
		long cnt = 0;
		for(long i = 1; ; i++){
			String str = String.valueOf(i + cnt);
			if(str.contains("4") || str.contains("6")){
				cnt++;
				continue;
			}
			if(i == target){
				return i + cnt;
			}
		}
	}*/
	
	private static long getNewNum2(int target){
		int[] tb = {0, 1, 2, 3, 5, 7, 8, 9};
		String str = Integer.toOctalString(target);
		
		String result = "";
		for(String s : str.split("")){
			int i = Integer.parseInt(s);
			result = result + tb[i];
		}
		
		return Long.parseLong(result);
	}
}

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

vector<int>to[200005],ans;
void dfs(int v,int p=-1){
    for(int u:to[v]){
        if(u==p)continue;
        ans[u]+=ans[v];
        dfs(u,v);
    }
}

int main(){
    int n,q;
    cin>>n>>q;
    rep(i,n-1){
        int a,b; cin>>a>>b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    ans.resize(n);
    rep(i,q){
        int p,x; cin>>p>>x;
        --p;
        ans[p]+=x;
    }
    dfs(0);
    rep(i,n){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

double f(int N, double d1, double x) {
	return d1 + (2 * N - 1) * x / 2;
}

int main() {
	int N;
	double d1, x;
	while (cin >> N >> d1 >> x) {
		double r = 0;
		while (N) {
			r += f(N, d1, x);
			double d2 = d1 + x;
			d2 += (d2 * 2 + x * 7) / (2 * N);
			d1 += (d1 * 2 + x * 5) / (2 * N);
			x = d2 - d1;
			--N;
		}
		printf("%.9f\n", r);
	}
}


Measured memory_bytes: 256
N = int(input())
int_list = list(map(int, input().split()))

sum_num = 0
sum_temp = sum(int_list[1:])

for i in range(N-1):
  sum_num += int_list[i] * sum_temp
  sum_temp -= int_list[i+1]
    
print(sum_num % (10 ** 9 + 7))

Measured memory_bytes: 105480
_,*a=map(str.split,open(0))
U,R,D,L=S="URDL"
d={i:[]for i in S}
for*z,u in a:d[u]+=[*map(int,z)],
N,P,M=9e9,"x+y,","x-y,"
for*F,S in(D,U,"x,y,"),(L,R,"y,x,"),(U,R,P+M),(L,D,P+M),(L,U,M+P),(D,R,M+P):
 n=p=-9e9
 for x,y,r in sorted(eval(f"[({S}Q)for Q,P in enumerate(F)for x,y in d[P]]")):
  if r:n,p=x,y
  elif x==n:N=min(N,y-p)
print(["SAFE",N*5][N<9e9])##

Measured memory_bytes: 131328
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  fix(12);
  while(1){
    int n; cin>>n;
    if(n==0) break;
    double c=0,a[n];
    rep(i,0,n){
      cin>>a[i];
      c+=a[i];
    }
    double av=c/n,as=0;
    rep(i,0,n){
      as+=(a[i]-av)*(a[i]-av);
    }
    as/=n;
    co(pow(as,0.5));
  }
    
  return 0;
}


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

  long long A,B,C;
  cin>>A>>B>>C;
  if(A%2==0||B%2==0||C%2==0){
  
    cout<<0;
    return 0;
  }
  long long ans=0;
  long long anscheck=0;
  anscheck=B*C;
  ans=anscheck;
  anscheck=A*C;
  ans=min(ans,anscheck);
  anscheck=A*B;
  ans=min(ans,anscheck);
  cout<<ans;
  return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
int main(){
   int n,m,sum=0,cnt=0;
   cin >> n >> m;
   int a[n];
   for(int i=0;i<n;i++){
       cin >> a[i];
       sum += a[i];
   } 
   for(int i=0;i<n;i++){
       if(sum<=4*m*a[i]) cnt++;
   }
   if(m<=cnt) cout << "Yes" << endl;
   else cout << "No" << endl;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (D, G) = readLine()!!.split(" ").map(String::toInt)
    val PCD = Array(D) { readLine()!!.split(" ").map(String::toInt).let { it[0] to it[1] } }
    val P = PCD.map(Pair<Int, Int>::first)
    val C = PCD.map(Pair<Int, Int>::second)

    var res = Long.MAX_VALUE

    for (bit in 0..(1 shl D)) {
        var sum = 0L
        var num = 0L
        for (i in 0 until D) {
            if ((1 shl i) and bit > 0) {
                sum += P[i] * 100 * (i + 1) + C[i]
                num += P[i]
            }
        }

        if (sum >= G) {
            res = Math.min(num, res)
            continue
        }
        for (i in D - 1 downTo 0) {
            if ((1 shl i) and bit > 0) {
                continue
            }
            for (j in 0 until P[i] - 1) {
                if (sum >= G) {
                    break
                }
                sum += (i + 1) * 100
                ++num
            }
        }
        if (sum >= G) {
            res = Math.min(num, res)
        }

    }

    println(res)
}



Measured memory_bytes: 38104
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
typedef long long int ll;
#define mod 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define m0(x) memset(x,0,sizeof(x))

int main(void){

	char s[100000];
	scanf("%s",s);
	int a=0,b=0;
	int n=strlen(s);
	//10101010列
	rep(i,n){
		if(i%2==0){
			if(s[i]!='1') a++;
		}
		else{
			if(s[i]!='0') a++;
		}
	}
	//01010101列
	rep(i,n){
		if(i%2==0){
			if(s[i]!='0') b++;
		}
		else{
			if(s[i]!='1') b++;
		}
	}
	if(a>b) printf("%d",b);
	else printf("%d",a);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int n;
  cin >> n;
  switch(n){
  case 22:
    cout << "Christmas Eve Eve Eve" << endl;
    break;
  case 23:
    cout << "Christmas Eve Eve" << endl;
    break;
  case 24:
    cout << "Christmas Eve" << endl;
    break;
  case 25:
    cout << "Christmas" << endl;
    break;

  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int d = sc.nextInt();
		int g = sc.nextInt();
		int p[] = new int[d];
		int c[] = new int[d];
		for (int i=0;i<d;i++) {
			p[i] = sc.nextInt();
			c[i] = sc.nextInt();
		}
		System.out.println(result(d,g,p,c));

	}

	private static int result(int d, int g, int[] p, int[] c) {
		int ans = Integer.MAX_VALUE;
		
		for (int i = 0; i<1<<d;i++) {
			int maxj = 0;
			int count = 0;
			int score = 0;
			for (int j=0;j<d;j++)
				if ((i>>j)%2==1) {
					count+=p[j];
					score += (j+1)*100*p[j] + c[j];
				} else
					maxj = j;
			if (score<g) {
				int t = (g-score+(maxj+1)*100-1)/((maxj+1)*100);
				if (t>=p[maxj]) {
					continue;
				}
				count +=t;
			}
			if (ans>count) ans=count;
		}
		
		return ans;
	}



}


Measured memory_bytes: 22868
N, K = map(int, input().split())
A = sorted([int(a) for a in input().split()], key = lambda x: -abs(x))
P = 10 ** 9 + 7
m = 0
ans = 1
lp = 0
lm = 0
np = 0
nm = 0
for a in A[:K]:
    if a > 0:
        lp = a
        ans = ans * a % P
    elif a < 0:
        lm = a
        m ^= 1
        ans = ans * a % P
    else:
        print(0)
        exit()

if m == 0:
    print(ans)
    exit()

for a in A[K:]:
    if a > 0:
        np = a
        break
for a in A[K:]:
    if a < 0:
        nm = a
        break

if lp and nm and lm and np:
    if lp * np > lm * nm:
        print(ans * pow(lm, P-2, P) * np % P)
    else:
        print(ans * pow(lp, P-2, P) * nm % P)
elif lp and nm:
    print(ans * pow(lp, P-2, P) * nm % P)
elif lm and np:
    print(ans * pow(lm, P-2, P) * np % P)
else:
    A = A[::-1][:K]
    ans = 1
    for a in A:
        ans = ans * a % P
    print(ans)


Measured memory_bytes: 31608
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct edge {
  int from;
  int to;
};
typedef pair<int, int> P;

int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;

  vector<edge> E[N];
  int A[M];
  int B[M];
  for (int i = 0; i < M; ++i) {
    cin >> A[i] >> B[i];
    edge e = {A[i] - 1, B[i] - 1};
    E[A[i] - 1].push_back(e);
    edge e2 = {B[i] - 1, A[i] - 1};
    E[B[i] - 1].push_back(e2);
  }

  priority_queue<P, vector<P>, greater<P> > que;
  int d[N];
  d[0] = 0;
  for (int i = 1 ; i < N; ++i)
    d[i] = 10000000;

  que.push(P(0, 0));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;
    for (int i = 0; i < E[v].size(); ++i) {
      edge e = E[v][i];
      if (d[e.to] > d[v] + 1) {
        d[e.to] = d[v] + 1;
        que.push(P(d[e.to], e.to));
      }
    }
  }

  cout << "Yes" << endl;

  for (int i = 1; i < N; ++i) {
    int min_d = 10000000;
    int ret;
    for (int j = 0; j < E[i].size(); ++j) {
      if (min_d > d[E[i][j].to]) {
        ret = E[i][j].to;
        min_d = d[E[i][j].to];
      }
    }
    cout << ret + 1 << endl;
  }


  return 0;
}

Measured memory_bytes: 14580
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  int n;
  cin >> n;
  ll ans = 1LL, x;
  for(int i = 0; i < n; i++){
    cin >> x;
    if(x == 0) ans = 0;
    if(ans == -1 or ans == 0) continue;
    if( __int128(ans) * x > ll(1e18)) ans = -1;
    else ans *= x;
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define ll long long
#define mp make_pair
#define ii pair<int,int>
using namespace std;
int n,m;
ii a[200005];
vector < int > v[200005];
int main()
{
    cin>>n>>m;
    for(int i=0;i<n;i++)
    {
        scanf("%d%d",&a[i].fr,&a[i].sc);
        v[a[i].fr].push_back(a[i].sc);
    }
       for(int i=0;i<=200000;i++)
       {
           sort(v[i].begin(),v[i].end());
           reverse(v[i].begin(),v[i].end());
       }
    multiset < int > r;
    for(int i=m;i>=1;i--)
    {
        int can = m-i+1;
        if(can < 0)
            continue;

        for(int j=0;j<min((int)v[i].size(),can);j++)
        {
            r.insert(v[i][j]);
            if(r.size() > can)
            {
                multiset < int > :: iterator itr = r.begin();
                r.erase(r.find(*itr));
            }
        }
    }
   ll ans = 0;
   for(auto x : r)
    ans+=x;
    cout<<ans<<endl;
}


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

n,k = inpl()
a = inpln(n)
a.sort()
res = INF
for i in range(n-k+1):
    res = min(res, a[i+k-1] - a[i])
print(res)

Measured memory_bytes: 44380
#include <iostream>
#include <queue>
#include <vector>
#define rep(i,n) for (int i = 0; i < (n); ++i)
const int INF = 1001001001;

using namespace std;
int main(void){
   int n, m;
  cin >> n >> m;vector<int> to[100005];
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
 
  queue<int> q;
  vector<int> dist(n, INF);
  vector<int> pre(n, -1);
  dist[0] = 0;
  q.push(0);
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : to[v]) {
      if (dist[u] != INF) continue;
      dist[u] = dist[v]+1;
      pre[u] = v;
      q.push(u);
    }
  }
 
  cout << "Yes" << endl;
  rep(i,n) {
    if (i == 0) continue;
    int ans = pre[i];
    ++ans;
    cout << ans << endl;
  }
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<n;++i)
#define RREP(i,n) for(ll i=n-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<n;++i)
#define RFOR(i,m,n) for(ll i=n-1;i>=m;--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }
///(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)(´・ω・`)///

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	map<int, int> m;
	ll c = 0, d = 0;
	vl v;
	REP(i, n) {
		int a;
		cin >> a;
		m[a]++;
		if (m[a] == 2) {
			v.push_back(a);
		}
		else if (m[a] == 4) {
			v.push_back(a);
		}
	}
	sort(ALL(v));
	if (v.size() < 2) {
		cout << 0 << endl;
	}
	else {
		cout << v[v.size() - 2] * v[v.size() - 1] << endl;
	}
}


Measured memory_bytes: 4992
# frozen_string_literal: true

a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = gets.to_i
puts a[k - 1]


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N; cin >> N;

  int count = 0;
  int ans = 0;
  vector<long long int> H(N);
  for(int i = 0; i < N; i++){
    cin >> H.at(i);
    if(i > 0 && H.at(i) <= H.at(i-1)){
      count++;
    }else{
      ans = max(count ,ans);
      count = 0;
    }
  }
  ans = max(count ,ans);
  
  cout << ans;
  return 0;
}


Measured memory_bytes: 1024
import math
N=10000
prime=[1]*(N+1)
prime[0],prime[1]=0,0
for i in range(2,int(math.sqrt(N))):
    if prime[i]==1:
        j=i
        while i*j<=N:
            prime[i*j]=0
            j+=1

while True:
    try:
        n=input()
    except EOFError:
        break
    cnt=0
    for i,j in zip(prime[1:n+1],prime[1:n+1][::-1]):
        if i==j==1:
            cnt+=1
    print cnt

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

vector<int>num_357 ;

int function(int64_t A,int X){
  if(A>X) return 0 ;
  string S ;
  if(A==0) S="" ;
  S=to_string(A) ;
  int flag3=0,flag5=0,flag7=0 ;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='3') flag3=1 ;
    else if(S.at(i)=='5') flag5=1 ;
    else if(S.at(i)=='7') flag7=1 ;
  }
  if(flag3*flag5*flag7==1) num_357.push_back(A) ;
  
  /*Xの後ろに3,5,7をそれぞれ足す*/
  A=stol(S+'3') ;
  function(A,X) ;
  A=stol(S+'5') ;
  function(A,X) ;
  A=stol(S+'7') ;
  function(A,X) ;
}

int main()
{
  int N ;
  cin>>N ;
  if(N<357){
    cout<<0<<endl ;
    return 0 ;
  }
  function(0,N) ;
  cout<<num_357.size()<<endl ;
  return 0 ;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int i,n,c,d,ans,e;
	cin >> n;
	int P[n];
	int Q[n];
	for(i=0;i<n;i++){
		cin >> P[i];
		Q[P[i]] = i;
	}
	for(i=1;i<=n;i++){
	//cout << Q[i] << endl;
	}
	c = 0;
	d = 0;
	for(i=1;i<n;i++){
		if(Q[i]<Q[i+1]){
			c++;
			e = 1;
		}else{
			d = max(d,c);
			//cout << d <<" " <<  i << endl;
			c = 0;
		}
	}
	if(e=1){
		d = max(d,c);
	}
	//cout << d << endl;
	cout << n-d-1 << endl;
	
}

		
	

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

input()
numbers = [int(i) for i in input().split(' ')]

operateCount = 0
while True:
  if (all(num % 2 == 0 for num in numbers)):
    numbers = [num / 2 for num in numbers]
    operateCount += 1
  else:
    break
print(operateCount)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, C, ans = 0;
  cin >> N >> M >> C;
  vector<int> B(M);
  for(int i = 0; i < M; i++){
    cin >> B.at(i);
  }
  for(int i = 0; i < N; i++){
    int eval=0;
    for(int i = 0; i < M; i++){
      int a;
      cin >> a;
      eval += a * B.at(i);
    }
    eval += C;
    if(eval > 0){
      ans += 1;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

void mdc(int a, int b, int k){
	int aux, div = 0, aux2 = 0;
	if(a > b)
		aux = a;
	else
		aux = b;


	for(int i=aux; i>=1; i--){
		if(a % i == 0 and b % i == 0 and aux2 != k){
			div = i;
			aux2++;
		}
	}

	cout << div << endl;
}


int main(){

	ios::sync_with_stdio(false);

	int a, b, k;
	cin >> a >> b >> k;


	mdc(a, b, k);

	return 0;
}

Measured memory_bytes: 256
N = int(input())
s = [0]*N
for i in range(N):
    s[i] = int(input())

l = [x for x in s if x%10]

if len(l) == 0:
    print(0)
    exit()

hoge = sum(s)

if hoge % 10 != 0:
    print(hoge)
    exit()

print(hoge-min(l))

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)



int main() {

    int n,a,b; cin >> n >> a >> b;
    if(a*n > b) cout << b << endl;
    else cout << a*n << endl;

    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <random>
#include <iterator>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

bool is_less(int val, int c) {
	return (val <= c);
}


int main() {
	long long sum = 0;
	int n, m;
	cin >> n >> m;
	VI v(n);
	vector<P> bc(m);

	REP(i, n) {
		cin >> v[i];
	}
	SORT(v);

	REP(i, m) {
		int b, c;
		cin >> b >> c;
		P p = make_pair(c, b);
		bc[i] = p;
	}
	SORT(bc);
	reverse(bc.begin(), bc.end());

	REP(i, n) {
		sum += v[i];
	}

	int changed = 0;
	long long plused = 0;
	REP(i, m) {
		int less_than = lower_bound(v.begin() + changed, v.end(), bc[i].first) - v.begin()-changed;
		less_than = min(less_than, bc[i].second);
		changed += less_than;
		plused =plused + (long long)bc[i].first*less_than;
	}
	long long minus = 0;
	REP(i, changed) {
		minus += v[i];
	}
	sum = sum - minus + plused;
	ANS(sum)




	return 0;

}


Measured memory_bytes: 1408
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i = 0; i <= VMAX; i++) C[i] = 0;

  for(i = 0; i < n; i++){
    scanf("%hu", &A[i+1]);
    C[A[i+1]]++;
  }

  for(i = 1; i <= VMAX; i++) C[i] = C[i] + C[i-1];

  for(j = 1; j <= n; j++){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }  
  
  for(i = 1; i <= n; i++){
    if(i > 1) printf(" ");
    printf("%d",B[i]);
  }
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 9564
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as B

main = do
    n <- read <$> getLine :: IO Int
    ns <- replicateM n ((\[a,b]->(b-a)+1) . map (fst . fromJust . B.readInt) . B.words <$> B.getLine) :: IO [Int]
    print $ sum ns


Measured memory_bytes: 1148
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    X = int(rl())
    ans = 1000 * (X // 500)
    X -= ans // 2
    ans += 5 * (X // 5)
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 2940
n,k=map(int,input().split())
h=sorted([int(input()) for _ in range(n)])
dis=[0]*(n)
bh=h[0]
for i,ah in enumerate(h[1:]):
    dis[i]=ah-bh
    bh=ah
s=sum(dis[:k-1])
ms=s
for i in range(k-1,n-1):
    s+=dis[i]-dis[i-k+1]
    ms=min(ms,s)
print(ms)

Measured memory_bytes: 11836
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */
const ll MOD = 1e9+7;
int main() {
  string s; cin >> s;
  ll n = s.size();
  ll dp[n+1][4] = {0};
  dp[0][0] = 1;
  REP(i, n){
    ll c = s[i] == '?' ? 3 : 1;
    REP(j, 4) (dp[i+1][j] += c*dp[i][j] % MOD) %= MOD;
    if(s[i] == '?'){
      REP(j, 3) (dp[i+1][j+1] += dp[i][j] ) %= MOD;
    }else{
      ll tmp = s[i] - 'A';
      (dp[i+1][tmp+1] += dp[i][tmp]) %= MOD;
    }
  }
  cout << dp[n][3] << endl;
}



Measured memory_bytes: 3584
import java.util.*;
import java.math.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        String[] s = new String[h];
        char[][] ar = new char[h][w];
        for (int i = 0; i < h; i++) {
            s[i] = sc.next();
            for (int j = 0; j < w; j++) {
                ar[i][j] = s[i].charAt(j);
            }
        }
        int x = 0;
        int y = 0;
        boolean f = true;

        while (true) {
            ar[x][y] = '.';
            if (x == h - 1 && y == w - 1) {
                break;
            }

            if (x + 1 < h && ar[x + 1][y] == '#') {
                x++;
            } else if (y + 1 < w && ar[x][y + 1] == '#') {
                y++;
            } else {
                f = false;
                break;
            }
        }

        for (int i = 0; i < h; i++) {
            for (int j = 0; j < w; j++) {
                if (ar[i][j] == '#') {
                    f = false;
                }
            }
        }

        System.out.println(f ? "Possible" : "Impossible");

        sc.close();
    }
}

class io {
    public static void br() {
        System.out.println("");
    }

    public static void yesno(boolean f) {
        System.out.println(f ? "yes" : "no");
    }

    public static void YesNo(boolean f) {
        System.out.println(f ? "Yes" : "No");
    }

    public static void YESNO(boolean f) {
        System.out.println(f ? "YES" : "NO");
    }

}

class Algo {
    public static int nibutan(int target, int[] ar) {
        // ar[i] >= target なる最小のiを探す
        int res;
        int high = ar.length;
        int low = 0;
        while (high > low) {
            res = (high + low) / 2;
            if (ar[res] < target) {
                // ↑↓ここを変える
                low = res + 1;
            } else {
                // ↓ここを変える
                high = res;
            }
        }
        return low;
    }

    public static boolean isOdd(int n) {
        return n % 2 == 1;
    }

    public static boolean isEven(int n) {
        return n % 2 == 0;
    }


}



Measured memory_bytes: 21844
N = int(input())
a = [0] + list(map(int, input().split()))
b = set([i for i in range(N//2 + 1, N + 1) if a[i] == 1])

for i in range(N//2, 0, -1):
    k, temp = 2, 0
    while k * i < N + 1:
        if k * i in b:
            temp += 1
        k += 1
    if temp % 2 != a[i]:
        b.add(i)

if len(b) > 0:
    print(len(b))
    print(' '.join(list(map(str, sorted(list(b))))))
else:
    print(0)

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

typedef long long LL;

const int N = 1e5+7, RT = 100;
int a[N];
LL sum[N][RT];

LL query(int l, int r, int d) {
    assert((r-l)%d==0);
    if (d < RT) {
        if (l<=d)    return sum[r][d];
        return sum[r][d] - sum[l-d][d];
    }

    LL ans = 0;
    for (int i=l; i<=r; i+=d)   ans += a[i];
    return ans;
}

vector<int> divs[N];
int cnt[N];

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

    for (int i=1; i<N; i++)
        for (int j=i; j<N; j+=i)
            divs[j].push_back(i);

    int n;
    cin>>n;
    n--;

    for (int i=0; i<=n; i++)    cin>>a[i];
    for (int i=1; i<RT && i<=n; i++) {
        for (int j=1; j<=n; j++) {
            sum[j][i] = a[j];
            if (j>=i)  sum[j][i] += sum[j-i][i];
        }
    }

    LL ans = 0;
    for (int a=1; a<n; a++) {
        for (int d: divs[n-a]) {
            if (d >= a) break;
            int k = (n-a)/d;
            if (a%d==0 && k*d>=a)   continue;
            LL x = query(a, n, d) ;
            LL y = query(d, k*d, d);
            LL cur =  x + y;
            ans = max(ans, cur);
//            cout<<a<<" "<<a-d<<" = "<<cur<<" "<<x<<" "<<y<<endl;
        }
    }
    cout<<ans<<endl;
}


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

N = int(input())

counter = 0

def func(cur=0, use=0):
    global counter
    if cur > N:
        return None
    if use == 0b111:
        counter += 1
    func(cur * 10 + 7, use | 0b001)
    func(cur * 10 + 5, use | 0b010)
    func(cur * 10 + 3, use | 0b100)

func()
print(counter)


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

using namespace std;

int D;
int c[27];
int s[410][27];
const int MAX = 26;

int ans[410];

int last[27];
long long dec = 0, score = 0;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> D;

	for(int i = 1; i <= MAX; i++) cin >> c[i];

	for(int i = 1; i <= D; i++){
		for(int j = 1; j <= MAX; j++){
			cin >> s[i][j];
		}
	}

	for(int i = 1; i <= D; i++){
		cin >> ans[i];

		score += s[i][ans[i]];

		last[ans[i]] = i;
		for(int j = 1; j <= MAX; j++){
			score -= c[j] * (i - last[j]);
		}

		cout << score << "\n";
	}

	return 0;
}

Measured memory_bytes: 3700
import java.util.Scanner;

public class Main {
    static int[][] map;
    static int[][] label;

    static int M;
    static int N;
    static int T;
    static int P;
    static int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int N = scanner.nextInt();

        int cnt = 0;
        for (int i = 0; i < N; i++) {
            int temp = scanner.nextInt();

            if(temp % 2 == 1)cnt++;
        }

        if(cnt % 2 == 0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }


    }



}


Measured memory_bytes: 48716
# 2019/08/13

sx,sy,tx,ty=map(int,input().split())

lr=tx-sx
ud=ty-sy

ans=[('R'*lr),
    ('U'*ud),
    ('L'*lr),
    ('D'*ud),
    ('D'),
    ('R'*(lr+1)),
    ('U'*(ud+1)),
    ('L'),
    ('U'),
    ('L'*(lr+1)),
    ('D'*(ud+1)),
    ('R')
    ]
print(''.join(ans))

Measured memory_bytes: 3064
S = input()
i = 0
parts = [S[0]]
parts_append = parts.append
while i < len(S) - 1:
    if S[i + 1] == parts[-1]:
        parts_append(S[i + 1:i + 3])
        i += 2
    else:
        parts_append(S[i + 1])
        i += 1

print(len(parts) - (1 if i == len(S) else 0))

Measured memory_bytes: 8068
#include <iostream>
using namespace std;
 
int main(){
	int x,y;
    while(1){
		cin >> x >> y;
		if ( x == 0 && y ==0 ) {
			break;
		}else{
			if ( x > y ) {
				cout << y << " " << x << "\n";
			}else{
				cout << x << " " << y << "\n";
			}
		}
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
//typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef pair<ll,pll> plpll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const int INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, k;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> k;
    int cnt = 0;
    int ans = 1;
    while (cnt < n && ans < k) {
      ans *= 2;
      cnt++;
    }
    while (cnt < n) {
      ans += k;
      cnt++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char tmp[1000010];
int n;
string s;

char re(char a){
    return a == 'S' ? 'W' : 'S';
}

int isisOK(int i){
    if(tmp[i] == 'S'){
        return (s[i] == 'o' ? tmp[(n+i-1)%n] == tmp[(i+1)%n] : tmp[(n+i-1)%n] != tmp[(i+1)%n]);
    }else{
        return (s[i] == 'x' ? tmp[(n+i-1)%n] == tmp[(i+1)%n] : tmp[(n+i-1)%n] != tmp[(i+1)%n]);
    }
}

bool isOK(int one, int two){
    tmp[0] = (one == 0 ? 'S' : 'W');
    tmp[1] = (two == 0 ? 'S' : 'W');

    for(int i = 1;i < n-1;i++){
        if(tmp[i] == 'S'){
            if(s[i] == 'o'){
                tmp[i+1] = tmp[i-1];
            }else{
                tmp[i+1] = re(tmp[i-1]);
            }
        }else{
            if(s[i] == 'x'){
                tmp[i+1] = tmp[i-1];
            }else{
                tmp[i+1] = re(tmp[i-1]);
            }
        }
    }

    return isisOK(n-1) && isisOK(0);
}

int main(){
    cin >> n >> s;

    for(int i = 0;i < 2;i++){
        for(int j = 0;j < 2;j++){
            if(isOK(i, j)){
                for(int x = 0;x < n;x++){
                    cout << tmp[x];
                }
                cout << endl;
                return 0;
            }
        }
    }

    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    vector<int> hoge(5);
    for(int i=0; i<5; i++){
        cin>>hoge.at(i);
    }
    int k;
    cin>>k;
    string ans = "Yay!";
    for(int i=0; i<5; i++){
        for(int j=0; j<5; j++){
            if(abs(hoge.at(i)-hoge.at(j))>k) ans=":(";
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,y,nx,ny;
  int a[]={1,3,5,7,8,10,12};
  int b[]={4,6,9,11};
  cin>>x>>y;
  for(int i=0;i<7;i++){
    if(a[i]==x)nx=1;
    if(a[i]==y)ny=1;
  }
  for(int i=0;i<4;i++){
    if(b[i]==x)nx=2;
    if(b[i]==y)ny=2;
  }
  if(x==2)nx=3;
  if(y==2)ny=3;
  if(nx==ny)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数　ATCODER_AMARIに注意
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    //sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() {
  ll a,b,x; cin >> a >> b >> x;
  ll ans = 0;
  ll ans_a = 0, ans_b = 0;

  if(a == 0) {
    ans_a = 0;
  }
  else{
    ans_a = (a-1)/x+1;
  }
  ans_b = b/x + 1;

  ans = ans_b - ans_a;

  // ll kosu = b - a + 1;
  // ll syoko = a % x;
  // ll zero_position = INF,tmp = syoko;
  // ll current_pos = 1;
  // 
  // rep(i,x){
  //   if(tmp % x == 0) {
  //     zero_position = current_pos;
  //     break;
  //   }
  //   tmp++;
  //   current_pos++;
  // }
  // 
  // ll number_group = kosu / x;
  // ll rem_kou = kosu % x;
  // ll ans = 0;
  // if(rem_kou >= zero_position) {
  //   ans++;
  // }
  // ans += number_group;

  cout << ans << endl;
}



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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a <= c && c <= b) {
    cout << "Yes";
  }else if(c <= a && b <= c){
    cout << "Yes";
  }else{
    cout << "No";
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<stdio.h>
using namespace std;
typedef long long ll;
ll mod = 998244353;

int main(){
	int A,B,T;
	cin>>A>>B>>T;
	int i = 0;
	int ans = 0;
	for(int i = 1; i <= T; i++){
		if(i % A == 0)ans += B;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main (String[] args) {

//	パターン1（Aから順番に使って足していく）
//	変数を読み込む
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int K = sc.nextInt();

		int total = 0;  //合計を入れる変数

//	Aから順に、合計K枚になるまで足していく
		if(A >= K) {  //A>KならKの枚数を表示で終了
			System.out.println(total=K);
			return;
		}
		else {  //A＜Kの場合は続く
			total = A;
		}

//	BがK-Aより多いか少ないかで判断
		if(B < K-A) {  //B<=K-AならK-A-B枚分-1をする
			System.out.println(total-= K-A-B);
		}
		else {  //B>K-Aならそのまま表示
			System.out.println(total);
			return;
		}
	}
}


Measured memory_bytes: 27084
def solve():
    c = list(map(int, input().split()))
    c = [min(10, e) for e in c]
    
    if c == [0]:
        return 1
    if len(c) > 21:
        print(0)
        return 0
    else:
        ans = 0
        for bit in range(1 << len(c)):
            s = 0
            for i in range(len(c)):
                if c[i] != 1:
                    s += c[i]
                else:
                    if bit >> i & 1:
                        s += 11
                    else:
                        s += 1
            if s <= 21:
                ans = max(ans, s)
        print(ans)
        return 0

def main():
    while solve() == 0:
        pass

if __name__ == '__main__':
    main()



Measured memory_bytes: 5604
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<stdio.h>
#include<time.h>
#include<math.h>
#include<algorithm>
#include<string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<map>
#define REP(i, N) for(ll i = 0; i < N; ++i)
#define FOR(i, a, b) for(ll i = a; i < b; ++i)
#define ALL(a) (a).begin(),(a).end()
#define pb push_back
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int qx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
int qy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

int main(void) {
	while(true) {
		int w, h;
		cin>>w>>h;
		if(w == 0 && h == 0) break;
		vector<vector<int> > d(h, vector<int>(w, INF));
		vector<vector<int> > m(2 * h - 1, vector<int>(w));
		REP(i, 2 * h - 1) {
			if(i % 2 == 0) {
				REP(j, w - 1) {
					cin>>m[i][j];
				}
			} else {
				REP(j, w) {
					cin>>m[i][j];
				}
			}
		}
		d[0][0] = 0;
		queue<P> q;
		q.push(P(0, 0));
		while(!q.empty()) {
			P p = q.front();
			q.pop();
			REP(i, 4) {
				ll nh = p.first + dx[i];
				ll nw = p.second + dy[i];
				if(nh >= 0 && nh < h && nw >= 0 && nw < w && d[nh][nw] == INF) {
					switch(i) {
						case 0: {
							if(m[2 * p.first + 1][p.second] == 0) {
								d[nh][nw] = d[p.first][p.second] + 1;
								q.push(P(nh, nw));
							}
							break;
						}
						case 1: {
							if(m[2 * p.first][p.second] == 0) {
								d[nh][nw] = d[p.first][p.second] + 1;
								q.push(P(nh, nw));
							}
							break;
						}
						case 2: {
							if(m[2 * (p.first - 1) + 1][p.second] == 0) {
								d[nh][nw] = d[p.first][p.second] + 1;
								q.push(P(nh, nw));
							}
							break;
						}
						case 3: {
							if(m[2 * p.first][p.second - 1] == 0) {
								d[nh][nw] = d[p.first][p.second] + 1;
								q.push(P(nh, nw));
							}
							break;
						}
					}
				}
			}
		}
		if(d[h - 1][w - 1] == INF) cout<<0<<endl;
		else cout<<d[h - 1][w - 1] + 1<<endl;
	}
}

Measured memory_bytes: 3048
#include<iostream>
#include<set>
#include <bitset>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
#include <limits>
#include <numeric>
#include <type_traits>
#include<bitset>
#define int long long
#define ll long long
#define mod  1000000007
#define inf 1e17
#define rep(i,j,n) for(int i=j;i<n;i++)
#define P pair<int,int>
double pi = 3.141592653589793;
using namespace std;
//ここから始めよう
signed main(){
    int n;string s;cin>>n>>s;
    s+=s;
    //cout<<s<<endl;
    int animal[114514]={};
    rep(i,0,1<<2){
        rep(i,0,114514)animal[i]=0;
        rep(j,0,2){
            if(i&(1<<j))animal[j]=1;
        }
        rep(j,1,n+1){
            if((animal[j]==1&&s[j]=='o')||(animal[j]==0&&s[j]=='x'))animal[j+1]=animal[j-1];
            else animal[j+1]=animal[j-1]*-1+1;
        }
       // rep(j,0,n+1)cout<<animal[j];cout<<endl;
        if(animal[n]==animal[0]&&animal[n+1]==animal[1]){
            rep(j,0,n){if(animal[j]==0)cout<<'W';else cout<<'S';}cout<<endl;return 0;
        }
    }cout<<-1<<endl;return 0;
}

Measured memory_bytes: 1576
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	char a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
	}
	if(n<3)
	{
		cout<<0;
		return 0;
	}
	int ans=0;
	for(int i=0;i<n-2;i++)
	{
		if(a[i]=='A'&&a[i+1]=='B'&&a[i+2]=='C')
		{
			ans++;
		}
	}
	cout<<ans;
	return 0;
}


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

int main()
{
	string s, t, subs;
	cin >> s >> t;

	int n = s.size(), m = t.size(), min = n + 1, ctr;
	for(int i = 0; i <= n - m; i++)
	{
		subs = s.substr(i, m);
		ctr = 0;
		for(int j = 0; j < m; j++)
		{
			if(subs[j] != t[j])	ctr++;
		}
		if(min > ctr)	min = ctr;
	}
	cout << min << endl;
}

Measured memory_bytes: 3200