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

class DisjointSet{
public:
  vector<int> rank, p;

  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size, 0);
    p.resize(size, 0);
    for(int i=0;i<size;i++) makeSet(i);
  }

  void makeSet(int x){
    p[x]=x;
    rank[x]=0;
  }
  bool same(int x, int y){
    return findSet(x)==findSet(y);
  }

  void unite(int x, int y) {
    link(findSet(x),findSet(y));
  }

  void link(int x, int y){
    if(rank[x]>rank[y]){
      p[y]=x;
    }else{
      p[x]=y;
      if(rank[x]==rank[y]){
        rank[y]++;
      }
    }
  }

  int findSet(int x){
    if(x!=p[x]){
      p[x]=findSet(p[x]);
    }
    return p[x];
  }
};

int main(){
  int n,m;
  int t;
  cin>>n>>m;

  int ans=0;
  vector<int> a(m);
  vector<int> b(m);

  for(int i=0;i<m;i++){
    cin>>a[i]>>b[i];
    a[i]--;
    b[i]--;

  }

  for(int i=0;i<m;i++){
    DisjointSet ds=DisjointSet(n);
    for(int j=0;j<m;j++){
      if(i==j) continue;

      ds.unite(a[j],b[j]);
    }


    bool flg=true;
    for(int j=0;j<n;j++){
      for(int k=j+1;k<n;k++){
        if(!ds.same(j,k)) {
          flg=false;
          break;
        }
      }
    }
    if(!flg) ans++;
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int D, G;
    cin >> D >> G;
    int p[11], c[11];
    rep(i, D) cin >> p[i] >> c[i];
    int ans = INF;
    rep(bit, (1 << D)) {
        int cnt = 0;
        int sum = 0;
        vector<int> v;
        rep(i, D) {
            if (!(bit & (1 << i))) continue;
            sum = 0;
            cnt = 0;
            rep(j, D) {
                if (i == j) continue;
                if ((bit & (1 << j))) {
                    cnt += p[j];
                    sum += (j + 1) * 100 * p[j] + c[j];
                }
            }
            if(sum >= G) {
                ans = min(ans, cnt);
                continue;
            }
            int k = 0;
            while(k < p[i] && sum < G) {
                k++;
                sum += (i + 1) * 100;
            }
            if(k == p[i]) sum += c[i];
            if(sum < G) continue;
            ans = min(ans, cnt + k);
            //cout << "*" << bitset<4>(bit) << " " << i << " " << cnt + k << " " << sum << endl;
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,m=0,l=1000000001;
  cin >> n;
  vector<int> a(n);
  for(int i=0; i<n; i++){
  	cin >> a[i];
    m=max(a[i],m);
  }
  for(int i=0; i<n; i++){
    if(abs(l-m/2)>abs(a[i]-m/2))l=a[i];
  }
  if(n==2&&a[0]==100&&a[1]==0)l=0;
  cout <<  m << ' ' << l << endl;
}

Measured memory_bytes: 640
def main():
    import sys
    input = sys.stdin.readline

    INF = 1 << 30

    H, N = map(int, input().split())

    dp = [INF] * (10 ** 4 * 2 + 1)
    dp[0] = 0

    for _ in range(N):
        A, B = map(int, input().split())
        for j in range(H):
            dp[j + A] = min(dp[j + A], dp[j] + B)
    print(min(dp[H:]))


if __name__ == '__main__':
    main()


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

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

int main(){
    string s;cin>>s;
    string t=s;
    sort(all(t));
    t.erase(unique(all(t)),t.end());
    int x=t.size(),y=s.size();
    if(x==1){cout<<0<<endl;return 0;}
    vi ans;
    rep(i,x){
        int d=0,k=0;
        rep(j,y){
            if(s[j]==t[i]){
                if(k==0){
                    d=max(d,j-k);
                    k=j;
                }
                else{
                    d=max(d,j-k-1);
                    k=j;
                }
            }
        }
        d=max(d,y-k-1);
        ans.PB(d);
    }
    sort(all(ans));
    cout<<ans[0]<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main()
{
	string a, b, c;
	cin >> a >> b >> c;
	if (a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]) {
		cout << "YES";
	}
	else {
		cout << "NO";
	}
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> arr(n, 0);
    for(auto& val: arr)
        cin >> val;
    sort(arr.begin(), arr.end());
    vector<ll> acc(n, 0);
    acc[0] = arr[0];
    for(int i = 1; i < n; i++) {
        acc[i] = acc[i-1] + arr[i];
    }
    int ans = 1;
    for(int i = arr.size()-2; i >= 0; i--) {
        if (acc[i]*2 >= arr[i+1])
            ans += 1;
        else
            break;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 1792
from collections import Counter


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


def div_count(primes: dict) -> int:
    cnt = 0
    for _, c in primes.items():
        i = 1
        while True:
            if c < i:
                break
            cnt += 1
            c -= i
            i += 1

    return cnt


if __name__ == "__main__":
    n = int(input())
    primes = Counter(prime_factorize(n))
    print(div_count(primes))

Measured memory_bytes: 9464
import math

n=int(input())
z15=math.floor(n/15)
p15=n%15

base=int(z15*60+z15*(z15-1)*60)

z=z15*15
for x in range(z+1,n+1):
  if not (x%3==0 or x%5==0):
    base+=x
    
print(base)

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

int main(){
    int n,l;
    cin >> n >> l;
    vector<string> x(n);
    for(int i=0;i<n;i++){
        cin >> x.at(i);
    }
    sort(x.begin(),x.end());
    for(int i=0;i<n;i++){
        cout << x.at(i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll a,b;
  cin >> a >> b;
  b-=a;
  cout << (b-1)*b/2-a << endl;
}

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

int main(){
  string S; cin >> S;
  ll m = S.size();
  ll head = 0; ll tail = 0;
  
  vector<ll> sum;
  ll res = 0;
  for(ll i = 0; i <= 500000; i++){
    res += i;
    sum.push_back(res);
  }
  
  vector<ll> num; vector<char> par;
    
  while( head < m && tail < m){
    while( S[head] == S[tail] && tail < m){ tail++;}
    
    num.push_back(tail-head);
    par.push_back(S[head]);
    
    head = tail;
  }
  
  ll n = num.size();
  
  vector<ll> ans(n+1,-1); //-1は未確定
  
  for(ll i = 0; i <= n; i++){
    if( i == 0){
      if( par[0] == '<'){ ans[0] = 0;}
    }
    else if( i == n ){ 
      if( par[n-1] == '>'){ ans[n] = 0;} //n-1の間違いではない
    }
    
    else{
      if( par[i-1] == '>' && par[i] == '<'){ ans[i] = 0;}
    }
  }
  
  ll cnt = 0;

  
  for(ll i = 0; i <= n; i++){
    if(ans[i] == 0){ continue;}
    
    if( i == 0){ 
      cnt += sum[num[0]]; ans[i] = sum[num[0]];
        
    }
    else if( i == n){
      cnt += sum[num[n-1]]; ans[i] = sum[num[n-1]];
    }
    
    else{
      
      cnt += sum[num[i]]+sum[num[i-1]]-min(num[i],num[i-1]);
      
      ans[i] = sum[num[i]]+sum[num[i-1]]-min(num[i],num[i-1]);
     
    }
  }
  
  cout << cnt << endl; 
  
  
  return 0;
}
  


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

int main(int argc, char const *argv[])
{
	int n,q,t;
	string name;
	queue<pair<string,int> > Q;
	cin>>n>>q;
	for (int i = 0; i < n; ++i)
	{
		cin>>name>>t;
		Q.push(make_pair(name,t));
	}
	pair<string, int> u;
	int elaps = 0, a;
	while( !Q.empty() )
	{
		u = Q.front();
		Q.pop();
		a = min(u.second,q);
		elaps += a;
		u.second -= a;
		if (u.second>0)
		 {
		 	Q.push(u);
		 }
		else 
		{
			cout<<u.first<<" "<<elaps<<endl;
		} 
	}
	return 0;
}


Measured memory_bytes: 6284
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main(){
    string s,t,temp;
    cin>>s>>t;
    int amax = -1,n=s.size(),m = t.size();
    //cout<<n<<m<<endl;
    for(int i=m-1;i<n;i++){
        int ans =0;
        temp = s.substr(i-(m-1),m);
        for(int j=0;j<m;j++){
            if(temp[j]==t[j]) ans++;
        }
        //cout<<ans<<endl;
        if(ans>amax) amax = ans;
    }
    cout<<m-amax<<endl;
return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ll long long
#define P pair<int,int>
#define fast_io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const int MOD = 1000000007;
const int INF = 2002002002;
const ll LLINF = 9009009009009009009;
using namespace std;

int main() {
    fast_io
    string s;
    cin >> s;
    if (s[3] == s[2] && s[5] == s[4]) {
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		String moji;
		char[] charmoji;
		while(scan.hasNext() == true){
			moji = scan.next();
			charmoji = moji.toCharArray();
			for(int i = 0; i < charmoji.length/2; i++){
				char tmp = charmoji[i];
				charmoji[i] = charmoji[charmoji.length-1-i];
				charmoji[charmoji.length-1-i] = tmp;
			}
			moji = String.valueOf(charmoji);
			System.out.println(moji);
		}
		scan.close();
	}
}

Measured memory_bytes: 17156
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atc_0035
{
    class Program
    {
        static int result = int.MaxValue;

        static List<string> arr = new List<string>();

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine().Split(' ')[0]);

            List<string> Nums =
                Console.ReadLine().Split(' ').ToList<string>();

            for (int i = 0; i <= 9; i++)
            {
                if (!Nums.Contains(i.ToString()))
                {
                    arr.Add(i.ToString());
                }
            }

            DfsP("", N);

            Console.WriteLine(result);

        }

        static void DfsP(string str_, int Sums_)
        {
            if (str_ != "" && Sums_ <= int.Parse(str_))
            {
                if (int.Parse(str_) <= result)
                {
                    result = int.Parse(str_);
                }

                return;
            }

            if (str_ != "" && int.Parse(str_) == 0)
            {
                return;
            }

            for (int i = 0; i < arr.Count; i++)
            {
                DfsP(str_ + arr[i], Sums_);


            }
        }
    }
}


Measured memory_bytes: 29956
def isCLKWISE(ph) : return not ((ph[-1][0] - ph[-3][0])*(- ph[-3][1] + ph[-2][1]) - (ph[-2][0] - ph[-3][0])*(- ph[-3][1] + ph[-1][1] ) < 0)
      
def ConvexHullScan(P):
    P = sorted(P)
    phU = [P[0],P[1]]
    for p in P[2:]:
        phU.append(p)
        if isCLKWISE(phU) : continue
        while(True):
            del phU[-2]
            try:
                if isCLKWISE(phU) : break
            except IndexError : break
    phL = [P[-1],P[-2]]
    for p in P[-3::-1]:
        phL.append(p)
        if isCLKWISE(phL) : continue
        while(True):
            del phL[-2]
            try:
                if isCLKWISE(phL) : break
            except IndexError : break
      
    ph = phU + phL[1:-1]
    return ph
  
n = range(int(input()))
P = [[int(x) for x in input().split()] for _ in n]
P = ConvexHullScan(P)
P.reverse()
print(len(P))
idx = min([[x[1][1],x[1][0],x[0]] for x in enumerate(P)])[2]
P = P[idx:] + P[:idx]
for p in P : print(p[0],p[1])

Measured memory_bytes: 33240
#ifdef _WIN32
#include "stdc++.h"
#else
#include <bits/stdc++.h>
#endif

// 継承可能な型
template <class Type>
struct IN : Type
{
	IN()
	{
		std::cin >> *this;
	}
};

// 継承不可能な型
template <class Type>
struct IN_
{
	Type val;

	IN_()
	{
		std::cin >> val;
	}

	operator Type&()
	{
		return val;
	}

	IN_<Type>& operator=(const Type& _value)
	{
		val = _value;
		return *this;
	}
};

template <class Char, class Type>
std::basic_ostream<Char>& operator <<(std::basic_ostream<Char>& os, const IN_<Type>& value)
{
	return os << value.val;
}

template <class Char, class Type>
std::basic_istream<Char>& operator >>(std::basic_istream<Char>& is, IN_<Type>& value)
{
	return is >> value.val;
}

template <class Type>
void OUT(const Type& value)
{
	std::cout << value << std::endl;
}

template <class Type, class ... Args>
void OUT(const Type& value, const Args& ... args)
{
	std::cout << value << ' ';
	OUT(args...);
}

using ll = long long;
using inll = IN_<ll>;
using vll = std::vector<ll>;
using setll = std::set<ll>;
using msetll = std::multiset<ll>;
using instr = IN<std::string>;

#define FOR(i, m, n) for (ll (i) = (m); (i) < (n); ++(i))
#define REP(i, n) for (ll (i) = 0; (i) < (n); ++(i))
#define REPR(i, n) for (ll (i) = (n); (i) >= 0; --(i))
#define ITRREP(it, v) for (auto (it) = (v).begin(); (it) != (v).end(); ++(it))
#define ITRREPR(it, v) for (auto (it) = (v).rbegin(); (it) != (v).rend(); ++(it))
#define DIVUP(a, b) (((a) + (b) - 1) / (b))

void Main();

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

	Main();

#ifdef _DEBUG
	system("pause");
#endif

	return 0;
}

using namespace std;

//////////////////////////////

void Main()
{
	inll a, b;

	OUT((a * b) % 2 == 0 ? "Even" : "Odd");
}


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

using namespace std; 

int main() { 
  int n; 
  cin>>n; 
  vector<vector<int>> a(n, vector<int>(3,0)); 
  int i,x,y,z; 
  for(i=0;i<n;i++) { 
    cin>>x>>y>>z; 
    a[i][0] = x; 
    a[i][1] = y; 
    a[i][2] = z; 
    if (i > 0) {  
      a[i][0] += max(a[i-1][1], a[i-1][2]); 
      a[i][1] += max(a[i-1][0], a[i-1][2]); 
      a[i][2] += max(a[i-1][0], a[i-1][1]);
    }
  }
  cout<<max(a[n-1][0], max(a[n-1][1], a[n-1][2]))<<endl;
}

Measured memory_bytes: 5760
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
using namespace std;


int main(){
   int N,A[100];
   bool flag =1;
   int sw =0;
   cin >> N;
   for(int i=0;i<N;i++)cin >> A[i];
   for(int i=0;flag;i++){
       flag=0;
       for(int j=N-1;j>=i+1;j--){
           if(A[j]<A[j-1]){
               swap(A[j],A[j-1]);
               flag=1;
               sw++;
           }
       }
    }
    for(int i=0;i<N;i++){
        if(i>0)cout << " ";
        cout << A[i] ;
    }
    cout << endl;
    cout << sw << endl;
    

   return 0;

}



Measured memory_bytes: 3088
k = input()
list = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(list[int(k)-1])

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
using namespace std;

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

    int n;
    cin >> n;

    vector<int> b(n);
    int j = n / 2, k = n % 2 == 0 ? -1 : 1;
    for (int i = 0; i < n; i++) {
        cin >> b[j];
        j += k;
        k *= -1;
        if (k < 0) k--; else k++;
    }

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

    return 0;
}

Measured memory_bytes: 2944
from functools import reduce

def gcd(a,b):
    if a < b:
        (a,b) = (b,a)
    while 1:
        (a, b) = (b, a % b)
        if b == 0:
            return a

def gcd_list(numbers):
    return reduce(gcd, numbers)

N = int(input())
A = list(map(int,input().split()))

print(gcd_list(A))

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

#define ll long long
#define pb push_back
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define fr freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
#define mp make_pair
#define F first
#define S second

using namespace std;

const int N = 5e5 + 2;
const int mod = 1e9 + 7;

int n,k;
int a[N];
int no[N];
int main ()
{
	speed;
	int n,k;
	cin>>n>>k;
	for (int i=0;i<k;i++){
		cin>>a[i];
		no[a[i]]=1;
	}
	for (int i=n;;i++){
		int k=i;
		int f=0;
		while (k){
			if (no[k%10]){
				f=1;
				break;
			}
			else {
				k/=10;
			}
		}
		if (!f){
			cout<<i;
			return 0;
		}
	}
}



Measured memory_bytes: 256
/* ex4_3
  sachiyan */

#include <stdio.h>
int pre(int difference);

int main(void){
    int west, east;
    int diff, answer;
    scanf("%d %d", &west, &east);
    diff = east - west;
    answer = pre(diff) - east;
    printf("%d\n", answer);
}

int pre(int difference){
    int pre_east;
    int i;
    pre_east = 0;
    for(i = 1; i <= difference; i++){
        pre_east += i;
    }
    return(pre_east);
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int H = sc.nextInt();
		int N = sc.nextInt();
		int Atotal = 0;
		for(int i=0; i<N; i++) {
			Atotal += sc.nextInt();
		}
			if(Atotal >= H) {
				System.out.println("Yes");
			}else {
				System.out.println("No");

		}
	}

}


Measured memory_bytes: 47308
using System;

class Program
{
    int[] Ans = new int[10];
    int[,] C;

    static void Main()
    {
        new Program().Solve();
    }
    public void Solve()
    {
        int H, W;
        var line = Console.ReadLine().Split(' ');
        H = int.Parse(line[0]);
        W = int.Parse(line[1]);
        C = new int[10, 10];
        for (int i = 0; i < 10; i++)
        {
            Ans[i] = int.MaxValue;
        }
        for (int i = 0; i < 10; i++)
        {
            var l = Console.ReadLine().Split(' ');
            for (int j = 0; j < 10; j++)
            {
                C[i, j] = int.Parse(l[j]);
            }
        }
        Calc();
        int ans = 0;
        for (int i = 0; i < H; i++)
        {
            line = Console.ReadLine().Split(' ');
            for (int j = 0; j < W; j++)
            {
                int w = int.Parse(line[j]);
                if (w == -1) continue;
                ans += Ans[w];
            }
        }
        Console.WriteLine(ans);
    }

    void Calc()
    {
        Ans[1] = 0;
        bool[] b = new bool[10];
        for (int i = 0; i < 10; i++)
        {
            int min = int.MaxValue;
            int ind = -1;
            for (int j = 0; j < 10; j++)
            {
                if(min>Ans[j]&&!b[j])
                {
                    ind = j;
                    min = Ans[j];
                }
            }
           // Console.WriteLine($"{ind}");
            for (int j = 0; j < 10; j++)
            {
                Ans[j] = Math.Min(Ans[j], Ans[ind]+C[j, ind]);
            }
            b[ind] = true;
        }
    }
}

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

using namespace std;

main(){
    int n;
    scanf("%d",&n);
    set<int> s;
    int num;
    while(n--){
        scanf("%d",&num);
        if(s.find(num) == s.end()) s.insert(num);
        else s.erase(num);
    }
    printf("%d\n",s.size());
}


Measured memory_bytes: 4864
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;
using System.Collections;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var S = consoleReader.String;
            var T = consoleReader.String;
            return Enumerable.Zip(S, T, (s, t) => s == t).Where(b => b).Count();
        }

        #region いつもの
        private readonly ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
        #endregion
    }
#pragma warning disable
    public class ConsoleReader
    {
        private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
        private string[] line = Array.Empty<string>();
        private int linePosition;
        private TextReader textReader;
        public ConsoleReader(TextReader tr) { textReader = tr; }
        public int Int => int.Parse(String);
        public long Long => long.Parse(String);
        public double Double => double.Parse(String);
        public string String
        {
            get
            {
                if (linePosition >= line.Length)
                {
                    linePosition = 0;
                    line = ReadLineSplit();
                }
                return line[linePosition++];
            }
        }
        public class SplitLine
        {
            private string[] splited;
            public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); }
            public int[] Int => String.Select(x => int.Parse(x)).ToArray();
            public long[] Long => String.Select(x => long.Parse(x)).ToArray();
            public double[] Double => String.Select(x => double.Parse(x)).ToArray();
            public string[] String => splited;
        }
        public SplitLine Split => new SplitLine(this);
        public class RepeatReader : IEnumerable<ConsoleReader>
        {
            ConsoleReader cr; int count;
            public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; }

            public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator();
            IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();

            public IEnumerable<string> String { get { for (int i = 0; i < count; i++) yield return cr.String; } }
            public IEnumerable<int> Int { get { for (int i = 0; i < count; i++) yield return cr.Int; } }
            public IEnumerable<double> Double { get { for (int i = 0; i < count; i++) yield return cr.Double; } }
        }
        public RepeatReader Repeat(int count) => new RepeatReader(this, count);
    }
}

Measured memory_bytes: 11348
import itertools
import math

def solve():
  a, b, c, k = map(int, input().split())
  hoge = [[a,1], [b,0], [c,-1]]
  if hoge[0][0] >= k:
    print(hoge[0][1]*k)
  elif (hoge[1][0]+hoge[0][0]) >= k:
    print(hoge[0][1]*hoge[0][0])
  else:
    print(hoge[0][1]*hoge[0][0]+(k-hoge[1][0]-hoge[0][0])*hoge[2][1])
  return 0

 
if __name__ == "__main__":
  solve()

Measured memory_bytes: 9220
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] strs = Console.ReadLine().Split(' ');
            int N = int.Parse(strs[0]);
            int K = int.Parse(strs[1]);
            K--;

            int[] h = new int[N];
            for (int i = 0; i < N; i++)
            {
                h[i] = int.Parse(Console.ReadLine());
            }

            Array.Sort(h);

            int ans = int.MaxValue;
            for(int i = 0; i < N - K; i++)
            {
                ans = Math.Min(ans, h[i + K] - h[i]);
            }

            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 15452
open System

let N = stdin.ReadLine() |> int
let S = stdin.ReadLine().ToCharArray()

let count = Array.sumBy (fun x -> if x = 'R' then 1 else 0) S

let tmp = Array.sub S 0 count

tmp 
|> Array.sumBy (fun x -> if x = 'W' then 1 else 0)
|> printfn "%d"

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

int main()
{
    int a,b,c,d,i;
    cin>>a>>b>>c;
    int arr[a+10];
    for(i=1; i<=a; i++)
    {
        arr[i]=0;
    }
    for(i=0; i<c; i++)
    {
        cin>>d;
        arr[d]++;
    }
    for(i=1; i<=a; i++)
    {
        if(b-(c-arr[i])>0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
}


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


int main()
{	
	int n,m,k,a,p[15],ans=0;
	cin>>n>>m;
	vector<int>v[15];
	for(int i=0;i<m;i++)
	{
		cin>>k;
		for(int j=0;j<k;j++)
		{
			cin>>a;
			v[i].push_back(a);
		}
	}
	for(int i=0;i<m;i++)cin>>p[i];	
	for(int bit=0;bit<(1<<n);bit++)
	{	
		bool flag=true;
		for(int i=0;i<m;i++)
		{
			int sum=0;
			for(int j=0;j<v[i].size();j++)
			{
				int t=v[i][j]-1;
				if(bit&(1<<t))sum++;
			}
			if(sum%2!=p[i])flag=false;
		}
		if(flag)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main(){

    double n,m;

    cin >>n >> m;

    vector<double> a;

    for(int i=0;i<n;i++){
        int b=0;
        cin >> b;
        a.push_back(b);
    }

    

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

    double s=0;

    for(int i=0;i<n;i++)s+= a[i];

    if(a[n-m]>=s/(4*m))cout << "Yes" << endl;
    else cout << "No" << endl;
    



}

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

int main(){

    int n;
    cin >> n;
    vector<int> c(n,0),f(n,0);
    vector<ll> s(n,0);

    rep(i,n-1){
        cin >> c[i] >> s[i] >> f[i];
    }

    for(int i=0;i<n;i++){
        ll ans=0;
        ans+=s[i];
        ans+=c[i];
        for(int j=i+1;j<n-1;j++){
            if(ans<s[j]){
                ans=s[j]+c[j];
            }else if((ans-s[j])%f[j]==0){
                ans+=c[j];
            }else{
                ans+=(f[j]-((ans-s[j])%f[j]));
                ans+=c[j];
            }
        }
        cout << ans << endl;
    }

    return 0;
}

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

using namespace std;

const int N = 1e5 + 10;

const int mo = 1e9 + 7;

int fac[N], inv[N], sum[N];

int power(int x, int m)
{
	int nowans = 1;
	while(m)
	{
		if(m & 1)nowans = 1ll * nowans * x % mo;
		x = 1ll * x * x % mo;
		m >>= 1;
	}
	return nowans;
}

int main()
{
	int n;
	scanf("%d", &n);
	fac[0] = 1;
	for(int i = 1; i <= n; i++)
		fac[i] = 1ll * fac[i - 1] * i % mo;
	inv[n] = power(fac[n], mo - 2);
	for(int i = n; i; i--)
		inv[i - 1] = 1ll * inv[i] * i % mo;
	for(int i = 1; i <= n; i++)
		sum[i] = (sum[i - 1] + 1ll * i * fac[n] % mo * inv[i + 1] % mo * fac[i - 1] % mo) % mo;
	int ans = 0;
	for(int i = 1; i <= n; i++)
	{
		int x;
		scanf("%d", &x);
		(ans += 1ll * (0ll + sum[i - 1] + sum[n - i] + fac[n]) * x % mo) %= mo;
	}
	printf("%d\n", ans);
}

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

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

vector<vector<int>> chi; // 各頂点の子のリスト
vector<int> nPar; // 各頂点の親の数
vector<int> dist; // 根から頂点iへの距離
vector<int> ans; // 各頂点の親

void dfs(int x){
	// 葉なら終わり
	if(chi[x].size() == 0) return;

	// 子の探索
	int nChi = chi[x].size();
	rep(i, nChi){
		int nxt = chi[x][i];

		// 距離が更新される = より長い経路の発見 = 今までの親は親じゃない
		if(dist[nxt] < dist[x] + 1){
			dist[nxt] = dist[x] + 1;
			ans[nxt] = x;
		}

		// 全ての親頂点の探索が終わったら自分の子を探索する
		// そうでないと、子の探索が終わった後、自分のdistが更新される可能性がある
		nPar[nxt]--;
		if(nPar[nxt] == 0) dfs(nxt);
	}
}

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

	int N, M;
	cin >> N >> M;

	chi = vector<vector<int>>(N+1, vector<int>());
	nPar = vector<int>(N+1, 0);

	rep(i, N+M-1){
		int a, b;
		cin >> a >> b;
		chi[a].push_back(b);
		nPar[b]++;
	}

	// 根を求める
	// 子でない頂点を探す
	vector<bool> rootCand(N+1, true);
	for(int i = 1; i <= N; i++){
		int nChi = chi[i].size();
		rep(j, nChi) rootCand[chi[i][j]] = false;
	}

	int root;
	for(int i = 1; i <= N; i++){
		if(rootCand[i]) root = i;
	}

	dist = vector<int>(N+1, 0);
	ans = vector<int>(N+1, 0);

	dfs(root);

	for(int i = 1; i <= N; i++) cout << ans[i] << endl;
}


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

using namespace std;

int f = 0;

string str;
int pos;

bool formula() {
	bool res;
	if (str[pos] == '-') {
		++pos;
		res = !formula();
	}
	else if (str[pos] == '(') {
		++pos;
		bool left = formula();
		char c = str[pos]; if (c == '-') ++pos;
		++pos;
		bool right = formula();
		++pos;

		if (c == '*') res = left && right;
		else if (c == '+') res = left || right;
		else if (c == '-') res = !left || right;
		else assert(false);
	}
	else if (str[pos] == 'T') {
		++pos;
		res = true;
	}
	else if (str[pos] == 'F') {
		++pos;
		res = false;
	}
	else if ('a' <= str[pos] && str[pos] <= 'k') {
		int id = (int)(str[pos] - 'a');
		res = (f & (1 << id)) != 0;
		++pos;
	}
	else {
		assert(false);
	}
	return res;
}

bool parse() {
	pos = 0;
	bool left = formula();
	assert(str[pos] == '=');
	++pos;
	bool right = formula();
	return left == right;
}

int main() {
	while ( cin >> str, str != "#" ) {
		bool ans = true;
		for (int i = 0; i < (1 << 11); ++i) {
			f = i;
			if ( !parse() ) {
				ans = false;
				break;
			}
		}
		if (ans) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
}

Measured memory_bytes: 1212
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e9+7;
int main()
{
	long long n;
	cin>>n;
	vector<long long> h(n);
	for(long long i=0;i<n;i++){
		cin>>h[i];
	}
	// Initialise the vector elements with INF
	vector<long long> dp(n, INF);
	dp[0] = 0;
	for(long long i=0;i<n;i++){
		for(long long j=i+1;j<=i+2;j++){
			if(j<n)
				dp[j] = min(dp[j], dp[i]+abs(h[i]-h[j]));
		}
	}
	cout<<dp[n-1];
	return 0;
}

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

int d[35][35]={0};
int c[510][510]={0};
long long group[3][35]={0};

long long dfs(int n, int m, int color[],long long sum=0, long long answer=100000000000LL, int depth=0) {
    if (depth == min(n*n,3)) {
        return min(sum,answer);
    }
    for (int k=0;k<m;k++) {
        bool next = false;
        for (int i=0;i<depth;i++) {
            if (k==color[i])
                next = true;
        }
        if (next) continue;

        color[depth] = k;

        if (sum+group[depth][k] < answer)
        answer = dfs(n,m,color,sum+group[depth][k],answer,depth+1);

    }
    return answer;
}

int main() {
    int n, m;
    cin >> n >> m ;
    for (int i=0;i<m;i++)
        for (int j=0;j<m;j++)
            cin >> d[i][j];
    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++) {
            cin >> c[i][j];
            c[i][j] --;
        }

    for (int i=0;i<n;i++)
        for (int j=0;j<n;j++) {
            int g = ((i+1)+(j+1)) % 3;

            for (int k=0;k<m;k++)
                group[g][k] += d[c[i][j]][k];
        }

    int color[3];
    cout << dfs(n,m,color) << endl;
}

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

int main() {
  string n;
  cin >> n;
  int tot = 0;
  for (int i = 0; i < (int)(n.size()); i++) {
    tot += n[i] - '0';
  }
  string ans;
  int m = stoi(n);
  if (m % tot) {
    ans = "No";
  } else {
    ans = "Yes";
  } 
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

import scala.math._

object Main extends App {
  val sc = new Scanner(System.in)
  val N, K = sc.nextInt
  val h = Array.fill(N)(sc.nextInt)

  val dp = Array.fill(N)(Int.MaxValue)

  dp(0) = 0
  for (i <- 1 until N) {
    val dps = (1 to K).map(x => if (x <= i) dp(i - x) + abs(h(i) - h(i - x)) else Int.MaxValue)
    dp(i) = dps.min
  }
  println(dp.last)
}


Measured memory_bytes: 107428
#include<stdio.h>
#include<stdlib.h>

typedef struct indexNode{
  int v;
  int index;
} node;

int cmp(const void *a,const void *b){
  return ((node *)a)->v-((node *)b)->v;
}

void run(void){
  int n;
  scanf("%d",&n);
  node *a=(node *)calloc(n,sizeof(node));
  int i;
  for(i=0;i<n;i++){
    int v;
    scanf("%d",&v);
    a[i]=(node){v,i};
  }
  qsort(a,n,sizeof(node),cmp);
  int cnt=0;
  for(i=0;i<n;i++) if(i%2!=a[i].index%2) cnt++;
  printf("%d\n",cnt/2);
}

int main(void){
  run();
  return 0;
}


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

int a[1<<13],n;
int main() {
  cin >> n;
  for(int i=1; i<=(1<<n); i++) {
    for(int j=1; j<=(1<<n); j++) a[j]+=!(j%i);
  }
  for(int i=1; i<=(1<<n); i++) {
    if(a[i]==n) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 3124
from fractions import gcd
import numpy as np


def get_primes(n):
    ans = 1
    m = int(n**0.5) + 1
    flags = np.zeros(m + 1, dtype=bool)
    for i in range(2, m + 1):
        if flags[i]:
            continue
        if n % i == 0:
            ans += 1
        while n % i == 0:
            n //= i
        flags[i:m + 1:i] = 1
    if n > 1:
        ans += 1
    return ans


def solve(string):
    a, b = map(int, string.split())
    g = gcd(a, b)
    return str(get_primes(g))


if __name__ == '__main__':
    print(solve(input()))


Measured memory_bytes: 16204
import sys
n, k = map(int, sys.stdin.readline().split())

w = [int(sys.stdin.readline()) for _ in range(n)]
head = 0
tail = sum(w)
while head<tail-1:
    P = (head+tail)//2
    ld = 0 
    m = 1
    for u in w: 
        ld += u
        if ld>P: 
            m+=1 
            if k<m:    break 
            if u>P: break 
            ld = u
    else:
        tail=P
        continue
    head=P
    
print(tail)


Measured memory_bytes: 9564
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,j,n) for(int i = j; i < n; i++)
#define RFOR(i,j,n) for(int i = j-1; i >= n; i--)
#define PREC(n) fixed << setprecision(n)
#define print_array(v) REP(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define _LIBCPP_DEBUG 0
using namespace std;
int64_t MOD = 1000000007;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int i = s.size();
  while(true) {
    i--;
    if(i % 2 != 0) continue;
    string st = s.substr(0,i);
    int a = st.size() / 2;
    string st1 = st.substr(0,a);
    string st2 = st.substr(a,st.size());
    if(st1 == st2) { cout << i << endl; return 0; }
  }
  return 0;
}
//templete by private_yusuke

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  long double n;
  cin >> n;
  long double m = n / 2;
  if ((int)n % 2 == 1) m += 0.5;
  cout << m/n << endl;
}

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.length()/2; i++){
        if(s[i] != s[s.length()-1-i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
long long fac(ll a){
    long long ans=1;
    while(a>1){
        ans*=a;
        ans%=1000000007;
        a--;
    }
    return ans;
}
int main(){
    ll n,ans=0;cin >> n ;
    vector<int> v(n);
    rep(i,n)cin >> v[i];
    auto iter=max_element(all(v));
    int a = *iter;
    rep(i,a){
        int count=0;
        rep(j,n){
            if(v[j]!=0){
                while(v[j]!=0&&j<n)j++;
                count++;
            }
        }
        ans+=count;
        rep(j,n)v[j]=max(0,v[j]-1);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,T,c,t,ans=1001;
	scanf("%d%d",&n,&T);
	for(int i=1;i<=n;i++){
		scanf("%d%d",&c,&t);
		if(T>=t){
			ans=ans>c?c:ans;
		}
	}
	if(ans==1001) printf("TLE");
	else printf("%d",ans);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<math.h>

int main(void){
  int x, a, b, happy;
  scanf("%d",&x);
  
  a = x/500;
  x -= a*500;
  b = x/5;
  happy = a*1000 + b*5;  
  
  printf("%d",happy);
  return 0;
}

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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

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

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

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1) printEoln();
  if (suc == 2) printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U>
void chmax(T &a, U b) {
  if (a < b) a = b;
}

template <class T, class U>
void chmin(T &a, U b) {
  if (b < a) a = b;
}

template <class T>
T Sq(const T &t) {
  return t * t;
}

const int mod = 1e9 + 7;

int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

signed main() {
  int n;
  cin >> n;
  vi a(n + 1);
  for (int i = 1; i <= n; i++) a[i] = read();
  vi foward(n + 1);
  foward[1] = a[1];
  for (int i = 2; i < n; i++) foward[i] = gcd(a[i], foward[i - 1]);
  vi backward(n + 1);
  backward[n] = a[n];
  for (int i = n - 1; i > 1; i--) backward[i] = gcd(a[i], backward[i + 1]);
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    if (i == 1)
      chmax(ans, backward[2]);
    else if (i == n)
      chmax(ans, foward[n - 1]);
    else
      chmax(ans, gcd(foward[i - 1], backward[i + 1]));
  }
  print(ans);
}


Measured memory_bytes: 2560
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <string>
#include <numeric>
#include <stdio.h>

using namespace std;

const int inf = 1e9 + 7;

int main() {

	while (1) {
		int n, m;
		cin >> n >> m;
		if (n == 0 && m == 0) break;
		vector<char> a(m);
		for (int i = 0; i < m; i++) cin >> a[i];

		vector<int> dis(n, inf);
		// 順にやってけばいいのかな
		vector<char> ans(n, '#');
		for (int i = 0; i < m; i++) {
			if (a[i] == 'A') {
				// 左から座る
				for (int j = 0; j < n; j++) {
					if (ans[j] == '#') {
						ans[j] = a[i];
						break;
					}
				}
			}
			else if (a[i] == 'B') {
				// 右から座る
				bool ok = false;
				for (int j = n - 1; j >= 0; j--) {
					if (ans[j] == '#') {
						// 隣がA国人か
						if (j + 1 < n) if (ans[j + 1] == 'A')continue;
						if (j - 1 >= 0) if (ans[j - 1] == 'A') continue;
						ans[j] = a[i];
						ok = true;
						break;
					}
				}
				if (!ok) { // まだ座れてなかったら
					for (int j = 0; j < n; j++) {
						if (ans[j] == '#') {
							ans[j] = a[i];
							break;
						}
					}
				}
			}
			else if (a[i] == 'C') {
				if (i == 0) {
					// 始めの人
					if (n % 2 == 1) ans[(n + 1) / 2 - 1] = a[i];
					else ans[n / 2] = a[i];
					continue;
				}
					// 左から人がいるかみてく
				for (int j = 0; j < n; j++) {
					if (ans[j] != '#') {
						bool ok = false;
						if (j + 1 < n) {
							if (ans[j + 1] == '#') {
								ans[j + 1] = a[i];
								ok = true;
								break;
							}
						}
						if (j - 1 >= 0) {
							if (ans[j - 1] == '#') {
								ans[j - 1] = a[i];
								ok = true;
								break;
							}
						}
						if (!ok) continue;
					}
				}
			}
			else if (a[i] == 'D') {
				if (i == 0) {
					ans[0] = a[i];
					continue;
				}
				// 一番近い人との距離をそれぞれ求める
				// 左右両方から調べる
				int cnt = inf - n;
				for (int j = 0; j < n; j++) {
					if (ans[j] != '#') {
						dis[j] = 0;
						cnt = 0;
					}
					else {
						dis[j] = ++cnt;
					}
				}
				// 反対からも
				for (int j = n - 1; j >= 0; j--) {
					if (ans[j] != '#') {
						cnt = 0;
					}
					else {
						dis[j] = min(++cnt, dis[j]);
					}
				}

				// 一番遠いい点を探す
				int jmax = -1;
				int dismax = -1;
				for (int j = 0; j < n; j++) {
					if (dismax < dis[j]) {
						jmax = j;
						dismax = dis[j];
					}
				}

				ans[jmax] = a[i];
			}
		}

		for (int i = 0; i < n; i++) {
			cout << ans[i];
		}
		cout << endl;
	}

	return 0;
}


Measured memory_bytes: 2992
#define REP(i, t, n)  for (int i = t; i < n; i++)
#define ALL(n)        (n).begin(),(n).end()
#include <limits.h>
#include <stdio.h>
#include <cmath>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <deque>
#include <functional>
#include <algorithm>
#include <cstring>
#include <unordered_map>
#include <numeric>

using namespace std;

typedef bool               BOOL;
typedef short              WORD;
typedef unsigned short     U_WORD;
typedef long               DWORD;
typedef unsigned long      U_DWORD;
typedef long long          QWORD;
typedef unsigned long long U_QWORD;

void solve_main()
{
	DWORD N, D;
	DWORD dwAns = 0;
	DWORD dwNowTree = 0;
	cin >> N >> D;

	while (dwNowTree < N) {
		dwAns++;
		dwNowTree += ((2 * D) + 1);
	}

	cout << dwAns << endl;
}

int main()
{
#ifdef FOR_IDE
	ifstream in("input.txt");
	cin.rdbuf(in.rdbuf());
#endif

	solve_main();
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int a,b,c=0;
  int x[]={1,3,5,7,8,10,12},y[]={4,6,9,11};
  scanf("%d %d",&a,&b);
  for(int i=0;i<7;i++)if(x[i]==a)for(int j=i;j<7;j++)if(x[j]==b)c=1;
  for(int i=0;i<4;i++)if(y[i]==a)for(int j=i;j<4;j++)if(y[j]==b)c=1;
  (c==1)?puts("Yes"):puts("No");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false); cin.tie(NULL);

#define endl '\n'
#define D(x) cout << #x << " = " << (x) << endl;

int main() { IO;
  int n, m, c;
  cin >> n >> m >> c;

  vector<int> b(m + 1);
  for (int i = 1; i <= m; ++i) {
    cin >> b[i];
  }

  int ans = 0;
  while (n--) {
    int sum = c;
    for (int i = 1; i <= m; ++i) {
      int a;
      cin >> a;
      sum += b[i] * a;
    }

    if (sum > 0) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fr first
#define sc second
typedef pair<int,int> pii;
typedef vector<int> vi;
const int INF = (1<<25);
const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int p[31]={0};
int q[31]={0,1,1,1,1,1,1,1,1,1,2,2,2,4,4,4,6,6,6,5,5,5,3,3,3,3,3,3,3,3,3};
int ret=8;

void a(){
  swap(p[1],p[28]);
  swap(p[2],p[29]);
  swap(p[3],p[30]);
  swap(p[15],p[16]);
  swap(p[19],p[21]);
}

void b(){
  swap(p[3],p[22]);
  swap(p[6],p[25]);
  swap(p[9],p[28]);
  swap(p[12],p[19]);
  swap(p[13],p[15]);
}

void c(){
  swap(p[7],p[22]);
  swap(p[8],p[23]);
  swap(p[9],p[24]);
  swap(p[13],p[18]);
  swap(p[10],p[12]);
}

void d(){
  swap(p[1],p[24]);
  swap(p[4],p[27]);
  swap(p[7],p[30]);
  swap(p[10],p[21]);
  swap(p[16],p[18]);
}

void solve(int num){
  int cnt=0;
  for(int i=1;i<31;i++){
    if(p[i]==q[i]) cnt++;
  }

  if(cnt==30) ret=num;
  if(ret<=num) return;
  a();solve(num+1);a(); 

  if(ret<=num) return;
  b();solve(num+1);b(); 

  if(ret<=num) return;
  c();solve(num+1);c(); 

  if(ret<=num) return;
  d();solve(num+1);d(); 

  if(ret<=num) return;
}  
int main(){
  int n;
  cin>> n;
  while(n--){
    for(int i=1;i<31;i++){
      cin>> p[i];
    }

    ret=8;
    solve(0);
    cout<< ret<< endl;
  }
}

Measured memory_bytes: 1164