akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int n=1e5+10;
bitset<n> isprime;
vector<int>answer;
void sieve()
{
    isprime[0]=isprime[1]=0;
    for(int p=2; p<=n; ++p)
        if(isprime[p])
            for(int m=2*p; m<n; m+=p)
                isprime[m]=0;

}


int the2017ers[n];
void is2017()
{
    int sum=0;
    for (int p=1; p<=n; p++)
    {
        sum+=(isprime[p]&&isprime[(p+1)/2]);
        the2017ers[p]=sum;

    }

}

int main()
{

    isprime.set();
    sieve();
    is2017();
    int tc,l,r;
    cin>>tc;
    while(tc--)
    {
        cin>>l>>r;
        cout<<the2017ers[r]-the2017ers[l-1]<<endl;
    }


    return 0;
}


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

int main() {
	string s[8];
	for(int i = 0; i < 8; i++)
		cin >> s[i];

	cout << 90 << endl;

	for(int y = 0; y < 8; y++) {
		for(int x = 0; x < 8; x++) {
			char c = s[7 - x][y];
			cout << c;
		}
		cout << endl;
	}

	cout << 180 << endl;

	for(int y = 0; y < 8; y++) {
		for(int x = 0; x < 8; x++) {
			char c = s[7 - y][7 - x];
			cout << c;
		}
		cout << endl;
	}

	cout << 270 << endl;

	for(int y = 0; y < 8; y++) {
		for(int x = 0; x < 8; x++) {
			char c = s[x][7 - y];
			cout << c;
		}
		cout << endl;
	}
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		if ((a + b) % 2 == 0) {
			System.out.println((a + b) / 2);
		} else {
			System.out.println("IMPOSSIBLE");
		}

		sc.close();
	}
}

Measured memory_bytes: 27036
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define numrep(i,n) for(int i=1;i<=n;i++)
#define bitrep(n) for(int bit=0;bit<(1<<n);bit++)
#define ll int64_t
#define all(v) v.begin(), v.end()
 
const int MOD = 1000000007;
 
int main() {
  int N,Q;
  map<int,int> X;
  cin >> N;
  vector<int> A(N);
  ll ans=0;
  rep(i,N){
  cin>> A[i];
  ans+=A[i];
  X[A[i]]++;
  }
  cin>>Q;
  
  vector<int> B(Q),C(Q);
  
  rep(i,Q){
    
    cin>>B[i]>>C[i];
    
    if(X.count(B[i])){
      int E=X.at(B[i]);
      X[B[i]]=0;
      X[C[i]]+=E;
      ans+=E*(C[i]-B[i]);
    }
    
    cout << ans << endl; 
    
  } 
 
return 0;
 
}

Measured memory_bytes: 8216
import heapq

n, need = map(int, input().split())
a = [list(map(int, input().split())) for _ in range(n)]

ret = float('inf')
for mask in range(1 << n):
    total = 0
    count = 0
    pq = []
    for bit in range(n):
        num, bonus = a[bit]
        points = (bit + 1) * 100
        if (mask >> bit) & 1:
            total += points * num + bonus
            count += num
        else:
            for i in range(num):
                heapq.heappush(pq, -points)
    while total < need and pq:
        total -= heapq.heappop(pq)
        count += 1
    if total >= need:
        ret = min(ret, count)

print(ret)

Measured memory_bytes: 55516
#include<bits/stdc++.h>
using namespace std;
const int MAX = 3001;
int dp[MAX][MAX];
int main() {
	string s,t,lcs;
	cin>>s>>t;
	int i,j,ns = s.size(), nt = t.size();
	for(i=1;i<=ns;++i) {
		for(j=1;j<=nt;++j) {
			if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1]+1;
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	
	int ps = ns, pt = nt;
	while(ps > 0 and pt > 0) {
	    if(s[ps-1] == t[pt-1]) {
	        lcs.push_back(s[ps-1]);
	        ps--; pt--;
	    } else {
	        if(dp[ps][pt] == dp[ps][pt-1]) pt--;
	        else ps--;
	    }
	    
	}
	reverse(lcs.begin(), lcs.end());
	cout<<lcs<<endl;
	return 0;
}

Measured memory_bytes: 35456
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back
#define REP(i,a,b) for(int i=a; i<=b; i++)
#define MOD 1000000007

void solve(int test_case) {//209
	string ss;
	cin>>ss;
	bool n=0,e=0,w=0,s=0;
	for(char c:ss) {
		switch(c) {
			case 'N':n=1;break;
			case 'E':e=1;break;
			case 'W':w=1;break;
			case 'S':s=1;break;
		}
	}
	bool ans = 0;
	if((n&&e&&w&&s)||(n&&s&&!e&&!w)||(e&&w&&!s&&!n))ans=1;
	cout<<(ans?"Yes":"No");
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	//prefill();
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

/*
配列内の全ての整数について, 同じ素因数を持つ値が2つ以上あった場合(例えば4と8は
2を素因数として持つので, この2つが配列内に存在した時点でgcd==1とならない)
pairwise coprimeではない. setwise coprimeはgcdをループすれば判定できる.
*/

const int A = 1000005;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  vector<int> c(A);  // 同じ値がいくつあるかを保持する配列
  rep(i, n) {
    cin >> a[i];
    c[a[i]]++;
  }
  
  bool pairwise = true;
  for (int i = 2; i < A; i++) {
    int count = 0;
    // i=2ならj=2,4,6...と進み, 3なら3,6,9...と進む.
    // これで同じ素因数を持つ値の数をカウントできる
    for (int j = i; j < A; j += i) {
      count += c[j];
    }
    if (count > 1) pairwise = false;  // 同じ素因数を持つ値が2つ以上あった場合
  }
  if (pairwise) {  // 配列内の全ての値がそれぞれ違う素因数を持っていた場合
    cout << "pairwise coprime" << endl;
    return 0;
  }
  
  int g = 0;
  rep(i, n) g = gcd(g, a[i]);
  if (g == 1) {
    cout << "setwise coprime" << endl;
    return 0;
  }
  
  cout << "not coprime" << endl;
}

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

#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

//文字から数値に変換
int getChar(char ch) {
    if (ch == 'A') return 1;
    else if (ch == 'C') return 2;
    else if (ch == 'G') return 3;
    else if (ch == 'T') return 4;
    else return 0;
}

//文字列から数値へ変換してkey を生成する
ll getKey(char str[]) {
    ll sum = 0, p = 1, i;
    for (i = 0; i < strlen(str); i++) {
        sum += p*(getChar(str[i]));
        p *= 5;
    }
    return sum;
}

int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]) {
    ll key, i, h;
    key = getKey(str); //文字列の数値に変換
    for (i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str)==0) return 1;
        else if (strlen(H[h]) == 0) return 0;
    }
    return 0;
}

int insert(char str[]) {
    ll key, i, h;
    key = getKey(str);
    for (i = 0; ; i++) {
        h = (h1(key) + i * h2(key)) % M;
        if (strcmp(H[h], str) == 0) return 1;
        else if (strlen(H[h]) == 0) {
            strcpy(H[h], str);
            return 0;
        }
    }
    return 0;
}

int main() {
    int i, n, h;
    char str[L], com[9];
    for (i = 0; i < M; i++) H[i][0] = '\0';
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%s %s", com, str);

        if (com[0] == 'i') {
            insert(str);
        } else {
            if (find(str)) {
                printf("yes\n");
            } else {
                printf("no\n");
            }  
        }
    }

    return 0;
}



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

int update_i1(int i1, int i2, const vector<long long> & cums){
    long long p = cums[i1];
    long long q = cums[i2] - cums[i1];
    long long score = abs(p - q);
    int new_i1 = i1;
    while (p < q and new_i1 + 1 < i2){
        ++new_i1;
        p = cums[new_i1];
        q = cums[i2] - cums[new_i1];
        if (score < abs(p - q)){
            return new_i1 - 1;
        }else{
            score = abs(p - q);
        }
    }
    return new_i1;
}

int update_i3(int i3, int i2, const vector<long long> & cums){
    int N = cums.size();
    int new_i3 = max(i3, i2 + 1);
    long long r = cums[new_i3] - cums[i2];
    long long s = cums[N - 1] - cums[new_i3];
    long long score = abs(r - s);
    while (r < s and new_i3 < N - 2){
        ++new_i3;
        r = cums[new_i3] - cums[i2];
        s = cums[N - 1] - cums[new_i3];
        if (score < abs(r - s)){
            return new_i3 - 1;
        }else{
            score = abs(r - s);
        }
    }
    return new_i3;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<long long> As(N);
    for (auto & a : As) cin >> a;
    vector<long long> cums(N);
    long long cum = 0;
    for (int i = 0; i < N; ++i){
        cum += As[i];
        cums[i] = cum;
    }
    long long ans = 1e15;
    int i1 = 0;
    int i3 = 2;
    for (int i2 = 1; i2 < N - 2; ++i2){
        i1 = update_i1(i1, i2, cums);
        i3 = update_i3(i3, i2, cums);
        long long p = cums[i1];
        long long q = cums[i2] - cums[i1];
        long long r = cums[i3] - cums[i2];
        long long s = cums[N - 1] - cums[i3];
        ans = min(ans, max({p, q, r, s}) - min({p, q, r, s}));
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int A, B;
  cin >> A >> B;

  int count = 0;
  int sum = 0;

  while (sum < B) {
    count++;
    sum = (A - 1) * count + 1;
  }

  if (B == 1) {
    count = 0;
  }

  cout << count << endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main(){
    char s[1000000],t[1000000];
    scanf("%s\n", &s);
    scanf("%s\n", &t);
    int count=0,l=0,i;
    l = strlen(s);

    for(i=0;i<l;i++){
        if(s[i] != t[i]){
            count++;
        }
    }

    printf("%d\n", count);

}

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

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int H,W,K;
cin>>H>>W>>K;
vector<string>c(H);
rep(i,H)cin>>c[i];
int nh=1<<H;
int nw=1<<W;
ll ans =0;
rep(i,nh){
    rep(j,nw){
        vector<string> tmp(c);
        rep(n,H){
            if(i&(1<<n)){
                tmp[n]="";
                rep(l,W){
                    tmp[n]=tmp[n]+'r';
                }
            }
        }
        rep(m,W){
            if(j&(1<<m)){
                rep(l,H){
                    tmp[l][m]='r';
                }
            }   
        }
        int cnt=0;
        rep(n,H){
            rep(m,W){
                if(tmp[n][m]=='#')cnt++;
            }
        }
        if(cnt==K)ans++;
    }
}
cout<<ans<<endl;
return 0;
}

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

int main(){
	while(1){
		int p, n;
		
		scanf(" %d %d", &p, &n);
		if(p==0) break;	

		int x, y, u, v;
		double rp=sqrt(p);
		double big=10000, small=0;
		
		int re=(int)rp;
			
		for(int i=1; i<=n; ++i){
			for(int j=rp*i; j<=n; ++j){
				double a=(double)j/i;
				
				if(rp<a){
					if(a<big){
						big=a;	
						x=j;
						y=i;
					}
					
					break;
				}
				else{
					if(small<a){
						small=a;
						u=j;	
						v=i;
					}	
				}
		
			}
		}
					
		printf("%d/%d %d/%d\n", x, y, u, v);
	}
}

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

int main(){
	double a, b, c, d, e, f;
	double x, y;

	while(cin >> a >> b >> c >> d >> e >> f){
		x = (e*c-b*f) / (a*e-d*b);
		y = (d*c-a*f) / (b*d-e*a);
		if(x==0) x=0;
		if(y==0) y=0;
		printf("%.3f %.3f\n",x,y);
	}	

	return 0;
}

Measured memory_bytes: 3072
use std::io;

fn main() {
    let mut buffer = String::new();
    io::stdin().read_line(&mut buffer).unwrap();
    
    let mut input = buffer.trim().split_whitespace();
    let h = input.next().unwrap().to_string().parse::<usize>().unwrap();
    let w = input.next().unwrap().to_string().parse::<usize>().unwrap();

    let mut maze = vec!(vec!(None; w); h);
    let mut counter = 0;
    for y in 0..h {
        let mut buffer = String::new();
        io::stdin().read_line(&mut buffer).unwrap();
        let line: Vec<char> = buffer.trim().chars().collect();
        for x in 0..w {
            if line[x] == ".".chars().next().unwrap() {
                maze[y][x] = Some(counter);
                counter += 1;
            }
        }
    }

    let mut graph = vec!(vec!(std::usize::MAX / 2; counter); counter);
    for y in 0..h {
        for x in 0..w {
            if let Some(c) = maze[y][x] {
                for mov in &[(-0isize, 0), (1, 0), (0, 1), (0, -1isize)] {
                    let (mx, my) = *mov;
                    let (nx, ny) =(x as isize+mx, y as isize+my);
                    if ny < 0 || nx < 0 || ny > h as isize-1 || nx > w as isize-1 { continue; }
                    let (nx, ny) = (nx as usize, ny as usize);
                    if let Some(oc) = maze[ny][nx] {
                        graph[c][oc] = 1;
                        graph[oc][c] = 1;
                    }
                }
            }
        }
    }

    for y in 0..counter {
        graph[y][y] = 0;
    }

    for m in 0..counter {
        for i in 0..counter {
            for j in 0..counter {
                graph[i][j] = std::cmp::min(graph[i][j], graph[i][m] + graph[m][j]);
            }
        }
    }
    println!("{}", graph.iter().map(|v| v.iter().max().unwrap()).max().unwrap());
}


Measured memory_bytes: 4352
n = list(input())
x = int(n[0]+n[1])
y = int(n[2]+n[3])

if 1 <= x and x <= 12:
  if 1 <= y and y <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
elif 1 <= y and y <= 12:
  print("YYMM")
else:
  print("NA")

Measured memory_bytes: 9076
R,G,B,N = map(int, input().split())
index = 0
ans = 0
for_sort = [R,G,B]
for_sort.sort()
r = for_sort[2]
g = for_sort[1]
b = for_sort[0]
while N >=0:
  mid = N
  N -= r
  while mid >= 0:
    if mid % b == 0:
      ans += 1
    mid -= g
      
print(ans)    

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

using namespace std;

#define all(v) (v).begin(), (v).end()
#define Rep(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define rep(i, n) Rep(i, 0, n)
#define vi vector<int>
#define vvi vector<vi>

typedef long long ll;

int main() {
  int N;
  cin >> N;
  vi D(N, 0), cnt(N, 0);
  rep(i, N) {
    cin >> D[i];
    if (i == 0) {
      if (D[i] != 0) {
        cout << 0 << endl;
        return 0;
      }
    } else if (D[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
    cnt[D[i]] += 1;
  }
  ll ans = 1;
  if (D[0] != 0) {
    ans = 0;
  } else {
    Rep(i, 1, N) {
      rep(j, cnt[i]) {
        ans *= cnt[i - 1];
        ans %= 998244353;
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#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++)
typedef long long int ll;
typedef unsigned long long int ull;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a,b,c;
  string s,t="No";
  cin >>a;
  if(a>=30)t="Yes";
  cout <<t;
}

Measured memory_bytes: 3668
N,Y=map(int, input().split())

ans=False

for man in range(N+1):
    for gosen in range(N-man+1):
            if man*10000+gosen*5000+(N-man-gosen)*1000==Y:
                print(man,gosen,N-man-gosen)
                ans=True
                exit()



if not ans:
    print("-1 -1 -1")

Measured memory_bytes: 3060
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
INF = 10 ** 10
p = 2 ** N
dp = [INF] * p
dp[0] = 0

for _ in range(M):
    a, b = map(int, input().split())
    c = sum([2 ** (i - 1) for i in map(int, input().split())])
    for i in range(p):
        dp[i | c] = min(dp[i] + a, dp[i | c])

if dp[-1] != INF:
    print(dp[-1])
else:
    print(-1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb push_back
const int maxn=2e5+10;
const int mod=1e9+7;
int a[maxn];
int f[maxn];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        f[a[i]]=i;
    }
    for(int i=1;i<=n;i++)
        cout<<f[i]<<" ";




}

Measured memory_bytes: 4324
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define MAX_C 1000000001
#define MOD 1000000007

int main() {
  int n;
  cin >> n;
  set<string> gacha;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    gacha.insert(s);
  }

  cout << gacha.size() << endl;
}


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

using namespace std;

int mini = 1987654321, maxi, cnt;

int main() {
	int i;

	int n, t;
	scanf("%d%d",&n,&t);
	for (i=0;i<n;i++) {
		int a;
		scanf("%d",&a);
		if (mini<a) {
			if (maxi<a-mini) {
				cnt = 1;
				maxi=a-mini;
			}
			else if (maxi==a-mini) {
				cnt++;
			}
		}
		mini = min(mini,a);
	}
	printf("%d\n",cnt);

    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<cctype>
#include<cstdio>
using namespace std;
 
int main() {
    int count[26];
    char ch;
	
	for(int i = 0; i < 26; i++){
		count[i] = 0;
	}
 
    while (scanf("%c", &ch) != EOF) {
    	if(ch >= 'A'&& ch <= 'Z') ch += 32;
    	if(ch >= 'a'&& ch <= 'z'){
    		int num = ch - 'a';
    		count[num]++;
    	}
    }
	
	for(int i = 0;i < 26; i++){
		printf("%c : %d\n",i +'a', count[i]);
	}
	
	return 0;
}

Measured memory_bytes: 3200
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
//　何がダメなのかわからない
char s[30][30];

int dist[30][30];
bool visited[30][30];

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

int h,w;

int BFS(int x, int y, int a, int b){
  
  queue<P> Q; Q.push({x,y}); //inserting a starting point
 
  visited[x][y] = true;
  
  while(!Q.empty()){
     P p = Q.front(); Q.pop();
    
    for(int k = 0; k < 4; k++){
      P q = p;
      q.first += dx[k]; q.second += dy[k];
      
          
   if(q.first < 0 || q.first >= h || q.second < 0 || q.second >= w){ continue;}
   if(visited[q.first][q.second] || s[q.first][q.second] == '#'){ continue;}
      
 // if q is a block space or out of a rectangle, then the operation below should be skipped
  
      
      dist[q.first][q.second] = dist[p.first][p.second]+1;
      
      Q.push(q); visited[q.first][q.second] = true;
      
    }
  }
  
  int res = dist[a][b];
  
  return res;
}
      

int main(){
  
  cin >> h >> w;
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      cin >> s[i][j];
    }
  }
  
  //no problem on entering the datasets
  
  int ans = 0;
  
  for(int i = 0; i < h; i++){
    for(int j = 0; j < w; j++){
      
      if(s[i][j] ==  '#'){ continue;}
      
      for(int k = 0; k < h; k++){
        for(int l = 0; l < w; l++){
          
//considering the case in which (i,j) is the start point while (k,l) is the end point
          
          if(s[k][l] ==  '#'){ continue;}
         
          
          for(int x = 0; x < 30; x++){
            for(int y = 0; y < 30; y++){
              dist[x][y] = 0; visited[x][y] = false;
            }
          } //initializing
          
          ans = max(BFS(i,j,k,l),ans);
          // updating the answer if BFS is larger than the ans before
          
          
        }
      }
      
    }
  }

  printf("%d\n",ans);
    
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll A[200000];
int main() {
	int N;
	cin >> N;
	if (N == 1) {
		cout << 0 << endl;
		return 0;
	}
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		A[i] -= (i + 1);
	}
	sort(A, A + N);
	ll ans = 1LL << 60;
	for (int i = 0; i <= 1; i++) {
		ll sum = 0;
		for (int j = 0; j < N; j++) {
			sum += abs(A[j] - A[N / 2 + i]);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n; cin >> n;
	vi v(3 * n);
	rep(i, 3 * n) cin >> v[i];
	sort(all(v));
	ll ans = 0;
	rep(i, n) ans += v[3 * n - 2 * i - 2];
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int inf=1e9+7;
int main(){
    int n;cin>>n;
    vector<int> a(n+1);
    vector<int> b(n);
    for(int i=0;i<n+1;i++){
        cin>>a[i];
    }
    for(int i=0;i<n;i++){
        cin>>b[i];
    }
    ll count=0;
    int k=a[0];
    for(int i=0;i<n;i++){
        if(k<=b[i]){
            if(a[i+1]+k<=b[i]){
                count+=(k+a[i+1]);
                k=0;
            }else{
                count+=b[i];
                k=(a[i+1]+k-b[i]);
            }
        }else{
            count+=b[i];
            k=a[i+1];
        }
    }
    cout<<count<<endl;
}

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

int main(){
  int n;
  cin >> n;
  int sum=0;
  int i=0;
  while(sum<n){
    i++;
    sum += i;
  }
  for(int j=1; j<=i; j++){
    if(j==sum-n)continue;
    cout << j << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cout << '[' << #x << " is: " << x << "] " <<"\n";
#define imod(a , n) (a % n + n ) % n ;
#define int long long
const double eps = 1e-9 , PI = acos(-1) ;
const int N = 100;
int n , w , wt[N] , val[N] ;
vector<vector<int>> dp(101 , vector<int> (1e5 + 1 , -1));
int calc(int idx , int cap){
    if(idx == n || cap == 0)return dp[idx][cap] = 0 ;
    if(dp[idx][cap] != -1)return dp[idx][cap];
    int a1 = -1 , a2 = -1 ;
    if(cap >= wt[idx])a1 = val[idx] + calc(idx + 1 , cap - wt[idx]);
    a2 = calc(idx + 1 , cap);
    return dp[idx][cap] = max(a1 , a2);

}
int32_t main(){
    cin >> n >> w ;
    for(int x = 0 ;x < n ;x++){
        cin >> wt[x] >> val[x] ;
    }
    cout << calc(0 , w);





        return 0;
}


Measured memory_bytes: 80256
use proconio::{fastout, input};
use std::io::*;
use std::str::FromStr;

use std::cmp::{max, min};
use std::collections::{BinaryHeap, HashMap, HashSet, VecDeque};

fn main() {
    input! {
        n: usize,
        ab: [(usize, usize);n],
    }

    let mut cnt = 0;
    let mut maxv = 0;
    for i in 0..ab.len() {
        if ab[i].0 == ab[i].1 {
            cnt += 1;
        } else {
            cnt = 0;
        }
        maxv = max(maxv, cnt);
    }
    if maxv >= 3 {
        println!("Yes");
    } else {
        println!("No")
    }
}


Measured memory_bytes: 2164
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(int i=(s);i<(t);++i)
#define per(i,s,t) for(int i=((t)-1);i>=s;--i)
#define repb(i,s,t) for(int i=(s);i<=(t);++i)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
#define mst(a,b) memset(a,b,sizeof(a))
#define mcpy(des,sor) memcpy(des,sor,sizeof(sor))
#define dd(x) cout<<#x<<'='<<x<<' '
#define de(x) cout<<#x<<'='<<x<<'\n'
#define fi first
#define se second
#define sq(x) ((x)*(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;

const int inf = 0x3f3f3f3f;
const ll mod = 1e9+7;
const db eps = 1e-8;

char io[1<<15],*is=io,*ie=io+1;
#define rd if(++is==ie)ie=(is=io)+fread(io,1,sizeof(io),stdin)
template<class T>
inline bool Cin(T &a){
	a=0;bool s=0;
	if(is==ie)return 0;
	do{rd;if(*is=='-')s=1;}while(!isdigit(*is)&&is!=ie);
	if(is==ie)return 0;
	do{(a*=10)+=*is&15;rd;}while(isdigit(*is)&&is!=ie);
	if(s)a=-a;;return 1;}

inline int Gets(char a[]){
	int p=0;
	if(is==ie)return 0;
	do rd; while(!isgraph(*is)&&is!=ie);
	if(is==ie)return 0;
	do {a[p++]=*is;rd;}while(isgraph(*is)&&is!=ie);
	a[p]=0;return p;}

#define maxn 100005


int main()
{
	int n,k,z;ll a=0;
	cin>>n>>k;
	z=0;
	for(int i=1;i*k<=n;++i)z+=1;
	a+=1ll*z*z*z;
	if(k%2==0)
	{
		z=0;
		for(int i=0;i*k+k/2<=n;++i)z+=1;
		a+=1ll*z*z*z;
	}
	cout<<a<<endl;
}

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

public class Main {
    public static String reverse(long start, long end){
    	//print "end end-1 ... start+1 start"
    	String ans ="";
    	for(long i=end;i>start;i--) ans=ans+i+" ";
    	ans=ans+start;
    	return ans;
    }
    public static void printReverse(long start, long end){
    	//print "end end-1 ... start+1 start"
    	for(long i=end;i>start;i--) System.out.print(i+" ");
    	System.out.print(start);
    }
    
    public static void ans(long N, long A, long B){
    	if(A*B<N || A+B-1>N){
    	    System.out.println(-1);
    	    return;
    	}
    	if(A==1&&B==N){
    		printReverse(1,N);
    		return;
    	}
    	
    	printReverse(1,B);
    	
    	long next = B+1;
    	long leftBlocks=A-1;
    	if(next<=N) System.out.print(" ");
    	while(next<=N){
    	    long leftElms = N-next+1;
    	    if(B-1+leftBlocks<=leftElms){
    	    	printReverse(next,next+B-1);
    	    	next = next+B;
    	    	leftBlocks--;
    	    	if(next<=N) System.out.print(" ");
    	    }else{
    	    	printReverse(next,N-leftBlocks+1);
    	    	next=N-leftBlocks+2;
    	    	leftBlocks--;
    	    	if(next<=N) System.out.print(" ");
    	    }
    	}
    	
    	
    	
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long A = sc.nextLong();
        long B = sc.nextLong();
        ans(N,A,B);
        
    }
}

Measured memory_bytes: 48432
from itertools import accumulate
from math import*
from collections import deque
from collections import defaultdict
from itertools import permutations
from heapq import*
from collections import Counter
from itertools import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = 10**18
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

n = int(input())
a = list(map(int,input().split()))
dp = [[0]*2 for i in range(n+1)]
dp[0][1] = -inf
for i in range(n):
    dp[i+1][0] = max(dp[i][0]+a[i],dp[i][1]-a[i])
    dp[i+1][1] = max(dp[i][0]-a[i],dp[i][1]+a[i])
print(dp[n][0])

Measured memory_bytes: 77536
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int N;
ll K, A[101010];
ll dp[61][2]; // dp[dgt][isless]
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> K;
    rep(i, 0, N) cin >> A[i];

    rep(dgt, 0, 61) rep(isless, 0, 2) dp[dgt][isless] = -infl;
    dp[0][0] = 0;

    rep(dgt, 0, 60) rep(isless, 0, 2) if(0 <= dp[dgt][isless]) {
        int d = 59 - dgt;
        ll msk = 1LL << d;

        int zero = 0, one = 0;
        rep(i, 0, N) {
            if (A[i] & msk) one++;
            else zero++;
        }

        // 0
        int isless2 = isless;
        if (K & msk) isless2 = 1;
        chmax(dp[dgt + 1][isless2], dp[dgt][isless] + one * msk);

        // 1
        if ((K & msk) or isless == 1) {
            chmax(dp[dgt + 1][isless], dp[dgt][isless] + zero * msk);
        }
    }

    cout << max(dp[60][0], dp[60][1]) << endl;
}

Measured memory_bytes: 1024
A, B = map(int, input().split())
C = list(map(int, input().split()))

max_height = [0] * A

for i in range(B):
    a, b = map(int, input().split())
    max_height[a - 1] = max(max_height[a - 1], C[b - 1])
    max_height[b - 1] = max(max_height[b - 1], C[a - 1])

print((sum(C[i] > max_height[i] for i in range(A))))

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

int main() {
	int n,a,b,x=0,y=0;
	for(int q=0;q==q;q++){
	n=0,x=0,y=0;
	cin>>n;
	if(n==0)break;
	for(int t=0;t<n;t++){
		cin>>a;
		cin>>b;
		if(a>b){
			x+=a+b;
		}
		else if(a==b){
			x+=a;
			y+=b;
	}
		else {
			y+=a+b;
	}
		
	}
	cout<<x<<' '<<y<<'\n';
	}
	return 0;
}


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

int H, W;
vector<vector<char>> maze(21, vector<char>(21));
int Max = 0;

void searchMaze(int i, int j, vector<vector<bool>> &flag, queue<int> &qx_push, queue<int> &qy_push){
  if(flag.at(i).at(j)){
    return;
  }

  flag.at(i).at(j) = true;

  //上
  if(i - 1 >= 0){
    if(maze.at(i - 1).at(j) == '.'){
      qx_push.push(j);
      qy_push.push(i - 1);
    }
  }
  //下
  if(i + 1 < H){
    if(maze.at(i + 1).at(j) == '.'){
      qx_push.push(j);
      qy_push.push(i + 1);
    }
  }
  //右
  if(j + 1 < W){
    if(maze.at(i).at(j + 1) == '.'){
      qx_push.push(j + 1);
      qy_push.push(i);
    }
  }
  //左
  if(j - 1 >= 0){
    if(maze.at(i).at(j - 1) == '.'){
      qx_push.push(j - 1);
      qy_push.push(i);
    }
  }

  return;
}

int bfs(int starti, int startj, vector<vector<bool>> flag){
  queue<int> qx_push, qy_push, qx_pop, qy_pop;
  searchMaze(starti, startj, flag, qx_push, qy_push);
  int count = 0;
  while(qx_push.size() > 0){
    count++;
    swap(qx_pop, qx_push);
    swap(qy_pop, qy_push);
    while(qx_pop.size() > 0){
      //cout << qx_pop.size() << endl;
      int i, j;
      i = qy_pop.front();
      j = qx_pop.front();
      qy_pop.pop();
      qx_pop.pop();
      searchMaze(i, j, flag, qx_push, qy_push);
    }
  }
  return count;
}

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


  cin >> H >> W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> maze.at(i).at(j);
    }
  }

  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      if(maze.at(i).at(j) == '.'){
        vector<vector<bool>> flag(21, vector<bool>(21));
        int count = bfs(i, j, flag);
        if(count > Max){
          Max = count;
        }
      }
    }
  }
  cout << Max - 1 <<endl;
} 

Measured memory_bytes: 892
//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
typedef long long ll;
const int N=2e5+5;
int a[N],pos[N],n,L,T,x,w;ll t;
int main(){
	scanf("%d%d%d",&n,&L,&T);
	fp(i,0,n-1){
		scanf("%d%d",&x,&w),w=(w==2?-1:1);
		pos[i]=((x+T*w)%L+L)%L;
		if(w==1)t+=(x+T)/L;else t-=(L-1-x+T)/L;
	}
	t=(t%n+n)%n;
	sort(pos,pos+n);
	fp(i,t,n-1)printf("%d\n",pos[i]);
	fp(i,0,t-1)printf("%d\n",pos[i]);
	return 0;
}

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


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

    int d;
    cin >> d;
    if (d == 25) cout << "Christmas" << endl;
    else if (d == 24) cout << "Christmas Eve" << endl;
    else if (d  == 23) cout << "Christmas Eve Eve" << endl;
    else cout << "Christmas Eve Eve Eve" << endl;
    return 0;
}

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

#define int long long

#define rep(i,s,n) for(int i = (s);i<(n);i++)
#define repe(i,s,n) for(int i = (s);i<=(n);i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};

string s;


signed main(){
    cin>>s;
    int cnt=0,maxs=0,maxt=0,ans=0,cnts=0;
    rep(i,0,s.size()){
        if(s[i]=='S'){
            cnt++;
            
        }
        if(s[i]=='T'){
            cnt--;
            ans=min(ans,cnt);
        }
    }
    
    cout<<-1*ans*2<<endl;
    
    return 0;
}

Measured memory_bytes: 640
import unittest


class TestC(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think([1, 4, 3]), [4, 3, 4])

    def test_2(self):
        self.assertEqual(think([5, 5]), [5, 5])


def solve():
    a = read()
    result = think(a)
    write(result)


def read():
    n = read_int(1)[0]
    a = []
    for _ in range(n):
        a.append(read_int(1)[0])
    return a


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a):
    hist = make_histogram(a)

    list_form_of_hist = []
    for k, v in hist.items():
        list_form_of_hist.append([k, v])
    list_form_of_hist.sort(key=lambda x: -x[0])

    result = []
    for e in a:
        if e == list_form_of_hist[0][0]:
            if list_form_of_hist[0][1] == 1:
                result.append(list_form_of_hist[1][0])
            else:
                result.append(list_form_of_hist[0][0])
        else:
            result.append(list_form_of_hist[0][0])
    return result


def write(result):
    for e in result:
        print(e)


def make_histogram(a):
    hist = {}
    for e in a:
        if e in hist:
            hist[e] += 1
        else:
            hist[e] = 1
    return hist


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 36744
#include <cstdio>

using namespace std;

char line[1024];
char A[1024];
char B[1024];
char C[1024];

int main() {
	int N;
	scanf("%s", line);
	sscanf(line, "%d", &N);
	scanf("%s", A);
	scanf("%s", B);
	scanf("%s", C);
	int ret = 0;
	for(int i=0; i<N; ++i) {
		if(A[i]==B[i]) {
			if(A[i]!=C[i]) {
				ret += 1;
			}
		}
		else {
			if(A[i]==C[i]) {
				ret += 1;
			}
			else if(B[i]==C[i]) {
				ret += 1;
			}
			else {
				ret += 2;
			}
		}
	}
	printf("%d\n", ret);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

int main(){
  unsigned long H, W;
  std::cin >> H >> W;
  if(H == 1 or W == 1){
    std::cout << 1 << std::endl;
  }
  else if(H&1ul and W&1ul){
    std::cout << (H/2ul) * W + W/2ul + 1 << std::endl;
  }
  else if(H&1ul){
    std::cout << H * (W/2ul) << std::endl;
  }
  else{
    std::cout << (H/2ul) * W << std::endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <iostream>
#include <queue>
#include <list>
#include <stack>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;


int main(){
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> memo(N+1, 1), red(N+1, 0);
  red[1] = 1;
  rep(i,M){
    int x, y;
    cin >> x >> y;
    memo[x]--;
    memo[y]++;
    if(red[x]==1) red[y] = 1;
    if(memo[x]==0) red[x] = 0;
  }
  int ret = 0;
  REP(i,1,N+1){
    ret += red[i];
  }
  cout << ret << endl;
  return 0;
}

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

int main(){

    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    int x3, y3, x4, y4;
    int difx, dify;
    difx = abs(x1-x2);
    dify = abs(y1-y2);

    if (x1 > x2){
        if (y1 > y2){
            x3 = x2 + dify;
            y3 = y2 - difx;
            x4 = x1 + dify;
            y4 = y1 - difx;
        }
        else{
            x3 = x2 - dify;
            y3 = y2 - difx;
            x4 = x1 - dify;
            y4 = y1 - difx;
        }
    }
    else{
        if (y1 > y2){
            x3 = x2 + dify;
            y3 = y2 + difx;
            x4 = x1 + dify;
            y4 = y1 + difx;
        }
        else{
            x3 = x2 - dify;
            y3 = y2 + difx;
            x4 = x1 - dify;
            y4 = y1 + difx;
        }
    }

    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (i%2 == 0) {
      sum += vec.at(i);
    }
    else {
      sum -= vec.at(i);
    }
  }
  
  cout << sum << endl;
  
}


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

using namespace std;


void f(int n) {
    int half = n / 2;
    set<int> squares;
    for(int i = 1; i<=half; i++) {
        squares.insert((i*i) % n);
    }
    vector<int> nums(squares.begin(), squares.end());
    int len = nums.size();
    vector<int> cts(half+1, 0);
    for(int y=1; y<len; y++) {
        for(int x=0; x<y; x++) {
            int r = nums[y] - nums[x];
            if(r>half) r = n - r;
            cts[r] += 2;
        }
    }
    for(int i=1; i<=half; i++) cout << cts[i] << endl;
}

int main() {
    int n;
    while(scanf("%d", &n), n) f(n);
    return 0;
}




Measured memory_bytes: 3432
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main(){

    for(int N, L, R; cin >> N >> L >> R;){
        if(N == 0)break;
        vector<int>A(N + 1);
        for(int i = 1; i <= N; i++)cin >> A[i];
        int ans = 0;
        for(int x = L; x <= R; x++){
            int flg = -1;
            for(int i = 1; i <= N; i++){
                if(x % A[i] == 0){
                    if(i & 1)flg = 1;
                    else flg = 0;
                    break;
                }
            }
            if(flg < 0){
                if(N & 1)flg = 0;
                else flg = 1;
            }
            if(flg)ans++;
        }
        cout << ans << endl;
    }

    return 0;
}


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

using namespace std;

string s;

int ansl, ansr;

int main() {
    cin >> s;

    ansl = -1, ansr = -1;
    for (int i = 0; i < s.length() - 1; i++) {
        if (s[i] == s[i + 1]) {
            ansl = i + 1, ansr = i + 2;

            break;
        }

        if (i < s.length() - 2 && s[i] == s[i + 2]) {
            ansl = i + 1, ansr = i + 3;

            break;
        }
    }

    cout << ansl << ' ' << ansr << '\n';

    return 0;
}


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

int main() {
	long long in;
	while(cin >> in, in) {
		string s = "";
		while(in) {
			if(in % (-10) < 0) {
				s += char(in % (-10) + 10 + '0');
				in -= 10;
			}
			else {
				s += char(in % (-10) + '0');
			}
			in /= -10;
		}
		reverse(s.begin(), s.end());
		cout << s << endl;
	}
}

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

#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VC vector<char>
#define VVI vector<vector<ll>>
#define VVC vector<vector<char>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define l_b(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define u_b(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define sort(v) sort(v.begin(),v.end())
#define p_b push_back
#define p_f push_front
#define m_p make_pair
#define fir first
#define sec second
#define sz size()
ll n,m,k;
VI v;
int main() 
{   cin>>n>>k;
    v=VI(n+1);
    VVI dp(n+1,VI(k+1,0));
    lf(i,1,n)
        cin>>v[i];
    ll ans;
    lf(i,0,n)
    {   lf(j,0,k)
        {   if(i==0 && j==0)
                dp[i][j]=1;
            else if(i>0)
            {   ll minind=min(v[i],j);
                ll sum=0;
                if(minind<j)
                    sum=dp[i-1][j]-dp[i-1][j-minind-1];
                else
                    sum=dp[i-1][j];
                dp[i][j]=(sum+mod)%mod;
            }
            if(i==n && j==k)
                ans=dp[i][j];
        }
        lf(j,1,k)
                dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
    }
    cout<<ans<<endl;
}

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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;

void dfs(int cur, int pre, int color, vector<int> &colors, Graph &G) {
    colors[cur] = color;
    for (int nx : G[cur]) {
        if (nx != pre) dfs(nx, cur, 1-color, colors, G);
    }
}

void solve() {
    int N;
    cin >> N;
    Graph G(N);
    for (int i=0; i<N-1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }

    vector<int> colors(N);
    dfs(0, -1, 0, colors, G);
    int cnt0 = 0, cnt1 = 0;
    for (int x : colors) {
        if (x == 0) ++cnt0;
        else ++cnt1;
    }
    vector<int> ans(N);
    if (cnt0 > N / 3 && cnt1 > N / 3) {
        int t0 = 3, t1 = 1, t2 = 2;
        for (int i=0; i<N; ++i) {
            if (colors[i] == 0) {
                if (t1 <= N) {
                    ans[i] = t1;
                    t1 += 3;
                } else {
                    ans[i] = t0;
                    t0 += 3;
                }
            } else {
                if (t2 <= N) {
                    ans[i] = t2;
                    t2 += 3;
                } else {
                    ans[i] = t0;
                    t0 += 3;
                }
            }
        }
    } else if (cnt0 <= N / 3) {
        int t0 = 3, t1 = 1, t2 = 2;
        for (int i=0; i<N; ++i) {
            if (colors[i] == 0) {
                ans[i] = t0;
                t0 += 3;
            } else {
                if (t1 <= N) {
                    ans[i] = t1;
                    t1 += 3;
                } else if (t2 <= N) {
                    ans[i] = t2;
                    t2 += 3;
                } else {
                    ans[i] = t0;
                    t0 += 3;
                }
            }
        }
    } else {
        int t0 = 3, t1 = 1, t2 = 2;
        for (int i=0; i<N; ++i) {
            if (colors[i] == 1) {
                ans[i] = t0;
                t0 += 3;
            } else {
                if (t1 <= N) {
                    ans[i] = t1;
                    t1 += 3;
                } else if (t2 <= N) {
                    ans[i] = t2;
                    t2 += 3;
                } else {
                    ans[i] = t0;
                    t0 += 3;
                }
            }
        }
    }
    for (int i=0; i<N; ++i) {
        cout << ans[i];
        if (i == N-1) cout << '\n';
        else cout << ' ';
    }
}

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

    solve();

    return 0;
}


Measured memory_bytes: 24668
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    string a;
    cin >> a;
    a[3] = '8';
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
typedef pair<string, int> P;

int main(){
  int N,A,S,G;
  while(cin>>N>>A>>S>>G,N){
    vector<int> to[40]; vector<string> spell[40];
    REP(i,A){
      int u,v; string s;
      cin>>u>>v>>s;
      to[u].push_back(v);
      spell[u].push_back(s);
    }
    priority_queue<P, vector<P>, greater<P> > que;
    que.push(P("", S));
    string ans = "NO";
    set<P> memo;
    bool reachable[40][40]={};
    REP(i,N)reachable[i][i] = true;
    REP(i,N)REP(j,to[i].size())reachable[i][to[i][j]] = true;
    REP(k,N)REP(i,N)REP(j,N)reachable[i][j] |= reachable[i][k] & reachable[k][j];
    if(!reachable[S][G]) goto OUT;
    while(!que.empty()){
      P p = que.top(); que.pop();
      if(p.second == G){
        ans = p.first;
        break;
      }
      if((int)p.first.size() > N*6){
        break;
      }
      if(memo.count(p))continue;
      memo.insert(p);
      REP(i,to[p.second].size()){
        int next = to[p.second][i];
        if(reachable[next][G]) que.push(P(p.first + spell[p.second][i], next));
      }
    }
OUT:
    cout<<ans<<endl;
  }
  return 0;
}

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

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n;
  ll x;
  cin>>n>>x;
  vector<ll> xs(n);
  rep(i,n)cin>>xs[i];
  sort(xs.begin(),xs.end());
  ll g=abs(x-xs[0]);
  rep(i,n-1) {
    g=gcd(g,xs[i+1]-xs[i]);
  }
  cout << g << endl;
  return 0;
}


Measured memory_bytes: 1024