akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return b/gcd(a,b)*b;}

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

  string s;
  cin >> s;
  if (s == "SUN") {
    cout << 7 << endl;
  } else if (s == "MON") {
    cout << 6 << endl;
  } else if (s == "TUE") {
    cout << 5 << endl;
  } else if (s == "WED") {
    cout << 4 << endl;
  } else if (s == "THU") {
    cout << 3 << endl;
  } else if (s == "FRI") {
    cout << 2 << endl;
  } else {
    cout << 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

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

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n, m;
    cin >> n >> m;

    vector<int> x(n), y(m);
    rep(i, n) cin >> x[i];
    rep(i, m) cin >> y[i];

    int sumX, sumY;
    sumX = sumY = 0;
    rep(i, n){
        sumX += x[i] * (2 * i - n + 1) % MOD;
        sumX %= MOD;
    }
    rep(i, m){
        sumY += y[i] * (2 * i - m + 1) % MOD;
        sumY %= MOD;
    }
    cout << sumX * sumY % MOD << endl;

    return 0;
}


Measured memory_bytes: 1792
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 998244353


def resolve():
    a, b, c, d = map(int, input().split())
    dp = [[0] * (d + 1) for _ in range(c + 1)]
    dp[a][b] = 1
    for i in range(a, c + 1):
        for j in range(b, d + 1):
            if i == a and j == b:
                continue
            dp[i][j] = dp[i - 1][j] * j + dp[i][j - 1] * i - dp[i - 1][j - 1] * (i - 1) * (j - 1)
            dp[i][j] %= mod

    print(dp[-1][-1] % mod)


if __name__ == '__main__':
    resolve()


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

using namespace std;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);
	
	int a, b;
	char op;

	cin >> a >> op >> b;
	switch(op) {
		case '+':
			cout << a + b;
			break;
		case '-':
			cout << a - b;
			break;
	}
	cout << "\n";

	return 0;
}

Measured memory_bytes: 256
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
using namespace std;
using ll=long long;
#define MOD  1000000007

int main(int argc, char const *argv[]) {
  int n,a,b;
  std::cin >> n;
  if(n==1)std::cout << "Hello World" << '\n';
  
  else{
    std::cin >> a >> b;
    std::cout << a+b << '\n';
  }
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
int main()
{
	int n;
	long long m;
	scanf("%d %lld", &n, &m);
	map<int, long long> a;
	for(int i = 0, j; i < n; ++i)
	{
		long long k;
		scanf("%d %lld", &j, &k);
		if(a.find(j) == a.end())
		{
			a.insert(make_pair(j, k));
		}
		else
		{
			a[j] += k;
		}
	}
	for(auto i : a)
	{
		m -= i.second;
		if(m <= 0)
		{
			printf("%d\n", i.first);
			break;
		}
	}
}


Measured memory_bytes: 4224
def resolve():
    S = int(input())
    # S == 10 ** 9 * i + mod
    i, mod = divmod(S, 10 ** 9)
    # 求めたいのは、10 ** 9 * i - modなるiとmodの組
    # mod == 0のときはそのまま
    if mod == 0:
        print(0, 0, 10 ** 9, mod, 1, i)
    # そうでないときはiをインクリしてmodの項を負にしてしまえばいい
    else:
        print(0, 0, 10 ** 9, 10 ** 9 * (i + 1) - S, 1, i + 1)


resolve()

Measured memory_bytes: 38384
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		HashSet<int>[] E = new HashSet<int>[N];
		for(int i=0;i<N;i++) E[i] = new HashSet<int>();
		for(int i=0;i<M;i++){
			E[A[i]].Add(B[i]);
			E[B[i]].Add(A[i]);
		}
		
		int[] bw = new int[N];
		bw[0] = 0;
		for(int i=1;i<N;i++) bw[i] = -1;
		var Q = new Queue<int>();
		Q.Enqueue(0);
		while(Q.Count > 0){
			var now = Q.Dequeue();
			foreach(var nxt in E[now]){
				if(bw[nxt] == -1){
					bw[nxt] = bw[now] ^ 1;
					Q.Enqueue(nxt);
				}
				if(bw[nxt] == (bw[now] ^ 1)) continue;
				
				long tot = ((long) N * (N-1))/2;
				Console.WriteLine(tot - M);
				return;
			}
		}
		
		long[] cnt = new long[2];
		for(int i=0;i<N;i++){
			cnt[bw[i]]++;
		}
		
		long vv = 0;
		for(int i=0;i<M;i++){
			if(bw[A[i]] != bw[B[i]]) vv++;
		}
		
		long tot0 = cnt[0] * cnt[1];
		Console.WriteLine(tot0 - vv);
		
		
		
	}
	int N,M;
	int[] A,B;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = new int[M];
		B = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			A[i] = d[0] - 1;
			B[i] = d[1] -1;
		}
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 41992
r, c = [int(i) for i in input().split()]

data = []
sum_row = [0] * (c + 1)

for ri in range(r):
    data.append([int(i) for i in input().split()])
    data[ri].append(sum(data[ri]))
    print(" ".join([str(d) for d in data[ri]]))
    for ci in range(c + 1):
        sum_row[ci] += data[ri][ci]

print(" ".join([str(s) for s in sum_row]))

Measured memory_bytes: 7676
import javax.swing.plaf.IconUIResource;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;
public class Main {
    static long dp[]= new long[2006];
    static long mod=(long) (1e9+7);
    static long mod(long x){
        return ((x%mod+mod)%mod);
    }
    static long add(long a,long b){
        return mod(mod(a)+mod(b));
    }

    static long find(int s){
        if (s==0){
            return 1;
        }
        if (s==1||s==2){
            return 0;
        }

        if (dp[s]!=-1)return dp[s];
        long total=0;
        for (int i=3;i<=s;i++){
            if (s-i>=0){
//                total=add(total,find(s-i));
                total=(total+find(s-i))%mod;
            }
        }
        return dp[s]=total;
    }

     public static void main(String[] args) {
//        Scanner sc = new Scanner(System.in);
         FastScanner sc = new FastScanner();
         PrintWriter out = new PrintWriter(System.out);
         int n=sc.nextInt();
         Arrays.fill(dp,-1);
         System.out.println(find(n));

     }






    static void sort(int[] a) {
        ArrayList<Integer> l=new ArrayList<>();
        for (int i:a) l.add(i);
        Collections.sort(l);
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }
    static void sortReverse(long[] a) {
        ArrayList<Long> l=new ArrayList<>();
        for (long i:a) l.add(i);
//        Collections.sort.(l);
        Collections.sort(l,Collections.reverseOrder());
        for (int i=0; i<a.length; i++) a[i]=l.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");
        String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }
        long[] readArrayLong(long n) {
            long[] a=new long[(int)n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }


}

Measured memory_bytes: 34340
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut limit = 599;
    for q in 0.. {
        if n <= limit {
            println!("{}", 8 - q);
            return;
        }
        limit += 200;
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


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

using namespace std;

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

int n;
vector<int> a[101];
string s;

void nhap()
{
    scanf("%d",&n);
    cin>>s;
    for (int i=0;i<n;++i)
        a[s[i]-48].push_back(i+1);
}

void process()
{
    int dem=0;
    for (int i=0;i<=9;++i)
    {
        if (a[i].empty())
            continue;
        for (int j=0;j<=9;++j)
        {
            if (a[j].empty()) continue;
            for (int k=0;k<=9;++k)
            {
                if (a[k].empty())
                    continue;
                auto ii=lower_bound(a[j].begin(),a[j].end(),a[i][0]);
                if (ii==a[j].end())
                    continue;
                if (*ii==a[i][0])
                    ii++;
                if (ii==a[j].end())
                    continue;
                auto jj=lower_bound(a[k].begin(),a[k].end(),*ii);
                if (jj==a[k].end())
                    continue;
                if (*jj==*ii)
                    jj++;
                if (jj==a[k].end())
                    continue;
                dem++;
            }
        }
    }
    cout<<dem;
}

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


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cmath>
#include<string>
#include <iomanip>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<complex>
#include<ctime>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;

int main(void)

{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << ketasitei;

	ll n;
	cin >> n;
	vector<ll> a(n + 1);
	rep(i, n)
	{
		cin >> a[i+1];
	}

	vector<ll> m(n + 1, 0);
	vector<ll> ans;
	ll sum = 0;

	for (ll i = n; i >= 1; i--)
	{
		if (m[i] % 2 == a[i])
		{
			continue;
		}
		else
		{
			ans.push_back(i);
			sum++;
			for (ll j = 1; j * j <= i; j++)
			{
				if (i % j == 0)
				{
					if (j * j == i)
					{
						m[j]++;
					}
					else
					{
						m[j]++;
						m[i / j]++;
					}
				}
			}
		}
	}
	if (ans.size() == 0)
	{
		cout << 0 << endl;
		ret;
	}
	cout << sum << endl;
	reverse(all(ans));
	cout << ans[0];
	for (int i = 1; i < ans.size(); i++)
		cout << " " << ans[i];
	cout << endl;

	return 0;
}

Measured memory_bytes: 5108
#include <stdio.h>
#include <string.h>

int main(void)
{
    char s[11], ans[11] = "";
    int i;
    scanf("%s", s);
    for (i = 0; i < strlen(s); i++)
    {
        if (s[i] == 'B') {
            ans[strlen(ans) - 1] = '\0';
        } else {
            ans[strlen(ans)] = s[i];
        }
    }
    printf("%s\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
vector<int> v;
signed main(){
	int n,a,b,c;
	cin>>n;
	f(i,n){
		int aa;
		cin>>aa;
		v.push_back(aa);
	}
	sort(v.begin(),v.end());
	a=v[0],b=v[min((int)(upper_bound(v.begin(),v.end(),v[0])-v.begin()),n-1)];
	v.erase(v.begin());
	v.erase(min(upper_bound(v.begin(),v.end(),a),n-2+v.begin()));
	if(binary_search(v.begin(),v.end(),a^b)){
		c=a^b;
		v.erase(lower_bound(v.begin(),v.end(),a^b));
	}
	else{
		puts("No");
		return 0;
	}
	f(i,n-3){
		if(i%3==0){
			if(binary_search(v.begin(),v.end(),a))v.erase(lower_bound(v.begin(),v.end(),a));
			else{
				puts("No");
				return 0;
			}
		}
		if(i%3==1){
			if(binary_search(v.begin(),v.end(),b))v.erase(lower_bound(v.begin(),v.end(),b));
			else{
				puts("No");
				return 0;
			}
		}
		if(i%3==2){
			if(binary_search(v.begin(),v.end(),c))v.erase(lower_bound(v.begin(),v.end(),c));
			else{
				puts("No");
				return 0;
			}
		}
	}
	if(n%3&&!(a==b&&a==c&&b==c))puts("No");
	else puts("Yes");
}


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

int main()
{
    int n;
    cin >> n;
    if(n%2==0){
        cout<<(n/2)-1<<endl;
    }else{
        cout<<(n+1)/2-1<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <numeric>
#include <complex>

using namespace std;

typedef long long ll;

#define mp make_pair
#define pb push_back
#define PI 3.1415926535897932384626433832795

#define fill(x, v)  fillchar(x, v, sizeof(x))
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector< pii >   vpii;

#define MAXN 100500

vi g[MAXN];
vi o;
int f[MAXN];
int was[MAXN];
int n, m, x, y;

void dfs(int v) {
    if (was[v]) return;

    was[v] = true;
    for(int w : g[v]) dfs(w);
    o.pb(v);
}

int main() {
    scanf("%i%i", &n, &m);
    for(int i = 0; i < m; ++i) {
        scanf("%i%i", &x, &y);
        g[x].pb(y);
    }

    for(int i = 1; i <= n; ++i) dfs(i);


    for(int i = 0; i < n; ++i) {

        for(int w : g[ o[i] ]) {
            f[o[i]] = max(f[o[i]], f[w] + 1);
        }
        //cout << o[i] << " " << f[ o[i] ] << endl;
    }

    printf("%i\n", *max_element(f + 1, f + n + 1));
    return 0;
}

Measured memory_bytes: 9080
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll  long long
#define mp make_pair
#define fi first
#define se second
#define pii pair<ll,ll>
#define pb push_back
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define what_is(x) cerr << #x << " is " << x << endl;
int main()
{
    string str;
    cin >> str;
    int count = 0;
    for(int i=1;i<str.size();i++)
    {
        if(str[i]!=str[i-1])
        count++;
    }
    cout << count;
}

Measured memory_bytes: 512
/*
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define FRO freopen("in.txt","r",stdin);

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);


      int n,i,j



	return 0;
}

cout<<"Case "<<++tt<<": No"<<endl;

#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745
*/

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define FRO freopen("in.txt","r",stdin);
class day{
public:
      int a[3];
      day(){}
      day(int aa,int bb,int cc){a[0]=aa; a[1]=bb;a[2]=cc;}
};

vector<day>vec(100005);
int dp[100005][3];

int fun(int n,int today_job)
{
      if(dp[n][today_job]!=0) return dp[n][today_job];
      if(n==1)
      {
            if(today_job==0) return max(vec[n].a[1],vec[n].a[2]);
            if(today_job==1) return max(vec[n].a[0],vec[n].a[2]);
            return max(vec[n].a[0],vec[n].a[1]);
      }
      if(today_job==0)
            return dp[n][today_job]=max(fun(n-1,1)+vec[n].a[1],fun(n-1,2)+vec[n].a[2]);
      if(today_job==1)
            return dp[n][today_job]=max(fun(n-1,0)+vec[n].a[0],fun(n-1,2)+vec[n].a[2]);

      return dp[n][today_job]=max(fun(n-1,0)+vec[n].a[0],fun(n-1,1)+vec[n].a[1]);
}

int main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
	cout.tie(nullptr);
	cerr.tie(nullptr);


      int n,i,j;
      cin>>n;
      for(i=1;i<=n;i++)
      {
            int a,b,c;
            cin>>vec[i].a[0]>>vec[i].a[1]>>vec[i].a[2];
      }
      int a=fun(n,0);
      int b=fun(n,1);
      int c=fun(n,2);
      cout<< max(a,max(b,c));

	return 0;
}



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

int main(){
    int N;
    cin >> N;
    vector<int> A(N), ans(N);
    for (int i = 1; i <= N; ++i) {
        int n;
        cin >> n;
        A[n - 1] = i;
    }
    for (int i = 0; i < N; ++i) {
        cout << A[i] << " ";
    }
    return 0;
}


Measured memory_bytes: 1536
n, s = map(int, input().split())
A = list(map(int, input().split()))
MOD = 998244353
W_MAX = s
dp = [0]*(W_MAX+1)
dp[0] = 1
inv_2 = pow(2, MOD-2, MOD)
for a in A:
    for j in reversed(range(W_MAX+1)):
        if W_MAX < j+a:
            continue
        dp[j+a] += dp[j]*inv_2
        dp[j+a] %= MOD

print(dp[-1]*pow(2, n, MOD) % MOD)

Measured memory_bytes: 68528
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

#define debug(...) fprintf(stderr, __VA_ARGS__)
#define int long long int
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
typedef pair<int, int> pii;
typedef long long ll;
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1001001001001001LL;
const ll MOD = 1000000007LL;

int solve() {
    int N, L, R; cin >> N >> L >> R;
    if(N == 0 and L == 0 and R == 0) return 1;

    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];

    int ans = 0;
    for(int y=L; y<=R; y++) {
        int chk = N;
        for(int i=N-1; i>=0; i--) {
            if(y % A[i] == 0) chk = i;
        }
        if(chk % 2 == 0) ans++;
    }
    cout << ans << endl;
    return 0;
}
 
signed main() {
    while(!solve());
    return 0;
}



Measured memory_bytes: 3072
L = gets.chomp.chars.map(&:to_i)

MOD = 10 ** 9 + 7
dp = Array.new(L.size + 1) { Array.new(2, 0) }
dp[0][0] = 0
dp[0][1] = 1
L.size.times do |i|
  bit = L[i]
  if bit == 0
    dp[i + 1][0] = (dp[i][0] * 3) % MOD
    dp[i + 1][1] = dp[i][1]
  else
    dp[i + 1][0] = (dp[i][0] * 3 + dp[i][1]) % MOD
    dp[i + 1][1] = (dp[i][1] * 2) % MOD
  end
end
puts (dp[L.size][0] + dp[L.size][1]) % MOD

Measured memory_bytes: 12668
#include<bits/stdc++.h>
using namespace std;
int a[500005];
int main()
{
    int n;
    cin>>n;
    while(n--)
    {
        int x;
        cin>>x;
        a[x]++;
        a[x-1]++;
        a[x+1]++;
    }
    int maxv=0;
    for(int i=0;i<=500000;i++)
        if(a[i]>maxv)
            maxv=a[i];
    cout<<maxv;
    return 0;
 } 

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

using namespace std;

int main() {
    int n, q;
    string s;
    cin >> n >> q >> s;

    vector<char> t(q), d(q);
    for (int i = 0; i < q; i++) {
        cin >> t[i] >> d[i];
    }

    int ll = -1, lr = n;
    while (ll < lr) {
        int m0 = (ll + lr + 2) / 2 - 1, mi = m0;
        for (int i = 0; i < q && 0 <= mi && mi < n; i++) {
            if (t[i] == s[mi] && d[i] == 'L') {
                mi--;
            } else if(t[i] == s[mi] && d[i] == 'R') {
                mi++;
            }
        }

        if (mi < 0) {
            ll = m0 + 1;
        } else {
            lr = m0;
        }
    }

    int rl = -1, rr = n;
    while (rl < rr) {
        int m0 = (rl + rr + 3) / 2 - 1, mi = m0;
        for (int i = 0; i < q && 0 <= mi && mi < n; i++) {
            if (t[i] == s[mi] && d[i] == 'L') {
                mi--;
            } else if(t[i] == s[mi] && d[i] == 'R') {
                mi++;
            }
        }

        if (mi < n) {
            rl = m0;
        } else {
            rr = m0 - 1;
        }
    }

    cout << rl - lr + 1 << endl;
}


Measured memory_bytes: 900
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

typedef pair<int, int> P;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	vi m1(100001);
	vi m2(100001);
	REP(i, N) {
		int v;
		cin >> v;
		if (i % 2 == 0) {
			m1[v]++;
		}
		else {
			m2[v]++;
		}
	}
	vector<P> p1;
	REP(i, 100001) {
		p1.push_back(P((N / 2) - m1[i], i));
		
	}
	vector<P> p2;
	REP(i, 100001) {
		p2.push_back(P((N / 2) - m2[i], i));
	}
	so(p1); so(p2);
	if (p1[0].second != p2[0].second) {
		cout << p1[0].first + p2[0].first << endl;
	}
	else {
		if (N == 2) {
			cout << 1 << endl;
			PAU;
			return 0;
		}
		int a = INT_MAX;
		if (SZ(p1) != 1)a = p1[1].first + p2[0].first;
		if (SZ(p2) != 1)a = min(a, p1[0].first + p2[1].first);
		cout << a << endl;
	}
	
	PAU;
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

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

ll func(ll n)
{
    ll L = 0;
    rep(i, n){
        int p;
        cin >> p;
        L += p;
    }
    
    vi j(n-1);
    rep(i, n-1){
        cin >> j[i];
    }
    sort(j.rbegin(), j.rend());
    
    for(int l : j){
        if((n-1)*(L+l) > n*L){
            L += l;
            --n;
        }
        else{
            break;
        }
    }
    
    return n*L;
}

int main()
{
    int n;
    while(cin >> n, n){
        cout << func(n) << endl;
    }
}

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

int main(){
    int n;
    long long int x;
    cin >> n >> x;

    vector<long long int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
    }

    long long int ans = 0;
    for(int i=0; i<n-1; i++){
        long long int rem = a[i] + a[i+1] - x;
        if(rem > 0){
            ans += rem;
            a[i+1] = max(a[i+1] - rem, 0LL);
        }        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
/*
In every question first approach must be basic, atleast give 15 mins for try to solve in basic approach
*/
 #include<iostream>
 #include<cstring>
 #include<string>
 #include<vector>
 #include<utility>
 #include<stdlib.h>
 #include<limits.h>
 #include<cmath>
 #include<set>
 #include<initializer_list>
 #include<unordered_set>
 #include<unordered_map>
 #include<map>
 #include<iomanip>
 #include<algorithm>
 #include<queue>
 #include<stack>
  
 #define sze 1000005
 #define ld long double
 #define ull unsigned long long
 #define ll long long
 #define endl "\n"
 #define pb push_back
 #define mkp make_pair
 #define mod 1000000007
 #define ff first
 #define ss second
 #define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
 #define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
 #define all(c) (c).begin(),(c).end()
  
 using namespace std;
 //const ll inf=1ll<<60;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
      
}
ll binpow(ll a, ll b) {
    ll res = 1;
    while (b > 0) {
        if (b & 1)
            res = (res%mod * a%mod)%mod;
        a = (a%mod * a%mod)%mod;
        b >>= 1;
    }
    return res;
}
//const int N=300005;


 int main()
 {
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     
     ll a,b,c,k; cin>>a>>b>>c>>k;
     if(a>=k)
     {
         cout<<k<<endl;
     }
     else
     {
         k = k-a;
         if(b>=k)
         {
             cout<<a<<endl;
         }
         else
         {
             k = k-b;
             cout<<a-k<<endl;
         }
     }
 }


Measured memory_bytes: 3652
#include<iostream>
using namespace std;
int main(){
    int H,W;
    while(1){
        cin>>H>>W;
        if(W==0&&H==0) break;
        for(int i=0;i<H;i++){
            for(int x=0;x<W;x++)
                if(i==0||i==H-1||x==0||x==W-1)cout<<'#';
                else cout<<'.';
            cout<<endl;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 3104
n, k = list(map(int, input().split()))

ans = 0
if k == 0:
    ans = n * n
else:
    for b in range(k + 1, n + 1):
        ans += n // b * (b - k)
        ans += max(0, (n - (n // b * b)) - k + 1)

print(ans)


Measured memory_bytes: 2940
/**
 * 最短経路の練習：「Warshall-Floyd法」
 * ABC160 D
 * https://atcoder.jp/contests/abc160/tasks/abc160_d
 * 
 * 期待する入力
 * N X Y
 * 3 <= N <= 2000
 * 1 <= X, Y <= N
 * X+1 < Y
 */

 package main

 import (
	 "fmt"
	 "bufio"
	 "os"
	 "strconv"
 )
 
 func main() {
	 sc := bufio.NewScanner(os.Stdin)
	 sc.Split(bufio.ScanWords)
 
	 N, X, Y := nextInt(sc), nextInt(sc), nextInt(sc)
	 
	 // 距離計算「Warshall-Floyd法」
	 // 今回、エッジの距離は全て１だが、1以外でも行けるはず...
	 // 参考：https://qiita.com/ta-ka/items/a023a11efe17ab097433#warshall-floyd%E6%B3%95
	 distance := make([][]int, N)
	 counter := make([]int, N-1)
	 ks := []int{0, X-1, Y-1}  // 0は隣接行列?を初期化するため
	 for index, k := range ks {
		 for i := 0; i < N; i++ {
			 if k == 0 {
				 distance[i] = make([]int, N)
				 if i == (X-1) {
					 distance[i][Y-1] = 1
				 } else if i == (Y-1) {
					 distance[i][X-1] = 1
				 }
			 }
			 for j := 0; j < i; j++ {
				 if k == 0 {
					 isSetedDistance := false
					 isSetedDistance = isSetedDistance || i == j
					 isSetedDistance = isSetedDistance || i == (X - 1) && j == (Y - 1)
					 isSetedDistance = isSetedDistance || j == (X - 1) && i == (Y - 1)
					 if !isSetedDistance {
						 distance[i][j] = i - j  // 迂回路が無い場合の距離を計算
					 }
				 }
				 distance[i][j] = min(distance[i][j], distance[i][k] + distance[k][j])
				 distance[j][i] = distance[i][j]  // 無向グラフのため、対称行列
				 if index == 2 {
					 counter[distance[i][j]-1] += 1
				 }
			 }
		 }
	 }
 
	 // 表示
	 for _, num := range counter {
		 fmt.Println(num)
	 }
 
 }
 
 func min(a, b int) int {
	 if a < b {
		 return a
	 }
	 return b
 }
 
 func nextInt(sc *bufio.Scanner) int {
	 sc.Scan()
	 t, _ := strconv.Atoi(sc.Text())
	 return t
 }

Measured memory_bytes: 59776
# カードの枚数を受け取る
n = int(input())

# インプットのカードをリストに入れる
input_list = [input() for i in range(n)]

# カードの辞書
card = {
    "S": [str(i) for i in range(1, 14)],
    "H": [str(i) for i in range(1, 14)],
    "C": [str(i) for i in range(1, 14)],
    "D": [str(i) for i in range(1, 14)]
}

# 辞書からインプットの値を削除
for j in input_list:
    suit, number = j.split()
    card[suit].remove(number)

# 処理実行
for key, value in card.items():
    for v in value:
        print(f"{key} {v}")



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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  cout<<(1000-n%1000==1000?0:1000-n%1000)<<endl;

}

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

using namespace std;

int main(){


int k, s, ans=0;

cin >> k >> s;
for (int x = 0; x <= k; x++){
	for (int y = 0; y <= k; y++){
		if ((s - x - y >= 0) and (s - x - y <= k)){
			ans++;
		}
	}
}
cout << ans;

}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        long n = scan.nextLong();
        long k = scan.nextLong();
        n -= k * (n / k - 1);
        System.out.println(Math.min(Math.abs(n - k), Math.abs(n - k * 2)));
    }
}

Measured memory_bytes: 27076
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <map>
using namespace std;
int x;
int main() {
    scanf("%d", &x);
    if (x >= 30) printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 3680
#include <stdio.h>
#include <string.h>
int main(void){
    long long n,x[1000],hp,ans=100100100;
    scanf("%lld",&n);
    for(long long i=1;i<=n;i++){
        scanf("%lld",&x[i]);
    }
    
    for (long long i=0;i<=100;i++){
        hp = 0;
        for (long long j=1;j<=n;j++){
            hp += (x[j]-i)*(x[j]-i);
        }
        if (ans > hp){
            ans = hp;
        }
    }
    printf("%lld",ans);
}

Measured memory_bytes: 128
fn main() {
    let read: Vec<u32> = read_vec();
    let _ = read[0];
    let num = read[1];
    let mut prices: Vec<u32> = read_vec();

    prices.sort();
    let mut price = 0;
    for i in 0..num {
        price += prices[i as usize];
    }

    println!("{}", price);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}



Measured memory_bytes: 2132
import sys
sys.setrecursionlimit(10**7)

# n = int(input())
# a, b = map(int, input().split())
# int_list = list(map(int, input().split()))
# l = list(input().split())

def solve():
    a, p = map(int, input().split())

    n_frac = a * 3 + p
    n_pi = n_frac // 2
    print(n_pi)
solve()

Measured memory_bytes: 2940
/**
 * @author: Mackenzie
**/
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < (int)n; i++)
#define pb push_back
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
int main() {
#ifdef LOCAL
    // freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#else
    fastIO;
#endif
    int n;
    cin >> n;
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (i & 1) {
            int cnt = 0;
            for (int j = 1; j * j <= i; j++) {
                if (i % j == 0) {
                    if (j * j == i)
                        cnt++;
                    else
                        cnt += 2;
                }
            }
            if (cnt == 8) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
input = require('fs').readFileSync('/dev/stdin', 'utf8')
lines = input.split('\n')
N = lines.shift() * 1
max = 0
sum = 0
for (i=0;i<N;i++) {
    sum += lines[i] * 1
    if (max < lines[i] * 1) {
      max = lines[i]
    }
}
console.log(sum - max / 2)

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

int main (){
    ll a,b;
    cin >> a >> b;
    if(a==1 || b==1)cout<<"1" << endl;
    else cout  << (ll)(a*b+1)/2 << endl;
    return 0;

}

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

int main(){
  int N,a=0,b,c;
  cin >> N;
  vector<int> vec(N);
  for(int i=0;i<N;i++){
    cin >> vec.at(i);
  }
  for(int i=0;i<N;i++){
    a = max(a,vec.at(i));
    if(vec.at(i)==a){
      b = i;
    }
  }
  sort(vec.begin(),vec.end());
  c = vec.at(vec.size()-2);
  for(int i=0;i<b;i++){
    cout << a << endl;
  }
  cout << c << endl;
  for(int i=b+1;i<vec.size();i++){
    cout << a << endl;
  }
}  


Measured memory_bytes: 2432
H, W = map(int,input().split())
s=[]

for i in range(0, H):
    s.append(input())

for y in range(0, H):
    for x in range(0, W):
        c=0
        for dx in range(-1, 2):
            for dy in range(-1, 2):
                xx = x + dx
                yy = y + dy
                if 0<=xx and xx<W and 0<=yy and yy<H:
                    if s[yy][xx]=="#":
                        c+=1

        if s[y][x]=="#":
            print("#", end='')
        else:
            print(c, end='')
    print("")

Measured memory_bytes: 3444
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ANot solver = new ANot();
        solver.solve(1, in, out);
        out.close();
    }

    static class ANot {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int x = in.nextInt();
            out.println(x ^ 1);
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }
}



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

const double EPS=1e-6;

double evaluate(vector<double>&r){
    double res=r[0]+r[r.size()-1];
    for(int i=0;i+1<r.size();i++){
        double h=(r[i]+r[i+1]);
        double s=abs(r[i]-r[i+1]);
        res+=sqrt(h*h-s*s);
    }
    return res;
}

double optimize(vector<double>r){
    double T=10000;
    double cool=0.99;
    double step=1;

    double mi=evaluate(r);

    while(T>0.00001){
        int a,b;
        while(true){
            a=rand()%r.size();
            b=rand()%r.size();
            if(a!=b)break;
        }

        double score=evaluate(r);
        swap(r[a],r[b]);
        double new_score=evaluate(r);

        double p=exp(-abs(new_score-score)/T);

        if(new_score>score || rand()<p*RAND_MAX);
        else{
            swap(r[a],r[b]);
        }

        mi=min(mi,new_score);
        T*=cool;
    }
    return mi;
}

int main(){
    //srand((unsigned)time(NULL));
    int l;
    while(cin>>l){
        string str;
        getline(cin,str);
        stringstream ss(str);
        vector<double>r;
        while(!ss.eof()){
            double t;
            ss>>t;
            r.push_back(t);
        }

        double ans;
        if(r.size()==1)ans=r[0]*2;
        else ans=optimize(r);

        if(ans<l+EPS)puts("OK");
        else puts("NA");
    }

    return 0;
}

Measured memory_bytes: 1308
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>
#include<map>


#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 ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
typedef pair<ll,ll> LL_LLP;
#define INF 1000000007
#define MAX_H 20000

#define ARRAY_MAX 100005



typedef struct edge{

    int to;
    int cost;

}EDGE;

void dijkstra(int n,vector<vector<EDGE> >& G,int x,vector<ll>& d){
    /*頂点の個数、辺の情報、始点となる頂点、直前の頂点の情報、最短距離の情報*/

    /*最終的にdは経由点からの最短距離が格納される、その過程では暫定的な最短距離が格納され、最短距離が見つかれば、その都度更新される*/

    //vector<ll> d(n,INF);/*最終的な最短距離を保持、初期化はINF*/
    d[x] = 0;
    priority_queue<LL_IP,vector<LL_IP>,greater<LL_IP> > que;/*vectorのpriority_queueで暫定的な最短距離が小さい順に取り出す*/
    que.push(LL_IP(0,x));/*経由点からダイクストラを適用するので経由点の暫定的な最短距離のコストは0*/

    while(!que.empty()){/*queが空になれば最短距離が全て探索できたことになる*/

        LL_IP p = que.top();/*最短距離の１番小さいものの取り出し*/
        que.pop();/*取り出したので調べたとみなし、queから出す*/
        int v = p.second;/*取り出した頂点の番号*/
        if(d[v] < p.first){
            /*取り出した頂点からの最短距離よりも短い経路があるので更新の必要はない*/
            continue;
        }

        for(int i = 0;i < G[v].size(); i++){
            /*取り出した頂点から辺でつながっている頂点への最短距離を調べて現在の値より短ければ更新する*/
            EDGE e = G[v][i];/*取り出した頂点からつながっている頂点を1つ取り出す*/
            if(d[e.to] > d[v] + e.cost){
                /*現在の最短距離よりも、現在の頂点を経由する経路のほうが最短距離が短い場合は最短距離を更新し、次の頂点を調べる*/
                d[e.to] = d[v] + e.cost;/*最短経路の更新*/
                que.push(P(d[e.to],e.to));/*先の頂点を調べるためqueに格納*/
            }
                    
        }
    }
}


int main(){

    int n,a,b,c,q,k,x,y;
    cin >> n;
    vector<vector<EDGE> > G(n);/*n個の各頂点からそれ以外の頂点へのコスト*/
    vector<ll> d1(n,INF);/*最短経路*/
    vector<ll> d2(n,INF);
    vector<ll> path;/*経路復元用*/

    REP(i,n-1){
        cin >> a >> b;
        a--;
        b--;/*配列の添え字へ合わせる*/
        c = 1;
        EDGE e1 = {b,c};
        EDGE e2 = {a,c};
        /*無効グラフなので双方向にコストを保持*/
        G[a].pb(e1);/*頂点aから頂点bへのコストがc*/
        G[b].pb(e2);/*頂点bから頂点aへのコストがc*/
    }
    /*辺の張り終わり*/

    dijkstra(n,G,0,d1);/*経由点から各頂点への最短距離を格納した配列*/
    dijkstra(n,G,n-1,d2);/*経由点から各頂点への最短距離を格納した配列*/

    int Fennec = 0,Snuke = 0;
    for(int i = 1;i <= n-2;i++){
        if(d1[i] <= d2[i]){
            Fennec++;
        } else{
            Snuke++;
        }
    }
    
    if(Fennec > Snuke){
        cout << "Fennec" << endl;
    }else{
        cout << "Snuke" << endl;
    }

    return 0;
}

Measured memory_bytes: 8544
#include<iostream>
#include<algorithm>
#include<vector>
int H, W;
int N;
int ans[110][110];
int A[10100];
std::vector<int> SS;
int main() {
	std::cin >> H >> W >> N;
	int a = 0;
	for (int i = 1; i <= N; i++) {
		int tmp;
		std::cin >> tmp;
		for (int j = 0; j < tmp; j++) {
			SS.push_back(i);
		}
	}
	for (int i = 0; i < H; i++) {
		if (i % 2 == 0) {
			for (int j = 0; j < W; j++) {
				ans[i][j] = SS[a];
				a++;
			}
		}
		else {
			for (int j = W - 1; j >= 0; j--) {
				ans[i][j] = SS[a];
				a++;
			}
		}
	}
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			std::cout << ans[i][j];
			if (j != W - 1)std::cout << " ";
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 384
n=int(input())
p=[int(input()) for i in range(n)]
l=[-1 for i in range(n)]
for i in range(n):
  l[p[i]-1]=i
ans=[]
ct=1
for i in range(n-1):
  if l[i]<l[i+1]:
    ct+=1
  else:
    ans.append(ct)
    ct=1
ans.append(ct)
ct=1
print(n-max(ans))

Measured memory_bytes: 20532
def fuga(check_dict, check_str):
  for j, num_str in enumerate(str(check_str)):
    if(not(j in check_dict)):
      continue
    if(check_dict[j] != int(num_str)):
      return False
  return True

N,M = list(map(int, input().split()))
li = [list(map(int, input().split())) for _ in range(M)]
check = {}
for s,c in li:
  if(s-1 in check):
    if(check[s-1] != c):
      print(-1)
      exit()
  check[s-1] = c

if(N == 1):
  for i in range(10):
    if(fuga(check, i)):
      print(i)
      exit()
  print(-1)
  exit()
for i in range(10**(N-1), 10**(N)):
  if(fuga(check, i)):
    print(i)
    exit()
print(-1)


Measured memory_bytes: 3064
n = int(input())

result = [0 for i in range(n+1)]

for i in range(1, n+1):
    for j in range(2, i+1):
        while i%j == 0:
            result[j] += 1
            i //= j
        if i == 1:
            break
r = 1
for i in range(n+1):
    r *= result[i]+1
    r %= 10**9 + 7
print(r)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <stack>
#include<algorithm>
#include<sstream>
#include<iomanip>


using namespace std;

typedef long long ll;

const ll MOD_CONST = 1000000007;
const ll BIG_NUM = 1000000000000000000;

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

	

	vector<pair<ll,int>> sushi(n);
	
	
	for (int i = 0; i < n;i++) {
		int t, d;
		cin >> t >> d;
		t--;
		sushi[i] = make_pair(d, t);
	}
	
	vector<int> cnt_Ate(n);

	sort(sushi.begin(), sushi.end());

	vector<ll> sum_d(n+1);
	priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> pq;
	ll s = 0;
	for (int i = n - 1; i >= n - k;i--) {
		s += sushi[i].first;
		if (cnt_Ate[sushi[i].second] > 0) {
			pq.push(sushi[i]);
		}
		cnt_Ate[sushi[i].second]++;
		
	}

	int c = 0;
	for (int i = 0; i < n;i++) {
		if (cnt_Ate[i] > 0) {
			c++;
		}
	}
	

	sum_d[c] = s;
	
	int p = n - k - 1;
	for (int i = c + 1; i <= n;i++) {
		
		while(p >=0 &&cnt_Ate[sushi[p].second] != 0 ) {
			p--;
			
		}
		
		if (p == -1) {
			break;
		}
		if (pq.empty()) {
			break;
		}
		cnt_Ate[sushi[p].second]++;
		sum_d[i] = sum_d[i - 1] + sushi[p].first - pq.top().first;
		
		pq.pop();

	}

	ll ans = 0;
	for (ll i = 1; i <=n; i++) {
		if (sum_d[i] > 0) {
			ans = max(i*i + sum_d[i], ans);
		}
	}
	
	cout << ans << endl;
}


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

using namespace std;

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

	vector<pair<long long, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first >> a[i].second;
	}

	long long ans = 0, sum = 0, t;
	for (int i = n - 1; i >= 0; i--) {
		t = a[i].second - (a[i].first + sum) % a[i].second;
		t %= a[i].second;

		ans += t;
		sum += t;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()

using namespace std;

int N;
int A[200010];
int B[200010];

signed main()
{
	cin >> N;
	REP(i, N) cin >> A[i + 1];

	for (int i = N; i >= 1; i--)
	{
		int s = 0;
		int c = i * 2;
		while (c <= N)
		{
			s ^= B[c];
			c += i;
		}
		B[i] = (A[i] ^ s);
	}

	
	int cnt = 0;
	for (int i = 1; i <= N; i++)
	{
		if (B[i])
		{
			cnt++;
		}
	}
	cout << cnt << endl;
	for (int i = 1; i <= N; i++)
	{
		if (B[i])
		{
			cout << i << " ";
		}
	}
	cout << endl;
}




Measured memory_bytes: 3968