akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  int n;
  cin >> n;
  int i,j;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  sort(all(a));
  vector<bool> bt(1000001,false);
  vector<int> nums(1000001,0);
  rep(i,n)
  {
    nums[a[i]]++;
  }
  int now=0;
  rep(i,n)
  {
    if(a[i] <= now) continue;
    now = max(now,a[i]);
    int num = a[i];
    for(j=num*2;j<=1000000;j+=num)
    {
      bt[j] = true;
    }
  }
  int ans = 0;
  rep(i,n)
  {
    if(!bt[a[i]]&&nums[a[i]]<2)
    {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8012
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
 
using namespace std;
 
int main() {
  int h, w;
  cin >> h >> w;
 
  vector<string> g(h);
  int black = 0;
  for (int i = 0; i < h; i++) {
    cin >> g[i];
    for (int j = 0; j < w; j++) {
      black += g[i][j] == '#';
    }
  }
 
  queue<pair<int, int>> q;
  q.emplace(0, 0);
 
  vector<vector<int>> dist(h, vector<int>(w, -1));
  dist[0][0] = 0;
  
  const int dy[] = { 0, 1, 0, -1 };
  const int dx[] = { 1, 0, -1, 0 };
 
  while (!q.empty()) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    for (int k = 0; k < 4; k++) {
      int yy = y + dy[k];
      int xx = x + dx[k];
      if (yy < 0 || xx < 0 || yy >= h || xx >= w) continue;
      if (g[yy][xx] == '#') continue;
      if (dist[yy][xx] != -1) continue;
      dist[yy][xx] = dist[y][x] + 1;
      q.emplace(yy, xx);
    }
  }
 
  if (dist[h - 1][w - 1] == -1) {
    cout << -1 << endl;
  } else {
    cout << (h * w) - dist[h - 1][w - 1] - black - 1 << endl;
  }
}

Measured memory_bytes: 256
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

def ufinit(n):
  global ufsz, ufances
  ufsz = [1] * n
  ufances = [0] * n
  for i in range(n):
    ufances[i] = i

def ufroot(x):
  global ufances
  a = []
  y = x
  while ufances[y] != y:
    a.append(y)
    y = ufances[y]
  for z in a:
    ufances[z] = y
  return y

def ufconn(x,y):
  global ufsz, ufances
  i = ufroot(x)
  j = ufroot(y)
  if i==j:
    return
  #k  = [i,j].min
  k  = j if (ufsz[i]<ufsz[j]) else i
  if k==j:
    ufances[i] = j
  else:
    ufances[j] = i
  ufsz[k] = ufsz[i] + ufsz[j]


n,m = inm()
p = inl()
p[0:0] = [0]
x = []
y = []
for i in range(m):
    xx,yy = inm()
    x.append(xx)
    y.append(yy)
ufinit(n+1)
for i in range(m):
    ufconn(x[i],y[i])
ga = [0]*(n+1)
gb = [0]*(n+1)
for i in range(1,n+1):
    r = ufroot(i)
    ga[i] = gb[p[i]] = r
sm = 0
for i in range(1,n+1):
    if ga[i]==gb[i]:
        sm += 1
print(sm)


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

int main() {
    string s;
    cin >> s;
    int counter = 0;
    if (s[0] == '1') ++counter;
    if (s[1] == '1') ++counter;
    if (s[2] == '1') ++counter;
    cout << counter << endl;
}



Measured memory_bytes: 256
#!/usr/bin/env python3

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()

    li = []
    mm1 = A[N-1]
    mm2 = A[0]
    i = 1
    while(i<N-1):
        if A[i]<=0:
            li.append([mm1,A[i]])
            mm1 -= A[i]
        else:
            li.append([mm2,A[i]])
            mm2 -= A[i]
        i += 1
    li.append([mm1,mm2])
    print(mm1-mm2)
    for i in range(N-1):
        print(*li[i])
    

        


if __name__ == '__main__':
    main()





Measured memory_bytes: 22456
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#define ll long long
using namespace std;

int main(){

  int N,K;
  cin >> N >> K;
  int p[N];
  for (int i=0; i<N; i++)
    cin >> p[i];

  sort(p, p+N);

  int res=0;
  for (int i=0; i<K; i++)
    res += p[i];

  cout << res << endl;

  return 0;
}

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

int main() {
  int64_t N, D;
  cin >> N >> D;
  int ans = 0;
  for (int i = 0; i < N; i++) {
    int64_t X, Y;
    cin >> X >> Y;
    if (sqrt(X * X + Y * Y) <= D) {
      ans++;
    }
  }
  cout << ans << endl;
}

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

int main(){
    string A,B,C,K;
    int num[3],k;
    cin >> A >> B >> C >> K;
    num[0] = stoi(A);
    num[1] = stoi(B);
    num[2] = stoi(C);
    k = stoi(K);
    sort(num,num+3);
    for(int i = 0;i < k;i++){
        num[2] *= 2;
    }
    cout << num[0] + num[1] + num[2];
}

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

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

    bool output_flag = false;
    for(int i = 1; i <= 10000; i++) {
        int tax_a = i * 8 / 100;
        int tax_b = i * 10 / 100;
        if(tax_a == a && tax_b == b) {
            cout << i << endl;
            output_flag = true;
            break;
        }
    }

    if(!output_flag) cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#define sqr(x) (x)*(x)
using namespace std;
int n,m,i,j,a[105],ans=1<<30,sum;
int main()
{
	cin>>n;
	for (i=1;i<=n;i++) cin>>a[i];
	for (i=-100;i<=100;i++)
	{
		sum=0;
		for (j=1;j<=n;j++)
		{
			sum+=sqr(i-a[j]);
		}
		ans=min(ans,sum);
	}
	cout<<ans;
	return 0;
}

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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  if ( ( A + B ) > ( C + D ) ) {
    cout << "Left" << endl;
  }
  else if ( ( A + B ) == ( C + D ) ) {
    cout << "Balanced" << endl;
  }
  else {
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[], int n, int key) {
	int i = 0;
	A[n] = key;
	while (A[i] != key) i++;
	return i != n;
}

int main(){
	int i, n, A[10000+1], q, key, sum = 0;
	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);

	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &key);
		if (search(A, n, key)) sum++;
	}
	printf("%d\n", sum);

	return 0;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<int,int>;
const int INF = 100000000;
/* ちゃんと考えてわかって実装 */

vector<string> s;
int h, w;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int d[25][25];


int bfs(P st){

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            d[i][j] = INF;
        }
    }

    int res = 0;
    queue<P> que;
    que.push(st);
    d[st.first][st.second] = 0;
    while(!que.empty()){
        P now = que.front(); que.pop();
        for(int i=0; i<4; i++){
            int nx = now.first + dx[i];
            int ny = now.second + dy[i];
            // 「次の状態」が条件を満たしていて、未訪問なら候補に追加


            /* ここの対応関係でバグらせた(行が先、列が後) */
            /* 0<=nx && nx<w && 0<=ny && ny<h にすると、縦横入れ替わるので、配列外参照を起こす。 */
            if(0<=nx && nx<h && 0<=ny && ny<w && s[nx][ny] == '.' && d[nx][ny] == INF){
                que.push(make_pair(nx, ny));
                d[nx][ny] = d[now.first][now.second] + 1;
                res = max(res, d[nx][ny]);
            }
        }
    }
    return res;
}

int main(void){
    
    cin >> h >> w;
    s.resize(h);
    for(int i=0; i<h; i++){
        cin >> s[i];
    }

    int ans = 0;

    /* ここの対応関係も気をつける。(行が先、列が後) */
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            if(s[i][j] == '.') ans = max(ans, bfs(P(i, j)));
        }
    }

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

Measured memory_bytes: 256
import heapq as hq

n, m = map(int, input().split())
a = [-int(i) for i in input().split()]
hq.heapify(a)

for _ in range(m):
  hq.heappush(a, -(-hq.heappop(a) // 2))
  
print(sum(a) * -1)

Measured memory_bytes: 14180
open Printf
open Scanf

let () =
  let db = [|0;1;2;1;3;1;3;1;1;3;1;3;1|] in
  let x, y = scanf "%d %d\n" (fun x y -> (x, y)) in
  printf "%s\n" @@ if db.(x) = db.(y) then "Yes" else "No"


Measured memory_bytes: 384
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N;
	char[] S;
	int[][] counts;
	long result = 0L;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		N = Integer.parseInt(in.readLine());
		S = in.readLine().toCharArray();
		counts = new int[N][3];
		for (int i = 0; i < N; ++i) {
			Arrays.fill(counts[i], 0);
		}
		int countR = 0, countG = 0, countB = 0;
		for (int i = N - 1; i >= 1; --i) {
			switch (S[i]) {
			default:
			case 'R':
				++countR;
				break;
			case 'G':
				++countG;
				break;
			case 'B':
				++countB;
				break;
			}
			counts[i - 1][0] = countR;
			counts[i - 1][1] = countG;
			counts[i - 1][2] = countB;
		}
	}

	void calc() {
		for (int i = 0; i < N; ++i) {
			for (int j = i + 1; j < N; ++j) {
				if ((S[i] == 'R' && S[j] == 'G') || (S[i] == 'G' && S[j] == 'R')) {
					// ラストがB; R-G or G-R
					result += counts[j][2];
				} else if ((S[i] == 'G' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'G')) {
					// ラストがR: G-B or B-G
					result += counts[j][0];
				} else if ((S[i] == 'R' && S[j] == 'B') || (S[i] == 'B' && S[j] == 'R')) {
					// ラストがG: R-B or B-R
					result += counts[j][1];
				}
			}
		}
		for (int step = 1; step <= N / 2 + 1; ++step) {
			for (int i = 0; i < N; ++i) {
				int j = i + step;
				int k = j + step;
				if (j >= N || k >= N) {
					break;
				}
				if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
					result--;
				}
			}
		}
	}

	void showResult() {
		System.out.println(result);
	}
}

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

using namespace std;

int main() {
    int n, a;
    double tmp;
    vector<double> f;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a;
        f.push_back(1.0/a);
        tmp += f.at(i);
    }
    
    cout << 1.0 / tmp << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
std::string c[ 4 ] =
{
 "dream",
 "dreamer",
 "erase",
 "eraser" 
};
#ifdef ONLINE_JUDGE
bool dp[ 100010 ];
#else
bool dp[ 100 ];
#endif
std::string s; 
int main( )
{
 std::cin >> s;
 dp[ 0 ] = 1;
 for( int i = 5; i <= s.size( ); ++i )
 {
  for( int j = 0; j < 4; ++j )
  {
   if( i >= ( int ) c[ j ].size( ) && s.substr( i - ( int ) c[ j ].size( ), c[ j ].size( ) ) == c[ j ] )
    dp[ i ] |= dp[ i - ( int ) c[ j ].size( ) ];
  }
 }
 std::cout << ( dp[ s.size( ) ] ? "YES" : "NO" );
 return 0;
}

Measured memory_bytes: 3860
def ceil(a, b):
    return (a + b - 1) // b


N = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
n = sum(b) - sum(a)
for _a, _b in zip(a, b):
    if _a < _b:
        n -= ceil(_b - _a, 2)
if n >= 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 4596
import re

n, k = map(int, input().split())
str = input()

result = n-1

pattern = re.compile("RL")
X = len(pattern.findall(str))

if (str[0] == 'R') ^ (str[-1] == 'L'):
    Y = 0
else:
    if (str[0] == 'R') and (str[-1] == 'L'):
         X -= 1
    Y = 1

if k < X+Y:
    result -= Y + 2 * (X-k)

print(result)





Measured memory_bytes: 6516
#include <stdio.h>
#include <string.h>
#define LEN 100005

// 構造体
typedef struct pp {
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enqueue(P x) {
    Q[tail] = x;
    tail = (tail + 1) % LEN;
}

P dequeue() {
    P x = Q[head];
    head = (head + 1) % LEN;
    return x;
}

int min(int a, int b) { return a < b ? a : b; }


int main() {
    int elaps = 0, c;
    int i, q;
    P u;
    
    scanf("%d %d", &n, &q);
    for (i=1; i<=n; i++) {
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1; tail = n + 1;
    
    while (head != tail) {
        u = dequeue();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if (u.t > 0) enqueue(u);
        else {
            printf("%s %d\n", u.name, elaps);
        }
    }
    
    return 0;
}


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

int main(){
  int N;
  cin >> N;
  pair<int,int> P;
  vector<pair<int,int>> A(N);
  vector<pair<int,int>> B(N);
  
  for(int i=0; i<N; i++){
    int x, y;
    cin >> x >> y;
    P = make_pair(y,x);
    A.at(i) = P;
  }
  for(int i=0; i<N; i++){
    int x, y;
    cin >> x >> y;
    P = make_pair(x,y);
    B.at(i) = P;
  }
  
  sort(A.rbegin(), A.rend());
  sort(B.begin(), B.end());
  
  map<int,bool> mp;
  
  int j = 0;
  for(int i=0; i<N; i++){
    P = B.at(i);
    int a = P.first; //x座標
    int b = P.second; //y座標
    while(j < N){
      P = A.at(j);
      int c = P.first; //y座標
      int d = P.second; //x座標
      if(d <= a && c <= b){
        if(mp.count(j)){
          j++;
          continue;
        }
        else{
          mp[j] = true;
          j = 0;
          break;
        }
      }
      j++;
    }
    j = 0;
  }
  cout << mp.size() << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define int long long
using P = pair<int,int>;

signed main(){
  int s;
  cin >> s;
  int sss = s % 1000000000;
  int ss = s / 1000000000;
  if(sss != 0){
    ss++;
    sss = 1000000000 - sss;
  }
  cout << 0 << " " << 0 << " " << sss << " " << ss << " " << 1000000000 << " " << 1;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
using namespace std;
 
int main()
{
  int n;
  cin>>n;
  vector<vector<int>> arr(n,vector<int>(3,0));
  for(int i=0;i<n;i++)
    cin>>arr[i][0]>>arr[i][1]>>arr[i][2];
  for(int i=1;i<n;i++)
  {
    for(int j=0;j<3;j++)
    {
      int ans=INT_MIN;
      for(int k=0;k<3;k++)
      {
        if(k!=j)
          ans=max(ans,arr[i-1][k]);
      }
      arr[i][j]+=ans;
    }
  }
  int res=INT_MIN;
    res=max(res,max(arr[n-1][0],max(arr[n-1][1],arr[n-1][2])));
  cout<<res<<endl;
  return 0;
}

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

using namespace std;

const int MAXN = 100000 + 10;
const int INF = (int)(1e9);

int n;
int a[MAXN], d[MAXN];
vector<int> win[MAXN];

void DFS(int u) {
    d[u] = 0;
    vector<int> x;
    for(int v : win[u]) {
        DFS(v);
        x.push_back(d[v]);
    }
    if (x.size() > 0) {
        sort(x.begin(), x.end());
        int j = 0;
        for(int i = (int)(win[u].size()); i >= 1; --i) {
            d[u] = max(d[u], x[j] + i);
            ++j;
        }
    }
}

void run() {
    cin >> n;
    for(int i = 1; i <= n; ++i) win[i].clear();
    for(int i = 2; i <= n; ++i) {
        cin >> a[i];
        win[a[i]].push_back(i);
    }
    d[1] = 0;
    DFS(1);
    int res = d[1];
    cout << res << endl;
}

int main()
{
    //freopen("input.txt", "r", stdin);

    int ntests = 1;
    //cin >> ntests;
    for(int tc = 1; tc <= ntests; ++tc) {
        run();
    }
}


Measured memory_bytes: 14336
#include"bits/stdc++.h"
#define int long long
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define itr(i,x) for(auto i=(x).begin();i!=(x).end();++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
typedef pair<int,int> P;
const int mod=1000000007;
int gcd(int x,int y){return y?gcd(y,x%y):x;}
int lcm(int x,int y){return x*y/gcd(x,y);}
void YN(bool flg){cout<<(flg?"YES":"NO")<<endl;}
void Yn(bool flg){cout<<(flg?"Yes":"No")<<endl;}
void yn(bool flg){cout<<(flg?"yes":"no")<<endl;}
signed main(){
	int a,b;
	cin>>a>>b;
	cout<<(a+b+1)/2<<endl;
}

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

using namespace std;

int main() {
	const Int MOD = 1e9 + 7;
	int N;
	cin >> N;
	string s;
	cin >> s;

	vector<Int> R(2 * N, 0);
	vector<int> L;
	Int cnt = 0;
	for (int i = 0; i < s.size(); ++i) {
		if (cnt < 0) {
			cout << 0 << endl;
			return 0;
		}

		if (s[i] == 'B') {
			if (cnt % 2 == 0) {
				L.push_back(i);
				++cnt;
			} else {
				R[i] = 1;
				--cnt;
			}
		} else {
			if (cnt % 2 == 0) {
				R[i] = 1;
				--cnt;
			} else {
				L.push_back(i);
				++cnt;
			}
		}
	}
	for (int i = 2*N - 2; i >= 0; --i) { R[i] += R[i + 1]; }
	
	Int ans = (cnt == 0 ? 1 : 0);
	for (Int i = 1; i <= N; ++i) { (ans *= i) %= MOD; }

	int sz = L.size();
	for (int i = 0; i < L.size(); ++i) {
		Int x = R[L[sz - 1 - i]] - i;
		(ans *= x) %= MOD;
	}
	cout << ans % MOD << endl;

	return 0;
}


Measured memory_bytes: 3196
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Scanner;
import java.util.Set;

//Code Art Online
public class Main{

	double EPS = 1e-8;
	double norm(double[] a, double[] b){
		return (a[0]-b[0])*(a[0]-b[0]) + (a[1]-b[1])*(a[1]-b[1]);
	}
	double[] sub(double[] a, double[] b){
		return new double[]{a[0]-b[0], a[1]-b[1]};
	}
	
	double[] smallestCircle(double[][] p){
		int n = p.length;
		double[] pos = new double[2];
		double ratio = 0.5;
		while(ratio > EPS){
			for(int t=0;t<100;t++){
				double max = -1;
				int id = -1;
				for(int i=0;i<n;i++){
					double d = norm(pos, p[i]);
					if(max < d){
						max = d; id = i;
					}
				}
				double[] dt = sub(p[id], pos);
				pos[0]+=dt[0]*ratio;
				pos[1]+=dt[1]*ratio;
			}
			ratio/=2;
		}
		return pos;
	}
	
	class R implements Comparable<R>{
		int id, r;
		public R(int id, int r) {
			this.id = id;
			this.r = r;
		}
		public int compareTo(R o) {
			return r-o.r;
		}
	}
	
	int n, m;
	List<R>[] list;
	boolean[][] e;
	int[] res;
	boolean[] u;
	boolean ok;
	
	void f(int k){
		if(k==m){
			ok = true; return;
		}
		for(int i=0;i<n;i++)if(!u[i] && e[k][i]){
			u[i] = true;
			if(greedy(k+1)){
				res[k] = i;
				f(k+1);
				return;
			}
			u[i] = false;
		}
	}
	
	boolean greedy(int k){
		Set<Integer> use = new HashSet<Integer>();
		boolean res = true;
		for(int i=k;i<m;i++){
			boolean ok = false;
			for(R r:list[i]){
				if(!u[r.id]){
					u[r.id] = true; use.add(r.id); ok = true; break;
				}
			}
			if(!ok){
				res = false; break;
			}
		}
		for(int x:use)u[x] = false;
		return res;
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt(); m = sc.nextInt();
		int[] r = new int[n];
		for(int i=0;i<n;i++)r[i]=sc.nextInt();
		list = new List[m];
		e = new boolean[m][n];
		for(int i=0;i<m;i++){
			list[i] = new ArrayList<R>();
			int k = sc.nextInt();
			double[][] p = new double[k][2];
			for(int j=0;j<k;j++)for(int f=0;f<2;f++)p[j][f] = sc.nextInt();
			double[] c = smallestCircle(p);
			double R = 0;
			for(int j=0;j<k;j++)R = Math.max(R, norm(c, p[j]));
			R = Math.sqrt(R);
			for(int j=0;j<n;j++)if(R < r[j]+1e-6){
				e[i][j] = true;
				list[i].add(new R(j, r[j]));
			}
			Collections.sort(list[i]);
		}
		res = new int[m];
		u = new boolean[n];
		f(0);
		if(ok)for(int x:res)System.out.println(x+1);
		else System.out.println("NG");
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
#define all(i) i.begin(),i.end()
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll N,K;
  cin>>N>>K;
  vector<ll> a(N);
  rep(i,N) cin>>a[i];
  sort(all(a));
  
  ll lb=0,ub=a[N-1];
  
  while(ub-lb>1){
    ll mid=(lb+ub)/2;
    ll sum=0;
    for(int i=0;i<N;i++){
      sum+=(a[i]-1)/mid;
    }
    if(sum<=K) ub=mid;
    else lb=mid;
  }
  cout<<ub<<endl;
  
}

Measured memory_bytes: 4756
#include <stdio.h>
int max(int a,int b){
    if(a>b)return a;
    return b;
}
int min(int a,int b){
    if(a>b)return b;
    return a;
}
int abs(int a){
    if(a>0)return a;
    return -a;
}
int d(int a,int b){
    return min(abs(a-b)%24,abs(24-abs(a-b))%24);
}
bool check(bool a[],int ans){
    bool temp[24];
    for(int i=0;i<24;i++)temp[i]=a[i];
    for(int i=0;i<24;i++)if(temp[i])for(int j=i+1;j<24;j++)if(temp[j]){
        if(d(i,j)<ans){
            if(j>=12)return false;
            temp[j]=false;
            temp[24-j]=true;
        }
    }
    return true;
}
int main(){
    int n,temp;
    bool a[25];
    scanf("%d",&n);
    for(int i=0;i<24;i++)a[i]=false;
    a[0]=a[24]=true;
    for(int i=0;i<n;i++){
        scanf("%d",&temp);
        if(a[temp]){
            if(a[24-temp]){
                printf("0\n");
                return 0;
            }
            a[24-temp]=true;
        }
        else a[temp]=true;
    }
    for(int i=23;i>0;i--){
        if(check(a,i)){
            printf("%d\n",i);
            return 0;
        }
    }
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
#include <cmath>
using namespace std;
using ll = long long int;

ll factorial(ll n) {
    if (n == 0) {
        return 0;
    }
    if (n == 1) {
        return 1;
    } else {
        return n * factorial(n-1);
    }
}

map<ll, ll> sosuu (ll n)
{
    map<ll, ll> res;
    for (ll i = 2; i*i <= n; i++)
    {
        if (n % i == 0) {
            while (n % i == 0) {
                res[i]++;
                n /= i;
            }
        }
    }
    if (n != 1) res[n] = 1;
    return res;
}

ll combination(const ll n, const ll k) {    
    map<ll, ll> n_fact;
    // n!
    for (size_t i = 1; i <= n; i++)
    {
        map<ll, ll> mp = sosuu(i);
        for (auto &&e : mp)
        {
            n_fact[e.first] += e.second;
        }
    }
    // (n-1)!
    for (size_t i = 1; i <= (n-k); i++)
    {
        map<ll, ll> mp = sosuu(i);
        for (auto &&e : mp)
        {
            n_fact[e.first] -= e.second;
        }
    }
    // k!
    for (size_t i = 1; i <= k; i++)
    {
        map<ll, ll> mp = sosuu(i);
        for (auto &&e : mp)
        {
            n_fact[e.first] -= e.second;
        }
    }
    
    ll ans = 1;
    for (auto &&e : n_fact)
    {
        ans *= pow(e.first, e.second);
    }
    return ans;
}

int main()
{
    ll n, p;
    cin >> n >> p;
    ll even = 0, odd = 0;

    for (size_t i = 0; i < n; i++)
    {
        ll ai;
        cin >> ai;
        if (ai % 2 == 0) {
            even++;
        } else {
            odd++;
        }
    }

    ll all = (1LL<<n);
    ll even_to_even = (1LL<<even);
    ll odd_to_even = 1;
    for (size_t i = 1; i <= odd; i++)
    {
        if (i % 2 == 0) {
            odd_to_even += combination(odd, i);
        }
    }
    ll even_count = even_to_even * odd_to_even;
    ll odd_count = all - even_count;

    if (p == 0) {
        cout << even_count << endl;
    } else {
        cout << odd_count << endl;
    }
}

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

int main(){
  ll h,n,cnt=0;
  cin >> h >> n;
  vector<ll> a(n);
  for(ll i=0;i<n;i++){
    cin >> a.at(i);
    cnt += a.at(i);
  }
  if(cnt >= h) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	long H[] = new long[N];
	
	sc.nextLine();
	for (int i=0; i<N; i++){
		H[i] = sc.nextInt();
	}
	
	int NumMove = 0;
	int tmpNumMove = 0;
	
	for (int i=0; i<N-1; i++){
		if(H[i] >= H[i+1]){
			tmpNumMove++;
        }else{
			if(tmpNumMove > NumMove){
				NumMove = tmpNumMove;
            }
			tmpNumMove = 0;
		}
	}
    
    if(tmpNumMove > NumMove){
      NumMove = tmpNumMove;
    }
    
    System.out.println(NumMove);
  }
}

Measured memory_bytes: 49848
#include<stdio.h>


int main()
{
    int count=0;
    char c1, c2, c3;
    scanf("%c%c%c", &c1, &c2, &c3);

    if(c1=='R')
    {
        count++;
        if(c2=='R')
        {
            count++;
            if(c3=='R')
                count++;

        }
    }
    else if(c2=='R')
    {
        count++;
        if(c3=='R')
            count++;
    }
    else if(c3=='R')
        count++;

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


    return 0;
}


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

#define REP(i,m,n) for(int i=(m); i<(int)(n); i++)
#define RREP(i,m,n) for(int i=(int)((n)-1); i>=m; i--)
#define rep(i,n) REP(i,0,n)
#define rrep(i,n) RREP(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define fi first
#define se second
#define debug(...) {cerr<<"[L"<<__LINE__<<"] "; _debug(__VA_ARGS__);}

template<typename T>
string join(const vector<T>&v, string del=", "){ stringstream s;
    for(auto x : v) s << del << x; return s.str().substr(del.size());
}
template<typename T>
ostream& operator<<(ostream& o, const vector<T>&v){
    if(v.size()) o << "[" << join(v) << "]"; return o;
}
template<typename T>
ostream& operator<<(ostream& o, const vector<vector<T> >&vv){
    int l = vv.size();
    if(l){ o<<endl; rep(i,l) o << (i==0 ? "[ " : ",\n  " ) << vv[i] << (i==l-1 ? " ]" : ""); }
    return o;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& o, const pair<T1, T2>& p){
    return o << "(" << p.first << ", " << p.second << ")";
}
inline void _debug(){cerr<<endl;}
template<class First, class... Rest>
void _debug(const First& first, const Rest&... rest){cerr<<first<<" ";_debug(rest...);}

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

const double PI = (1*acos(0.0));
const double EPS = 1e-9;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const ll mod = 1e9 + 7;

inline void finput(string filename) {
    freopen(filename.c_str(), "r", stdin);
}

int di[] = {0, 1, 0, -1};
int dj[] = {1, 0, -1, 0};

int h,w;
vector<string> g;
vvi bfs(int si, int sj){
    vvi d = vvi(h, vi(w, INF));
    d[si][sj] = 0;
    deque<pii> dq({pii(si,sj)});
    while(!dq.empty()){
        int i = dq.front().fi;
        int j = dq.front().se;
        dq.pop_front();
        rep(k,4){
            int ni = i + di[k];
            int nj = j + dj[k];
            if(ni < 0 || h <= ni) continue;
            if(nj < 0 || w <= nj) continue;
            if(g[ni][nj] == '#') continue;
            if(d[ni][nj] > d[i][j]){
                d[ni][nj] = d[i][j];
                dq.emplace_front(ni, nj);
            }
        }
        rep(ii,5) rep(jj,5){
            int ni = i + ii - 2;
            int nj = j + jj - 2;
            if(ni < 0 || h <= ni) continue;
            if(nj < 0 || w <= nj) continue;
            if(g[ni][nj] == '#') continue;
            if(d[ni][nj] > d[i][j] + 1){
                d[ni][nj] = d[i][j] + 1;
                dq.emplace_back(ni, nj);
            }
        }
    }
    return d;
}

int main(){
    ios_base::sync_with_stdio(0);
    // finput("./input");
    cin >> h >> w;
    int ch,cw; cin >> ch >> cw;
    int dh,dw; cin >> dh >> dw;
    ch--; cw--; dh--; dw--;
    g = vector<string>(h);
    rep(i,h) cin >> g[i];

    auto d = bfs(ch, cw);
    if(d[dh][dw] == INF){
        cout << -1 << endl;
    }else{
        cout << d[dh][dw] << endl;
    }
    return 0;
}

Measured memory_bytes: 8776
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>
#include <cassert>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

template<typename T1, typename T2>
inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }

template<typename T1, typename T2>
inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

typedef long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using Int = long long int;
using uInt = long long unsigned int;
using Double = long double;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//edit
class Solve {
public:
    bool solve() {
        Int n, m, k;
        cin >> n >> m >> k;
        if (n == 0) return false;

        if (n == 1) {
            Double ans = (k + (1 + (m - k)) * (m - k) / 2.) / m;
            cout << ans << endl;
            return true;
        }

        vector<Double> kumi(static_cast<unsigned long>(n * m + 1));
        kumi[0] = 1.;
        rep(_, 0, n) {
            for (Int x = n * m; x >= 0; --x) {
                for (int y = 1; y <= m; ++y) {
                    if (x + y <= n * m)kumi[x + y] += kumi[x];
                }
                kumi[x] = 0.;
            }
        }

        Double ans = 0.0;
        for (Int x = 0; x <= n * m; ++x) {
            Double tmp = max<Double>(x - k, 1.) * kumi[x];
            ans += tmp;
        }
        for (int i = 0; i < n; ++i) {
            ans /= m;
        }
        cout << ans << endl;

        return true;
    }
};


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

    while (Solve().solve());


    return 0;
}



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

int main() {
  int i,j,n,k,m,l[100],max,total=0;
  cin>>n>>k;
  for(i=0;i<n;i++){
    cin>>l[i];
  }
  
  for(j=0;j<k;j++){
    max=0;
    for(i=0;i<n;i++){
      if(max<l[i]){
        max=l[i];
        m=i;
      }
    }
    l[m]=0;
    total+=max;
    //cout<<total<<endl;
  }
  
    cout<<total<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,n,s) for(int i = s; i < (n); ++i)
#define rsrep(i,n,s) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a; }

int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    vint l(n+1, 0);
    vint r(n+1, 0);
    rep(i, n) l[i+1] = gcd(l[i], a[i]);
    rrep(i, n) r[i] = gcd(r[i+1], a[i]);

    int ans = 0;
    rep(i, n) {
        ans = max(ans, (int)gcd(l[i], r[i+1]));
    }

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

Measured memory_bytes: 1408
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.HashSet;
import java.util.NoSuchElementException;

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		}

		ptr = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return buflen > 0;
	}

	private int readByte() {
		return hasNextByte() ? buffer[ptr++] : -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
		return hasNextByte();
	}

	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
			throw new NumberFormatException();
		}
		return (int) nl;
	}

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

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		FastScanner fs = new FastScanner();
		int n = fs.nextInt(), m = fs.nextInt();

		int[] heights = new int[n + 10];
		for (int i = 1; i <= n; ++i) {
			heights[i] = fs.nextInt();
		}

		HashMap<Integer, HashSet<Integer>> adjacentMap = new HashMap<Integer, HashSet<Integer>>();
		for (int i = 0; i < m; ++i) {
			int a = fs.nextInt(), b = fs.nextInt();
			adjacentMap.putIfAbsent(a, new HashSet<Integer>());
			adjacentMap.get(a).add(b);
			adjacentMap.putIfAbsent(b, new HashSet<Integer>());
			adjacentMap.get(b).add(a);
		}

		int ans = 0;
		for (int protagonist = 1; protagonist <= n; ++protagonist) {
			if (isGood(protagonist, adjacentMap, heights)) {
				++ans;
			}
		}
		System.out.println(ans);
	}

	static boolean isGood(int protagonist, HashMap<Integer, HashSet<Integer>> adjacentMap, int[] heights) {
		HashSet<Integer> adjacents = adjacentMap.get(protagonist);
		if (adjacents == null) {
			return true;
		}

		for (int deck : adjacents) {
			if (heights[protagonist] <= heights[deck]) {
				return false;
			}
		}

		return true;
	}

}


Measured memory_bytes: 84308
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}

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

ll rec(ll N, ll X)
{
  if (X == 0) return 0;
  return 3*X*(N/X) + rec(X, N%X);
}

int main()
{
  ll N, X;
  cin >> N >> X;
  cout << rec(N - X, X) << endl;
  return 0;
}

Measured memory_bytes: 256
n,x,m = map(int,input().split())

a = x
r = [False for _ in range(m)]
s = []
i = 0
while(r[a] == False and i < n):
  r[a] = True
  s.append(a)
  a = pow(a,2,m)
  i += 1
if i == n:
  ans = sum(s)
else:
  ai = s.index(a)
  c = (n-len(s))//(len(s)-ai)
  d = (n-len(s))-(len(s)-ai)*c
  # print(i,ai,c,d)
  ans = sum(s)+sum(s[ai:])*c+sum(s[ai:ai+d])
print(ans)

Measured memory_bytes: 76240
/***************************************************************
	File name: B.cpp
	Author: ljfcnyali
	Create time: 2019年09月01日 星期日 19时57分35秒
***************************************************************/
#include<bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for ( int i = (a), _end_ = (b); i <= _end_; ++ i ) 
#define mem(a) memset ( (a), 0, sizeof ( a ) ) 
#define str(a) strlen ( a ) 
typedef long long LL;

int n, m, ans;

int main()
{
    scanf("%d%d", &n, &m);
    int now = 1;
    while ( now < m ) 
    {
        now += n - 1;
        ++ ans;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static char[][] c;
	static char[][] cp;
	static int n;
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char c = sc.next().charAt(0);
		System.out.println((char) (c + 1));
		sc.close();
	}

}



Measured memory_bytes: 21076
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////
const ll inf = 1LL<<60;

ll d;
vector<ll> c(26);
vector<vector<ll>> s(365, vector<ll>(26));
vector<ll> t(365);

vector<ll> calc() {
  vector<ll> nsc(26);
  vector<ll> score(d);
  vector<ll> last(26, -1);
  rep(i, d) {
    last[t[i]] = i;
    rep(j, 26) {
      if (t[i] == j) nsc[j] += s[i][j];
      else nsc[j] -= c[j]*(i-last[j]);
    }
    ll sum = 0;
    rep(j, 26) sum += nsc[j];
    score[i] = sum;
  }
  return score;
}

int main()
{
  srand((unsigned)time(NULL));

  cin>>d;
  rep(i, 26) cin>>c[i];
  rep(i, d) rep(j, 26) cin>>s[i][j];

  rep(i, d) {
    ll tmp = 0;
    ll ma = -inf;
    rep(j, 26) {
      if (s[i][j] > ma) {
        ma = s[i][j];
        tmp = j;
      } else if (s[i][j] == ma) {
        if (c[j] < c[tmp]) {
          tmp = j;
        }
      }
    }
    t[i] = tmp;
  }
  vector<ll> fsc = calc();

  {
    vector<ll> last(26, -1);
    vector<ll> nsc(26);
    rep(i, d) {
      ll idx = 0;
      ll sum = 0;
      rep(j, 26) {
        nsc[j] -= c[j]*(i-last[j]);
        sum += nsc[j];
      }
      rep(j, 26) {
        ll aa = sum + c[j]*(i-last[j]) + s[i][j];
        ll bb = sum + c[idx]*(i-last[idx]) + s[i][idx];
        if (aa > bb && aa >= fsc[i]) {
          idx = j;
        }
      }
      nsc[idx] += c[idx]*(i-last[idx]) + s[i][idx];
      last[idx] = i;
      t[i] = idx;
    }
  }
  vector<ll> ssc = calc();

  int ti = clock();
  while (clock() - ti < 190 * CLOCKS_PER_SEC / 100) {
    ll nd = rand() % d;
    ll nx = rand() % 26;
    ll px = t[nd];
    t[nd] = nx;
    vector<ll> tsc = calc();
    if (ssc[d-1] < tsc[d-1]) {
      ssc = tsc;
    } else {
      t[nd] = px;
    }
  }

  rep(i, d) cout << t[i]+1 << endl;

  return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  int x, y; cin >> x >> y;
  if(x == 1 && y == 1) {
    cout << 600000 + 400000 << endl;
  } else {
    int ans = 0;
    if(x == 1) {
      ans += 300000;
    } else if(x == 2) {
      ans += 200000;
    } else if(x == 3) {
      ans += 100000;
    }
    if(y == 1) {
      ans += 300000;
    } else if(y == 2) {
      ans += 200000;
    } else if(y == 3) {
      ans += 100000;
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<stack>
#include<queue>
#include<numeric>
#include<algorithm>
#include<string>
#include<map>
#include<bitset>
#include<set>
#include<cmath>
#define int long long
const int inf=8938103643641919514ll;
const int mod=1000000007ll;
const int dd[]={0,-1,0,1,0};
using namespace std;
int pri[10001];
int ps;
int p[50][50],q[50][50];
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++){
		string s;
		cin>>s;
		for(int j=0;j<n;j++)
			p[i][j]=s[j];
	}
	for(int i=0;i<m;i++){
		string s;
		cin>>s;
		for(int j=0;j<m;j++)
			q[i][j]=s[j];
	}
	for(int i=0;i<=n-m;i++){
		for(int j=0;j<=n-m;j++){
			bool f=true;
			for(int k=0;k<m;k++){
				for(int l=0;l<m;l++){
					if(q[k][l]!=p[i+k][j+l]){
						f=false;
						goto aaaaa;
					}
				}
			}
aaaaa:
			if(f){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define all(vec) vec.begin(), vec.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl
#define isEven(t) t % 2 == 0

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

//(a,b)から(c,d)までの距離
int dis(int a,int b,int c,int d){
	return abs(a - c) + abs(b - d);
}

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

	int N;
	cin >> N;
	bool flg = true;
	vector<int> t(N + 1), x(N + 1), y(N + 1);
	t[0] = x[0] = y[0] = 0;

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

	for (int i = 1; i <= N; i++) {
		int time = t[i] - t[i - 1];
		int distance = dis(x[i], y[i], x[i - 1], y[i - 1]);

		if(distance>time){
			flg = false;
		}

		if((distance%2)!=(time%2)){
			flg = false;
		}
	}

	yn(flg);

	return 0;
}

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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int N;
vi arr;
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> N;
	arr.resize(N);
	F0R(i, N) cin >> arr[i];

	vi perm (N);
	F0R(i, N) perm[i] = i;
	sort(perm.begin(), perm.end(), [](const auto& lhs, const auto& rhs) {
		return arr[lhs] < arr[rhs];
	});

	int best = N;
	int last = -1;
	int size = 0;
	for (int i : perm) {
		if (i > last) ++size;
		else {
			size = 1;
		}
		last = i;
		best = min(best, N - size);
	}
	print(best);
}

Measured memory_bytes: 4764
import java.util.*

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    
    val arr = Array<Int>(n, { cin.nextInt() })

    val costs = Array<Int>(n, { 0 })

    for (i in 0..n-1) {
        if (i == 0) {
            continue
        } else if (i == 1) {
            costs[i] = Math.abs(arr[0] - arr[1])
        } else {
            costs[i] = Math.min(costs[i-1] + Math.abs(arr[i] - arr[i - 1]), costs[i-2] + Math.abs(arr[i] - arr[i-2]))
        }
    }
    println(costs[n-1])
}

Measured memory_bytes: 53620
#include<iostream>
#include<map>
#include<vector>
using namespace std;
long long r[300001]={0};
long long c[300001]={0};
map<pair<long long, long long>,long long>mp;
vector<long long>r1;
vector<long long>c1;
//using namespace std;
int main()
{
	long long h,w,m,cnt=0,row=0,col=0,i,s1,s2,a,b;
	cin>>h>>w>>m;
	pair<long long,long long>p;
	for(i=1;i<=m;i++)
	{
		cin>>a>>b;
		r[a]++;
		c[b]++;
		p=make_pair(a,b);
		mp[p]=1;
	}
	for(i=1;i<=h;i++)
	{
		row=max(row,r[i]);
	}
	for(i=1;i<=w;i++)
	{
		col=max(col,c[i]);
	}
	for(i=1;i<=h;i++)
	{
		if(row==r[i])
		{
			r1.push_back(i);
		}
	}
	for(i=1;i<=w;i++)
	{
		if(col==c[i])
		{
			c1.push_back(i);
		}
	}
	s1=r1.size();
	s2=c1.size();
	for(i=0;i<s1;i++)
	{
		for(int j=0;j<s2;j++)
		{
			if(mp[make_pair(r1[i],c1[j])]==0)
			{
				cnt=1;
				break;
			}
		}
	}
	if(cnt==1)
	{
		cout<<row+col<<endl;
	}
	else
	{
		cout<<col+row-1<<endl;
	}
	return 0;
}

Measured memory_bytes: 50008
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> ABC(3);
  int K;
  cin >> ABC.at(0) >> ABC.at(1) >> ABC.at(2) >> K;
  
  sort(ABC.begin(), ABC.end());
  
  cout << ABC.at(0)+ABC.at(1)+ABC.at(2)*pow(2,K) << endl;
}

Measured memory_bytes: 256