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

using ll = long long int;

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

const int MAX_N = (int)(1e4 + 5);
const ll MOD = (ll)(1e9 + 7);

/////////////////////////////////////////////////////////////
class ModuloOperator {
 public:
  ll modulo;

  ModuloOperator(ll modulo) { this->modulo = modulo; }

  ll add(ll a, ll b) {
    ll ret = a + b;
    ret %= modulo;
    return ret;
  }

  ll sub(ll a, ll b) {
    ll ret = a - b;
    if (ret < 0)
      ret += modulo;
    else
      ret %= modulo;
    return ret;
  }

  ll mul(ll a, ll b) {
    ll ret = a * b;
    ret %= modulo;
    return ret;
  }

  ll div(ll a, ll b) { return mul(a, pow(b, modulo - 2)); }

  ll pow(ll x, ll y) {
    ll res = 1LL;

    x %= modulo;

    while (y > 0) {
      if (y & 1) {
        res = mul(res, x);
      }

      y = y >> 1;
      x = mul(x, x);
    }

    return res;
  }
};
/////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////
map<ll, ll> prime_factorization(ll n) {
  map<ll, ll> res;
  for (ll i = 2; i * i <= n; ++i) {
    while (n % i == 0) {
      res[i] += 1;
      n /= i;
    }
  }
  if (n != 1) res[n] = 1;
  return res;
}
/////////////////////////////////////////////////////////////

int n;
ll a[MAX_N];

ModuloOperator mo(MOD);

void update_lcm(unordered_map<ll, ll>& lcm, ll target) {
  auto primes = prime_factorization(target);

  for (auto& e : primes) {
    lcm[e.first] = max(lcm[e.first], e.second);
  }
}

ll calc_actual(unordered_map<ll, ll>& lcm) {
  ll ret = 1LL;

  for (auto& e : lcm) {
    ll power = mo.pow(e.first, e.second);

    ret = mo.mul(ret, power);
  }

  return ret;
}

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

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

  unordered_map<ll, ll> lcm;

  for (int i = 0; i < n; ++i) {
    update_lcm(lcm, a[i]);
  }

  ll ans = 0LL;

  ll lcm_actual = calc_actual(lcm);

  for (int i = 0; i < n; ++i) {
    ans = mo.add(ans, mo.div(lcm_actual, a[i]));
  }

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

  return 0;
}


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

const int n_MAX = 100;
const int m_MAX = 100;
int A[n_MAX][m_MAX];
int B[m_MAX];

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

	for (int N = 0; N < n; N++){
		for (int M = 0; M < m; M++){
			cin >> A[N][M];
		}
	}
	for (int M = 0; M < m; M++){
		cin >> B[M];
	}

	for (int i = 0; i < n; i++){
		int c = 0;
		for (int j = 0; j < m; j++){
			c += A[i][j] * B[j];
		}
		cout << c << endl;
	}

	return 0;
}


Measured memory_bytes: 3112
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

class Main {

    static int[] makePrimes( final int max ) {

	final boolean[] isPrime = new boolean[ max + 1 ];
	Arrays.fill( isPrime, true );
	isPrime[ 0 ] = isPrime[ 1 ] = false;
	for ( int i = 0; i * i <= max ; i++ ) {
	    if ( isPrime[ i ] ) {
		for ( int j = i * i; j <= max; j += i ) {
		    isPrime[ j ] = false;
		}
	    }
	}
	int size = 0;
	for ( final boolean val : isPrime ) {
	    if ( val ) size++;
	}
	final int[] primes = new int[ size ];
	int index = 0;
	for ( int i = 0; i <= max; i++ ) {
	    if ( isPrime[ i ] ) {
		primes[ index++ ] = i;
	    }
	}
	return primes;
    }
    
    public static void main( final String[] args ) {

	final Scanner stdin = new Scanner( System.in );
	final int[] primes = makePrimes( 123456 * 2 );

	while ( true ) {
	    final int n = stdin.nextInt();
	    if ( n == 0 ) break;
	    final int tmpFromI = Arrays.binarySearch( primes, n );
	    final int fromI = tmpFromI >= 0 ? tmpFromI :-tmpFromI - 1 - 1;
	    final int tmpToI = Arrays.binarySearch( primes, n * 2 );
	    final int toI = tmpToI >= 0 ? tmpToI : -tmpToI - 1 - 1;
	    System.out.println( toI - fromI );
	}
    }    
}

Measured memory_bytes: 22964
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define lp(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int a[12];
  rep(i,12) cin>>a[i];
  sort(a,a+12);
  for(int i=0;i<12;i+=4){
    for(int j=i;j<i+4;j++){
      if(a[i]!=a[j]){cout<<"no"<<endl;return 0;}
    }
  }
  cout<<"yes"<<endl;
      

  return 0;
}



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

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

using namespace std;

typedef pair<int, int> P;

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

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

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

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

    int n;
    cin >> n;
    auto edge = initVec2<P>(n + 1, 0);
    rep(i, n - 1){
        int u, v, w;
        cin >> u >> v >> w;
        edge[u].emplace_back(v, w);
        edge[v].emplace_back(u, w);
    }

    vector<int> ans(n + 1);
    stack<P> st;
    st.emplace(1, 0);

    while(not st.empty()){
        int v = st.top().first;
        int per = st.top().second;
        st.pop();

        for(P p : edge[v]){
            int u = p.first;
            int w = p.second;
            if(u == per){
                continue;
            }
            if(w % 2){
                ans[u] = (ans[v] + 1) % 2;
            }else{
                ans[u] = ans[v];
            }
            st.emplace(u, v);
        }
    }

    rep(i, n){
        cout << ans[i+1] << endl;
    }

    return 0;
}


Measured memory_bytes: 8704
import java.util.*;
public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int ans = 0;
		Map<Integer,Integer>[] list = new Map[N];
		for(int i = 0;i < N;i++){
			int A = sc.nextInt();
			Map<Integer,Integer> maps = new HashMap<>();
			for(int j = 0;j < A;j++){
				int x = sc.nextInt() - 1;
				int y = sc.nextInt();
				maps.put(x,y);
			}
			list[i] = maps; 
		}
		for(int i = 0;i < 1<<N;i++){
			boolean flg = true;
			int[] people = new int[N];
			int buf = 0;
			for(int j = 0;j < N;j++){
				if((1 & i>>j) == 1){
					people[j] = 1;
					buf++;
				}
			}
			for(int j = 0;j < N;j++){
				if(people[j] == 1){
					for(int key : list[j].keySet()){
						if(people[key] != list[j].get(key)){
							flg = false;
						}
					}
				}
			}
			if(flg){
				ans = Math.max(ans,buf);
			}
		}
		System.out.println(ans);
	}
}

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


using namespace std;

typedef long long ll;

#define pi 2*acos(0.0)
#define eps 1e-9
const int N = 1e7+1;
bool isprime[N];

void sieve()
{
    memset(isprime,true,sizeof(isprime));
    isprime[0]=isprime[1]=false;

    for(ll i=2; i*i<=N; i++)
    {
        if(isprime[i])
        {
            for(ll j=i*i; j<=N; j+=i)
            {
                isprime[j]=false;
            }
        }
    }
}
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);


    string a,b;
    cin>>a>>b;
    if(a.size()==b.size())
    {
        if(a>b)
        {
            cout<<"GREATER\n";
        }
        else if(a<b)
        {
            cout<<"LESS\n";
        }
        else
        {
            cout<<"EQUAL\n";
        }
    }
    else if(a.size()>b.size())
    {
        cout<<"GREATER\n";
    }
    else
    {
        cout<<"LESS\n";
    }


}




Measured memory_bytes: 3596
#include <iostream>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
const ll MAX = 20000;
constexpr ll nx[8] = {1,0,-1,0,-1,-1,1,1};
constexpr ll ny[8] = {0,1,0,-1,-1,1,-1,1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m,u,v,s,t;
    cin >> n >> m;
    vector<vector<ll>> g(3*n);
    vector<ll> d(3*n,-1);
    rep(i,m){
        cin >> u >> v;
        --u;
        --v;
        g[3*u].push_back(3*v+1);
        g[3*u+1].push_back(3*v+2);
        g[3*u+2].push_back(3*v);
    }
    cin >> s >> t;
    --s;
    --t;
    d[3*s] = 0;
    queue<ll> q;
    q.push(3*s);
    while(!q.empty()){
        ll x;
        x = q.front();
        q.pop();
        for(ll i:g[x]){
            if (d[i] != -1) continue;
            d[i] = d[x]+1;
            q.push(i);
        }
    }
    if (d[3*t] != -1) PRINT(d[3*t]/3);
    else PRINT(-1);
}




Measured memory_bytes: 19072
N=int(input())
B=list(map(int,input().split()))
A=[0]*N
if N==2:
  print(sum(B)*2)
  exit()
for i in range(1,N-1):
  A[i]=min(B[i-1],B[i])
A[0]=max(A[1],B[0])
a=sum(A)+B[N-2]
print(a)

Measured memory_bytes: 3064
a, b, h, m = gets.chomp.split.map(&:to_i)

hh = 30 * h + 0.5 * m
mm = 6 * m

C = (hh - mm).abs
if C == 180
  p a+b
elsif C == 0
  p (a-b).abs
else
  p Math.sqrt(a*a + b*b - 2*a*b*Math.cos(C*Math::PI/180))
end

Measured memory_bytes: 14728
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define MSET(x,y) memset(x,y,sizeof(x))
#define M 100005
using namespace std;
using LL = long long;
using P = pair<int,int>;
class DSJ {
public:
    int ngroups;
    vector<int> fa,sz;
    DSJ() {}
    DSJ(int _n) {
        ngroups = _n;
        fa = vector<int> (_n+1);
        sz = vector<int> (_n+1, 1);
        REP(i,0,_n) fa[i] = i;
    }
    int find(int x) {
        return x==fa[x] ? x : fa[x]=find(fa[x]);
    }
    int size(int x) {
        return sz[find(x)];
    }
    void con(int x,int y) {
        x = fa[x];
        y = fa[y];
        if (x==y) return;
        fa[x] = y;
        sz[y] += sz[x];
        ngroups--;
    }
    int groups() {
        return ngroups;
    }
};
int n,m;
P in[M];
LL ans[M];
DSJ dsj;
int main()
{
    while (~scanf("%d %d",&n,&m)) {
        dsj = DSJ(n);
        LL sum = (LL)n*(n-1)/2LL;
        REP(i,1,m) scanf("%d %d",&in[i].first,&in[i].second);
        
        ans[m] = sum;
        for (int i=m; i>=1; i--) {
            int x = dsj.find(in[i].first);
            int y = dsj.find(in[i].second);
            if (x!=y) {
                sum -= (LL)dsj.size(x) * dsj.size(y);
                dsj.con(x,y);
            }
            ans[i-1] = sum;
        }

        REP(i,1,m) printf("%lld\n", ans[i]);
    }
    
    return 0;
}



Measured memory_bytes: 3712
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n;cin>>n;
    ll a[n],sum=0;
    for(ll i=0;i<n;i++)cin>>a[i],sum+=a[i];
    ll tot = (n*(n+1))/2;
    if(sum%tot)return cout<<"NO" , 0;
    ll k = sum/tot;
    //cout<<"K: "<<k<<endl;
    for(ll i=0;i<n;i++){
        ll diff = a[(i+1)%n] - a[i];
        ll val = k - diff;
        if(val>=0 && val%n==0)continue;
        return cout<<"NO" , 0;
    }
    cout<<"YES";
}


Measured memory_bytes: 1024
//https://atcoder.jp/contests/abc126/tasks/abc126_b

import java.io.*;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String S = br.readLine();
        String pre = String.valueOf(S.charAt(0))+String.valueOf(S.charAt(1));
        String rear = String.valueOf(S.charAt(2))+String.valueOf(S.charAt(3));
        String ans;
        if (pre.equals("00") || Integer.parseInt(pre)>12){
            if (rear.equals("00") || Integer.parseInt(rear)>12){
                ans = "NA";
            } else {
                ans = "YYMM";
            }
        } else {
            if (rear.equals("00") || Integer.parseInt(rear)>12){
                ans = "MMYY";
            } else {
                ans = "AMBIGUOUS";
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 20948
#include <stdio.h>
using namespace std;

int A, P;
int a;


int main(){
  if(scanf("%d %d", &A, &P)==1);
  a = 3*A + P;
  
  if(a%2==0){
    printf("%d", a/2);
  }
  if(a%2==1){
    printf("%d", (a-1)/2);
  }
 
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>

#define W 0
#define G 1
#define B 2
#define N 100
#define INF 1000000000

int n;
int M[N][N];

void dijkstra();

int main(){
  int i,j,k,a,b,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j]=INF;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&a,&k);

    for(j=0;j<k;j++){
      scanf("%d%d",&b,&c);
      M[a][b]=c;
    }
  }

  dijkstra();

  return 0;
}

void dijkstra(){
  int i;
  int min,u,v;
  int d[N],color[N];

  for(i=0;i<n;i++){
    d[i]=INF;
    color[i]=W;
  }

  d[0]=0;
  color[0]=G;

  while(1){
    min=INF;
    u=-1;
    for(i=0;i<n;i++){
      if(min>d[i] && color[i]!=B){
	u=i;
	min=d[i];
      }
    }

    if(u==-1) break;
    color[u]=B;
    for(v=0;v<n;v++){
      if(color[v]!=B && M[u][v]!=INF){
	if(d[v] > d[u]+M[u][v]){
	  d[v]=d[u]+M[u][v];
	  color[v]=G;
	}
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d ",i);
    if(d[i]==INF) printf("-1\n");
    else printf("%d\n",d[i]);
  }
}



Measured memory_bytes: 2036
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n, m;
  cin >> n >> m;
  ll a = 0;
  rep(i, 0, m) {
    int x;
    cin >> x;
    a += x;
  }

  if (a <= n)
    cout << n - a << endl;
  else
    cout << -1 << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define file_se_input  freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define pp long long int
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned long long int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


bool check_prime(long long n)
{
	int flag = 0;
	for (long long i = 2; i * i <= n; i++)
	{
		if (n % i == 0)
		{
			flag = 1;
			break;
		}
	}
	if (n == 1)
		return false;
	else if (flag == 0 || n == 2 || n == 3)
	{
		return true;
	}
	else
	{
		return false;
	}

}

int BE(int x, int n, int m) //function to calculate x raise to power n modulo m
{
	int result = 1;
	while (n > 0)
	{
		if (n % 2 == 1)
			result = result * x % m;
		x = x * x % m;
		n = n / 2;
	}
	return result;
}

int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int n;
	cin >> n;
	int p[n], q[n];
	zip(i, 0, n) cin >> p[i];
	zip(i, 0, n)  cin >> q[i];
	int a1 = 0, b1 = 0;
	int a[n];
	rep(i, 0, n - 1)  a[i] = i + 1;
	int i = 0;
	while (next_permutation(a, a + n))
	{
		i++;
		int flag = 0;
		zip(j, 0, n)
		{
			if (a[j] != p[j])
			{
				flag = 1;
				break;
			}
		}
		if (flag == 0)
		{
			a1 = i;
		}

		flag = 0;
		zip(j, 0, n)
		{
			if (a[j] != q[j])
			{
				flag = 1;
				break;
			}
		}
		if (flag == 0)
		{
			b1 = i;
		}

	}
	cout << abs(a1 - b1) << en;


	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <stdio.h>
#include<vector>
#include<climits>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<functional>
#include <numeric>
#include <map>
#define FORi(N) for(int i=0;i<N;++i)
#define FORj(N) for(int j=0;j<N;++j)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
ll gcd(ll m,ll n){
  if(n==0)return abs(m);
  return(gcd(n,m%n));
}
void putYN(bool b){
  if(b){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}
int main(){
  ll N;
  cin>>N;
  vector<ll> a,b;
  bool flag =true;
  FORi(N/2){
     if(flag){
       a.push_back(i+1);
       a.push_back((N/2)*2-i);
     }
  }
  if(N%2==1){
    a.push_back(N);
    a.push_back(0);
  }
  stringstream sout;
  ll count = 0;
  FORi(a.size()/2-1){
    count+=2;
    sout<<a[i*2]<<" "<<a[(i+1)*2]<<endl;
    sout<<a[i*2+1]<<" "<<a[(i+1)*2]<<endl;
    if(a[(i+1)*2+1]!=0){
      count+=2;
      sout<<a[i*2]<<" "<<a[(i+1)*2+1]<<endl;
      sout<<a[i*2+1]<<" "<<a[(i+1)*2+1]<<endl;
    }
  }
  if(a.size()>=6){
    count+=2;
    sout<<a[0]<<" "<<a[a.size()-2]<<endl;
    sout<<a[1]<<" "<<a[a.size()-2]<<endl;
    if(a[a.size()-1]!=0){
      count+=2;
      sout<<a[0]<<" "<<a[a.size()-1]<<endl;
      sout<<a[1]<<" "<<a[a.size()-1]<<endl;
    }
  }
  cout<<count<<endl;
  cout<<sout.str();
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <numeric>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <functional>
#include <complex>
#include <stack>
#include <tuple>
using namespace std;
#define rep(i,n) for (int i=0; i < (n); i++)


typedef long long int ll;
typedef double D;      // ??§?¨?????????????double???long double?????????
typedef complex<D> P;  // Point
typedef pair<P, P> L;  // Line
typedef vector<P> VP;


const int INF = (1<<30) - 1;
const D EPS = 1e-9;

#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)

int N, M, K;

void solve(){
    vector<int> next_stones(N);
    for(int i=0; i<N; i++)
        next_stones[i] = (i+1)%N;
    
    //first-remove
    int cur = M-1;
    int pcur = (cur-1+N)%N;
    int remained_stone = N;
    
    while(remained_stone-- > 1){
        next_stones[pcur] = next_stones[cur];
        for(int i=0; i<K; i++){
            pcur = cur;
            cur = next_stones[cur];
        }
    }
    cout << cur+1 << endl;
}

//g++ -std=c++0x -msse4.2 -O3
//#include <bits/stdc++.h>
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    while(cin>>N>>K>>M, N|K|M)
        solve();
    
    return 0;
}

Measured memory_bytes: 1232
H,W = map(int,input().split())
N = int(input())
A = list(map(int,input().split()))

ans = [[-1] * W for _ in range(H)]

from itertools import cycle
v = cycle([(1,0),(0,1),(-1,0),(0,-1)])

def nextxy(x,y,nv):
    return x+nv[0],y+nv[1]

nv = next(v)
x,y = 0,0
for i,a in enumerate(A):
    while a > 0:
        ans[y][x] = i+1
        a -= 1
        nx, ny = nextxy(x,y,nv)
        if nx < 0 or W <= nx or ny < 0 or ny >= H or ans[ny][nx] != -1:
            nv = next(v)
        x, y = nextxy(x,y,nv)
        
for j in range(H):
    print(' '.join(map(str,ans[j])))


Measured memory_bytes: 3572
# Problem
# Python 2nd Try
import sys


def solver(yen500, yen100, yen050, sumX):
    result = 0
    for j in range(0, yen500+1, +1):
        for k in range(0, yen100+1, +1):
            for m in range(0, yen050+1, +1):
                totalsum = j*500+k*100+m*50
                if sumX == totalsum:
                    result = result + 1
    return result


if __name__ == "__main__":
    A = int(sys.stdin.readline())
    B = int(sys.stdin.readline())
    C = int(sys.stdin.readline())
    X = int(sys.stdin.readline())
    # print(A, B, C, X, sep="\n")
    print("{}".format(solver(A, B, C, X)))


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define int long long
#define p pair<int, int>
#define endl '\n'
const int INF = 1000000001;
const long double E = 0.00000001;

using namespace std;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, max1 = 0;
    cin >> n;
    vector<int> a(n);
    for (int q = 0; q < n; q++){
        cin >> a[q];
        max1 = max(max1, a[q]);
    }
    vector<int> s(max1+1, 0);
    for (int q = 0; q < n; q++){
        s[a[q]]++;
    }
    int ans = 0;
    for (int q: a){
        if (s[q] > 1){
            continue;
        }
        if (q == 1){
            ans++;
            continue;
        }
        if (s[1] > 0){
            continue;
        }
        int sqrt1 = sqrt(q);
        bool flag = true;
        for (int q1 = 2; q1 <= sqrt1; q1++){
            if (q % q1 == 0 && s[q1]+s[q/q1] > 0){
                flag = false;
                break;
            }
        }
        ans += flag;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12704
<?php
list($h, $w) = ints();
if ($h % 3 === 0 || $w % 3 === 0) exit('0');
$min = PHP_INT_MAX;

$min = min($min, $w * (intdiv($h, 3) + 1) - $w * intdiv($h, 3));
$min = min($min, $h * (intdiv($w, 3) + 1) - $h * intdiv($w, 3));

$s = [intdiv($w, 3) * $h, intdiv($h, 2) * ($w - intdiv($w, 3)), ($h - intdiv($h, 2)) * ($w - intdiv($w, 3))];
$min = min($min, max($s) - min($s));
$s = [(intdiv($w, 3) + 1) * $h, intdiv($h, 2) * ($w - (intdiv($w, 3) + 1)), ($h - intdiv($h, 2)) * ($w - (intdiv($w, 3) + 1))];
$min = min($min, max($s) - min($s));
$s = [intdiv($h, 3) * $w, intdiv($w, 2) * ($h - intdiv($h, 3)), ($w - intdiv($w, 2)) * ($h - intdiv($h, 3))];
$min = min($min, max($s) - min($s));
$s = [(intdiv($h, 3) + 1) * $w, intdiv($w, 2) * ($h - (intdiv($h, 3) + 1)), ($w - intdiv($w, 2)) * ($h - (intdiv($h, 3) + 1))];
$min = min($min, max($s) - min($s));
echo $min;
function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}


Measured memory_bytes: 4604
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
//#include"Bignum/bignum.h"
//#define big bignum
#define lowbit(x) (x & -x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define Set(x, i) memset (x, i, sizeof(x))
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 100011;
const ll INF = 5e16;

/*
	设 Len[i][j] 表示从 S 到 i ，经过距离 % 3 为 j 走的步数。 
*/

namespace IO {

	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) +
			fread (buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}

	#define dd ch = getchar()
	inline ll read() {
		R ll x = 0; R int f = 0; R char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write (x); putchar (' '); }

	inline void wln ( ll x ) { write (x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn (x), wln (y); }

}

using IO::wln;
using IO::read;

namespace Cesare {
	
	ll n, m, S, T, Ans, Vis[N][4], Len[N][4];
	
	struct Node {
		ll u, w;
	};
	
	queue <Node> Q;
	vector <ll> E[N];
	
	inline ll Add ( ll x ) { return ++x >= 3? x - 3: x; }
	
	inline ll Dijkstra() {
		Set (Len, 0x3f);
		Q.push((Node) {S, Len[S][0] = 0}); 
		while (!Q.empty()) {
			Node T = Q.front(); Q.pop();
			if (Vis[T.u][T.w]) continue; 
			Vis[T.u][T.w] = 1;
			For ( i, 1, E[T.u].size() ) {
				ll v = E[T.u][i - 1];
				if (Len[v][Add(T.w)] > Len[T.u][T.w] + 1) {
					Len[v][Add(T.w)] = Len[T.u][T.w] + 1;
					Q.push((Node) {v, Add(T.w)});
				}
			}
		} return Len[T][0] > INF? -1: Len[T][0] / 3;
	}

	int main() {
		n = read(), m = read();
		for (R int i = 1, u, v; i <= m; ++i) 
			u = read(), v = read(), E[u].push_back(v);
		S = read(), T = read();
		return wln (Dijkstra()), 0;
	}
	
}

int main()
{
	return Cesare::main();
}

/*

*/






Measured memory_bytes: 11904
N = int(input())

from math import factorial
num_divide = factorial(N)

divided = False

factor_dict = {}

for i in range(2, N + 1):
    for t in range(2, i + 1):
        
        while i % t == 0:
        
            i /= t
            if t not in factor_dict:
                factor_dict[t] = 1
            else:
                factor_dict[t] += 1

        if i == 1:
            break

count = 1
for key, value in factor_dict.items():
    count *= value + 1
    count %= (1000000007)
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#define il inline
#define ri register
#define Size 600050
using namespace std;
namespace{
	template<class free>
		il void read(free&x){
		x^=x;ri char c;while(c=getchar(),c==' '||c=='\n'||c=='\r');
		ri bool check(false);if(c=='-')check=true,c=getchar();
		while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
		if(check)x=~x+1;
	}
	template<class f1,class...f2>
		il void read(f1&x,f2&...y){
		read(x),read(y...);
	}
}
struct point{
	int next,to;
}ar[Size];
bool is[Size];
int head[Size],art(1);
int son[2][Size],rt[2],a[Size];
il void link(int,int),dfs(int);
int main(){
	//freopen("in","r",stdin);
	//freopen("out","w",stdout);
	int n;read(n);
	for(int i(1),j;i<=n;++i)
		read(j),~j?link(j,i),
			++son[0][j]:rt[0]=i;
	for(int i(1),j;i<=n;++i)
		read(j),~j?link(j+n,i+n),
			++son[1][j]:rt[1]=i+n;
	link(rt[0],rt[1]);
	for(int i(1);i<=n;++i){
		if(son[0][i]+son[1][i]&1)
			return puts("IMPOSSIBLE"),0;
		if(~son[0][i]&1)link(i,i+n),a[i]=art;
	}dfs(1),puts("POSSIBLE");
	for(int i(1);i<=n;++i)
		if(son[0][i]&1)puts("0");
		else puts(is[a[i]]?"-1":"1");
	return 0;
}
il void dfs(int x){
	for(int i(head[x]);i;i=head[x])
		if(head[x]=ar[head[x]].next,!is[i])
			is[i^1]=1,dfs(ar[i].to);
}
il void link(int u,int v){
	ar[++art]={head[u],v},head[u]=art;
	ar[++art]={head[v],u},head[v]=art;
}


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

int main(){
string S;
  cin>>S;
  
  int sum=0;

int r=15-S.size();
  
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='o'){
      sum++;
    }
  }
  
  if(sum+r>=8){
    cout<<"YES"<<endl;
  }
  else {
    cout<<"NO"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
typedef long long ll;
int main(){
    int n;
    cin >> n;
    vector<ll> a(n+2);
    vector<ll> dp(n+2);
    rep(i,n){
        cin >> a[i+1];
        dp[i+1] = dp[i]+abs(a[i]-a[i+1]);
    }
    a[n+1] = 0;
    dp[n+1] = dp[n]+abs(a[n]);
    for(int i = 1;i<=n;i++){
        cout << dp[i-1]+abs(a[i+1]-a[i-1])+dp[n+1]-dp[i+1]<<endl;
    }
    return 0;
}

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

int main() {
  int H,W;
  cin>>H>>W;
  int C[10][10];
  for(int i=0;i<10;i++){
    for(int j=0;j<10;j++){
      cin>>C[i][j];
    }
  }

  for(int j=0;j<10;j++){
    for(int k=0;k<10;k++){
      for(int i=0;i<10;i++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }   
  for(int j=0;j<10;j++){
    for(int k=0;k<10;k++){
      for(int i=0;i<10;i++){
        if(C[i][j]>C[i][k]+C[k][j]) C[i][j]=C[i][k]+C[k][j];
      }
    }
  }   

  int temp;
  int ans=0;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>temp;
      if(temp != -1) ans+=C[temp][1];
    }
  }
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
using namespace std;

typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
const int SIZE = 100005;

int N, M, L, R, D;
vector<pii> adj[SIZE];
bool visited[SIZE];
long long int pos[SIZE];
bool isEnd;

void search(int here){
	visited[here] = true;
	for(int i=0; i<adj[here].size(); ++i){
		int next = adj[here][i].first;
		int dist = adj[here][i].second;
		if(visited[next]){
			if(pos[next] != pos[here] + dist){
				isEnd = true;
			}
		}
		else{
			pos[next] = pos[here] + dist;
			search(next);
		}
	}
}

int main(){
	scanf("%d %d", &N, &M);
	for(int i=0; i<M; ++i){
		scanf("%d %d %d", &L, &R, &D);
		adj[L].push_back({R, D});
		adj[R].push_back({L, -D});
	}
	for(int i=1; i<=N; ++i){
		if(!visited[i])
			search(i);
	}
	if(isEnd)
		printf("No\n");
	else
		printf("Yes\n");
	
}


Measured memory_bytes: 12416
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

#define PI 3.1415926535
using namespace std;

int main()
{
	int X, Y, Z;
	cin >> X >> Y >> Z;
	
	cout << Z << " " << X << " " << Y << endl;	

	return 0;

}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <algorithm>
#include <utility>
using namespace std;
int main() {
	int K; 
	cin >> K; 
	int A[512][512] = {}; 
        int N = 0; 
	if(K == 1){N = 1; A[0][0] = 1;} 
    else if(K == 2){N = 2; A[0][0] = 1; A[0][1] = 2; A[1][0] = 2; A[1][1] = 1;}
 	else{
		N = ((K + 3) / 4) * 2; 
		for(int i = 0; i < N; i++){
			for(int j = 0; j < N; j++){
				A[i][j] = ((N + j - i) % N) * 2 + 1; 
				if(i % 2 == 1){A[i][j] ++;}
				if(K % 4 == 3 && A[i][j] == N * 2){A[i][j] = N * 2 - 1;}
                if(K % 4 == 2 && (A[i][j] == N * 2 || A[i][j] == N * 2 - 1))
                	{A[i][j] = N * 2 - 2;}
                else if(K % 4 == 2 && (A[i][j] == N * 2 - 2|| A[i][j] == N * 2 - 3))
                	{A[i][j] = N * 2 - 3;}
              	if(K % 4 == 1 && (A[i][j] == N * 2 || A[i][j] == N * 2 - 1))
                	{A[i][j] = N * 2 - 3;}
                else if(K % 4 == 1 && (A[i][j] == N * 2 - 2|| A[i][j] == N * 2 - 3))
                	{A[i][j] = N * 2 - 4;}
                else if(K % 4 == 1 && (A[i][j] == N * 2 - 4|| A[i][j] == N * 2 - 5))
                	{A[i][j] = N * 2 - 5;}
			}
		}
	}
	cout << N << endl; 
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			cout << A[i][j] << " "; 
		}
		cout << endl; 
	}
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main () {
    int a, b, c;
    cin >> a >> b >> c;
    if (((a < c) && (c < b)) || ((b < c) && (c < a))) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 3536
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>
#include <fstream>
#include <functional>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 1000000000
//#define NCONS 100001
//#define NCONS 1001
//#define NCONS 101
#define MCONS 2001
#define LIMIT 1000000000
#define TRUE 1
#define FALSE 0
#define toRadian(degree) ((degree) * (M_PI / 180.))
#define toDegree(radian) ((radian) * (180. / M_PI))
using namespace std;
struct Point{int x; int y;};
struct PPoint{Point x; Point y;};
inline ll gcd(ll a, ll b) { if(a < b) swap(a, b); if(b <= 0) return a; return gcd(b, a % b); }


int N, K;
vector<int> vec;
ll ret;
int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    cin >> N >> K;
    for(int i = 1; i <= N; i++)
    {
        int v; cin >> v; vec.push_back(v);
    }

    for(int a = 0; a <= K; a++)
    {
        if(a > N) continue;
        for(int b = 0; b <= K; b++)
        {
            if(a + b > N) continue;
            for(int c = 0; c <= K; c++)
            {
                if(c > a) continue;
                for(int d = 0; d <= K; d++)
                {
                    if(d > b) continue;
                    ll temp = 0;
                    if(a + b + c + d > K) continue;
                    priority_queue<int, vector<int>, greater<int>> l, r;
                    
                    for(int i = 0; i < a; i++)
                    {
                        temp += vec[i];
                        l.push(vec[i]);
                    }
                    
                    for(int i = 0; i < b; i++)
                    {
                        temp += vec[N-1-i];
                        r.push(vec[N-1-i]);
                    }
                    
                    for(int i = 0; i < c && !l.empty(); i++)
                    {
                        temp -= l.top(); l.pop();
                    }
                    for(int i = 0; i < d && !r.empty(); i++)
                    {
                        temp -= r.top(); r.pop();
                    }
                    
                    
                    ret = max(ret, temp);
                }
            }
        }
    }
    
    
   
    cout << ret << endl;
    return 0;
}


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

int main() {
  vector<int> a(3);
  for(int i=0;i<3;i++){
    cin >> a[i];
  }
  
  sort(a.begin(),a.end());
  
  int ans=0;
  int x = (a[2]-a[0])/2;
  a[0] += 2*x;
  ans += x;
  int y = (a[2] - a[1])/2;
  a[1] += 2*y;
  ans += y;
  
  sort(a.begin(),a.end());
  
  if(a[0] == a[1] && a[1] == a[2]){
    cout << ans << endl;
  }else if(a[0] == a[1] - 1 && a[1] == a[2]){
    ans += 2;
    cout << ans << endl;
  }else{
    ans++;
    cout << ans << endl;
  }
  return(0);
}

Measured memory_bytes: 3572
#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>;
const int INF=1000000007;

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


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

int main() {
  const int MOD=1000000007;
  int n,m;
  cin >> n >> m;
  int a[114514];
  long long b[114514];
  a[0]=-1;
  a[m+1]=n+1;
  b[0]=0;
  b[1]=0;
  b[2]=1;
  for(int i=3;i<n+5;i++){
    b[i]=(b[i-1]+b[i-2])%MOD;
  }
  for(int i=1;i<=m;i++)cin >> a[i];
  unsigned long long res=1;
  for(int i=1;i<=m+1;i++){
    res=res*b[a[i]-a[i-1]]%MOD;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 1408
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner()

	n := sc.ReadInt()
	m := sc.ReadInt()
	q := sc.ReadInt()
	abcds := make([]ABCD, q)
	for i := 0; i < q; i++ {
		a := sc.ReadInt()
		b := sc.ReadInt()
		c := sc.ReadInt()
		d := sc.ReadInt()
		abcds[i] = ABCD{a, b, c, d}
	}

	cur := make(SeqA, n)
	maxScore := maxScoreOfSeqACombinations(abcds, 1, m, n, 0, cur, 0)

	fmt.Println(maxScore)
}

func maxScoreOfSeqACombinations(abcds []ABCD, min, max, n, pos int, cur SeqA, curMaxScore int) int {
	if pos == n {
		score := computeScore(abcds, cur)
		if score > curMaxScore {
			curMaxScore = score
		}
		return curMaxScore
	}

	for i := min; i <= max; i++ {
		cur[pos] = i
		curMaxScore = maxScoreOfSeqACombinations(abcds, i, max, n, pos+1, cur, curMaxScore)
	}
	return curMaxScore
}

func computeScore(abcds []ABCD, seqA SeqA) int {
	totalD := 0
	for _, abcd := range abcds {
		if seqA[abcd.B-1]-seqA[abcd.A-1] == abcd.C {
			totalD += abcd.D
		}
	}
	return totalD
}

type SeqA []int

type ABCD struct {
	A int
	B int
	C int
	D int
}

// util
// *   math/simple

func Abs(x int) int {
	if x >= 0 {
		return x
	}
	return -x
}

func Min(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	min := values[0]
	for _, v := range values {
		if v < min {
			min = v
		}
	}
	return min
}

func Max(values ...int) int {
	if len(values) == 0 {
		panic("no values")
	}
	max := values[0]
	for _, v := range values {
		if v > max {
			max = v
		}
	}
	return max
}

func Pow(base int, exponent uint) int {
	answer := 1
	for i := uint(0); i < exponent; i++ {
		answer *= base
	}
	return answer
}

// *   io

type Scanner struct {
	bufScanner *bufio.Scanner
}

func NewScanner() *Scanner {
	bufSc := bufio.NewScanner(os.Stdin)
	bufSc.Split(bufio.ScanWords)
	bufSc.Buffer(nil, 100000000)
	return &Scanner{bufSc}
}

func (sc *Scanner) ReadString() string {
	bufSc := sc.bufScanner
	bufSc.Scan()
	return bufSc.Text()
}

func (sc *Scanner) ReadInt() int {
	bufSc := sc.bufScanner
	bufSc.Scan()
	text := bufSc.Text()

	num, err := strconv.Atoi(text)
	if err != nil {
		panic(err)
	}
	return num
}


Measured memory_bytes: 1768
#include<stdio.h>
#include<stdlib.h>
int a[100005], b[100005];
int asc(const void *x, const void *y)
{
    return a[*(int *)x] - a[*(int *)y];
}
int main()
{
    int n, m;
    scanf("%d %d", &n, &m);
    int i;
    for (i = 0; i < n; i++)
        scanf("%d %d", &a[i], &b[i]);
    int c[100005];
    for (i = 0; i < n; i++)
        c[i] = i;
    qsort(c, n, sizeof(int), asc);
    long long int ans = 0;
    for (i = 0;; i++)
    {
        if (m - b[c[i]] > 0)
        {
            m -= b[c[i]];
            ans += ((long long int)a[c[i]]) * ((long long int)b[c[i]]);
        }
        else
        {
            ans += ((long long int) m) *((long long int) a[c[i]]);
            break;
        }
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
 
// Shortcut
 
#pragma optimize ("O3")
#define int long long
#define endl '\n'
#define eb emplace_back
#define pb push_back
#define pob pop_back
#define mp make_pair
#define upb upper_bound
#define lwb lower_bound
#define fi first
#define se second
#define For(i, l, r) for (int i = l; i < r; i++)
#define ForE(i, l, r) for (int i = l; i <= r; i++)
#define Ford(i, r, l) for (int i = r; i > l; i--)
#define FordE(i, r, l) for (int i = r; i >= l; i--)
#define Fora(i, a) for (auto i : a)
 
// I/O & Debug
 
#define PrintV(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << ' ';
#define PrintVl(a) for (int iiii = 0; iiii < a.size(); iiii++) cout << a[iiii] << endl;
#define PrintA(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << ' ';
#define PrintAl(a, n) for (int iiii = 0; iiii < n; iiii++) cout << a[iiii] << endl;
#define Ptest(x) return cout << x, 0;
#define gl(s) getline(cin, s);
#define setpre(x) fixed << setprecision(x)
/*
#define debug(args...){ string _sDEB = #args; replace(_sDEB.begin(), _sDEB.end(), ',', ' '); stringstream _ssDEB(_sDEB); istream_iterator<string> _itDEB(_ssDEB); DEB(_itDEB, args); }
void DEB(istream_iterator<string> it) {}
template<typename T, typename... Args>
void DEB(istream_iterator<string> it, T a, Args... args){
    cout << *it << " = " << a << endl;
    DEB(++it, args...);
}
*/
 
// Functions
 
//#define isvowel(a) (a == 'a' || a == 'e' || a == 'i' || a == 'o' || a == 'u')
#define bend(a) a.begin(), a.end()
#define rbend(a) a.rbegin(), a.rend()
#define mset(a) memset(a, 0, sizeof(a));
#define mmset(a) memset(a, 0x3f, sizeof(a));
//mt19937 rando(chrono::steady_clock::now().time_since_epoch().count());
 
// Data Structure
 
#define pque priority_queue
#define mts multiset
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <string> vs;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <vi > vvi;
typedef vector <vll > vvll;
typedef vector <pii > vpii;
typedef vector <pll > vpll;
 
const int N = 5e3 + 5, mod = 1e9 + 7, inf = 1e9 + 7;
 
int n;
int a[4], b[4], c[N], d[N * N];
 
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin >> n;
    ForE(i, 1, 3) cin >> a[i];
    ForE(i, 1, 3) cin >> b[i];
    ForE(i, 0, n){
        ForE(j, 1, 3){
            if (i - a[j] >= 0){
                c[i] = max(c[i], c[i - a[j]] + b[j] - a[j]);
            }
        }
    }
    n += c[n];
    ForE(i, 0, n){
        ForE(j, 1, 3){
            if (i - b[j] >= 0){
                d[i] = max(d[i], d[i - b[j]] + a[j] - b[j]);
            }
        }
    }
    n += d[n];
    cout << n;
}
 
/*
==================================+
INPUT:                            |
------------------------------    |
 
------------------------------    |
==================================+
OUTPUT:                           |
------------------------------    |
 
------------------------------    |
==================================+
*/

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

int main(){
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  int l[q], r[q], ac[n] = {};
  for(int i = 0; i < q; ++i){
    cin >> l[i] >> r[i];
  }
  
  ac[0] = 0;
  for(int i = 1; i < n; ++i){
    ac[i] = ac[i-1];
    if(s[i-1] == 'A' && s[i] == 'C'){
      ac[i]++;
    }
  }
  
  for(int i = 0; i < q; ++i){
    cout << ac[r[i]-1] - ac[l[i]-1] << '\n';
  }
}


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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   
    int n,m;
    cin>>n>>m;
    ll mod=1000000007;


    int arr[n][m];
    for(int i=0;i<n;i++)
    {
    	for(int j=0;j<m;j++)
    		arr[i][j]=0;
    }

    for(int i=0;i<n;i++)
    {
    	string s;
    	cin>>s;
    	for(int j=0;j<m;j++)
    	{
    		if(s[j]=='#')
    			arr[i][j]=1;
    	}
    }

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


    for(int i=0;i<n;i++)
    {
    	if(arr[i][0]==1)
    	{
    		dp[i][0]=0;
    		break;
    	}
    	else
    		dp[i][0]=1;
    }


    for(int i=0;i<n;i++)
    {
    	if(arr[0][i]==1)
    	{
    		dp[0][i]=0;
    		break;
    	}
    	else
    		dp[0][i]=1;
    }

    for(int i=1;i<n;i++)
    {
    	for(int j=1;j<m;j++)
    	{
    		if(arr[i][j]==1)
    			dp[i][j]=0;
    		else
    			dp[i][j]=(dp[i-1][j]+dp[i][j-1])%mod;
    	}
    }

    cout<<dp[n-1][m-1];
}

Measured memory_bytes: 12032
import fractions

N, X   = map(int, input().split())
x = list(map(int, input().split()))
assert len(x) == N

x.sort()

# distance between each two cities
dist = [x[i] - x[i-1] for i in range(1, len(x))]

# distance between the first city and the start point
dist.append(abs(x[0] - X))

def listgcd(xs):
    g = xs[0]
    for i in range(1, len(xs)):
        g = fractions.gcd(g, xs[i])
    return g

print(listgcd(dist))


Measured memory_bytes: 16276
#include<bits/stdc++.h>
#define INF 2147483647
#define SYOU(x) setprecision(x)
using namespace std;
long long i[300000];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  cin >>a>>b>>c;
  cout <<a*b/2<<'\n';
  return (0);
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int INF = 1e9;
int N,M,R;
int r[205];
int d[205][205];
 
int main(){
    cin >> N >> M >> R;
    
    for(int i = 1; i <= N; ++i){
        for(int j = 1; j <= N; ++j)  if(i^j) d[i][j] = INF;
    }
    
    for(int i = 1; i <= R; ++i){
        cin >> r[i];
    }
    
    for(int i = 1,a,b,c; i <= M; ++i){
        cin >> a >> b >> c;
        d[a][b] = d[b][a] = c;
    }
    
    for(int k = 1; k <= N; ++k){
        for(int j = 1; j <= N; ++j){
            for(int i = 1; i <= N; ++i){
                d[i][j] = min(d[i][j],d[i][k] + d[k][j]);
            }
        }
    }
    
    int ans = INF;
    
    sort(r+1,r+R+1);
    
    do{
        int sum = 0;
        for(int i = 2; i <= R ; ++i){
            sum += d[r[i-1]][r[i]];
        }
        ans = min(sum,ans);
        
    }while(next_permutation(r+1,r+R+1));
    
        
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 384
import java.lang.reflect.Array;
import java.util.*;
import java.io.*;
import java.lang.*;

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

        String s = sc.next();

        if (s.charAt(0)==s.charAt(1)|| s.charAt(1)==s.charAt(2)|| s.charAt(2)==s.charAt(3))
            System.out.println("Bad");
        else
            System.out.println("Good");
    }
}


Measured memory_bytes: 35696
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=l;i<r;i++)
#define max(p,q)((p)>(q)?(p):(q))
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}

ll a[1010];
int main(){
	ll n,m;
	while(scanf("%lld%lld",&n,&m),n){
		rep(i,0,n)scanf("%lld",a+i);
		sortup(a,n);
		ll M=0;
		ll r=n-1;
		rep(l,0,n){
			while(r>l&&a[l]+a[r]>m)r--;
			if(l==r)break;
			M=max(M,a[l]+a[r]);
		}
		if(M)printf("%lld\n",M);
		else puts("NONE");
	}
}


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

int main(){
  string s;
  cin>>s;
  int a=0;
  int c=0;
  for(int i=0;i<300000;i++){
if(s.at(i)=='A'){
a=i;
  break;
}
  }
   for(int i=s.size()-1;i<300000;i--){
if(s.at(i)=='Z'){
c=i;
  break;
}
  }
   cout<<c-a+1<<endl;
}
   


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    int n;
    int a=0,b=0,c=0,d=0;
    cin>>n;
    cin.ignore();
    for(int i=0;i<n;i++)
    {
        cin>>s;
        if(s=="AC")a++;
        else if(s=="WA")b++;
        else if(s=="TLE")c++;
        else if(s=="RE")d++;
        s.clear();
    }
    printf("AC x %d\n",a);
    printf("WA x %d\n",b);
    printf("TLE x %d\n",c);
    printf("RE x %d\n",d);
    return 0;
}


Measured memory_bytes: 3720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Stack;
import java.util.StringTokenizer;

class Main{		//スタック練習

	public static void main(String[] args) {

	BufferedReader bfr=new BufferedReader(new InputStreamReader(System.in));
		String str="";
		String toridasi="";
		StringTokenizer stk;
		int stacksize=0;
		Stack<Integer> st=new Stack<Integer>();

		try {
			str=bfr.readLine();
			stk=new StringTokenizer(str," ");
			stacksize=stk.countTokens();
			for(int i=0; i<stacksize; i++) {
				toridasi=stk.nextToken();

				if(toridasi.equals("+") || toridasi.equals("-") || toridasi.equals("*")) {
					int b=st.pop();
					int a=st.pop();
					if(toridasi.equals("+")) {
						st.push(a+b);
					}
					else if(toridasi.equals("-")) {
						st.push(a-b);
					}

					else if(toridasi.equals("*")) {
						st.push(a*b);
					}
				}
				else {
					st.push(Integer.parseInt(toridasi));
				}
			}
			System.out.println(st.pop());
		}
		catch (IOException e) {
			e.printStackTrace();
		}

	}
}



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

using std::cout;
using std::endl;
using std::cin;
using std::vector;
using std::count;

int main(){
    vector<int> v;

    v.resize(3);
    cin >> v[0] >> v[1] >> v[2];
    count(v.begin(),v.end(),7)==1 && count(v.begin(), v.end(), 5)==2?
    cout << "YES" << endl : cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 256