akhauriyash/Code-Regression huggingface dataset:
#ifndef DEBUG
#pragma GCC optimize("O3,unroll-loops")
#pragma loop_opt(on)
#endif
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#define FAST ;
#else
#define FAST ios::sync_with_stdio(0);cin.tie(0);
#define endl '\n'
#define cerr
#endif
#define _ <<' '<<
#define Fr(i, s, e) for(auto i = s; i < e; ++i)
#define All(v) v.begin(),v.end()
#define Ft first
#define Sd second
using ll = long long;
using pii = pair<int, int>;
constexpr ll MOD = 1e9+7;

signed main() {
    FAST;

    array<int,3> v;
    for(auto &x: v) cin >> x;
    sort(All(v));
    int c = 0;
    Fr(i, 0, 2) {
        int x = (v[2]-v[i])/2;
        v[i] += x*2;
        c += x;
    }
    sort(All(v));
    if (v[0] == v[2]-1) {
        if (v[0]==v[1]) c++;
        else c+=2;
    }
    cout << c << endl;

}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var x1, y1, x2, y2 int
	_, _ = fmt.Scan(&x1, &y1, &x2, &y2)
	delta1 := y1 - y2
	delta2 := x2 - x1
	fmt.Println(x2 + delta1, y2 + delta2, x1 + delta1, y1 + delta2)
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <cmath>
#include <set>
#include <list>
#include <deque>
#include <map>
#include <queue>
#include <fstream>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <sstream>
#include <time.h>
#include <complex>
#include <iomanip>
#include <tuple>

#define Max(a,b) ((a)>(b)?(a):(b))
#define Min(a,b) ((a)<(b)?(a):(b))
#define FOR(a,b,c) for (ll (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (ll (a)=(b);(a)<=(c);++(a))
#define DFOR(a,b,c) for (ll (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (ll (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define rep(i,n) FOR(i,0,n)
#define repn(i,n) FORN(i,1,n)
#define drep(i,n) DFOR(i,n-1,0)
#define drepn(i,n) DFOR(i,n,1)
#define MAX(a,b) a = Max(a,b)
#define MIN(a,b) a = Min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define Reset(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(all(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)
#define forever for(;;)
#define PINF 1000000000000
#define newline '\n'

#define test if(1)if(0)cerr
using namespace std;
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<double,double> dd;
typedef pair<char,char> cc;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> l4;

int a, b, c;
bool solve()
{
    cin >> a >> b >> c;
    return c >= a && c <= b;
}
int main()
{
    cout << (solve()?"Yes":"No") << newline;
}

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

int main(){
  string S;
  cin >> S;
  long long sum=0;
  for(int i=0;i<S.size();i++){
    int A=S.at(i)-'0';
    sum+=A;
  }
  if(sum%9==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int main() {
    int A, B; cin >> A >> B;
    vector<char> S(A + B + 1);
    for (int i = 0; i < A + B + 1; i++) {
        cin >> S.at(i);
    }

    string ans = "Yes";
    if (S.at(A) != '-') ans = "No";
    for (int i = 0; i < S.size(); i++) {
        if (S.at(i) == '-' && i != A) ans = "No";
    }
    cout << ans << endl;
}

Measured memory_bytes: 3600
import sys
from itertools import permutations


def in_board(r, c):
    return 0 <= r < 8 and 0 <= c < 8


def reachable_generator(r, c):
    # 斜め(左上-右下)
    i = 1
    while True:
        if not in_board(r - i, c - i):
            break
        yield r - i, c - i
        i += 1
    i = 1
    while True:
        if not in_board(r + i, c + i):
            break
        yield r + i, c + i
        i += 1
    # 斜め(右上-左下)
    i = 1
    while True:
        if not in_board(r - i, c + i):
            break
        yield r - i, c + i
        i += 1
    i = 1
    while True:
        if not in_board(r + i, c - i):
            break
        yield r + i, c - i
        i += 1


def solve(ini):
    for p in permutations(range(8)):
        s = set()
        for i, j in enumerate(p):
            s.add((i, j))
        if not ini <= s:
            continue
        for i, j in s:
            for k, l in reachable_generator(i, j):
                if (k, l) in s:
                    break
            else:
                continue
            break
        else:
            return s


def main():
    input = sys.stdin.buffer.readline
    k = int(input())
    # ini:初期条件
    ini = set()
    for _ in range(k):
        r, c = map(int, input().split())
        ini.add((r, c))
    s = solve(ini)

    board = [["."] * 8 for _ in range(8)]
    for i, j in s:
        board[i][j] = "Q"
    for i in range(8):
        print("".join(board[i]))


if __name__ == "__main__":
    main()



Measured memory_bytes: 5644
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int i,j,x,n,sss,sum[1000000];

int main(void){
	while(scanf("%lld",&n)*n){
		for(i=0;i<n;i++){
			sss=0;
			for(j=0;j<n;j++){
				scanf("%d",&x);
				sss+=x;
				if(i==0)sum[j]=x; else sum[j]+=x;
				printf("%5d",x);
			}
			printf("%5d\n",sss);
		}
		sss=0;
		for(j=0;j<n;j++){
			sss+=sum[j];
			printf("%5d",sum[j]);
		}
		printf("%5d\n",sss);
	}
	return 0;
}

Measured memory_bytes: 616
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける

ll n,m;

int main(){
  ll ans=0;
  cin >> n >>m;
  vi x(m);
  
  REP(i,m){
	  cin>>x[i];
  }

  sort(x.begin(), x.end());
  vi xs(m);//xの差分
  REP(i,m-1){
	  xs[i]=x[i+1]-x[i];
  }
  sort(xs.begin(), xs.end());


  if (n>m)n=m;
  ll sum=accumulate(xs.begin(),xs.begin()+m-n+1 ,0LL);
  cout<<sum<<endl;

}

Measured memory_bytes: 1792
def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
def main():
  N = int(input())
  l = fac(N)
  counter = 0
  if N == 1:
    print(0)
    exit()
  if len(l) == 1 and l[0][1] == 1:
    print(1)
    exit()
  for x in l:
#    print(x)
    temp = 0
    for k in range(1, 141423):
      temp += 1
      z = x[0] ** temp
#      print("z:" + str(z))
      if N/z < 1:
        break
#      print("OK")
      N = N/z
      if float(N).is_integer() == False:
        N = N * z
        break
#      print("z:" + str(z) + ", N:" + str(N))
      counter += 1
    if N <= 1:
      break
  print(counter)
if __name__ == "__main__":
  main()

Measured memory_bytes: 9476
import scala.math.abs

object Main extends App {
  val sc = new java.util.Scanner(System.in) 
  val N = sc.nextInt()
  val P = Vector.fill(N)(sc.nextInt())
  val Q = Vector.fill(N)(sc.nextInt())
  val permutations = (1 to N).permutations.toList
  val a = permutations.indexOf(P) + 1
  val b = permutations.indexOf(Q) + 1
  println(abs(a - b))
}



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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

string s;

int main(){
    cin >> s;
    int cnt = 0;
    rep(i,s.size()){
        if(s[i] == '(')cnt++;
        else if(s[i] == ')')cnt--;
        else{
            cout << cnt << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3208
SHIFT = 1 << 20


class fenwick_tree:
    """
    区間の一点更新と，区間和の取得がO(log n)で可能なデータ構造
    1-indexedで実装
    """

    def __init__(self, N):
        self.size = N
        self.tree = [0] * (N+1)

    def sum_until(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & (-i)
        return s

    def sum_acc(self, i, j):
        """ [i,j] の和を返す """
        return self.sum_until(j) - self.sum_until(i-1)

    def add(self, i, x):
        if i <= 0:
            return
        while i <= self.size:
            self.tree[i] += x
            i += i & (-i)


def main():
    N, Q = (int(i) for i in input().split())
    C = [int(i) for i in input().split()]
    Query = []
    for j in range(Q):
        le, ri = (int(i) for i in input().split())
        Query.append(ri << 40 | le << 20 | j)
    Query.sort()

    # Query復元
    for i in range(Q):
        j = Query[i] % (SHIFT)
        Query[i] >>= 20
        le = Query[i] % (SHIFT)
        Query[i] >>= 20
        ri = Query[i]
        Query[i] = (le, ri, j)
    Query.append((-1, -1, -1))

    lastappend = [-1] * (N + 1)
    bit = fenwick_tree(N)
    idx = 0  # Queryのindex
    ans = [0]*Q

    for i, a in enumerate(C, start=1):
        if lastappend[a] != -1:
            bit.add(lastappend[a], -1)
        lastappend[a] = i
        bit.add(i, 1)
        while i == Query[idx][1]:
            (le, ri, j) = Query[idx]
            ans[j] = bit.sum_acc(le, ri)
            idx += 1

    print(*ans, sep="\n")


if __name__ == '__main__':
    main()


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

#define MOD 10000007
#define f first
#define s second
#define pb push_back
#define es " "
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n, m, wa=0, ac=0, check[100005], check2[100005];
    memset(check, 0, sizeof check);
    memset(check2, 0, sizeof check2);
    cin >> n >> m;
    for(int i=0, a; i<m; i++){
        string atual;
        cin >> a >> atual;
        if(atual=="WA" && !check[a]){
            check2[a]++;
        }
        if(atual=="AC" && !check[a]){
            ac++;
            check[a]=1;
        }
    }
    for(int i=1; i<=n; i++){
        if(check2[i]>0 && check[i]){
            wa+=check2[i];
        }
    }
    cout << ac << es << wa << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {

		int N=nextInt();
		int K=nextInt();
		int[] s = new int[N+1];
		Arrays.fill(s, 0);
		for(int i=0;i<K;i++){
			nextInt();
			int[] A=nextInts();
			for(int k=0;k<A.length;k++){
				s[A[k]]++;
			}
		}
		int ans = 0;
		for(int i=1;i<s.length;i++){
			if(s[i]==0){
				ans++;
			}
		}
		System.out.println(ans);

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 27424
#include <iostream>
using namespace std;
int main(){
    string s,left[233],right[233];
    cin >> s;
    int i,j,wrong,lenth;
    lenth = s.size();
    for(i = 0;i < s.size();i++){
        wrong = 0;
        if(lenth % 2 == 1 || lenth == s.size()){
            lenth--;
            continue;
        }
        for(j = 0;j < lenth/2;j++){
            left[j] = s[j];
            right[j] = s[j+lenth/2];
        }
        for(j = 0;j < lenth/2-1;j++){
            if(left[j] != right[j]){
                wrong = 1;
                break;
            }
        }
        if(wrong == 0){
            cout << lenth << endl;
            break;
        }
        lenth--;
    }
    return 0;
}

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

string s;
vector<string> ans;

void dfs(int idx, int used, string c) {
    if (idx == s.size()) {
        ans.push_back(c);
        return;
    }
    char now = s[idx];
    if ((used >> (now - 'a')) & 1) {
        dfs(idx + 1, used, c + now);
    }
    if (now != 'z' && !((used >> (now - 'a' + 1)) & 1)) {
        used |= (1 << (now - 'a' + 1));
        dfs(idx + 1, used, c + (char)(now + 1));
    }
    return;
}

int main() {
    while (cin >> s) {
        if (s == "#") break;
        ans.clear();
        dfs(0, 1, "");
        cout << ans.size() << endl;
        if (ans.size() <= 10) {
            for (auto e : ans) cout << e << endl;
        } else {
            for (int i = 0; i < 5; i++) cout << ans[i] << endl;
            for (int i = ans.size() - 5; i < ans.size(); i++) cout << ans[i] << endl;
        }
    }
    return 0;
}


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

int main()
{
    char s[10], t[10], u[10];
    cin >> s;
    cin >> t;
    int a, b;
    cin >> a >> b;
    cin >> u;
    if(strcmp(u,s)==0)
    {
        cout << a-1 << " " << b << endl;
    }
    else if(strcmp(u,t)==0)
    {
        cout << a << " " << b-1 << endl;
    }

    return 0;
}


Measured memory_bytes: 256
/***************************************************
 * Problem Name : A - 9x9.cpp
 * Problem Link : https://atcoder.jp/contests/abc144/tasks/abc144_a
 * OJ           : atCoder
 * Verdict      : Trying
 * Date         : 2019-10-31
 * Problem Type :
 * Author Name  : Saikat Sharma
 * University   : CSE, MBSTU
 ***************************************************/
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <cstdlib>
#include <deque>
#include <stack>
#include <bitset>
#include <cassert>
#include <map>
#include <set>
#include <cassert>
#include <iomanip>
#include <random>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;

#define __FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define __FileRead freopen ("input.txt", "r", stdin)
#define __FileWrite freopen ("output.txt", "w", stdout)
#define SET(a,v) memset(a,v,sizeof(a))
#define SZ(v) (int)v.size()
#define pii pair<int,int>
#define pil pair <int, ll>
#define pli pair <ll, int>
#define pll pair <ll, ll>
#define debug cout <<"######\n"
#define debug1(x) cout <<"### " << x << " ###\n"
#define debug2(x,y) cout <<"# " << x <<" : "<< y <<" #\n"
#define nl cout << "\n";
#define sp cout << " ";
#define sl(n) scanf("%lld", &n)
#define sf(n) scanf("%lf", &n)
#define si(n) scanf("%d", &n)
#define ss(n) scanf("%s", n)
#define pf(n) scanf("%d", n)
#define pfl(n) scanf("%lld", n)
#define all(v) v.begin(), v.end()
#define rall(v) v.begin(), v.end()
#define srt(v) sort(v.begin(), v.end())
#define r_srt(v) sort(v.rbegin(), v.rend())
#define rev(v) reverse(v.begin(), v.end())
#define Sqr(x) ((x)*(x))
#define Mod(x, m) ((((x) % (m)) + (m)) % (m))
#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define pb push_back
#define mk make_pair
#define MAX 100005
#define INF 1000000009
#define MOD 1000000007

template<class T>
using min_heap = priority_queue<T, std::vector<T>, std::greater<T>>;
template<typename T>
using ordered_set  = tree<T, null_type, less<T>, rb_tree_tag,
      tree_order_statistics_node_update>;

template <typename T> string toString ( T Number ) {
    stringstream ss;
    ss << Number;
    return ss.str();
}
template<typename T> int toInt (T str) {
    stringstream ss;
    ss << str;
    int num;
    ss >> num;
    return num;
}
ll lcm (ll a, ll b) {
    return a * b / __gcd (a, b);
}
/************************************ Code Start Here ******************************************************/
int main () {
    //~ __FastIO;
    //~ cout << setprecision (10);
    //~ cout << fixed;
    int a, b;
    cin >> a >> b;

    if (a > 9 || b > 9) cout << -1 << "\n";
    else cout << a *b << "\n";

    return 0;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn.readLine
    val Array(datN, datK) = readLine.split(" ").map(_.toInt)
    val datL = readLine.split(" ").map(_.toInt)

    val ans = datL.sorted.reverse.slice(0, datK).sum

    println(ans)
  }
}


Measured memory_bytes: 25408
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
using namespace std;
int dp[2][210][210][210];
char a[210][210];
int to[210][210];
int main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",a[i]+1);
		to[i][m]=m;
		for(int j=m-1;j>=1;j--)
			if(a[i][j]==a[i][j+1])
				to[i][j]=to[i][j+1];
			else to[i][j]=j;
	}
	for(int l=1;l<=m;l++)
		for(int r=l;r<=m;r++)
			for(int u=n+1;u>=1;u--)
			{
				if(u==n+1)dp[0][l][r][u]=n;
				else if(to[u][l]<r)dp[0][l][r][u]=u-1;
				else{
					if(a[u][l]!=a[u+1][l])dp[0][l][r][u]=u;
					else dp[0][l][r][u]=dp[0][l][r][u+1];
				}
			}
	int ans=0;
	while(dp[ans&1][1][m][1]<n){
		ans++;int now=ans&1;int lst=now^1;
		for(int l=1;l<=m;l++)
			for(int r=l;r<=m;r++)
				for(int u=n;u>=1;u--)
					dp[now][l][r][u]=dp[lst][l][r][dp[lst][l][r][u]+1];
		for(int l=1;l<=m;l++)
			for(int u=1;u<=n;u++)
			{
				/*
				int cur=l;
				for(int r=l+1;r<=m;r++)
				{
					
					while(cur+1<r&&dp[lst][l][cur][u]>=dp[lst][cur+1][r][u])cur++;
					dp[now][l][r][u]=max(dp[now][l][r][u],min(dp[lst][l][cur][u],dp[lst][cur+1][r][u]));
					if(cur>l)dp[now][l][r][u]=max(dp[now][l][r][u],min(dp[lst][l][cur-1][u],dp[lst][cur][r][u]));
					
					//for(cur=l;cur<r;cur++)
					//	dp[now][l][r][u]=max(dp[now][l][r][u],min(dp[lst][l][cur][u],dp[lst][cur+1][r][u]));
				}*/
				int cur=l-1,r=l;
				for(int d=n;d>=u-1;d--)
				{
					while(cur<m&&dp[lst][l][cur+1][u]>=d)cur++;
					if(cur<l)continue;
					while(r<=m&&(cur>=r||dp[lst][cur+1][r][u]>=d)){
						dp[now][l][r][u]=max(dp[now][l][r][u],d);
						r++;
					}
				}
			}
//		printf("%d:",ans);
//		for(int u=1;u<=n;u++)
//			printf("%d ",dp[now][1][m][u]);
//		printf("\n");
//		system("pause");
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 67456
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
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,l;
    cin >> n >> l;
    vector<string> s(n);
    rep(i,n)cin >> s.at(i);
    
    sort(s.begin(),s.end());
    string ans = "";
    rep(i,n)ans += s.at(i);
    cout << ans << endl;
    return 0;
}
/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

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

using namespace std;

bool dp[1000001];

bool isPrime(int x){
  int i, flag=0;
  for(i=2; i*i<=x; i++){
    if(x%i==0){
      flag += 1;
    }
  }
  if(flag==0){
    return true;
  }else{
    return false;
  }
}

int solve(int x){
  int temp = x;
  while(1){
    if(dp[temp] && isPrime(temp)){
      return temp;
    }
    temp--;
  }
}
int main(){
  int dish, budget, dishPrice[30], i, j;
  while(cin >> dish >> budget, dish+budget){
    for(i=1; i<=budget; i++){
      dp[i] = false;
    }
    dp[0] = true;
    for(i=0; i<dish; i++){
      cin >> dishPrice[i];
      for(j=dishPrice[i]; j<=budget; j++){
        if(dp[j-dishPrice[i]]){
          dp[j] = true;
        }
      }
    }
    int ans = solve(budget);
    if(ans){
      cout << ans << endl;
    }else{
      cout << "NA" << endl;
    }
  }
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
ll X, Y;
ll i, j, k;

int main(){
    scanf("%lld%lld", &X, &Y);
    if(Y%2==1){
        printf("No\n");
        return 0;
    }
    if(X*2<=Y&&Y<=X*4){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    

    return 0;
}

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

inline int read() {
  int ret, cc, sign = 1;
  while (!isdigit(cc = getchar()))
    sign = cc == '-' ? -1 : sign;
  ret = cc - 48;
  while (isdigit(cc = getchar()))
    ret = cc - 48 + ret * 10;
  return ret * sign;
}

const int MOD = 1e9 + 7;
inline int add(int a, int b) { return (a += b) >= MOD ? a - MOD : a; }
inline int sub(int a, int b) { return (a -= b) <    0 ? a + MOD : a; }
inline int mul(int a, int b) { return 1ll * a * b % MOD; }
inline int qpow(int a, int p) {
  int ret = 1;
  for (; p; p >>= 1, a = mul(a, a))
    if (p & 1) ret = mul(ret, a);
  return ret;
}

const int SHIFT = 2001;
const int MAXN = 200010;

int A[MAXN];
int B[MAXN];
int dp[4010][4010];
int fac[MAXN];
int inv[MAXN];
int n;

inline int Binom(int n, int m) { return mul(fac[n], mul(inv[m], inv[n - m])); }

int main() {
#ifdef ARK
  freopen("test.in", "r", stdin);
#endif
  n = read();
  fac[0] = 1;
  for (int i = 1; i < MAXN; ++i) fac[i] = mul(fac[i - 1], i);
  inv[MAXN - 1] = qpow(fac[MAXN - 1], MOD - 2);
  for (int i = MAXN - 1; i >= 1; --i) inv[i - 1] = mul(inv[i], i);
  for (int i = 1; i <= n; ++i) {
    A[i] = read(), B[i] = read();
    dp[SHIFT - A[i]][SHIFT - B[i]]++;
  }
  for (int i = 1; i <= 4001; ++i)
    for (int j = 1; j <= 4001; ++j) 
      dp[i][j] = add(dp[i][j], add(dp[i - 1][j], dp[i][j - 1]));
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    ans = add(ans, dp[SHIFT + A[i]][SHIFT + B[i]]);
    ans = sub(ans, Binom((A[i] + B[i]) << 1, A[i] << 1));
  }
  ans = mul(ans, qpow(2, MOD - 2));
  printf("%d\n", ans);
}


Measured memory_bytes: 66176
A,B,H,M=list(map(int,input().split()))
min_s=0.5*(H*60+M)
max_s=6*M
import math
radi=min(abs(max_s-min_s),360-abs(min_s-max_s))
ans=A**2+B**2-2*math.cos(math.radians(radi))*A*B
print(ans**0.5)

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

exist = True

if n == 1:
    sc_list = []
    for i in range(m):
        sc_list.append(list(map(int, input().split())))
    
    if m >= 2:
        for j in range(m-1):
            if sc_list[j][1] != sc_list[j+1][1]:
                exist = False
    
    if exist:
        if m >= 1:
            x = str(sc_list[0][1])
        elif m == 0:
            x = '0'

elif n >= 2:
    x = [-1] * n

    for i in range(m):
        s, c = map(int, input().split())
        if s == 1:
            if c == 0:
                exist = False
            else:
                if x[0] != -1 and x[0] != c:
                    exist = False
                else:
                    x[0] = c
        else:
            if x[s-1] != -1 and x[s-1] != c:
                exist = False
            else:
                x[s-1] = c

    if x[0] == -1 :
        x[0] = 1
    if exist:
        x = [0 if j == -1 else j for j in x]
        x = "".join(map(str,x))
            
if exist:
    print(x)
else:
    print('-1')


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

#define LL long long
typedef pair<int, int> pii;

template< typename T > inline void read(T &x)
{
    static char _c;
    static bool _f;

    x = 0;
    _f = 0;
    _c = getchar();

    while(_c < '0' || '9' < _c) {if(_c == '-') _f = true; _c = getchar();}
    while('0' <= _c && _c <= '9') {x = (x << 1) + (x << 3) + (_c & 15); _c = getchar();}
    if(_f) x = -x;
}

template < typename T > inline void Min(T &x, T y) {if(y < x) x = y;}
template < typename T > inline void Max(T &x, T y) {if(x < y) x = y;}


#define lowbit(x) ((x) & -(x))
#define lson l,mid,id<<1
#define rson mid+1,r,id<<1|1
#define ls id<<1
#define rs id<<1|1
#define MID(l,r) ((l)+(((r)-(l))>>1))
#define fi first
#define se second
#define mk make_pair
#define pb push_back

const int INF = 0x3f3f3f3f;
const int MOD = (int) 1e9 + 7;
//const int MOD = (int) 998244353;
const int maxn = (int) 2e5 + 20;
const int maxm = (int) 1000000 + 20;
const double pi = (double) acos(-1.0);
const double eps = (double) 1e-8;

inline int sig(double x) {return x < -eps ? -1 : eps < x;}
LL fp(LL a, LL n, LL m = MOD) {LL res = 1; for(; n; n >>= 1, a = a * a % m) if(n & 1) res = res * a % m; return res;}

int n;
int c[10][10];

void work()
{
    cin >>n;

    LL cnt = 0;
    for(int i = 1; i <= n; i++)
    {
        int p = i, q = i % 10;
        while(p > 9) p /= 10;

        c[p][q]++;
        cnt += c[q][p] * 2;
        if(p == q) cnt--;
    }

    cout <<cnt <<endl;
}

int main()
{
#ifdef yukihana0416
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // yukihana0416
//    get_prime();
    int tc = 1;
//    read(tc);
    for(int ca = 1; ca <= tc; ca++)
    {
//        printf("Case #%d: ", ca);
        work();
    }
    return 0;
}


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

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

int main()
{
    int a, b;
    cin >> a >> b;
    cout << a + (b >= a) - 1 << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res


N,K=LI()
MP=[0] + LI()
LG = 10**15
DP=[[LG]*(N+1) for i in range(N-K+2)]

for i in range(1, N+1):
    DP[0][i] = 0
    DP[1][i] = MP[i]

for i in range(1, N-K):
    for j in range(1, N+1):
        for k in range(1, j):
            DP[i+1][j] = min(DP[i+1][j], DP[i][k] + max(0, MP[j] - MP[k]))

res = 10**15
for i in range(1, N+1):
    res = min(res, DP[N-K][i])
print(res)


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

int main(){
	vector<int> a;
	int N;
	cin >> N;
	int temp = 0;
	for(int i=0;i<N;i++){
		cin >> temp;
		a.push_back(temp);
	}
	sort(a.begin(),a.end(),greater<int>());
	int A = 0;
	int B = 0;
	for(int i=0;i<N;i++){
		if(i % 2 == 0) A += a[i];
		else B += a[i];
	}
	cout << A - B << endl;
}

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

#define ll long long
#define ii pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi acos(-1.0)
#define oo 1000000007
#define loo 10000000000000007

#define prime 1000000007

#define W(x) cerr << "\033[31m" << #x << " = " << x << "\033[0m" << "\n";
using namespace std;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	
	int n, x, t; cin >> n >> x >> t;
	cout << ((n+(x-1))/x)*t << "\n";
	
	
	return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
	ll x,res;
	cin>>x;
	res = (x/11)*2;
	if(x%=11)res += x%11>6 ? 2 : 1;
	cout<<res<<endl;
	return 0;
}


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

ll n, tmp, ans = 0, sum = 0;
map<ll, int> mp;

int main() {    
    cin >> n;
    while (n--) {
        cin >> tmp;
        sum += tmp;
        mp[sum]++;
    }
    for (auto it = mp.begin(); it != mp.end(); ++it) {
        ll num = it->second;
        if (num >= 2) {
            ans += num * (num-1) / 2; // nC_2
        }
        if (it->first == 0) ans += num;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 12800
import sys
import heapq

def solve():
    input = sys.stdin.readline
    N, M = map(int, input().split())
    A = [-1 * int(a) for a in input().split()]
    heapq.heapify(A)

    for i in range(M):
        a = -1 * heapq.heappop(A)
        heapq.heappush(A, -1 * (a // 2))

    print(-1 * sum(A))


    return 0

if __name__ == "__main__":
    solve()

Measured memory_bytes: 14172
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define MAX 100
#define MOD 1000000007
#define pb push_back

/* add vars here */

ll n,x;
vector<ll> v;

/* add your algorithm here */

ll gcd(ll x, ll y) {
  if (y > x) swap(x,y);
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main() {
  cin >> n >> x;
  if (n == 1) {
    ll t;
    cin >> t;
    cout << abs(x - t) << endl;
    return 0;
  }

  rep(i,n) {
    ll t; cin >> t;
    v.pb(abs(t - x));
  }

  ll ans = 0;

  for (auto itr = v.begin(); itr != v.end(); ++itr) {
    ans = gcd(*itr, ans);
  }

  cout << ans << endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fastio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
const int maxn = 1e5 + 5;
const int inf = 1000000000;
const int MOD = 1e9+7;
const double PI = 3.14159265358979323846264338; // double PI = 4*atan(1);

	 

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastio
	//ifstream cin (".in");
	//ofstream cout (".out");
	//int t;
	//cin >> t;
	//while(t--){
	int n,a,b;
	cin >> n >> a >> b;
	string s;
	int pa = 0,pb = 0;
	for(int i=0; i<n; i++){
		cin >> s;
		if(s[i] == 'a' && pa+pb<a+b){ 
			pa++;
			cout << "Yes\n";
		}else if(s[i] == 'b' && pa+pb<a+b && pb<b){
			pb++;
			cout << "Yes\n";
		}else{
			cout << "No\n";
		} 
	}
	return 0;
 }




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

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds; 
 
typedef long long int ll;
typedef long int li;

const ll mod = 1000000007;
const ll inf = 1000000000000000000;

typedef vector<int> vi;
typedef vector<li> vli;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef vector<vli> vvli;
typedef vector<vll> vvll;
typedef vector<vs> vvs;
typedef map<ll, ll> mll;
typedef map<ll, string> mls;
typedef map<string, ll> msl;
typedef pair<ll, ll> pll;

// #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
#pragma GCC optimize ("-O3")
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); 
#define PI acos(-1)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define all(v) v.begin(), v.end()
#define mini(a) *min_element(all(a))
#define maxi(a) *max_element(all(a))
#define tol(s) transform(s.begin(), s.end(), s.begin(), ::tolower);
#define tou(s) transform(s.begin(), s.end(), s.begin(), ::toupper);
#define FOR(i, j, k, in) for(li i=j; i<k; i+=in)
#define RFOR(i, j, k, de) for(li i=j; i>=k; i-=de)
#define rep(i,j,k) FOR(i, j, k, 1)
#define rrep(i,j,k) RFOR(i, j, k, 1)
#define repc(v) for(auto it=v.begin(); it!=v.end(); it++)
#define rrepc(v) for(auto it=v.rbegin(); it!=v.rend(); it--)
#define T ll t; cin>>t; while(t--)

ll gen(){
    ll temp;
    cin>>temp;
    return temp;
}

ll power(ll a, ll b, ll m){    
    ll res=1;
    while(b>0){
        if(b&1){
            res=(res*a)%m;
            b--;
        }
        a=(a*a)%m;
        b=b>>1;
    }
    return res;
}

ll gcd(ll a, ll b){if(a==0)return b; else return gcd(b%a, a);}
ll lcm(ll a, ll b){return (a*b)/gcd(a,b);}

#define inpt(v) generate(all(v),gen)
#define sum(v) accumulate(all(v),0LL)
#define vpll vector<pll>
#define umap unordered_map
#define uset unordered_set
#define print(v) rep(i,0,n) cout<<v[i]<<" ";

int32_t main(){
  FAST

    string s;
    cin>>s;

    ll sum = 0;
    ll n = s.length();

    rep(i,0,n)
    sum += (s[i]-48);

    if(sum % 9 == 0) cout<<"Yes";
    else cout<<"No";  


  
  return 0;
}

Measured memory_bytes: 3772
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
typedef long long int ll;
using namespace std;
#define P 1000000007
#define rep(i,n) for(i=0;i<n;++i)
#define repp(i,a,n) for(i=a;i<n;++i)
#define repr(i,a,n) for(i=a;i>=n;--i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second

ll binpowmod(ll a, ll b, ll m) {
    a %= m;
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
}

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

ll modInverse(ll n, ll p)
{
    return binpowmod(n, p-2, p);
}

int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t,m,n,i,f=0,j,ans=0,k;
    cin >> k;
    if(k<=12)
    {
        cout << k ;
        return 0;
    }
    ll dp[11][10] ;//i digit number starting from j 
    memset(dp,0,sizeof(dp));
    repp(i,0,11) dp[1][i]=1;
    for(i=2;i<11;++i)
    {
        for(j=0;j<=9;++j)
        {
            if(j==0)
            {
                dp[i][j]=dp[i-1][0] + dp[i-1][1];
            }
            else if(j==9)
            {
                dp[i][j]+=dp[i-1][j-1] + dp[i-1][j];
            }
            else
            {
                dp[i][j]+=dp[i-1][j-1] + dp[i-1][j] + dp[i-1][j+1] ;
            }
            
        }
    }
    //rep(i,11) dp[i][0]=0;
    vector<ll> v;
    for(i=1;i<11;++i)
    {
        for(j=1;j<=9;++j)
        {
            f+=dp[i][j];
            if(f>=k) break;
        }
        if(f>=k) break;
    }
    v.pb(j);
    f-=dp[i][j];
    k-=f;
    i--;
    while(k&&i)
    {
        if(j!=0)
        {if(dp[i][j-1]>=k)
        {
            v.pb(j-1);
            i--;
            j--;
            continue;
            
        }
        else k-=dp[i][j-1];
        }
        if(dp[i][j]>=k)
        {
            v.pb(j);
            i--;
            
            continue;
            
        }
        else k-=dp[i][j];
        if(j!=9)
        {if(dp[i][j+1]>=k)
        {
            v.pb(j+1);
            i--;
            j++;
            continue;
            
        }
        }
        
    }
    for(i=0;i<v.size();++i)
    {
        cout << v[i];
        
    }
    return 0;
}


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

using namespace std;


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

	long long s = 0;
	for (int i = 1; i <= m; ++i)
	{
		long long x = 0;
		cin >> x;
		s += x;
	}

	if (n - s < 0)
		cout << "-1\n";
	else
		cout << (n - s) << "\n";

	return 0;
}

Measured memory_bytes: 3620
n = int(input())
s = list(input())

max_interval = (n-3)//2+1

exception = 0

for interval in range(1,max_interval+1):
    for i in range(n-interval*2):
        if s[i]!=s[i+interval] and s[i+interval]!=s[i+2*interval] and s[i+2*interval]!=s[i]:
            exception += 1

allc = s.count("R")*s.count("G")*s.count("B")

print(allc-exception)

Measured memory_bytes: 68452
#include <stdio.h>

int A[1000000],n;

bool search (int *A,int key)
{
	int mid,r,l;
	l=0;r=n;
	while (l<r)
	{
		mid=(r+l)/2;
		if (A[mid]==key) return true;
		if (A[mid]<key) l=mid+1;
		else if (A[mid]>key) r=mid;
	}
	return false;
}

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


Measured memory_bytes: 2912
def resolve():
    lower = "abcdefghijklmnopqrstuvwxyz"
    N = int(input())    

    ans = ""
    while N > 26:
        idx = N % 26
        ans += lower[idx-1]
        N = -(-N//26)-1
    idx = N % 26
    ans += lower[idx - 1]
    print(ans[::-1])

if __name__ == "__main__":
    resolve()


Measured memory_bytes: 9180
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

s = rs()
t = rs()


import collections
pos = collections.defaultdict(list)
for i, c in enumerate(s):
	pos[c].append(i)

import bisect

def search(arr, x):
	l, r = 0, len(arr)
	while r-l >= 1:
		mid = (r+l)//2
		if x < arr[mid]:
			r = mid
		else:
			l = mid+1
	return l

num = 0
cur = -1

for c in t:
	if c not in pos:
		print(-1)
		exit()
	#i = bisect.bisect_right(pos[c], cur)
	i = search(pos[c], cur)
	if i == len(pos[c]):
		i = 0
		num += 1
	cur = pos[c][i]
print(num*len(s)+cur+1)



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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const ll mod = 1e9+7;
constexpr ll inf = ((1<<30)-1)*2+1 ;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0,1,-1,1,-1};
const int dx[] = {0,-1,0,1,1,-1,-1,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

ll n;
ll s = 0;
ll ans = inf;

ll f(ll s){
  return (s > 0 ? -1 : 1) * (abs(s) + 1);  
}
inline int sgn(ll a,ll b = 0) { return a < b ? -1 : a > b ? 1 : 0; }

void solve(vector<ll> v){
  vector<ll> a(n),b(n);
  a[0] = 1;
  b[0] = -1;
  rep(i,n-1){
    a[i+1] = -1 * a[i]; 
    b[i+1] = -1 * b[i];
  }
  ll ca = 0,cb = 0;
  auto v2 = v;
  auto v3 = v;
  rep(i,n){
    if(sgn(s + v[i]) != sgn(a[i])){
      v3[i] = a[i] - s;
      ca += abs(v3[i] - v[i]);
    }
    s += v3[i];
  }
  v = v2;
  v3 = v2;
  s = 0;
  rep(i,n){
    if(sgn(s + v[i]) != sgn(b[i])){
      v3[i] = b[i] - s;
      cb += abs(v3[i] - v[i]);
    }
    s += v3[i];
  }
  ans = min(ca,cb);
}
bool judge(vector<ll> v){
  ll s = 0;
  REP(i,0,n-1){
    s += v[i];
    if(s == 0) return false;
    if(sgn(s) == sgn(s + v[i+1])) return false;
  }
  return true;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  vector<ll> v(n);
  rep(i,n){
    cin >> v[i];
  }
  if(!judge(v)){
    solve(v);
    std::cout << ans << std::endl;
  }
  else
    std::cout << 0 << std::endl;
  return 0;
}


Measured memory_bytes: 4976
#include<bits/stdc++.h>
using namespace std;
long long n;
long long x;
long long ans=1;
int main()
{
	cin>>x;
	while(x)
	{
		x/=2;
		++n;
	}
	for(int i=1;i<=n;++i)
	   ans*=2;
	ans--;
	cout<<ans<<endl;
	return 0;
 } 

Measured memory_bytes: 3564
#include<bits/stdc++.h>
#include<map>
using namespace std;
int main()
{
	map<int,int> mp;
	int run;
	cin>>run;
	for(int i=0;i<run;i++)
	{
		int a;
		cin>>a;
		mp[a]++;
	}
	map<int,int>::iterator it;
	for(it = mp.begin();it!=mp.end();it++)
	{
		if(it->second>1)
		{
			cout<<"NO"<<endl;
			return 0;
		}
	}
	cout<<"YES"<<endl;
	return 0;
 } 

Measured memory_bytes: 9600
#![allow(non_snake_case)]
#![allow(unused_imports)]
use ascii::AsciiChar;
use ascii::AsciiStr;
use itertools::Itertools as _;
use permutohedron::LexicalPermutation as _;
use petgraph::algo::dijkstra;
use petgraph::algo::min_spanning_tree;
use petgraph::data::FromElements;
use petgraph::graph::NodeIndex;
use petgraph::graph::UnGraph;
use petgraph::unionfind::UnionFind;
use proconio::fastout;
use proconio::input;
use proconio::marker::Chars;
use proconio::marker::Usize1;
use std::cmp::max;
use std::cmp::min;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use superslice::Ext as _;

#[fastout]
fn main() {
    input! {
        N: usize,
        mut As: [i64; N],
    }

    As.sort();

    // 1個だけマイナスにしたい場合 As[N-1] - (((As[0] - b) - c) -d)
    // 2個だけマイナスにしたい場合 (As[N-1] - ((As[0] - b) - c)) - As[1]
    // 以下同様

    // 何個マイナスにしたいか?
    let minus_cnt: usize = min(N - 1, max(1, As.iter().filter(|&a| *a < 0).count()));

    // // 特殊パターン :
    // if minus_cnt == N {

    //     return ;
    // }

    let mut outputs: Vec<String> = Vec::new();

    let mut generated = As[0] - As[minus_cnt];

    if minus_cnt == N - 1 {
        // A[N-1] - A[0] - A[1] - ...
        let msg0 = format!("{} {}", As[N - 1], As[0]).to_string();
        outputs.push(msg0);
        generated = As[N - 1] - As[0];

        for i in 1..N - 1 {
            let msg = format!("{} {}", generated, As[i]).to_string();
            outputs.push(msg);
            generated = generated - As[i];
        }

        println!("{}", generated);
        for s in outputs.iter() {
            println!("{}", s);
        }
    } else {
        let msg0 = format!("{} {}", As[0], As[minus_cnt]).to_string();
        outputs.push(msg0);

        for i in minus_cnt + 1..N - 1 {
            let msg = format!("{} {}", generated, As[i]).to_string();
            outputs.push(msg);
            generated -= As[i];
        }

        let msg = format!("{} {}", As[N - 1], generated).to_string();
        outputs.push(msg);
        generated = As[N - 1] - generated;

        for i in 1..minus_cnt {
            let msg = format!("{} {}", generated, As[i]).to_string();
            outputs.push(msg);
            generated -= As[i];
        }

        println!("{}", generated);
        for s in outputs.iter() {
            println!("{}", s);
        }
    }
}


Measured memory_bytes: 9028
from collections import deque

n, m = map(int, input().split())
G = [[]for i in range(n+1)]

# グラフ生成
for i in range(m):
    a, b = map(int, input().split())
    G[a].append(b)
    G[b].append(a)
 
ans = [0]*(n+1)
 
stk = deque([1])
 
# BFS 幅優先探索
while stk:
    v = stk.pop()
    for s in G[v]:
        # 未到達ノードであれば、キューに追加
        if ans[s] == 0:
            ans[s] = v
            stk.appendleft(s)
ans = ans[2:]
 
if 0 in ans:
    print("No")
else:
    print("Yes")
    for i in ans:
        print(i)

Measured memory_bytes: 34592
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE

map<vector<int>,int > mem;
int dfs(vector<int> stone){
  if(stone.empty()) return 0;
  if(mem.count(stone)) return mem[stone];
  
  int n = stone.size();
  set<int> S;
  for(int i=1;i<(1<<n);i++){
    auto nStone = stone;
    for(int j=0;j<n;j++) if(i>>j & 1) nStone[j]--;
    sort(nStone.begin(), nStone.end(), greater<int>());
    while(nStone.size() && nStone.back() == 0) nStone.pop_back();
    int x = dfs(nStone);
    S.insert(x);
  }
  int x = 0;
  while(S.count(x)) x++;
  return mem[stone] = x;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  /*
  for(int i=1;i<=10;i++)
    for(int j=i;j<=10;j++){
      int res = dfs({i, j});
      if(res == 0) pr(i, j);
    }
  
  for(int i=1;i<=10;i++)
    for(int j=i;j<=10;j++)
      for(int k=j;k<=10;k++){
	int res = dfs({i, j, k});
	if(res == 0) pr(i, j, k);
    }
  
  for(int i=1;i<=10;i++)
    for(int j=i;j<=10;j++)
      for(int k=j;k<=10;k++)
	for(int l=k;l<=10;l++){
	  int res = dfs({i, j, k,l});
	  if(res == 0) pr(i, j, k,l);
    }
  */

  int N;
  cin>>N;
  vector<int> A(N);
  cin>>A;
  int ans = 0;
  for(int i=0;i<N;i++) if(A[i]%2) ans = 1;
  cout<<(ans? "first":"second")<<endl;
  

  return 0;
}


Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()
{
    long long int n;
    long long int ans = 0;
    cin >> n;
    int start = n;
    if(n - 1000000 > 0){
      start = 1000000;
    }
    for(int i = 1; i < start; i++){
      if((n - i) % i == 0 && (n / ((n - i) / i)) == i){
        ans += (n - i) / i;
      }
    }
    cout << ans << endl;
    return 0;
}

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

import sys
import copy

sys.setrecursionlimit(1000000)

# input = sys.stdin.readline

# ~~~~~~~~~~~~~~~~~~~~~_(＾～＾ ｣ ∠)_~~~~~~~~~~~~~~~~~~~~~

N, K = map(int, input().split())

S = input().rstrip()

print(S[:K - 1] + S[K - 1].lower() + S[K:])


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

using namespace std;

int num(int64_t n) {
    string s(to_string(n));
    return s.size();
}

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

    vector<int64_t> arr;
    int64_t ans = INT64_MAX;
    for (int64_t i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            int64_t one = i;
            int64_t other = N / i;
            int64_t f = max(
                num(one),
                num(other)
            );
            ans = min(ans, f);
        }
    }

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


Measured memory_bytes: 256