akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int main()
{
	long long n, sum=0;
	cin>>n;
	long long a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		a[i]=a[i]-i-1;
	}
	sort(a,a+n);
	int b=a[n/2];
	for(int i=0;i<n;i++)sum+=fabs(a[i]-b);
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 1792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
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);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            int ans = 1;
            for (int i = 1; i * i <= m; i++) {
                if (m % i == 0) {
                    if (i <= m / n) ans = Math.max(ans, i);
                    if (m / i <= m / n) ans = Math.max(ans, m / i);
                }
            }

            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader br;
        private StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
            st = new StringTokenizer("");
        }

        public String nextString() {
            while (!st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine(), " ");
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextString());
        }

    }
}



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

using namespace std;

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

    set <int> st;
    for (int i = 0; i < n; i++) {
        int x;  cin >> x;
        st.insert(x);
    }

    cout << (st.size() == n ? "YES" : "NO") << '\n';
    return 0;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    istream& in(cin);
    ostream& out(cout);
    int n;
    in>>n;
    fr(i,n+1){
        int x=i;
        x*=108;
        x/=100;
        if(n==x) return cout<<i<<endl,0;
    }
    cout<<":("<<endl;
}

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

int main(){
  long int A,B;
  string S,T,U;
  cin>>S>>T;
  cin>>A>>B;
  cin>>U;
  if(U==S)A--;
  else if(U==T)B--;
  cout<<A<<" "<<B<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
int max(int x, int y) {
    return x >= y ? x : y;
}
int min(int x, int y) {
    return x <= y ? x : y;
}
static int w, h, n, x, y, a, i;
static int x_max, x_min, y_max, y_min;
int main(void) {
    scanf("%d%d%d", &w, &h, &n);
    x_min = y_min = 0;
    x_max = w;
    y_max = h;
    for (i = 1; i <= n; ++i) {
        scanf("%d%d%d", &x, &y, &a);
        if (a == 1) {
            x_min = max(x_min, x);
        } else if (a == 2) {
            x_max = min(x_max, x);
        } else if (a == 3) {
            y_min = max(y_min, y);
        } else if (a == 4) {
            y_max = min(y_max, y);
        } else {
        
        }
    }
    if (x_min > x_max)
        x_min = x_max;
    if (y_min > y_max)
        y_min = y_max;
    printf("%d\n", (x_max - x_min) * (y_max - y_min));
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i=0; i<(n); ++i)
#define REP(i, d, n) for(int i=(d); i<(n); ++i)
#define all(v) v.begin(), v.end()
using P = pair<int, int>;

signed main() {

    string s;
    cin >> s;

    if(s == "ABC"){
        cout << "ARC" << endl;
    }
    else{
        cout << "ABC" << endl;
    }

    return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define ll long long
#define F(i,a,b) for(i = a; i <= b; i ++)
#define RF(i,a,b) for(i = a; i >= b;i --)
#define sz(a) sizeof(a)
#define deb(a) cout<<#a<<' '<<a
using namespace std;

typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<char,int> pci;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef map<char,int> mci;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
typedef unordered_map<char,int> umci;
typedef vector<ll>  vll;
typedef vector<vector<ll> > vvll;

int n_v = 100000,n_e;
bool visited[100000];
vector< vector<int> > graph(n_v); 
vector<int> LongestPath(n_v, -1);

int LongestPathFromANode(int node){
    if(LongestPath[node] != -1)
        return LongestPath[node];
    //deb(node);
    int MaxPath = 0;
    for(int child: graph[node]){
        MaxPath = max(1 + LongestPathFromANode(child), MaxPath);
    }
    LongestPath[node] = MaxPath;
    return MaxPath;
}


void solve()
{
    int i;
    cin>>n_v>>n_e;
    memset(visited , false ,sizeof(visited));
    F(i,0,n_e - 1)
    {
        int u,v;
        cin>>u>>v;
        graph[u - 1].push_back(v - 1);
    }
    int Maxpath = 0;
    F(i, 0, n_v - 1){
        if(LongestPath[i] == -1)
            LongestPathFromANode(i);
    }
    F(i, 0, n_v - 1) 
        Maxpath = max(LongestPath[i], Maxpath);
    cout<<Maxpath<<'\n';
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    //#else
    //#endif
    solve();
}


Measured memory_bytes: 11028
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s,t;
    cin>>s>>t;
    int n=s.size(),m=t.size();
    int dp[n+1][m+1]={0};

    for(int i=1;i<=n;i++)dp[i][0]=i;
    for(int i=1;i<=m;i++)dp[0][i]=i;

    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            int x = dp[i-1][j]+1,y = dp[i][j-1]+1,z=dp[i-1][j-1];
            if(s[i-1]==t[j-1]){dp[i][j] = min(x,min(y,z));}
            else dp[i][j] = min(x,y);
        }
    }
    
    
    
    // for(int i=0;i<=n;i++){
    //     for(int j=0;j<=m;j++){
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    

    int i=n,j=m;

    string ans;
    
    // vector<int> v;

    while(i>0 && j>0){
        if(dp[i][j]==dp[i-1][j-1] && s[i-1]==t[j-1]){ans+=s[i-1];  i--;j--;}
        else if(dp[i][j]==dp[i-1][j]+1){i--;}
        else j--;
    }
    // for(auto u:v)cout<<u<<" ";
    // if(v.size()>0)
    // {for(int q=v.size()-1;q>=0;q++)cout<<(v[q]);}
    
    for(int i=ans.size()-1;i>=0;i--)cout<<ans[i];
    
    return 0;
}    

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

using namespace std;

int main(){
	int a,b; cin>>a>>b;
  string s; cin>>s;
  for(int i=0;i<=a+b;i++){
  	if(i==a){
    	if(s[i]!='-'){
        	printf("No");
          return 0;
        }
    }
    else{
    	if(s[i]=='-'){
        	printf("No");
          return 0;
        }
    }
  }
  printf("Yes");
}

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

using namespace std;

const int N = 5e5+5;

const int mod = 1e9+7;

long long x , k , d;

int main(){
    cin >> x >> k >> d;
    long long ans = abs(x);
    if(x == 0){
        if(k % 2 == 0){
            ans = 0;
        } else {
            ans = d;
        }
        cout << ans << "\n";
        return 0;
    }
    if(x > 0){
        long long toP = x - min((x - 0) / d , k) * d;
        long long tmpK = (k - (min((x - 0) / d , k))) % 2;
        if(tmpK){
            toP = min(abs(toP + d) , abs(toP - d));
        }
        long long toN = x - min((x - 0 + d - 1) / d , k) * d;
        long long tmpK2 = (k - (min((x - 0 + d - 1) / d , k))) % 2;
        if(tmpK2){
            toN = min(abs(toN - d) , abs(toN + d));
        }
        //cout << toP << "\n";

        ans = min(abs(toN) , abs(toP));
    } else {
        //first -ve number
        long long toN = x + min((0 - x) / d , k) * d;
        long long tmpK = (k - (min((0 - x) / d , k))) % 2;
        if(tmpK){
            toN = min(abs(toN + d) , abs(toN - d));
        }
        //first +ve number
        long long toP = x + min((0 - x + d - 1) / d , k) * d;
        long long tmpK2 = (k - (min((0 - x + d - 1) / d , k))) % 2;
        if(tmpK2){
            toP = min(abs(toP + d) , abs(toP - d));
        }
        ans = min(abs(toN) , abs(toP));
    }
    cout << ans << "\n";
}


Measured memory_bytes: 3632
#include <stdio.h>

int main()
{
    int input[10000];
    
    for (int i = 0; i < 10000; i++){
        scanf("%d", &input[i]);
        if (input[i] == 0) {
            break;
        }
        else {
            /* NOP */
        }

    }

    for (int j = 0; j < 10000; j++) {
        if (input[j] == 0) {
            break;
        }
        else {
            /* NOP */
        }

        printf("Case %d: %d\n", (j + 1), input[j]);
        
    }
}


Measured memory_bytes: 1992
import java.util.*;
public class Main{
public static void main(String[]args){
Scanner sc=new Scanner(System.in);
int n=sc.nextInt();
  int k=sc.nextInt();
  int []po=new int [n+1];
  for(int i=0;i<n;i++){
  po[sc.nextInt()]++;
  }
  Arrays.sort(po);
  int ans=0;
  for(int i=0;i<k;i++){
  	ans+=po[n-i];
  }
  System.out.println(n-ans);
}

}

Measured memory_bytes: 85724
import java.io.IOException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

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

	void run() {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int Q = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		--A;
		--B;
		int[] x = new int[Q];
		for (int i = 0; i < Q; ++i) {
			x[i] = sc.nextInt();
			--x[i];
		}
		long[] f = new long[N];
		Arrays.fill(f, Long.MAX_VALUE / 16);
		Seg sAdd = new Seg(N);
		Seg sSub = new Seg(N);
		f[B] = Math.abs(A - x[0]);
		f[A] = Math.abs(B - x[0]);
		sAdd.setVal(A, f[A] + A);
		sAdd.setVal(B, f[B] + B);
		sSub.setVal(A, f[A] - A);
		sSub.setVal(B, f[B] - B);
		long pending = 0;
		for (int i = 1; i < Q; ++i) {
			long add = Math.abs(x[i] - x[i - 1]);
			pending += add;
			long cur = f[x[i]];// pending分は除く
			cur = Math.min(cur, -x[i] + sAdd.query(x[i], N) - add);
			cur = Math.min(cur, x[i] + sSub.query(0, x[i]) - add);
			f[x[i - 1]] = cur;
			sAdd.setVal(x[i - 1], f[x[i - 1]] + x[i - 1]);
			sSub.setVal(x[i - 1], f[x[i - 1]] - x[i - 1]);
		}
		long ans = Long.MAX_VALUE / 16;
		for (int i = 0; i < N; ++i) {
			ans = Math.min(ans, f[i] + pending);
		}
		System.out.println(ans);
	}

	class Seg {
		int n;
		long[] v;

		public Seg(int n_) {
			n = 1;
			while (n < n_)
				n *= 2;
			v = new long[2 * n - 1];
			Arrays.fill(v, Long.MAX_VALUE / 16);
		}

		void setVal(int k, long val) {
			k += n - 1;
			v[k] = val;
			while (k > 0) {
				k = (k - 1) / 2;
				v[k] = Math.min(v[2 * k + 1], v[2 * k + 2]);
			}
		}

		long query(int a, int b) {
			return query(0, n, a, b, 0);
		}

		long query(int l, int r, int a, int b, int k) {
			if (r <= a || b <= l) {
				return Long.MAX_VALUE / 16;
			} else if (a <= l && r <= b) {
				return v[k];
			} else {
				long vl = query(l, (l + r) / 2, a, b, 2 * k + 1);
				long vr = query((l + r) / 2, r, a, b, 2 * k + 2);
				return Math.min(vl, vr);
			}
		}

	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Measured memory_bytes: 91312
#include <algorithm>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#define repd(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;

using namespace std;

int inputValue();
void inputArray(int *, int);
void inputVector(vector<int> *, int);
template <typename T> void output(T, int);
int gcd(int a, int b);

int main() {
    // source
    int h, w;
    cin >> h >> w;
    vector<string> a;
    rep(i, h) {
        string temp;
        cin >> temp;
        a.push_back(temp);
    }

    vector<int> index0, index1;

    rep(i, h) {
        bool judge = false;
        rep(j, w) {
            if (a[i][j] == '#') {
                judge = true;
            }
        }
        index0.push_back(judge);
    }
    rep(j, w) {
        bool judge = false;
        rep(i, h) {
            if (a[i][j] == '#') {
                judge = true;
            }
        }
        index1.push_back(judge);
    }

    rep(i, h) {
        if (!index0[i]) {
            continue;
        }
        rep(j, w) {
            if (index1[j]) {
                cout << a[i][j];
            }
        }
        cout << endl;
    }
    return 0;
}

int inputValue() {
    int a;
    cin >> a;
    return a;
}

void inputArray(int *p, int a) {
    rep(i, a) { cin >> p[i]; }
}

void inputVector(vector<int> *p, int a) {
    rep(i, a) {
        int input;
        cin >> input;
        p->push_back(input);
    }
}

template <typename T> void output(T a, int precision) {
    if (precision > 0) {
        cout << setprecision(precision) << a << "\n";
    } else {
        cout << a << "\n";
    }
}

int gcd(int a, int b) {
    if (b > a) {
        int temp = a;
        a = b;
        b = temp;
    }
    if (b == 0) {
        return a;
    }
    return (b, b % a);
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
const int MOD = 1e9+7;
const long long INF = 1LL << 60;
const int inf = 1e9;
typedef long long ll;

int main() {
    string s; cin >> s;
    int ans = inf, Ans = inf;
    if(s[0]=='0'){
        ans=0;
        for(int i=1;i<s.size();i++){
            if(s[i-1]=='0'&&s[i]=='0'){
                ans++;
                s[i]='1';
            }else if(s[i-1]=='0'&&s[i]=='1'){
                ;
            }
            if(s[i-1]=='1'&&s[i]=='0'){
                ;
            }else if(s[i-1]=='1'&&s[i]=='1'){
                ans++;
                s[i]='0';
            }
        }
    }
    if(s[0]=='1'){
        Ans=0;
        for(int i=1;i<s.size();i++){
            if(s[i-1]=='0'&&s[i]=='0'){
                Ans++;
                s[i]='1';
            }else if(s[i-1]=='0'&&s[i]=='1'){
                ;
            }
            if(s[i-1]=='1'&&s[i]=='0'){
                ;
            }else if(s[i-1]=='1'&&s[i]=='1') {
                Ans++;
                s[i]='0';
            }
        }
    }
    cout<<min(ans,Ans)<<endl;
}

Measured memory_bytes: 512
#!/usr/bin/env python3
x1, y1, x2, y2 = map(int, input().split())
def f(x1,y1,x2,y2):
    x3=x2+y1-y2
    y3=y2-(x1-x2)
    return x3,y3
x3,y3=f(x1,y1,x2,y2)
x4,y4=f(x2,y2,x3,y3)

print(x3,y3,x4,y4)


Measured memory_bytes: 2940
fn gcd(a: u64, b: u64) -> u64 { if b == 0 { a } else { gcd(b, a % b) } }
fn lcm(a: u64, b: u64) -> u64 { a / gcd(a, b) * b }


fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let mut input: Vec<i32> = s.split_whitespace().map(|x| x.parse::<i32>().unwrap()).collect();
    let n = input[0];

    let ans = lcm(n as u64, 2);
    println!("{}", ans);
}


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

#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
const int MOD = 1e9 + 7;
const int maxn = 1e6 + 5;
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-8;

void header() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}

char s[maxn];

void solve() {
    cin >> (s + 1);
    int f = 1, n = strlen(s + 1);
    for (int i = 1; i <= n; i++) {
        if (s[i] != s[n - i + 1]) {
            f = 0;
            break;
        }
    }
    int r = (n - 1) / 2;
    for (int i = 1; i <= r; i++) {
        if (s[i] != s[r - i + 1]) {
            f = 0;
            break;
        }
    }
    int l = (n + 3) / 2;
    for (int i = l; i <= n; i++) {
        if (s[i] != s[n - i + 1]) {
            f = 0;
            break;
        }
    }
    cout << (f ? "Yes" : "No") << endl;
}

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


Measured memory_bytes: 256
N,K=[int(s) for s in input().split()]
S=input()
ls=[]
if S[0]=='0':
  ls.append([0,0])
else:
  start=0
i=1
while True:
  if i>=N:
    if S[N-1]=='0':
      ls.append([N,N])
    else:
      ls.append([start,N])
    break
  if S[i-1]=='0' and S[i]=='1':
    start=i
  if S[i-1]=='1' and S[i]=='0':
    goal=i
    ls.append([start,goal])
  i+=1
if K>=len(ls)-1:
  print(N)
else:
  ls2=[ls[i+K][1]-ls[i][0] for i in range(len(ls)-K)]
  print(max(ls2))



Measured memory_bytes: 13040
def flagcount(num):
    count = 0
    while num:
        count += num & 1
        num >>= 1
    return count
n=int(input())
g=[[-1]*n for _ in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        g[i][x-1]=y
ans=0
for bit in range(1<<n):
    d=[]#
    for x in range(n):
        if bit&1<<x:
            d.append(1)
        else:
            d.append(0)
    flag=1
    for i in range(n):
        if d[i]:
            for j in range(n):
                if g[i][j]==-1:
                    continue
                if g[i][j]!=d[j]:
                    flag=0
    if flag:
        ans=max(ans,flagcount(bit))     
print(ans)

Measured memory_bytes: 44764
import java.awt.*;
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.time.*;
import java.util.List;


//给出两个数a,b 求出[a,b]中各位数字之和能整除原数的数的个数。
public class Main {
    int[][] dirs = new int[][]{{0, -1}, {0, 1}, {1, 0}, {-1, 0}};

    int find_max(int[] arr) {
        int max = Integer.MIN_VALUE;
        int n = arr.length;
        for (int i = 0; i < n; i++) {
            max = Math.max(max, arr[i]);
        }
        return max;
    }

    int sum(int[] arr, int md) {
        int res = 0;
        for (int i = 0; i < arr.length; i++) {
            res += arr[i];
            res %= mod;
        }
        return res;
    }

    long db(long sx, long mx, long xs) {//等比数列
        return (sx + mx) * xs / 2;
    }

    int mod = (int) 1e9 + 7;
    int mx = 0;
    long[] dp;

    ///int v = (int) 1e5;
    ///
    void solve(int l,int r,int d) {
        int cnt = 0;
        for(int i=1;i*d<=r;i++){
            int v = i*d;
            if(v>=l&&v<=r) cnt++;
        }
        System.out.println(cnt);
    }




    public static void main(String[] args)  throws IOException {
        // Use the Scanner class
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Main test = new Main();
        String[] s = br.readLine().split(" ");
        test.solve(Integer.parseInt(s[0]),Integer.parseInt(s[1]),Integer.parseInt(s[2]));
    }
}


Measured memory_bytes: 32628
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

void fi(int a) {
//    cout << a << endl;
    if(a % 2 == 0) output("First");
    else output("Second");
    exit(0);
}

void se(int a) {
//    cout << a <<  endl;
    if(a % 2 == 0) output("Second");
    else output("First");
    exit(0);
}

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

template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) {
        cin >> A[i];
    }
    
    
    int loop = 0;
    while(1){
        int even = 0;
        int odd = 0;
        rep(i, N){
            if(A[i] % 2 == 0) even++;
            else odd++;
        }
        
        if(odd == 1 && even % 2 == 0){
            
            rep(i, N) {
                if(A[i] == 1){
                    se(loop);
                }
                if(A[i] % 2 == 1) A[i]--;
            }
            ll g = A[0];
            rep(i, N) g = gcd(g, A[i]);
            rep(i, N) A[i] /= g;
        }
        else{
            if(even % 2 == 0){
                se(loop);
            }
            else{
                fi(loop);
            }
        }
        loop++;
    }
    
    
    return 0;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  while(1) {
    int n; cin >> n;
    if(n == 0) break;
    vector<int> a(n);
    double me = 0;
    for(int i=0;i<n;++i) {
      cin >> a[i];
      me += a[i];
    }
    me /= n;
    me += eps;
    int cnt = 0;
    for(int i=0;i<n;++i) {
      if(a[i] <= me) {
        cnt++;
      }
    }
    cout << cnt << endl;
  }
}



Measured memory_bytes: 3120
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<algorithm>
#define maxn 100005
#define ll long long
using namespace std;
int n;
ll a,b;
ll x[maxn];
int main()
{

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

    for(int i=1;i<=n;i++)
        scanf("%lld",&x[i]);
        ll ans=0;
        for(int i=1;i<n;i++)
        {
            if((x[i+1]-x[i])*a>b)
                ans+=b;
            else
                ans+=(x[i+1]-x[i])*a;
        }
        printf("%lld\n",ans);
        return 0;
}


Measured memory_bytes: 1024
s = gets.chomp
ln = s.length
s = s.split("")
id = 0
cnt = 0
pre = Array.new(2)
while id < ln
  if id > 0
    if pre.join.length >= 2
      pre[0] = s[id]
      pre[1] = nil
      cnt += 1
      id += 1
    else
      if pre[0] == s[id]
        if id+1 < ln
          pre[0] = s[id]
          pre[1] = s[id+1]
          cnt += 1
          id += 2
        else
          pre[0] = s[id]
          id += 1
        end
      else
        pre[0] = s[id]
        pre[1] = nil
        cnt += 1
        id += 1
      end
    end
  else
    pre[0] = s[id]
    pre[1] = nil
    cnt += 1
    id += 1
  end
end
puts cnt


Measured memory_bytes: 26108
#include<bits/stdc++.h>
//#include<atcoder/all>

typedef long long ll;

using namespace std;

int main(){
    string S; cin >> S;
    if(S[S.size()-1] == 's')cout << S << "es" << endl;
    else cout << S << 's' << endl;
    return 0;

}

Measured memory_bytes: 3620
# n = gets.chomp.to_i
# a = gets.chomp.split(" ").map(&:to_i)
# ans = 0
mod = 10 ** 9 + 7

# i = 0
# while true
#     t = i + 1
#     kake = 0
#     until t == n 
#     kake += (a[t] % mod)
#     t += 1
#     end
#     ans = ans + (a[i] * kake) % mod
#     ans %= mod
#     if i == n - 2
#         break
#     end
#     i += 1
# end
# puts ans
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)
ans = 0
hiku = 0
a.each do |i|
    ans += i
    hiku += i * i
end
puts ((ans * ans - hiku)/ 2) % mod

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

int main() {
	int x, mx = 1;
	cin >> x;

	for (int b = 1; b <= x; b++) {
		for (int p = 2; p <= x; p++) {
			if (pow(b, p) > x) break;
			else if (mx < pow(b, p)) mx = pow(b, p);
		}
	}
	cout << mx << endl;
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
template<class T> void chmax(T& a, T b) { if(a < b) a = b; }

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

    // 最大次数から最大色数を特定
    int mc = 0;
    for(int i = 0; i < n; i++) chmax(mc, (int)g[i].size());

    V<int> ans(n - 1, -1); // 各辺の色を記録
    V<int> d(n, -1); // 訪問未訪問の管理
    queue<P<int, int>> que;
    que.push({0, -1});
    d[0] = 1;
    while(!que.empty()){
        auto p1 = que.front();
        que.pop();
        int v = p1.first; // 頂点
        int c = p1.second; // 色
        int color = 1;
        if(color == c) color++; // 親と被ったらスキップ
        for(auto p2 : g[v]){
            // 未訪問の場合
            if(d[p2.first] == -1){
                d[p2.first] = 1;
                que.push({p2.first, color});
                ans[p2.second] = color;
                color++;
                if(color == c) color++; // 親と被ったらスキップ
            }
        }
    }
    cout << mc << endl;
    for(int i = 0; i < n - 1; i++) cout << ans[i] << endl;

}


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

using namespace std;

using ll = long long;
constexpr ll inf = 1e18;

array<ll, 100001> dp;
ll ww[100];
ll vs[100];

int main() {
  for (auto &&x : dp) {
    x = inf;
  }
  dp[0] = 0;
  ll n, w;
  cin >> n >> w;
  for (ll i = 0; i < n; ++i) {
    cin >> ww[i] >> vs[i];
  }
  ll ans = 0;
  for (ll i = 0; i < n; ++i) {
    for (ll j = 100000; j >= 0; --j) {
      if (j - vs[i] < 0)
        break;
      dp[j] = min(dp[j], dp[j - vs[i]] + ww[i]);
    }
  }
  for (int i = 0; i <= 100000; ++i) {
    if (dp[i] <= w)
      ans = i;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define loop(i,k,n) for(int i=k;i<n;i++)
#define rloop(i,k,n) for(int i=k;i>=n;i--)
#define tests int l; cin>>l; while(l--)
#define input(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define lli long long int
#define ld long double
#define pb push_back
#define mod1 1000000007
using namespace std;
int main()
{
  lli n,i=0;
  cin>>n;
  string s[2];
  cin>>s[0]>>s[1];
  lli ways[n]={0};
  lli ans=1;
  if(s[0][0]==s[1][0])
  {
    ways[0]=3;
    i++;
    ans*=3;
  }
  else
  {
    ways[0]=3,ways[1]=3;
    i+=2;
    ans*=6;
  }
  for(i;i<n;i++)
  {
    if(s[0][i]==s[1][i])
    {
      if(s[0][i-1]!=s[1][i-1])
      {
        //cout<<1<<endl;
        ans*=1;
        ans=ans%mod1;
      }
      else
      {
        //cout<<2<<endl;
        ans*=2;
        ans=ans%mod1;
      }
    }
    else
    {
      if(s[0][i-1]!=s[1][i-1])
      {
        //cout<<3<<endl;
        ans*=3;
        ans=ans%mod1;
      }
      else
      {
        //cout<<4<<endl;
        //cout<<"y";
        ans*=2;
        ans=ans%mod1;
      }
      i++;
    }
  }
  cout<<ans;
}


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

#define  ll         long long
#define  llu        unsigned long long
#define  mod        1000000007
#define  pi         ((2.0)*acos(0.0))
#define  pb         push_back
#define  pf         push_front
#define  eb         emplace_back
#define  mp         make_pair
#define  all(x)     (x).begin(),(x).end()
#define  X          first
#define  Y          second

/*loop*/
#define  fr(i,m,n)   for(ll i=m;i<n;++i)

/*output shortcuts*/
#define  nl         "\n"
#define  Yes        cout<<"Yes\n"
#define  yes        cout<<"yes\n"
#define  YES        cout<<"YES\n"
#define  No         cout<<"No\n"
#define  no         cout<<"no\n"
#define  NO         cout<<"NO\n"


bool cmp(const std::pair<ll,ll>&a, const std::pair<ll,ll>&b)
{
    if(a.X == b.X)
        return a.Y>b.Y;
    return a.X < b.X;
}

using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    ll n,weight;
    cin>>n>>weight;

    vector<pair<ll,ll>>v;
    fr(i,0,n)
    {
        ll x,y;
        cin>>x>>y;
        v.pb({x,y});
    }
    sort(all(v),cmp);

    ll w[n+1],val[n+1],k=0;
    for(auto x:v)
    {
        w[++k]=x.X;
        val[k]=x.Y;
    }
    ll dp[n+1][weight+1];

    fr(i,0,n+1)
    {
        fr(j,0,weight+1)
        {
            if(i==0 || j==0)
                {dp[i][j]=0;continue;}
            if(w[i]<=j)
                dp[i][j]=max(dp[i-1][j], val[i]+dp[i-1][j- w[i]]);
            else
                dp[i][j]=dp[i-1][j];
            //cout<<dp[i][j]<<" ";
        }
        //cout<<nl;
    }
    cout<<dp[n][weight]<<nl;
return 0;
}



Measured memory_bytes: 82476
#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, k;
    cin >> n >> k;
    vector<int> p(n);
    for (int i = 0; i < n; i++)
    {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int ans = 0;
    for (int j = 0; j < k; j++)
    {
        ans += p[j];
    }
    cout << ans << endl;
    return 0;
}

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

int main(void)
{
	char y,a[20],b[20];
	int x=0;
	scanf("%s",a);
	while(1){
		scanf("%s",b);
		int f=strcmp(b,"END_OF_TEXT");
		if(f==0){
			break;
		}
		for(y=0;y<strlen(b);y++){
			b[y]=tolower(b[y]);
		}
		int e=strcmp(a,b);
		if(e==0){
			x++;
		}
	}
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 552
#include<stdio.h>
int main(void)
{
	int A[100][100],b[100],m,n,c[100],i,j;
	scanf("%d",&m); scanf("%d",&n);
	for(i=0;i<m;i++){
		for(j=0;j<n;j++){
			scanf("%d",&A[i][j]);
		}
	}
	for(j=0;j<n;j++)
		scanf("%d",&b[j]);
	for(i=0;i<m;i++){
		c[i] = 0;
		for(j=0;j<n;j++){
			c[i] = c[i] +A[i][j]*b[j];
		}
		printf("%d\n",c[i]);
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

const int dx[6] = {1, 0, 0, -1, 0, 0};
const int dy[6] = {0, 1, 0, 0, -1, 0};
const int dz[6] = {0, 0, 1, 0, 0, -1};
ll A, B, C, N;
map<int, map<int, map<int, int>>> used;

bool contain(int x, int y, int z) {
  return x >= 0 && x < A && y >= 0 && y < B && z >= 0 && z < C;
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> A >> B >> C >> N;
  ll ans = 2 * (A * B + B * C + C * A);
  for (int i = 0; i < N; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    used[x][y][z] = 1;
    for (int j = 0; j < 6; j++) {
      int nx = x + dx[j];
      int ny = y + dy[j];
      int nz = z + dz[j];
      if (!contain(nx, ny, nz) || used[nx][ny][nz]) {
        ans--;
      } else {
        ans++;
      }
    }
  }  
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 4252
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main(){
    string x,y="CODEFESTIVAL2016";
    ll z=0;
    cin >> x;
    for (ll i=0;i<x.size();++i){
        if (x[i]!=y[i]){
            ++z;
        }
    }
    cout << z << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

array<int,10000> A;
array<int,10000> B;

int main(){ _;
  int n,m,l;cin>>n>>m>>l;
  REP(i,n*m)
    cin>>A[i];
  REP(i,m*l)
    cin>>B[i];
  REP(i,n){
    REP(k,l){
      long long sum=0;
      REP(j,m){
	sum+=A[i*m+j]*B[j*l+k];
      }
      cout<<sum<<(k+1==l?"\n":" ");
    }
  }
}

Measured memory_bytes: 1276
#include<stdio.h>
#include<string.h>
#include<math.h>

int ddd(const void* a, const void* b)
{
	return *(int*)a - *(int*)b;
}

int main(void) {
	int n;
	int a[200110];

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	qsort(a, n, sizeof(int), ddd);

	for (int i = 0; i < n; i++) {
		if (a[i] == a[i + 1]) {
			printf("NO");
			return 0;
		}
	}
	printf("YES");
	return 0;
}

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

using namespace std;
using llong = long long;
using P = pair<llong, llong>;

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

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

int main(){
	int N, M, C;
	vector<int> B;

	cin >> N >> M >> C;
	B.resize(M);
	for(int i = 0; i < M; i++)
		cin >> B[i];

	llong ans = 0;
	for(int i = 0; i < N; i++){
		llong res = C;
		llong in;
		for(int j = 0; j < M; j++){
			cin >> in;
			res += in*B[j];
		}
		// cerr << res << endl;
		if(res > 0)
			ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
#define LL long long

LL N,M,K,ans,r;
LL a, b;
string s;
LL con[1001];
bool sosu[1001];
int main() {
	LL sx, sy, tx, ty;
	cin >> sx>>sy>>tx>>ty;
	for (int i = 0; i < -sx + tx; i++) {
		cout << 'R';
	}
	for (int i = 0; i < -sy + ty; i++) {
		cout << 'U';
	}

	for (int i = 0; i < -sx + tx; i++) {
		cout << 'L';
	}
	for (int i = 0; i < -sy + ty; i++) {
		cout << 'D';
	}

	cout << 'D';
	for (int i = 0; i < -sx + tx+1; i++) {
		cout << 'R';
	}
	for (int i = 0; i < -sy + ty+1; i++) {
		cout << 'U';
	}
	cout << 'L';

	cout << 'U';
	for (int i = 0; i < -sx + tx+1; i++) {
		cout << 'L';
	}
	for (int i = 0; i < -sy + ty+1; i++) {
		cout << 'D';
	}
	cout << 'R';

	return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
using namespace std;
using ll = long long;
#define rep(i,a,b) for(int i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
 
int main() {
    int n,k;
    cin >> n >> k;
    vector <int> p(n);
    for(int i =0;i<n;i++) {
        cin >> p[i];
    }
    sort(p.begin(), p.end());
    int ans =0;
    for (int i = 0; i < k;i++) {
        ans += p[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3164
#include <cstdio>
#include <random>
#include <cassert>
#include <algorithm>    
#include <iostream>
#include <chrono>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#include <bitset>
#define pb push_back
#define mk make_pair
#define eb emplace_back
#define eps 1e-8
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
// #define int long long


using namespace std;
typedef long double ld;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef tuple<int, int, int> tiii;
typedef vector<int> vii;
typedef vector<long double> vd;
const int inf = 1e9;
const long long INF = 1e18;
const int M = 1e9 + 7;

int n, m, q;
int a[55], b[55], c[55], d[55];
int res = 0;
int t[20];
void dfs(int len) {
	for(int i = t[len - 1]; i <= m; ++i) {
		t[len] = i;
		int tot = 0;
		for(int j = 0; j < q; ++j) {
			if(b[j] <= len && t[b[j]] - t[a[j]] == c[j]) {
				tot += d[j];
			}
		}
		res = max(res, tot);
		if(len < n) dfs(len + 1);
	}
}


signed main()
{
#ifndef ONLINE_JUDGE
	// freopen("out.txt", "w", stdout);
#endif
	cin >> n >> m >> q;
	for(int i = 0; i < q; ++i) {
		cin >> a[i] >> b[i] >> c[i] >> d[i];
		// cout << a[i] << ' ' << b[i] << endl;
		--a[i], --b[i];
	}
	t[0] = 1;
	dfs(1);
	cout << res << endl;




    
	return 0;
}

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

int main(){
	long long n,a,b,x=0;
	cin>>n>>a>>b;
	if(a==b) x=1;
	else if(a<b&&n!=1) x=(b-a)*(n-1)+a-b+1;
	cout<<x<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
//make_tuple emplace_back next_permutation push_back make_pair second first setprecision

#if MYDEBUG
#include "lib/cp_debug.h"
#else
#define DBG(...) ;
#endif

using LL = long long;
constexpr LL LINF=334ll<<53;
constexpr int INF=15<<26;
constexpr LL  MOD=1E9+7;

struct Problem{
    int n;
    map<int,int> m;
    Problem(LL n):n(n){};

    void solve(){
        for(int i=0; i<n; ++i){
            int tmp;
            cin >> tmp;
            m[tmp]++;
        }
        int ans=0;
        for(auto && x:m){
            if(x.second>=x.first)ans +=x.second-x.first;
            else ans+=x.second;
        }
        cout << ans <<"\n";


    }
};

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    long long n=0;
    cin >> n;
    Problem p(n);
    p.solve();
    return 0;
}



Measured memory_bytes: 4736
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
typedef long long ll;
typedef vector<int> vint;
#define rep(i,n) for (int i = 0; i < (ll)(n); ++i)
ll INF = 1LL << 60;
ll mod = 1e9 + 7;

int main() {
	int a,b,c,d; cin >> a >> b >> c >> d;
	if(d==1) cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
N, M = map(int, input().split())
F = [0, 1]
fib_minus1 = 1
fib_minus2 = 0
for i in range(N):
	fib = (fib_minus1 + fib_minus2) % mod
	F.append(fib)
	fib_minus2 = fib_minus1
	fib_minus1 = fib
x = 1
a = -1
for i in range(M):
	b = int(input())
	if b > a + 1:
		x = (x * F[b - a - 1]) % mod
		a = b
	elif b == a + 1:
		x = 0
x = (x * F[N - a]) % mod
print(x)

Measured memory_bytes: 7084
#include <stdio.h>
#define abs(x) ((x) > 0 ? (x) : -(x))

int
main(int argc, char *argv[])
{
  int n; float t, a, h[1000]; int ans = 0;
  scanf("%d", &n);
  scanf("%f %f", &t, &a);
  for(int i = 0; i < n; i++){
    scanf("%f", &h[i]);
    h[i] = abs(a - t + h[i] * 0.006);
    if(h[ans] > h[i]) ans = i;
  }
  printf("%d\n", ans + 1);
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define speed                   \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define ll long long
#define pb push_back
#define mem1(a) memset(a, -1, sizeof(a))
#define mem0(a) memset(a, 0, sizeof(a))
#define endl "\n"
#define mod1 1000000007
#define mod 998244353
#define ff first
#define ss second
#define MAX 500005
#define N 200005
#define INF 1000000009
#define all(v) v.begin(), v.end()
#define sbit(a) __builtin_popcount(a)
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef pair<ll, ll> pll;
typedef pair<pll, ll> ppl;
typedef map<ll, ll> mpll;
typedef map<vector<ll>, ll> mpvl;
ll power(ll x, ll y, ll p)
{
  ll 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()
{
  ll x;
  cin >> x;
  if (x)
    cout << 0 << endl;
  else
    cout << 1 << endl;
}

int main()
{
  speed;
  ll kk;
  kk = 1;
  //cin >> kk;
  while (kk--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3612
#include<stdio.h>
int main(){
  int a,b,c,temp;
  scanf("%d %d %d",&a,&b,&c);
  if(a>b){
    temp = a;
    a = b;
    b = temp;
  }
  if(b>c){
    temp = b;
    b = c;
    c = temp;
  }
  if(a>b){
    temp = a;
    a = b;
    b = temp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
a=gets.to_i
b=a.times.map{gets.chomp.to_s}
d=1
stock="aa"
for c in b do
    if d !=1 && c[0]!=stock[-1]
        puts "No"
        exit
    end
    stock=c
    d +=1
end

if b.length == b.uniq.length then
    puts "Yes"
else
    puts "No"
end

Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int n,a,b,c,d;
  cin >> n >> a >> b >> c >> d;
  int ret = 500;
  for(int i=1; i <= n; i++){
    int ax = (a-1)%i, ay = (a-1)/i;
    int bx = (b-1)%i, by = (b-1)/i;
    int cx = (c-1)%i, cy = (c-1)/i;
    int dx = (d-1)%i, dy = (d-1)/i;
    int d1 = abs(ax - bx) + abs(ay - by);
    int d2 = abs(cx - dx) + abs(cy - dy);
    ret = min(ret, d1+d2);
  }
  cout << ret << endl;
  return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define MAX 100

int pop();
void push();

char S[MAX];
int stack_size = 0, A[MAX];

int main()
{
  int i, a, b, x;
  
  while(scanf("%s",S)!=EOF){
    if(S[0]=='+'){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(S[0]=='-'){
      a = pop();
      b = pop();
      push(b-a);
    }
    else if(S[0]=='*') {
      a = pop();
      b = pop();
      push(a*b);
    }
    else{
      x = atoi(S);
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}

int pop(void)
{
  stack_size--;
  return A[stack_size+1];
}

void push(int a)
{
  A[++stack_size] = a;
}

Measured memory_bytes: 548
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    int n;
    cin >> n;
    while(n-- > 0){
        double xa, ya, ra, xb, yb, rb;
        cin >> xa >> ya >> ra >> xb >> yb >> rb;
        double len = sqrt(pow(xa-xb, 2.0) + pow(ya-yb, 2.0));

        if(len > ra + rb)
            cout << 0 << endl;
        else if(len >= abs(ra - rb))
            cout << 1 << endl;
        else if(ra > rb)
            cout << 2 << endl;
        else
            cout << -2 << endl;
    }
    return 0;
}

Measured memory_bytes: 0
C = input()
a = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
for i in range(len(a)-1):
    if C == a[i]:
        print(a[i+1])
        break
    else:
        pass

Measured memory_bytes: 3060
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
const int MOD=1e9+7;

vector<int> deduplicate(vector<int> a) {
    sort(a.begin(),a.end());
    auto itr=unique(a.begin(),a.end());
    a.resize(itr-a.begin());
    return a;
}

int main() {
    int x,y,z;
    cin >> x >> y >> z;
    swap(x,y);
    swap(x,z);
    cout << x << ' ' << y << ' ' << z << endl; 
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
#ifdef __LOCAL
#define debug(x) cerr << __LINE__ << ": " << #x << " = " << x << endl
#define debugArray(x, n)                           \
  cerr << __LINE__ << ": " << #x << " = {";        \
  for (long long hoge = 0; (hoge) < (n); ++(hoge)) \
    cerr << ((hoge) ? "," : "") << x[hoge];        \
  cerr << "}" << endl
#else
#define debug(x) (void(0))
#define debugArray(x, n) (void(0))
#endif

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;
  cin >> N;
  vector<vector<int>> graph(N);
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  int par[N];
  function<void(int, int)> dfs = [&](int v, int p) {
    par[v] = p;
    for (int u : graph[v])
      if (u != p) dfs(u, v);
  };
  dfs(0, -1);
  int M;
  cin >> M;
  long long cond[M];
  fill(cond, cond + M, 0);
  for (int i = 0; i < M; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    for (; u != -1; u = par[u]) cond[i] ^= 1ll << u;
    for (; v != -1; v = par[v]) cond[i] ^= 1ll << v;
  }
  long long ans = 0;
  for (int s = 0; s < (1 << M); s++) {
    int sgn = (__builtin_popcount(s) & 1) ? -1 : 1;
    long long t = 0;
    for (int i = 0; i < M; i++)
      if ((s >> i) & 1) {
        t |= cond[i];
      }
    int cnt = __builtin_popcountll(t);
    ans += (1ll << (N - 1 - cnt)) * sgn;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int Q = Integer.parseInt(sc.next())	;
        StringBuilder str = new StringBuilder(S);
        StringBuilder left = new StringBuilder();
        StringBuilder right = new StringBuilder();

        boolean reverse = false;
        for (int i = 0; i < Q; i++) {
            int T = sc.nextInt();
            reverse = T == 1 ? !reverse : reverse;
            if (T == 1) {
                continue;
            }
            int F = Integer.parseInt(sc.next())	;
            char C = sc.next().charAt(0);
            if (F == 1) {
                if (reverse) {
                    right.append(C);
                    continue;
                }

                left.insert(0, C);
                continue;
            }
            if (reverse) {
                left.insert(0, C);
                continue;
            }
            right.append(C);
        }
        System.out.println(reverse ? str.append(right).insert(0,left).reverse(): str.append(right).insert(0,left));
    }
}

Measured memory_bytes: 94240
#include <cstdio>
#include <cstring>
#include <cctype>
#include <cmath>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long LL;
const int INF=2e9+1e8;

const int MOD=1e9+7;
const double eps=0.0000000001;
void fre()
{
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
}
#define MSET(a,b) memset(a,b,sizeof(a))
const int maxn=1e5+100;
struct Node 
{
    int to,next;
}edge[maxn*2];
int first[maxn],sz;
void init()
{
    sz=0;
	memset(first,-1,sizeof(first));
}
void add(int s,int t)
{
    edge[sz].to=t;edge[sz].next=first[s];
	first[s]=sz++;
}
int dis[maxn],tot;
void dfs(int x,int pre,int deep)
{
    dis[x]=deep;
	//printf("dis[%d]=%d\n",x,dis[x]);
	for(int i=first[x];i!=-1;i=edge[i].next)
	{
	    int to=edge[i].to;
		if(to==pre) continue;
		dfs(to,x,deep+1);
	}
}
void F(int x,int pre,int deep)
{
    if(deep<=dis[x]) tot++;
	//printf("F dis[%d]=%d\n",x,deep);
	for(int i=first[x];i!=-1;i=edge[i].next)
	{
	    int to=edge[i].to;
		if(to==pre) continue;
		F(to,x,deep+1);
	}
}



int main()
{
	init();
	tot=0;
	int n;
	scanf("%d",&n);
	for(int i=2;i<=n;i++)
	{
	    int x,y;
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
	}
	dfs(n,n,0);
	F(1,1,0);
	//printf("tot=%d\n",tot);
	if(tot>(n-tot)) printf("Fennec\n");
	else printf("Snuke\n");
    return 0;
}


/**************************************************/
/**             Copyright Notice                 **/
/**  writer: wurong                              **/
/**  school: nyist                               **/
/**  blog  : http://blog.csdn.net/wr_technology  **/
/**************************************************/


Measured memory_bytes: 7296
NN =input().split()
a = int(NN[0])
b = int(NN[1])
c = int(NN[2])
d = int(NN[3])
list1=[a,b,c,d]
list1.sort()
ans = list1[2] -list1[1]
if b < c or d < a:
  print(0)
else:
  print(ans)

Measured memory_bytes: 9108
s = input()
l = len(s)
MOD = 10**9+7
dp = [[0]*13 for _ in range(100005)]
dp[0][0] = 1
for i in range(l):

    c = -1 if s[i] == '?' else int(s[i])
    for j in range(10):
        if c != -1 and c != j:
            continue
        for r in range(13):
            dp[i+1][(10*r+j)%13] += dp[i][r]
    for k in range(13):
        dp[i+1][k] %= MOD
print(dp[l][5])

Measured memory_bytes: 62172