akhauriyash/Code-Regression huggingface dataset:
#include <stack>
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <array>
#include <iomanip>
using namespace std;
int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
int main(){
    //std::stack<int> stack;
    string s;
    cin >> s;
    int n;
    cin >> n;
    int k = 1;
    string B = "";
    string E = "";
    for(int i = 0; i < n; i++){
        int m;
        cin >> m;
        if(m == 1){
            k *= (-1);
        }else{
            int f;
            char c;
            cin >> f >> c;
            if(f == 1){
                if(k == 1){
                    B = c + B;
                }else{
                    E = E + c;
                }
            }else{
                if(k == -1){
                    B = c + B;
                }else{
                    E = E + c;
                }
                
            }
        }
    }
    string ans = B + s + E;
    if(k == -1){
        reverse(ans.begin(), ans.end());
    }
    cout << ans << endl;
    return 0;
}





Measured memory_bytes: 1512
import java.util.Scanner;
import java.util.*;
import java.io.*;

public class Main{
	public static void main(String [] args){
		BufferedReader r = new BufferedReader(new InputStreamReader(System.in),1200);
		String w = "";
		String work = "";
		String input = "";
		int count = 0;
		try{
			w = r.readLine();
			input = r.readLine();
			while(input != null){
				work += " ";
				work += input;
				input = r.readLine();
			}
		}catch(Exception e){
			System.out.println(e);
		}
		input = work;
		input = input.toLowerCase();
		StringTokenizer st = new StringTokenizer(input," ");
		while(st.hasMoreTokens()){
			work = st.nextToken();
			if(work.length() < w.length()){
					continue;
			}else{
				if(w.equals(work)){
					count++;
				}
			}
		}
		
		
		System.out.println(count);
	}
}

Measured memory_bytes: 24124
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static boolean adj[][];

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

		//Getting 隣接行列
		int N = scan.nextInt();
		int M = scan.nextInt();

		adj = new boolean[N][N];

		for (int i = 0; i < N; i++) {
			Arrays.fill(adj[i], false);
		}

		for (int i = 0; i < M; i++) {
			int A = scan.nextInt();
			int B = scan.nextInt();
			adj[A-1][B-1] = adj[B-1][A-1] = true;
		}

		boolean visited[] = new boolean[N];
		Arrays.fill(visited, false);
		visited[0] = true;

		System.out.println(dfs(0, N, visited));
	}

	public static int dfs(int x, int N, boolean[] visited) {

		boolean allvisited = true;

		for (int i = 0; i < N; i++) {
			if (visited[i] == false) {
				allvisited = false;
			}
		}

		if (allvisited)	return 1;
		//以上全てのノードを回ったかの確認

		//以下DFS本体
		int ret = 0;

		for (int i = 0; i < N; i++) {
			if (adj[x][i] == false) continue;
			if (visited[i]) continue;

			visited[i] = true;
			ret += dfs(i, N, visited);
			visited[i] = false;
		}

		return ret;
	}
}


Measured memory_bytes: 21972
#include <stdio.h>
#include <math.h>



int main(){
    int i,a[100000];
    long n,k,cnt;
    scanf("%ld %ld",&n,&k);
    for(i=0;i<n;i++)
        scanf("%d",&a[i]);
    cnt=(n-1)/(k-1);
    if((n-1)%(k-1)!=0)
        cnt+=1;
    printf("%ld",cnt);
    
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
ll pwr(ll a, ll pw)
{
    ll ret = 1;
    while(pw > 0)
    {
        if(pw & 1) ret = ret * a % mod;
        a = a * a % mod;
        pw >>= 1;
    }
    return ret;
}
ll inv(ll a)
{
    return pwr(a, mod - 2);
}
int h, w, n, X[maxn], Y[maxn], id[maxn];
ll fac[maxn], ifac[maxn], dp[maxn];
ll ways(ll a, ll b)
{
    if(a == b || a == 0) return 1;
    return fac[b] * ifac[a] % mod * ifac[b - a] % mod;
}
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    fac[0] = ifac[0] = 1;
    for(int i = 1; i < maxn; i++)
    {
        fac[i] = fac[i - 1] * i % mod;
        ifac[i] = inv(fac[i]);
    }
    cin >> h >> w >> n;
    for(int i = 0; i < n; i++)
        cin >> X[i] >> Y[i];
    for(int i = 0; i <= n; i++)
        id[i] = i;
    X[n] = h, Y[n] = w;
    sort(id, id + n, [&](int a, int b)
    {
        if(X[a] == X[b]) return Y[a] < Y[b];
        return X[a] < X[b];
    });
    for(int i = 0; i <= n; i++)
    {
        int j = id[i];
        dp[j] = ways(X[j] - 1, X[j] + Y[j] - 2);
        for(int k = 0; k < i; k++)
        {
            int o = id[k];
            dp[j] -= dp[o] * ways(X[j] - X[o], X[j] - X[o] + Y[j] - Y[o]) % mod;
            dp[j] = (dp[j] + mod ) % mod;
        }
    }
    cout << dp[n] << "\n";
    return 0;
}


Measured memory_bytes: 4864
import collections


def main():
    s = list(input())
    c = collections.Counter(s)
    keys = list(c.keys())
    print("Yes" if ((keys.count("S") == 0 and keys.count("N") == 0) or (keys.count("S") == 1 and keys.count("N") == 1)) and (
        (keys.count("E") == 0 and keys.count("W") == 0) or (keys.count("E") == 1 and keys.count("W") == 1)) else "No")


if __name__ == '__main__':
    main()


Measured memory_bytes: 9232
#include<stdio.h>
#include<string.h>
#define MAX 25
#define LEN 14
#define NIL -1

typedef struct{
  int parent;
  int left; //左の子の節点番号
  int right; //右の子の節点番号
  char state[LEN]; //節点の種類
  int depth; //深さ
  int sib; //兄弟
  int deg; //子の数
  int height; //高さ
}node;

void setDepth(int, int);
int setHeight(int, int);

node t[MAX];

int main(){
  int n, index, parent, root;
  int i;

  scanf("%d", &n);

  //初期化
  for(i=0;i<n;i++){
    t[i].parent = NIL;
    t[i].deg = 0;
  }
  
  for(i=0;i<n;i++){
    scanf("%d", &index);
    scanf("%d %d", &t[index].left, &t[index].right);
    //右の子と左の子の親を設定
    if(t[index].left != NIL) t[t[index].left].parent = index; 
    if(t[index].right != NIL) t[t[index].right].parent = index;
  }

  for(i=0;i<n;i++){
    if(t[i].parent == NIL) root = i;
  }

  setDepth(root, 0);
  setHeight(root, 0);

  for(i=0;i<n;i++){
    //stateの設定
    if(t[i].parent == NIL) strcpy(t[i].state, "root");
    else if(t[i].left == NIL && t[i].right == NIL) strcpy(t[i].state, "leaf");
    else strcpy(t[i].state, "internal node");

    //兄弟の設定
    //親がいる前提
    if(t[i].parent != NIL){
      parent = t[i].parent;
      //左に子がいてかつ自分が左の子ではないとき
      if(t[parent].left != NIL && t[parent].left != i) t[i].sib = t[parent].left;
      //右に子がいてかつ自分が右の子ではないとき
      else if(t[parent].right != NIL && t[parent].right != i) t[i].sib = t[parent].right;
      else t[i].sib = NIL;
    }
    else t[i].sib = NIL;

    //子の数の設定
    if(t[i].left != NIL) t[i].deg++;
    if(t[i].right != NIL) t[i].deg++;

    //printf("%2d: parent %2d: left %2d: right %2d\n", i, t[i].parent, t[i].left, t[i].right);
    //表示
    printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, %s\n",
	   i, t[i].parent, t[i].sib, t[i].deg, t[i].depth, t[i].height, t[i].state);
  }
  
  return 0;
}

//uは節点番号, dは深さ
void setDepth(int u, int d){
  t[u].depth = d;
  //子がいるとき深さ更新して再帰
  if(t[u].left != NIL) setDepth(t[u].left, d+1);
  if(t[u].right != NIL) setDepth(t[u].right, d+1);
}

//uは節点番号, hは高さ
int setHeight(int u, int h){
  int h1 = 0, h2 = 0;
  int ans;
  if(t[u].left != NIL) h1 = setHeight(t[u].left, h) + 1;
  if(t[u].right != NIL) h2 = setHeight(t[u].right, h) +1;
  if(h1 > h2) ans = h1;
  else ans = h2;
  t[u].height = ans;
  return ans;
}



Measured memory_bytes: 2108
import java.util.Scanner;

class Main {
	Scanner sc = new Scanner(System.in);

	public void run() {
		while (true) {
			int n = sc.nextInt(), x = sc.nextInt();
			if (n == 0 && x == 0) {
				break;
			}
			int count = 0;
			for (int a = 1; a <= n; a++)
				for (int b = a + 1; b <= n; b++)
					for (int c = b + 1; c <= n; c++) {
						if (a + b + c == x) {
							count++;
						}
					}
			ln(count);
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public static void pr(Object o) {
		System.out.print(o);
	}

	public static void ln(Object o) {
		System.out.println(o);
	}

	public static void ln() {
		System.out.println();
	}
}

Measured memory_bytes: 12000
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))


SINT32 main() {
    SINT32 ans = 0;
    SINT32 max = 10;

    scanf("%d",&max);


    
    SINT32 *data = malloc(sizeof(SINT32)*max);
    for (SINT32 i = 0; i < max; i++) {
        scanf("%d", &data[i]);
    }

    
    
    while(1) {
        SINT32 buf = 0;
        SINT32 buf2 = 1;
        for (SINT32 i = 0; i < max; i++) {
            if (data[i] == 0) {
                if (buf == 1) {
                    ans = ans + 1;
                    buf = 0;
                }
            } else {
                data[i] = data[i] - 1;
                buf = 1;
                buf2 = 0;
            }
        }
        if (buf==1) {
            ans = ans + 1;
        }
        if (buf2 == 1) {
            break;
        }
    }


    printf("%d\n",ans);
    free(data);
	return 0;
}

Measured memory_bytes: 128
/*{{{*/
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define mset(x,c) memset(x, c, sizeof(x))
#define mem0(x) mset(x,0)
#define mem1(x) mset(x,-1)
#define memc(x,y) memcpy(x, y, sizeof(x));
#define P(a,n) FOR(_,0,n) _W(a),printf("%c", " \n"[_==n-1])
#define print(a,n) cout << #a << " = ";FOR(_,0,n) _W(a),printf("%c", " \n"[_==n-1])
using namespace std;

template<class T> void _R(T &x) { cin >> x; }
void _R(signed &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const signed &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.fi); putchar(' '); _W(x.se);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef LOCAL
 #define debug(...) {printf(" [" #__VA_ARGS__ "]: ");W(__VA_ARGS__);}
#else
 #define debug(...)
#endif

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
/*}}}*/
//#define int long long

const int N = 1e6+10;

int cnt[N], a[N];

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

signed main() {
#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
#endif
	int n;
	R(n);
	int g = 0;
	FOR(i,0,n) {
		int x;
		R(x);
		g = gcd(x, g);
		a[x]++;
	}
	bool pc = true;
	FOR(i,2,N) {
		for (int j = i; j < N; j += i) {
			cnt[i] += a[j];
		}
		if (cnt[i] > 1) pc = false;
	}
	if (pc) puts("pairwise coprime");
	else if (g == 1) puts("setwise coprime");
	else puts("not coprime");
}


Measured memory_bytes: 11564
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		long INF = 1 << 58;
		while (true) {
			int n = sc.nextInt();
			int k = sc.nextInt();
			if ((n | k) == 0)
				break;
			long fare[][] = new long[n][n];
			for (int i = 0; i < n; i++) {
				Arrays.fill(fare[i], INF);
				fare[i][i] = 0;
			}
			for (int i = 0; i < k; i++) {
				int init = sc.nextInt();
				if (init == 1) {
					int c = sc.nextInt() - 1;
					int d = sc.nextInt() - 1;
					int e = sc.nextInt();
					if (e < fare[c][d]) {
						fare[c][d] = fare[d][c] = e;
						for (int p = 0; p < n; p++) {
							for (int q = 0; q < n; q++) {
								fare[p][q] = Math.min(fare[p][q], fare[p][c]
										+ fare[c][d] + fare[d][q]);
								fare[p][q] = Math.min(fare[p][q], fare[p][d]
										+ fare[c][d] + fare[c][q]);
							}
						}
					}
				} else {
					int a = sc.nextInt() - 1;
					int b = sc.nextInt() - 1;
					System.out.println(fare[a][b] != INF ? fare[a][b] : -1);
				}
			}
		}
	}
}

Measured memory_bytes: 13000
import scala.io.StdIn.{readLine,readInt}
import scala.math.BigDecimal

object Main {
    def main(args:Array[String]) = {
        val n = readInt
         for(i <- 0 until n) {
            val m = readLine.split(" ").map(_.toDouble)
            val (x12,y12,x13,y13) = (m(0)-m(2),m(1)-m(3),m(0)-m(4),m(1)-m(5))
            val (xx1,yy1,xx2,yy2,xx3,yy3) = (m(0)*m(0),m(1)*m(1),m(2)*m(2),m(3)*m(3),m(4)*m(4),m(5)*m(5))
            val g = 2*(x12*y13 - y12*x13)
            val x = (y13*(xx1 - xx2 + yy1 - yy2) - y12*(xx1 - xx3 + yy1 - yy3))/g
            val y = (x12*(xx1 - xx3 + yy1 - yy3) - x13*(xx1 - xx2 + yy1 - yy2))/g

            printf("%.3f %.3f %.3f\n",x,y,Math.sqrt((x-m(0))*(x-m(0))+(y-m(1))*(y-m(1))))
        }
    }
}

Measured memory_bytes: 44160
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <list>
#include <set>
#include <algorithm>
#include <cmath>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>

using namespace std;

#define ll long long
#define f0(i,n)for(i=0;i<n;i++)
#define f1(i,n)for(i=1;i<=n;i++)
#define fc(i,c,n)for(i=c;i<=n;i++)
#define f0r(i,n)for(i=n-1;i>=0;i--)
#define f1r(i,n)for(i=n;i>0;i--)
#define fcr(i,c,n)for(i=n;i>=c;i--)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef list<ll> LST;
typedef vector<ll> VEC;
typedef map<ll, ll> MAP;

ll i, j, q;
ll n, m, p, k, t, s, v;
ll a, b, c, d;
ll x, y, z, l, r;
ll one = 1, zero = 0, ans = 0;
ll mod = 1000000007;
ll INF = 9223372036854775807;
ll a1, a2, a3, a4;
string st1, st2, st3;
char ch1, ch2, ch3;

int main() {
	ifstream fin("Text.txt");
	
	cin >> a >> b >> c >> k;
	if (k & 1)
		cout << b - a << endl;
	else
		cout << a - b << endl;
	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 vi = vector<int>;

int main(){
  int n,a,b; cin >> n >> a >> b;
  vi level(3,0);
  int p;
  rep(i,n){
    cin >> p;
    if(p>b)level[2]++;
    else if(p>a)level[1]++;
    else level[0]++;
  }
  
  cout << min(level[0], min(level[1], level[2])) << endl;
  return 0;
}

Measured memory_bytes: 256
import math

c1x, c1y, c1r = map(int, input().split())
c2x, c2y, c2r = map(int, input().split())

d = math.sqrt((c1x-c2x)**2 + (c1y-c2y)**2)
if d > c1r + c2r:
    print(4)
elif d == c1r + c2r:
    print(3)
elif d+c1r==c2r or d+c2r==c1r:
    print(1)
elif d+c1r<c2r or d+c2r<c1r:
    print(0)
else:
    print(2)


Measured memory_bytes: 5664
import * as fs from "fs"

function Main(input: string) {

  const p = input.split("\n")[0]
  const ans = p.replace(/,/g, " ")
  console.log(ans)
}


fs.readFile('/dev/stdin', (err, data) => {
  if (err) {
    Main(fs.readFileSync('./input.txt', 'utf8'))
    return null
  }
  Main(data.toString())
  return null
})

Measured memory_bytes: 11468
using System;
using System.Collections.Generic;
using System.Linq;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            long[] x = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long ret = x[1];
            long[] a = new long[] { x[0],x[3],x[4] }; long aret = 0;
            aret += a[0] / 2 * 2; aret += a[1] / 2 * 2; aret += a[2] / 2 * 2;
            long[] b = new long[] { x[0] - 1,x[3] - 1,x[4] - 1 };
            if (b.Min() >= 0)
            {
                long bret = 0;
                bret += b[0] / 2 * 2; bret += b[1] / 2 * 2; bret += b[2] / 2 * 2;
                Console.WriteLine(ret + Math.Max(aret,(bret + 3)));
            }
            else
            {
                Console.WriteLine(ret + aret);
            }
        }
    }
}

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

int main() {

  int N;
  cin >> N;

  vector<int> L(N);
  rep(i, N) cin >> L[i];

  sort(L.begin(), L.end());
  //rep(i, N) cout << L[i] << endl;

  int a, b;
  int cnt = 0;
  rep(i, N) {
	for (int j=i+1; j<N; ++j) {
	  a = L[i];
	  b = L[j];

	  int ab = a+b;

	  int r = lower_bound(L.begin(), L.end(), ab) - L.begin();  // right side

	  int l =  j+1;  // left side
	  // c in [l, r)
	  cnt += max(0, r-l);
	}
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod LLONG_MAX
#define mod1 998244353
#define Mmax 1000005
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
bool comp(pair<li,pair<li,li>>a,pair<li,pair<li,li>>b)
{
  if(a.first<b.first)
  return 1;
  else if(a.first>b.first)
  return 0;
  else
  {
    return a.second.first<b.second.first;
  }
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
li modInverse(li n)
{
    return mpow(n, mod-2);
}

li nCrModPFermat(li n, li r,li x,li y,li z)
{
   // Base case
   if (r==0)
      return 1;
    // li fac[n+1];
    // fac[0] = 1;
    // for (int i=1 ; i<=n; i++)
    //     fac[i] = fac[i-1]*i%mod;
    return (x* modInverse(y) % mod *modInverse(z) % mod) % mod;
}
void bfs(vector<li>v[],li visit[],li s,li ans[])
{
  deque<li>q;
  q.push_back(s);
  visit[s]=1;
  while(!q.empty())
  {
    li x=q.front();
    q.pop_front();
    for(auto i=v[x].begin();i!=v[x].end();i++)
    {
      if(!visit[*i])
      {
        q.push_back(*i);
        visit[*i]=1;
      }
    }
  }
}
void buildtree(int*tree,int*arr,int start,int end,int treeNode)
{
  if(start<end)
  {
    int mid=start+(end-start)/2;
    buildtree(tree,arr,start,mid,2*treeNode);
    buildtree(tree,arr,mid+1,end,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}
void update(int*tree,int*arr,int start,int end,int pos,int val,int treeNode)
{
  if(start==end)
  tree[treeNode]=val;
  else
  {
    int mid=start+(end-start)/2;
    if(pos<=mid)
    update(tree,arr,start,mid,pos,val,2*treeNode);
    else
    update(tree,arr,mid+1,end,pos,val,2*treeNode+1);
    tree[treeNode]=tree[2*treeNode]+tree[2*treeNode+1];
  }
}

void dfs(vector<li>v[],li visit[],li s,li c[],li ans[],map<li,li>*m,li pred[])
{
    visit[s]=1;
     (*m)[c[s]]++;
    for(auto i=v[s].begin();i!=v[s].end();i++)
      {
        if(!visit[*i])
        {pred[*i]=s;
           dfs(v,visit,*i,c,ans,m,pred);
        }
      }
      if((*m)[c[pred[s]]]==1)
    ans[s]=(*m).size()-1;
    else
    ans[s]=(*m).size();
}
vector<li>factor(li n)
{
  vector<li>v;
  if(n%2==0)
  {
    while(n%2==0)
    {n/=2;
    v.push_back(2);
    }
  }
  for(li i=3;i<=sqrt(n);i+=2)
  {
    if(n%i==0)
    {
      while(n%i==0)
      {n/=i;
      v.push_back(i);
      }
    }
  }
  if(n>1)
  v.push_back(n);
  return v;
}
int main()
{
 li t,i,j,k;
// cin>>t;
// while(t--)
// {
//
//   cout<<endl;
// }
li n,m,x;
cin>>n>>m>>x;
li a[n],b[n][m];
for(i=0;i<n;i++)
{cin>>a[i];
for(j=0;j<m;j++)
cin>>b[i][j];
}
li mi=INT_MAX;
for(i=0;i<=mpow(2,n)-1;i++)
{
  li p=i;
  li ans=0;
  li arr[m]={0};
  for(j=0;j<n;j++)
  {
    li r=(1<<j);
    if((r&p))
    {
      ans+=a[j];
      for(k=0;k<m;k++)
      arr[k]+=b[j][k];
    }
  }
  for(j=0;j<m;j++)
  {if(arr[j]<x)
  break;
  }
  if(j<m)
  continue;
  else
  mi=min(mi,ans);
}
if(mi==INT_MAX)
cout<<"-1";
else
cout<<mi;
return 0;
}


Measured memory_bytes: 3728
#include <stdio.h>

int main(void){
    int k,x;
    scanf("%d %d", &k,&x);
    int i;
    if(x-k+1>=-1000000){
        for(i=x-k+1;i<=x;i++){
            printf("%d ",i);
        }
    }else{
        for(i=-1000000;i<=x;x++){
            printf("%d ",i);
        }
    }

    if(x+k-1<=1000000){
        for(i=x+1;i<=x+k-1;i++){
            printf("%d ",i);
        }
    }else{
        for(i=x+1;i<=1000000;i++){
            printf("%d ",i);
        }
    }
    putchar('\n');
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int n;
int a[200];

bool C(int t){
	int sum=0;
	rep(i,n){
		sum+=a[i];
		if(sum<t){
			return false;
		}
		sum-=t;
	}
	return true;
}
int main(){
	cin>>n;
	rep(i,n)cin>>a[i];
	for(int i=10000;i>=1;i--){
		if(C(i)){
			cout<<i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3108
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

#[derive(Clone)]
enum Edge {
    Start(usize),
    End(usize),
}

fn main() {
    let N: usize = read();
    let M: usize = read();
    let mut vec: Vec<Vec<Edge>> = vec![vec![]; N];
    for i in 0..M {
        let a = read::<usize>() - 1;
        let b = read::<usize>() - 1;
        vec[a].push(Edge::Start(i));
        // 0以下の場合は
        vec[b].push(Edge::End(i));
    }

    use std::collections::HashSet;
    let mut set = HashSet::new();

    let mut ans = 0;
    for actions in vec {
        let mut starts = vec![];
        let mut ends = vec![];
        for v in actions {
            match v {
                Edge::Start(v) => starts.push(v),
                Edge::End(v) => ends.push(v),
            }
        }
        if ends.iter().any(|v| set.contains(v)) {
            set.clear();
            ans += 1;
        }
        for v in starts {
            set.insert(v);
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 18684
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vii = vector<ii>;
const ll oo = 1e18L+7;


int main() {
    
    int n;
    scanf("%d", &n);
    
    vi slimes(n);
    vector<vector<ll>> dp(n, vector<ll>(n, oo));
    
    for(int& i : slimes) {
        scanf("%d",&i);
    }
    
    vector<ll> pre(n, 0);
    ll run = 0;
    
    for(int i = 0; i < n; ++i) {
        run += slimes[i];
        pre[i] = run;
    }
    
    // dp[i][j] - the minimal cost of grouping all slimes in range
    // [i, j) together into one slime
    
    for(int i = n-1; i >= 0; --i) {
        dp[i][i] = 0;
        if(i+1 < n) dp[i][i+1] = slimes[i] + slimes[i+1];
        
        for(int j = i+2; j < n; ++j) {
            for(int k = i+1; k <= j; ++k) {
                ll cost = dp[i][k-1] + dp[k][j] + (pre[j] - (i > 0 ? pre[i-1] : 0));
                debug() << imie(i) imie(k) imie(j) imie(dp[i][k-1]) imie(dp[k][j]) imie((pre[j] - (i > 0 ? pre[i-1] : 0))) imie(cost);
                dp[i][j] = min(dp[i][j], cost);
            }
        }
    }
    
    debug() << imie(dp);
    
    printf("%lld\n", dp[0][n-1]);
    
    return 0;
}




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

const int N = 200010;

int white[N], black[N];
char s[N];

int main(){
    int n;
    scanf("%d%s", &n, s + 1);
    for (int i = 1; i <= n; ++ i) {
        black[i] = black[i - 1] + (s[i] == '#');
    }
    for (int i = n; i >= 1; -- i){
        white[i] = white[i + 1] + (s[i] == '.');
    }
    int min = INT_MAX;
    for (int i = 0; i <= n; ++ i){
        min = std::min(min, black[i] + white[i + 1]);
    }
    printf("%d\n", min);
    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
typedef long long LL;
LL ans,now,tmp;
int num[3000],n;
char s[N];
int c(char ch){
	return ch-'0';
}
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	num[0]=1;
	int now=1;
	for(int i=n;i;i--){
		tmp+=now*c(s[i]);
		tmp%=2019;
		ans+=num[tmp];num[tmp]++;
		now*=10;
		now%=2019;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3856
#include <iostream>

int main() {

	using namespace std;
	int a, b;

	cin >> a >> b;

	if (a % 2 == 1 && b % 2 == 1) {

		cout << "Yes" << endl;
	}

	else {

		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const int N = 20;
int a[N];

ll dp[N][2][5][2];
// no, 5, 51, 51(5以外), 515,
ll dfs(int d, int small, int state, int g){
    if(d==N){
        return g;
    }
    if(dp[d][small][state][g]>=0) return dp[d][small][state][g];

    int lim = 9;
    if(small==0) lim = a[d];

    ll ret = 0;
    for(int i=0; i<=lim; ++i){
        int ns = small|(i<a[d]);
        int nx = 0;
        int ng = g;
        if(i==1){
            if(state==1 || state==4) nx = 2;
            if(state==2) nx = 3;
        }
        else if(i==3){
            if(state==2) nx = 3;
            if(state==3 || state==4) ng = 1;
        }
        else if(i==5){
            if(state==2) nx = 4;
            else nx = 1;
        }
        else{
            if(state==2) nx = 3;
        }

        ret += dfs(d+1, ns, nx, ng);
    }

    return dp[d][small][state][g] = ret;
}

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

    for(int i=N-1; i>=0; --i){
        a[i] = n%10;
        n/=10;
    }

    memset(dp,-1,sizeof(dp));
    cout << dfs(0,0,0,0) << endl;
    return 0;
}



Measured memory_bytes: 3100
/*COMPETITIVE PROGRAMMING C++ TEMPLATE */

#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << " = " << x << "\n"
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
    map<string, int> mp;
    int n;
    cin >> n;

    for(int i = 0; i < n; i++)
    {
        string s;
        cin >> s;

        mp[s]++;
    }

    cout << "AC x " << mp["AC"] << "\n";
    cout << "WA x " << mp["WA"] << "\n";
    cout << "TLE x " << mp["TLE"] << "\n";
    cout << "RE x " << mp["RE"] << "\n";


}

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

    int T = 1;
    //cin >> T;
    
    while (T--)
    {
        solve();
    }
    
    return 0;
}



Measured memory_bytes: 3664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong a, b;

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

    cout << max({a + b, a - b, a * b}) << endl;

    return 0;
}


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

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

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

#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef pair<int, int> pii;
typedef double D;
typedef complex<D> P;
typedef vector<string> vs;

#define SZ(x) ((int)(x).size())

#define fill(x,y) memset(x,y,sizeof(x))

// with compile option -DLOCAL
#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

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

#define pcnt __builtin_popcount
#define pcntll __builtin_popcountll

#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(v) begin(v), end(v)
#define RALL(v) rbegin(v), rend(v)
#define F first
#define S second

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};



#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

const int MOD = 1e9 + 7;
const int INF = INT_MAX;

signed main() {
    Fast();

    int n;
    cin >> n;

    for(int i=n; i<=999; i++) {
        if(i%10 == (i/10) % 10 && i%10 == (i/100) % 10) {
            cout << i << endl;
            exit(0);
        }
    }
    
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define P pair<int, int>

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    vector<vector<int>> a(k);
    vector<int> flag(n+1, 0);
    for(int i = 0; i < k; i++) {
        cin >> d[i];
        for(int j = 0; j < d[i]; j++) {
            int input;
            cin >> input;
            flag[input] = 1;
        }
    }
    int ans = 0;
    for(int i = 1; i <= n; i++) {
        if(flag[i] == 0) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)

using namespace std;
static const int MAX=50;
int n,m;
int a[MAX],b[MAX];
bool graph[MAX][MAX];
bool visited[MAX];

void dfs(int v){
    visited[v]=true;//vからスタート
    for(int v2=0;v2<n;v2++){
        if(!graph[v][v2])continue;
        if(visited[v2])continue;
        dfs(v2);
    }
}
int main(){
    cin>>n>>m;
    for(int i=0;i<m;i++){//隣接リスト表現→隣接行列
        cin>>a[i]>>b[i];

        a[i]--;b[i]--;
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;
    }
    int ans=0;
    for(int i=0;i<m;i++){
        graph[a[i]][b[i]]=graph[b[i]][a[i]]=false;
        for(int j=0;j<n;j++)visited[j]=false;

        dfs(0);//iを抜いてみて探索
        
        bool bridge=false;
        for(int j=0;j<n;j++){
            if(!visited[j])bridge=true;
        }
        if(bridge)ans+=1;

        graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;//元に戻す
    }
    cout<<ans<<"\n";
    return 0;
}


Measured memory_bytes: 256
(* unihernandez22
 * https://atcoder.jp/contests/abc171/tasks/abc171_a
 * implementation
 * *)

let is_uppercase = function
    'A' .. 'Z' -> true
    | _ -> false;;

Printf.printf "%c\n" @@
Scanf.scanf "%c" @@ fun a ->
    if is_uppercase a then 'A'
    else 'a';;


Measured memory_bytes: 3744
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int n;
int c[10010] = { 0 };
int d[10010] = { 0 };
int ecnt[10010] = { 0 };
vector<int> edges[10010];
bool visited[10010] = { false };
int idx = 0;

void solve(int i)
{
	for(int j = 0; j < edges[i].size(); ++j)
	{
		if(!visited[edges[i][j]])
		{
			visited[edges[i][j]] = true;
			solve(edges[i][j]);
		}
	}

	d[i] = c[idx];
	++idx;
}

int main()
{
	cin >> n;

	for(int i = 0; i < n - 1; ++i)
	{
		int a, b;
		cin >> a >> b;
		edges[a].push_back(b);
		edges[b].push_back(a);
		++ecnt[a];
		++ecnt[b];
	}

	int sum = 0;
	for(int i = 0; i < n; ++i)
	{
		cin >> c[i];
		sum += c[i];
	}
	sort(c, c + n);

	int start = max_element(ecnt + 1, ecnt + 1 + n) - ecnt;

	visited[start] = true;

	solve(start);

	cout << sum - d[start] << endl;
	cout << d[1];
	for(int i = 2; i <= n; ++i)
	{
		cout << " " << d[i];
	}
	cout << endl;
}

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

int main(){
  int N;
  cin >> N;
  if(N % 10 == 3){
    cout << "bon" << endl;
  }
  else if(N % 10 == 0 || N % 10 == 1 || N % 10 == 6 || N % 10 == 8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
 return 0;
}

Measured memory_bytes: 3632
/**
 *  author:   TakeruOkuyama
 *  created:  2020-04-17 18:03:35
**/
#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>;

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    int N;
    cin >> N;
    vector<int> d(N);
    rep(i, N){
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    //reverse(d.begin(), d.end());
    int left = d[d.size()/2-1];
    int right = d[d.size()/2];
    cout << right - left << endl;
return 0;}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 640
using System;

namespace ABC112_a
{
	class Program
	{
		static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());
			if (n == 1) Console.WriteLine("Hello World");
			else
			{
				int a = int.Parse(Console.ReadLine());
				int b = int.Parse(Console.ReadLine());
				Console.WriteLine(a + b);
			}
		}
	}
}

Measured memory_bytes: 11092
n,m,q=map(int,input().split())
d=[[0 for j in range(n)] for i in range(n)]
for i in range(m):
	l,r=map(lambda x:int(x)-1,input().split())
	d[l][r]+=1
for l in range(n):
	for r in range(1,n):
		d[l][r]+=d[l][r-1]
for l in range(n-1,0,-1):
	for r in range(n):
		d[l-1][r]+=d[l][r]
for i in range(q):
	l,r=map(lambda x:int(x)-1,input().split())
	print(d[l][r])

Measured memory_bytes: 9460
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T>
bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    ll N,X,D; cin>>N>>X>>D;
    if(D==0){
        if(X==0) cout<< 1 <<"\n";
        else cout<< N+1 <<"\n";
        return;
    }
    if(D<0){
        D=-D;
        X=-X;
    }
    unordered_map<ll,vector<P>> mp;
    rep(k,N+1){
        ll kxmodd=( (k*X)%D>=0 ? (k*X)%D : (-(k*X)%D)+D );
        ll kxmodsho=( X<0 ? (k*X)/D -1 : (k*X)/D );
        ll left=kxmodsho+(k*(k-1))/2;
        ll right=kxmodsho+((2*N-k-1)*k)/2;
        mp[kxmodd].emplace_back(left,right);
    }
    ll ans=0;
    for(auto& x: mp){
        auto& pev=x.second;
        SORT(pev);
        ll right=-INF2;
        for(auto& pe: pev){
            ll le=pe.first;
            ll ri=pe.second;
            if(ri<=right) continue;
            if(le>right){
                ans+=ri-le+1;
            }
            else{
                ans+=ri-right;
            }
            right=ri;
        }
    }
    cout<< ans <<"\n";
}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 17864
#include <stdio.h>
int main(void)
{
        int n,i,j;

        scanf("%d",&n);
        for(i=1;i<=9;i++)
        for(j=1;j<=9;j++){
        if(i*j==n){
        printf("Yes\n");
        return 0;
                }
        }
        printf("No\n");
        return 0;
}


Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <algorithm>
#include <fstream>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stack>
#include <climits>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
double EPS =1e-10;
double EQ(double a,double b){
	return abs(a-b)<EPS;
}

void fast_stream(){
	std::ios_base::sync_with_stdio(0);
}

void solve(){
	int p[4][4]={{1,2,3,4},{2,-1,4,-3},{3,-4,-1,2},{4,3,-2,-1}};
	int a[4],b[4],ans[5]={},n;
	while(cin>>n,n){
		for(int ii=0;ii<n;ii++){
			memset(ans,0,sizeof(ans));
			for(int i=0;i<4;i++) cin>>a[i];
			for(int i=0;i<4;i++) cin>>b[i];
			for(int i=0;i<4;i++){
				for(int j=0;j<4;j++){
					if(p[i][j]<0) ans[abs(p[i][j])]-=a[i]*b[j];
					else ans[p[i][j]]+=a[i]*b[j];
				}
			}
			for(int i=1;i<4;i++) cout<<ans[i]<<" ";
			cout<<ans[4]<<endl;
		}
	}
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b){
    if(b==0)return a;
    return gcd(b, a%b);
}

int main(int argc, char const *argv[])
{
    ll n;cin>>n;
    vector<ll> dif;
    vector<ll> v(n+1);
    ll x;cin>>v[n];
    for(int i=0;i<n;i++){
        cin>>v[i];
    }
    sort(v.begin(), v.end());

    for(int i=0;i<=n;i++){
        if(i>0){
            dif.push_back(abs(v[i]-v[i-1]));
        }
    }
    ll ret = 1<<30l;
    if(dif.size()==1){
        ret = dif[0];
    }
    else{
        for(int i=1;i<n;i++){
            ret = min(ret, gcd(dif[i-1],dif[i]));
            // cout << ret << endl;
        }
    }

    cout << ret << endl;


    return 0;
}


Measured memory_bytes: 2168
n, a, b = gets.split.map(&:to_i)

if (b - a).even?
  puts (b - a) / 2
else
  if a - 1 < n - b
    puts (a - 1) + 1 + (b - a - 1) / 2
  else
    puts (n - b) + 1 + (n - (a + (n - b + 1))) / 2
  end
end


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

int main(){
  string s;
  cin >> s;
  vector<char> vec(0);
  
  for(int i = 0; i < s.size(); i++){
  if(s.at(i) == '0' || s.at(i) == '1'){
    vec.push_back(s.at(i));
  }
  else if(s.at(i) == 'B' && vec.size() != 0){
    vec.pop_back();
    }
  }
  for(int i = 0; i < vec.size(); i++){
  cout << vec.at(i);
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	int n, i, j, k, x, ans;
	cin >> n;
	map<int, int> c;
	for (i = 0; i < n; i++) {
		cin >> x;
		c[x]++;
	}
	ans = 0;
	for (auto p : c) {
		if (p.first > p.second) ans += p.second;
		else ans += p.second - p.first;
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 4736
#include <iostream>
using namespace std;
main(){
	int i,j,k,n;string s;cin>>n>>s;
	long long x=0,r=0,g=0,b=0;
	for(i=0;i<n;i++){
		s[i]=='R'?r++:s[i]=='G'?g++:b++;
		for (j=i+1,k=i+2;k<n;k+=2,j++)if((s[i]^s[j]^s[k])==('R'^'G'^'B'))x++;
	}
	cout<<r*g*b-x<<endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<math.h>
#include<algorithm>
#define ll long long int
#define FOR(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n)
  
using namespace std;

int main() {
	int n, y;
	cin >> n >> y;
	REP(i,n+1) {
		REP(j,n-i+1) {
			if ( 10000*i + 5000*j + 1000*( n - i - j ) == y ) {
				cout << i << " " <<  j << " " << n - i - j << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;	
}

Measured memory_bytes: 256
import sys
 
input = sys.stdin.readline
N,K=map(int,input().rstrip().split())
D=list(map(int,input().rstrip().split()))
sys.setrecursionlimit(10**6)

def dfs(N):
    for i in range(K):
        if(str(N).find(str(D[i]))!=-1):
            dfs(N+1)
            return
    else:
        print(N)
    
    

dfs(N)


Measured memory_bytes: 75484
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

//const LLONG GetAllNum(const int digit)
//{
//    LLONG ret = 0;
//    if (digit == 1) ret += 9;
//    if (digit == 2) ret += 99;
//    if (digit == 3) ret += 2610;
//    if (digit == 4) ret += 810000 + 162000 + 16200 + 1800;
//    return ret;
//}

const LLONG ComputeNumerObPossibleB(const int N, const int Ndigit, const int A)
{
    int top = to_string(A).front() - '0';
    int bottom = A % 10;
    if (bottom == 0) return 0;
    LLONG ret = 0;
    // XYYXという形になるとき，BとしてXを選んでよい
    if (top == bottom)
    {
        if (top <= N) ++ret;
    }
    // Nが３桁以上のとき，Nの桁数以下の値BT,BXT,BXXT,...をBとして選んでよい
    int Bdigit = 2;
    for (; Bdigit < Ndigit; ++Bdigit)
    {
        // 間に入る数の選び方
        LLONG num = 1;
        for (int i = 0; i < Bdigit - 2; ++i) num *= 10;
        ret += num;
    }
    // Nと同じ桁数のB候補を数える
    if (Ndigit == 2)
    {
        int B = bottom * 10 + top;
        if (B <= N) ++ret;
    }
    // Nが３桁以上のとき，Nと同じ桁数のBXXTという形のBを考える
    else if (Ndigit >= 3)
    {
        int init = bottom;
        for (int i = 1; i < Ndigit; ++i) init *= 10;
        init += top;    // B00T
        // BXXTという形のBのうち，最大の数を求める
        int possibleMax = init + static_cast<int>(pow(10, Ndigit - 1)) - 10;
        int maxB = min(N, possibleMax);
        if (maxB >= init)
        {
            ret += (maxB - init) / 10 + 1;
        }
    }
    return ret;
}

const int ComputeDigit(const int N)
{
    int tmp = N;
    int digit = 1;
    for (;;)
    {
        tmp /= 10;
        if (tmp == 0) break;
        ++digit;
    }
    return digit;
}

int main()
{
    int N;
    cin >> N;
    LLONG ans = 0;
    int digit = ComputeDigit(N);
    for (int A = 1; A <= N; ++A)
    {
        ans += ComputeNumerObPossibleB(N, digit, A);
    }
    cout << ans << endl;
}

    //int digit = 1;
    //for (;;)
    //{
    //    N /= 10;
    //    if (N == 0) break;
    //    ++digit;
    //}
    //LLONG ans = 0;
    //for (int d = 1; d < digit; ++d)
    //{
    //    ans += GetAllNum(d);
    //}
    //if (digit == 1)
    //{
    //    cout << N << endl;
    //}
    //else if (digit == 2)
    //{
    //    int top = N / 10;
    //    int bottom = N % 10;
    //    for (int a = 1; a < top; ++a)
    //    {
    //    }
    //}
//}


Measured memory_bytes: 256
using System;

namespace aoj
{
    class Program
    {
        static void Main(string[] args)
        {
            var length = int.Parse(Console.ReadLine());
            
            var minv = int.Parse(Console.ReadLine());
            var input = int.Parse(Console.ReadLine());
            var maxv = input - minv;
            if (input < minv) { minv = input; }
            
            for (var i = 2; i < length; ++i)
            {
                input = int.Parse(Console.ReadLine());
                if (maxv < input - minv) { maxv = input - minv; }
                if (input < minv) { minv = input; }
            }
            Console.WriteLine(maxv);
        }
    }
}



Measured memory_bytes: 20108
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <bitset>
#include <complex>
using namespace std;

const double EPS = 1e-9;
const double PI = 3.14159265359;

typedef complex<double> P;

int main(){
	double x, h;

	while(cin >> x >> h, x+h){
		printf("%lf\n", sqrt(x*x/4+h*h)*x*2+x*x);
	}

	return 0;
}

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

struct Point {
  long x, y;
  Point(long x = 0, long y = 0) : x(x), y(y) {}
};

std::istream& operator>>(std::istream &is, Point &p)
{
  is >> p.x >> p.y;
  return is;
}

long distance(const Point &p, const Point &q) {
  return std::abs(p.x - q.x) + std::abs(p.y - q.y);
}

int main()
{
  unsigned N, M;
  std::cin >> N >> M;
  
  std::vector<Point> v(N);
  for (unsigned n = 0; n < N; ++n) {
    std::cin >> v[n];
  }
  
  std::vector<Point> u(M);
  for (unsigned m = 0; m < M; ++m) {
    std::cin >> u[m];
  }
  
  for (unsigned n = 0; n < N; ++n) {
    long min = 1e+18;
    unsigned index = -1;
    for (unsigned m = 0; m < M; ++m) {
      long d = distance(v[n], u[m]);
      if (min > d) {
        min = d;
        index = m;
      }
    }
    std::cout << (index + 1) << std::endl;
  }
  
  return 0;
}

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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int one, two, three;
int main() {
    //cout.precision(10);
    int n;
    cin >> n;
    int a, b;
    cin >> a >> b;
    for(int i = 1; i <= n; i++){
        int p;
        cin >> p;
        if(p <= a) {
            one++;
        } else if(p <= b) {
            two++;
        } else {
            three++;
        }
    }
    cout << min(one, min(two, three)) << endl;
    return 0;
}


Measured memory_bytes: 256
from sys import stdin
import sys
import itertools
import array
import textwrap
import math

N = int(input())
A = list(map(int, input().split()))
A.sort()
ans = A[-1]
c = len(A)-2
temp = len(A)-2
d = 0
for i in range(c):
    ans += A[temp]
    d += 1
    if d == 2:
        d = 0
        temp = temp-1
print(ans)


Measured memory_bytes: 33028
n,m=map(int,input().split())
data=[input().split() for _ in range(m)]
ans=["0"]*n
for s,c in data:
  s=int(s)-1
  if ans[s]!="0" and ans[s]!=c:
    print(-1)
    exit()
  if n!=1 and s==0 and c=="0":
    print(-1)
    exit()
  ans[s]=c
if n!=1 and ans[0]=="0":
  ans[0]="1"
print("".join(ans))

Measured memory_bytes: 3064