akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(1e5 + 5);

int n;
ll c;

ll x[MAX_N], v[MAX_N];
ll acc_v[MAX_N];
ll fwd[MAX_N], bwd[MAX_N];

ll ans;

void prepare() {
  for (int i = 1; i <= n; ++i) {
    acc_v[i] = v[i] + acc_v[i - 1];
  }

  for (int i = 1; i <= n; ++i) {
    fwd[i] = -1LL;
    bwd[i] = -1LL;
  }

  // clock forward
  fwd[0] = 0LL;

  for (int i = 1; i <= n; ++i) {
    ll cur = acc_v[i] - x[i];
    fwd[i] = max(fwd[i], cur);
    fwd[i] = max(fwd[i - 1], fwd[i]);
  }

  // clock backward
  bwd[0] = 0LL;

  for (int i = n; i >= 1; --i) {
    ll cur = (acc_v[n] - acc_v[i - 1]) - (c - x[i]);

    int last_ind = (i == n) ? 0 : i + 1;

    bwd[i] = max(bwd[i], cur);
    bwd[i] = max(bwd[last_ind], bwd[i]);
  }
}

int main(void) {
  // Here your code !
  scanf("%d %lld", &n, &c);

  for (int i = 1; i <= n; ++i) {
    scanf("%lld %lld", &(x[i]), &(v[i]));
  }

  prepare();

  ans = -1LL;

  ans = max(ans, fwd[n]);  // only forward
  ans = max(ans, bwd[1]);  // only backward

  // clock forward
  for (int i = 1; i <= n; ++i) {
    ll fst_cost = x[i] * 2;
    ll fst_gain = acc_v[i];

    int opposite_ind = (i == n) ? 0 : i + 1;

    ll cur = fst_gain - fst_cost + bwd[opposite_ind];

    ans = max(ans, cur);
  }

  // clock backward
  for (int i = n; i >= 1; --i) {
    ll fst_cost = (c - x[i]) * 2;
    ll fst_gain = (acc_v[n] - acc_v[i - 1]);

    int opposite_ind = i - 1;

    ll cur = fst_gain - fst_cost + fwd[opposite_ind];

    ans = max(ans, cur);
  }

  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 4096
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(void)
{
	int a,s=0,d=0,f,g,h,j,i;
	char z[101];
	scanf("%d",&a);
	scanf("%s",z);
	for(i=0;i<a;i++){
		if(z[i]=='('){
			d++;
		}
		if(z[i]==')'){
			s++;
			if(d==0){
				printf("(");
				d++;
			}
			d--;
		}
	}
	printf("%s",z);
	for(i=0;i<d;i++) printf(")");
	printf("\n");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(int i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(int i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define uniq(x) (x).erase(unique((x).begin(), (x).end()), (x).end())

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    vector<pair<int, int>> b(n);
    
    rep(i, n) {
        int a;
        cin >> a;
        b[i].first = a;
        b[i].second = i + 1;
    }
    
    sort(all(b));
    
    rep(i, n) {
        cout << b[i].second << endl;
    }
    
    
    return 0;
}

Measured memory_bytes: 1664
n = int(input())
s = input()

max_score = 0
for cut in range(1, n-2):
    bh = set(s[:cut])
    lh = set(s[cut:])
    cscore = len(bh.intersection(lh))
    if max_score < cscore:
        max_score = cscore

print(max_score)

Measured memory_bytes: 3060
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn get_msd(n: u64) -> u64{
    return n.to_string().chars().nth(0).unwrap().to_digit(10).unwrap() as u64;
}

fn is_almost9(n: u64) -> bool{
    let mut n: u64 = n;

    while n/10 > 0{
        if n%10 != 9{
            return false;
        }
        n /= 10;
    }

    return true;
}

fn num_digits(n: u64) -> u64{
    let mut n = n;
    let mut ans = 0;
    while n > 0{
        n /= 10;
        ans += 1;
    }

    return ans;
}

fn main(){
    let n = read_as_vec::<u64>()[0];
    let k = num_digits(n);
    let c = get_msd(n);
    if is_almost9(n){
        println!("{}", c+9*(k-1));
    }else{
        println!("{}", c+9*(k-1)-1);
    }
}


Measured memory_bytes: 4352
N = int(input())
M = int(input())
A = list(map(int, input().split()))
p = [0] * N
for i in range(M):
    for bi, b in enumerate(map(int, input().split())):
        if b == A[i]:
            p[bi] += 1
        else:
            p[A[i] - 1] += 1
print('\n'.join(map(str, p)))

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

int main(void){
    int n, w;
    cin >> n >> w;
    int value[110], weight[110];

    for(int i = 0 ; i < n; i++){
        cin >> value[i] >> weight[i];
    }
    
    int dp[110][10010];
    
    //?????????
    for(int i = 0; i < n; i++){
        dp[i][0] = 0;
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 1; j <= w; j++){
            if(i == 0){
                if(j - weight[i] >= 0){
                    dp[i][j] = dp[i][j-weight[i]] + value[i];
                }else{
                    dp[i][j] = 0;
                }
            }else{
                if(j - weight[i] >= 0){
                    dp[i][j] = max(dp[i-1][j], dp[i][j-weight[i]] + value[i]);
                }
                else{
                    dp[i][j] = dp[i-1][j];
                }
            }
        }
    }

   cout << dp[n-1][w] << endl;
    
    return 0;

}

Measured memory_bytes: 6980
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define f first
#define s second
#define MOD 1000000007
 
using namespace std;


int fr[200001];

void solve(){

	int n; cin>>n;
	for(int i=0; i<n-1; i++){
		
		int x; cin>>x;
		fr[x] += 1;

	}
	for(int i=1; i<=n; i++){
		cout<<fr[i]<<"\n";
	}


}





int main()
{ 
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//cout<<fixed<<setprecision(12);
	//memset(dp,-1,sizeof(dp));
	
	int t =1; 
	//cin>>t;



	for(int i=1; i<=t; i++){
		solve();
		cout<<"\n";
	}

	return 0;

}




Measured memory_bytes: 4388
#include<stdio.h>
#include<string.h>
	int func(char s[]){
		int h=strlen(s),i=0,j;
		j=h-1;
		while(s[i]==s[j]){
			i++;
			j--;
			if(i>j)
				break;
		}
		if(h%2==1&&i==h/2+1)
			return 1;
		else if(h%2==0&&i==h/2)
			return 1;
		else return 0;
}
	int main(){
		int x,k=0;
	char s[1000];
	while(scanf("%s",s)!=EOF){
		if(func(s))
			k++;
	}
	printf("%d\n",k);
	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
#define debug(x) cerr << #x << ": " << x << endl
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2018/10/06  Problem: abc112 D / Link: __CONTEST_URL__  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

VL f(LL n) {
	VL res;
	for (LL i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			res.push_back(i);
			if (n / i != i)res.push_back(n / i);
		}
	}
	SORT(res);
	return res;
}

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

	// (N+K)G=M ,(K≧0) M%G==0
	LL N, M; cin >> N >> M;
	VL divs = f(M);
	LL ans = 0;
	FOR(i, 0, SZ(divs)) {
		LL x = M / divs[i];
		if (x >= N) {
			ans = max(ans, divs[i]);
		}
	}
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
# 桁DPの練習にきました

n = input()
k = int(input())

dp = {}


def rec(i, smaller, count):
    if (i, smaller, count) in dp:
        return dp[(i, smaller, count)]
    if i == len(n):
        dp[(i, smaller, count)] = 1 if count == k else 0
        return dp[(i, smaller, count)]
    ret = 0
    upper = 10 if smaller else int(n[i]) + 1
    for j in range(upper):
        ret += rec(
            i + 1,
            True if smaller or j < int(n[i]) else False,
            count + 1 if 0 < j else count,
        )
    dp[(i, smaller, count)] = ret
    return ret


print(rec(0, False, 0))


Measured memory_bytes: 3768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Threading;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var h = Console.ReadLine()
            .Split(' ').Select(x => long.Parse(x)).ToArray();
        long max = h[0];
        for (var i = 1; n > i; i++)
        {
            if (h[i] > max)
            {
                max = h[i];
            }
            if (max - h[i] >= 2)
            {
                Console.WriteLine("No");
                return;
            }
        }
        Console.WriteLine("Yes");
    }
}

Measured memory_bytes: 39536
// #include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<queue>
#define PI 3.14159265358979323846264338327950288
#define rep(i,n) for(int i=0;i<n;i++)
#define exf(x)	 for(auto&& tmp : x) { cout << tmp << endl; }	// 拡張for
#define testP	 cout << "------------------ test ------------------" << endl;	// 動作確認テスト
#define testX(x) cout << "testout : " << x << endl;	// テストアウト
typedef long long ll;
using namespace std;
const int MOD{ int(1e9 + 7) };	// = 1000000007
const int inf{ 2100000000 };	// = 2100000000 (MAX:2147483647)

// ------------------ ベクター表示 ------------------ //
void printVec(vector<int>& vec) {
	cout << "";
	for (auto it = vec.begin(); it != vec.end(); it++) cout << *it << " ";
	cout << endl;
}

// ------------------ ベクター合計 ------------------ //
int sumVec(vector<int> v) {
	int sum = 0;
	for (size_t i = 0; i < v.size(); i++) sum += v[i];
	return sum;
}

// -------------------------------------------------- //
// ------------------ ここから本編 ------------------ //
// -------------------------------------------------- //

int main(void) {

	int H, W;
	cin >> H >> W;

	static char maze[50][50];
	fill(maze[0], maze[50], '-');
	int white = 0;
	rep(i, H) {
		rep(j, W) {
			cin >> maze[i][j];
			if (maze[i][j] == '.') white++;
		}
	}

	// ----------------------
	
	int dx[4] = { 1,0,-1,0 },
		dy[4] = { 0,1,0,-1 };
	int cnt[50][50] = { 0 };

	queue<pair<int, int>> que;
	que.push(make_pair(0, 0));

	while (!que.empty()) {
		pair<int,int> tmp = que.front();
		que.pop();

		rep(n, 4) {
			int nextY = tmp.first + dy[n],
				nextX = tmp.second + dx[n];

			if (nextY < 0 || nextY >= H || nextX < 0 || nextX >= W) continue;
			if (maze[nextY][nextX] == '#') continue;
			if (cnt[nextY][nextX] != 0) continue;
			
			cnt[nextY][nextX] = cnt[tmp.first][tmp.second] + 1;
			que.push(make_pair(nextY, nextX));
		}

	}

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

	if (cnt[H - 1][W - 1] == 0) cout << "-1" << endl;
	else cout << white - (cnt[H - 1][W - 1] + 1) << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int n;
string s;
int num_of_cards[16];
int trush;

int main()
{
    while (cin >> n, n != 0) {
        trush = 0;
        for (auto &i: num_of_cards) i = 0;
        
        cin >> s;

        for (int i = 0; i < s.size(); i++) {
            int idx = i % n;

            if (s[i] == 'M') {
                num_of_cards[idx]++;
            }
            else if (s[i] == 'L') {
                num_of_cards[idx] += trush + 1;
                trush = 0;
            }
            else if (s[i] == 'S') {
                trush += num_of_cards[idx] + 1;
                num_of_cards[idx] = 0;
            }
        }

        sort(num_of_cards, num_of_cards + n);
        for (int i = 0; i < n; i++) {
            printf("%d ", num_of_cards[i]);
        }
        printf("%d\n", trush);
    }

    return 0;
}



Measured memory_bytes: 3332
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl "\n"
#define mod 1000000007
vector<int>adj[200002];
vector<int>temp;
int dp[101][100001];
int power(int x,int y)
{ int temp;
  if(y==0)
    return 1;
  temp=power(x,y/2)%mod;
  if(y%2==0)
    return (temp%mod*temp%mod)%mod;
  else
    return ((x%mod)*((temp%mod*temp%mod)%mod))%mod;
}
int check(vector<int>&a,vector<int>&b,int s,int n)
{
  if(n<=0 || s==0)
    return 0;
  if(dp[n][s]!=-1)
    return dp[n][s];
  if(a[n-1]<=s)
    return dp[n][s]=max(check(a,b,s-a[n-1],n-1)+b[n-1],check(a,b,s,n-1));
  else
    return dp[n][s]=check(a,b,s,n-1);
}
void solve()
{ int n,w;
  cin>>n>>w;
  vector<int>a(n+1),b(n+1);
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    cin>>b[i];
  }
  for(int i=0;i<=100;i++)
  { for(int j=0;j<=w;j++)
      dp[i][j]=-1;

  }
  int k=check(a,b,w,n);
  cout<<k<<endl;

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

  int t;
  //cin>>t;
  t=1;
  for(int i=1;i<=t;i++)
    {solve();
    }



    return 0;     

  }

Measured memory_bytes: 87220
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream> 
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include<fstream>
#include <unordered_map>  
using namespace std;
#define eps 0.00000001
#define LONG_INF 10000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define f(n) for(int i=0;i<n;++i)
#define REP(i,n) for(long long i = 0;i < n;++i)
int geko[2000][2000] = {};
int main(){
	int c,n;
	cin >> c >> n;
	REP(i,n){
		string s;
		cin >> s;
		REP(q,n){
			geko[i][q] = s[q]-'0';
		}
	}
	int ans = 0;
	int now_bad = 0;
	for(int i = 0;i < n;++i){
		for(int q = 0;q < n;++q){
			if(geko[i][q] != geko[i][n-q-1]||geko[i][q] != geko[n-i-1][q]||geko[i][q] != geko[n-i-1][n-q-1]){
				now_bad++;
			}
		}
	}
	now_bad /= 4;
	if(now_bad == 0) ans++;
	for(int i =0;i < c-1;++i){
		int a;
		cin >> a;
		for(int q = 0;q < a;++q){
			int aa,ab;
			cin >>aa >> ab;
			aa--;
			ab--;
			if(geko[aa][ab] != geko[aa][n-ab-1]||geko[aa][ab] != geko[n-aa-1][ab]||geko[aa][ab] != geko[n-aa-1][n-ab-1]){
				geko[aa][ab] = (geko[aa][ab]+1)%2;
				if(geko[aa][ab] == geko[aa][n-ab-1]&&geko[aa][ab] == geko[n-aa-1][ab]&&geko[aa][ab] == geko[n-aa-1][n-ab-1])now_bad--;
			}else{
				geko[aa][ab] = (geko[aa][ab]+1)%2;
				now_bad++;
			}
		}
		if(now_bad == 0) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 11040
h = [list(map(int,input().split())) for i in range(3)]
a = []
for i in h:
  a.append(i[0])
  a.append(i[1])
  a.append(i[2])
b = [0 for i in range(9)]
for i in range(int(input())):
  n = int(input())
  if n in a:
    b[a.index(n)] = 1
if b[0]==b[1]==b[2]==1 or b[3]==b[4]==b[5]==1 or b[6]==b[7]==b[8]==1 or b[0]==b[3]==b[6]==1 or b[1]==b[4]==b[7]==1 or b[2]==b[5]==b[8]==1 or b[0]==b[4]==b[8]==1 or b[2]==b[4]==b[6]==1:
  print("Yes")
else:
  print("No")


Measured memory_bytes: 3064
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int k = sc.nextInt();
		long ans = 0l;
		for(int i = 1; i <= k; i++) {
			for(int j = 1; j <= k; j++) {
				for(int l = 1; l <= k; l++) {
					int x = gcd3(i, j ,l);
					ans += x;
				}
			}
		}
		System.out.println(ans);
	}

	public static int gcd2(int num1, int num2) {
		if(num1 < num2) return gcd2(num2, num1);
		if(num2 == 0) return num1;
		else return gcd2(num2, num1%num2);
	}

	public static int gcd3(int num1, int num2,int num3) {
		int num12 = gcd2(num1, num2);
		return gcd2(num12, num3);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

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

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 32732
# -*- coding: utf-8 -*-

s = str(input())
t = str(input())

a=int(1)

for i in range(len(s)+1):
    if s==t:
        print('Yes')
        a=0
        break
    else :
        s = s[-1] + s[0:len(s) - 1]

if a==1:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <map>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;
using ll = long long;
using ld = long double;

int H, W;
vector<string> S;
vector<vector<bool>> Used;
ll writeCount;
ll blackCount;

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

void checkAround(int x, int y) {
    if (Used[x][y]) {
        return;
    }
    Used[x][y] = true;

    if (S[x][y] == '.') {
        writeCount++;
    }
    else {
        blackCount++;
    }

    for (int i = 0; i < 4; ++i) {
        int nx = x + dx[i];
        int ny = y + dy[i];

        if (nx < 0 || nx >= H || ny < 0 || ny >= W) {
            continue;
        }
        if (S[x][y] == S[nx][ny]) {
            continue;
        }
        checkAround(nx, ny);

    }
}

int main() {
    cin >> H >> W;

    for (int i = 0; i < H; ++i) {
        vector<bool> us;
        for (int j = 0; j < W; ++j) {
            us.push_back(false);
        }
        Used.push_back(us);
    }

    for (int i = 0; i < H; ++i) {
        string S2;
        cin >> S2;
        S.push_back(S2);
    }


    ll result = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            if (Used[i][j]) {
                continue;
            }
            writeCount = 0;
            blackCount = 0;
            checkAround(i, j);
            result += writeCount * blackCount;


        }
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 18048
#include<iostream>
using namespace std;
int main(){
	string a,b;
	cin>>a>>b;
	if(a.length()+1!=b.length()){
		cout<<"No";
		return 0;
	}
	for(int i=0;i<a.length();i++){
		if(a[i]!=b[i]){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
} 

Measured memory_bytes: 3628
import sys
import math
from fractions import gcd
from copy import deepcopy
from collections import deque, defaultdict
from operator import mul
from functools import reduce
sys.setrecursionlimit(20000000)

# input = sys.stdin.readline


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


def check(n, ans):
    for v in n:
        if v in ans and v != 1:
            return False

    return True


def main():
    a, b = map(int, input().split())

    ans = []

    nums = make_divisors(gcd(a, b))
    nums.sort()

    for n in nums:
        if check(make_divisors(n), ans):
            ans.append(n)

    print(len(ans))


if __name__ == '__main__':
    main()

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

int main(){
  long long int x,y;
  
  cin >> x >> y;
  if(x<y){
    x^=y; y^=x; x^=y;
  }
  while(x%y!=0){
    long long int r;
    r = x%y;
    x = y;
    y = r;
  }
  cout << y << endl;
}


Measured memory_bytes: 3136
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;
using ll = long long;
using pii = pair<int, int>;

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

	string s;
	cin >> s;
	if (s == "hi" || s == "hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi")
		puts("Yes");
	else
		puts("No");
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main(){
	int N;
  	cin>>N;
	string s;
  	cin>>s;
  	int x=0,maxX=0;
  	for(int i=0;i<s.size();++i){
    	if(s[i]=='I')++x;
      	else --x;
    	maxX=max(maxX,x);
    }
  	cout<<maxX<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>

double circleArea(double r) {
	return M_PI*pow(r,2);
}

double circleCircum(double r) {
	return 2*M_PI*r;
}


int main()
{
	double r;
	std::cin >> r;
	
	std::cout << std::setprecision(6) << std::fixed << circleArea(r) << " " << circleCircum(r) << "\n";
	
    return 0;
}




Measured memory_bytes: 3244
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007


int main() {
  
  int N,M;
  cin >> N >> M;

  vector<bool> vec(N+1,false);
  for(int i = 0;i < M;i++) {
    int a;
    cin >> a;
    vec.at(a) = true;
  }

  long long dp[N+1] = {0};
  dp[0] = 1;
  if(!vec.at(1))dp[1] = 1;
  
  for(int i = 2;i <= N;i++) {
    dp[i] = (dp[i-1] + dp[i-2]) % MOD;
    if(vec.at(i)) dp[i] = 0;
  }

  cout << dp[N] << endl;
  



}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>

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

using namespace std;

int main()
{
	int n;
	string s[256];
	while(cin >> n && n)
	{
		rep(i,n)
		{
			cin >> s[i];
		}

		int len = 0;
		int ans = 0;

		rep(i,n)
		{
			bool flag = false;
			len = 0;
			rep(j,n)
			{
				if(s[i][j] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;	
				}
				else 
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}

		rep(i,n)
		{
			len = 0;
			bool flag = false;
			rep(j,n)
			{
				if(s[j][i] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;	
				}
				else 
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}

		rep(i,n)
		{
			bool flag =false;
			len = 0;
			rep(k,i+1)
			{
				if(s[k][i-k] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
			}
			ans = max(ans,len);
		}
		/*   //under  */
		for(int i=n-1;i>=0;i--)
		{
			bool flag = false;
			len = 0;
			int cnt = n-1;
			for(int j=i;j<n;j++)
			{
				if(s[j][cnt] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt--;
			}
			ans = max(ans,len);
		}
		/*  \\up */
		rep(i,n)
		{
			bool flag = false;
			len = 0;
			int cnt = 0;
			REP(j,i,n)
			{
				if(s[cnt][j] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt++;
			}
			ans = max(ans,len);
		}
		/*   \\under */
		for(int i=n-1;i>=0;i--)
		{
			bool flag = false;
			len = 0;
			int cnt = 0;
			for(int j=i;j<n;j++)
			{
				if(s[j][cnt] == '1')
				{
					if(!flag) flag = true;
					if(flag) len++;
				}
				else
				{
					ans = max(ans,len);
					len = 0;
					flag = false;
				}
				cnt++;
			}
			ans = max(ans,len);
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1296
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
 
public class Main {
    int count = 0;
     
    public static void main(String[] args) {
        Main main = new Main();
        main.solv();
    }
     
    private void solv() {
        Scanner input = new Scanner(System.in);
         
        int n = input.nextInt();
        int[] S = new int[n];
        for (int i = 0; i < n; i++) S[i] = input.nextInt();
         
        count = 0;
        mergeSort(S, 0, S.length);
        print(S);
        System.out.println(count);
    }
     
    private void merge(int[] A, int left, int mid, int right) {
        int n1 = mid - left;
        int n2 = right - mid;
        int[] L = new int[n1+1], R = new int[n2+1];
         
        for (int i = 0; i < n1; i++) {
            L[i] = A[left + i];
        }
        for (int i = 0; i < n2; i++) {
            R[i] = A[mid + i];
        }
        L[n1] = Integer.MAX_VALUE;
        R[n2] = Integer.MAX_VALUE;
         
        int i = 0, j = 0;
        for (int k = left; k < right; k++) {
            count++;
            if (L[i] <= R[j]) {
                A[k] = L[i++];
            } else {
                A[k] = R[j++];
            }
        }
    }
    private void mergeSort(int[] A, int left, int right) {
        if (left + 1 < right) {
            int mid = (left + right) / 2;
            mergeSort(A, left, mid);
            mergeSort(A, mid, right);
            merge(A, left, mid, right);
        }
    }
     
    private void print(Object[] xs) {
        StringBuilder sb = new StringBuilder();
        for (Object x : xs) sb.append(x.toString()).append(' ');
        System.out.println(sb.toString().trim());
    }
     
    private void print(int[] xs) {
        StringBuilder sb = new StringBuilder();
        for (int x : xs) sb.append(x).append(' ');
        System.out.println(sb.toString().trim());
    }
     
    private static class Scanner {
        BufferedReader r;
        StreamTokenizer st;
         
        public Scanner(InputStream in) {
            r = new BufferedReader(new InputStreamReader(in));
            st = new StreamTokenizer(r);
        }
         
        public String next() {
            nextToken();
            return st.sval;
        }
         
        public Integer nextInt() {
            nextToken();
            return (int)st.nval;
        }
         
        private int nextToken() {
            int token = st.TT_EOF;
            try {
                token = st.nextToken();
            } catch (IOException e) {
            }
            return token;
        }
    }
}

Measured memory_bytes: 94168
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
typedef long long int ll;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000001
using namespace std;

struct Info{
	double x,y;
};

struct Data{
	Data(double arg_distance,bool arg_is_under_ground){
		distance = arg_distance;
		is_under_ground = arg_is_under_ground;
	}
	bool operator<(const struct Data &arg) const{
		return distance > arg.distance;
	};

	double distance;
	bool is_under_ground;
};


int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}

Info calc(double x1,double y1,double x2,double y2,double x3,double y3,double x4,double y4){
	Info ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(x1 != x2){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}

double calc_dist(double x1,double y1,double x2,double y2){
	return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
}

void func(){

	double start_x,start_y,goal_x,goal_y;
	scanf("%lf %lf %lf %lf",&start_x,&start_y,&goal_x,&goal_y);

	int N;
	scanf("%d",&N);

	priority_queue<Data> Q;

	double x1,y1,x2,y2;
	int Owner,L;

	Info ret;
	double tmp_dist;

	for(int loop = 0; loop < N; loop++){
		scanf("%lf %lf %lf %lf %d %d",&x1,&y1,&x2,&y2,&Owner,&L);

		if(func(x1,y1,x2,y2,start_x,start_y)*func(x1,y1,x2,y2,goal_x,goal_y) <= 0 &&
				func(start_x,start_y,goal_x,goal_y,x1,y1) * func(start_x,start_y,goal_x,goal_y,x2,y2) <= 0){
			ret = calc(start_x,start_y,goal_x,goal_y,x1,y1,x2,y2);
			tmp_dist = calc_dist(start_x,start_y,ret.x,ret.y);
			if(Owner == 1){
				if(L == 1){
					Q.push(Data(tmp_dist,false));
				}else{
					Q.push(Data(tmp_dist,true));
				}
			}else{
				if(L == 1){
					Q.push(Data(tmp_dist,true));
				}else{
					Q.push(Data(tmp_dist,false));
				}
			}
		}
	}

	if(Q.empty()){
		printf("0\n");
		return;
	}

	bool under_ground = Q.top().is_under_ground;
	Q.pop();

	int ans = 0;

	while(!Q.empty()){
		if(under_ground == Q.top().is_under_ground){
			//Do nothing
		}else{
			ans++;
			under_ground = Q.top().is_under_ground;
		}
		Q.pop();
	}
	printf("%d\n",ans);
}

int main(){

	int num;
	scanf("%d",&num);

	for(int i = 0; i < num; i++)func();

	return 0;
}

Measured memory_bytes: 2640
class Heap
    attr_reader :size
    def initialize
        @heap = []
        @size = 0
    end

    def length
        @size
    end

    def push(x)
        i = @size
        @size += 1
        while i > 0 do
            p = (i - 1) / 2
            break if @heap[p] <= x
            @heap[i] = @heap[p]
            i = p
        end
        @heap[i] = x
        self
    end

    def pop
        return nil if @size == 0
        ret = @heap[0]
        @size -= 1
        x = @heap[@size]
        i = 0
        while i * 2 + 1 < @size do
            a = i * 2 + 1
            b = a + 1
            if b < @size && @heap[b] < @heap[a]
                a = b
            end
            break if @heap[a] >= x
            @heap[i] = @heap[a]
            i = a
        end
        @heap[i] = x
        @heap.pop
        return ret
    end
end

class Dpair
    attr_reader :dist, :vertex
    include Comparable
    def initialize(dist, vertex)
        @dist = dist
        @vertex = vertex
    end
    def <=>(other)
        @dist <=> other.dist
    end
end

# edges[src][dst] = cost
def dijkstra(start, n, edges)
    queue = Heap.new
    dist = Array.new(n+1, Float::INFINITY)
    prev = Array.new(n+1)
    dist[start] = 0
    queue.push(Dpair.new(0, start))
    while queue.size > 0 do
        dpair = queue.pop
        v = dpair.vertex
        next if dist[v] < dpair.dist
        edges[v].each do |dst, cost|
            if dist[dst] > dist[v] + cost
                dist[dst] = dist[v] + cost
                queue.push(Dpair.new(dist[dst], dst))
                prev[dst] = v
            end
        end
    end
    return dist, prev
end

def prev2path(start, goal, prev)
    path = [goal]
    pt = goal
    loop do
        break if pt == start
        pt = prev[pt]
        path.unshift(pt)
    end
    return path
end


N = gets.to_i
edges = Array.new(N){{}}
(N-1).times do |i|
    a, b, c = gets.split.map(&:to_i)
    edges[a-1][b-1] = c
    edges[b-1][a-1] = c
end

Q, K = gets.split.map(&:to_i)

dist, _ = dijkstra(K-1, N, edges)

Q.times do |i|
    x, y = gets.split.map(&:to_i)
    puts dist[x-1] + dist[y-1]
end

Measured memory_bytes: 46016
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <functional>
#include <numeric>
#include <set>
// #include <bits/stdc++.h>


using namespace std;
typedef long long li;

struct edge {
    li to;
    li c;
};


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

    li n, m;
    cin >> n >> m;
    vector<vector<edge>> g(n);
    for (int i = 0; i < m; ++i) {
        li x, y, c;
        cin >> x >> y >> c;
        x--; y--;

        g[x].push_back({y, c});
        g[y].push_back({x, c});
    }

    vector<li> as(n), bs(n), vis(n);
    queue<pair<li, li>> q;
    q.push(make_pair(0, -1));
    as[0] = 1;
    bs[0] = 0;
    vis[0] = 1;

    li lb = 1, ub = 1e9 + 7;
    while (not q.empty()) {
        const li pos = q.front().first;
        const li prev = q.front().second;
        q.pop();

        for (int i = 0; i < g[pos].size(); ++i) {
            const li next = g[pos][i].to;
            const li c = g[pos][i].c;

            if (next == prev) {
                continue;
            }

            if (vis[next]) {
                const li a = as[pos] + as[next];
                const li b = c - (bs[next] + bs[pos]);
                if (a == 0) {
                    if (b != 0) {
                        lb = 1e9 + 7;
                        ub = -1;
                    }
                } else {
                    if (b % 2 == 1) {
                        lb = 1e9 + 7;
                        ub = -1;
                    } else {
                        ub = min(ub, b / a);
                        lb = max(lb, b / a);
                    }
                }

            } else {
                as[next] = -as[pos];
                bs[next] = c - bs[pos];
                vis[next] = 1;
                q.emplace(next, pos);
                if (as[next] < 0) {
                    ub = min(ub, bs[next] - 1);
                } else {
                    lb = max(lb, -bs[next] + 1);
                }
            }
        }
    }

    cout << max(ub - lb + 1, 0LL) << endl;
    cerr << lb << " " << ub << endl;

    return 0;
}


Measured memory_bytes: 11248
#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int a, b, c;
  while (cin >> a >> b >> c, a) {
    double cheese = min({a * a + b * b, a * a + c * c, b * b + c * c});
    int m;
    cin >> m;
    for (int i = 0; i < m; ++i) {
      int r;
      cin >> r;
      cout << ((4 * r * r <= cheese) ? "NA" : "OK") << endl;
    }
  }
}


Measured memory_bytes: 3072
#include<iostream>
#include<vector>
using namespace std;
#define ll long long

int main(){
  ll H, W, D;
  cin >> H >> W >> D;
  ll N = H*W;

  vector<ll> X(N), Y(N);
  for(ll h=0; h<H; ++h)
  for(ll w=0; w<W; ++w){
    ll A;
    cin >> A;
    X[A-1] = w;
    Y[A-1] = h;
  }

  vector<ll> S(N);
  for(ll d=0; d<D; ++d) {
    S[d] = 0;
    for(ll k = d+D; k<N; k+=D) { S[k] = S[k-D] + abs(X[k]-X[k-D]) + abs(Y[k]-Y[k-D]);  }
  }

  ll Q, L, R;
  cin >> Q;
  for(ll q=0; q<Q; ++q){
    cin >> L >> R;
    cout << S[R-1]-S[L-1] << endl;
  }
  

  return 0;
}


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

int main(){
    int h,w;
    cin>>h>>w;
    char a[55][55];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int sum = 0;
            if(a[i][j]=='#') continue;
            for(int x=i-1;x<=i+1;x++){
                for(int y=j-1; y<=j+1; y++){
                    sum += (a[x][y]=='#');
                }
            }
            a[i][j]=sum+'0';
        }
    }
    
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout << a[i][j];
        }
        cout<<endl;
    }
    
}


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

using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	reverse(S.begin(), S.end());
	S.push_back('0');
	int N = S.size();
	int dp[2];
	dp[0] = 0;
	dp[1] = (int)1 << 60;
	for (int i = 0; i < N; i++) {
		int ndp[2];
		ndp[0] = ndp[1] = (int)1 << 60;
		for (int j = 0; j < 2; j++) {
			int val = S[i] - '0' + j;
			for (int k = 0; k < 2; k++) {
				int a = 0;
				if (k == 0) {
					if (val == 10) {
						a = 50;
					} else {
						a = val;
					}
				} else {
					a = 10 - val;
				}
				ndp[k] = min(ndp[k], dp[j] + a);
			}
		}
		swap(dp, ndp);
	}

	cout << min(dp[0], dp[1] + 1) << endl;
}

Measured memory_bytes: 1948
#include <bits/stdc++.h>
#define rep(i, n) for (ll(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()
#define print(x) cout << (x) << endl;

typedef long long ll;
const ll INF = 99999999999999;
const ll MOD = 1000000007;

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll lcm(ll number1, ll number2)
{
    return number1 * number2 / gcd(number1, number2);
}
template <class T>
bool contain(const std::string &s, const T &v)
{
    // contain(to_string(N), '3')
    return s.find(v) != std::string::npos;
}

int ctoi(char c)
{
    if (c >= '0' && c <= '9')
        return c - '0';
    return 0;
}
using namespace std;

void transpose(vector<vector<char>> &b)
{
    if (b.size() == 0)
        return;

    vector<vector<char>> trans_vec(b[0].size(), vector<char>());

    for (int i = 0; i < b.size(); i++)
    {
        for (int j = 0; j < b[i].size(); j++)
        {
            trans_vec[j].push_back(b[i][j]);
        }
    }

    b = trans_vec; // <--- reassign here
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a, b, ans = 0, kuti = 1;
    cin >> a >> b;

    while (true)
    {
        if (kuti >= b)
        {
            break;
        }
        ans++;
        kuti = kuti - 1 + a;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  
  int n,i;
  
  while(scanf("%d",&n),n){
      i=0;
      while(n!=1){
	  i++;
	  if(n%2==0)n=n/2;
	  else n=3*n+1;
	}
      printf("%d\n",i);
    }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e9;

int main()
{
    int a, b;
    cin >> a >> b;
    if((a * b) % 2 == 0)
        cout << "Even" << endl;
    else
        cout << "Odd" << endl;
    return 0;
}


Measured memory_bytes: 3636
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

typedef long long ll;
using namespace std;

int main()
{
	string str;
	getline(cin,str);
	for(int i=0;i<str.size();i++){
		if(str[i] == ' ' || str[i] == '.') continue;
		str[i] = toupper(str[i]);
	}

	cout << str << endl;	
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
struct node{
	int ba,value;
};
int main(){
  int n,q;
  cin>>n>>q;
  node a[200005];
  for(int i=0;i<200005;i++){
  	a[i].value=0;
  }
  int x,y,gen;
  for(int i=1;i<n;i++){
  	cin>>x>>y;
  	if(i==1) gen=x;
  	a[y].ba=x;
  }
//  for(int i=1;i<=n;i++){
//  	printf("%d ",a[i].ba);
//  }
//  printf("\n");
  while(q--){
  	cin>>x>>y;
  	a[x].value+=y;
  }
  int sum;
  printf("%d",a[1].value);
  for(int i=2;i<=n;i++){
  	sum=0;
  	int f=i;
  	a[i].value+=a[a[i].ba].value;
	printf(" %d",a[i].value);
  }
  return 0;
}

Measured memory_bytes: 3968
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * 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);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			String s = in.next();
			for(int i = 0; i < s.length(); i++) {
				if(i % 2 == 0) {
					out.print(s.charAt(i));
				}
			}
			out.println();
		}
	}

	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

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

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}

	}
}


Measured memory_bytes: 20308
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    int N;
    cin >> N;

    LL ans = 1;
    int m;
    cin >> m; //! A0
    for (int i = 1; i < N; ++i) {
        int A;
        cin >> A;
        if (A <= m) {
            ++ans;
        }
        m = min(A, m);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())

template <class T>
void cout_vec(const vector<T> &vec1){
  rep(i,len(vec1)){
    cout<<vec1[i]<<' ';
  }
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin>>n;
    vector<string> s(n);
    //vector<int> a,b;
    set<int> a,b,c;
    string ans;
    rep(i,n){
      cin>>s[i];
      bool flag=true;
      if(s[i][0]=='B' && s[i].back()=='A'){
        c.insert(i);
        flag=false;
      }else if(s[i].back()=='A'){
        flag=false;
        a.insert(i);
      }else if(s[i][0]=='B'){
        flag=false;
        b.insert(i);
      }
      if(flag) ans+=(s[i]);
    }
    if(!a.empty()){
      ans+=s[*begin(a)];
      a.erase(begin(a));
    }
    while(!c.empty()){
      ans+=s[*begin(c)];
      c.erase(begin(c));
    }
    while(!b.empty()){
      ans+=(s[*begin(b)]);
      b.erase(begin(b));
      if(!a.empty()){
        ans+=s[*begin(a)];
        a.erase(begin(a));
      }
      //cout<<a[i]<<' '<<b[i]<<endl;
      //cout<<s[a[i]]<<' '<<s[b[i]]<<endl;
    }
    while(!a.empty()){
      ans+=s[*begin(a)];
      a.erase(begin(a));
    }
    int cnt=0;
    rep(i,len(ans)){
      if(i+1<=len(ans)-1 && ans[i]=='A' && ans[i+1]=='B') cnt++;
    }
    //cout<<ans<<endl;
    cout<<cnt<<endl;
}

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

vector<int> p;

void solve(int a, int d, int n){
	int cnt = 0;
	for(int i=a; cnt<n; i+=d){
		if(i == 1) continue;
		bool f = true;
		for(int j=0; j<p.size()&&p[j]*p[j]<=i; ++j){
			if(i % p[j] == 0){
				f = false;
				break;
			}
		}
		if(f) ++cnt;
		if(cnt == n)
			cout << i << "\n";
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	for(int i=2; i<=1000000; ++i){
		bool f = true;
		for(int j=0; j<p.size()&&p[j]*p[j]<=i; ++j){
			if(i % p[j] == 0){
				f = false;
				break;
			}
		}
		if(f) p.push_back(i);
	}
	while(1){
		int a, d, n;
		cin >> a >> d >> n;
		if(a == 0 && d == 0 && n == 0)
			return 0;
		solve(a, d, n);
	}
}


Measured memory_bytes: 3292
def examC():
    ABC = LI(); ABC.sort()
    ans = (ABC[2]*2-ABC[1]-ABC[0]+1)//2 + (ABC[2]*2-ABC[1]-ABC[0])%2
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


Measured memory_bytes: 38256
n, q = map(int, input().split())
t = [input().split() for _ in range(n)]
a = []
for i in t:
    i[1] = int(i[1])
time = 0
while t:
    for i in t:
        if i[1] > q:
            time += q
            i[1] -= q
        else:
            time += i[1]
            i[1] = 0
            a.append([i[0], str(time)])
    t = [i for i in t if i[1] != 0]
for i in a:
    print(" ".join(i))



Measured memory_bytes: 22368
while True:
    n, a, b, c, x = map(int, input().split())
    if n == 0:
        break

    flame = 0
    first = True

    for y in list(map(int, input().split())):
        if not first:
            x = (a * x + b) % c
            flame += 1
        else:
            first = False

        while x != y and flame <= 10000:
                x = (a * x + b) % c
                flame += 1

    if flame > 10000:
        print(-1)
    else:
        print(flame)


Measured memory_bytes: 5612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
#define X first
#define Y second
#define PB push_back
#define eps 1e-9
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i=0; i<(int)(n); ++i)

const int maxn = 1e4+7;

inline int read() {
    int ret=0,c,f=1;
    for(c=getchar(); !(isdigit(c)||c=='-'); c=getchar());
    if(c=='-') f=-1,c=getchar();
    for(; isdigit(c); c=getchar()) ret=ret*10+c-'0';
    if(f<0) ret=-ret;
    return ret;
}

ll Xor(ll n)
{
    if(n%4==0)
    return n;
    if(n%4==1)
    return 1;
    if(n%4==2)
    return n+1;
    if(n%4==3)
    return 0;
}

int main() {
	
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);    
    // #ifndef ONLINE_JUDGE
    // freopen("i.txt", "r", stdin);
    // freopen("o.txt", "w", stdout);
    // #endif

    ll a,b;
    cin>>a>>b;

    cout<<(Xor(b)^Xor(a-1));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/* Karen {{{
  ___  ____
 |_  ||_  _|
   | |_/ /    ,--.   _ .--.  .---.  _ .--.
   |  __'.   `'_\ : [ `/'`\]/ /__\\[ `.-. |
  _| |  \ \_ // | |, | |    | \__., | | | |
 |____||____|\'-;__/[___]    '.__.'[___||__]
}}} */
/* cpp template {{{*/
using namespace std;

#define endl '\n'

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPS(i, a, n) for (int i = (a); i < (n); i++)
#define RREP(i, n) for (int i = 1; i <= (n); i++)
#define X real()
#define Y imag()
#define EQ(n,m) (abs((n)-(m)) < EPS)

typedef double D;
typedef long long ll;
typedef long double lb;
typedef complex<D> P;
typedef vector<P> VP;
typedef vector<int> vi;
typedef vector<vector<int> > vii;
typedef pair<int, int> pii;
typedef pair<int, string> pis;
typedef pair<string, int> psi;

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

template <typename T>
void print(std::vector<T>& v, char c = ' ') {
  REP(i, v.size()) {
    if (i != 0) std::cout << c;
    std::cout << v[i];
  }
  std::cout << endl;
}
template <typename T>
void print(T x) {
  std::cout << x << '\n';
}
/* }}} */
/* ?????° {{{*/
const ll MOD = 1e9 + 7;
const ll INF = 1e9 + 9;
const D EPS  = 1e-5;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
/* }}} */

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

  int n = in();
  float x[4], y[4];

  while(n--){
    REP(i, 4) cin >> x[i] >> y[i];
    float l1 = (y[1] - y[0]) / (x[1] - x[0]), l2 = (y[3] - y[2]) / (x[3] - x[2]);
    if (l1 == l2){
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
  return (0);
}

Measured memory_bytes: 1212