akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;

namespace contest_Csharp
{
    class Program
    {
        

        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var vals = Console.ReadLine().Split(' ').
                Select(x => int.Parse(x)).ToArray();

            int X = vals[0];
            int Y = vals[1];

            var ans = (Y>=X*2 && Y<=X*4 && Y%2==0)?"Yes":"No";
            



            Console.WriteLine(ans);
            Console.Out.Flush();
        }
        



    }
}




Measured memory_bytes: 28288
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#include <map>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;
int main()
{
    long  double A,B,C,i,Z;
    cin >> A >>B>>C;
	i=-1;
	Z=0;
		if(B>C){
			Z=floor(A*C/B)-A*floor(C/B);
		}else{
			Z=floor(A*(B-1)/B)-A*floor((B-1)/B);
		}
    cout << Z<< endl;
}

Measured memory_bytes: 3712
n=int(input())
a=list(map(int,input().split()))
s=sum(a)
b=list(map(int,input().split()))
for i in range(n):
  x=max(a[i]-b[i],0)
  b[i]=max(b[i]-a[i],0)
  a[i]=x
  a[i+1]=max(a[i+1]-b[i],0)
print(s-sum(a))

Measured memory_bytes: 19156
import java.util.*;
public class Main {
	public static void main(String[] args)
	{
		//変数
		int count=0;
		boolean sw=false;
		String answer="";
		int e=0;
		int f=0;
		int g=0;
		int h=0;
		//List<Integer> hb=new ArrayList<Integer>();
		//long a=0;
		//int af=Integer.MAX_VALUE;
		//入力
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		int d=sc.nextInt();
		//int [][] cost =new int[N-1][2];
		//処理
		if(a==1 || b==1 || c==1 || d==1)
		{
			e=1;
		}
		if(a==9 || b==9 || c==9 || d==9)
		{
			f=1;
		}
		if(a==7 || b==7 || c==7 || d==7)
		{
			g=1;
		}
		if(a==4 || b==4 || c==4 || d==4)
		{
			h=1;
		}
		//
		if(e==1 && f==1 && g==1 && h==1)
		{
			answer="YES";
		}else
		{
			answer="NO";
		}
		// 出力
		System.out.println(answer);
	}
}

Measured memory_bytes: 23636
import sys

X, N = map(int, input().split())
p = list(map(int, input().split()))
flag = 0
if (X in p) is False:
    print(X)
    sys.exit()
Xmin = X
Xmax = X
while flag == 0:
    Xmin = Xmin - 1
    Xmax = Xmax + 1

    if (Xmin in p) is False:

        print(Xmin)
        sys.exit()
    if (Xmax in p) is False:
        print(Xmax)
        sys.exit()

Measured memory_bytes: 9204
#include<bits/stdc++.h>
using ll=long long;
using namespace std;
int main(void){
  int x; cin>>x;
  int q=sqrtl(sqrtl(x));
  for(ll a=-q; abs(a)<=q; ++a) for(ll b=-q; abs(b)<=q; ++b) if(a*a*a*a*a-b*b*b*b*b==x){ printf("%lld %lld\n",a,b); return 0;}
  return 0;
}


Measured memory_bytes: 3708
C = [list(map(int, input().split())) for _ in range(3)]

# a1=0と仮定すると、b1=C[0][0], b2=C[0][1], b3=C[0][2]
# a2=C[1][0]-b1=C[1][1]-b2=C[1][2]-b3
# a3=C[2][0]-b1=C[2][1]-b2=C[2][2]-b3

b1, b2, b3 = C[0][0], C[0][1], C[0][2]
if (C[1][0]-b1 == C[1][1]-b2 == C[1][2]-b3) and (C[2][0]-b1 == C[2][1]-b2 == C[2][2]-b3):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9088
import java.io.*;

class Main
{
    public static void main (String[ ] args) throws Exception
    {
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        StringBuffer sb = new StringBuffer();
        
        while(true)
        {
            String[] strAry = (br.readLine()).split(" ");
            int x = Integer.parseInt(strAry[0]);
            int y = Integer.parseInt(strAry[1]);
            
            if(0 == x && 0 == y)
            {
                break;
            }
            
            if(x > y)
            {
                sb.append(y + " " + x + "\n");
            }
            else
            {
                sb.append(x + " " + y + "\n");
            }
        }
        System.out.print(sb);
    }
}

Measured memory_bytes: 27036
#include "bits/stdc++.h"
using namespace std;
using ll=long long;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define ALL(s) s.begin(),s.end()
#define P pair<ll,ll>
#define vl vector<ll>
#define vi vector<int>
#define vvl vector<vector<ll>>
#define vvi vector<vector<int>>
#define print(n) cout<<n<<endl
const int M=100111;
const int inf=1000000007;
const long long INF=1000000000000000007;
int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};
int ddx[8]={1,-1,0,0,1,-1,-1,1},ddy[8]={0,0,1,-1,1,-1,1,-1};



int main(){
	int n,d;
	cin>>n>>d;
	int look=2*d+1;
	int ans=n/look;
	if(n%look!=0)ans++;
	print(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,x,a[104],t=0;
	cin>>n>>x;
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;;i++)
	{
		t+=a[i];
		if(t>x)
		{
			cout<<i+1;
			return 0;
		}
	}
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )

const int INF = 1e9;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int MOD = 1e9 + 7;


int main() {

    vector<ll> abc(3);
    fo(i, 3) cin >> abc[i];

    sort(all(abc));
    bool tp = false;
    for ( auto n : abc ) {
        if ( !(n & 1) ) tp = true;
    }

    cout << (tp ? 0 : abc[0] * abc[1]) << endl;

    return 0;
}

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

int main(){
    double n, i, a = 1;
    cin >> n;
    n = log(n)/log(2.0);
    for(i=0; i<(int)n; i++){
        a *= 2;
    }
    cout << a;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>

int main() {
	std::string s,t;
  	std::cin >> s >> t;
  	unsigned int i = s.length(), c = 0;
  	for ( unsigned int l = 0; l < i; l++ )
		if ( s[l] != t[l] )
          	c++;
  	std::cout << c << std::endl;
  	return 0;
}



Measured memory_bytes: 3876
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let input: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    let D = input[0];
    let G = input[1];

    let mut ps = Vec::with_capacity(D);
    let mut cs = Vec::with_capacity(D);
    for i in 0..D {
        let input: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
        ps.push(input[0]);
        cs.push(input[1]);
    }

    let mut memo = vec![vec![0; 1010]; 2];

    for i in 0..D {
        let a = (i+1)%2;
        let b = i%2;
        for j in 0..ps[i] {
            for k in j..1010 {
                memo[a][k] = cmp::max(memo[a][k], memo[b][k-j] + (i+1) * j * 100);
            }
        }
        for k in ps[i]..1010 {
            memo[a][k] = cmp::max(memo[a][k], memo[b][k-ps[i]] + cs[i] + ps[i] * (i+1) * 100);
        }
    }

    for i in 0..1010 {
        if memo[D%2][i] >= G {
            println!("{}", i);            
            break;
        }
    }
}


Measured memory_bytes: 4352
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int[] a = new int[7];
		for (int i = 1; i < 7; i++) {
			a[i] = scanner.nextInt();
		}

		char[] b = scanner.next().toCharArray();
		for (int i = 0; i < b.length; i++) {
			if (b[i] == 'N') {
				a[0] = a[1];
				a[1] = a[2];
				a[2] = a[6];
				a[6] = a[5];
				a[5] = a[0];
			} else if (b[i] == 'S') {
				a[0] = a[1];
				a[1] = a[5];
				a[5] = a[6];
				a[6] = a[2];
				a[2] = a[0];
			} else if (b[i] == 'E') {
				a[0] = a[1];
				a[1] = a[4];
				a[4] = a[6];
				a[6] = a[3];
				a[3] = a[0];
			} else {
				a[0] = a[1];
				a[1] = a[3];
				a[3] = a[6];
				a[6] = a[4];
				a[4] = a[0];
			}
		}
		System.out.println(a[1]);
	}
}

Measured memory_bytes: 17328
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
	Scanner in = new Scanner(System.in);
	int maxInput = (int) Math.pow(2, 15);
	boolean[] isPrime = new boolean[maxInput];
	for (int i = 2; i < maxInput; i++) {
	  isPrime[i] = true;
	}
	isPrime[0] = false;
	isPrime[1] = false;
	for (int i = 2; i * i < maxInput; i++) {
	  if (isPrime[i]) {
		for (int j = 2 * i; j < maxInput; j += i) {
		  isPrime[j] = false;
		}
	  }
	}

	while (true) {
	  int n = in.nextInt();
	  if (n == 0) return;
	  int cnt = 0;
	  for (int i = 2; i <= n / 2; i++) {
		if (isPrime[i] && isPrime[n - i]) cnt++;
	  }
	  System.out.println(cnt);
	}
  }
}


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

int main() {
  int N, A, B;
  cin >> N >> A >> B;

  if (N * A > B) {
    cout << B << endl;
  }
  else {
    if (N * A <= B) {
      cout << N * A << endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
    int l, r, d;
    cin >> l >> r >> d;
    int tmp1, tmp2;
    tmp1 = (l - 1) / d;
    tmp2 = r / d;
    int ans = tmp2 - tmp1;    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define rep2(i,j,n) for(int j=i;j<n;j++)
#define rep3(i,j,n) for(int j=i;j<=n;j++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define sp(n) cout << fixed << setprecision(n)
typedef long long ll;
using namespace std;
// b/aで考える
int main(void){
    int n,k;cin>>n>>k;
    ll res=0;
    for(int b=k+1;b<=n;b++){
        int buf=n/b;
        res+=buf*(b-k);
        int buf2=n-buf*b-k+1;
        res+=max(buf2,0);
        //cout<<buf*(b-k)<<" "<<max(buf2,0)<<endl;
        if(k==0)res--;
    }
    
    cout<<res<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define ALL(a)    a.begin(), a.end() 
#define rep(i, K, N)  for(long long int i = K; i < N; i++)
#define ll long long int
using namespace std;



int main() {
ll N, Ans = powl(10, 18);cin >> N;
map<ll, ll> M;

rep(i, 0, N){
  ll a;cin >> a;
  M[a]++;
}
  
rep(i, -100, 101){
  
ll ans = 0;
  
for(auto x : M )ans += (x.first - i)*(x.first - i)*x.second;

Ans = min(Ans, ans);
  
}
  cout << Ans;
}

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

int main() {
  int H, W, M, h, w, hb[300001]={},wb[300001]={}, maxh = 0, maxw = 0, count, mc = 0;
  vector<int> hv ={}, wv ={};
  vector<vector<int>> m = {};
  cin >> H >> W >> M;
  for (int i = 0; i<M; i++){
    cin >> h >> w;
    hb[h]++;
    wb[w]++;
    m.push_back({h, w});
  }
  for (int j = 0; j<=H; j++){
    if(maxh < hb[j]){
      maxh = hb[j];
      hv = {j};
    } else if(maxh == hb[j]) hv.push_back(j);
  }
  for (int j = 0; j<=W; j++){
    if(maxw < wb[j]){
      maxw = wb[j];
      wv = {j};
    } else if(maxw == wb[j]) wv.push_back(j);
  }
  for(int i = 0; i<M; i++){
    if(hb[m.at(i).at(0)]==maxh && wb[m.at(i).at(1)]==maxw) mc++;  
  }
  int hs = hv.size(), ws = wv.size();
  if(mc == hs*ws && M!=0) count = maxh+maxw-1;
  else count = maxh+maxw;
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 26424
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		List<String> s = new ArrayList<String>();
		int i = 0;
		for(i = 0; i < n; i++) {
			s.add(scan.next());
		}
		int m = scan.nextInt();
		List<String> t = new ArrayList<String>();
		for(i = 0; i < m; i++) {
			t.add(scan.next());
		}
		int max = 0;
		for(; s.size() != 0;) {
			int s_before = s.size();
			int t_before = t.size();
			List<String> set = new ArrayList<>();
			Collections.addAll(set, s.get(0));
			s.removeAll(set);
			t.removeAll(set);
			int s_after = s.size();
			int t_after = t.size();
			int money = (s_before - s_after) - (t_before - t_after);
			if(max < money) {
				max = money;
			}
		}
		System.out.println(max);
	}
}

Measured memory_bytes: 21844
import sys
input = sys.stdin.readline
N = int(input())
mod = 998244353
dp = [0] * 900001
dp2 = [0] * 900001
dp[0] = 1
dp2[0] = 1
sm = 0
for _ in range(N):
  x = int(input())
  for y in range(900000, -1, -1):
    if dp[y]:
      dp[x + y] += dp[y]
      dp[x + y] %= mod
      dp2[x + y] += dp2[y]
      dp2[x + y] %= mod
      dp[y] *= 2
      dp[y] %= mod
  sm += x
res = 0
for x in range(sm + 1):
  if x > sm - x:
    res += max(0, dp[x])
    res %= mod
  elif x == sm - x:
    res += dp[x] - dp2[x]
    res %= mod

print((pow(3, N, mod) - res * 3) % mod)

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

vector<int> dp(50,-1);

int fib(int n){
    if(dp[n]!=-1){
        return dp[n];
    }
    return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
    int n;
    cin>>n;
    dp[0]=1;
    dp[1]=1;
    cout<<fib(n)<<endl;
}


Measured memory_bytes: 3100
N = int(input())
L = list(map(int, input().split()))
L.sort(reverse=True)
total = 0

for i in range(N-2):
    a = L[i]
    for j in range(i+1, N-1):
        b = L[j]
        # j以降の項で、初めてL[k] < a-bとなるkを二分探索する
        if L[-1] > a - b:  # 一番最後の項でもOKな場合(j+1以降全部OK)
            total += N - j - 1
        elif L[j+1] <= a - b:  # 一番最初の項からNGな場合
            continue
        else:
            head = j+1  # head はL[head] > a - bを満たす(OK側)
            tail = N-1  # tail はL[tail] <= a - bを満たす(NG側)
            while head+1 != tail:
                if L[(head + tail)//2] > a - b:  # 中間地点はOK側
                    head = (head + tail) // 2
                else:  # 中間地点はNG側
                    tail = (head + tail) // 2
            total += head - j

print(total)


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

typedef long long ll;

typedef pair<ll,ll> ii;
typedef pair<ii, ll > iii;

const int kn = 2e5 + 5, N = 1e5+5;
const ll mod = 1e9 + 7, inf = 1e18 ;

#define x first
#define y second

#define ff(i,n) for(int i=1;i<=n;i++)

int n, m, k, nums, cnt =0;
int c[kn], par[kn*5];

ll ans = 0;

pair<ll, pair<int,int> > edge[kn];

int fin(int u)
{
	return (par[u] == u) ? u : par[u] = fin(par[u]);
}

void unite(int i, int j, ll w)
{
	if(cnt == k-1) return;
	int pi = fin(i), pj = fin(j);
	if(pi == pj) return ;
	ans += w;
	par[pi] = pj;
	cnt++;
}

int tmp ;

int main() {
	cin >> n >> m >> k;
	nums = k; tmp = n;
	ff(i,n) cin >> c[i];
	ff(i,5*n) par[i] = i;
	ff(i,m)
	{
		cin >> edge[i].y.x >> edge[i].y.y >> edge[i].x;
		if(not c[edge[i].y.x]) 
		{
			c[edge[i].y.x] = edge[i].y.x + k;
		}
		edge[i].y.x = c[edge[i].y.x];
		if(not c[edge[i].y.y]) 
		{
			c[edge[i].y.y] = edge[i].y.y + k;
		}
		edge[i].y.y = c[edge[i].y.y];
	}
	sort(edge+1, edge+m+1);
	ff(i,m)
	{
		//cout << edge[i].x <<endl;
		unite(edge[i].y.x, edge[i].y.y, edge[i].x);
	}
	if(cnt<k-1) cout<<"-1"; else cout << ans;
	
}
//hahahahahahahahahhahahahahahaahahahahhahahahahahahah


Measured memory_bytes: 6272
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<int> v(N+1);
  for(int i=1;i<=N;i++) cin >> v[i];
  int sum=0;
  vector<bool> visited(N+1);
  int i=1;
  while(!visited[i]) {
    visited[i] = true;
    sum++;
    i = v[i];
    if (i==2) {
      cout << sum << endl;
      return 0;
    }
  }
  cout <<-1<<endl;
}

Measured memory_bytes: 640
c = [list(map(int,input().split())) for _ in range(3)]
count=0
for i in range(2):
    for j in range(2):
        if (c[i][j]+c[i+1][j+1]) == (c[i][j+1] + c[i+1][j]):
            count += 1
if count == 4:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

int main() {
    int n, k;
    cin >> n >> k;

    int l[50];
    for (int i = 0; i < n; i++) {
        cin >> l[i];
    }

    sort(l, l + n);

    int r = 0;
    for (int i = n - k; i < n; i++) {
        r += l[i];
    }

    cout << r << endl;

    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 a = sc.nextInt();
        int b = sc.nextInt();
        int area = a * b;
        int length = 2 * (a + b);
        System.out.println(area + " " + length);
        sc.close();
    }
}


Measured memory_bytes: 26152
#include<stdio.h>
int main(){
  int N;
  scanf("%d",&N);
  for(int i = N;i > 0;i -= 4){
    if(i % 7 == 0){
      printf("Yes\n");
      return 0;
    }
  }
  for(int i = N;i > 0;i -= 7){
    if(i % 4 == 0){
      printf("Yes\n");
      return 0;
    }
  }
  printf("No");
  return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

const int MAXN = 1e5 + 10;
int a[MAXN][3];
int dp[MAXN][3];

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

    for (int i = 0; i < n; i++)
        cin >> a[i][0] >> a[i][1] >> a[i][2];

    dp[0][0] = a[0][0];
    dp[0][1] = a[0][1];
    dp[0][2] = a[0][2];
    for (int i = 1; i < n; i++)
        for (int j = 0; j < 3; j++)
            for (int k = 0; k < 3; k++)
                if (k != j)
                    dp[i][j] = max(dp[i][j], dp[i-1][k] + a[i][j]);

    int ans = 0;
    for (int i = 0; i < 3; i++)
        ans = max(ans, dp[n-1][i]);

    cout << ans;
    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

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

    vector<int> num;
    for (int i = 0; i < n; i++) {
        num.push_back(-2);
    }

    int sc[5][2];
    int temp;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < 2; j++) {
            cin >> temp;
            sc[i][j] = temp;
        }
    }

    for (int i = 0; i < m; i++) {
        if (num[sc[i][0] - 1] == -2) {
            num[sc[i][0] - 1] = sc[i][1];
            //cout << "set";
        } else if (num[sc[i][0] - 1] == sc[i][1]) {
            //cout << "same";
        } else if (num[sc[i][0] - 1] != sc[i][1]) {
            cout << -1;
            return 0;
        }
    }
    for (int i = 0; i < n; i++) {
        if (num[i] == -2) {
            if (n > 1 && i == 0) {
                num[i] = 1;
            } else {
                num[i] = 0;
            }
        }
    }

    int ans = 0;

    if (n == 1 & num[0] == 0) {
        cout << 0;
    } else if (num[0] == 0) {
        cout << -1;
    } else {
        for (int i = 0; i < n; i++) {
            ans += num[i] * pow(10, n - i - 1);
        }
        cout << ans;
    }


    return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

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

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

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

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

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

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

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

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

const MOD: i64 = 1000000007;

fn main() {
    input! {
      n: usize,
      s: chars
    };

    let mut count = [0i64; 26];
    for c in s {
        let idx = (c as usize) - ('a' as usize);
        count[idx] += 1;
    }

    let mut ways = 1;
    for cn in count.iter() {
        ways *= cn+1;
        ways %= MOD;
    }
    ways += MOD-1;
    ways %= MOD;

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


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

int main()
{
    ll h, w;
    cin >> h >> w;

    ll ans = h * w / 2 + h * w % 2;
    cout << (h == 1 || w == 1 ? 1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<math.h>
using namespace std;

int main(){
  int64_t n;
  cin>>n;
  
  int64_t i=1;
  int64_t minimum=n;
  while(i<=sqrt(n)){
    if(n%i==0){
      minimum=min(max(i,n/i),minimum);
    }
    i++;
  }
  
  int count=0;
  while(minimum>0){
    minimum/=10;
    count++;
  }
  
  cout<<count<<endl;
}


Measured memory_bytes: 256
# Wrote in Feb 29, 2020 13:22 by reetok
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
#---------------

a,b = inp
puts "#{a*b} #{(a+b)*2}"


Measured memory_bytes: 6876
#[allow(dead_code)]
fn is_whitespace(c: &char) -> bool {
    c.is_whitespace()
}

#[allow(dead_code)]
fn is_eol(c: &char) -> bool {
    ['\r', '\n'].contains(c)
}

#[allow(unused_macros)]
macro_rules! input {
    ($var:ident, $($r:tt)*) => {
        input_inner!{$var, $($r)*}
    };

    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_mut, unused_variables, bare_trait_objects)]
        let mut next = move |f: &Fn(&char)->bool| -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|f(&c))
                .take_while(|c|!f(&c))
                .collect()
        };
        input_inner!{next, $($r)*};
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; eol ]) => {
        $next(&is_eol).split(' ').map(|x| x.parse::<$t>().unwrap()).collect::<Vec<_>>()
    };

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

    ($next:expr, parser) => {
        $next
    };

    ($next:expr, $t:ty) => {
        $next(&is_whitespace).parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap, HashSet};

#[allow(dead_code)]
struct Edge {
    from: usize,
    to: usize,
}

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;
#[allow(dead_code)]
const M: usize = 1_000_000_007;

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

    for x in a {
        if x % 2 == 0 && (x % 3 != 0 && x % 5 != 0) {
            println!("DENIED");
            return;
        }
    }
    println!("APPROVED");
}


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

int main(void)
{
    string s, p;
    cin >> s >> p;
    s = s + s;
    auto r = search(s.begin(), s.end(), p.begin(), p.end());
    cout << ((r != s.end())? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 3236
n,p=map(int,input().split())
a=list(map(int,input().split()))
judge=True
for i in range(n):
    if a[i]%2!=0:
        judge=False
if judge==True:
    if p==0:
        print(2**n)
    else:
        print(0)
else:
    print(2**(n-1))
    

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define bp __builtin_popcountll
#define pb push_back
#define in(s) freopen(s, "r", stdin);
#define out(s) freopen(s, "w", stdout);
#define inout(s, end1, end2) freopen((string(s) + "." + end1).c_str(), "r", stdin),\
		freopen((string(s) + "." + end2).c_str(), "w", stdout);
#define fi first
#define se second
#define bw(i, r, l) for (int i = r - 1; i >= l; i--)
#define fw(i, l, r) for (int i = l; i < r; i++)
#define fa(i, x) for (auto i: x)
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
int n, p[N], dp[N][2];
signed main() {
	#ifdef BLU
	in("blu.inp");
	#endif
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//bad - bad => a swap makes good - good. bad - good also does the same.
	//dp(i, 2): ith element, i is swapped with i - 1 or not.
	cin >> n;
	fw (i, 0, n) cin >> p[i], p[i]--;
	memset(dp, 63, sizeof dp);
	dp[0][0] = 0;
	fw (i, 1, n) {
		if (p[i] == i) dp[i][1] = min(dp[i - 1][1], dp[i - 1][0]) + 1;
		else {
			//If i - 1 and i - 2 was swapped and at least 1 is bad => both are good after => no cause to use
			//it.
			if (p[i - 1] == i - 1) dp[i][1] = dp[i - 1][0] + 1;
		}
		
		dp[i][0] = dp[i - 1][1];
		if (p[i - 1] != i - 1) dp[i][0] = min(dp[i][0], dp[i - 1][0]);
	}
	if (p[n - 1] == n - 1) cout << dp[n - 1][1];
	else cout << min(dp[n - 1][0], dp[n - 1][1]);
	return 0;
}

Measured memory_bytes: 1408
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 6)
N = int(input())

res = set()
def dfs(x, s):
  global res
  res.add(int("".join(s)))
  if x == 10: return
  for i in range(3):
    if (int(s[-1]) + i - 1) in range(10):
      y = s + [str(int(s[-1]) + i - 1)]
      dfs(x + 1, y)
for i in range(1, 10): dfs(1, [str(i)])
res = sorted(res)
print(res[N - 1])

Measured memory_bytes: 72384
#include <stdio.h>
long long n, x, ans = 1;
long long p = 1000000007;
char s[200005];
int a[200005];
int main() {
	scanf("%lld", &n);
	scanf(" %s", s);
	for (int i = 0; i < 2 * n; i++) {
		if (i % 2) {
			if (s[i] == 'W')a[i] = 0;
			else a[i] = 1;
		}
		else {
			if (s[i] == 'B')a[i] = 0;
			else a[i] = 1;
		}
	}
	for (int i = 0; i < 2 * n; i++) {
		if (a[i]) {
			ans *= x;
			ans %= p;
			x--;
		}
		else x++;
	}
	if (x != 0)ans = 0;
	for (long long i = 1; i <= n; i++) {
		ans *= i;
		ans %= p;
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 1152
#include<stdio.h>
int main(void)
{
	int a, b, d, r;
	double f;
	scanf("%d %d", &a, &b);

	d = a / b;
	r = a % b;
	f = (double)a / b;

	printf("%d %d %f\n", d, r, f);

	return 0;
}




Measured memory_bytes: 2104
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
using namespace std;
#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define DEBUG(x) cerr << #x << " = " << x << endl
#define int long long
struct Edge {
  int a, b, s, t, cost;
  Edge() {}
  Edge(int a_, int b_, int s_, int t_, int cost_) : a(a_), b(b_), s(s_), t(t_), cost(cost_) {}
};
struct State {
  int v, t, cost;
  State(int v_, int t_, int cost_) : v(v_), t(t_), cost(cost_) {}
  bool operator >(const State &other) const {
    return cost > other.cost;
  }
};
signed main() {
  int N, M, S, T; cin >> N >> M >> S >> T;
  S--, T--;
  vector<Edge> E(M);
  REP(i,M) {
    cin >> E[i].a >> E[i].b >> E[i].s >> E[i].t;
    E[i].a--;
    E[i].b--;
    E[i].t += E[i].s;
    E[i].cost = 0;
  }
  vector<vector<int>> TIME(N);
  TIME[S].push_back(0);
  REP(i,M) {
    TIME[E[i].a].push_back(E[i].s);
    TIME[E[i].b].push_back(E[i].t);
  }
  vector<map<int, vector<Edge>>> G(N);
  REP(i,N) {
    sort(TIME[i].begin(), TIME[i].end());
    REP(j,(int)TIME[i].size()-1) {
      if(TIME[i][j] != TIME[i][j+1]) {
        G[i][TIME[i][j]].emplace_back(i, i, TIME[i][j], TIME[i][j+1], TIME[i][j+1] - TIME[i][j]);
      }
    }
  }
  REP(i,M) {
    G[E[i].a][E[i].s].push_back(E[i]);
  }
  //REP(i,N) {
  //  for(const pair<int, vector<Edge>> &pp : G[i]) {
  //    for(const Edge &e : pp.second) {
  //      cerr << e.a << " => " << e.b << " (" << e.s << "," << e.t << ") C=" << e.cost << endl;
  //    }
  //  }
  //}
  vector<map<int, int>> D(N);
  priority_queue<State, vector<State>, greater<State>> Q;
  Q.emplace(S, 0, 0);
  D[S][0] = 0;
  while(!Q.empty()) {
    State s = Q.top(); Q.pop();
    if(D[s.v].count(s.t) && s.cost > D[s.v][s.t]) continue;
    for(const Edge &e : G[s.v][s.t]) {
      if((D[e.b].count(e.t) == 0) || (D[e.b][e.t] > s.cost + e.cost)) {
        D[e.b][e.t] = s.cost + e.cost;
        Q.emplace(e.b, e.t, D[e.b][e.t]);
      }
    }
  }
  int ans = (int)1e18;
  for(pair<int, int> iter : D[T]) {
    ans = min(ans, iter.second);
  }
  cout << ans << endl;
}

Measured memory_bytes: 105532
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define rep2(i,n) for(int i=0;i<=n;i++)
#define repr(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define P pair<long long,long long>
#define double long double
#define vector2(a,b,c) vector<vector<int>> a(b/*縦！w*/,vector<int>(c/*横！w*/))
#define INF 1e10
#define MOD 1e9+7
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;
signed main(){
  int a,b;
  cin>>a>>b;
  vector<int> w(a),v(a);
  rep(i,a)
    cin>>w[i]>>v[i];
  int dp[110][100010];
  rep(i,a)rep2(j,b){
  if(j>=w[i])
    chmax(dp[i+1][j],dp[i][j-w[i]]+v[i]);
      chmax(dp[i+1][j],dp[i][j]);
  }
  cout<<dp[a][b]<<endl;
}

Measured memory_bytes: 80384
#include<stdio.h>
#include<math.h>

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

void coordinate_comp(int a[],int n){
  int i,c=1;
  sd dat[524288];
  for(i=0;i<n;i++){
    dat[i].val=a[i];
    dat[i].node=i;
  }
  qsort(dat,n,sizeof(dat[0]),sdsortfnc);
  a[dat[0].node]=c;
  for(i=1;i<n;i++){
    if(dat[i-1].val!=dat[i].val){c++;}
    a[dat[i].node]=c;
  }
}

int main(){
  int n,t[524288],a[524288],q,i,equ[524288]={0};
  double rss[524288];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d%d",&t[i],&a[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d%d",&t[n+i],&t[n+q+i]);
  }
  coordinate_comp(t,n+2*q);
  rss[0]=1.0;
  for(i=0;i<n;i++){
    equ[t[i]]=a[i];
  }
  for(i=1;i<524288;i++){
    rss[i]=rss[i-1]+log(10.0-(double)equ[i])-log(10.0);
  }
  for(i=0;i<q;i++){
    printf("%.12lf\n",1.0e9*exp(rss[t[n+q+i]]-rss[t[n+i]]));
  }
}


Measured memory_bytes: 12352
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Collections;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long k = sc.nextLong();
        int[] a = new int[n];
        int[] b = new int[n];
        List<Pair> pairs = new ArrayList<Pair>();
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            b[i] = sc.nextInt();
            pairs.add(new Pair(a[i], b[i]));
        }
        Collections.sort(pairs);

        long cnt = 0;
        sc.close();
        for (int i = 0; i < n; i++) {
            int value = pairs.get(i).value;
            cnt += value;
            if (cnt >= k) {
                System.out.println(pairs.get(i).key);
                return;
            }
        }

    }
}

class Pair implements Comparable {
    int key;
    int value;

    Pair(int key, int value) {
        this.key = key;
        this.value = value;
    }

    @Override
    public int compareTo(Object other) {
        Pair otherPair = (Pair) other;
        if (this.key == otherPair.key)
            return this.value - this.value;
        return this.key - otherPair.key;
    }
}

Measured memory_bytes: 92016
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);

    public static void main(String[] args) {
	int K = Integer.parseInt(scan.next());
	int S = Integer.parseInt(scan.next());

	int count = 0;
	for (int i = 0; i <= K; i++) {
	    int XY = S - i;
	    if(XY < 0) break;
	    if(XY <= 2 * K) {
		for (int j = 0; j <= K; j++) {
		    int X = XY - j;
		    if(X < 0) break;
		    if(X <= K) count++;
		}
	    }
	}

	System.out.println(count);
	scan.close();
    }
}


Measured memory_bytes: 21844
N = int(input())
A_up_list = list(map(int, input().split()))
A_dw_list = list(map(int, input().split()))

sum_list = []
for i in range(N):
    sum_up = sum(A_up_list[0:i+1])
    sum_dw = sum(A_dw_list[i:N+1])
    sum_list.append(sum_up+sum_dw)

print(max(sum_list))


Measured memory_bytes: 2940
package main

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

var N, K int
var as []int
var minOfAs int
var memo map[int]bool

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &K)

	as = make([]int, N)
	for i := 0; i < N; i++ {
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%d", &as[i])
	}
	minOfAs = min(as...)
	memo = make(map[int]bool)

	b := canWin(K)
	if b {
		fmt.Println("First")
	} else {
		fmt.Println("Second")
	}
}

func canWin(n int) bool {
	if n < minOfAs {
		return false
	}
	if _, e := memo[n]; e {
		return memo[n]
	}
	ret := false
	for _, a := range as {
		if n - a >= 0 && !canWin(n - a) {
			ret = true
			break
		}
	}
	memo[n] = ret
	return ret
}

func min(ns ...int) int {
	ret := math.MaxInt64
	for _, n := range ns {
		if n < ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 30464
#include <stdio.h>
#include <math.h>

int main(int argc, char* aragv[])
{
    int dish[5];

    for(int i = 0 ; i < 5 ; i++){
        if(scanf("%d", &dish[i]) != 1){
            return -1;
        }
    }

    int max_wait_time = 0;
    for(int i = 0 ; i < 5 ; i++){
        int wait = 10 - dish[i] % 10;
        if(wait == 10){
            continue;
        }
        if( wait > max_wait_time){
            max_wait_time = wait;
        }    
    }

    int total_wait = 0;
    for(int i = 0 ; i < 5 ; i++){
        total_wait += (int)ceil((double)dish[i]/10) * 10;
    }

    printf("%d\n", total_wait - max_wait_time);

    return 0;
}

Measured memory_bytes: 128
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.util.Collections.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// Trading Ship
// 2012/12/15
public class Main{
	Scanner sc=new Scanner(System.in);

	double w, h;
	int n;
	double[] xs, ys;

	void run(){
		w=sc.nextInt();
		h=sc.nextInt();
		n=sc.nextInt();
		xs=new double[n];
		ys=new double[n];
		for(int i=0; i<n; i++){
			xs[i]=sc.nextInt();
			ys[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		double left=0, right=1e9;
		for(int t=0; t<100; t++){
			double mid=(left+right)/2;
			if(check(mid)){
				left=mid;
			}else{
				right=mid;
			}
		}
		double ans=(left+right)/2;
		println(String.format("%.3f", ans));
	}

	boolean check(double r){
		LinkedList<Integer> que=new LinkedList<Integer>();
		boolean[] visited=new boolean[n];
		for(int i=0; i<n; i++){
			if(abs(xs[i])<r){
				que.offer(i);
				visited[i]=true;
			}
		}
		for(; !que.isEmpty();){
			int v=que.poll();
			for(int u=0; u<n; u++){
				if(!visited[u]){
					double dx=xs[u]-xs[v], dy=ys[u]-ys[v];
					if(dx*dx+dy*dy<4*r*r){
						que.offer(u);
						visited[u]=true;
					}
				}
			}
		}
		for(int i=0; i<n; i++){
			if(visited[i]&&abs(w-xs[i])<r){
				return false;
			}
		}
		return true;
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define ll long long
#define M 1000000007
#define N 3010
using namespace std;

ll n,ans,dp[N][N];
string s;

int main()
{
    cin>>n>>s; 
    s="  "+s; 
    dp[1][1]=1;
    FOR(i,1,n+1)
    {
        if(s[i]=='<') FOR(j,2,i+1) dp[i][j]=(dp[i-1][j-1]+dp[i][j-1])%M;
        else if(s[i]=='>') for(int j=i;j>0;j--) dp[i][j]=(dp[i-1][j]+dp[i][j+1])%M;
    }
    FOR(i,1,n+1) ans=(ans+dp[n][i])%M;
    cout<<ans<<'\n';

    return 0;
}

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

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

using namespace std;

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

  int result=0;
  rep(i,n){
    int l,r;cin>>l>>r;
    result+=(r-l+1);
  }

  cout<<result;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define pb(a) push_back(a)
#define pr(a) cout<<(a)<<endl
#define PR(a,b) cout<<(a)<<" "<<(b)<<endl
#define R cin>>
#define F first
#define S second
#define ll long long
bool check(int n,int m,int x,int y){return (x<0||x>=n||y<0||y>=m)?false:true;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

int a[10];

bool solve(int x,int y, int z) {
  if(x==10) return (y==1&&z==4);
  if(!a[x]) return solve(x+1,y,z);
  bool ck=false;
  if(a[x]>=3) {
    a[x]-=3;
    if(solve(x,y,z+1)) ck=true;
    a[x]+=3;
  }
  if(ck) return ck;
  if(a[x]>=2 && !y) {
    a[x]-=2;
    if(solve(x,1,z)) ck=true;
    a[x]+=2;
  }
  if(ck) return ck;
  if(x<=7 && a[x] && a[x+1] && a[x+2]) {
    a[x]--,a[x+1]--,a[x+2]--;
    if(solve(x,y,z+1)) ck=true;
    a[x]++,a[x+1]++,a[x+2]++;
  }
  return ck;
}

int main() {
  string s;
  while(R s) {
    memset(a,0,sizeof(a));
    rep(i,s.size()) a[s[i]-'0']++;
    vector<int> ans;
    REP(i,1,10) {
      if(a[i]>=4) continue;
      a[i]++;
      if(solve(1,0,0)) ans.pb(i);
      a[i]--;
    }
    if(ans.size()) {
      rep(i,ans.size()) {
	if(i) cout << " ";
	cout << ans[i];
      }
      cout << endl;
    } else pr(0);
  }
  return 0;
}


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

int main(){
    int N;
    cin >> N;
    int d[N] = {};
    for (int i = 0;i < N;i++){
        cin >> d[i];
    }
    sort(d,d + N);
    cout << d[(N / 2)] - d[(N / 2) - 1] << endl;
}

Measured memory_bytes: 640
#include <cstring>
#include <algorithm>
#include <cstdio>

using namespace std;
typedef long long ll;
int nowarn;

const int n = 50;
ll k, a[n];

void simulate() {
	int p = int(max_element(a, a+n) - a);
	for( int i = 0; i < n; ++i )
		a[i] += (i == p ? -n : 1);
}

int main() {
	nowarn = scanf( "%lld", &k );
	ll op = k / n + 1;
	for( int i = 0; i < n; ++i ) a[i] = n-1 + op;
	for( op *= n; op > k; --op ) simulate();
	printf( "%d\n", n );
	for( int i = 0; i < n; ++i ) printf( "%lld ", a[i] );
	puts("");
	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : abs(x); }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : abs(x); }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	string s;
	cin >> s;

	ll n = s.size();
	ll ans = n * (n - 1LL) / 2LL + 1LL;
	// a1: a2, a3, a4
	// a2: a3, a4
	// a3: a4

	vector<ll> cnt(26);
	for (int i = 0; i < n; i++) {
		cnt[s[i] - 'a']++;
	}

	for (auto v : cnt) {
		if (v >= 2) {
			ans -= v * (v - 1LL) / 2LL;
		}
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 720
<?php
fscanf(STDIN, '%d %d', $n, $k);
fscanf(STDIN, '%s', $s);
$i = $top = $cnt = 0;
$top_s = $s[$top];
while($top < $n) {
    $next_s = ($top_s === 'L') ? 'R' : 'L';
    $next_top = strpos($s, $next_s, $top);
    if ($next_top === false) $next_top = $n;
    if ($i % 2 === 1) {
        $cnt_s = $next_top - $top;
        $s = substr_replace($s, str_repeat($next_s, $cnt_s), $top, $cnt_s);
        $cnt++;
        if ($cnt >= $k) break;
    }
    $i++;
    $top_s = $next_s;
    $top = $next_top;
}
$ans = 0;
for ($i = 0; $i < $n - 1; $i++) {
    if ($s[$i + 1] === $s[$i]) $ans++;
}
echo $ans . PHP_EOL;

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


int main(){

  

  int n,m;
  cin>>n>>m;
  
  vector<int> k(m);
  vector<vector<int>> s(m,vector<int>(0));
  vector<int> p(m);
  
  
  for (int i=0;i<m;i++){
    int tmp;
    cin>>tmp;
    k.at(i)=tmp;
    for (int j=0;j<tmp;j++){
      int stmp;
      cin>>stmp;
      s.at(i).push_back(stmp);
    }
  }
  
  for (int i=0;i<m;i++){
    int tmp;
    cin>>tmp;
    p.at(i)=tmp;
  }
  
  int answer=0;
  
  
  for (int i=0;i<(1<<n);i++){
    bitset<10> mybit(i);
    
    bool flag=true;
    
    for (int j=0;j<m;j++){
      int tmpsum=0;
      for (int x=0;x<k.at(j);x++){
        if (mybit.test(s.at(j).at(x)-1)){
          tmpsum++;
        }
      }
      if (tmpsum%2!=p.at(j)){
        flag=false;
        break;
      }
    }
    
    if (flag==true){
      answer++;
    }
  }
  
  cout<<answer<<endl;
  
  
  
    

}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  long long x,emp[4001],val[4001];
  long long emp1,val1,con,flag;
  int i,j;

  while(scanf("%lld",&x),x){

    for(i=0;i<4001;i++){
      emp[i]=0;
      val[i]=0;
    }
    for(i=0;i<x;i++){

      scanf("%lld %lld %lld",&emp1,&val1,&con);

      flag=0;
      for(j=0;j<x;j++){
	if(emp[j]==emp1){
	  flag=1;
	  val[j]+=val1*con;
	  break;
	}
      }

      if(flag==0){
	for(j=0;j<4001;j++){
	  if(emp[j]==0){
	    emp[j]=emp1;
	    val[j]=val1*con;
	    break;
	  }  
	}
      }
    }
      flag=0;
    for(j=0;j<4001;j++){
      if(val[j]>=1000000){
	printf("%lld\n",emp[j]);
	flag=1;
      }
    }
    if(flag==0)printf("NA\n");
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
using namespace std;
 
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
#define endl '\n'
#define spc " "
#define pb push_back
#define mp make_pair
#define mod 1000000007

int main() 

{
    ios::sync_with_stdio(0);
    cin.tie(0);
    //freopen("in.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,k;
    cin>>n>>k;
    ll c=0;
    map<ll,ll>m;
    while(k--){
    	ll d;
    	cin>>d;
    	while(d--){
    		ll x;
    		cin>>x;
    		m[x]++;
    	}
    }
    f(i,1,n+1){
    	if(m[i]==0) c++;
    }
    cout<<c<<endl;
}

Measured memory_bytes: 3668
def main():
    N = int(input())
    T, A = map(int, input().split())
    H = list(map(int, input().split()))
    ans, tmp = -1, 1001001
    for i in range(N):
        if tmp > abs(A - (T - H[i] * 0.006)):
            ans, tmp = i + 1, abs(A - (T - H[i] * 0.006))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;
 
signed main()
{
    tezz
    
    string s, t;
    cin>>s>>t;
    cout<<(t+s);
} 

Measured memory_bytes: 384
using System;
using System.Collections.Generic;

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("10");
            //Yes
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("50");
            //No
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("81");
            //Yes
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int N = int.Parse(InputList[0]);

        var ProdSet = new HashSet<int>();
        for (int I = 1; I <= 9; I++) {
            for (int J = 1; J <= 9; J++) {
                ProdSet.Add(I * J);
            }
        }
        Console.WriteLine(ProdSet.Contains(N) ? "Yes" : "No");
    }
}


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

int main() {
	int n; cin >> n;
	int a[6*n];
	
	memset(a,0,sizeof(a));
	
	for (int i=1; i<=int(sqrt(n)); ++i)
		for (int j=1; j<=n; ++j)
			for (int k=1; k<=int(sqrt(n)); ++k) {
				int v = i*i+j*j+k*k+i*j+j*k+i*k;
				if (v <= n) a[v]++;
			}
	for (int i=1; i<=n;++i) cout << a[i] << endl;
		
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)
using P = pair<int,int>;
using ll = long long;
static const int INF = 1000000000;
static const ll MOD = 1000000007;

ll gcd(ll a, ll b){return b!=0 ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}

int main(){
	int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  int mn = INF, mx = 0;
  rep(i, n){
    mn = min(mn, a[i]);
    mx = max(mx, a[i]);
  }

  cout << mx - mn << endl;
	return 0;
}



Measured memory_bytes: 256