akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A = [(a, i) for i, a in enumerate(A)]
A.sort(reverse=1)

# dp[i][j] := 左にi人、右にj人確定した状態での最大値
dp = list2d(N+1, N+1, -INF)
dp[0][0] = 0
for i, (a, x) in enumerate(A):
    # j := 今左に確定してる人数
    for j in range(i+1):
        # k := 今右に確定してる人数
        k = i - j
        # このaを左にする遷移
        y = j
        dp[j+1][k] = max(dp[j+1][k], dp[j][k] + abs(x - y) * a)
        # このaを右にする遷移
        y = N - 1 - k
        dp[j][k+1] = max(dp[j][k+1], dp[j][k] + abs(x - y) * a)
ans = 0
for i in range(N+1):
    # 左右に計N人決まった状態での最大を取る
    ans = max(ans, dp[i][N-i])
print(ans)


Measured memory_bytes: 106060
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define LEN 1000000

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
P w[LEN+1];
int head, tail, n;

int Empty(){
  if(head == tail)
    return 1;
  else return 0;
}

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

void ini(){
  head = 0;
  tail = n+1;
}


int main(){
  int elaps = 0, c, count=1;
  int i, q;
  scanf("%d %d", &n, &q);
  int A[n+1];
  
  for(i=1;i<=n;i++){
    w[i].t = 0;
  }
  
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  ini();

  i=1;
  while(count != n+1){
    if(Q[i].t > q){
      Q[i].t=(Q[i].t-q);
      elaps+=q;
      enqueue(Q[i]);
      i++;
    }
    else if(Q[i].t<=q){
      elaps+=Q[i].t;
      w[count].t=elaps;
      strcpy(w[count].name,Q[i].name);
      i++;
      count++;
    }
  }
    for(i=1;i<=n;i++){
      printf("%s %d\n",w[i].name,w[i].t);
    }
	
  
  return 0;
}



Measured memory_bytes: 26156
//#include <conio.h>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;

int main()
{
	int count4 = 0,count2 = 0;
	int n;
	cin >> n;
	string str = "No";
	int *arr = new int[n];

	for (int i = 0; i < n; i++)
		cin >> arr[i];
	if (n == 2)
	{

		if (arr[0] % 4 == 0 || arr[1] % 4 == 0 || ( arr[0] % 2 == 0 && arr[1] % 2 == 0))
			cout << "Yes";
		else cout << "No";
		return 0;
	}
	for (int i = 0; i < n; i++)
	{
		if (arr[i] % 4 == 0)
			count4++;
		if (arr[i] % 2 == 0 && arr[i] % 4 != 0)
			count2++;
	}
	//cout << count2 << " " << count4 << endl;
	if (n % 2 == 0){
		if (count2 != 0)
		{
			if (count4 >= (n - count2 + 1) / 2)
				str = "Yes";
		}
		else {
			if (count4 >= n/2)
				str = "Yes";

		}
	}
	else{
		if (count2 != 0){
			if (count4 >= (n - count2 + 1)/2 )
				str = "Yes";
		}
		else {
			if (count4 >= (n - 1)/2)
				str = "Yes";
		}
	}
	cout << str;
	//_getch();
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repp(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)
#define p(s) cout << s << endl;
typedef long long LL;
template <class T>
bool contain(const std::string &s, const T &v)
{
    return s.find(v) != std::string::npos;
}

int main()
{
    string s; cin>>s;
    if(s[5]==','){
        s[5]=' ';
        s[13]=' ';
    }else{
        s[5] = ',';
        s[13] = ',';
    }
    cout<<s<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>
#define llint long long
#define inf 1e18

using namespace std;

// sum-query

struct SegTree{
	struct SegNode{
		double val;
		int left, right, parent;
		SegNode(int p, double x = 1){  //initial value
			left = right = -1;
			parent = p;
			val = x;
		}
	};
	
	int size;
	vector<SegNode> seg;
	
	SegTree(int size){
		this->size = size;
		init();
	}
	
	void init()
	{
		seg.clear();
		seg.push_back(SegNode(-1));
	}
	
	void check(int p){
		if(seg[p].left == -1){
			seg.push_back(SegNode(p));
			seg[p].left = (int)seg.size()-1;
		}
		if(seg[p].right == -1){
			seg.push_back(SegNode(p));
			seg[p].right = (int)seg.size()-1;
		}
	}
	
	void update(int i, double val)
	{
		int p = 0, l = 0, r = (1<<size)-1;
		while(l < r){
			check(p);
			if(i <= (l+r)/2) p = seg[p].left, r = (l+r)/2;
			else p = seg[p].right, l = (l+r)/2+1;
		}
		seg[p].val = val;
		
		p = seg[p].parent;
		while(p != -1){
			seg[p].val = seg[seg[p].left].val * seg[seg[p].right].val;
			p = seg[p].parent;
		}
	}
	
	double query(int a, int b, int p, int l, int r)
	{
		if(b < l || r < a) return 1;
		if(a <= l && r <= b) return seg[p].val;
		
		check(p);
		double lval = query(a, b, seg[p].left, l, (l+r)/2);
		double rval = query(a, b, seg[p].right, (l+r)/2+1, r);
		return lval * rval;
	}
	double query(int a, int b)
	{
		return query(a, b, 0, 0, (1<<size)-1);
	}
};

llint n, Q;
SegTree seg(30);

int main(void)
{
	//ios::sync_with_stdio(0);
	//cin.tie(0);
	
	cin >> n;
	seg.init();
	
	llint t; double a;
	for(int i = 1; i <= n; i++){
		cin >> t >> a;
		a = 1 - a*0.1;
		seg.update(t, a);
	}
	
	cin >> Q;
	llint l, r;
	for(int i = 1; i <= Q; i++){
		cin >> l >> r;
		printf("%.11f\n", 1e9*seg.query(l, r));
	}
	
	return 0;
}


Measured memory_bytes: 199688
#C
#入力
K=int(input())


#デバッグ用
def pront(*n):
    if debug==1:
        print(n)
        
debug=1#0:本番,1:デバッグ

#処理
import math as m
Z=[ [-1 for i in range(K+1)] for j in range(K+1)]
def C_1(i,j):
    if Z[i][j]!=-1:
        return Z[i][j]
    else:
        x=m.gcd(i,j)
        Z[i][j]=x
        Z[j][i]=x
        return Z[i][j]

x=0
for i in range(1,K+1):
    for j in range(1,K+1):
        y=C_1(i,j)
        if y==1:
            x+=K
        else:
            for k in range(1,K+1):
                x+=C_1(y,k)
print(x)

Measured memory_bytes: 9520
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;




int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    int a = s[0] - '0', b = s[1] - '0', c = s[2] - '0', d = s[3] - '0';
    if (a - b - c - d == 7) printf ("%d-%d-%d-%d=7\n" , a, b, c, d);
    else if (a - b - c + d == 7) printf ("%d-%d-%d+%d=7\n", a, b, c, d);
    else if (a - b + c - d == 7) printf ("%d-%d+%d-%d=7\n", a, b, c, d);
    else if (a - b + c + d == 7) printf ("%d-%d+%d+%d=7\n", a, b, c, d);
    else if (a + b - c - d == 7) printf ("%d+%d-%d-%d=7\n", a, b, c, d);
    else if (a + b - c + d == 7) printf ("%d+%d-%d+%d=7\n", a, b, c, d);
    else if (a + b + c - d == 7) printf ("%d+%d+%d-%d=7\n", a, b, c, d);
    else if (a + b + c + d == 7) printf ("%d+%d+%d+%d=7\n", a, b, c, d);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
int n;
cin>>n;
vector<int> a(n);
for(int i=0;i<n;i++)cin>>a.at(i);
sort(a.begin(),a.end());
int count=1,ans=0,check=a.at(0);
for(int i=1;i<n;i++){
  if(check==a.at(i))count++;
  else{
      check=a.at(i);
      if(count<a.at(i-1))ans+=count;
      else ans+=count-a.at(i-1);
      count=1;
  }
}
 if(count<a.at(n-1))ans+=count;
 else ans+=count-a.at(n-1);
 cout<<ans<<endl;
}

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

int main() {

    int A, B;
    cin >> A >> B;

    int ans = -1;
    for (int i = 0; i < 1500; i++) {
        if (floor(i*0.08) == A && floor(i*0.1) == B) {
            ans = i;
            break;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<queue>
#include<cstdlib>
using namespace std;
#define For(i,a,b) for(register int i=(a);i<=(b);++i)
#define LL long long
int read(){
	char x=getchar(); int u=0;
	while(!isdigit(x)) x=getchar();
	while(isdigit(x)) { u=(u<<3)+(u<<1)+(x^48); x=getchar(); }
	return u;
}
char s[10000];
bool flag=0;
int main(){
	scanf("%s",s+1);
	int len=strlen(s+1);
	For(i,1,len-8)
		printf("%c",s[i]);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <array>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <iomanip>
using namespace std;

int main()
{
    char S[5];
    char T[5];
    cin >> S[0] >> S[1] >> S[2];
    cin >> T[0] >> T[1] >> T[2];
    int ans = 0;
    for(int i=0;i<3;i++){
        if(S[i]==T[i]){
            ans ++;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 888
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		long ans = 0;
		for(int i = 1;i < n;++i){
			ans += (n-1)/i;
		}
		System.out.print(ans);
	}
}


Measured memory_bytes: 35720
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

long long kMod = 1e9+7;
vector<vector<long long>> nck;

long long combinations(long long n, long long k)
{
  if (n < k) {
    return 0;
  }
  if (n < (long long)nck.size() && k < (long long)nck.at(n).size()) {
    return nck.at(n).at(k);
  }
  nck.resize(n+1);
  for (int i = 0; i < (int)nck.size(); i++) {
    nck.at(i).resize(i+1);
  }
  nck.at(0).at(0) = 1;
  nck.at(1).at(0) = 1;
  nck.at(1).at(1) = 1;
  for (int i = 2; i < (int)nck.size(); i++) {
    for (int j = 0; j < (int)nck.at(i).size(); j++) {
      if (j == 0 || j == (int)nck.at(i).size() - 1) {
        nck.at(i).at(j) = 1;
      } else {
        nck.at(i).at(j) = (nck.at(i-1).at(j-1) + nck.at(i-1).at(j)) % kMod;
      }
    }
  }
  return nck.at(n).at(k);
}

long long solve(long long n, long long k, long long i)
{
  if (k-1 > n-k+1) {
    return (combinations(k-1, i-1) * combinations(n-k+1, i)) % kMod;
  } else {
    return (combinations(n-k+1, i) * combinations(k-1, i-1)) % kMod;
  }
}

int main()
{
  long long n, k;
  cin >> n >> k;
  //cout << combinations(n, k) << '\n';
  for (long long i = 1; i <= k; i++) {
    //cout << k-1 << ',' << i-1 << '*' << n-k+2 << ',' << i+1 << '\n';
    cout << solve(n, k, i) << '\n';
  }
  return 0;
}


Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int nex[66][202020];

int main(){
  int N; cin>>N;
  ll K; cin>>K;
  int A[N];
  rep(i,N){
    cin>>A[i];
    A[i]--;
    nex[0][i]=A[i];
  }
  rep(i,60) rep(j,N){
    nex[i+1][j]=nex[i][nex[i][j]];
  }
  int ans=0;
  rep(i,61){
    if((1LL<<i)&K) ans=nex[i][ans];
  }
  cout<<ans+1<<endl;
  return 0;
}

Measured memory_bytes: 52268
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;

template<typename T>
void dmax(T & x, const auto &y){
	if(y > x) x = y;
}

int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n, m;
	
	cin>>n>>m;
	
	vector<vector<int>> a(n, vector<int>(m));
	
	int q;
	cin>>q;
	while(q--){
		int i,j,x;
		cin>>i>>j>>x;
		a[--i][--j] = x;
	}
	
	ll inf = 1e18;
	vector<vector<array<ll,4>>> d(n, vector<array<ll,4>>(m));
	for(int i=0;i<n;++i)
	for(int j=0;j<m;++j) for(int t=0;t<4;++t) d[i][j][t] = -inf;
	d[0][0][0] = 0;
	d[0][0][1] = a[0][0];
	
	for(int i=0;i<n;++i)
	for(int j=0;j<m;++j){
		for(int t=0;t<4;++t){
			ll &res = d[i][j][t];
			
			if(i+1<n){
				dmax(d[i+1][j][0], res);
				dmax(d[i+1][j][1], res + a[i+1][j]);
			}
			
			if(j+1<m){
				dmax(d[i][j+1][t], res);
				if(t+1<4) dmax(d[i][j+1][t+1], res + a[i][j+1]);
			}
		}
	}
	
	cout<<*max_element(ALL(d[n-1][m-1]))<<endl;
	
	
	return 0;
}


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

int main() {
	
	string s; cin >> s;
	int ans = 0;
	for (int i = 0; i < s.size() - 1; i++) {
		if (s[i] != s[i + 1]) {
			ans++;
		}
	}

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

Measured memory_bytes: 512
//#include <iostream>
#include <stdio.h>
#include <math.h>

int main(void) {

  char a[8],b[4];
  float x;
  
  // input
  scanf("%s %s",a,b);
  strcat(a,b);
  x = atoi(a);
  
  x = sqrt(x);
  
  // output
  if( (x-(int)x) <= 0 ){
    printf("Yes");
  } else {
    printf("No");
  }
  
  return 0;
}

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

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

    vector <long> A(N);
    for(int i=0; i<N; i++){
        cin >> A[i];
    }
    sort(A.begin(), A.end());

    vector <int> count(N,0);

    count[0] = 1;
    int mark=0;
    for(int i=0; i<N-1; i++){
        if(A[i] != A[i+1]){
            mark++;
            count[mark]++;
        }
        else{
            count[mark]++;
        }
    }

    int ans=0;
    for(int i=0; i<N; i++){
        ans = ans + count[i] % 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
fun main(args: Array<String>) {
    abc068c()
}

fun abc068c() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val aList = IntArray(m)
    val bList = IntArray(m)
    (1..m).map { readLine()!!.split(' ').map { it.toInt() } }
        .forEachIndexed { index, list ->
            aList[index] = list[0]
            bList[index] = list[1]
        }

    val from1 = aList.withIndex().filter { it.value == 1 }.map { bList[it.index] }.toSet()
    val toN = bList.withIndex().filter { it.value == n }.map { aList[it.index] }.toSet()

    val answer = if ((from1 intersect toN).isNotEmpty()) "POSSIBLE" else "IMPOSSIBLE"

    println(answer)
}


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

#define fast ios_base::sync_with_stdio(false),cin.tie(NULL)
#define ldb long double 
#define db double
#define int long long

#define fr first
#define se second
#define lb lower_bound 
#define ub upper_bound 
#define pb push_back
#define mpr make_pair

#define pi pair<int,int>
#define pdb pair<db,db>
#define pldb pair<ldb,ldb>

#define vi vector<int>
#define vdb vector<db>
#define vldb vector<ldb>
#define vpi vector< pi >

#define mi map<int,int>
#define mdb map<db,db>
#define mldb map<ldb,ldb>


#define forr(a,b) for (int i = (a); i < (b); ++i)
#define rrof(a,b) for (int i = (b)-1; i >= (a); --i)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)

const int md = 1e9+7;
const int MX = 2e5+5;
const int INF = 1e18; 
const ldb PI = 4*atan((ldb)1);

int power_md(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res=(res%md*a%md)%md;
  a=(a%md*a%md)%md;
  n/=2;
}
res%=md;
return res;
}

int power(int a,int n)
{
 int res=1;
 while(n)
{
 if(n%2)
  res*=a;
  a=a*a;
  n/=2;
}
return res;
}

int abst(int a)
{
 return ((a<0)?(-1*a):(a));
}

class cmp_set{
public:
	bool operator() (int a, int b){
		return a > b;
	}
};

vector<string> vec_splitter(string s) {
	s += ',';
	vector<string> res;
	while(!s.empty()) {
		res.push_back(s.substr(0, s.find(',')));
		s = s.substr(s.find(',') + 1);
	}
	return res;
}
void debug_out(
vector<string> __attribute__ ((unused)) args,
__attribute__ ((unused)) int idx, 
__attribute__ ((unused)) int LINE_NUM) { cerr << endl; } 
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
	if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
	stringstream ss; ss << H;
	cerr << args[idx] << " = " << ss.str();
	debug_out(args, idx + 1, LINE_NUM, T...);
}
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
#else
#define debug(...) 42
#endif

int32_t main()
{
    int n;
    cin>>n;
    int sum=0;
    int maxn=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        maxn=max(maxn,x);
        sum+=x;
    }
    int res=sum-maxn+(maxn/2);
    cout<<res<<"\n";
     return 0;
}

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

int main() {
 	int K;
  	cin >> K;
  
  	if (K % 2 == 0) {
      cout << (K / 2)*(K / 2) << endl;
    } else {
      cout << ((K + 1) / 2) * ((K + 1) / 2 - 1) << endl;
    }
}

Measured memory_bytes: 256
/* C - Skill Up */

#include <stdio.h>

int main(void){
  int N, M, X, ans = 1e9;
  scanf("%d %d %d", &N, &M, &X);
  int C[N], A[N][M];
  for(int i = 0; i < N; i++){
    scanf("%d", &C[i]);
    for(int j = 0; j < M; j++){
      scanf("%d", &A[i][j]);
    }
  }
  /* bit全探索 */
  for(int bit = 0; bit < (1 << N); bit++){
    int money = 0, totalA[M]; // 可変長配列は = {} で初期化できない
    // 以下のように配列を初期化
    for(int j = 0; j < M; j++){
      totalA[j] = 0;
    }
    for(int i = 0; i < N; i++){
      if(bit & (1 << i)){
        money += C[i];
        for(int j = 0; j < M; j++){
          totalA[j] += A[i][j];
        }
      }
    }
    int judge = 1;
    for(int j = 0; j < M; j++){
      if(totalA[j] < X){
        judge = 0;
        break;
      }
    }
    if(judge && money < ans){
      ans = money;
    }
  }
  if(ans == 1e9){
    puts("-1");
  }else{
    printf("%d\n", ans);
  }
  return 0;
}


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

   int n;
   cin>>n;
   vector<vector<int>>v(n,vector<int>(3,0));
   for(int i=0;i<n;i++)
   {
       cin>>v[i][0]>>v[i][1]>>v[i][2];
   }
    vector<vector<int>>s(n,vector<int>(3,0));
    s[0][0] =v[0][0];
    s[0][1] =v[0][1];
    s[0][2] =v[0][2];

   for(int i=1;i<n;i++)
   {
       s[i][0] = v[i][0] + max(s[i-1][1],s[i-1][2]);
       s[i][1] = v[i][1] + max(s[i-1][0],s[i-1][2]);
       s[i][2] = v[i][2] + max(s[i-1][1],s[i-1][0]);
   }

   cout<<max(s[n-1][0],max(s[n-1][1],s[n-1][2]))<<endl;

    return 0;
}

Measured memory_bytes: 14004
#include <bits/stdc++.h>
  
int main(){
  int n, w = 0;
  std::cin>>n>>w;
  std::vector<std::vector<long> > dp(n+1, std::vector<long>(n * 100+1, 0));
  dp[0][0]=0;
  for (int i = 1; i <dp[0].size() ; ++i) {
    dp[0][i]=1000000001;
  }
  std::vector<int> iv;
  std::vector<long> iw;
  for (int i = 0; i < n; ++i) {
    int a, b = 0;
    std::cin>>a>>b;
    iv.emplace_back(a);
    iw.emplace_back(b);
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= dp[0].size(); ++j) {
      if (j < iv[i - 1]) {
        dp[i][j] = dp[i - 1][j];
      } else {
        dp[i][j] = std::min(dp[i - 1][j], dp[i - 1][j - iv[i - 1]] + iw[i - 1]);
      }
    }
  }
  int ans=0;
  for (int i = 0; i < dp[0].size(); ++i) {
    if(dp[n][i]<=w)ans=i;
  }
  std::cout<<ans<<std::endl;
  return 0;
}


Measured memory_bytes: 11124
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1001001001
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
int main() {
    int K,N;cin >> K >> N;
    vector<int> A(N);
    REP(i,N) cin >> A[i];
    sort(ALL(A));
    vector<int> d(N);
    REP(i,N-1) d[i]=A[i+1]-A[i];
    d[N-1] = A[0] + K - A[N-1];
    sort(ALL(d));
    cout << K-d[N-1] << endl;
}

Measured memory_bytes: 4880
#include <cstdio>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;

int main(void)
{
  while(1){
    int n, r;
    cin >> n >> r;
    if(n == 0 && r == 0)
      break;
    
    int card[n+1];
    for(int i = 1; i <= n; i++) card[i] = n - i + 1;
    // for(int i = 1; i <= n; i++) printf("%d ", card[i]);
    // puts("A");
    
    int shuf[n+1];
    shuf[0] = 0;
    for(int i = 1; i <= r; i++){
      int p, c;
      cin >> p >> c;
      
      for(int j = 0; j < c; j++){ // p~
	shuf[j+1] = card[p+j];
	//	printf("%d ", shuf[j+1]);
      }
      // printf("|");
      for(int j = 1; j < p; j++){ // 1~
	shuf[c+j] = card[j];
	//printf("%d ", shuf[c+j]);
      }
      // printf("|");
      for(int j = c + p; j <= n; j++){ //others
	shuf[j] = card[j];
	//printf("%d ", shuf[j]);
      }
      //puts("");
      for(int j = 1; j <= n; j++){ // copy
	card[j] = shuf[j];
      }
      for(int j = 1; j <= n; j++){
	//	printf("%d ", card[j]);
      }
      //puts("");
      
    }

    printf("%d\n", card[1]);
  }
  
  return 0;
}

Measured memory_bytes: 1144
<?php
fscanf(STDIN, "%d %d", $h, $w);
$data = array();
for ($i = 0;$i < $h;$i ++) {
	fscanf(STDIN, "%s", $str);
	$data[] = str_split($str);
}

$start = array(0,0);
$goal = array($h - 1,$w - 1);

for($i = 0;$i < $h;$i ++) {
	for($j = 0;$j < $w;$j ++) {
		$ret = judge($i, $j);
//		print("$i, $j, $ret\n");

		if($ret === 'false') {
			print("Impossible\n");
			exit;
		}
	}
}

print("Possible\n");
exit;


function judge($h, $w) {
	global $data,$goal,$start;

	if($data[$h][$w] === '.')return 'true';

	$cnt = 0;
	$t_cnt = 0;
	if(isset($data[$h + 1][$w]) && $data[$h + 1][$w] === '#')$cnt ++;
	if(isset($data[$h][$w + 1]) && $data[$h][$w + 1] === '#')$cnt ++;
	if(isset($data[$h + 1][$w]) && $data[$h + 1][$w] === '#')$t_cnt ++;
	if(isset($data[$h][$w + 1]) && $data[$h][$w + 1] === '#')$t_cnt ++;
	if(isset($data[$h - 1][$w]) && $data[$h - 1][$w] === '#')$cnt ++;
	if(isset($data[$h][$w - 1]) && $data[$h][$w - 1] === '#')$cnt ++;

	$start_flg = false;
	$goal_flg = false;
	if($h === $start[0] && $w === $start[1])$start_flg = true;
	if($h === $goal[0] && $w === $goal[1])$goal_flg = true;

	if($goal_flg === true && $cnt === 1 && $t_cnt === 0) {
		return 'true';
	} else if($start_flg === true && $cnt === 1 && $t_cnt === 1) {
		return 'true';
	} else if(($goal_flg === false && $start_flg === false ) && $cnt === 2 && $t_cnt === 1) {
		return 'true';
	} else {
		return 'false';
	}
}


print_r($data);

?>


Measured memory_bytes: 2936
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define loop(i, r, n) for (int i = (r); i < (n); i++)
#define pb push_back
#define all(in) in.begin(),in.end()

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

using ll = long long;
using ull = unsigned long long;
using namespace std;

ll n, k;
ll a[500];

bool check(ll div){
    vector<ll> b(n);
    rep(i,n) b[i] = a[i]%div; sort(all(b));
    vector<ll> sum1(n+1,0), sum2(n+1,0);
    rep(i,n) sum1[i+1] = sum1[i] + b[i];
    rrep(i,n) sum2[i] = sum2[i+1] + (div-b[i])%div;
    bool res = false;
    rep(i,n+1) if(sum1[i] <= k && sum2[i] <= k) { res = true; break; }
    return res;
}

int main(){
    cin >> n >> k;
    rep(i,n) cin >> a[i];
    ll sum = 0; rep(i,n) sum += a[i];
    ll ans = 1;
    for(ll i = 1; i*i <= sum; i++){
        if(sum%i == 0){
            if(check(sum/i)) { chmax(ans,sum/i); break; }
            if(check(i)) chmax(ans,i);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    int X, Y;
    cin >> X >> Y;
    bool possible = false;
    for (int i = 0; i < X + 1; i++) {
        int c = i;
        int t = X - i;
        if (c * 2 + t * 4 == Y) {
            possible = true;
            break;
        }
    }
    string ans = (possible == true)?"Yes":"No";
    cout << ans << endl;
}

Measured memory_bytes: 3620
import sys
input = sys.stdin.readline

L=int(input())
A=[int(input()) for i in range(L)]
            
SUM=[0]
for a in A:
    SUM.append(SUM[-1]+a)

def div2(x):
    if x==0:
        return 2
    else:
        return x%2
    
DP0=[0]*(L+1)
DP1=[0]*(L+1)
DP2=[0]*(L+1)
DP3=[0]*(L+1)
DP4=[0]*(L+1)

for i in range(L):
    DP0[i]=DP0[i-1]+A[i]
    DP1[i]=min(DP0[i-1]+div2(A[i]),DP1[i-1]+div2(A[i]))
    DP2[i]=min(DP2[i-1]+(A[i]+1)%2,DP1[i-1]+(A[i]+1)%2,DP0[i-1]+(A[i]+1)%2)
    DP3[i]=min(DP3[i-1]+div2(A[i]),DP2[i-1]+div2(A[i]),DP1[i-1]+div2(A[i]),DP0[i-1]+div2(A[i]))
    DP4[i]=min(DP4[i-1]+A[i],DP3[i-1]+A[i],DP2[i-1]+A[i],DP1[i-1]+A[i],DP0[i-1]+A[i])

print(min(DP0[L-1],DP1[L-1],DP2[L-1],DP3[L-1],DP4[L-1]))


Measured memory_bytes: 61660
#!/usr/bin/perl
use Data::Dumper;

my ($h,$w,$k) = map { $_ - 0 } split(/\s+/,<STDIN>);

my @s = ();
for(my $i=0;$i<$h;$i++){
  my $s1 = scalar(<STDIN>);
  push(@s,$s1);
}

my $h2 = 2 ** $h;
my $w2 = 2 ** $w;

my $res = 0;
for(my $i=0;$i<$h2;$i++){
  for(my $j=0;$j<$w2;$j++){
    my $c1 = 0;
    my $ybit = 1;
    for(my $y=0;$y<$h;$y++){
      if( ( $ybit & $i ) != 0 ){
        my $xbit = 1;
        for(my $x=0;$x<$w;$x++){
          if( ( $xbit & $j ) != 0 ){
            $c1 += ( substr($s[$y],$x,1) eq '#' ? 1 : 0 );
          }
          $xbit += $xbit;
        }
      }
      $ybit += $ybit;
    }
    $res ++ if( $c1 == $k );
  }
}

print "$res\n";


Measured memory_bytes: 6360
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

class Main {
    public static void main(String[] args){
        try{
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            double pi=3.14159;
            System.out.println(2*pi*t);


        }catch(Exception e){
            System.out.println("KKKK "+e.getMessage());
        }
    }
    static boolean check(int[] arr){
        int odd=0;
        for(int i=0;i<arr.length;i++){
            if(arr[i]%2!=0){
                odd++;
            }
        }
        if(odd<=1){
            return true;
        }
        return false;
    }
}

Measured memory_bytes: 33288
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Vec2(T, n, m, xs, x0) vector<vector<T>> xs(n, vector<T>(m, x0))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n, a, b);
    Cout(((b-a) % 2 == 0) ? "Alice" : "Borys");
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

#define rep(i, N) for (int i = 0; i < N; i++)

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

double solve(int x, double P) {
	return (double)x / 2 / P;
}

int main() {
	int x, p; cin >> x >> p;
	double P = p / 100.0;
	double ans;
	if (x % 2 == 0) ans = solve(x, P);
	else ans = 1 + P * solve(x - 1, P) + (1 - P) * solve(x + 1, P);
	printf("%.15f\n", ans);
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <functional>
#include <climits>
#include <cstring>

using namespace std;

#define int long long
#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 range(i, l, r) for (int i=l;i<(int)(r);++i)
#define rrange(i, l, r) for (int i=r-1;i>=(int)(l);--i)
#define unless(a) if(!(a))
#define all(a) begin(a),end(a)
#define fst first
#define scd second
#define PB emplace_back
#define PPB pop_back

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

bool chmin(int&a,int b){return a>b?(a=b,true):false;}
bool chmax(int&a,int b){return a<b?(a=b,true):false;}
int read(){int a;scanf("%lld",&a);return a;}

int N;

signed main()
{
	cin >> N;
	vi A(N);
	rep(i, N) cin >> A[i];

	int l = 0, r = 0; // [l, r]

	int Xor = A[0], Sum = A[0]; // [l, r) の xor, sum;

	int ans = 0;

	while (l < N) {
		while (r + 1 < N and (Xor ^ A[r + 1]) == (Sum + A[r + 1])) {
			Xor ^= A[r + 1];
			Sum += A[r + 1];
			r++;
		}

		int len = r - l + 1;

		ans += len;

		Xor ^= A[l];
		Sum -= A[l];
		
		l++;
	}

	cout << ans << endl;
}




Measured memory_bytes: 4816
/*
 * Binary Search.c
 *
 *  Created on: 2015/02/15
 */

#include <stdio.h>

int S[100000]={0},T[50000]={0};


//void printarray(int a[],int n){
//	int i;
//	for(i=0;i<n;i++){
//		printf("%d ",a[i]);
//	}printf("\n");
//}

int main(){
	int n,q;
	int i,j,counter=0;
	int start,end;

	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&S[i]);
	}

	scanf("%d",&q);
	for(j=0;j<q;j++){
		scanf("%d",&T[j]);
	}


	for(i=0;i<q;i++){

		start=0,end=n;

		while(start < end){
			int middle = (start + end) / 2;

			if(S[middle] > T[i]){
				end = middle;
			}
			else if(S[middle] < T[i]){
				start = middle + 1;
			}
			else if(S[middle] == T[i]){
				counter++;
				break;
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
#define boost ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define M 1000000007
#define eb emplace_back
#define watch(x) cout << (#x) <<" is "<< x <<"\n";


using namespace std;
//const int N = 1e6;

int32_t main(){
  boost;
  int tc = 1; //cin >> tc;
  while(tc--)
  {
    int n; cin >> n;
    map<int, int>mp;
    int sum = 0;
    for(int i=1; i<100; i++)
    {
      for(int j=1; j<100; j++)
      {
        for(int k=1; k<100; k++)
        {
          sum = (i*i)+(j*j)+(k*k);
          sum += (i*j)+(j*k)+(i*k);
          mp[sum]++;
        }
      }
    }
    for(int i=1; i<=n; i++)
    {
      cout << mp[i] <<"\n";
    }
  }
}



Measured memory_bytes: 5944
#include<iostream>
#include<cstdio>
#include<map>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(void)
{
  int n;
  char c;
  string s;
  vector<string> v;
  map<string, int> m;
  vector<pair<int, string> > vv;

  while(cin >> n, n){
    v.clear(); vv.clear(); m.clear();
    for(int i = 0;i < n; ){
      cin >> s;
      if(!m[s]){
	m[s]--;
	v.push_back(s);
      } else {
	m[s]--;
      }
      if(getchar() == '\n') i++;
    }

    cin >> c;
    for(int i = 0;i < v.size(); i++){
      if(v[i][0] == c)
	vv.push_back(make_pair(m[v[i]], v[i]));
    }
    sort(vv.begin(), vv.end());

    if(vv.size() == 0)
      cout << "NA" << endl;
    else{
      cout << vv[0].second;
      for(int i = 1;i < 5 && i < vv.size(); i++)
	cout << ' ' << vv[i].second;
      cout << endl;
    }
  }
}


Measured memory_bytes: 1224
#include <iostream>
#include <algorithm>
using namespace std;
int q,h,s,d,n;
int main(){
	cin>>q>>h>>s>>d>>n;
	cout<<1ll*min(min(q*8,h*4),min(s*2,d))*(n/2)+min(min(q*4,h*2),s)*(n&1)<<endl;
	return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)
#define repr(i, n) for(int i = (n-1); i >= 0; --i)

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

const int MAX = 200005;
const int INF = 1001001001;
const int MOD = 1000000007;

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    vector<string> c(H);
    for (auto &i : c) cin >> i;

    int ans = 0;
    rep(i, 1 << H)rep(j, 1 << W) {
        int cnt = 0;
        rep(y, H)rep(x, W) {
            if (c[y][x] == '#' && ((i >> y & 1) && (j >> x & 1))) cnt++;
        }
        if (cnt == K) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3620
#include<iostream>

using namespace std;

int main(){
	int n, m, ans = 1;
	cin >> n >> m;
	if(n == 1){
		ans = m;
	}else{
		for(int i = 2; n * i <= m; i++){
			if((m - n * i) % i == 0){
				ans = i;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from collections import deque 
def main():
    N, Q = map(int, readline().split())
    to = [[] for _ in range(N)]
    for _ in range(N-1):
        a, b = map(int, readline().split())
        a -= 1
        b -= 1
        to[a].append(b)
        to[b].append(a)
    score = [0 for  _ in range(N)]
    for _ in range(Q):
        p, x = map(int, readline().split()) 
        p -= 1
        score[p] += x  
    
    dq = deque() 
    dq.append(0)
    done = [0 for _ in range(N)]
    done[0] = 1

    while len(dq)>0:
        v = dq.popleft()
        for nx in to[v]:
            if done[nx]:
                continue
            score[nx] += score[v]
            done[nx] = 1
            dq.append(nx)
    for i in range(N):
        if i==N-1:
            print(score[i])
        else:
            print(score[i], end=' ')
if __name__ == '__main__':
    main()


Measured memory_bytes: 53000
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <memory>

#define int long long

using namespace std;

int gcd(int a, int b) {
	if (a < b) swap(a, b);
	if (a % b == 0) return b;
	return gcd(a % b, b);
}

void Main()
{
	int k;
	cin >> k;

	int ans = 0;
	for (int a = 1; a <= k; a++) {
		for (int b = 1; b <= k; b++) {
			int gcd_ab = gcd(a, b);
			for (int c = 1; c <= k; c++) {
				ans += gcd(gcd_ab, c);
			}
		};
	}

	cout << ans << endl;
}

int32_t main()
{
	Main();
	return 0;
}



Measured memory_bytes: 3620
#複数の整数入力を受け付ける関数
def datain(num):

    data = []
    iscnt = True

    while iscnt:
        for val in map(int,input().split()):
            data.append(val)
            if len(data) == num:
                iscnt = False
                break
        
    return data

data = datain(2)
ans = 0

for x in range(data[0]+1):
    for y in range(data[0]+1):
        #print(x,y,data[1]-x-y)
        if data[0] >= data[1]-x-y >= 0:
            ans += 1

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (__typeof(a) i=(a); i<(b); ++i)
#define iter(it,c) for (__typeof((c).begin()) \
		  it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
return (a % b + b) % b; }


int main()
{
    int n, m;
    cin >> n >> m;
    vvi adj(n);
    rep(i,0,m)
    {
        int a, b;
        cin >> a >> b;
        a--,b--;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }

    int start = 0;
    queue<int> q;
    q.push(start);
    vi back(n, -1);
    back[start] = start;

    while(!q.empty())
    {
        int at = q.front(); q.pop();
        iter(it, adj[at])
        {
            if(back[*it] == -1)
            {
                back[*it] = at;
                q.push(*it);
            }
        }
    }

    cout << "Yes" << endl;
    rep(i,1,n)
    {
        cout << back[i]+1 << endl;
    }

    return 0;
}


Measured memory_bytes: 10088
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <functional>
#include <map>
#include <set>
#define REP(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long

using namespace std;
 
typedef pair<int, int> P;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main () {
  int n;
  scanf("%d", &n);

  int m = (n % 2 == 0) ? (n / 2) : ((n+1) / 2);
  double ans = (double)m / (double)n;

  printf("%.10f\n", ans);  
}

Measured memory_bytes: 764
/*
 * src.cpp
 *
 *  Created on: 2016/08/08
 *      Author: joi
 */

#include <bits/stdc++.h>

using namespace std;

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

char N[5];

char L[5],S[5];
char g[5]="6174";

void itoa(int x){
	REP(i,4){
		N[3-i]=x%10+'0';
		x/=10;
	}
}

bool isend(){
	REP(i,4){
		if (N[i]!='0'){
			return false;
		}
	}
	return true;
}

bool isNA(){
	char c=N[0];
	FOR(i,1,4){
		if (N[i]!=c){
			return false;
		}
	}
	return true;
}

int main(){
	do{
		scanf("%s",N);
		if (!isend()){
			if (isNA()){
				printf("NA\n");
			}else{
				int ans=0;
				while (strcmp(N,g)){
					strcpy(L,N);
					strcpy(S,N);
					sort(L,L+4);
					reverse(L,L+4);
					sort(S,S+4);
					itoa(atoi(L)-atoi(S));
					ans++;
				}
				printf("%d\n",ans);
			}
		}
	}while (!isend());
	return 0;
}

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

int main(){
    int n, m = 0, a;
    int num[105];
    cin >> n;
    int las = -1;
    for(int i = 0; i < n; i++){
        cin >> a;
        if(a == las){
            num[m-1] ++;
        }
        else{
            num[m++] = 1;
            las = a;
        }
    }
    int res = 0;
    for(int i = 0; i < m; i++) res += num[i] / 2;
    cout << res;

}

Measured memory_bytes: 256
M, D = map(int, input().split())

c = 0
for m in range(1, M+1):
  for d in range(1, D+1):
    d10 = d//10
    d1 = d - (d//10 * 10)
    # print(m, d10, d1)
    if d10 * d1 == m:
      if d1 >= 2 and d10 >= 2:
        c += 1
        # print(m, d)

print(c)

Measured memory_bytes: 2940
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int i=0;
    	int n;
    	for(;;i++){
    		n=Integer.parseInt(sc.next());
    		if(n==0){
    			break;
    		}
    		System.out.println("Case "+(i+1)+": "+n);
    	}
    	
    }
}


Measured memory_bytes: 40424
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;

int dp[(int)1e5 + 99];

int f(int u, vector<vi> &g) {
    int &res = dp[u];
    if(res != -1)return res;
    int w = sz(g[u]);
    res = w;
    vi a(w);
    rep(i, w) {
        a[i] = f(g[u][i], g);
    }
    sort(all(a), greater<int>());
    rep(i, w) {
        smax(res, i + 1 + a[i]);
    }
    return res;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n; 
    vi a(n + 1);
    vector<vi> g(n + 1);
    MEM(dp, -1);
    for(int i=2;i<=n;++i) {
        cin >> a[i];
        g[a[i]].push_back(i);
    }

    int ans = f(1, g);
    cout << ans << endl;
}


Measured memory_bytes: 18944
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;


	public class Main {
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int k = sc.nextInt();
			int[] d = new int[k];
			Set<Integer> a = new HashSet<Integer>();
			
			for(int i=0;i<k;i++) {
				d[i] = sc.nextInt();
				for(int j=0;j<d[i];j++) {
					a.add(sc.nextInt());
				}
			}
			
			System.out.println(n-a.size());
		}
		
		
	}


Measured memory_bytes: 46180
max = ""
a = ('a'..'z').to_a


n = gets.to_i
S = Array.new(n)
for i in 0..n-1
  S[i] = gets.split("").sort
end

for i in 0..a.size-1
  min = 50
  for j in 0..n-1
    num = 0
    for k in 0..S[j].size-1
      if S[j][k] == a[i]
        num += 1
      end
    end
    if num < min
      min = num
    end
  end
  min.times do
    max += a[i]
  end
end

puts max

Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define SORT(i) sort((i).begin(),(i).end())
#define INF 2000000000
constexpr ll mod = 1000000007;

int main() {
	int N;
	cin >> N;
	vector<ll>A(N);
	for (int i = 0;i < N;++i) {
		cin >> A[i];
	}
	ll ans = 0;
	for (int i = 0;i < N;++i) {
		for (int j = 0;j < N;++j) {
			ans = max(ans, abs(A[i] - A[j]));
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
using namespace std;
int n,c=0;
long long a,b,ans[2];
priority_queue<long long> pq;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a;
		pq.push(a);
	}
	
	while(!pq.empty())
	{
		a=pq.top(); 
		  pq.pop();
		b=pq.top();
		
		if(a==b)
		{
			ans[c]=a;
			c++;
			pq.pop();
		}
		
		if(pq.size()==1||c==2)
		break;
	}
	
	if(c==2)
	{
		long long area=ans[0]*ans[1];
	
		cout<<area;
	}
	else
	{
		cout<<"0";
	}
	
}

Measured memory_bytes: 1400
import sys
input = sys.stdin.readline

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

    l = [0 for i in range(N)]
    l[0] = a[0]

    for i in range(1, N):
        l[i] = l[i-1] + a[i]
    ans = int(1e15)
    for i in range(N):
        ans = min(ans, abs(l[-1] - l[i] * 2))
    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 26216
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <cmath>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int n, d[110000];
    cin >> n;

    rep(i,n) cin >> d[i];

    sort(d, d+n);
    int frontmax = d[n/2-1];
    int backmin = d[n/2];

    cout << backmin-frontmax << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
using namespace std;
int main()
{
    int health_T,health_A,strength_T,strength_A;
    cin>>health_T>>strength_T>>health_A>>strength_A;
    do{
        health_A-=strength_T;
        if(health_A<=0){
            cout<<"Yes";
            break;
        }
        health_T-=strength_A;
        if(health_T<=0){
            cout<<"No";
            break;
        }
    } while(health_A>0 || health_T>0);
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
using ll = long long;
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=int(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
const ll mod = 1000000007;

using namespace std;
int main() {
int N;
	cin >> N;
	map<long long, long long> mp;
	REP(i, N) {
		int n; cin >> n;
		mp[n]++;
	}
	int ans = 0;
	for (std::map<long long, long long>::iterator e = mp.begin(); e!=mp.end(); ++e){
		if(e->second%2!=0) ans++;
	}
	cout << ans << endl;
		return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;


int main(){
 int n,m,i,a,sum=0;
 cin>>n>>m;
 for(i=0;i<m;i++){
   cin>>a;
   sum=sum+a;
 }
 if(sum>n){
   cout<<-1;
 }
 else{
   cout<<n-sum;
 }
 return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n ,k;
  cin >> n >> k;
  vector<int> vec(n);
  
  for(int i = 0; i < n; i++){
    cin >> vec.at(i);
  }
  
  sort(vec.begin(),vec.end());
  
  int S = 0;
  for(int i = 0; i < k; i++){
    S += vec.at(i);
  }
  cout << S << endl;
}

Measured memory_bytes: 3596
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define ub(v,val) upper_bound(v.begin(),v.end(),val)-v.begin()
#define lb(v,val) lower_bound(v.begin(),v.end(),val)-v.begin()
#define sortv(vec) sort(vec.begin(),vec.end())
#define v vector
#define PI 3.1415926535
#define len length()
#define repc(i,s,e) for(ll i=s;i<e;i++)
#define fi first
#define se second
#define mt make_tuple
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define rep(i,n) for(ll i=0;i<n;i++)
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int M = 1e9+7;
int ll_max=1e6;
v<ll> fact;
//factorial
void factorial(ll n)
{
    fact[0] = 1;
    for (ll i = 1; i <=n; i++)
    {
        fact[i] = i * fact[i - 1];
        fact[i] %= M;
    }
}
// modular exponentiation 
ll binpow(ll val, ll deg)
{
    if (!deg)
        return 1 % M;
    if (deg & 1)
        return binpow(val, deg - 1) * val % M;
    ll res = binpow(val, deg >> 1);
    return (res * res) % M;
}
//combination
ll C(ll n, ll i)
{
    if(n<i) return 0;      
    ll res = fact[n]; 
    ll div = fact[n - i] * fact[i];
    div %= M;
    // using fermat little theorum
    div = binpow(div, M - 2); // modular inverse  
    return (res * div) % M; 
}
int main() {
	//your code goes here
	IOS;
	ll n,m;       
	ll j,y,z,k,b,x,t,i;      
	 cin>>n;
	 ll a[n];
	 rep(i,n) cin>>a[i];
	 sort(a,a+n,greater<ll>());
	 ll sum=0;
	 k=n-1;
	 i=0;
	 while(k>0){
	       if(k==n-1){
	             sum+=a[i];
	             i++;
	             k--;
	       }
	       else{
	             k--;
	             sum+=a[i];
	             if(k>0){
	                   k--;
	                   sum+=a[i];
	             }
	             i++;
	       }
	 }
	 cout<<sum;
	return 0;
}

Measured memory_bytes: 5216