akhauriyash/Code-Regression huggingface dataset:
K = [i+1 for i in range(2000)]

while 1:
    N = int(input())
    if N == 0:
        break
    *S, = map(int, input().split())
    if S == K[:len(S)]:
        print(0)
        continue
    i = 1; s = 0; su = sum(S)
    while s < su:
        s += i; i += 1

    if s != su:
        print(-1)
        continue

    for t in range(10000):
        T = []
        for s in S:
            if s > 1:
                T.append(s-1)
        T.append(len(S))
        S, T = T, S
        if S == K[:len(S)]:
            print(t+1)
            break
    else:
        print(-1)


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

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

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		String input = reader.readLine();
		reader.close();
		
		int totalArea = 0;
		Stack<Integer> st1 = new Stack<Integer>();
		Stack<int[]> st2 = new Stack<int[]>();
		
		for (int i = 0; i < input.length(); i++) {
			char c = input.charAt(i);
			if (c == '\\') {
				st1.push(i);
			} else if (c == '/') {
				int area = 0;
				int pos = 0;
				if (!st1.isEmpty()) {
					pos = st1.pop();
					area = i - pos;
					totalArea += area;
					while (!st2.isEmpty() && st2.peek()[0] > pos) {
						area += st2.pop()[1];
					}
					st2.push(new int[] {pos, area});
				}
			}
		}
		
		System.out.println(totalArea);
		System.out.print(st2.size());
		StringBuilder sb = new StringBuilder();
		while (!st2.isEmpty()) {
			sb.insert(0, st2.pop()[1]);
			sb.insert(0, " ");
		}
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 26032
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using ll=long long;
using vi=vector<int>;
using pii=pair<int,int>;
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define SZ(c) ((int)c.size())
#define CONTAIN(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const signed INF_=1001001001; const ll INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct{template<class T> operator T(){T x;cin>>x;return x;}} IN;
struct before_main_function {
    before_main_function() {
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
        #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    string a=IN,b=IN;
    int sum=stoi(a+b);
    int t=sqrt(sum);
    if(t*t==sum) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll A[100005];

int main(){

cin.tie(0);
ios::sync_with_stdio(false);


cin>>N;
rep(i,N){
	cin>>A[i];
	if(A[i]==0){
		puts("0");
		return 0;
	}
}
ll ans=1;
rep(i,N){
	long double ld=(long double)ans*(long double)A[i];
	if(ld>1e18){
		puts("-1"); 
		return 0;
	}
	ans=ans*A[i];
}
cout<<ans<<endl;


}
    


Measured memory_bytes: 4424
N = int(input())
V = list(map(int, input().split(' ')))

V.sort()
V = list(reversed(V))

def insert(A, t):
  for i in range(len(A)):
    if A[i] <= t:
      A.insert(i, t)
      break
  else:
    A.append(t)

while(len(V) > 1):
  v1 = V.pop()
  v2 = V.pop()
  insert(V, (v1 + v2) / 2)

print(V[0])


Measured memory_bytes: 3064
#include<stdio.h>
int main()
{
    int N,num,cnt=0;
    scanf("%d", &N);
    while(N!=0)
    {
        num=N%10;
        if(num==7)
        {
            cnt++;
            break;
        }
        N/=10;
    }
    if(cnt==0)
        printf("No\n");
    else
        printf("Yes\n");
    return 0;
}


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

int main() {
  int timeCount;
  int timePay;
  int constPay;

  cin >> timeCount >> timePay >> constPay;

  if (timeCount * timePay >= constPay)
  {
    cout << constPay << endl;
  }
  else
  {
    cout << timeCount * timePay << endl;
  }
}



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

int a,c[20],d[20];
int main(){
  while(true){
    for(int i=0;i<20;i++) 
      {c[i]=0;d[i]=0;}
    cin>>a;
    if(a==0){break;}
    for (int i=0;i<a;i++){
      cin>>c[i];
    }
    int meta=0;
    while(true){
      for(int i=0;i<a;i++){
	for(int j=0;j<a;j++){ 
	  if(c[i]==c[j]){
	    d[i]++;
	  }
	}
      }
      int k=0;
      for(int i=0;i<a;i++){
	if(c[i]==d[i]){
	  k++;
	}
	c[i]=d[i];
	d[i]=0;
      }
 
      if(k>a-1){break;}
      meta++;
    }
    printf("%d\n",meta);
    for(int i=0;i<a;i++){
      printf("%d",c[i]);
      if(i!=a-1){printf(" ");}
    }
    printf("\n");
    
  }
}

Measured memory_bytes: 1148
#include<cstdio>
#include<algorithm>
#include<cstring>
#define rep(i, s, t) for(i = s; i <= t; ++i)

using namespace std;

int n, ans;
int a[100010];

int main() {
	int i;
	scanf("%d", &n);
	rep(i, 1, n) scanf("%d", &a[i]);
	rep(i, 0, n) ans += abs(a[i] - a[i+1]);
	rep(i, 1, n) printf("%d\n", ans - abs(a[i]-a[i+1]) - abs(a[i]-a[i-1]) + abs(a[i+1]-a[i-1]));
	return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define itn int
typedef long long ll;
typedef pair<int,int> p;


int main()
{
 int a,b;
 cin >> a >> b;
 if (a <= 8 && b <= 8)
 {
   cout << "Yay!" << endl;
 }else{
   cout << ":(" << endl;
 }

}


Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

x,y = map(int,readline().split())
if abs(x) == abs(y):
    if x == y:
        print(0)
    else:
        print(1)
    exit()
need = min(abs(x-y),abs(x+y))
if abs(x) <= abs(y):
    grad = "+"
else:
    grad = "-"

if grad == "+" and x < 0:
    need += 1
if grad == "-" and x > 0:
    need += 1

if grad == "+" and y < 0:
    need += 1
if grad == "-" and y > 0:
    need += 1

print(need)

Measured memory_bytes: 61928
#include<iostream>
#include <climits>
#include<vector>
#include<list>
#include<numeric>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<queue>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;

ll pow_int(int x, int y){
	ll res = 1;
	for (int i = 1;i <= y;i++) res *= x;
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n;
	cin >> n;
	map<string,int> map;
	REP(i, n) {
		string meirei, str;
		cin >> meirei >> str;
		if (meirei[0] == 'i') map[str] = 1;
		else if (map[str] == 1) cout << "yes\n";
		else cout << "no\n";
	}

	return 0;
}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef map<int,int> mii;
typedef map<ll,int> mli;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;  ///1e9+7

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///
ll n;
bool a[1001];
vl v;
void seive()
{
    ll mx=sqrt(1000),ii,jj;
    for(ii=3;ii<=mx;ii+=2)
        if(!a[ii])
            for(jj=ii*ii;jj<=1000;jj+=2*ii) a[jj]=true;
    v.pb(2);
    for(ll i=3;i<=1000;i+=2) if(!a[i]) v.pb(i);
}

void _case()
{
    cin>>n;
    seive();
    ll ans=1,s=sqrt(n);
    for(ll i=0;i<v.size() and v[i]<=n;i++){
        ll rate=0,x=v[i];
        while(x<=n) {rate+=n/x; x*=v[i];}
        ans*=(rate+1);
        ans%=MOD;
    }
    //for(auto i:v) cout<<i sp;
    cout<<ans<<'\n';
}

main()
{
//    fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3628
#include<cstdio>

int n, m, x;

int main() {
	scanf("%d%d", &n, &m);
	
	for(int i = 1; i <= m; ++i) {
		scanf("%d", &x);
		
		n -= x;
	}
	
	if(n < 0) puts("-1");
	else printf("%d", n);
}

Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string str;
    int n,x,l,r=0,b=0;
    cin >> n;
    cin >> str;
    for(int i=0;i<n;i++){
        if(str[i]=='R'){
            r++;
        }else{
            b++;
        }
    }
    if(r>b){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  a,b = map(int,input().split())
  p = a
  cnt = 0
  while a <= p <= b:
    P = str(p)
    if P == P[::-1]:
      cnt += 1
    p += 1
  print(cnt)
if __name__ == '__main__':
  main()

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

const ll MOD = 1000000007;

ll H, W, K;
ll mat[10][10];
ll umu[10];

void dfs(ll nxt = 1){
    // if(nxt == W){
    //     for(ll i = 1; i < nxt; i++)cout << umu[i];
    //     cout << endl;
    // }
    if(nxt == W){
        for(ll to = 1; to <= W; to++){
            if(umu[to - 1])mat[to - 1][to]++;
            else if(umu[to])mat[to + 1][to]++;
            else mat[to][to]++;
        }
        return;
    }
    umu[nxt] = 0;
    dfs(nxt + 1);
    if(umu[nxt - 1] == 0){
        umu[nxt] = 1;
        dfs(nxt + 1);
    }
}

int main(){

    cin >> H >> W >> K;
    dfs();
    ll dp[110][10] = {};
    dp[0][1] = 1;
    for(ll y = 0; y < H; y++){
        for(ll from = 1; from <= W; from++){
            for(ll to = 1; to <= W; to++){
                dp[y + 1][to] += (dp[y][from] * mat[from][to]) % MOD;
                dp[y + 1][to] %= MOD;
            }
        }
    }
    cout << dp[H][K] << endl;

    return 0;
}

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

int main() {
	ll n,k;
	cin>>n>>k;
	ll arr[n];
	for(ll i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	sort(arr,arr+n);
	ll ans=0;
	for(ll i=0;i<n-k;i++)
	{
		ans=ans+arr[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#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>;

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

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

int n, m, d[21];
int dp[21][50001];

int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
		scanf("%d", &d[i]);

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

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

	for (int i = 1; i <= m; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			dp[i][j] = dp[i - 1][j];
			if (j >= d[i])
				dp[i][j] = std::min(dp[i - 1][j], dp[i][j - d[i]] + 1);
		}
	}
	printf("%d\n", dp[m][n]);

	return 0;
}



Measured memory_bytes: 6800
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;

int search_b_cnt(const ll min, const ll max, const VL& b) {
    if(b.back() < min) return 0;
    if(b.front() >= max) return 0;
    // min探索
    int left_index = -1;
    int right_index = b.size();
    while(right_index - left_index > 1) {
        int mid = (right_index + left_index) / 2;
        if(b[mid] < min) left_index = mid;
        else right_index = mid;
    }
    int b_min_index = right_index;
    // max探索
    left_index = -1;
    right_index = b.size();
    while(right_index - left_index > 1) {
        int mid = (right_index + left_index) / 2;
        if(b[mid] < max) left_index = mid;
        else right_index = mid;
    }
    int b_max_index = left_index;
    return b_max_index - b_min_index + 1;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    VL a(n), b(n);
    REP(i, n) cin >> a[i];
    REP(i, n) cin >> b[i];
    
    ll ans = 0;
    REP(k, 31) {
        ll cnt = 0;
        VL b_mod(n);
        REP(i, n) b_mod[i] = b[i] % (2 << k);
        sort(ALL(b_mod));
        REP(i, n) {
            ll mod_a = a[i] % (2 << k);
            cnt += search_b_cnt((1 << k) - mod_a, (2 << k) - mod_a, b_mod);
            cnt += search_b_cnt(3 * (1 << k) - mod_a, (4 << k) - mod_a, b_mod);
        }
        ans += (cnt % 2) << k;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
  int a, b, c, d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if (a > b){
	printf("%d\n", c*b+d*(a-b));
  }else{
	printf("%d\n", c*a);
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>
int dict[128][128];
int sort_bub[36][2];
int sort_sel[36][2];

void selection_sort(int arr[][2], int len)
{
	int tmp[2];
	for (int i = 0; i < len; i++)
	{
		int min = i;
		for (int j = i+1; j < len; j++)
		{
			if (arr[min][1] > arr[j][1])
			{
				min = j;
			}
		}
		if (i != min) {
			tmp[0] = arr[i][0];
			tmp[1] = arr[i][1];
			arr[i][0] = arr[min][0];
			arr[i][1] = arr[min][1];
			arr[min][0] = tmp[0];
			arr[min][1] = tmp[1];
		}
	}
}

void bubble_sort(int arr[][2], int len)
{
	int tmp[2];
	for (int i = 0; i < len; i++)
	{
		int max = len - i;
		for (int j = 1; j < max; j++)
		{
			if (arr[j - 1][1] > arr[j][1])
			{
				tmp[0] = arr[j-1][0];
				tmp[1] = arr[j-1][1];
				arr[j-1][0] = arr[j][0];
				arr[j-1][1] = arr[j][1];
				arr[j][0] = tmp[0];
				arr[j][1] = tmp[1];
			}
		}
	}
}

int main()
{
	int len, tmp;
	char mark;
	char stable_bub[256] = "Stable", stable_sel[256] = "Stable";

	scanf("%d\n", &len);

	scanf("%c", &mark);
	scanf("%d", &tmp);
	sort_bub[0][0] = mark;
	sort_bub[0][1] = tmp;
	sort_sel[0][0] = mark;
	sort_sel[0][1] = tmp;
	dict[mark][tmp] = 0;

	for (int i = 1; i < len; i++) {
		scanf(" %c", &mark);
		scanf("%d", &tmp);
		sort_bub[i][0] = mark;
		sort_bub[i][1] = tmp;
		sort_sel[i][0] = mark;
		sort_sel[i][1] = tmp;
		dict[mark][tmp] = i;
	}

	bubble_sort(sort_bub, len);
	selection_sort(sort_sel, len);

	printf("%c%d", (char)sort_bub[0][0], sort_bub[0][1]);
	for (int i = 1; i < len; i++) {
		printf(" %c%d", (char)sort_bub[i][0], sort_bub[i][1]);

		if (sort_bub[i-1][1] == sort_bub[i][1] && dict[sort_bub[i-1][0]][sort_bub[i-1][1]] > dict[sort_bub[i][0]][sort_bub[i][1]]) {
			strcpy(stable_bub, "Not stable");
		}
	}
	printf("\n%s\n", stable_bub);

	printf("%c%d", (char)sort_sel[0][0], sort_sel[0][1]);
	for (int i = 1; i < len; i++) {
		printf(" %c%d", (char)sort_sel[i][0], sort_sel[i][1]);

		if (sort_sel[i-1][1] == sort_sel[i][1] && dict[sort_sel[i-1][0]][sort_sel[i-1][1]] > dict[sort_sel[i][0]][sort_sel[i][1]]) {
			strcpy(stable_sel, "Not stable");
		}
	}
	printf("\n%s\n", stable_sel);

	return 0;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define TMP(arr, index, max_n) for(arr[index] = arr[index-1]; arr[index]<=max_n; ++arr[index])

int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
/***** MAIN *****/
signed main() {
  int n = in(), m = in(), q = in();
  int nums[15];
  REP(i,n) nums[i] = 1;
  int a[q], b[q], c[q], d[q];
  REP(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];
    --a[i]; --b[i];
  }
  int ans = 0;
  for(nums[0]=1; nums[0]<=m; ++nums[0]) {
    TMP(nums, 1, m) TMP(nums, 2, m) TMP(nums, 3, m) TMP(nums, 4, m) TMP(nums, 5, m) TMP(nums, 6, m) TMP(nums, 7, m) TMP(nums, 8, m) TMP(nums, 9, m) {
      int tmp_ans = 0;
      REP(i,q) {
        if(nums[b[i]] - nums[a[i]] == c[i]) {
          tmp_ans += d[i];
        }
      }
      ans = max(ans, tmp_ans);
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3628
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (int i = j; i < (n); i++)
#define CLR(mat) memset(mat, 0, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<int,int>P;
const ll mod=1e9+7;
const ll INF = 1e9;



int main(){

  ll n;cin>>n;

  out((n-1)*n/2);

  return 0;
}


Measured memory_bytes: 256
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	int N, M;
	while (cin >> N >> M, N) {
		set<int> s; int S = 0, mn = 1 << 30, ans = 0;
		for (int i = 0; i <= N; ++i) {
			long long X;
			if (i >= 1) cin >> X;
			S = (S + X) % M;
			set<int>::iterator ptr = s.lower_bound(S + 1);
			if (ptr != s.end()) {
				ans = max(ans, S - *ptr + M);
			}
			ans = max(ans, S - mn);
			mn = min(mn, S);
			s.insert(S);
		}
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 4344
//abc161_d.cpp
//Sat Apr  4 20:34:54 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
#define MOD 1000000007

using namespace std;
using ll=long long;
typedef pair<ll,ll> P;


int main(){
	ll k;
	cin >> k;

	vector<P> keta[12];
	vector<ll> lunlun;
	for (int i=1;i<10;i++){
		keta[0].push_back(P(i,i));
		lunlun.push_back(i);
	}

	for (int i=1;i<12;i++){
		for (int j=0;j<keta[i-1].size();j++){
			if (keta[i-1][j].second == 0){
				keta[i].push_back(P(keta[i-1][j].first*10,0));
				lunlun.push_back(keta[i-1][j].first*10);

				keta[i].push_back(P(keta[i-1][j].first*10+1,1));
				lunlun.push_back(keta[i-1][j].first*10+1);

			}else if (keta[i-1][j].second == 9){
				keta[i].push_back(P(keta[i-1][j].first*10+8,8));
				lunlun.push_back(keta[i-1][j].first*10+8);

				keta[i].push_back(P(keta[i-1][j].first*10+9,9));
				lunlun.push_back(keta[i-1][j].first*10+9);

			}else {
				keta[i].push_back(P(keta[i-1][j].first*10+keta[i-1][j].second-1,keta[i-1][j].second-1));
				lunlun.push_back(keta[i-1][j].first*10+keta[i-1][j].second-1);

				keta[i].push_back(P(keta[i-1][j].first*10+keta[i-1][j].second,keta[i-1][j].second));
				lunlun.push_back(keta[i-1][j].first*10+keta[i-1][j].second);

				keta[i].push_back(P(keta[i-1][j].first*10+keta[i-1][j].second+1,keta[i-1][j].second+1));
				lunlun.push_back(keta[i-1][j].first*10+keta[i-1][j].second+1);
			}
		}
	}

	cout << lunlun[k-1] << endl;

}

Measured memory_bytes: 68428
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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


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

    vi a(5);
    int cnt = 0;
    rep (i, 5) {
        cin >> a[i];
        if (a[i] % 10 == 0) cnt++;
    }

    int ans = 0;
    rep (i, 5) {
        int mmod = -1;
        int index = -1;
        rep (j, a.size()) {
            if(a[j] % 10 > mmod) {
                mmod = a[j] % 10;
                index = j;
            }
        }
        if( (5 - cnt) <= (i + 1)) {
            ans += a[index];
        } else {
            ans += a[index];
            ans += 10 - (ans % 10);
        }
        a.erase(a.begin() + index);
    }
    COUT(ans);
}

Measured memory_bytes: 256
//----------ACCIDENTAL COMPETITIVE PROGRAMMER---------------------

#include<bits/stdc++.h>

/*
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
using namespace std;

#define LL long long
#define LD long double
#define PB push_back
#define MP make_pair


const LL MOD = (1e9) + 7 ;
const LD EPS = 0.0000001 ;

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

    int n; cin >> n;
    int k; cin >> k;
    string s; cin >> s;
    if (s[k-1] - 'A' <= 25){
    	s[k - 1] = s[k - 1] - 'A' + 'a';
    }
    cout << s << endl;

	return 0;
}

Measured memory_bytes: 256
w = str.lower(raw_input())
t = []
while True:
  line = raw_input()
  if line == "END_OF_TEXT":
    break
  else:
    t += (map(str.lower, line.split(" ")))

count = 0
for i in xrange(len(t)):
  if w == t[i]:
    count += 1

print count

Measured memory_bytes: 6384
from bisect import bisect_left, bisect_right
n = int(input())
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
c = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    a_cnt = bisect_left(a, b[i], 0, n)
    c_cnt = n - bisect_right(c, b[i], 0, n)
    #print(a_cnt, c_cnt)
    ans += a_cnt * c_cnt

print(ans)

Measured memory_bytes: 23232
import java.util.Scanner;
import java.util.stream.Stream;

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

        if(str.equals("Sunny")){
            System.out.println("Cloudy");
        }
        else if (str.equals("Cloudy")){
            System.out.println("Rainy");
        }
        else if (str.equals("Rainy")){
            System.out.println("Sunny");
        }
    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++);
using ll=long long;
int  main(){
string S;
cin>>S;
char a=S.at(0);
bool t=false;
if(a==S.at(1)&&S.at(2)!=a&&S.at(3)!=a){
    if(S.at(2)==S.at(3)){
        t=true;
    }
}
 else if(a==S.at(2)&&S.at(1)!=a&&S.at(3)!=a){
    if(S.at(1)==S.at(3)){
        t=true;
    }
}
else if(a==S.at(3)&&S.at(2)!=a&&S.at(1)!=a){
    if(S.at(1)==S.at(2)){
        t=true;
    }
}

if(t==false){
    cout<<"No"<<endl;
}
else
{
    cout<<"Yes"<<endl;
}

 }




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;
 
int main() {
    ll n;
    cin >> n;

    set<char> st;
    rep(i, n) {
        char c;
        cin >> c;
        st.insert(c);
    }

    if(st.size() == 3) {
        out("Three");
    }
    else if(st.size() == 4) {
        out("Four");
    }
    
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 0; i < n; ++i)
#define rep3(i, a, b) for (ll i = a; i < b; ++i)
#define rep4(i, a, b, c) for (ll i = a; i < b; i += c)
#define erep(n) for (ll i = 0; i <= n; ++i)
#define erep2(i, n) for (ll i = 0; i <= n; ++i)
#define erep3(i, a, b) for (ll i = a; i <= b; ++i)
#define erep4(i, a, b, c) for (ll i = a; i <= b; i += c)
#define rrep(i, a, b) for (ll i = a; i > b; --i)
#define rrep2(i, a, b, c) for (ll i = a; i > b; i -= c)
#define errep(i, a, b) for (ll i = a; i >= b; --i)
#define errep2(i, a, b, c) for (ll i = a; i >= b; i -= c)
#define print(a) cout << a << endl;
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define cin(x) cin >> x;
inline int newline() { putchar('\n'); return 0; }

int main() {
    ll n, k;
    cin(n);
    cin(k);

    print(max(1.0, ceil(log(n) / log(k))));
    return 0;
}

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

int main(){
    int N;
    cin >> N;
    vector <int> A(N);
    for (int i=0; i<N; ++i) cin >> A.at(i);
    int highest=A.at(0);
    long long sum=0;

    for (int i=1; i<N; ++i){
        if (A.at(i) < highest) sum += highest - A.at(i);
        else highest = A.at(i);
    }
    cout << sum;
}

Measured memory_bytes: 4044
from sys import stdin
N=int(input())
num_list=[]
for i in range(N):
    line = list(stdin.readline().strip().split())
    num_list.append([line[0],int(line[1]),i])
def partition(A,p,r):
    x=A[r][1]
    i=p-1
    for j in range(p,r):
        if A[j][1]<=x:
            i+=1
            A[i],A[j]=A[j],A[i]
    A[i+1],A[r]=A[r],A[i+1]
    return i+1
def quicksort(A,p,r):
    if p<r:
        q=partition(A,p,r)
        quicksort(A,p,q-1)
        quicksort(A,q+1,r)
def check(A):
    for i in range(N-1):
        if A[i][1]==A[i+1][1]:
            if A[i][2]>A[i+1][2]:
                return 0
    return 1
quicksort(num_list,0,N-1)
if check(num_list):
    print("Stable")
else:print("Not stable")
for i in num_list:
    del i[2]
    print(*i)





Measured memory_bytes: 22004
#include <stdio.h>

#define Mod 998244353

long long gcd(long long a, long long b)
{
	if (a > b) {
		a += b;
		b = a - b;
		a -= b;
	}
	if (b % a == 0) return a;
	else return gcd(b % a, a);
}

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long solve(long long a, long long b, long long c)
{
	if (b % a == 0) return c / a;
	else return (c - solve(b % a, a, c % a) * b) / a;
}

int main()
{
	int N;
	long long A, B, K;
	scanf("%d %lld %lld %lld", &N, &A, &B, &K);
	
	long long G, X, Y;
	G = gcd(A, B);
	if (K % G != 0) {
		printf("0\n");
		fflush(stdout);
		return 0;
	}
	A /= G;
	B /= G;
	K /= G;
	if (A > B) {
		A += B;
		B = A - B;
		A -= B;
	}
	X = solve(A, B, K);
	if (X < 0) X += B * ((-X + B - 1) / B); 
	else X -= B * (X / B);
	Y = (K - A * X) / B;
	for (; Y > N; X += B, Y -= A);
	
	int i;
	long long fact[300001], fact_inv[300001], ans = 0;
	for (i = 1, fact[0] = 1; i <= N; i++) fact[i] = fact[i-1] * i % Mod;
	for (i = N - 1, fact_inv[N] = div_mod(1, fact[N], Mod); i >= 0; i--) fact_inv[i] = fact_inv[i+1] * (i + 1) % Mod;
	for (; X <= N && Y >= 0; X += B, Y -= A) ans += fact_inv[X] * fact_inv[N-X] % Mod * fact_inv[Y] % Mod * fact_inv[N-Y] % Mod; 
	printf("%lld\n", ans % Mod * fact[N] % Mod * fact[N] % Mod);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 6424
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("Failed to read bytes") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let s:String = read();
    let k:u128 = read();
    let mut c = s.chars();
    let mut ans = '1';
    for i in 0..s.len() {
        let x = c.next().unwrap();
        if x != '1' {
            ans = x;
            break;
        }
        if i as u128 == k -1 {
            break;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 2060
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

const int N = 1e5 + 10;
char s[N];

int main() {
  scanf("%s", s);
  int n = strlen(s);
  if (s[n - 1] == '1' || s[0] == '0') {
    puts("-1");
    return 0;
  }
  for (int i = 0; i + i <= n - 2; ++i) {
    if (s[i] != s[n - 2 - i]) {
      puts("-1");
      return 0;
    }
  }
  int rt = 0, last = 1;
  vector<ii> edge;
  for (int i = 0; i < n - 1; ) {
    edge.emplace_back(rt, last);
    rt = last;
    last++;
    for (++i; i < n - 1 && s[i] == '0'; ++i) {
      edge.emplace_back(last++, rt);
    }
  }
  // edge.emplace_back(rt, last++);
  for (auto& it : edge) {
    printf("%d %d\n", it.first + 1, it.second + 1);
  }
  return 0;
}


Measured memory_bytes: 2420
#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--)
#define INF 1e9;
using namespace std;
typedef long long ll;
int main() {
  ll n;
  cin >> n;
  vector<ll> t(n), x(n), y(n);
  REP(i, n) { cin >> t[i] >> x[i] >> y[i]; }

  ll prev_t = 0, prev_x = 0, prev_y = 0;
  REP(i, n) {
    ll diff_t = t[i] - prev_t;
    ll diff_d = abs(x[i] - prev_x + y[i] - prev_y);
    if (diff_t < diff_d || diff_t % 2 != diff_d % 2) {
      cout << "No" << endl;
      return 0;
    }
    prev_t = t[i];
    prev_x = x[i], prev_y = y[i];
  }
  cout << "Yes" << endl;
  return 0;
}

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

#define TRACE(x) x
#define WATCH(x) TRACE(cout << #x" = " << x << endl)
#define WATCHR(a, b) TRACE(for (auto it=a; it!=b;) cout << *(it++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end());})

#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

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

    int N;
    cin >> N;

    vi a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    sort(all(a));

    int n = a.back(), r = a[0];
    for (int i = 1; i < N - 1; i++) {
        if (abs(n/2. - a[i]) < abs(n/2.-r))
            r = a[i];
    }

    cout << n << " " << r << "\n";

    return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
    #define ld long double
    #define ll long long
    using namespace std;
    
    
    
    int main() {
        
            ll n, m, k, i, c, j, mx=0;
            map<ll, ll> A;
            map<ll, ll> B;
            cin>>n>>m>>k;
            for(i=0; i<n; i++)
            {
                cin>>c;
                A[i]=c;
            }
            for(i=0; i<m; i++)
            {
                cin>>c;
                B[i]=c;
            }
            for(i=1; i<n; i++)
            {
                A[i]+=A[i-1];
            }
            for(i=1; i<m; i++)
            {
                B[i]+=B[i-1];
            }
            
            ll note=n, in=0;
            for(i=0; i<n; i++)
            {
                if(A[i]>k)
                {
                    note=i;
                    break;
                }
            }
            
            if(note==0)
            {
                ll u=m;
                for(i=0; i<m; i++)
                {
                if(B[i]>k)
                {
                    u=i;
                    break;
                }
                }
                mx=max(mx, u);
            }
            
            else
            {
            while(note--)
            {
                ll f=0;
                for(j=in; j<m; j++)
                {
                    if(A[note]+B[j]>k)
                    {
                        mx=max(mx, note+1+j);
                        in=j;
                        f=1;
                        break;
                    }
                }
                if(f==0)
                {mx=max(mx, note+1+m);
                break;}
            }
            }
            
            
            
            
            note=m;
            in=0;
            for(i=0; i<m; i++)
            {
                if(B[i]>k)
                {
                    note=i;
                    break;
                }
            }
            
            
            if(note==0)
            {
                ll u=n;
                for(i=0; i<n; i++)
                {
                if(A[i]>k)
                {
                    u=i;
                    break;
                }
                }
                mx=max(mx, u);
            }
            
            else
            {
            while(note--)
            {
                ll f=0;
                for(j=in; j<n; j++)
                {
                    if(B[note]+A[j]>k)
                    {
                        mx=max(mx, note+1+j);
                        in=j;
                        f=1;
                        break;
                    }
                }
                if(f==0)
                {mx=max(mx, note+1+n);
                break;}
            }
            
            }
            
            
            
            
            
            
            cout<<mx;
        return 0;
    }

Measured memory_bytes: 28620
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lp = rli()
    m = n+1
    ans = 0
    for p in lp:
        if p <= m:
            ans += 1
        m = min(m, p)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25348
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const ll N=1e5+5;
ll n,a[N];
bool solve(){
    ll even=0,ones=0;
    for(ll i=0;i<n;i++){
        if(a[i]%2==0)even++;
        if(a[i]==1)ones++;
    }

    if(even&1)return 1;
    if(even<n-1 || ones>0)return 0;

    ll g=0;
    for(ll i=0;i<n;i++){
        if(a[i]&1)a[i]--;
        g=__gcd(g,a[i]);
    }
    for(ll i=0;i<n;i++)
        a[i]/=g;
    return solve()^1;
}
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n;
    for(ll i=0;i<n;i++)cin>>a[i];
    cout<<(solve()?"First\n":"Second\n");
}

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

#define ll long long
#define dd double

using namespace std;



int main(){
    int A,B;
    cin >> A >> B;
    int count = 0;
    bool flag = false;
    for(ll i = 0; i < 100000; i++){
        if(floor(i * 0.08) == A && floor(i * 0.1) == B) {
            count = i;
            flag = true;
            break;
        }
        
    }
    cout << (flag ? count : -1) << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python

from sys import stdin, stderr

def cut(A, p):
   v1 = 1
   v2 = 1
   for i in xrange(len(A)):
      if i == p:
         v1 *= A[i]/2
         v2 *= A[i] - A[i]/2
      else:
         v1 *= A[i]
         v2 *= A[i]
   return abs(v2-v1)

def main():
   A = map(int, stdin.readline().split())
   res = min(cut(A, 0), cut(A, 1), cut(A, 2))
   print res
   return 0

if __name__ == '__main__': main()


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

long long gcd(long long a, long long b){
  if(a < b) swap(a, b); 
  if(a % b == 0) return b;
  else return gcd( a - b, b);
}

long long lcm(long long a, long long b){
  return a / gcd( a, b) * b;
}
 
int main() {
  long long a, b;
  while(cin >> a >> b){
  cout << gcd( a, b) << " " << lcm( a, b) << endl;
  }
}


Measured memory_bytes: 3008
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define ft first
#define sc second
#define ve vector
#define tos to_string
#define len length
#define rt return 0
#define gcd __gcd
#define lcm(n, m) n * m / gcd(n, m)
#define np next_permutation
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// sqrt ルート, int 2*10^9, gcd　最大公約数

int main() {
  int N, a = 0;
  st S;
  ci(N, S);
  rep(i, N - 1){
    if(S.at(i) != S.at(i + 1)){
      a++;
    }
  }
  co(a + 1);
}

Measured memory_bytes: 512
#include <vector> 
#include <list> 
#include <map> 
#include <set> 
#include <deque> 
#include <queue> 
#include <stack> 
#include <bitset> 
#include <algorithm> 
#include <functional> 
#include <numeric> 
#include <utility> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 

using namespace std;

#define _int64 long long

int n,x,y;
int a[110000];

int doit(_int64 c)
{
  int i;
  _int64 tmp,cnt;
  cnt=0;
  for (i=0;i<n;i++)
  {
    if (c>=a[i]) tmp=0;
    else if (y>=a[i]) tmp=0;
    else tmp=a[i]-c*y;
    if (tmp>0)
    {
      cnt+=(tmp-1)/x+1;
    }
  }
  if (cnt<=c) return 1;
  else return 0;
}

int main()
{
  int i,tmp;
  _int64 left,right,mid;
  scanf("%d%d%d",&n,&x,&y);
  x-=y;
  for (i=0;i<n;i++)
    scanf("%d",&a[i]);
  left=0;right=(1LL<<60);
  while (right-left>1)
  {
    mid=(left+right)/2;
    tmp=doit(mid);
    //cout<<tmp<<" "<<mid<<endl;
    if (tmp==1) right=mid;
    else left=mid;
  }
  printf("%lld\n",right);
  return 0;
}

Measured memory_bytes: 640
// Problem : E - Decrease (Judge ver.)
// Contest : AtCoder Regular Contest 079
// URL : https://atcoder.jp/contests/arc079/tasks/arc079_c
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define temptts template <class T, class... Ts>

const int N = 55, mod = 1e9 + 7, inf = 2e9;

int n;
ll ans = 0, a[N];

int main() { cin.tie(0)->sync_with_stdio(0);
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	while (true) {
		ll mx = 0;
		int pos = 0;
		for (int i = 1; i <= n; i++) {
			if (mx < a[i]) {
				mx = a[i];
				pos = i;
			}
		}
		if (mx < n) {
			break;
		}
		for (int i = 1; i <= n; i++) {
			if (i == pos) {
				a[i] %= n;
			} else {
				a[i] += mx / n;
			}
		}
		ans += mx / n;
	}
	cout << ans;
}


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

typedef long long ll ;

const ll MOD = 1000000007;

ll dp[2100][2100];

int main() {

//  std::chrono::system_clock::time_point  start, end; // 型は auto で可
//  start = std::chrono::system_clock::now(); // 計測開始時間

  int N,M;
  cin >> N >> M;
  vector< int > S(N+3),T(M+3);
  REP(i,N) cin >> S[i];
  REP(i,M) cin >> T[i];

  REP(si, N+1)
    REP(ti, M+1)
      dp[si][ti] = 0;
  
  dp[0][0] = 1;

  REP(si, N+1) {
    REP(ti, M+1) {
      if (ti-1>=0 && si-1>=0 ) {
        if (S[si-1] == T[ti-1]) dp[si][ti] = (dp[si][ti] + dp[si-1][ti-1]) % MOD;
      }
      if (si-1>=0) dp[si][ti] = (dp[si][ti] + dp[si-1][ti]) % MOD;
      if (ti-1>=0) dp[si][ti] = (dp[si][ti] + dp[si][ti-1]) % MOD;
      if (ti-1>=0 && si-1>=0) {
        if ( dp[si][ti] - dp[si-1][ti-1] < 0 ) {
          dp[si][ti] += MOD;
        }
        dp[si][ti] = (dp[si][ti] - dp[si-1][ti-1]);
      }
    }
  }
  cout << dp[N][M] << endl;

  /*
  REP(si, N+1) {
    REP(ti, M+1) {
      cout << dp[si][ti];
    }
    cout << endl;
  }
  cout << endl;
    */
  
// end = std::chrono::system_clock::now();  // 計測終了時間
// double elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(end-start).count(); //処理に要した時間をミリ秒に変換
// std::cout << elapsed << " ms" << std::endl;

}



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

int main() {
    int n, k;
    string s;
    cin >> n >> k >> s;
    int ans = 0;
    for (int i = 0; i < n - 1; ++i) if (s[i] == s[i + 1]) ans++;
    cout << min(ans + 2 * k, n - 1) << endl;
}


Measured memory_bytes: 512
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1001001001;
const ll LONGINF = 1001001001001001LL;
const ll MOD = 1000000007LL;

const double EPS = 1e-12;
double dp[110][51][51];
int main() {
    int N, M, L; cin >> N >> M >> L;
    vector<int> P(N), T(N), V(N);
    for(int i=0; i<N; i++) {
        cin >> P[i] >> T[i] >> V[i];
    }

    for(int x=0; x<N; x++) {
        dp[x][0][0] = 1.0;
        double p = 1.0 * P[x] / 100;
        
        for(int i=0; i<=M; i++) {
            for(int j=0; j<=M; j++) {
                // fprintf(stderr, "dp[%d][%d][%d] = %.12f\n", x, i, j, dp[x][i][j]);
                
                if(i == M or dp[x][i][j] < EPS) continue;
                // やすむ
                dp[x][i+1][j+1] += dp[x][i][j] * p;

                // やすまない
                dp[x][i+1][j  ] += dp[x][i][j] * (1 - p);
            }
        }

        // るいせき
        for(int j=1; j<=M; j++) dp[x][M][j] += dp[x][M][j-1];
    }

    for(int x=0; x<N; x++) {
        // x 番目の人が i 回休んだ場合
        double ans = 0.0;
        for(int i=0; i<=M; i++) {
            double p = (i ? dp[x][M][i] - dp[x][M][i-1] : dp[x][M][i]);
            double tx = 1.0 * L / V[x] + T[x] * i;
            
            // y 番目の人が j 回休む
            for(int y=0; y<N; y++) {
                if(x == y) continue;

                bool defeat = false;
                for(int j=0; j<=M; j++) {
                    double ty = 1.0 * L / V[y] + T[y] * j;
                    if(ty - tx > EPS) {
                        // fprintf(stderr, "x = %d, i = %d, y = %d, j = %d: tx = %.12f, ty = %.12f\n", x, i, y, j, tx, ty);
                        // j 回以上休んだら勝てる
                        double q = (j ? dp[y][M][j-1] : 0);
                        p *= (1 - q);
                        defeat = true;
                        break;
                    }
                }

                if(!defeat) p = 0;
            }
            ans += p;
        }
        printf("%.12f\n", ans);
    }
    return 0;
}



Measured memory_bytes: 5240
N = int(input())
Hn = list(map(int, input().split()))
Hn.reverse()
if N==1:
  print('Yes')

for i in range(N-1):
  if Hn[i] < Hn[i+1]:
    Hn[i+1] -= 1
    if Hn[i] < Hn[i+1]:
      print('No')
      break
  elif i==N-2:
    print('Yes')

Measured memory_bytes: 63856
require 'prime'
require 'set'

a, b = gets.strip.split.map(&:to_i)

pd_b = Set.new(Prime.prime_division(b).map(&:first))
pd_a = Set.new(Prime.prime_division(a).map(&:first))

# p pd_a
# p pd_b

p 1+ (pd_a & pd_b).size



Measured memory_bytes: 4220