akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
 
  ll n, s; cin >> n >> s;
  if(n == s) {
    cout << n + 1 << endl; return 0;
  }
  if(s > n) {
    cout << -1 << endl; return 0;
  }
  ll b = 2;
  for(; b * b <= n; b++) {
    ll N = n;
    ll f = 0;
    while(N != 0) {
      f += N % b;
      N /= b;
    }
    if(f == s) {
      cout << b << "\n";
      return 0;
    }
  }
  ll N = n - s;
  ll sqt;
  for(ll i = 1; i * i <= N; i ++) sqt = i;
  for(ll i = sqt; i >= 1; i--) {
    if(N % i == 0) {
      ll j = N / i;
      if(s >= i && s <= i + j) {
        cout << j + 1 << endl; return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}

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

using namespace std;

int main(int argc, char const *argv[])
{
    
    int r[200000], n, i;
    cin >> n;
    for(i = 0; i < n; i++) cin >> r[i];
    
    int maxv = -2000000000, minv = r[0];
    
    for(i = 1; i < n; i++)
    {
        maxv = max(maxv, r[i] - minv);
        minv = min(minv, r[i]);
    }
    
    cout << maxv << endl;
}

Measured memory_bytes: 3836
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
		a[i]--
	}
	c := 0
	isPassed := make([]bool, n)
	isPassed[0] = true
	rest := n
	now := make(map[int]struct{})
	now[0] = struct{}{}
	for rest > 0 && len(now) > 0 {
		next := make(map[int]struct{})
		for k := range now {
			if !isPassed[a[k]] {
				if a[k] == 1 {
					fmt.Println(c + 1)
					return
				}
				isPassed[a[k]] = true
				next[a[k]] = struct{}{}
				rest--
			}
		}
		c++
		now = next
	}
	fmt.Println(-1)
}


Measured memory_bytes: 5504
N=int(input())
mod=10**9+7
c=list(map(int,input().split()))
c.sort()

ans=0
cnt=pow(4,N-1,mod)
for i in range(N):
    ans +=cnt*2*c[i] + cnt*(N-1-i)*c[i]
    ans%=mod
    
print(ans)



Measured memory_bytes: 87500
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
 
const int MOD=1e9+7;

ll myPow(ll x, ll n){
  if(n == 0) return 1;
  if(n % 2 == 0) return myPow(x * x % MOD, n / 2);
  else return x * myPow(x, n - 1) % MOD;
}


int main() {
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans=myPow(2,n)-1;
    ll c = (a>b) ? a : b;
    vector<ll> inv(c+1);
    inv[0]=1;
    inv[1]=1;
    for (ll i = 2;i <= c; i++) {
        inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    ll aans=n,bans=n;
    for (int i = 2;i <= a;i++) {
        aans *= ((n-i+1)*inv[i])%MOD;
        aans=aans%MOD;
    }
    
    for (int i = 2;i <= b;i++) {
        bans *= ((n-i+1)*inv[i])%MOD;
        bans=bans%MOD;
    }
    ans=(ans-aans-bans+2*MOD)%MOD;
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
template<typename V>
bool tomin(V&x,V y){if(y<x){x=y;return true;}return false;}
template<typename V>
bool tomax(V&x,V y){if(x<y){x=y;return true;}return false;}
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
#define lowbit(x) ((x)&-(x))
const int M=1e5+5;
int n,B[M];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&B[i]);
        B[i]+=B[i];
    }
    ll now=0;
    for(int i=1;i<=n;i++){
        if(i%2)now+=B[i];
        else now-=B[i];
    }
    cout<<now/2;
    now/=2;
    for(int i=2;i<=n;i++){
        now=B[i-1]-now;
        cout<<" "<<now;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 1664
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

N,M,X,Y = I()
x = l()
y = l()
x1 = max(x)
y1 = min(y)
for z in range(X+1,Y+1):
    if x1 < z and y1 >= z:
        print('No War')
        exit()
print('War')

Measured memory_bytes: 10116
n,K = map(int,input().split())
xy = [[int(i) for i in input().split()] for j in range(n)]

ans = 10**20

for i in range(n):
    for j in range(i+1,n):
        if K == 2:
            ans = min(ans,abs(xy[i][0]-xy[j][0])*abs(xy[i][1]-xy[j][1]))
        for k in range(j+1,n):
            if K == 2:
                break
            max_x_old = max(xy[i][0],xy[j][0],xy[k][0])
            min_x_old = min(xy[i][0],xy[j][0],xy[k][0])
            max_y_old = max(xy[i][1],xy[j][1],xy[k][1])
            min_y_old = min(xy[i][1],xy[j][1],xy[k][1])
            if K == 3:
                #max_x = max(xy[i][0],xy[j][0],xy[k][0])
                #min_x = min(xy[i][0],xy[j][0],xy[k][0])
                #max_y = max(xy[i][1],xy[j][1],xy[k][1])
                #min_y = min(xy[i][1],xy[j][1],xy[k][1])
                ans = min(ans,abs(max_x_old-min_x_old)*abs(max_y_old-min_y_old))
            for l in range(k+1,n):
                if K == 2 or K == 3:
                    break
                cnt = 0
                max_x = max(max_x_old,xy[l][0])
                min_x = min(min_x_old,xy[l][0])
                max_y = max(max_y_old,xy[l][1])
                min_y = min(min_y_old,xy[l][1])
                for m in range(n):
                    if xy[m][0] >= min_x and xy[m][0] <= max_x\
                       and xy[m][1] >= min_y and xy[m][1] <= max_y:
                           cnt += 1
                if cnt >= K:
                    #print(cnt,K)
                    ans = min(ans,(max_x-min_x)*(max_y-min_y))
                
print(ans)

Measured memory_bytes: 97496
#include<bits/stdc++.h>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int i,a=0,b=0;
  for(i=0;i<s.size();++i)
  {
    if(s[i]=='A')
      a++;
    else
      b++;
  }
  if(a>0 and b>0)
    cout<<"Yes";
  else
    cout<<"No";
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] symbols = br.readLine().split(" ");

        Stack stack = new Stack();

        for (String symbol : symbols) {
            try {
                int n = Integer.parseInt(symbol);
                stack.push(n);
            } catch (NumberFormatException e) {
                int a = stack.pop();
                int b = stack.pop();
                int result = calculate(b, a, symbol);
                stack.push(result);
            }
        }

        System.out.println(stack.pop());

    }

    private static int calculate(int a, int b, String symbol) {
        switch (symbol) {
            case "+":
                return a + b;
            case "-":
                return a - b;
            case "*":
                return a * b;
            default:
                throw new RuntimeException();
        }
    }

    public static class Stack {
        private int[] stacks;
        private int top;

        public Stack() {
            stacks = new int[100];
            top = 0;
        }

        public void push(int stack) {
            stacks[top] = stack;
            top++;
        }

        public int pop() {
            top--;
            return stacks[top];
        }
    }

}



Measured memory_bytes: 24492
import java.util.*;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
	int p[] = new int[n];
	int i=0;
	int previous_is_met=0;
	int sum=0;
	int k=0;
        for(i=0;i<n;i++) p[i] = sc.nextInt();
        for(i=0;i<n;i++){
	    if(p[i] == (i+1)){
		if(previous_is_met == 0) previous_is_met = 1;
		k++;
            }else{
		if(previous_is_met == 1){
                    previous_is_met = 0;
                    sum=sum + k/2 + k%2;
                    k =	0;
                }
            }
        }
	sum = sum + k/2	+ k%2;
        System.out.println(sum);
    }
}


Measured memory_bytes: 50684
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<stack>
#include<map>
#include<queue>
#include<vector>
#include<cmath>
#include<set>
#define inf 0x3f3f3f3f
#define lowbit(x) (x&-x)
typedef long long ll;

const int maxn=1e5+5;
const int mod=1e9+7;

using namespace std;
ll a,b,c,x;

int main()
{
    scanf("%lld%lld%lld",&a,&b,&c);
    if(c>=b)
        printf("%lld\n",a*(b-1)/b);
    else
        printf("%lld\n",a*c/b);
}


Measured memory_bytes: 3240
#include <iostream>
#include <algorithm>
#include <string> 
#include <math.h>
#include <set>
#include <vector>
#define rep(i,n) for(int i=0; i< (int)(n); ++i)
using namespace std;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
 
    int n,y;
    cin >> n >> y;
    int ans10000 = -1;
    int ans5000 = -1;
    int ans1000 = -1;
    for(int a=0; a<=n; ++a ){
    	for(int b=0; (a+b) <= n; ++b){
    		int c = n-a-b;
    		int total = 10000*a + 5000*b + 1000*c;
    		if(total==y) {
    			ans10000 = a;
    			ans5000 = b;
    			ans1000 = c;
    		}
    	}
    }
    cout << ans10000 << " " << ans5000 << " " << ans1000 << "\n";



	
} 


Measured memory_bytes: 256
def main():
    N, M = map(int, input().split())
    sc = [list(map(int, input().split())) for _ in range(M)]

    for i in range(1000):
        tmp = str(i).zfill(3)

        if N == 2 and (i <= 9 or i >= 100):
            continue
        elif N == 3 and i <= 99:
            continue
        elif N == 1 and i > 9:
            continue

        flag = True
        for q in sc:
            if tmp[q[0]-1-(N-3)] != str(q[1]):
                flag = False
        if flag:
            print(i)
            exit()

    print(-1)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65864
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,l,a=0,b=100000;
    bool f=0;
    cin>>n>>l;
    fr(i,n){
        a+=l;
        if(abs(l)<b){
            b=abs(l);
            f=(l>0);
        }
        ++l;
    }
    cout<<a-(f?b:-b)<<endl;
}

Measured memory_bytes: 256
loop do
  m,f,r=gets.split.map(&:to_i)
  break if m == -1 && f == -1 && r == -1
  sum = m + f
  a = if m == -1 || f == -1
        'F'
      elsif sum >= 80
        'A'
      elsif sum >= 65
        'B'
      elsif sum >= 50
        'C'
      elsif sum >= 30
        r >= 50 ? 'C' : 'D'
      else
        'F'
      end
  puts a
end

Measured memory_bytes: 6092
import java.io.InputStreamReader
import java.io.BufferedReader

//
fun _Do(){
    
    val scanEx = ScannerEx()
    
    //
    /*val N =*/ scanEx.nextInt()
    val ai = scanEx.ints()
    
    var count = 0
    var prev = false
    for(p in ai.indices){
        when(prev){
            true-> prev = false
            false -> {
                if( ai[p] == (p+1) ){
                    count+=1
                    prev = true
                }
            }
        }
    }
    println(count)

}

//
fun main( argv : Array<String> ) {
    _Do()
}

//
class ScannerEx {
    fun nextString():String{
        if( idx == 0 || strings.size <= idx)
        {
            idx = 0
            strings = bufferedReader.readLine().split(' ')
        }
        var v = strings[idx]!!
        idx += 1
        return v
    }
    fun nextInt():Int{
        if( idx == 0 || strings.size <= idx )
        {
            idx = 0
            strings = bufferedReader.readLine().split(' ')
        }
        var v = strings[idx]!!.toInt()
        idx += 1
        return v
    }
    fun nextLong():Long{
        if( idx == 0 || strings.size <= idx)
        {
            idx = 0
            strings = bufferedReader.readLine().split(' ')
        }
        var v = strings[idx]!!.toLong()
        idx += 1
        return v
    }
    private var idx:Int = 0 //
    private var strings:List<String?> = emptyList()   //
    fun strings(): Array<String> {
        val strings = bufferedReader.readLine().split(' ')
        return Array(strings.size, { strings[it] })
    }
    fun ints(): Array<Int> {
        val strings = bufferedReader.readLine().split(' ')
        return Array(strings.size, { strings[it].toInt() })
    }
    fun longs(): Array<Long> {
        val strings = bufferedReader.readLine().split(' ')
        return Array(strings.size, { strings[it].toLong() })
    }
    private var bufferedReader = BufferedReader(InputStreamReader(System.`in`))
}


Measured memory_bytes: 48908
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;

ll v[53];

int n, A, B;

double ans = 0;

bool cmp(int x, int y) {return v[x] > v[y];}

const int p = 1000000007;

int jc(int num) {
	int ret = 1;
	for (int i = 2; i <= num; ++i)
		ret = 1ll * ret * i % p;
	return ret;
}

int ipow(int a, int b) {
	int ret = 1, w = a;
	while (b) {
		if (b & 1) ret = 1ll * ret * w % p;
		w = 1ll * w * w % p;
		b >>= 1;
	}
	return ret;
}

ll C[53][53];

int main() {
	cin >> n >> A >> B;
	for (int i = 1; i <= n; ++i) cin >> v[i];
	stable_sort(v + 1, v + n + 1);
	reverse(v + 1, v + n + 1);
	
	double ans = 0;
	for (int i = 1; i <= A; ++i) ans += v[i];
	int tot = A, tt = 0;
	bool flag = true;
	for (int i = 1; i <= A; ++i) {
		if (v[i] == v[A]) continue;
		else flag = false;
	}
	
	C[0][0] = 1;
	for (int i = 1; i <= n; ++i) {
		C[i][0] = 1;
		for (int j = 1; j <= i; ++j)
			C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
	}
	
	if (flag) {
		cout << v[1] << endl;
		int sum = A; tt = 0;
		for (int i = A + 1; i <= n; ++i)
			if (v[i] == v[A]) ++tt;
		
		ll S = 0;
		for (int i = sum; i <= min(sum + tt, sum + B - A); ++i)
			S += C[sum + tt][i];
		cout << S << endl;
		return 0;
	}
	
	printf("%.7lf\n", ans / tot);
	tt = 0;
	for (int i = A + 1; i <= n; ++i) if (v[i] == v[tot]) ++tt;
	int sum = 0;
	for (int i = 1; i <= tot; ++i)
		if (v[i] == v[tot]) ++sum;
	cout << C[sum + tt][sum] << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define inf 1e9
#define F first
#define S second
#define dbg(x) cout<<#x<<" value : "<<x<<"\n";
#define rep(i,j,k) for(int i = (j); i <= (k); i++)
#define rep__(i,j,k) for(int i = (j); i < (k); i++)
#define per(i,j,k) for(int i = (j); i >= (k); i--)
#define per__(i,j,k) for(int i = (j); i > (k); i--)
#define mst(a,b) memset(a,b,sizeof(a))
#define sf(n) scanf("%d",&n)
#define stf(n,m) scanf("%d%d",&n,&m)
#define pf(n) printf("%d\n",n)
#define sllf(n) scanf("%lld",&n)
#define pllf(n) printf("%lld\n",n)
priority_queue<int,vector<int>,greater<int> > q;
const int N=1e2+10;
const int mod=1e9+7;
int n,a[N];
LL sum;
int main()
{
	sf(n);
	rep(i,1,n)sf(a[i]);
	rep(i,1,n){
		rep(j,i+1,n)sum+=a[i]*a[j];
	}
	cout<<sum;
	return 0;
}

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

vector<vector<int>> MOVE_A = {{0,1},{0,-1},{1,0},{-1,0}};
vector<int> MOVE_B = {-2, -1, 0, 1, 2};


void bfs(int Sh, int Sw, vector<string> &S, vector<vector<bool>> &visited, queue<pair<int,int>> &now_pos) {
  queue<pair<int,int>> q;
  q.push(make_pair(Sh, Sw));
  int h, w, y, x;
  while (!q.empty()) {
    tie(h, w) = q.front(); q.pop();
    now_pos.push(make_pair(h, w));
    for (auto next: MOVE_A) {
      y = h + next[0];
      x = w + next[1];
      if (S[y][x] == '#') continue;
      if (visited[y][x]) continue;
      q.push(make_pair(y, x));
      visited[y][x] = true;
    }
  }
}


void move_b(int Sh, int Sw, vector<string> &S, vector<vector<bool>> &visited, queue<pair<int,int>> &next_pos) {
  int h, w;
  for (int i: MOVE_B) {
    h = Sh + i;
    for (int j: MOVE_B) {
      w = Sw + j;
      if (S[h][w] == '#') continue;
      if (visited[h][w]) continue;
      next_pos.push(make_pair(h, w));
      visited[h][w] = true;
    }
  }
}


int main() {
  int H, W, Ch, Cw, Dh, Dw;
  cin >> H >> W >> Ch >> Cw >> Dh >> Dw;
  Ch++; Cw++; Dh++; Dw++;
  vector<string> S(H + 4);
  for (int i: {0, 1, H + 2, H + 3}) {
    S[i] = string(W + 4, '#');
  }
  string s;
  for (int i = 2; i < H + 2; i++) {
    cin >> s;
    S[i] = "##" + s + "##";
  }

  int ans = 0;
  vector<vector<bool>> visited(H + 4, vector<bool>(W + 4, false));
  queue<pair<int,int>> now_pos;
  queue<pair<int,int>> next_pos;
  next_pos.push(make_pair(Ch, Cw));
  visited[Ch][Cw] = true;
  int h, w;
  while (true) {
    while (!next_pos.empty()) {
      tie(h, w) = next_pos.front(); next_pos.pop();
      bfs(h, w, S, visited, now_pos);
    }

    if (visited[Dh][Dw]) break;

    while (!now_pos.empty()){
      tie(h, w) = now_pos.front(); now_pos.pop();
      move_b(h, w, S, visited, next_pos);
    }
    if (next_pos.empty()) {
      ans = -1;
      break;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 5832
#define ll long long
#define MOD 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define set2d(array, val, m, n) memset(array, val, sizeof(array[0][0]) * m * n);
#include <bits/stdc++.h>
using namespace std;
ll power(ll x, ll y, ll p)
{
  ll res = 1;
  x %= p;
  while (y > 0)
  {
    if (y & 1)
      res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
ll po(ll base, ll powerRaised)
{
  if (powerRaised != 0)
    return (base * po(base, powerRaised - 1));
  else
    return 1;
}
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  string u, s, t;
  ll a, b;
  cin >> s >> t >> a >> b >> u;
  if (u == s)
    a--;
  else
    b--;
  cout << a << " " << b;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
 int N, K;
 int A =0;
  cin >> N >> K ;
  rep(i, N) {
 int x;
 cin >> x;
 if(K-x>=x){
 A += x;
 }
 else {
  A+= K-x;
 }
 }
cout  << A*2 << endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <array>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <utility>
#include <assert.h>
#include <regex>
#include <numeric>
#include <functional>
#include <iomanip>
using namespace std;

typedef unsigned long long ull;
typedef signed long long ll;
#define INF (1LL << 48)

struct PT { ll x; ll y; };
string to_s(ull x) { return to_string(x); }
string to_s(ll x) { return to_string(x); }
ll to_ll(const string& x) { return stoll(x); }
ull to_ull(const string& x) { return stoull(x); }




int main(int argc, char* argv[])
{
	cout << std::fixed << std::setprecision(10);

	for (;;) {
		ll N, X;

		cin >> N >> X;
		if (cin.fail()) break;

		vector<int> A(N);
		for (int i = 0; i < N; i++) {
			cin >> A[i];
		}
		vector<int> S(N, INT_MAX);
		ll res = INF;
		for (ll i = 0; i < N; i++) {
			int old = S[N - 1];
			for (ll j = N - 1; j > 0; j--) {
				S[j] = S[j - 1];
			}
			S[0] = old;

			ll r = i * X;
			for (int j = 0; j < N; j++) {
				S[j] = min(S[j], A[j]);
				r += S[j];
			}
			res = min(res, r);
		}
		cout << res << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1e9+7
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long int lo;

vector<string> str;


int main(){
    string a;
    lo n,m;
    cin >> n >> m;
    for(lo i = 0;i < n;i++) {
        cin >> a;
        str.pb(a);
    }
    sort(str.begin(),str.end());
    for(lo i = 0;i < n;i++) cout << str[i];
}

Measured memory_bytes: 256
from math import log2

L = int(input())
n = int(log2(L))
print(n + 1, format(L, "b").count("1") - 1 + 2 * n)
Li = 1
for i in range(n):
    print(i + 1, i + 2, 0)
    print(i + 1, i + 2, Li)
    Li *= 2
mask = 2
for i in range(n):
    if L >> i & 1:
        print(i + 1, n + 1, L - (L & mask - 1))
    mask *= 2


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

#define ll long long

#define all(a) a.begin(),a.end()
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define output_s(a) printf("%s\n",(a).c_str())

//library----------------------------------------------


int main(){
    int x,a; cin>>x>>a;
  	if(x<a) printf("0");
  	else if(x>=a) printf("10");
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		String ans = "No";

		for(int j =0; j <= N /4; j++)
			for(int k = 0; k <= N / 7; k++){
					if(4*j + 7*k == N) ans = "Yes";
			}

			System.out.println(ans);

	}
}

Measured memory_bytes: 21844
/****************************
https://witacm.com/problem.php?pid=1507

Time	126	  	ms	
Memory	64676	MB
****************************/
# include <iostream>
# include <cstdio>
# include <cstring> 

const int maxn = 4e3 + 5;
int L[maxn][maxn];

int lcs(char* X, char* Y, int m, int n) {
	/* Following steps build L[m+1][n+1] in bottom up fashion. Note
	  that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
	for (int i = 1; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			 if (X[i - 1] == Y[j - 1]) {
				L[i][j] = L[i - 1][j - 1] + 1;
			} else {
				L[i][j] = std::max(L[i - 1][j], L[i][j - 1]);
			}
		}
	}

	return L[m][n];
}

int main() {
	char* x = new char[maxn];
	char* y = new char[maxn];
	scanf("%s", x);
	scanf("%s", y);

	int m = strlen(x);
	int n = strlen(y);

	int index = lcs(x, y, m, n);
	
	char* lcc = new char[index + 1];
	lcc[index] = '\0';
	
	int i = m;
	int j = n;
	while (i > 0 && j > 0) {
		if (x[i - 1] == y[j - 1]) {
			lcc[index - 1] = x[i - 1];
			i--;
			j--;
			index--;
		} else if (L[i - 1][j] > L[i][j - 1]) {
			i--;
		} else {
			j--;
		}
	}
	
	printf("%s", lcc);
	
	return 0;
}


Measured memory_bytes: 50120
#include <cstdio>
#include <algorithm>

using namespace std;

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

    int ans = 0;
    int maxh = -1;
    for (int i = 0; i < N; i++)
    {
        int h;
        scanf("%d", &h);
        if (h >= maxh)
        {
            ans++;
            maxh = h;
        }
    }

    printf("%d\n", ans);
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
  int n;
  bool zero = false;
  cin >> n;
  vector<ll> nums(n);
  rep(i,n){
  cin >> nums[i];
  if(nums[i] == 0){zero = true;break;}
  }
  ll ans = 0;
  if(!zero){
  ans = 1;
  rep(i,n){
    if(ans > powl(10,18)/nums[i]){
      ans = -1;
      break;
    }
    ans *= nums[i];
  }
  }
  cout << ans << endl;
}


Measured memory_bytes: 4056
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<stack>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
char a[5];

int main()
{
	scanf("%s", a + 1);
	int len = strlen(a + 1);
	if(len == 2) {
		for(int i = 1; i <= 2; i++) {
			printf("%c", a[i]);
		}
		printf("\n");
	}
	else if(len == 3) {
		for(int i = 3; i >= 1; i--) {
			printf("%c", a[i]);
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=998244353;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*invkaijo[a-b]%mod*invkaijo[b]%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
int calc(int a,int b,int &x,int &y){
    if(b==0){
        x=1;
        y=0;
        return a;
    }
    int d=calc(b,a%b,y,x);
    y-=a/b*x;
    return d;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m,ans;
    vector<int>v;
    map<int,int>mp;
    cin>>n;
    n*=2;
    ans=n-1;
    for(int i=2;i*i<=n;i++){
        while(n%i==0){
            mp[i]++;
            n/=i;
        }
    }
    if(n>1)mp[n]++;
    for(P p:mp){
        int x=1;
        rep(i,p.se)x*=p.fi;
        v.pb(x);
    }
    m=v.size();
    //m<=13
    rep(i,(1<<m)){
        int a=1,b=1;
        rep(j,m){
            if((i>>j)&1)a*=v[j];
            else b*=v[j];
        }
        rep(_,2){
            int x,y;
            calc(-a,b,x,y);
            if(x<=0||y<=0){
                int ret=0;
                if(x<=0)chmax(ret,(-x)/b+1);
                if(y<=0)chmax(ret,(-y)/a+1);
                y+=a*ret,x+=b*ret;
            }
            chmin(ans,b*y);
            swap(a,b);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3664
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

int main() {
  i64 K, N;
  std::cin >> K >> N;
  std::vector<i64> A;
  tools::read(A, N);

  std::vector<i64> diffs;
  diffs.reserve(N);
  for (i64 i = 1; i < N; ++i) {
    diffs.push_back(A[i] - A[i - 1]);
  }
  diffs.push_back(K + A.front() - A.back());

  std::cout << std::accumulate(diffs.begin(), diffs.end(), static_cast<i64>(0)) - *std::max_element(diffs.begin(), diffs.end()) << std::endl;
  return 0;
}

Measured memory_bytes: 3328
#include <stdio.h>

using namespace std;

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

	for(int i = 1; i<= n; i++)
	{
		if(i%3 == 0){
			printf(" %d",i);
		}else{
			x = i;
			do{
				if(x%10 == 3){
					printf(" %d",i);
					break;
				}
				x /=10;
			}while(x);
		}
	}
	printf("\n");
}


Measured memory_bytes: 2756
#include<iostream>
using namespace std;
int t[2000],u[2000];
int a[2000000],b[2000000];
int N,M;
int main(){
  while(1){
    cin>>N>>M;
    if(N==0&&M==0)break;
    for(int i=0;i<2000000;i++)a[i]=b[i]=0;
    for(int i=1;i<=N;i++)cin>>t[i],t[i]+=t[i-1];
    for(int i=1;i<=M;i++)cin>>u[i],u[i]+=u[i-1];
    for(int i=1;i<=N;i++)
      for(int j=i;j<=N;j++)
    a[t[j]-t[i-1]]++;
    for(int i=1;i<=M;i++)
      for(int j=i;j<=M;j++)
    b[u[j]-u[i-1]]++;
    int ans=0;
    for(int i=0;i<2000000;i++)ans+=a[i]*b[i];
    cout<<ans<<endl;
  }
  return 0;
}


Measured memory_bytes: 18584
N, X, Y = map(int,input().split())

ans = [0] * (N - 1)

for i in range(N - 1):
    vst = [False] * N
    q = [(i, 0)]
    vst[i] = True
    for u, c in q:
        if i < u: ans[c - 1] += 1
        next = [u + 1, u - 1]
        if u == X - 1:
            next.append(Y - 1)
        if u == Y - 1:
            next.append(X - 1)

        for v in next:
            if 0 <= v < N and not vst[v]:
                q.append((v, c + 1))
                vst[v] = True

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

Measured memory_bytes: 56668
#include <bits/stdc++.h>
using namespace std;
using ll= long long;
#define rep(i,n) for (ll i = 0; i < (n); ++i)

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

  std::cout << n*(n-1)/2+m*(m-1)/2 << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int H, W;
string S[2000];
int L[2000][2000];
int R[2000][2000];
int D[2000][2000];
int U[2000][2000];

void solve() {
    cin >> H >> W;
    for (int i = 0; i < H; ++i) {
        cin >> S[i];
    }
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            char c = S[i][j];
            if (c == '#') {
                L[i][j] = 0;
                U[i][j] = 0;
                continue;
            }
            if (j == 0) {
                L[i][j] = 1;
            } else {
                L[i][j] = L[i][j - 1]+1;
            }
            if (i == 0) {
                U[i][j] = 1;
            } else {
                U[i][j] = U[i-1][j] + 1;
            }
        }
    }
    for (int i = H - 1; i >= 0; --i) {
        for (int j = W - 1; j >= 0; --j) {
            char c = S[i][j];
            if (c == '#') {
                R[i][j] = 0;
                D[i][j] = 0;
                continue;
            }
            if (j == W - 1) {
                R[i][j] = 1;
            } else {
                R[i][j] = R[i][j + 1]+1;
            }
            if (i == H - 1) {
                D[i][j] = 1;
            } else {
                D[i][j] = D[i + 1][j] + 1;
            }
        }
    }
    int ans  = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int m = L[i][j]  + R[i][j] + D[i][j] + U[i][j] - 3;
            if (ans < m) ans = m;
        }
    }
    cout << ans << endl;
}

int main() {
    solve();
    return 0;
}



Measured memory_bytes: 66816
#include <bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
using namespace std;

int main()
{
    int n,m;
    cin>>n;
    vector<int>a(n);
    REP(i,n)cin>>a[i];
    cin>>m;
    vector<int>b(m);
    REP(i,m)cin>>b[i];
    vector<int>c;
    set_symmetric_difference(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
    for(auto i:c)cout<<i<<endl;
}



Measured memory_bytes: 6520
class BinaryTree {
  constructor(n) {
    this.nodes = [];
    for (let i = 0; i < n; i++) this.nodes[i] = {id: i + 1, parentId: -1, leftId: -1, rightId: -1}
  }

  get root() { return this.nodes.find(n => n.parentId === -1); }

  find(id) { return this.nodes[id - 1] || {}; }

  getByPostorder() {
    let res = [];
    const postorder = (id) => {
      if (id === -1) return;
      let n = this.find(id);
      postorder(n.leftId);
      postorder(n.rightId);
      res.push(id);
    };
    postorder(this.root.id);
    return res;
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const preOrder = lines.shift().split(' ').map(Number);
  const inOrder = lines.shift().split(' ').map(Number);

  let tree = makeTree(preOrder, inOrder);
  console.log(tree.getByPostorder().join(' '));
})();

function makeTree(preOrder, inOrder) {
  let tree = new BinaryTree(preOrder.length);
  const innerMakeTree = (p, i) => {
    let midId = p[0];
    let midIdx = i.indexOf(midId);
    if (midIdx === -1) return;
    if (midIdx > 0) {
      tree.find(midId).leftId = p[1];
      tree.find(p[1]).parentId = midId;
      innerMakeTree(p.slice(1, midIdx + 1), i.slice(0, midIdx))
    }
    if (midIdx < i.length - 1) {
      tree.find(midId).rightId = p[midIdx + 1];
      tree.find(p[midIdx + 1]).parentId = midId;
      innerMakeTree(p.slice(midIdx + 1), i.slice(midIdx + 1))
    }
  }
  innerMakeTree(preOrder, inOrder);
  return tree;
}



Measured memory_bytes: 17208
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)

int a[6]={};
int d[6]={};
int next_a[6]={};
vector<int> ans;


bool check(){
  for(int i=0;i<6;i++)
    if(a[i])return true;
  return false;
}

void div(int n){
  int next_a[6]={};
  for(int i=5;i>0;i--){
    next_a[i-1]=a[i];
    a[i-1]-=n*next_a[i-1];
    a[i]=0;
  }
  ans.push_back(n);
  for(int i=0;i<6;i++)
    a[i]=next_a[i];
}


int func(int n){
  int res=0;
  int i;
  for(i=0;i<6;i++)
    res+=a[i]*pow(n,i);
  return res;
}

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

  int i=0,j;
  while(i<s.size()){
    int num=0;
    if(s[i]=='-'){//-
      i++;
      if(s[i]=='x')num=1;
      while(s[i]!='x' && i<s.size()){
	//      	printf("s[%d]=%c\n",i,s[i]);////////
	num=num*10+(s[i]-'0');
	i++;
      }
      //cout<<"num"<<num<<endl;
      // cout<<i<<" "<<s[i]<<endl;//
      if(i==s.size())
	a[0]=-num;
      else if(i+1<s.size() && s[i+1]=='^')
	a[s[i+2]-'0']=-num,i+=3;
      else
	a[1]=-num,i++;
      //  cout<<"i"<<i<<endl;
      //rep(j,6)
      //	printf("a[%d]=%d\n",j,a[j]);
    }else{//+
      if(s[i]=='x'){
	num=1;
      }else{
	i++;
	if(s[i]=='x')num=1;
	while(s[i]!='x' && i<s.size()){
	  //  printf("s[%d]=%c\n",i,s[i]);////////
	  num=num*10+(s[i]-'0');
	  i++;
	}
      }
      //      cout<<"num"<<num<<endl;
      // cout<<i<<" "<<s[i]<<endl;/////
      if(i==s.size())
        a[0]=num;
      else if(i+1<s.size() && s[i+1]=='^')
        a[s[i+2]-'0']=num,i+=3;
      else
	a[1]=num,i++;
      //cout<<"i"<<i<<endl;
      // rep(j,6)
      //	printf("a[%d]=%d\n",j,a[j]);
    }
  }/*
  rep(i,6)
    printf("a[%d]=%d\n",i,a[i]);
   */
  for(i=1;i<=2e3;i++){
    if(func(i)==0){
      div(-i);	
      
    }
    if(func(-i)==0){
      div(i);
      
    }
  }
  sort(ans.begin(),ans.end());
  rep(i,ans.size()){
    cout<<"(x";
    if(ans[i]>0)cout<<"+";
    cout<<ans[i]<<")";
  }
  cout<<endl;
}

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

typedef ostringstream OSS;
typedef istringstream ISS;

typedef long long LL;
typedef pair<int, int> PII;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
typedef vector<double> VD;
typedef vector<VD> VVD;
typedef vector<string> VS;
typedef vector<VS> VVS;
typedef vector<bool> VB;
typedef vector<VB> VVB;
typedef vector<PII> VPII;

#define fst first
#define snd second
// #define Y first
// #define X second
#define MP make_pair
#define PB push_back
#define EB emplace_back 
#define ALL(x) (x).begin(),(x).end()
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define rep(i, N) for (int i = 0; i < (N); i++)
#define rep2(i, j, N, M) rep(i, N) rep(j, M)
#define rep3(i, j, k, N, M, L) rep(i, N) rep(j, M) rep(k, L)
#define REP(i, init, N) for (int i = (init); i < (N); i++)

template < typename T > inline T fromString(const string &s) { T res; ISS iss(s); iss >> res; return res; };
template < typename T > inline string toString(const T &a) { OSS oss; oss << a; return oss.str(); };

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;
const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};

set<string> anses;

string orig;
int N;

bool is_ok(string s) {
    for (char c = 'b'; c <= 'z'; c++) {
        auto pos = s.find(c);
        if (pos != string::npos) {
            s[pos]--;
        }
    }
    return orig == s;
}

void dfs(string &s, int step, int cnt, bool must_find) {
    if (step == 25 || cnt == N) {
        if (is_ok(s)) {
            anses.insert(s);
        }
        return;
    }

    bool is_find = false;
    rep(i, N) {
        if (s[i] == 'y' - step) {
            string ns(s);
            ns[i]++;
            dfs(ns, step + 1, cnt + 1, false);
            is_find = true;
        }
    }
    /*
    auto pos = s.find('y' - step);
    bool is_find = pos != string::npos;
    if (is_find) {
        string ns(s);
        ns[pos]++;
        dfs(ns, step + 1, cnt + 1, false);
    }*/

    if ((must_find && is_find) || !must_find) {
        dfs(s, step + 1, cnt, is_find);
    }

}

int main(void) {
    while (cin >> orig, orig != "#") {
        N = orig.size();
        anses.clear();
        dfs(orig, 0, 0, false);

        VS oks;
        for (auto s : anses) {
            oks.PB(s);
        }

        cout << oks.size() << endl;

        if (oks.size() <= 10) {
            for (auto s : oks) {
                cout << s << endl;
            }
        } else {
            for (int i = 0; i < 5; i++) {
                cout << oks[i] << endl;
            }
            for (int i = 4; i >= 0; i--) {
                cout << oks[oks.size() - 1 - i] << endl;
            }
        }
    }

	return 0;
}

Measured memory_bytes: 3392
n=gets.to_i
A=gets.split.map &:to_i
B=gets.split.map &:to_i
t=0
n.times{|i|
if A[i]<=B[i]
  t+=A[i]
  B[i]-=A[i]
else
  t+=B[i]
  B[i]=0
end
if A[i+1]<=B[i]
  t+=A[i+1]
  A[i+1]=0
else
  t+=B[i]
  A[i+1]-=B[i]
end
}
p t

Measured memory_bytes: 15388
n=int(input())
s = [input() for _ in range(n)]

dic={}

for i in  s:
    i = sorted(i)
    i = ''.join(i)
    if i in dic:
        dic[i]+=1
    else:
        dic[i]=1

ans =0
for i in dic.values():
    if i==1:
        continue
    else:
        ans+=i*(i-1)//2
print(ans)
    

Measured memory_bytes: 24976
#include<bits/stdc++.h>
using namespace std;
typedef vector<long double> vec;
typedef vector<vec> mat;
const double EPS=1E-8;


vec gauss_jordan(const mat& A,const vec& b){
  int n=A.size();
  mat B(n,vec(n+1));

  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)B[i][j]=A[i][j];

  for(int i=0;i<n;i++)B[i][n]=b[i];

  for(int i=0;i<n;i++){
    int pivot=i;
    for(int j=i;j<n;j++)
      if(abs(B[j][i])>abs(B[pivot][i]))pivot=j;
    swap(B[i],B[pivot]);

    if(abs(B[i][i])<EPS)return vec(); 

    for(int j=i+1;j<=n;j++)B[i][j]/=B[i][i];

    for(int j=0;j<n;j++)
      if(i!=j)
	for(int k=i+1;k<=n;k++)B[j][k]-=B[j][i]*B[i][k];
    
  }

  vec x(n);
  for(int i=0;i<n;i++)x[i]=B[i][n];
  return x;
}
#define N 101
#define INF 1e9

int main(){

  while(1){
    int n,s,t;
    cin>>n>>s>>t;
    if(!n)break;
    s--,t--;
    int G[N][N],g[N][N];
    
    bool q[N];
    for(int i=0;i<n;i++)cin>>q[i];

    for(int i=0;i<n;i++)
      for(int j=0,c;j<n;j++){
	cin>>c;
	G[i][j] = g[i][j] =c>0? c:INF;
      }


    for(int i=0;i<n;i++) G[i][i] = 0;
    for(int k=0;k<n;k++)
      for(int i=0;i<n;i++)
	for(int j=0;j<n;j++)G[i][j] = min(G[i][j],G[i][k]+G[k][j]);


    mat A(n,vec(n,0));
    vec B(n,0);
    for(int i=0;i<n;i++){
      if(G[i][t]==INF||i==t) {A[i][i] = 1; continue;}

      int cnt=0,sum=0;
      G[t][t]=0;
      for(int j=0;j<n;j++){
	if(g[i][j] >= INF) continue;
	if(q[i]&&G[i][t]<g[i][j]+G[j][t])continue;
	A[i][j] = -1;
	sum+=g[i][j];
	cnt++;
      }
      B[i] = sum;
      A[i][i] = cnt;
    }
  
    vec ans=gauss_jordan(A,B);
    if(ans.empty()) cout<<"impossible"<<endl;
    else printf("%.14f\n",(double)ans[s]);
  }
  return 0;
}

Measured memory_bytes: 3276
let N = Int(readLine()!)!
let A = readLine()!.characters.split(" ").map{Int(String($0))!}.sort()
let tmp = (0..<N).map{$0+($0+N+1)%2}
if A == tmp {
    print((0..<N/2).reduce(1){i,_ in i*2%1000000007})
} else {
    print(0)
}

Measured memory_bytes: 6848
H,W=map(int, input().split())
A=[input() for i in range(H)]

from collections import deque

q=deque([])
B=[[None]*W for _ in range (H)]
for i in range(H):
    for j in range(W):
        if A[i][j]=="#":
            q.append((i,j))
            B[i][j]=0
dx=[-1,1,0,0]
dy=[0,0,-1,1]
while len(q)>0:
  XY=[]
  while len(q)>0:
     XY.append(q.popleft())
  for xy in XY:
    for i in range(4):
      if 0<=(xy[0]+dx[i])<=H-1 and 0<=(xy[1]+dy[i])<=W-1:
        if B[xy[0]+dx[i]][xy[1]+dy[i]]==None:
          B[xy[0]+dx[i]][xy[1]+dy[i]]=B[xy[0]][xy[1]]+1
          q.append((xy[0]+dx[i],xy[1]+dy[i]))
        else: pass
      else: pass
print(max([max(B[i]) for i in range(H)]))

Measured memory_bytes: 130540
from collections import deque
N = int(input())
A = list(map(int, input().split()))
B = deque([])
i = 0
if N & 1:
    B.appendleft(A[i])
    i += 1
while i < N:
    B.append(A[i])
    i += 1
    B.appendleft(A[i])
    i += 1
print(*B)

Measured memory_bytes: 25528
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
#define INF 1e9
#define showVector(v) rep(i,0,v.size()){p(v[i]);p(" ")} pl("")
#define p(s) std::cout << s ;
#define pl(s)  std::cout << s << endl;
using namespace std;

// 素数判定 O(√n)
bool is_prime(int n){
    for(int i = 2; i * i <= n; i++){
        if(n % i == 0) return false;
    }
    return true;
}

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;
}
using Graph = vector<vector<int>>;//隣接リスト
 
vector<bool> seen;
bool check = true;
int ans = 0;
void dfs(Graph &G, int v) {
    seen[v] = true;
    rep(i, 1, seen.size()) {
        if (seen[i] == false) {
            check = false;
            break;
        }
    }
    if (check) ++ans;
    check = true;
    for (auto next_v: G[v]) {
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
    seen[v] = false;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int N, M, s, t;
    cin >> N >> M;
    Graph G(N+1);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a].push_back(b);
        //無向グラフ
        G[b].push_back(a);
    }

    seen.assign(N+1, false);
    dfs(G, 1);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import static java.util.Collections.swap;

/**
 * Wrong Answer
 */
class Main {
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);

		int w = in.nextInt();
		int n = in.nextInt();

		List<Integer> ans = new ArrayList<Integer>();
		for(int i=1;i<=w;i++) {
			ans.add(i);
		}

		String buf = in.nextLine();

		for(int i=0;i<n;i++) {
			String line = in.nextLine();
			String arr[] = line.split(",");
			int a = Integer.parseInt(arr[0]);
			int b = Integer.parseInt(arr[1]);
			swap(ans, a-1, b-1);
		}
		for(int i=0;i<ans.size();i++) {
			System.out.println(ans.get(i));
		}
	}
}

Measured memory_bytes: 26280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;

ll H, W;
char S[20][20];
typedef pair<int, int> P;

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

int bfs(int sx, int sy, int gx, int gy) {
    int d[20][20];

    queue<P> que;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            d[i][j] = 1e8;
        }
    }

    que.push(P(sx, sy));
    d[sx][sy] = 0;

    while (que.size()) {
        P p = que.front(); que.pop();
        if (p.first == gx && p.second == gy) break;

        for (int i = 0; i < 4; i++) {
            int nx = p.first + dx[i];
            int ny = p.second + dy[i];

            if (0 <= nx && nx < H && 0 <= ny && ny < W && S[nx][ny] == '.' &&
                d[nx][ny] == 1e8) {
                    que.push(P(nx, ny));
                    d[nx][ny] = d[p.first][p.second] + 1;
            }
        }
    }

    return d[gx][gy];
}

int main() {
    cin >> H >> W;
    rep(i, H)rep(j, W) cin >> S[i][j];

    int ans = 0;
    for (int sx = 0; sx < H; sx++) {
        for (int sy = 0; sy < W; sy++) {
            for (int gx = 0; gx < H; gx++) {
                for (int gy = 0; gy < W; gy++) {
                    if (S[sx][sy] == '#' || S[gx][gy] == '#') {
                        continue;
                    }
                    int res = bfs(sx, sy, gx, gy);
                    ans = max(ans, res);
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int M, D; cin >> M >> D;

  int ans = 0;
  for (int m = 1; m <= M; m++) {
    for (int i = 1; i <= D; i++) {
      int d1 = i % 10;
      int d10 = i / 10;
      if ((d1>=2) && (d10>=2) && (d1*d10==m)) ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


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

#define all(v) v.begin(), v.end()
#define mp make_pair
#define EPS (int)1e-9
#define PI acos(-1)
#define endl '\n'
#define pb push_back
#define fi first
#define se second

using namespace std;
using ld = long double;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;

const int mod = 1000000007;

ll lcm(ll a, ll b)
{
	if(a < b)
		swap(a,b);

	return a/__gcd(a, b)*b;
}


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n, x, ans;
	cin >> n;

	n--;
	cin >> ans;

	while(n--)
	{
		cin >> x;
		ans = lcm(ans, x);
	}

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

Measured memory_bytes: 256