akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 1e10
#define mod 1000000007
typedef long long int ll;
ll z(ll a){
  if(a<0)a*=-1;
  return a;
}
int u(const void *a, const void *b){
    return *(ll*)a-*(ll*)b;
}
int d(const void *a, const void *b){
    return *(ll*)b-*(ll*)a;
}
int min(int a,int b){
  if(a>b)return b;
  return a;
}
int max(int a,int b){
  if(a>b)return a;
  return b;
}
ll gcd(ll a,ll b){
  if(!b)return a;
  return gcd(b,a%b);
}
int kt(ll a){
  int sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
int ks(ll a){
  int sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
int main(void){
  int n;
  scanf("%d",&n);
  ll a[n],b[n],sum=0;
  FOR(n){
    scanf("%lld",&a[i]);
    b[i]=a[i]-(i+1);
  }
  qsort(b,n,sizeof(ll),u);
  FOR(n)sum+=abs(b[i]-b[(n-1)/2]);
  PRL(sum);
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int N = 8005;
bool dp[N][N];

bool isPossible(vector<int> v, int x){
	int n = v.size();
	memset(dp, false, sizeof(dp));
	dp[0][0] = true;
	for(int i = 1; i <= n; i++){
		for(int prev = 0; prev < N; prev++){
			if(prev + v[i - 1] < N)dp[i][prev + v[i - 1]] |= dp[i - 1][prev];
			if(prev >= v[i - 1])dp[i][prev - v[i - 1]] |= dp[i - 1][prev];
		}
	}
	return dp[n][x];
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	string s;
	cin>>s;
	int x, y;
	cin>>x>>y;
	vector<int> vx, vy;
	for(auto ch : s){
		if(ch == 'T'){
			if(vx.size() == vy.size())vy.push_back(0);
			else vx.push_back(0);
		}else if(vy.empty()){
			x--;
		}else if(vy.size() == vx.size()){
			vx.back()++;
		}else{
			vy.back()++;
		}
	}
	x = abs(x);
	y = abs(y);
	if(isPossible(vx, x) && isPossible(vy, y))cout<<"Yes\n";
	else cout<<"No\n";

	return 0;
}

Measured memory_bytes: 62976
import sys

mod = 10**9 + 7
S = sys.stdin.readline().strip()

S = S[::-1]
ls = len(S)
dp = [0] * 13
dp[0] = 1
for i in range(ls):
    ndp = [0] * 13
    # print("S", S[i])
    for j in range(13):
        if dp[j] == 0:
            continue
        digit = pow(10, i, 13)
        if S[i] == "?":
            for k in range(10):
                r = k * digit + j
                r %= 13
                ndp[r] += dp[j]
                ndp[r] %= mod

        else:
            n = int(S[i])
            r = n * digit + j
            r %= 13
            ndp[r] += dp[j]
            ndp[r] %= mod

    # print(ndp)
    dp = ndp

print(dp[5])

Measured memory_bytes: 74140
#include <bits/stdc++.h>
using namespace std;
long long us[100001],n,k,l,r,gam,ans,jerr,nas=1000000000+7;
int axa(long long n, long long x)
{
   
    if(x==1)
    {
        return n;
    }
    long long ret,save=axa(n, x/2);
    if(x%2==1)
    {
        ret=(save*save)%nas*n;

    }
    else
    {
        ret=(save*save)%nas;
    }
    ret%=nas;
    return ret;
}
int main() 
{
  cin>>n>>k;
  for(int i=k;i>=1;i--)
  {
      jerr=k/i;
      us[i]=axa(jerr,n);
      l=i+i;
      while(l<=k)
      {
          us[i]-=us[l];
          l+=i;
          us[i]%=nas;
          us[i]=(us[i]+nas)%nas;
      }
  }
  for(int i=1;i<=k;i++)
  {
      ans+=us[i]*i;
      ans%=nas;
  }
  cout<<ans;
}

Measured memory_bytes: 4424
<?php
fscanf(STDIN, '%d', $n);
fscanf(STDIN, '%s', $slimes);

$splited_slimes = str_split($slimes);
$fuioned_splited_slimes = $splited_slimes;
$prev = '';
foreach ($splited_slimes as $key => $slime) {
  if ($prev == $slime) {
    unset($fuioned_splited_slimes[$key]);
  }
  $prev = $slime;
}

echo count($fuioned_splited_slimes);

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

inline void cmin(int&x, const int&y) {if(x > y) x = y;}
inline void cmax(int&x, const int&y) {if(x < y) x = y;}
inline void cmin(ll&x, const ll&y) {if(x > y) x = y;}

inline void read(int&x){
	char c11=getchar();x=0;while(!isdigit(c11))c11=getchar();
	while(isdigit(c11))x=x*10+c11-'0',c11=getchar();
}

const int N = 201000, Inf = 1e9;

struct node {
	int x, y;
	friend inline bool operator < (const node&A,const node&B)
		{return A.x != B.x ? A.x < B.x : A.y  < B.y;}
}p[N];

int min_x, min_y;
int max_x, max_y;
int n;

int main(){
	read(n);
	min_x = min_y = Inf;
	max_x = max_y = 0;
	for(int i=1,x,y;i<=n;++i) {
		read(x), read(y);
		if(x > y) swap(x, y);
		p[i].x = x, p[i].y = y;
		cmin(min_x, x), cmax(max_x, x);
		cmin(min_y, y), cmax(max_y, y);
	}
	sort(p+1,p+n+1);
	ll ans = (ll)(max_x - min_x) * (max_y - min_y);
	int mi = Inf, mx = p[n].x;
	for(int i=1;i<=n;++i){
		if(i != 1) cmin(ans, (ll)(max_y - min_x) * (mx - min(p[i].x, mi)));
		cmax(mx, p[i].y), cmin(mi, p[i].y);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main(void)
{
  int count = 0;
  cin >> count;
  double sum_yen = 0;
  double sum_bit = 0;
  for (int i = 0; i < count; i++)
  {
    double x;
    string u;
    cin >> x >> u;
    if (u == "JPY")
      sum_yen += x;
    else
    {
      sum_bit += x;
    }
  }
  double sum = sum_yen + sum_bit * 380000;
  cout << sum;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  int N, M; cin >> N >> M;

  bool O_graph[N][N];

  for (int i = 0; i < N; i++){
    for (int j = 0; j < N; j++){
      O_graph[i][j] = false;
    }
  }

  vector <pair<int, int> > node(M);
  for (int i = 0; i < M; i++){
    int A, B; cin >> A >> B;
    A--; B--;
    node[i] = make_pair(A, B);
    O_graph[A][B] = true;
    O_graph[B][A] = true;
  }
  
  int ans = 0;
  for (int i = 0; i < M; i++){
    bool graph[N][N];
    
    for (int j = 0; j < N; j++){
      for (int k = 0; k < N; k++){
        graph[j][k] = O_graph[j][k];
      }
    }
    
    graph[node[i].first][node[i].second] = false;
    graph[node[i].second][node[i].first] = false;

    bool check[N];
    for (int j = 0; j < N; j++) check[j] = false;

    queue <int> que;
    que.push(0); check[0] = true;

    while(!que.empty()){
      int edge = que.front(); que.pop();

      for (int j = 0; j < N; j++){
        if (graph[edge][j] == true){
          if (check[j] == false){
            check[j] = true;
            que.push(j);
          }
        }
      }
    }

    int cnt = 0;
    for (int j = 0; j < N; j++){
      if(check[j] == true) cnt++;
    }
    
    if (cnt != N) ans++;

  }
  
  cout << ans << endl;

  return 0;
}


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

/*int main(){
    int d,c;
    cin>>d>>c;
    cout<<d*c<<endl;
    return 0;
}*/
int main(){
    int a,b,c,d,e,f;
    cin>>a>>b>>c>>d>>e>>f;
    if(a+5*b+10*c+50*d+100*e+500*f>=1000)
        cout<<"1"<<endl;
    else
        cout<<"0"<<endl;
    return 0;    
}

Measured memory_bytes: 1156
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<map>
using namespace std;

typedef long long ll;
typedef pair<int,int> P;
#define INF = 100000010

int main(){
    int N;
    cin >> N;
    int a[N];
    for(int i=0;i<N;i++){
        cin >> a[i];
    }
    int now=1;
    for(int i=0;i<N;i++){
        if(a[i]==now){
            now++;
        }
    }
    if(now>1) cout << N-(now-1) << endl;
    else cout << -1 << endl;
    return 0;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define REP(i,b,n) for(int i=b;i<(int)n;i++)
#define rep(i,n) REP(i,0,n)
#define all(obj) (obj).begin(),(obj).end()
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  ll tot=0;
  for(int i=1;i<=n;i++){
    if(i%3!=0&&i%5!=0)tot+=i;
  }
  cout<<tot<<endl;

  return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main(void){
	
	int a,b;
	
	scanf("%d %d", &a,&b);
	
	if(a < b) {
		printf("a < b\n");
	}
	else if(a > b){
		printf("a > b\n");
	}
	else{
		printf("a == b\n");
	}
	

return 0;
}

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

int main()
{int a,b,c,d,ctr=1;
  cin>>a>>b>>c>>d;

  while(a>0&&c>0)
  {
    if(ctr%2!=0)
      c=c-b;
    else
      a=a-d;
    ctr++;
    
  }

  if(a>0)
    cout<<"Yes";
  else
    cout<<"No";


  return 0;
}


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

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

    int a = n.size(), b = 0;
    for (int i = 0; i < a; i++) {
        b += n[i] -'0';
    }
    cout << (b%9 == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3708
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
int x[100];
int main()
{
	int num;
	scanf("%d", &num);
	for (int i = 0;; i++)
	{
		if (num < (1 << i))
		{
			printf("%d\n", 1 << (i - 1));
			return 0;
		}
	}
}

Measured memory_bytes: 256
while True:
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        break;
    for i in range(0, a):
        if i % 2 == 0:
            print(("#." * int((b + 1) / 2))[:b])
        else:
            print((".#" * int((b + 1) / 2))[:b])
    print("")

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

using i32 = int_fast32_t;
using i64 = int_fast64_t;

int main() {
    i32 n;
    cin >> n;
    vector<i32> ans(n);
    for (i32 i = 0; i < n-1; i++) {
        i32 a;
        cin >> a, a--;
        ans[a]++;
    }

    for (auto& e : ans) cout << e << endl;
}


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


int getRank( vector<int> flowers ){
  // 要素数が1
  if( flowers.size() == 1){
    return flowers.at(0);
  }
  
  // 左端が0
  if( flowers.at(0) == 0){
    vector<int> rights(flowers.size() - 1);
    for(int i = 0; i < rights.size(); i++){
      rights.at(i) = flowers.at(i + 1);
    }
    
    return getRank(rights);
  }
  
  // 右端が0
  if( flowers.at(flowers.size() - 1) == 0){
    vector<int> lefts(flowers.size() - 1);
    for(int i = 0; i < lefts.size(); i++){
      lefts.at(i) = flowers.at(i);
    }
    
    return getRank(lefts);
  }  


  bool include0 = false;
  int point0;
  for( int i = 0; i < flowers.size(); i++){
    if(flowers.at(i) == 0){
      include0 = true;
      point0 = i;
      break;
    }
  }

  // 内部に0が存在しなければ1回水をやり、再帰
  if(!include0){
    for( int i = 0; i < flowers.size(); i++){    
      flowers.at(i)--;
    }
    return 1 + getRank(flowers);
  }
  else{
    // 内部に0が存在すれば、左右に分けて再帰
    vector<int> lefts(point0);
    vector<int> rights(flowers.size() - point0 - 1);
    
    for(int i = 0; i < lefts.size(); i++){
      lefts.at(i) = flowers.at(i);
    }
    for(int i = 0; i < rights.size(); i++){
      rights.at(i) = flowers.at(point0 + 1 + i);
    }
    
    return getRank(lefts) + getRank(rights);
  }
  
}


int main() {
  int N;
  cin >> N;
  vector<int> h(N);
  for (int i = 0; i < N; i++) {
    cin >> h.at(i);
  }

  cout << getRank(h) << endl;
  
}


Measured memory_bytes: 384
#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; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    vector<int> A(3); cin >> A[0] >> A[1] >> A[2];

    sort(ALL(A));

    int ans = 0;
    ans += (A[2]-A[0])/2;
    A[0] = A[0] + ((A[2]-A[0])/2)*2;

    ans += (A[2]-A[1])/2;
    A[1] = A[1] + ((A[2]-A[1])/2)*2;

    sort(ALL(A));

    if(A[0]==A[1] && A[1]==A[2]) cout << ans << endl;
    else if (A[0]==A[1] && A[1]!=A[2]) cout << ans+1 << endl;
    else cout << ans+2 << endl;

    return 0;
}

Measured memory_bytes: 3624
#[cfg(test)]
#[macro_use]
extern crate contest;

use std::fmt::Debug;
use std::io::{self, Bytes, Read, Stdin, StdinLock};
use std::str::{self, FromStr};

fn main() {
    let stdin = io::stdin();
    let mut sc = StdinScanner::new(&stdin);
    let n = sc.next();
    let result = solve(sc.vec(n));
    println!("{} {}", result.0, result.1);
}


fn solve(a: Vec<usize>) -> (usize, usize) {
    let mut colors = [false; 8];
    let mut num_rainbows = 0;
    for &v in &a {
        if v >= 3200 {
            num_rainbows += 1;
        } else {
            colors[v / 400] = true;
        }
    }
    let min = colors.into_iter().filter(|x| **x).count();
    (if min == 0 { 1 } else { min }, min + num_rainbows)
}


#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        assert_eq_in_time!(1000, "", "");
    }
}


struct StdinScanner<'a> {
    buf: Vec<u8>,
    bytes: Bytes<StdinLock<'a>>,
}


#[allow(dead_code)]
impl<'a> StdinScanner<'a> {
    fn new(stdin: &'a Stdin) -> Self {
        StdinScanner {
            buf: Vec::with_capacity(256),
            bytes: stdin.lock().bytes(),
        }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut c = self.bytes.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = self.bytes.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = self.bytes.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug,
              <C as FromStr>::Err: Debug
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


trait PrintYn {
    fn print_yn(self, yes: &str, no: &str);
}

impl PrintYn for bool {
    fn print_yn(self, yes: &str, no: &str) {
        println!("{}", if self { yes } else { no });
    }
}


Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
	int c_score;
	int highscore[3];
	int i,j,k,u;
	for(u = 0; u < 2; u++){
		for(i = 0; i < 3; i++){
			highscore[i] = -1;
		}
		for(i = 0; i < 10; i++){
			scanf("%d",&c_score);
			for(j = 0; j < 3; j++){
				if(c_score > highscore[j]){
					for(k = 1; k >= j; k--){
						highscore[k+1] = highscore[k];
					}
					highscore[j] = c_score;
					break;
				}
			}
		}
		if(u == 0){
			printf("%d ",highscore[0] + highscore[1] + highscore[2]);
		}else{
			printf("%d\n",highscore[0] + highscore[1] + highscore[2]);
		}
	}

	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;

const int INF = 1<<25;
int path[200][200] = {};

int main(){
    for(int i = 0; i < 200; i++){
        for(int j = 0; j < 200; j++){
            if(i == j)  continue;
            path[i][j] = INF;
        }
    }

    int n, m, R;
    cin >> n >> m >> R;
    
    int r[R];
    for(int i = 0; i < R; i++)  cin >> r[i];
    for(int i = 0; i < R; i++)  r[i]--;
    sort(r, r+R);

    int a, b, c;
    for(int i = 0; i < m; i++){
        cin >> a >> b >> c;
        a--; b--;
        path[a][b] = path[b][a] = c;
    }

    for(int k = 0; k < n; k++){
        for(int i = 0; i < n; i++){
            for(int j = 0; j < n; j++){
                if(path[i][k] == INF || path[k][j] == INF)  continue;
                path[i][j] = min(path[i][j], path[i][k] + path[k][j]);
            }
        }
    }

    int ans = INT_MAX;
    do{
        int tmp = 0; bool connected = true;
        for(int i = 0; i < R-1; i++){
            if(path[r[i]][r[i+1]] == INF)   connected = false;
            else   tmp += path[r[i]][r[i+1]];
        }
        if(connected)   ans = min(ans, tmp);
    }while(next_permutation(r, r+R));

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 384
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
using namespace std;

// 插入此處

int main() {
    int a[105];
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    sort(a, a + n);
    printf("%d\n", a[n-1] - a[0]);
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define mx 100000
#define ll long long int
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll sum=0;
    int n,x,y;
    cin>>n;
    cin>>x;
    sum=sum+x;
    n=n-2;
    y=x;
    while(n--)
    {
        cin>>x;
        sum=sum+min(x,y);
        y=x;
    }
    sum+=y;
    cout<<sum<<endl;
    return 0;
}


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

string f(long long n){
  if(n == 0){
    return "";
  }
  
  n--;
  return f(n/26) + string(1, 'a'+n%26);
}

int main(){

  long long n;
  cin >> n;
  
  cout << f(n) << endl;
  
  return 0;
}

Measured memory_bytes: 3588
length = input()

values = input().split()
for i in range(len(values)):
  values[i] = int(values[i])
values.sort()

for i in range(len(values)-1):
  values[i+1] += values[i]
  values[i+1] = values[i+1]/2
print(values[len(values)-1])



Measured memory_bytes: 2940
from collections import deque

def main():
    h, w = map(int, input().split())
    start_h, start_w = map(lambda x: int(x)+1, input().split())
    goal_h, goal_w = map(lambda x: int(x)+1, input().split())

    s = ["#"*(w+4)]
    s.append("#"*(w+4))
    for _ in range(h):
        s.append("##" + input() + "##")
    s.append("#"*(w+4))
    s.append("#"*(w+4))

    ans = [[-1]*(w+4) for _ in range(h+4)]
    for i in range(h+4):
        for j in range(w+4):
            if s[i][j] == "#":
                ans[i][j] = -2
    ans[start_h][start_w] = 0

    move1 = [(-1, 0), (1, 0), (0, -1), (0, 1)]
    move2 = [(-2, -2), (-2, -1), (-2, 0), (-2, 1), (-2, 2),(-1, -2), (-1, -1), (-1, 0), (-1, 1), (-1, 2),(0, -2), (0, -1), (0, 0), (0, 1), (0, 2),(1, -2), (1, -1), (1, 0), (1, 1), (1, 2),(2, -2), (2, -1), (2, 0), (2, 1), (2, 2)]

    yet = deque([(start_h, start_w)])
    done = deque()

    while yet:
        x1, y1 = yet.popleft()
        done.append((x1, y1))
        for (p, q) in move1:
            v1, v2 = x1+p, y1+q
            if ans[v1][v2] == -1: #"."でまだ辿り着いていないマス
                yet.append((v1, v2))
                ans[v1][v2] = ans[x1][y1]

        if len(yet) == 0:
            while done:
                x2, y2 = done.popleft()
                for (p, q) in move2:
                    i, j = x2+p, y2+q
                    if ans[i][j] == -1:
                        ans[i][j] = ans[x2][y2]+1
                        yet.append((i, j))

    print(ans[goal_h][goal_w])

if __name__ == "__main__":
    main()


Measured memory_bytes: 23420
//set many funcs template
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}
int round(int a,int b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
int ceil(int a,int b){if(a%b==0){return a/b;}return (a/b)+1;}
int gcd(int a,int b){int c;while(b!=0){c=a%b;a=b;b=c;}return a;}
int lcm(int a,int b){int c=gcd(a,b);a/=c;return a*b;}
int nCr(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
int fact(int a){int i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
int pow(int a,int b){int i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
long long llmax(long long a,long long b){if(a>b){return a;}return b;}
long long llmin(long long a,long long b){if(a<b){return a;}return b;}
long long llzt(long long a,long long b){return llmax(a,b)-llmin(a,b);}
long long llround(long long a,long long b){if((a%b)*2 >= b){return (a/b)+1;}return a/b;}
long long llceil(long long a,long long b){if(a%b==0){return a/b;}return (a/b)+1;}
long long llgcd(long long a,long long b){long long c;while(b!=0){c=a%b;a=b;b=c;}return a;}
long long lllcm(long long a,long long b){long long c=llgcd(a,b);a/=c;return a*b;}
long long llnCr(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=(a+1-i);r/=i;}return r;}
long long llfact(long long a){long long i,r=1;for(i=1;i<=a;i++){r*=i;}return r;}
long long llpow(long long a,long long b){long long i,r=1;for(i=1;i<=b;i++){r*=a;}return r;}
double dbmax(double a,double b){if(a>b){return a;}return b;}
double dbmin(double a,double b){if(a<b){return a;}return b;}
double dbzt(double a,double b){return dbmax(a,b)-dbmin(a,b);}
int sortfncsj(const void *a,const void *b){if(*(int *)a>*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int sortfnckj(const void *a,const void *b){if(*(int *)a<*(int *)b){return 1;}if(*(int *)a==*(int *)b){return 0;}return -1;}
int llsortfncsj(const void *a,const void *b){if(*(long long *)a>*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int llsortfnckj(const void *a,const void *b){if(*(long long *)a<*(long long *)b){return 1;}if(*(long long *)a==*(long long *)b){return 0;}return -1;}
int dbsortfncsj(const void *a,const void *b){if(*(double *)a>*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}
int dbsortfnckj(const void *a,const void *b){if(*(double *)a<*(double *)b){return 1;}if(*(double *)a==*(double *)b){return 0;}return -1;}

int main(void){
    int r,g;
    scanf("%d%d",&r,&g);
    printf("%d\n",2*g-r);
    return 0;
}

Measured memory_bytes: 128
// be name khoda
#include<bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define int long long
#define mpr make_pair 
typedef long long ll;
#pragma GCC optimize("Ofast")

const int maxn = 310;
const int N = 1e6+5;
const int mod = 998244353;
const int inf = 1e9+10;

int n, k;
char a[maxn][maxn];

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

    cin>> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < n; j++)
            cin>> a[i][j];
    
    int ans = 0;
    for(int A = 0; A < n; A++)
    {
        bool is = 1;
        for(int i = 0; i < n; i++)
            for(int j = 0; j < n; j++)
                if(a[(i+A)%n][j] != a[(j+A)%n][i])
                    is = 0;
        ans += is;
    }
    cout<< ans * n;
}





Measured memory_bytes: 384
N, K = [int(_) for _ in input().split()]
A = [int(_) for _ in input().split()]
A = [0] + A

n = 1
done = [0 for i in range(N+1)]
if K > N:
    for i in range(N):
        n = A[n]
        if done[n] != 0:
            a = done[n]
            b = i + 1 - a
            break
        done[n] = i + 1

    K = (K - a) % b + a
    n = 1
for i in range(K):
    n = A[n]
print(n)


Measured memory_bytes: 32332
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9 + 7;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen("INP.txt", "r", stdin);
	//freopen("OUT.txt", "w", stdout);
	ll a, b;
	cin >> a >> b;
	cout << max(a + b, max(a - b, a * b)) << '\n';
	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 REP(i,n) for(int i = 1; i < n; i++)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }



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

  int n, m;
  cin >> n >> m;
  vi a(n);
  rep(i,n) cin >> a[i];
  vector<P> p(m);
  rep(i,m) {
    int b, c;
    cin >> b >> c;
    p[i] = make_pair(c,b);
  }
  sort(rall(p));
  sort(all(a));
  ll ans = 0;
  int cnt = 0;
  int count = 0;
  for(int i = 0; i < n && cnt < m; i++) {
    if(a[i] < p[cnt].first) {
      a[i] = p[cnt].first;
      count++;
    }
    if(count >= p[cnt].second) {
      cnt++;
      count = 0;
    }
  }
  rep(i,n) ans += a[i];
  cout << ans << endl;
}

Measured memory_bytes: 1408
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef long long int ll;

//define
#define INF 1e9 
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)

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

 cout<<3*r*r<<endl;
}



Measured memory_bytes: 256
#include<stdio.h>

int main(){

  int n, tmp, i, j ,k;
  //Input
  scanf("%d",&n);

  int a[100];

  for( i = 1; i <= n; i++)scanf("%d",&a[i]);
  //Algo
  for( i = 1; i <= n; i++){    

    tmp = a[i];
    j = i-1;
    while( j > 0 && a[j] > tmp){
      a[j+1] = a[j];
      j--;
    }      
    a[j+1] = tmp;
    //Print
    for( k = 1; k <= n; k++){
      printf("%d",a[k]);
      if(k==n)break;
      printf(" ");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 604
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

template <class T>
inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  rep(i, N) cin >> s[i];

  int M;
  cin >> M;
  vector<string> t(M);
  rep(i, M) cin >> t[i];

  int ans = 0;
  rep(i, N) {
    string temp_s = s[i];
    int temp_ans = 0;
    rep(j, N) {
      if (temp_s == s[j]) temp_ans++;
    }
    rep(j, M) {
      if (temp_s == t[j]) temp_ans--;
    }
    chmax(ans, temp_ans);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := makeWordScanner()
	n := eGetInt(scanner)
	fmt.Println(n * n * n)
}

////////////////////////////////////////////////////////////////////////////////
// ライブラリ
////////////////////////////////////////////////////////////////////////////////
func makeScanner(maxByte int) *bufio.Scanner {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]uint8, 0, 8192), maxByte)
	return scanner
}
func makeWordScanner() *bufio.Scanner {
	scanner := makeScanner(8192)
	scanner.Split(bufio.ScanWords)
	return scanner
}
func eGetLine(r *bufio.Scanner) string {
	if r.Scan() {
		return r.Text()
	}
	err := r.Err()
	if err != nil {
		log.Fatal(err)
	}
	// EOF
	return ""
}
func eGetInt(r *bufio.Scanner) int {
	line := eGetLine(r)
	return eAtoi(line)
}
func eGetInt64(r *bufio.Scanner) int64 {
	line := eGetLine(r)
	return eAtoInt64(line)
}
func eGetFields(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Fields(line)
}
func eGetInts(r *bufio.Scanner) []int {
	fields := eGetFields(r)
	ints := make([]int, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoi(fields[i])
	}
	return ints
}
func eGetInt64s(r *bufio.Scanner) []int64 {
	fields := eGetFields(r)
	ints := make([]int64, len(fields))
	for i := 0; i < len(ints); i++ {
		ints[i] = eAtoInt64(fields[i])
	}
	return ints
}
func eGetChars(r *bufio.Scanner) []string {
	line := eGetLine(r)
	return strings.Split(line, "")
}
func eAtoi(s string) int {
	n, err := strconv.Atoi(s)
	if err != nil {
		log.Fatal(err)
	}
	return n
}
func eAtoInt64(s string) int64 {
	n, err := strconv.ParseInt(s, 10, 64)
	if err != nil {
		log.Fatal(err)
	}
	return n
}


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

string toString(int n)
{
    string str;
    stringstream ss;
    ss << n;
    ss >> str;
    return str;
}

string toNegativeBase(int n, int negBase)
{
    if (n == 0)
        return "0";
    string converted = "";
    while (n != 0)
    {
        int remainder = n % negBase;
        n /= negBase;
        if (remainder < 0)
        {
            remainder += (-negBase);
            n += 1;
        }
        converted = toString(remainder) + converted;
    }
    return converted;
}
 
int main()
{
  int N;
  cin >> N;
  cout << toNegativeBase(N, base);
  return 0;
}

Measured memory_bytes: 256
/*
  AtCoder Regular Contest 097
  C - K-th Substring
*/

#include<iostream>
#include<string>
#include<vector>
using namespace std;
 
#define FOR(i,a,b) for (int i = a; i < b; ++i)
#define REP(i,n) FOR(i,0,n)
 
int comp(string& a, string& b) {
  if (a == b) return 0;
 
  int la = a.length(), lb = b.length();
  for(int i = 0; i < la && i < lb; ++i) {
    if (a[i] != b[i]) {
      return (a[i] > b[i]) ? 1 : -1; 
    }
  }
  
  return (la > lb) ? 1 : -1;
}
 
string s;
int K;
 
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  cin >> s >> K;
  vector<string> v;
 
  int L = s.length();
  FOR(l,1,K+1) {
    REP(i,L-l+1) {
      string ss = s.substr(i,l);
 
      if (v.empty()) v.push_back(ss);
      else {
        int idx;
        for(idx = v.size() - 1; idx >= 0; --idx) {
          int res = comp(ss, v[idx]);
          if (res == 0) break; // ss == v[idx]
          else if (res == 1) { // ss > v[idx]
            v.insert(v.begin()+idx+1, ss);
            break;
          }
        }
        
        if (idx == -1) v.insert(v.begin(), ss);
        if (v.size() > K) v.pop_back();
      }
    }
  }
 
  cout << v[K-1] << endl;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Mar 22 20:55:58 2020

@author: naoki
"""

N = int(input())
A = list(map(int,input().split()))

aC2 = [0] * (N+1)

for i in range(2,N+1):
    aC2[i] = int(i*(i-1)/2)

count = [0 for i in range(N+1)]

for i in range(N):
    count[A[i]] += 1

all_count = 0
for i in range(N+1):
    all_count += aC2[count[i]]

for i in range(N):
    print(all_count - aC2[count[A[i]]] + aC2[count[A[i]]-1])

Measured memory_bytes: 26140
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = int(1E5);
int main() {
	int A, B, C, X, Y;
	scanf("%d%d%d%d%d", &A, &B, &C, &X, &Y);
	long long ans = A * X + B * Y;
	int Acnt = X, Bcnt = Y;
	while( true ) {
		int del = C*2;
		if( Acnt == 1 ) del = del - A, Acnt--;
		else if( Acnt > 1 ) del -= A, Acnt--;
		if( Bcnt == 1 ) del = del - B, Bcnt--;
		else if( Bcnt > 1 ) del -= B, Bcnt--;
		if( del < 0 ) ans += del;
		else break;
	}
	printf("%lld", ans);
} 

Measured memory_bytes: 128
using static System.Math;
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public string s { get; set; }
    public int match { get; set; }
    public int rot { get; set; }
}
public class hello
{
    public static void Main()
    {
        while (true)
        {
            var n = int.Parse(Console.ReadLine().Trim());
            if (n == 0) break;
            string[] line = Console.ReadLine().Trim().Split(' ');
            var a = line[0];
            var b = line[1];
            getAns(a, b, n);
        }
    }
    static void getAns(string a, string b, int n)
    {
        var d = new Dictionary<string, int>();
        var ans = 10;
        var ch = "0123456789";
        var st = new Stack<P>();
        st.Push(new P { s = a, match = -1, rot = 0 });
        d[a] = 0;
        while (st.Count() > 0)
        {
            var w = st.Pop();
            if (w.s == b)
            {
                ans = Min(ans, w.rot);
                continue;
            }
            if (d.ContainsKey(w.s) && w.rot > d[w.s]) continue;
            var w2 = w.s.ToArray();
            var dif = b[w.match + 1] - w2[w.match + 1];
            if (dif == 0)
            {
                st.Push(new P { s = w.s, match = w.match + 1, rot = w.rot });
                continue;
            }
            for (int i = w.match + 1; i < n; i++)
            {
                var t = w2[i] - '0' + dif;
                if (t >= 10) t -= 10;
                else if (t < 0) t += 10;
                w2[i] = ch[t];
                var ns = new string(w2);
                if (!d.ContainsKey(ns) |
                   (d.ContainsKey(ns) && w.rot + 1 < d[ns]))
                {
                    st.Push(new P { s = ns, match = w.match + 1, rot = w.rot + 1 });
                    d[ns] = w.rot + 1;
                }
            }
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 25072
#include"bits/stdc++.h"
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define INF 1e+9


int main() {
	ll n, k, anso, anse, nx=0, ny=0;
	cin >> n >> k;
	
	ll i = k / 2;
	if (i == 0) i = 1;
	for (; i <= n; i++)
	{
		if (i%k == 0)
			nx++;
		if (i%k == k / 2)
			ny++;
	}

	anso = pow(ny, 3);
	anse = pow(nx, 3);

	if (k % 2 == 0) cout << anso + anse << endl;
	else cout << anse << endl;

	return 0;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void)
{
	int d;
	scanf("%d",&d);
	if(d==25){
			printf("Christmas\n");
	}
	else if(d==24){
		printf("Christmas Eve\n");
	}
	else if(d==23){
		printf("Christmas Eve Eve\n");
	}
	else{
		printf("Christmas Eve Eve Eve\n");
	}
	return 0;
}

Measured memory_bytes: 128
N, M = map(int, input().split())
connected = [list(map(int,input().split())) for _ in range(M)]
condition = list(map(int, input().split()))
ans = 0

for i in range(1<<N):
    FLG = True
    for j,lst in enumerate(connected):
        count2 = 0
        for s in lst[1:]:
            if (i>>(s-1)) & 1:
                count2 += 1
        if count2 % 2 != condition[j]:
            FLG = False
            break
    if FLG:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n,z[10001],q=1;
  z[1]=2;
  while(scanf("%d",&n)!=-1){
    if(n>q){
      for(;q<n;q++)
	z[q+1]=z[q]+q+1;
    }
    printf("%d\n",z[n]);
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    int mx = 0;
    for (int i=1;i<=x;i++){
        int j = 2;
        while(1){
            if (pow(i,j) <= x){
                mx = max((int) pow(i,j),mx);
                j++;
                if (i==1)break;

            }else{
                break;
            }
        }
    }
    cout << mx << endl;
}

Measured memory_bytes: 256
n = int(input())
s = input()

sl = s[:n]
sr = s[n:][::-1]

from collections import Counter
l = Counter()
r = Counter()

from itertools import product
for m in product([False, True], repeat=n):
  key = [sl[i] for i in range(n) if not m[i]]
  key += ['-']
  key += [sl[i] for i in range(n) if m[i]]
  l[''.join(key)] += 1
  
  key = [sr[i] for i in range(n) if not m[i]]
  key += ['-']
  key += [sr[i] for i in range(n) if m[i]]
  r[''.join(key)] += 1
  
ans = sum(l[lk] * r[lk] for lk in l.keys())

print(ans)

Measured memory_bytes: 65480
N, A, B = map(int, input().split())

target_total = 0    # 加算対象の数値の和

for n in range(1, N + 1):
    total_each_digit = 0    # 各位の和      
    str_n = str(n)
    n_length = len(str_n)  # nの桁数
    
    for i in range(n_length):
        total_each_digit += int(str_n[i])

    if A <= total_each_digit <= B:
        target_total += n

print(target_total)

Measured memory_bytes: 3060
x1,y1,x2,y2=map(int,input().split())

dify=y2-y1
difx=x2-x1

x3=x2-dify
y3=y2+difx
x4=x1-dify
y4=y1+difx

print("{0} {1} {2} {3}".format(x3,y3,x4,y4))


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

int main(){
  string s;
  cin >> s;
  
  //year 00~99
  //month 01~12
  
  bool a = (s[2] == '0' && s[3] != '0')||(s[2] == '1' && (s[3] == '1' || s[3] == '2'));
  bool b = (s[0] == '0' && s[1] != '0')||(s[0] == '1' && (s[1] == '1' || s[1] == '2'));
  
  if(a == true && b == false){
    cout << "YYMM" << endl;
  }
  else if(a == false && b == true){
    cout << "MMYY" << endl;
  }
  else if(a == true && b == true){
    cout << "AMBIGUOUS" << endl;
  }
  else{
    cout << "NA" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <stdio.h>
using namespace std;
using ll =long long;

int main (void) {
  int N,A,B;
  cin >> N >> A >>B;
  string S;
  cin >> S;
  int pass=0;
  int kpass=0;
  for(int i=0;i<N;i++){
    if(S[i]=='c'){
      cout << "No"<< endl;
      continue;
    }
    else if(pass<A+B && S[i]=='a'){
      cout << "Yes" <<endl;
      pass++;
    }
    else if(pass<A+B && S[i]=='b' && kpass<B){
      cout << "Yes" << endl;
      pass++;
      kpass++;
    }
    else {
      cout << "No"<< endl;
    }
  }
}

Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;



int main()
{
	int A, B;
	cin >> A >> B;
	if (A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
		cout << "Possible" << endl;
	}
	else cout << "Impossible" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>

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

using namespace std;

using ll = long long;

ll n;

int main(){
  cin >> n;

  ll l = 0;
  ll r = 5e4;
  while(r - l > 1){
    ll m = (l + r) / 2;
    if(n > m * (m + 1) / 2){
      l = m;
    }
    else{
      r = m;
    }
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    A, B = input().split(" ")
    A = int(A)
    B = int(B.replace(".", ""))

    result = str(A*B)
    
    if len(result) < 2:
        print(0)
    else:
        print(result[:-2])
if __name__=="__main__":
    main()

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

bool	CMP(vector<int> a, vector<int> b){
	if (a.at(0)==b.at(0))
		return(a.at(1)>b.at(1));
	return (a.at(0)<b.at(0));
}

int     main() {
	int N, H;
	cin >>N >>H;
	vector<vector<int>> ab(0);
	vector<int> a;
	for (int i=0; i<N; i++) {
		int A, B;
		cin >>A >>B;
		ab.push_back({A, B});
	}
	sort(ab.begin(), ab.end(), CMP);
	int A=ab.back().at(0);
	int B=ab.back().at(1);
	vector<int> b;
	for (int i=0; i<N-1; i++) {
		int bb=ab.at(i).at(1);
		if (bb>A)
			b.push_back(bb);
	}
	sort(b.begin(), b.end());
	reverse(b.begin(), b.end());
	int ib=0;
	int S=0;
	while (H>0) {
		if (H<=B) {
			H -=B;
			S++;
		} else if (ib<b.size()) {
			H -= b.at(ib);
			ib++;
			S++;
		} else {
			int AA=(H-B)/A;
			if (0!=(H-B)%A)
				AA++;
			H -=A*AA;
			S +=AA;
		}
	}
	cout <<S <<endl;
	return 0;
};


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

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());
  reverse(a.begin(), a.end());
  
  int A = 0;
  int B = 0;
  for(int i = 0; i < N; i++){
    if(i % 2 ==0) A += a.at(i);
    else B += a.at(i);
  }
  
  cout << A-B << endl;
}

Measured memory_bytes: 256
import numpy as np
#入力
S = input()
#入力値を取り出す
A = np.array([int(S[i]) for i in range(len(S))])
C = np.zeros(len(S), dtype='int')
C[1:len(S):2] = 1
D = np.zeros(len(S), dtype='int')
D[0:len(S):2] = 1
print(np.min([np.sum(A!=C), np.sum(A!=D)]))

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

using namespace std;

const int INF = 1e9 + 9;

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

    int n, k;
    cin >> n >> k;

    vector<int> h(n);
    vector<int> dp(n, INF);

    for (int &x : h)
        cin >> x;

    dp[0] = 0;

    for (int i = 0; i < n; i++)
        for (int j = 1; j <= k; j++)
            if (i + j < n)
                dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));

    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define mp make_pair
#define pb push_back
#define eb emplace_back
const int MOD=1e9+7;
const int INF=1e18;

signed main(){
    int X;cin>>X;
    bool T[100200];
    REP(i,100200)T[i]=false;
    T[0]=true;
    REP(k,1000){
        REP(i,100000){
            if(T[i])T[i+100]=T[i+101]=T[i+102]=T[i+103]=T[i+104]=T[i+105]=true;
        }
    }
    cout<<(T[X]?1:0)<<endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K; cin >> N>> K;
    VL a(N); REP(i,N) cin >> a[i];
    VL S1(N+1),S2(N+1);
    REP(i,N){
        S1[i+1] = S1[i] + a[i];
        S2[i+1] = S2[i] + (a[i] > 0 ? a[i] : 0);
    }
    LL ans = -LINF;
    for(int i = 0; i + K <= N; i++){
        int left = i;
        int right = i+K;
        LL tmp = (S2[left]-S2[0]) + max(0LL,S1[right]-S1[left]) + (S2[N]-S2[right]);
        ans = max(tmp,ans);
    }
    cout << ans << endl;

}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

using namespace std;

int n, x;
int l[101];
int d[101];

signed main() {
    cin >> n >> x;
    for (int i = 0; i < n; i++) cin >> l[i];

    int cnt = 1;
    for (int i = 1; i <= n; i++) {
        d[i] = d[i - 1] + l[i - 1];
        if (d[i] <= x) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
n,k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)


ng = -1
ok = 10**12
while ok-ng > 1:
    mid = (ok+ng)//2
    cnt = 0

    for i,e in enumerate(a):    
        cnt += max(0,e-mid//f[i])
    if cnt <= k:
        ok = mid
    else:
        ng = mid

print(ok)


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

int main()
{
  string a = "dream", b = "dreamer", c = "erase", d = "eraser";
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  reverse(c.begin(), c.end());
  reverse(d.begin(), d.end());
  string s;
  cin >> s;
  reverse(s.begin(), s.end());
  while (true) {
	if (s.size() < 5) {
	  break;
	}
	bool flag = false;
	string x = s.substr(0, 5), y = s.substr(0, 6), z = s.substr(0, 7);
	if (z == b) {
	  s.erase(s.begin(), s.begin() + 7);
	  flag = true;
	}
	else if (y == d) {
	  s.erase(s.begin(), s.begin() + 6);
	  flag = true;
	}
	else if (x == a || x == c) {
	  s.erase(s.begin(), s.begin() + 5);
	  flag = true;
	}
	if (!flag) {
	  break;
	}
  }
  if (s.empty()) {
	cout << "YES" << endl;
	return 0;
  }
  cout << "NO" << endl;
  return 0;
}



Measured memory_bytes: 512
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>
#define pb push_back
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<10)
#define MOD 1000000007
typedef long long ll;
using namespace std;

int main(){
  ll n,a,b;
  cin>>n>>a>>b;
  ll ans=0;
  ans+=(n/(a+b))*a;
  n-=(n/(a+b))*(a+b);
  ans+=min(n,a);
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
 
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();
    int X = sc.nextInt();
    
    int cnt = 0;
    for (int i = 0; i < A + 1; i++) {
      for (int j = 0; j < B + 1; j++) {
        for (int k = 0; k < C + 1; k++) {
          int total = 500*i+100*j+50*k;
          if (total == X) {
            cnt++;
          }
        }
      }
    }
    System.out.println(cnt);
  }
}

Measured memory_bytes: 35676
#include<bits/stdc++.h>
#define M 200002
using namespace std;
int A[M],Ans[M];
int main(){
	int n,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&A[i]);
	for(int i=n;i>=n/2+1;i--)
		Ans[i]=A[i],ans+=A[i];
	for(int i=n/2;i>=1;i--){
		int num=0;
		for(int j=i*2;j<=n;j+=i)
			num+=Ans[j];
		num%=2;
		if(num!=A[i])Ans[i]=1;
		ans+=Ans[i];
	}
	printf("%d\n",ans);
	for(int i=1;i<=n;i++)if(Ans[i])printf("%d ",i);
	return 0;
}

Measured memory_bytes: 2432
n = int(input())
v = list(map(int, input().split()))
c = list(map(int, input().split()))

benefit = []


for i in range(n):
  benefit.append(v[i] - c[i])
  
sum = 0
for i in range(n):
  if benefit[i] > 0:
    sum += benefit[i]

print(sum)

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

int main(){
	int n;
	scanf("%d", &n);
	int x = 0, y = 0;
	for(int i = 1; i <= n; i++) {
		x += 800;
		if(i % 15 == 0) y += 200;
	}
	printf("%d\n", x - y);
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-


def main():
    n = int(input())
    v = sorted(list(map(int, input().split())))
    ans = (v[0] + v[1]) / 2

    for i in range(2, n):
        ans = (ans + v[i]) / 2

    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
  int N;
  cin >> N;
  vector<int> v(N);
  stack<int> ans;
  for (int &e : v) cin >> e;
  
  while (v.size() > 0) {
    int p = -1;
    for (int i = 0; i < N; i++) {
      if (v[i] == i+1) p = i;
    }
    if (p < 0) {
      cout << -1 << endl;
      return 0;
    }
    ans.push(v[p]);
    v.erase(v.begin()+p);
    N--;
  }
  
  while (ans.size() > 0) {
    cout << ans.top() << endl;
    ans.pop();
  }
}

Measured memory_bytes: 3604
N,K=map(int,input().split())
A=[int(i) for i in input().split()]
dp=[0]*(K+1)
dp[0]=0
for i in range(1,K+1):
    flag=0
    s=1
    for a in A:
        if i-a>=0:
            s*=dp[i-a]
            flag=1
    if flag==0:
        dp[i]=0
    else:
        dp[i]=1-s
#print(dp)
if dp[K]==0:
    print('Second')
else:
    print('First')

Measured memory_bytes: 41836