akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations

N = int(input())
P = tuple([int(i) for i in input().split()])
Q = tuple([int(i) for i in input().split()])

a, b = 0, 0
for i, v in enumerate(permutations(range(1, N+1), N)):
    if v == P:
        a = i
    if v == Q:
        b = i

print(abs(a-b))

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

int main(){
  int N;
  cin >> N;
  vector<int> d(N);
  for(int i = 0; i < N; i++){
    cin >> d[i];
  }
  int x = 0;
  int y = 101;
  int max;
  for(int i = 0; i < N; i++){
    max = 0;
    for(int j = 0; j < N; j++){
      if(max <= d[j] && d[j] < y ){
        max = d[j];
      }
    }
    y = max;
    if(max != 0){
      x++;
    }
  }
  cout << x << endl;
}

    


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)  
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  string s;
  cin>>s;
  if(s.length()==3){
    reverse(s.begin(),s.end());
  }
  cout<<s<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast")
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
using ll=long long;
using P=pair<ll,ll>;
using PP=tuple<ll,ll,ll>;
using S=multiset<ll>;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
void decimal(int x){cout<<fixed<<setprecision(x);}
//ll GCD(ll a,ll b){if(b==0) return a; return GCD(b,a%b);}
//ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*POW(a,b-1)%mod;ll k=POW(a,b/2);return k*k%mod;}
vi calc(ll x){vi res;while(x>0){res.eb(x%10);x/=10;}reverse(all(res));return res;}

void solve(){
  int x,y;
  cin>>x>>y;
  bool f=false;
  rep(i,x+1){
    int j=x-i;
    if(i*4+j*2==y) f=true;
  }
  YesNo(f);
}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

/*  FordFulkerson: Ford-Fulkersonのアルゴリズムで最大流を求める構造体

    verify : http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=GRL_6_A&lang=ja

    max_flow(G,s,t)：sからtへのグラフGの最大流を求める
    副作用：G は最大流の残余ネットワークになる
    計算量: O(|f*||E|) (f*:最大流) (この最悪ケースになることはほぼ無い)
*/

template <class T>
struct Edge {
    int rev, from, to;  // rev:逆向きの辺の番号
    T cap, original_cap;
    Edge(int r, int f, int t, T c) : rev(r), from(f), to(t), cap(c), original_cap(c) {}
};
template <class T>
struct Graph {
    vector<vector<Edge<T>>> G;
    Graph(int n = 0) : G(n) {}
    vector<Edge<T>>& operator[](int i) { return G[i]; }
    const size_t size() const { return G.size(); }
    Edge<T>& redge(Edge<T> e) {  // 逆向きの辺を返す
        return G[e.to][e.rev];   // 自己ループはないと仮定（あれば G[e.to][e.rev + 1] とする必要がある）
    }
    void add_edge(int from, int to, T cap) {  // 有向辺を加える
        G[from].push_back(Edge<T>((int)G[to].size(), from, to, cap));
        G[to].push_back(Edge<T>((int)G[from].size() - 1, to, from, 0));
    }
};
/* FordFulkerson: Ford-Fulkersonのアルゴリズムで最大流を求める構造体
    max_flow(G,s,t)：sからtへのグラフGの最大流を求める
    副作用：G は最大流の残余ネットワークになる
    計算量: O(|f*||E|) (f*:最大流) (この最悪ケースになることはほぼ無い)
*/
template <class T>
struct FordFulkerson {
    const T INF = 1e9;
    vector<int> used;
    FordFulkerson(){};
    T dfs(Graph<T>& G, int v, int t, T f) {  // 増加可能経路を見つけて増加分のフローを返す
        if (v == t) return f;
        used[v] = true;
        for (auto& e : G[v]) {
            if (!used[e.to] && e.cap > 0) {
                T d = dfs(G, e.to, t, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G.redge(e).cap += d;
                    return d;
                }
            }
        }
        return 0;
    }
    T max_flow(Graph<T>& G, int s, int t) {
        T flow = 0;
        while (true) {
            used.assign(G.size(), 0);
            T f = dfs(G, s, t, INF);  // f が増加分のフロー
            if (f == 0) {
                return flow;
            } else {
                flow += f;
            }
        }
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll V, E;
    cin >> V >> E;
    Graph<ll> g(V);
    rep(i,E) {
        ll u, v, c;
        cin >> u >> v >> c;
        g.add_edge(u, v, c);
    }
    FordFulkerson<ll> ff;
    ll ans = ff.max_flow(g, 0, V-1);
    cout << ans << endl;
}



Measured memory_bytes: 3272
#include <iostream>
#include <cstring>

constexpr int MAX_X = 1000000, MAX_N = 30;

int value[MAX_N], n, x;
bool dp[MAX_X + 1];
bool is_prime_number[MAX_X + 1];

void initialize();

void solve();

int main(){
    initialize();

    while(true){
        std::cin >> n >> x;
        if(n == 0 && x == 0){
            break;
        }
        
        memset(dp, false, x + 1);

        dp[0] = true;

        for(int i = 0; i < n; ++i){
            std::cin >> value[i];
            dp[value[i]] = true;
        }

        solve();
    }
    return 0;
}

void solve(){
    int ans = 0;

    for(int i = 2; i < x + 1; ++i){
        for(int j = 0; j < n; ++j){
            if(i >= value[j]){
                if(dp[i - value[j]]){
                    dp[i] = true;

                    if(is_prime_number[i]){
                        ans = std::max(ans, i);
                    }

                    break;
                }
            }
        }
    }

    if(ans){
        std::cout << ans << std::endl;
    }
    else{
        std::cout << "NA" << std::endl;
    }
}

void initialize(){
    memset(is_prime_number, true, MAX_X + 1);

    is_prime_number[0] = false, is_prime_number[1] = false;
    for(int i = 2; i * i < MAX_X + 1; ++i){
        if(is_prime_number[i]){
            for(int j = 2; i * j < MAX_X + 1; ++j){
                is_prime_number[i * j] = false;
            }
        }
    }
}

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

using namespace std;
typedef long long ll;
const int MAXN = 200100;

int N;
ll K;
vector <ll> neg;
vector <ll> pos;
ll n0;

ll csolve (vector <ll> v, ll M)
{
    ll res = 0;
    int cpos = (int) v.size() - 1;
    for (int i = 0; i < v.size(); i++)
    {
        while (cpos > i && v[i] * v[cpos] > M)
            cpos--;
        res += max (0, cpos - i);
    }
    return res;
}

ll ncnt (ll M)
{
    // # of values <= M
    ll res = 0;
    if (M >= 0)
    {
        res += n0 * (N - n0);
        res += (n0 * (n0 - 1)) / 2;
        res += neg.size() * pos.size();
        res += csolve (neg, M) + csolve (pos, M);
    }
    else
    {
        M = -M;
        int cpos = (int) pos.size() - 1;
        for (int i = 0; i < neg.size(); i++)
        {
            while (cpos >= 0 && neg[i] * pos[cpos] >= M)
                cpos--;
            res += (int) pos.size() - 1 - cpos;
        }
    }
    return res;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin >> N >> K;
    for (int i = 0; i < N; i++)
    {
        ll x; cin >> x;
        if (x < 0)
            neg.push_back(-x);
        else if (x > 0)
            pos.push_back(x);
        else
            n0++;
    }
    sort (neg.begin(), neg.end());
    sort (pos.begin(), pos.end());

    ll lo = 0, hi = 4e18;
    ll Y = 2e18;
    while (lo < hi)
    {
        ll mid = (lo + hi) / 2;
        if (ncnt (mid - Y) >= K)
            hi = mid;
        else
            lo = mid + 1;
    }
    cout << lo - Y << "\n";
}


Measured memory_bytes: 3308
import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => root(p)
  }
}

object Main {
  val m = (1 << 9) - 1

  def solve(sc: => Scanner): Unit = {
    val N, M = sc.nextInt
    val A = Array.fill(N)(0)
    Array.fill(M) {
      val a, b = sc.nextInt - 1
      A(a) += 1
      A(b) += 1
    }

    println(if (A.map(_ % 2 == 0).fold(true)((a, b) => a & b)) ("YES") else ("NO"))
  }

  def recursive(now: Int, A: Array[List[Int]]): Int = {
    if (A(now).size == 0) (now) else {
      val next = A(now).head
      A(now) = A(now).filter(_ != next)
      A(next) = A(next).filter(_ != now)
      recursive(next, A)
    }
  }

  def check(A: Array[List[Int]]): Boolean = {
    A.map(_.size == 0).fold(true)((a, b) => a & b)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def calc(v: Long): Long = (v + 1) * v / 2

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

Measured memory_bytes: 70268
import java.util.ArrayList;
import java.util.Scanner;

class Main{

	static int N;
	static int M;
	static 		ArrayList<ArrayList<Integer>> map;
	static boolean[] used;
	static int f = 0;
	static int s = 0;

	static int mindis = 1000000000;
	static ArrayList<Integer> saitan;




	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);			//文字の入力
		N = sc.nextInt();
		long sum = 0;

		map = new ArrayList<ArrayList<Integer>>();
		for(int i = 0;i <= N;i++){								//初期値入力
			ArrayList<Integer> x = new ArrayList<Integer>();
			x.add(0);
			map.add(x);
		}

		for(int i = 0;i < N-1;i++){							//mapの作成
			int a = sc.nextInt();
			int b = sc.nextInt();
			map.get(a).add(b);
			map.get(b).add(a);
		}
		
		int[] dataf = new int[N+1];
		dataf	= dfs(1,-1,dataf);
		int[] datas = new int[N+1];
		datas	= dfs(N,-1,datas);

		int a = 0;
		int b= 0;
		
		for(int i= 1;i < N+1;i++){				//距離が近い方が結局は近い方の色になるので、それぞれの辺についてどちらが近いかみる
			if(dataf[i] <= datas[i]){
				a++;

			}else{
				b++;
			}

		}
		if(a > b){
			System.out.println("Fennec");
		}else{
			System.out.println("Snuke");
		}

	}

	static int[] dfs(int p,int back, int[] data){				//始点からそれぞれの辺までの距離を求める
		//pは現在地、backは一個前の場所
		
		ArrayList<Integer> edge = map.get(p);				//辺のリスト
		for(int v : edge){
			if(v != back){									//一個前と今の辺は繋がっているので無限ループに入るのを防ぐ
				data[v] = data[p] + 1;
				dfs(v, p, data);
			}

		}
		return data;

	}





}




Measured memory_bytes: 112164
def main():
    n = int(input())
    W = [input() for _ in range(n)]

    if n != len(set(W)):
        print("No")
        return

    for i in range(n-1):
        if W[i][-1] != W[i+1][0]:
            print('No')
            return
    print('Yes')


if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define yn(x, ok, ng) cout << ((x)?(ok):(ng)) << endl
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}
int const INF = 1001001001;


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

int D;
cin >> D;
vi c(26);
rep(i,26) cin >> c[i];
vvi s(D,vi(26));
rep(d,D) rep(i,26) cin >> s[d][i];
vi t(D);
rep(d,D) {
    cin >> t[d];
    t[d]--;
}

vi last(26,-1);

int res = 0;
rep(d,D) {
    res += s[d][t[d]];
    last[t[d]] = d;
    rep(i,26) {
        res -= c[i] * (d - last[i]);
    }
    cout << res << endl;
}

return 0;
}

Measured memory_bytes: 3704
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    ll r;
    cin>>r;
    cout<<2*PI*r<<endl;
}

Measured memory_bytes: 3788
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	int N, K;
	int[] P;
	double[] ave;
	double result = 0.0;

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		N = Integer.parseInt(tokens[0]);
		K = Integer.parseInt(tokens[1]);
		P = new int[N];
		tokens = in.readLine().split(" ");
		for (int i = 0; i < N; ++i) {
			P[i] = Integer.parseInt(tokens[i]);
		}
		// それぞれの期待値を求めておく
		ave = new double[N];
		for (int i = 0; i < N; ++i) {
			ave[i] = getAve(P[i]);
		}

	}

	double getAve(int p) {
		return (double) (1 + p) / 2.0;
	}

	void calc() {
		double sum = 0.0;
		// 初期解
		for (int i = 0; i < K; ++i) {
			sum += ave[i];
		}
		result = sum;
		// 順にずらしながら探す
		for (int i = K; i < N; ++i) {
			sum -= ave[i - K];
			sum += ave[i];
			result = Math.max(sum, result);
		}
	}

	void showResult() {
		System.out.println(result);
	}
}


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

int main() {

	int n1 = 0,n2 = 0,n3= 0;
	cin >> n1 >> n2 >> n3;

	if(n3 >= n1 && n3 <= n2){
		cout << "Yes";
	}else{
		cout << "No";
	}


	// your code goes here
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
using namespace std;
string s;
int l;
int main() {
	cin>>s;
	l=s.size();
	for( register int i=0; i<l; i++ ) {
		if( s[i]=='C' ) {
			for( register int j=i+1; j<l; j++ ) {
				if( s[j]=='F' ) {
					cout<<"Yes";
					return 0;
				}
			}
		}
	}
	cout<<"No";
	return 0;
}


Measured memory_bytes: 256
nim, M = map(int, input().split())
ps = list(map(int, input().split()))
G = list(range(nim))
def getparent(n):
  if G[n] == n:
    return n
  G[n] = getparent(G[n])
  return G[n]
for i in range(M):
  x, y = map(int, input().split())
  x, y = x-1, y-1
  x = getparent(x)
  y = getparent(y)
  G[x] = y
Ss = [set() for i in range(nim)]
for i in range(nim):
  j = getparent(i)
  Ss[j].add(ps[i])
r = 0
for i in range(nim):
  if i+1 in Ss[G[i]]:
    r += 1
print(r)


Measured memory_bytes: 40676
var a:array[0..1000]of longint;
    n,i,j,t,s:longint;
begin
  readln(n);
  for i:=1 to 2*n do
    read(a[i]);
  for i:=1 to 2*n do
    for j:=i+1 to 2*n do
      if a[i]>a[j] then
      begin
        t:=a[i];a[i]:=a[j];a[j]:=t;
      end;
  for i:=1 to n do
    inc(s,a[2*i-1]);
  writeln(s);
end.

Measured memory_bytes: 128
#include<iostream>
#include<math.h>
#include<cstdio>
#include<cstring>
#include<string>
#include<string.h>
#include<cmath>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
int main()
{
	int n,k,s=1;
	cin>>n>>k;
	for(int i=0;i<n;i++)
	{
		if(s>=k)
		s+=k;
		else
		s*=2;
	}
	cout<<s;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <cstring>
#include <cstdio>
#include <cmath>

using namespace std;

void f(const int,const int,int*);

int main()
{
    priority_queue<int> qu;
    char str[8];
    int num;
    while(1){
        scanf("%s",str);
        if(!strcmp(str,"insert")){
            scanf("%d",&num);
            qu.push(num);
        }else if(!strcmp(str,"end")){
            break;
        }else{
            printf("%d\n",qu.top());
            qu.pop();
        }
    }
}

Measured memory_bytes: 7252
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}





int main() {
	ll D;
	cin >> D;
	vector<ll> c(27);
	vector<vector<ll>> s(D+1, vector<ll>(27));
	vector<ll> zenkai(27);/*各nameコンテストが前回行われた日*/

	for (ll name = 1; name <= 26; name++)cin >> c.at(name);

	for (ll day = 1; day <= D; day++) { 
		for (ll name = 1; name <= 26; name++) { 
			cin >> s.at(day).at(name); 
		}
	}
	vector<ll> t(D+1); 

	/*for (ll day = 1; day <= D; day++) {
		cin >> t.at(day);
	}*/
	
	for (ll name = 1; name <= 26; name++) {
		zenkai.at(name) = 0;
	}

	ll an =0;/*満足度*/
	ll n = 0;/*各日のコンテスト仮*/
	for (ll day = 1; day <= D; day++) {
		ll karimax = an-999999999999;
		n = -1;
		for (ll kariname = 1; kariname <= 26; kariname++) {
			ll karian = an;
			
			karian += s.at(day).at(kariname);
			/*zenkai.at(t.at(day)) = day;*/

			for (ll name = 1; name <= 26; name++) {
				if (name != kariname) {
					an -= c.at(name) * (day - zenkai.at(name));
				}
			}
			
			if (karian >= karimax) {
				n = kariname;
				karimax = karian;
			}
		}
		if (n == -1) {
			n = 1;
		}
		an += s.at(day).at(n);
		zenkai.at(n) = day;

		for (ll name = 1; name <= 26; name++) {
			
				an -= c.at(name) * (day - zenkai.at(name));
			
		}
		
			cout << n << endl;
	

	}
	/*cout << an << endl;*/

}

Measured memory_bytes: 3720
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    println!("{}", solve(&stdin!()));
}
fn solve(src: &str) -> String {
    input! {
        source = src,
        n:usize,
    }
    let mut s = String::new();
    while {
        n -= 1;
        let c = ((n % 26) as u8 + 'a' as u8) as char;
        s.push(c);
        n /= 26;
        n > 0
    } {}
    s.chars().rev().collect::<String>()
}
test! {
    "2" => "b",
    "27" => "aa",
    "123456789" => "jjddja",
}


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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);

    int n, x, t;
    cin >> n >> x >> t;

    cout << (n + x - 1) / x * t << "\n";

    return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>
static const int N =100;
int min(int ,int );

int main()
{
  int i,j,k,n,l,a=0;
  int p[N+1];
  int m[N+1][N+1];
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    {
      scanf("%d",&p[i-1]);
      scanf("%d",&p[i]);	    
    }

  for(i=1;i<=n;i++) m[i][i] =0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j] =(1<<21);
      for(k=i;k<=j-1;k++){
	m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
    }
  }
  
  /*
  for (i=1;i<=n;i++){
    for(j=1;j<=n;j++){
      printf("%d ",m[i][j]);
    }
    printf("\n");
  }
  */
  
  printf("%d\n",m[1][n]);
	  
  return  0;
}
int min(int x,int y)
{
  if(x>y)return y;
  else return x;
  
}



Measured memory_bytes: 2056
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <numeric>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <deque>
#include <cmath>
#include <complex>
#include <cassert>
#include <cstring>
#include <functional>
#include <bitset>
#include <climits>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define cmn(x,y) x=min(x,y)
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}
template<typename T> class segtree {
private:
    int n,sz;
    vector<pair<T, int> > node;
public:
    segtree(vector<T>& v){
        sz = (int)v.size();
        n = 1;
        while(n < sz){
            n *= 2;
        }
        node.resize(2*n);
        rep(i,sz){
            node[i+n] = make_pair(v[i], i);
        }
        for(int i=n-1; i>=1; i--){
            node[i] = min(node[2*i], node[2*i+1]);
        }
    }
    void update(int k, T a)
    {
    	node[k+=n] = make_pair(a, k);
    	while(k>>=1){
            node[k] = min(node[2*k], node[2*k+1]);
    	}
    }
    pair<T, int> query(int a,int b,int k=0,int l=0,int r=-1)
    {
        pair<T, int> res1 = make_pair(numeric_limits<T>::max(), -1);
        pair<T, int> res2 = make_pair(numeric_limits<T>::max(), -1);
        a += n, b += n;
        while(a != b){
            if(a % 2) cmn(res1, node[a++]);
            if(b % 2) cmn(res2, node[--b]);
            a >>= 1, b>>= 1;
        }
        return min(res1, res2);
    }
    void print()
    {
        rep(i,sz){
            pair<T, int> p;
            p = query(i,i+1);
            cout << "st[" << i << "]: " << p.first << " " << p.second << endl;
        }
    }
};


int n;
ll d;
ll saiki(segtree<ll>& sg, int a,int b){
    //cerr << a << " " << b << endl;
    if(b==a+1)return 0;
    auto p = sg.query(a,b);
    ll s = p.first;
    ll ans = 0;
    int ind = p.second;
    if(ind-1>=a){
        ll xx = sg.query(ind-1,ind).first;
        ans += s+d+xx;
        sg.update(ind-1,min(xx,s+d));
        ans += saiki(sg,a,ind);
    }
    if(ind+1<b){
        ll xx = sg.query(ind+1,ind+2).first;
        ans += s+d+xx;
        sg.update(ind+1,min(xx,s+d));
        ans += saiki(sg,ind+1,b);
    }
    return ans;
}


int main(){
    cin >> n >> d;
    vector<ll>v(n);
    rep(i,n)cin >> v[i];
    segtree<ll> sg(v);
    ll ans = saiki(sg,0,n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 34944
#include <iostream>
#include <cstring>
#include <string>
#include <cstdlib>
using namespace std;
 
int main(){
    string s;
    int n,m,mem,plnum;
    while(1){
        int cnt = 0;
        plnum = 1;
        cin >> m >> n;
        if(m == 0 && n == 0) break;
        bool pl[m+1];
        memset(pl,true,sizeof(pl));
        for(int i=1;i<=n;i++){
            cin >> s;
            if(i % 15 == 0){
	      if(s != "FizzBuzz"){
                pl[plnum] = false;
                cnt++;
	      }
            }
            else if(i % 3 == 0){
	      if(s != "Fizz"){
                cnt++;
                pl[plnum] = false;
	      }
            }
            else if(i % 5 == 0){
	      if(s != "Buzz"){
                cnt++;
                pl[plnum] = false;
	      }
            }
	    else if(i != atoi(s.c_str())){
	      cnt++;
	      pl[plnum] = false;
	    }
            if(m - cnt == 1){
                for(int j=i+1;j<=n;j++) cin >> s;
                break;
            }
            do{
                (plnum == m)? plnum = 1 : plnum++;
            }while(!pl[plnum]);
        }
        for(int i=1;i<=m;i++) {
            if(pl[i]) mem = i;
        }
        for(int i=1;i<=mem;i++){
            if(pl[i]) {
                (i == mem)? cout << i << endl : cout << i << " ";
            }
        }
    }
}

Measured memory_bytes: 1228
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N = gete(int)
    a = (geta(int) for _ in range(N))

    dp = [[0]*3 for _ in range(N+1)]

    for i, ai in enumerate(a):
        for j in range(3):
            dp[i+1][j] = max(dp[i][j-1], dp[i][j-2]) + ai[j] 


    print(max(dp[N]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 58860
package main

import (
	"container/list"
	"fmt"
)

const maxCost = 401

func bfs(i, j int, m [][]byte, visited [][]bool) int {
	queue := list.New()
	next := [][]int{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}
	queue.PushBack([]int{i, j, 0})
	reset(visited)

	maxCost := -1
	for queue.Len() > 0 {
		e := queue.Front()
		c := e.Value.([]int)
		queue.Remove(e)
		if m[c[0]][c[1]] == '#' || visited[c[0]][c[1]] {
			continue
		}

		visited[c[0]][c[1]] = true
		if maxCost < c[2] {
			maxCost = c[2]
		}

		for _, n := range next {
			ni, nj, nc := c[0]+n[0], c[1]+n[1], c[2]+1
			if ni < 0 || ni >= len(m) || nj < 0 || nj >= len(m[0]) {
				continue
			}
			queue.PushBack([]int{ni, nj, nc})
		}

	}
	return maxCost
}

func reset(v [][]bool) {
	for i := 0; i < len(v); i++ {
		for j := 0; j < len(v[0]); j++ {
			v[i][j] = false
		}
	}
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)

	m := make([][]byte, h)
	v := make([][]bool, h)
	for i := 0; i < h; i++ {
		var s string
		fmt.Scan(&s)
		m[i] = make([]byte, w)
		v[i] = make([]bool, w)
		for j := 0; j < w; j++ {
			m[i][j] = s[j]
		}
	}

	ans := 0
	for i := 0; i < h; i++ {
		for j := 0; j < w; j++ {
			c := bfs(i, j, m, v)
			if ans < c {
				ans = c
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 5504
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
typedef long long ll;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (b - a == c - b) cout << "YES" << endl;
	else cout << "NO" << endl;

	return 0;
}


Measured memory_bytes: 256
// IO library
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>

// container library
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

// namespace
using namespace std;

// typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VB> VVB;

// conversion
#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)

// container
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); i++)
#define SORT(c) sort((c).begin(), (c).end())
#define GSORT(c) sort((c).begin(), (c).end(), greater<decltype((c).front())>())
#define SZ(x) (INT((x).size()))
#define MEMSET(c, v) memset((c), v, sizeof(c))

// repetition
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define NREP(i, n) FOR(i, 1, n + 1)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define RREP(i, n) RFOR(i, n, 0)
#define RNREP(i, n) RFOR(i, n, 1)

// constant
// const ll MOD = 1e9 + 7;
// const int INF = 1<<25;
// const ll INF = 1LL<<50;
// const int dx[4] = {0, -1, 1, 0};
// const int dy[4] = {-1, 0, 0, 1};
// const int dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1};
// const int dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1};

// debug
#define test(x) cout << #x << " = " << x << endl

// answer output
#define Yes(c) cout << ((c) ? "Yes" : "No") << endl;
#define YES(c) cout << ((c) ? "YES" : "NO") << endl;
#define yes(c) cout << ((c) ? "yes" : "no") << endl;

#define possible(c) cout << ((c) ? "possible" : "impossible") << endl;
#define POSSIBLE(c) cout << ((c) ? "POSSIBLE" : "INPOSSIBLE") << endl;


// --------------------------------------------------------


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

  int N;
  ll W;
  cin >> N >> W;

  VVL value(4);

  int w1, v1;
  cin >> w1 >> v1;
  value[0].push_back(v1);

  REP(i, N - 1) {
    int w, v;
    cin >> w >> v;
    value[w - w1].push_back(v);
  }

  VVL vsum(4);
  REP(i, 4) {
    GSORT(value[i]);
    vsum[i].resize(value[i].size() + 1);
    vsum[i][0] = 0;
    NREP(j, value[i].size()) {
      vsum[i][j] = vsum[i][j - 1] + value[i][j - 1];
    }
  }

  VL num(4, 0);
  ll maxV = 0;

  for (num[0] = 0; num[0] <= value[0].size(); num[0]++) {
    for (num[1] = 0; num[1] <= value[1].size(); num[1]++) {
      for (num[2] = 0; num[2] <= value[2].size(); num[2]++) {
        for (num[3] = 0; num[3] <= value[3].size(); num[3]++) {
          ll wpart = 0, vpart = 0;
          REP(i, 4) {
            wpart += num[i] * (w1 + i);
            vpart += vsum[i][num[i]];
          }
          if (wpart <= W) {
            maxV = max(maxV, vpart);
          }
        }
      }
    }
  }

  cout << maxV << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX = 1400;
int main() {
	int num[4];
	for (int i = 0; i < 4; i++) {
		scanf("%1d", &num[i]);
	}
	int ans[8];
	ans[0] = num[0] + num[1] + num[2] + num[3];
	ans[1] = num[0] + num[1] + num[2] - num[3];
	ans[2] = num[0] + num[1] - num[2] + num[3];
	ans[3] = num[0] + num[1] - num[2] - num[3];
	ans[4] = num[0] - num[1] + num[2] + num[3];
	ans[5] = num[0] - num[1] + num[2] - num[3];
	ans[6] = num[0] - num[1] - num[2] + num[3];
	ans[7] = num[0] - num[1] - num[2] - num[3];
	for (int i = 0; i < 8; i++) {
		if (ans[i] == 7) {
			switch (i) {
			case 0:
				cout << num[0] << "+" << num[1] << "+" << num[2] << "+" << num[3] << "=7" << endl;
				break;
			case 1:
				cout << num[0] << "+" << num[1] << "+" << num[2] << "-" << num[3] << "=7" << endl;
				break;
			case 2:
				cout << num[0] << "+" << num[1] << "-" << num[2] << "+" << num[3] << "=7" << endl;
				break;
			case 3:
				cout << num[0] << "+" << num[1] << "-" << num[2] << "-" << num[3] << "=7" << endl;
				break;
			case 4:
				cout << num[0] << "-" << num[1] << "+" << num[2] << "+" << num[3] << "=7" << endl;
				break;
			case 5:
				cout << num[0] << "-" << num[1] << "+" << num[2] << "-" << num[3] << "=7" << endl;
				break;
			case 6:
				cout << num[0] << "-" << num[1] << "-" << num[2] << "+" << num[3] << "=7" << endl;
				break;
			default:
				cout << num[0] << "-" << num[1] << "-" << num[2] << "-" << num[3] << "=7" << endl;
				break;
			}
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
using namespace std;

int x[2000], y[2000];

int main()
{
	int W, H, N;
	int X, Y;
	
	int cnt = 0;
	
	scanf("%d %d %d", &W, &H, &N);
	for (int i = 0; i < N; i++){
		scanf("%d %d", &x[i], &y[i]);
		if (i == 0){
			X = x[i];
			Y = y[i];
		}
		
		if (i > 0){
			while (x[i] != X || y[i] != Y){
				if (X < x[i] && Y < y[i]){
					X++;
					Y++;
				}
				else if (X > x[i] && Y > y[i]){
					X--;
					Y--;
				}
				else if (X == x[i]){
					if (Y > y[i]){
						Y--;
					}
					else {
						Y++;
					}
				}
				else {
					if (X > x[i]){
						X--;
					}
					else {
						X++;
					}
				}
				cnt++;
			}
		}
	}
	
	printf("%d\n", cnt);
	
	return 0;
}

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

public class Main {

	boolean in(int p, int q, int x) {
		// is x in segment p-q(inclusive)
		return (p <= x && x <= q) || (q <= x && x <= p);
	}

	static class Point implements Comparable<Point> {
		int x, y;

		public Point(int x, int y) {
			this.x = x;
			this.y = y;
		}

		@Override
		public int compareTo(Point o) {
			return Integer.compare(x, o.x);
		}
	}

	void submit() {
		int x1 = nextInt();
		int y1 = nextInt();
		int x2 = nextInt();
		int y2 = nextInt();

		int n = nextInt();

		Point[] a = new Point[n];

		int ptr = 0;

		for (int i = 0; i < n; i++) {
			int x = nextInt();
			int y = nextInt();
			if (!in(x1, x2, x) || !in(y1, y2, y)) {
				continue;
			}

			x = Math.abs(x - x1);
			y = Math.abs(y - y1);

			a[ptr++] = new Point(x, y);
		}

		a = Arrays.copyOf(a, ptr);

		int dx = Math.abs(x2 - x1);
		int dy = Math.abs(y2 - y1);

		if (dx > dy) {
			int tmp = dy;
			dy = dx;
			dx = tmp;

			for (Point p : a) {
				tmp = p.x;
				p.x = p.y;
				p.y = tmp;
			}
		}

		Arrays.sort(a);

		long base = 100L * (dx + dy);

		int[] arr = new int[a.length];
		for (int i = 0; i < a.length; i++) {
			arr[i] = a[i].y;
		}

		int[] aux = new int[a.length + 2];
		Arrays.fill(aux, Integer.MAX_VALUE);
		aux[0] = Integer.MIN_VALUE;

		int ans = 0;
		for (int x : arr) {
			int low = 0; // <
			int high = ans + 1; // >=

			while (high - low > 1) {
				int mid = (low + high) >> 1;
				if (aux[mid] < x) {
					low = mid;
				} else {
					high = mid;
				}
			}
			
			aux[high] = x;
			if (high == ans + 1) {
				ans++;
			}
		}
		
		double ret = base - BONUS * ans;
		
		if (a.length == dx + 1 && ans == a.length) {
			ret += BONUS;
			ret += PENALTY;
		}
		
		out.println(ret);
	}

	static final double BONUS = 20 - 5 * Math.PI;
	static final double PENALTY = 10 * Math.PI - 20;

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	Main() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new Main();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


Measured memory_bytes: 53308
//#pragma GCC optimize("Ofast")

//#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
// From Geeksforgeeks
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
// Power function took from geeksforgeeks
ll power(ll x, ll y)
{
	ll res = 1;

	x = x%N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x)%N;
		y = y >> 1;
		x = (x * x)%N;
	}
	return res;
}
double dist(ll x1,ll y1, ll x2,ll y2)
{
	double ans = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	vector<ll> arr(n, 0);
	f(i, 0, n)
	{
		cin >> arr[i];
	}
	sort(all(arr));
	ll ans = 0;
	f(i, 0, n)
	{
		f(j, i + 1, n)
		{
			f(k, j + 1, n)
			{
				if (arr[k] < arr[i] + arr[j])
				{
					ans += 1;
				}

			}
		}
	}
	cout << ans;
	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++)
int64_t gcc(int64_t a,int64_t b){
  while(b!=0){
    int64_t r=a%b;
    a=b;
    b=r;
  }
  return a;
}
int main(){
  int64_t n,x;
  cin >> n>>x;
  vector<int64_t> a(n),y(n);
  rep(i,n){
    cin >> a.at(i);
    y.at(i)=abs(x-a.at(i));
  }
  int64_t ans=1e10;
  rep(i,n-1){
    int64_t q=gcc(y.at(i),y.at(i+1));
    ans=min(ans,q);
  }
  if(n==1){
    cout << abs(y.at(0));
    return 0;
  }
  cout << ans;
}

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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> columns(N, 0);
  vector<int> rows(N, 0);
  int full_rows = 0;
  int all_blacks = 0;
  for (int r = 0; r < N; ++r) {
    int blacks = 0;
    for (int c = 0; c < N; ++c) {
      char bw;
      cin >> bw;
      bool is_black = bw == '#';
      if (is_black) {
        ++all_blacks;
        ++rows[r];
        ++columns[c];
        ++blacks;
      }
    }
    if (blacks == N) ++full_rows;
  }
  int full_columns = count(columns.begin(), columns.end(), N);

  int ans = 2 * N + 1;
  if (all_blacks == 0) {
    ans = -1;
  } else if (full_rows > 0) {
    ans = N - full_columns;
  } else {
    int most = 2 * N - full_columns;
    for (int i = 0; i < N; ++i) {
      int a = most - rows[i] + (columns[i] == 0 ? 1 : 0);
      if (a < ans) ans = a;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main() {
	int a, b;

	scanf("%d %d", &a, &b);

	if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) printf("Possible\n");
	else printf("Impossible\n");

	return 0;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;
    if (abs(a - x) < abs(b - x)){
        cout << 'A' << endl;
    }else{
        cout << 'B' << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int K;
	cin>>K;
	string S;
	cin>>S;
	if(S.length() <=K)
	{
		cout<<S<<endl;
	}
	else
	{
		for(int i=0;i<K;i++)
		{
			cout<<S.at(i);
		}
		cout<<"..."<<endl;
	}
	return 0;
}

Measured memory_bytes: 3116
N=int(input())
S=input()

#ans = S.count('#')

cum1=[0]
cnt=0
for i in range(N):
  if S[i]=='#':
    cnt += 1
  cum1.append(cnt)
  
cum2=[0]
cnt=0
for s in reversed(S):
  if s=='.':
    cnt += 1
  cum2.append(cnt)
  
cum2 = cum2[::-1]

print(min([cum1[i]+cum2[i] for i in range(N+1)]))

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

using namespace std;

#define REP(i, N) for (int (i) = 0; (i) < (N); ++(i))
#define READALL(c) for (auto &e : c) { cin >> e; }
#define PRINTALL(c) for (const auto &e : c) { cout << e << "\t"; } cout << "\n";

template <typename T>
using V = vector<T>;

typedef long double ld;


int64_t fast(int64_t N, int64_t W, V<int> weights, V<int> values) {
	int64_t w0 = weights[0];

	V<V<int64_t>> items(4);

	REP(i, N) {
		items[weights[i]-w0].push_back(values[i]);
	}

	REP(i, 4) {
		sort(items[i].begin(), items[i].end());
		reverse(items[i].begin(), items[i].end());
	}

	// V<int64_t> csum3(items[3].size());
	// if (items[3].size())
	// 	csum3[0] = items[3][0];
	// for (int i = 1; i < items[3].size(); ++i) {
	// 	csum3[i] += csum3[i-1]+items[3][i];
	// }


	int64_t ans = 0, v0 = 0, v1 = 0, v2 = 0, v3 = 0;

	for (int64_t cnt0 = 0; cnt0 <= items[0].size(); ++cnt0) {
		v1 = 0;
		for (int64_t cnt1 = 0; cnt1 <= items[1].size(); ++cnt1) {
			v2 = 0;
			for (int64_t cnt2 = 0; cnt2 <= items[2].size(); ++cnt2) {
				v3 = 0;
				for (int64_t cnt3 = 0; cnt3 <= items[3].size(); ++cnt3) {
					if (cnt0*w0+cnt1*(w0+1)+cnt2*(w0+2)+cnt3*(w0+3) <= W)
						ans = max(ans, v0+v1+v2+v3);
					if (items[3].size())
						v3 += items[3][cnt3];
				}
				// int64_t cnt3 = N-(cnt0+cnt1+cnt2);
				// cnt3 = min(cnt3, (int64_t)items[3].size());
				// v3 = 0;
				// if (cnt3)
				// 	v3 = csum3[cnt3-1];
				// cout << cnt0 << " " << cnt1 << " " << cnt2 << " " << cnt3 << endl;
				// cout << cnt0 << " " << v1 << " " << v2 << " " << v3 << endl;
				// cout << endl;
				// if (cnt0*v0+cnt1*(w0+1)+cnt2*(w0+2)+cnt3*(w0+3) <= W)
				// 	ans = max(ans, v0+v1+v2+v3);
				if (items[2].size())
					v2 += items[2][cnt2];
			}
			if (items[1].size())
				v1 += items[1][cnt1];
		}
		if (items[0].size())
			v0 += items[0][cnt0];
	}
	return ans;
}

int64_t brute(int64_t N, int64_t W, V<int> weights, V<int> values) {
	int64_t ans = 0;
	for (int bs = 0; bs < (1<<N); ++bs) {
		int64_t v = 0, w = 0;
		REP(i, N) if (bs&(1<<i)) {
			v += values[i];
			w += weights[i];
		}
		if (w > W)
			continue;
		ans = max(ans, v);
	}
	return ans;
}

void test() {
	default_random_engine re;
	for (int tc = 0; tc < 1000; ++tc) {
		int64_t N = re()%10+1, W = re()%10+1;
		V<int> weights(N), values(N);
		int base = re()%9+1;
		REP(i, N) {
			if (i == 0)
				weights[i] = base;
			else
				weights[i] = base + (re()%4);
			values[i] = re()%9+1;
		}

		int64_t b = brute(N, W, weights, values);
		int64_t f = fast(N, W, weights, values);

		cout << N << " " << W << endl;
		REP(i, N) {
			cout << weights[i] << " " << values[i] << endl;
		}

		cout << b << " " << f << endl;
		assert(b == f);
		cout << "----" << endl;
	}
}

int main() {
	// test();
	// return 0;
	ios::sync_with_stdio(0);
	cin.tie(0);

	int64_t N, W;
	cin >> N >> W;

	V<int> weights(N), values(N);

	REP(i, N) {
		cin >> weights[i] >> values[i];
	}


	cout << fast(N, W, weights, values) << endl;

	
}

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

int main() {
    int N, M, L;
    cin >> N >> M >> L;
    long long A[N][M], B[M][L];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < M; j++) cin >> A[i][j];
    }
    for (int i = 0; i < M; i++) {
        for (int j = 0; j < L; j++) cin >> B[i][j];
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < L; j++) {
            long long tmp = 0;
            for (int k = 0; k < M; k++) tmp += A[i][k] * B[k][j];
            if (j) cout << " ";
            cout << tmp;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3240
#include<bits/stdc++.h>
using namespace std;
 
#define int long long
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
 
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}
 
signed main(){
    int N,M;cin>>N>>M;
 
    vint d(N);
    rep(i,M){
        int a,b;cin>>a>>b;
        a--;b--;
        d[a]++;d[b]++;
    }
 
    rep(i,N)cout<<d[i]<<endl;
    return 0;
}

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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
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; } }

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(a+b>c+d) cout << "Left" << endl;
    else if(a+b<c+d) cout << "Right" << endl;
    else cout << "Balanced" << endl;
    return 0;
}


Measured memory_bytes: 256
import bisect

n=int(input())
a=list(map(int,input().split()))

a.sort()

ans=0

for i in range(n-2):
    for j in range(i+1,n-1):
        under=a[i]+a[j]
        num=bisect.bisect_left(a,under)
        ans+=num-j-1

print(ans)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#pragma warning(disable:4996)
#ifdef _MSC_VER
#  define __builtin_popcount __builtin_popcountll
#  define __builtin_popcountll __popcnt
#endif
//#define int long long
using namespace std;
using ll = long long;
using ld = long double;
const long double PI = acos(-1.0);
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
inline void my_io() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout << fixed << setprecision(10);
}

signed main(){
	
	int n;
	cin >> n;
	unordered_set<string>st;
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		string str1;
		cin >> str1;
		if (str == "insert") {
			st.emplace(str1);
		}
		else {
			if (st.count(str1)) {
				cout << "yes" << endl;
			}
			else {
				cout << "no" << endl;
			}
		}
	}



}


Measured memory_bytes: 31884