akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>


using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	vector<int>s(M), c(M);
	for (int i = 0; i < M; i++) {
		cin >> s[i] >> c[i];
		s[i]--;
	}
	bool ok = false;
	for (int i = 0; i < 10; i++) {
		for (int j = 0; j < 10; j++) {
			for (int k = 0; k < 10; k++) {
				string S = to_string(i * 100 + j * 10 + k);
				if (S.size() != N) {
					break;
				}
				bool flag = true;
				for (int x = 0; x < M; x++) {
					if ((S[s[x]]-'0') != c[x]) {
						flag = false;
						break;
					}
				}
				if (flag) {
					cout << stoi(S) << endl;
					ok = true;
					break;
				}
			}
			if (ok)break;
		}
		if (ok)break;
	}
	if (!ok)cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
attrs = Array.new
while line = $stdin.gets
    attrs << line.chomp.split
end
N = attrs.shift[0].to_i
S = attrs.shift[0].split("")

prev = ""
result = 0

for i in 0..(N - 1) do
  if prev != S[i] then
    prev = S[i]
    result += 1
  end
end

puts result

Measured memory_bytes: 8700
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"unsafe":"safe")
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
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;}
const long long INFLL = 1LL<<62;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int s,w;
	int ans=0;
	cin >>s>>w;
	cout<<solve(s<=w)<<endl;
}

Measured memory_bytes: 3636
#include "stdio.h"

int main(){
	int H, W, i, j;
	for(;;){
		scanf("%d %d", &H, &W);	
		if(H==0 && W==0){
			break;
		}
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i+j)%2==0){printf("#");}
				else{printf(".");}
			}
			printf("\n");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 572
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
#define BIGP   1000000007
#define INF_I  std::numeric_limits<ll>::max()
#define INF_F  std::numeric_limits<float>::infinity()
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //
    ll H,A;
    cin >> H >> A;
    cout << (H + (A - 1)) / A;
    //
    return 0;
}

Measured memory_bytes: 3108
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int main() {
	char buf[512];
	int i;

	gets(buf);
	for (i = 0; i < strlen(buf); i++)
		buf[i] = toupper(buf[i]);
	printf("%s\n", buf);
	return 0;
}

Measured memory_bytes: 524
import java.io.*;
import java.util.*;
class Main{
	static final long MOD = 1_000_000_007; // 10^9+7
    static final int MAX = 2_147_483_646; // intMax 
    static final int INF = 1_000_000_000; // 10^9  
    public static void main(String[] args) throws Exception {
		hayami saori = new hayami();
		String[] s = saori.nextHayami().split("");
		boolean flg = true;
		for(int i = 0;i < s.length;i++){
			if(i%2 == 0){
				if(s[i].equals("h")){

				} else {
					flg = false;
				}
			} else {
				if(s[i].equals("i")){

				} else {
					flg = false;
				}
			}
		}
		if(s.length%2 == 1){
			flg = false;
		}
		if(flg){
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		
		saori.close();
    }
}

class hayami implements Closeable {
	private final InputStream in = System.in;
	private final byte[] hayami = new byte[1024];
	private int Hayami = 0;
	private int saori = 0;
	private boolean HayamiSaori() {
		if (Hayami < saori) {
			return true;
		}else{
			Hayami = 0;
			try {
				saori = in.read(hayami);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (saori <= 0) {
				return false;
			}
		}
		return true;
	}
	private int SaoriHayami() { 
		if (HayamiSaori()) {
            return hayami[Hayami++];
         }else{
             return -1;
         }
	}
	private static boolean hayami_saori(int hayami) { 
		return 33 <= hayami && hayami <= 126;
	}
	public boolean hayamisaori() { 
		while(HayamiSaori() && !hayami_saori(hayami[Hayami])) Hayami++; return HayamiSaori();
	}
	public String nextHayami() {
		if (!hayamisaori()) throw new NoSuchElementException();
		StringBuilder hayamin = new StringBuilder();
		int saori = SaoriHayami();
		while(hayami_saori(saori)) {
			hayamin.appendCodePoint(saori);
			saori = SaoriHayami();
		}
		return hayamin.toString();
	}
	public long saorihayami() {//nextLong
		if (!hayamisaori()) throw new NoSuchElementException();
		long hayami = 0;
		boolean misao = false;
		int saori = SaoriHayami();
		if (saori == '-') {
			misao = true;
			saori = SaoriHayami();
		}
		if (saori < '0' || '9' < saori) {
			throw new NumberFormatException();
		}
		while(true){
			if ('0' <= saori && saori <= '9') {
				hayami *= 10;
				hayami += saori - '0';
			}else if(saori == -1 || !hayami_saori(saori)){
				return misao ? -hayami : hayami;
			}else{
				throw new NumberFormatException();
			}
			saori = SaoriHayami();
		}
	}
	public int saori_hayami() {//nextInt
		long hayami = saorihayami();
		if (hayami < Integer.MIN_VALUE || hayami > Integer.MAX_VALUE) throw new NumberFormatException();
		return (int) hayami;
	}
	public double Hayamin() { //nextDouble
		return Double.parseDouble(nextHayami());
	}
	public void close() {
		try {
			in.close();
		} catch (IOException e) {
		}
    }
    
}

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

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)
#define dump3(x, y, z) (cout << "(" << #x << ", " << #y << ", " << #z << ") = (" << x << ", " << y << ", "<< z << ")" << endl)

typedef long long ll;
typedef pair<int, int> pii;
typedef complex<double> pt;

int n, m;
vector< vector<pt> > ls;

pt unit(pt p) { return p/abs(p); }
pt rotate(pt p, int i)
{
	double x, y;
	x = p.real()*cos(i*M_PI/2.0) - p.imag()*sin(i*M_PI/2.0);
	y = p.real()*sin(i*M_PI/2.0) + p.imag()*cos(i*M_PI/2.0);
	return pt(x, y);
}

#define EPS 1e-9
#define EQ(x, y) ((x)-EPS <= (y) && (y) <= (x)+EPS)

bool same(vector<pt> l1, vector<pt> l2)
{
	if (l1.size() != l2.size()) return false;

	rep(r, 4) {
		bool f = true;
		rep(i, l1.size()) {
			pt b = rotate(l1[i], r);
			if (!(EQ(b.real(), l2[i].real()) && EQ(b.imag(), l2[i].imag()))) {
				f = false;
				break;
			}
		}
		if (f)
			return true;
	}
	return false;
}

int main(void)
{
	while (cin >> n, n) {
		ls = vector< vector<pt> >();
		rep(i, n+1) {
			cin >> m;

			vector<pii> ps = vector<pii>(m);
			rep(j, m)
				cin >> ps[j].first >> ps[j].second;

			vector<pt> line;
			REP(j, 1, ps.size()) line.push_back(pt(ps[j].first, ps[j].second)-pt(ps[j-1].first, ps[j-1].second));

			ls.push_back(line);
		}

		vector<pt> rls0 = vector<pt>(ls[0]);
		reverse(ALL(rls0));
		REP(i, 1, ls.size())
			if (same(ls[0], ls[i]) || same(rls0, ls[i]))
				cout << i << endl;
		cout << "+++++" << endl;
	}
	return 0;
}

Measured memory_bytes: 1220
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

long long int N, M, K, H, W, L, R;
//int N, M, K, H, W, L, R

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

	cin >> N >> M;
	vector<int>v(N + 1);
	for (int i = 1; i <= N; i++)cin >> v[i];
	vector<int>r(N + 1);
	vector<vector<int>>edge(N + 1);
	for (int i = 0; i < M; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
	}
	for (int i = 1; i <= N; i++) {
		r[i] = max(r[i - 1], i + 1);
		for (auto j : edge[i])r[i] = max(r[i], j + 1);
	}
	vector<long long int>dp(N + 2);
	for (int i = 1; i <= N; i++) {
		dp[i] = max(dp[i], dp[i - 1]);
		dp[r[i]] = max(dp[r[i]], dp[i] + v[i]);
	}
	cout << dp.back() << endl;
}


Measured memory_bytes: 14224
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<long double,long double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<62;
const double pi=acos(-1);
const long double eps=1e-7;
const ll mod=1e6+3;
const int dx[8]={0,1,0,-1,-1,-1,1,1},dy[8]={1,0,-1,0,-1,1,-1,1};

int h,w;
vvi a;

int main(){
	cin>>h>>w;
	a=vvi(h,vi(w));
	for(int i=0;i<h;i++) for(int j=0;j<w;j++){
		char c;
		cin>>c;
		if(c=='#'){
			a[i][j]-=inf;
			for(int k=0;k<8;k++){
				int x=i+dx[k],y=j+dy[k];
				if(x>=0&&x<h&&y>=0&&y<w) a[x][y]++;
			}
		}
	}
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(a[i][j]>=0) cout<<a[i][j];
			else cout<<'#';
		}
		cout<<endl;
	}
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        if(a*b%2==0){
            System.out.print("Even");
        }else{
            System.out.print("Odd");
        }
    }         
}


Measured memory_bytes: 35604
#include <iostream>
#include <map>
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
map<int,int>vis;
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n,x,temp;
    cin>>x>>n;
    For(i,1,n)cin>>temp,vis[temp]=1;
    int ans=0,i=x,j=x;
    while(1)
    {
        if(vis[i])i--;
        else
        {
            ans=i;
            break;
        }
        if(vis[j])j++;
        else
        {
            ans=j;
            break;
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

//mapの使い方
#include <map>

ll n,x,y;


vi tp(224);
vi ama(224);
/*

void ruiseki(vi &ina,vi &vl,vi &vr){
  for(ll i=0;i<224;i++){
    tp[i]=ina[i]*ama[(i+offset)%224]%2019;
  }
  vl[0]=tp[0];
  for(ll i=1;i<224;i++){
    vl[i]=(vl[i-1]+tp[i])%2019;
  }
  vr[223]=tp[223];
  for(ll i=222;i>=0;i--){
    vr[i]=(vr[i+1]+tp[i])%2019;
  }

}
*/
ll offset;

int main(){
  ll ans=0;
  string s;
  cin>>s;
  n=s.length();
  vi ama(224);
  ama[0]=1;
  for(ll i=1;i<224;i++){
    ama[i]=ama[i-1]*10%2019;
  }
  vi si(n);
  for(ll i=0;i<n;i++){
    si[n-1-i]=s[i]-48;
  }
  
    /*
    for (auto it : nums) {
        long long num = it.second; // it.first が it.second 個ある
        res += num * (num - 1) / 2;
    }
    */
  vi nums2(2019);

  for(ll k=0;k<224;k++){

      //map<long long, long long> nums;
      vi nums(2019);
      ll gk=0;
      nums[0]=1;
      for(ll i=0;i+k<n;i++){
        gk+=ama[i%224]*si[i+k]%2019;
        gk%=2019;
        //何個あるか
        ans+=nums[(2019-gk)%2019];
        /*
        for (auto it : nums) {
            // it.first が it.second 個ある
            if ((it.first+gk)%2019==0)ans+=it.second;
        }
        */
        if (i%224==223){
          //初期化
          //map<long long, long long> nums2;
          for(ll j=0;j<2019;j++){
            nums2[(j+gk)%2019]=nums[j];
          }
          nums2[0]++;
          for(ll j=0;j<2019;j++){
            nums[j]=nums2[j];
          }
          gk=0;
        }
      }
  }

  //offset=n%224;//これを224回やる



  cout<<ans<<endl;


  return 0;
}

Measured memory_bytes: 5192
#include<stdio.h>
#include<math.h>
int main()
{
          double x1,x2,y1,y2,dis1,dis2,Dis;
          double dis;
          scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

          dis1=pow((x1-x2),2);
          dis2=pow((y1-y2),2);
          Dis=sqrt(dis1+dis2);
          printf("%.8lf",Dis);
          return 0;

}



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

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
		//		new Main().solveE();
		//		new Main().solveF();
	}

	private void solveA() {
		Scanner scanner = null;
		int numN = 0;
		int numA = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();
			numA = scanner.nextInt();

			int res = numN % 500;

			System.out.println(res <= numA ? "Yes" : "No");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int numN = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			int[] wk = new int[numN];
			for (int i = 0; i < wk.length; i++) {
				wk[i] = scanner.nextInt();
			}

			Arrays.sort(wk);

			int alice = 0;
			int bob = 0;
			int cnt = 0;
			for (int i = wk.length - 1; i >= 0; i--) {
				if (cnt % 2 == 0) {
					alice += wk[i];
				} else {
					bob += wk[i];
				}
				cnt++;
			}

			System.out.println(alice - bob);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveC() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveE() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveF() {
		Scanner scanner = null;
		int numN = 0;
		int numK = 0;
		int numS = 0;

		try {
			scanner = new Scanner(System.in);
			numN = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define X first
#define Y second

using namespace std;

//FILE *fi=freopen("1.txt","r",stdin);

typedef pair<int,int> pii;

int n,m,a[1001][1001],d[1001][1001],hi[]={0,0,1,-1},hj[]={1,-1,0,0};
pii st,en;

void nhap()
{
    scanf("%d %d",&n,&m);
    scanf("%d %d %d %d",&st.X,&st.Y,&en.X,&en.Y);
    for (int i=1;i<=n;++i)
    {
        for (int j=1;j<=m;++j)
        {
            char c;
            cin>>c;
            a[i][j]=(c=='.');
        }
    }
}

void process()
{
    for (int i=1;i<=n;++i)
        for (int j=1;j<=m;++j)
            d[i][j]=INT_MAX;
    deque<pair<pii,int> > h;
    h.push_back({st,0});
    d[st.X][st.Y]=0;
    while (!h.empty())
    {
        pii u=h.front().X;
        int du=h.front().Y;
        h.pop_front();
        for (int i=0;i<4;++i)
        {
            int x=u.X+hi[i],y=u.Y+hj[i];
            if (x<=n && x>0 && y<=m && y>0 && a[x][y] && d[x][y]>du)
            {
                d[x][y]=du;
                h.push_front({{x,y},d[x][y]});
            }
        }
        for (int i=-2;i<=2;++i)
        {
            int x=u.X+i;
            if (x<=0 || x>n)
                continue;
            for (int j=-2;j<=2;++j)
            {
                int y=u.Y+j;
                if (y>0 && y<=m && a[x][y] && d[x][y]>du+1)
                {
                    d[x][y]=du+1;
                    h.push_back({{x,y},d[x][y]});
                }
            }
        }
    }
    if (d[en.X][en.Y]==INT_MAX)
        cout<<-1;
    else cout<<d[en.X][en.Y];
}

int main()
{
    nhap();
    process();
    return 0;
}


Measured memory_bytes: 11548
N,K=map(int, input().split())
*X,=map(int, input().split())

P=[]
N=[]
Z=0
for x in X:
    if x < 0: N.append(-x)
    elif x > 0: P.append(x)
    else: Z+=1

P.sort()
N.sort()
Pc=len(P)
Nc=len(N)

L=[]
for x in N:
    L.append(x)
R=[]
for x in P:
    R.append(x)

if Z>=K:
    print(0)
    exit()
K-=Z
ans=10**9
count=0
for x in P:
    count+=1
    if count==K:
        ans = min(ans, x)
        break
    if Nc+count>=K:
        ans = min(ans, 2*x+L[K-count-1])
count=0
for x in N:
    count+=1
    if count==K:
        ans = min(ans, x)
        break
    if Pc+count>=K:
        ans = min(ans, 2*x+R[K-count-1])
print(ans)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef complex<double> P;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define MOD (ll)(1e4+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

int main(){
  vi dp(8,0);
  dp[1] = 1;
  int n;
  cin>>n;
  string s;
  cin>>s;
  int bef = 0;
  REP(i,n){
    int t = 0;
    if(s[i]=='J')t = 0;
    if(s[i]=='O')t = 1;
    if(s[i]=='I')t = 2;
    vi nx(8,0);
    REP(yes,8)REP(tod,8){
      if(yes>>bef&1==1 && __builtin_popcount(yes&tod)>=1 && tod>>t&1==1 )nx[tod] = (nx[tod]+dp[yes])%MOD;
    }
    bef = t;
    dp = nx;
  }
  int res = 0;
  REP(i,8)res += dp[i];
  res %= MOD;
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1228
package main

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

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

var sc = bufio.NewScanner(os.Stdin)

func main() {
	// Code for C - Prison
	var N, M int
	fmt.Scanf("%d %d", &N, &M)

	sc.Split(bufio.ScanWords)

	var L, R int
	var l int = 0
	var r int = 100000

	var flag int
	for i := 0; i < M; i++ {
		L = nextInt()
		R = nextInt()
		if r < L || R < l {
			flag = 1
		}
		if l < L {
			l = L
		}
		if R < r {
			r = R
		}
	}

	if flag == 0 && r-l+1 > 0 {
		fmt.Println(r - l + 1)
	} else {
		fmt.Println("0")
	}
}


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

int main()
{
    int n, k, x[100];
    int i, ans = 0;
    
    cin >> n >> k;
    
    for(i = 0; i < n; i++) {
        cin >> x[i];
        
        if(x[i] <= (k - x[i])) {
            ans = ans + x[i] * 2;
        } else {
            ans = ans + (k - x[i]) * 2;
        }
    }
    
    cout << ans << "\n";
    
    return 0;
}

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

using ll = long long;

ll n, d, a;
vector< pair<ll, ll> > monsters;

ll teto(ll num, ll div) { return 1 + (num - 1) / div; }

int main() {
	ios::sync_with_stdio(false);

	cin >> n >> d >> a;
	for(ll i = 0; i < n; ++i) {
		ll x, h; cin >> x >> h;
		monsters.emplace_back(x,h);
	}
	sort(monsters.begin(), monsters.end());

	ll ans = 0;
	queue< pair<ll, ll> > q;
	long long total = 0;

	for(ll i = 0; i < n; i++) {
		while(!q.empty() and monsters[i].first - q.front().first > d) {
			total -= q.front().second * a;
			q.pop();
		}
		monsters[i].second -= total;
		if(monsters[i].second <= 0) continue;

		ll coord = monsters[i].first + d;
		ll qnt = teto(monsters[i].second, a);
		ans += qnt;
		q.emplace(coord, qnt);
		total += a * qnt;
	}


	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
#define ALL(A) (A).begin(),(A).end()
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)

const ll mod = 1e9+7;
const ll INF = -1*((1LL<<63)+1);
const int inf = -1*((1<<31)+1);

using namespace std;
int N;
vector<vector<ll>> g,cost;
vector<ll> dist;
ll func(int v,int to){
   ll ret = 0;

   return ret;
}

void djkstra(int K){
   for(auto &x:dist)x = 1e18;
   dist[K] = 0;
   priority_queue<pair<ll,int>, vector<pair<ll,int>>, greater<pair<ll,int>>> q;
   q.push({0,K});
   while(!q.empty()){
      pair<ll,int> now = q.top();q.pop();
      int nowv = now.second;
      ll nowcost = now.first;
      // 現地点からいける場所をqueueに入れていく？
      for(int i=0;i<g[nowv].size();i++){
         int next = g[nowv][i];
         if(dist[next] > dist[nowv] + cost[nowv][i]){
            dist[next] = dist[nowv] + cost[nowv][i];
            q.push({dist[next],next});
         }
      }
   }
}
int main(void){
   cin.tie(0);
   ios::sync_with_stdio(false);
   cout<<fixed<<setprecision(20);
   cin >> N;
   g.resize(N);
   cost.resize(N);
   dist.resize(N);
   rep(i,N-1){
      int a,b,c;
      cin >> a >> b >> c;
      a--;b--;
      g[a].push_back(b);
      cost[a].push_back(c);
      g[b].push_back(a);
      cost[b].push_back(c);
   }
   int Q,K;
   cin >> Q >> K;
   K--;
   djkstra(K);
   rep(i,Q){
      int x,y;
      cin >> x >> y;
      x--;y--;
      ll res = 0;
      cout << dist[x] + dist[y] << endl;
   }
}

Measured memory_bytes: 15720
#include <bits/stdc++.h>
using namespace std;
#define fo(x, n) for(int i = x; i <= n; i++)
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector <int> vi;
const int MOD = 1e9 + 7;
void solve(){
    int a, b;
    cin >> a >> b;
    cout << max({a + a - 1, b + b - 1, a + b});
}

int main(){
    ios::sync_with_stdio(false); cin.tie(0);
	int T = 1;
    //cin >> T;
    fo(1, T){
        solve();
    }
}




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

using namespace std;
typedef long long llint;
#define inf 1e18

llint n,m;
llint a,b;
llint island[200005]={0};
void solve(){
	cin >> n >> m;
	bool f=false;
	for(int i=1;i<=m;i++){
		cin >> a >> b;
		if(a==1){
			island[b]++;
			if(island[b]==2){
				cout << "POSSIBLE" << endl;
				f=true;
				break;
			}
		}
		else if(b == n){
      island[a]++;
      if(island[a] == 2){
        cout << "POSSIBLE" << endl;
				f=true;
        break;
      }
    }
	}
	if(!f){
		cout << "IMPOSSIBLE" << endl;
	}

}

int main(int argc, char *argv[]) {
  solve();
  return 0;
}


Measured memory_bytes: 1792
#include "stdio.h"

int main(){
    int a,b;
    //int x;
    scanf("%d %d",&a,&b);

    // if((a+b)%2==0){
    //     printf("%d\n",(a+b)/2);
    // }else{
    //     printf("%d\n",(a+b+1)/2);
    // }

    printf("%d\n",(a+b+1)/2);
    return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int A = sc.nextInt();
		

		if (A > 999) {

			System.out.println("ABD");
			
		}else {

			System.out.println("ABC");

		}
	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

int main(){
    int n, W;
    cin >> n >> W;
    vl w(n), v(n);
    rep(i, n) cin >> w[i] >> v[i];
    vl cur(W+1);
    rep(i, n) {
        auto nxt = cur;
        for(int j = 0; j + w[i] <= W; ++j) nxt[j + w[i]] = max(nxt[j + w[i]], cur[j] + v[i]);
        swap(nxt, cur);
    }
    cout << cur[W] << endl;
    return 0;
}

Measured memory_bytes: 1804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+5,mod=1e9+7;
ll n,a[N],p[N],f[N],p1,p2;
ll res[N];
ll powmod(ll x,ll n){ll s=1;for(;n;n>>=1,x=(x*x)%mod)	if(n&1)	s=(s*x)%mod;return s;}
ll C(int n,int m)
{
	if(n<m)	return 0;
	ll a=f[n],b=(f[n-m]*f[m])%mod;
	return (a*powmod(b,mod-2))%mod;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>n;
	for(int i=1;i<=n+1;i++){
		cin>>a[i];
		if(!p[a[i]])
			p[a[i]]=i;
		else
		{
			p1=p[a[i]];
			p2=i;
		}
	}
	f[0]=1;
	for(ll i=1;i<N;i++)	f[i]=(f[i-1]*i)%mod;
	for(int k=1;k<=n+1;k++)
	{
		ll foo=C(p1-1+n+1-p2,k-1); 
		res[k]=(C(n+1,k)-foo+mod)%mod;
		cout<<res[k]<<'\n';
	}
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#define myfor(i,N) for(i=0;i<N;i++)
#define myforFL(i,f,l) for(i=f;i<l;i++)
#define myforInv(i,N) for(i=N;i>=0;i--)
#define myforFLInv(i,f,l) for(i=f;i>l;i--)

using namespace std;

int main(){
	int N,K,d,a,i,j,human[101]={},ans=0;
	cin >> N >> K;
	myfor(i,K){
		cin >> d;
		myfor(j,d){
			cin >> a;
			human[a] = 1;
		}
	}
	myforFL(i,1,N+1){
		if(human[i] == 0){
			ans++;
		}
	}
	cout << ans <<endl;
	return 0;
}

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

int main() {
	int H, W;
	cin >> H >> W;
	
  	vector<vector<char>> a(H, vector<char>(W));

   for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        cin >> a.at(i).at(j);
      }
    }
  
  for (int i = 0; i < W+3; i++){
    if(i < W+2) cout << '#';
    if(i == W+2) cout << endl;
  }
  
  for (int i = 0; i < H; i++) {
    cout << '#';
      for (int j = 0; j < W; j++) {
        cout << a.at(i).at(j);
      }
    cout << '#' << endl;
    }
  
  for (int i = 0; i < W+3; i++){
    if(i < W+2) cout << '#';
    if(i == W+2) cout << endl;
  }
  
}

Measured memory_bytes: 256
#include <cstdio>

using namespace std;
typedef long long int LL;
const int Max_N(100050);

namespace io
{
	const int SIZE = (1 << 21) + 1;
	char ibuf[SIZE], *iS, *iT, obuf[SIZE], *oS = obuf, *oT = oS + SIZE - 1, c, qu[55]; int f, qr;
	#define gc() (iS == iT ? (iT = (iS = ibuf) + fread (ibuf, 1, SIZE, stdin), (iS == iT ? EOF : *iS ++)) : *iS ++)
	inline void flush (){fwrite (obuf, 1, oS - obuf, stdout);oS = obuf;}
	inline void putc (char x){*oS ++ = x;if (oS == oT) flush ();}
	template <class I>
	inline void gi (I &x) {for (f = 1, c = gc(); c < '0' || c > '9'; c = gc()) if (c == '-') f = -1;
		for (x = 0; c <= '9' && c >= '0'; c = gc()) x = x * 10 + (c & 15); x *= f;}
	template <class I>
	inline void print (I x){
		if (!x) putc ('0'); if (x < 0) putc ('-'), x = -x;while(x) qu[++ qr] = x % 10 + '0',  x /= 10;while (qr) putc (qu[qr--]);}
	struct Flusher_ {~Flusher_(){flush();}}io_flusher_;
}
using io::gi;
using io::putc;
using io::print;

int N, S, X[Max_N], V[Max_N];
LL P[Max_N], Ans;

void solve(int l, int r)
{
	if (l == r)
	{
		V[++V[0]] = X[l], V[++V[0]] = S;
		return;
	}
	if (S < X[l])
	{
		V[++V[0]] = X[r], solve(l, r - 1);
		return;
	}
	if (S > X[r])
	{
		V[++V[0]] = X[l], solve(l + 1, r);
		return;
	}
	if (P[l] >= P[r])
		V[++V[0]] = X[r], P[l] += P[r], solve(l, r - 1);
	else
		V[++V[0]] = X[l], P[r] += P[l], solve(l + 1, r);
}

constexpr int Abs(int x)
{
	return x >= 0 ? x : -x;
}

int main()
{
	gi(N), gi(S);
	for (int i = 1;i <= N;++i)
		gi(X[i]), gi(P[i]);
	solve(1, N);
	for (int i = V[0] - 1;i >= 1;--i)
		Ans += Abs(V[i + 1] - V[i]);
	print(Ans);
	return 0;
}

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

int main() {
long n,y;
cin >> n >>y;
long a=-1,b=-1,c=-1;
for(int i=0;i<n+1;i++){
    for(int j=0;j<n+1-i;j++){
        int z=n-i-j;
        if((1000*i+5000*j+10000*z)==y){
        a=i;
        b=j;
        c=z;}

    }
}
cout << c << " " << b << " " << a <<endl;}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int r,d,x,i,res;
    scanf("%d%d%d",&r,&d,&x);
    res=x;
    for(i=1;i<=10;i++)
    {
        res=(r*res)-d;
        printf("%d\n",res);
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main()
{
    int num;
    cin >> num;
    
    vector<int> vec(num);
    for(int i=0; i<num; ++i) cin >> vec.at(i);
    // bool flag = true;
    int counter = 0;  // 何回割れるかをカウント
    
    while(true){
        bool odd_exist=false;
        // 与えられた数の中に奇数があるかをチェック
        for(int i=0; i<num; ++i){
            if(vec.at(i)%2==1) odd_exist=true;
        }
        
        if(odd_exist) break;  // 奇数があったらループを抜ける
        
        for(int i=0; i<num; ++i){
            vec.at(i) /= 2;
        }
        ++counter;
    }
    
    cout << counter << endl;
}

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

using namespace std;

const int MAX_N = 1e5 + 10;

int n;
long long a[MAX_N], pref[MAX_N];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a, a + n);
    for (int i = 0; i < n; i++) {
        pref[i + 1] = pref[i] + a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int pos = i;
        while (1) {
            auto itr = upper_bound(a, a + n, 2 * pref[pos + 1]);
            itr--;
            int id = itr - a;
            if (id == pos) {
                break;
            }
            pos = id;
        }
        if (pos == n - 1) {
            ans++;
        }
    }
    cout << ans << "\n";
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define retunr return
#define pb push_back
#define mp make_pair
#define null NULL
#define sc(x) scanf("%d", &x)
#define sc64(x) scanf("%I64d", &x)
#define pr(x) printf("%d", (x))
#define sp putchar(' ')
#define ln putchar('\n')
#define pr64(x) printf("%I64d", (x))
#define rep(i,l,r) for (int i = l, lim = r;i <= lim; ++i)
#define repr(i,l,r) for (int i = r, lim = l;i >= lim; --i)
#define fi first
#define se second
#define SET(__set, val) memset(__set, val, sizeof __set)
#define prf(x) printf("%.20f", x)
typedef unsigned int uint;
typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define N 100010
#define M 1024
#define MOD 1000000007
void _add(int &a, int b){a = (a+b)%MOD;}
void _sub(int &a, int b){a = (a+MOD-b)%MOD;}
void _mul(int &a, int b){a = (ll)a*b%MOD;}
void _max(int &a, int b){a = max(a,b);}
void _min(int &a, int b){a = min(a,b);}
ll gcd(ll a, ll b){if(!b)return a;return gcd(b,a%b);}
ll pw(ll a, ll b){ll res(1);while(b){if(b&1)res=res*a%MOD;a=a*a%MOD;b>>=1;}return res;}
ll pwM(ll a, ll b, ll mod){ll res(1);while(b){if(b&1)res=res*a%mod;a=a*a%mod;b>>=1;}return res;}

const int infi = 2147483647;
const ll infl = 9223372036854775807ll;
const db PI = 3.14159265358979323846;

/*
struct E{
	int v, w, n;
}G[N];
int cnt, point[N];
void adde(int u, int v, int w = 0){
	G[++cnt]=(E){v,w,point[u]},point[u]=cnt;
	G[++cnt]=(E){u,w,point[v]},point[v]=cnt;
}
void Ginit(){
	cnt = 0;
	SET(point,0);
}
*/
/*
struct hh{
	int a, b;
	bool operator < (const hh &x) const{
		if(a==x.a)return b<x.b;
		return a<x.a;
	}
}a[N];
*/
int n, m, k,q,a[N];
int main(){
//	freopen("1", "r", stdin);
	int ans = infi;
	sc(a[1]),sc(a[2]),sc(a[3]);
	rep(i,1,3)rep(j,1,3)rep(k,1,3)if(i!=j&&i!=k&&j!=k)ans=min(ans,0+abs(a[i]-a[j])+abs(a[j]-a[k]));
	pr(ans);
/*
	int Case;
	sc(Case);
	rep(ca, 1, Case){
	    printf("Case #%d: ", ca);
	}
*/
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

/*
s

200000
 */
char s[200001];

int main(){
  cin>>s;
  int n = strlen(s);
  int l,r;
  REP(i,n){
    if(s[i]=='A'){
      l = i;
      break;
    }
  }
  for(int i=n-1; i>=0; i--){
    if(s[i]=='Z'){
      r=i;
      break;
    }
  }
  LOG("l=%d, r=%d\n",l,r);
  cout << max(0, r-l+1) << endl;

  return 0;
}


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


int main(){
	int N, Y;
	cin >> N >> Y;
	for(int i = 0; i <= N; i++){
		for(int j = 0; j <= N-i; j++){
			int k = N - i - j;
			if(Y == i*10000 + j*5000 + k*1000){
				cout << i << " " << j << " " << k << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;

}














Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
#define endl "\n"
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    int n, val;
    cin >> n;
    map<int, int> cnt;
    for(int i = 0; i < n; i++) {
        cin >> val;
        cnt[val] += 1;
    }
    int mx = cnt.rbegin()->first;
    vector<int> dp(mx+1, false);
    int ans = 0;
    for(auto& [fac, freq]: cnt) {
        if (dp[fac] == false) {
            if (freq == 1) ans += 1;
            for(ll i = fac*2; i <= mx; i += fac) {
                dp[i] = true;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

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

#define SZ(x) ((int)(x).size())
#define all(x) begin(x),end(x)

#define dump(x) cerr<<#x<<" = "<<(x)<<endl
#define debug(x) cerr<<#x<<" = "<<(x)<<" (L"<<__LINE__<<")"<<endl;

template<class T>
ostream &operator<<(ostream &os, const vector <T> &v) {
    os << "[";
    REP(i, SZ(v)) {
        if (i) os << ", ";
        os << v[i];
    }
    return os << "]";
}

template<class T, class U>
ostream &operator<<(ostream &os, const pair <T, U> &p) {
    return os << "(" << p.first << " " << p.second << ")";
}

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

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const int INF = INT_MAX / 2;
const ll LINF = LLONG_MAX / 2;
const ld EPS = 1e-9;


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

    for (;;) {
        int T, P, R; cin >> T >> P >> R;
        if (T == 0) break;

        vvi penalty(T, vi(P));
        vi totalPenalty(T), totalAC(T);
        REP(i, R) {
            int tid, pid, time; string msg;
            cin >> tid >> pid >> time >> msg;
            --tid, --pid;

            if (msg == "WRONG") {
                ++penalty[tid][pid];
            } else {
                totalPenalty[tid] += 1200 * penalty[tid][pid] + time;
                ++totalAC[tid];
            }
        }

        vi ord(T);
        iota(all(ord), 0);
        sort(all(ord), [&](int i,int j){
            if (totalAC[i] != totalAC[j]) return totalAC[i] > totalAC[j];
            if (totalPenalty[i] != totalPenalty[j]) return totalPenalty[i] < totalPenalty[j];
            return i < j;
        });

        REP(i, T) {
            cout << ord[i]+1 << " " << totalAC[ord[i]] << " " << totalPenalty[ord[i]] << endl;
        }
    }

    return 0;
}



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

int n,a[105];
double ans;

int main()
{
	cin>>n;
	for(int i=1;i<=n;cin>>a[i++]);
	for(int i=1;i<=n;i++)
		ans += 1.0/a[i];
	printf("%.7lf\n",1.0/ans);
	
	return 0;
}

Measured memory_bytes: 256
/**
*    author:  y_takano
*    created: 23.06.2020 11:57:42
**/

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)

using namespace std;

struct _dice
{
    int dt, ds, de, dw, dn, du;
};

void dice(_dice &dice, char c)
{
    int tmp;

    switch (c)
    {
    case 'E':
        tmp = dice.dt;
        dice.dt = dice.dw;
        dice.dw = dice.du;
        dice.du = dice.de;
        dice.de = tmp;
        break;
    case 'N':
        tmp = dice.dt;
        dice.dt = dice.ds;
        dice.ds = dice.du;
        dice.du = dice.dn;
        dice.dn = tmp;
        break;
    case 'S':
        tmp = dice.dt;
        dice.dt = dice.dn;
        dice.dn = dice.du;
        dice.du = dice.ds;
        dice.ds = tmp;
        break;
    case 'W':
        tmp = dice.dt;
        dice.dt = dice.de;
        dice.de = dice.du;
        dice.du = dice.dw;
        dice.dw = tmp;
        break;
    }
}

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

    _dice sdice = {1, 2, 3, 4, 5, 6};

    int d[6];
    string s;

    REP(i, 6)
    {
        cin >> d[i];
    }

    cin >> s;

    REP(i, s.size())
    {
        dice(sdice, s[i]);
    }

    cout << d[sdice.dt - 1] << '\n';

    return 0;
}


Measured memory_bytes: 3216
N = int(input())
T,A = map(int,input().split())
H = list(map(int,input().split()))

H_temp = [abs(A-(T-0.006*i)) for i in H]

temp = 999999
best_spot = None

for i in range(len(H_temp)):
    if H_temp[i] < temp:
        temp = H_temp[i]
        best_spot = i+1

print(best_spot)

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll calc[1001001];

string s;

int main(void){
	int n,i,j,k=0;
	bool flag = false;
	cin >> n;
	for(i=0; i<=n; ++i){
		j = i;
		while(j){
			calc[i] += (j%2);
			j /= 2;
		}
	}
	cin >> s;
	for(i=0; i<n; ++i){
		s[i] -= '1';
		if(s[i]==1){
			flag = true;
		}
		k += s[i]*(!(calc[i]+calc[n-1-i]-calc[n-1]));
		k %= 2;
	}
	if(k || flag){
		cout << k << endl;
		return 0;
	}
	k = 0;
	for(i=0; i<n; ++i){
		s[i] /= 2;
		k += s[i]*(!(calc[i]+calc[n-1-i]-calc[n-1]));
		k %= 2;
	}
	cout << (k*2) << endl;
	return 0;
}


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

long long int C[2001][2001];

void before(){
	int p = 1e9 + 7;
	C[0][0]  = C[0][1] = 1;
	for(int i=1;i<2001;i++){
		C[i][0] = C[i][i] = 1;
		for(int j=1;j<i;++j){
			C[i][j] = (C[i-1][j] + C[i-1][j-1])%p;
		}
	}
/*
	for(int i=1;i<10;++i){
		for(int j=1;j<10;++j){
			cout << C[i][j] << " ";
		}cout <<endl;
	}*/
}

int main(){
	int n,k;
	cin >> n >> k;
	before();
	int p = 1e9 + 7;
	for(int i=1;i<=k;i++){
		long long int res  = (C[n-k+1][i] * C[k-1][i-1] );
		res = res %  p;
		cout << res <<endl;
	}
		
	
	return 0;
}


Measured memory_bytes: 30080
//In The Name of Beauty
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef map<ll,ll> mllll;
#define IB std::ios::sync_with_stdio(0);
#define pb(x) push_back(x);
#define mp(x,y) make_pair(x,y)
#define pll pair<ll,ll>
#define F first
#define S second
#define trvall(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define MAXN (ll)1e5 + 8
#define INF  (ll)1e12 + 8
ll const delta = 1000000007;

ll a[1000];

int main()
{
    IB;
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll i = 0;i < n;i++)
    {
        cin >> a[i];
    }
    ll temp = 0 , i = 0;
    while(i < n)
    {
        temp = 0;
        while(a[i] == a[i + 1] && i < n)
        {
            temp++;
            i++;
        }
        temp++;
        ans += (temp / 2);
        i++;
    }
    cout << ans;
    return 0;
}
//Written by M_H_H_7


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

int main()
{
  int n;
  cin>>n;
  vector<int> v(n);
  for(int &i:v) cin>>i;
  sort(v.begin(),v.end());
  
  long long md = 1e18;
  
  for(int i=v[0];i<=v.back();i++)
  {
    long long sum=0;
    for(int j:v)
    {
      sum += (j-i)*(j-i);
      if(sum>=md) break;
    }
    md = min(md,sum);
  }
  cout<<md;
  
  return 0;
}

Measured memory_bytes: 256
n = int(input())
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])
    if arr==[]:
        arr.append([n, 1])
    return arr
d = {}
for i in range(2, n+1):
  a = factorization(i)
  for i in a:
    if i[0] not in d.keys():
      d[i[0]] = i[1]
    else:
      d[i[0]] += i[1]
ans = 1
for value in d.values():
  ans *= value+1
print(ans%(10**9+7))

Measured memory_bytes: 3188
// -*- coding:utf-8-unix -*-


use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a
use itertools::Itertools;

fn main() {
/*     input! {
        n: usize,
        mut plan: [(i32, i32, i32); n],  // Vec<(i32, i32, i32)>
    }
 */
    input! {
        n: usize,
        m: i32,
        q: i32,
        mut abcd: [[i32; 4]; q],
    }

    let mut result = 0;
    for aa in (1..m + 1).combinations_with_replacement(n){
        let mut total = 0i64;
        for x in abcd.iter(){
            let b = x[1] - 1;
            let a = x[0] - 1;
            if aa[b as usize ] - aa[a as usize] == x[2]  {
                total += x[3] as i64;
            }
        }
        if total > result {
            result = total;
        }
    }
    println!("{}",result);
}


Measured memory_bytes: 2168
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

bool bfs(int s, vector<vector<int>> &edges, vector<int> &depth){
    queue<pair<int,int>> que;
    que.push(make_pair(s,1));

    while((int)que.size()){
        int x=que.front().first;
        int d=que.front().second;
        que.pop();

        if(depth[x]==-1){
            depth[x]=d;
        }else{
            if(depth[x]%2==d%2){
                continue;
            }else{
                return false;
            }
        }

        for(auto nx:edges[x]){
            que.push(make_pair(nx,d+1));
        }
    }

    return true;
}

int main(){
    int N;
    cin >> N;
    vector<vector<int>> edges(N,vector<int>(0));
    vector<int> depth(N,-1);

    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            char c;
            cin >> c;
            if(c=='1'){
                edges[i].push_back(j);
                edges[j].push_back(i);
            }
        }
    }

    if(bfs(0,edges,depth)==false){
        cout << -1 << endl;
        return 0;
    }

    int ans=0;
    for(int i=0; i<N; i++){
        depth=vector<int>(N,-1);
        bfs(i,edges,depth);
        //cout << endl;
        for(auto d:depth){
            //cout << d << endl;
            ans=max(ans,d);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


typedef long long ll;
typedef pair<int,int> pii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	int N,M;

	cin >> N >> M;

	char in[N+1][M+1];

	for(int i = 0; i < N; i++)
		for(int j = 0; j < M; j++)
			cin >> in[i+1][j+1];

	char out[2*N + 1][M + 1];

	for(int i = 1; i <= 2*N; i++){
		for(int j = 1; j <= M; j++) out[i][j] = in[(i + 1)/2][j];
	}

	for(int i = 1; i <= 2*N; i++)
		for(int j = 1; j <= M; j++)
			cout << out[i][j] << (j == M ? "\n" : "");

	return 0;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long mod = 1e9 + 7;

int n;
long long arr[N];
long long power(long long x, long long y, long long p){
    long long res = 1;
    x = x % p;
    if (x == 0) return 0;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void solve(){
    long long sum = 0, sum1 = 0;
    int i = 0;
    for(i = 0; i < n; i++){
        sum += arr[i];
        sum %= mod;
        sum1 += (arr[i] * arr[i]) % mod;
        sum1 %= mod;
    }
    sum *= sum;
    sum %= mod;
    sum -= sum1;
    sum += mod;
    sum %= mod;
    sum *= power(2, mod - 2, mod);
    sum %= mod;
    cout << sum;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    int i = 0;
    for(i = 0; i < n; i++)
        cin >> arr[i];
    solve();
    return 0;
}

Measured memory_bytes: 5196
fn input() -> String {
	let mut s = String::new();
	std::io::stdin().read_line(&mut s).unwrap();
	s.trim().to_owned()
}

fn z_algorithm(s: &str, f: bool) -> (Vec<usize>, usize) {
	let     b = s.as_bytes();
	let     n = b.len();
	let mut v = Vec::with_capacity(n);
	let mut l = 0;
	let mut r = 0;
	let mut m = 0;
	
	v.resize(n, 0);
	
	for i in 1..n {
		if r < i {
			l = i;
			r = i;
			
			while r < n &&  b[r - l] == b[r] {
				r += 1;
			} 
			
			v[i] = r - l;
			r   -= 1;
		} else {
			let j = i - l;
			
			if v[j] < r - i + 1 {
				v[i] = v[j];
			} else {
				l = i;
				
				while r < n && b[r - l] == b[r] {
					r += 1;
				}
				
				v[i] = r - l;
				r   -= 1;
			}
		}
		
		if f == true || v[i] <= i {
			m = std::cmp::max(m, v[i]);
		}
	}
	
	v[0] = s.len();
	
	(v, m)
}

fn main() {
	input();
	
	let     s = input();
	let     n = s.len();
	let mut c = 0;
	
	for i in 0..n {
		c = std::cmp::max(c, z_algorithm(&s[i..n], false).1);
	}
	
	println!("{}", c);
}


Measured memory_bytes: 4352