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

typedef long long ll;
typedef pair<int,int> pii;
#define FOR(i,ii,iii)for(int i=ii;i<iii;i++)
#define RFOR(i,ii,iii)for(int i=iii-1;i>=ii;i--)
#define OUT(a)cout<<a<<endl
#define ALL(s) s.begin(),s.end()
#define PB push_back
#define mset(a,b) memset(a,b,sizeof(a))
#define ANS(a) OUT(res.size());for(auto i:a)cout<<i<<" ";ENDL
#define PRINT(a,init,end) FOR(i,init,end) cout<<a[i]<<" ";ENDL
#define PRINTV(a) for(auto i:a)cout<<i<<" ";ENDL
#define F first
#define S second

const int N=1e5+15;
int n,k;
int a[N],dp[N];
int solve(int k) {
  if(!k)return 0;
  if(dp[k]!=-1)return dp[k];
  int res=0;
  FOR(i,0,n) {
    if(a[i]>k)continue;
    if(!solve(k-a[i]))res=1;
  }
  dp[k]=res;
  return res;
}

int main() {
  mset(dp,-1);
  ios::sync_with_stdio(false);
  cin>>n>>k;
  FOR(i,0,n)cin>>a[i];
  if(solve(k))cout<<"First"<<endl;
  else cout<<"Second"<<endl;
}

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

long long gcd(long long N, long long X){
  if (X == 0) return N;
  else return gcd(X, N%X);
}


int main(){
  long long N, X;
  cin >> N >> X;
  cout << 3*(N - gcd(N,X)) << endl;
}


Measured memory_bytes: 256
#! python3
# structured_programming.py

n = int(input())

for i in range(1, n+1):
    if i%3 == 0:
        print(' ' + str(i), end='')
    else:
        x = i
        while x != 0:
            if x%10 == 3:
                print(' ' + str(i), end='')
                break
            x = int(x/10)
print('')


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

#define REP(i ,n) for(int i=0 ;i < n; i++)
#define REPB(i ,n) for(int i=n; i >= 0; i--)
#define FOR(i ,m ,n) for(int i=m; i < n; i++)
#define FORB(i, m, n) for(int i=m; i>= m; i--)
#define ll long long
#define pb push_back
#define popb pop_back
using namespace std;
vector<int> f;
int makeFib(int k){
    f.pb(1);
    f.pb(1);
    if(k >= 2){
    FOR(i,2,(k + 1)){
        f.pb(f[i - 2] + f[i - 1]);
      }
    }
      return f[k];
  }
int main(){
  int n;
  cin >> n;

  cout << makeFib(n) << endl;
}


Measured memory_bytes: 3152
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
int MAX = 100100;
int A[100100], M[100100], L[100100], R[100100];
signed main() {
  int N; cin >> N;
  for (int i = 0; i < N; i++) cin >> A[i];
  
  L[0] = 0;
  for (int i = 0; i < N; i++) {
    L[i+1] = __gcd(L[i], A[i]);
  }

  R[N+1] = 0;
  for (int i = N; i >= 0; i--) {
    R[i] = __gcd(R[i+1], A[i]);
  }

  for (int i = 0; i < N; i++) {
    M[i] = __gcd(L[i], R[i+1]);
  }
  
  int ans = -1;
  for (int i = 0; i < N; i++) {
    ans = max(ans, M[i]);
  }

  cout << ans << endl;
}


Measured memory_bytes: 3328
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
int main()
{
	int t=0,ac=0,tle=0,wa=0,re=0;
	cin>>t;
	for(int i=0;i<t;i++)
	{
		string s;
		cin>>s;
		if(s=="AC")	
		ac++;
		else if(s=="RE")
		re++;
		else if(s=="WA")
		wa++;
		else if(s=="TLE")
		tle++;	
	}
	cout<<"AC x "<<ac<<endl<<"WA x "<<wa<<endl<<"TLE x "<<tle<<endl<<"RE x "<<re;
	return 0;
}

Measured memory_bytes: 3624
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>

int main() {
	int a, b;

	scanf("%d %d", &a, &b);

	if (a < b) {
		printf("a < b\n");
	}else if (a > b) {
		printf("a > b\n");
	}else if (a == b){
		printf("a == b\n");
	}
	return 0;
}


Measured memory_bytes: 2064
#include <bits/stdc++.h>
using namespace std;
long long int mod = 1e9+7;
typedef long long int lli;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<lli> vlli;
typedef vector<bool> vb;
long long int max(long long int a,long long int b){
  if(a>b)
    return a;
  else
    return b;
}
long long int min(long long int a,long long int b){
  if(a<b)
    return a;
  else
    return b;
}
long long int binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1)
      res = res * a % m;
      a = a * a % m;
      b >>= 1;
    }
  return res;
}
long long binpow(long long a, long long b) {
    if (b == 0)
        return 1;
    long long res = binpow(a, b / 2);
    if (b % 2)
        return res * res * a;
    else
        return res * res;
}

lli mul(lli a,lli b){
  return (a%mod * b%mod)%mod;
}

lli add(lli a,lli b){
  return (a%mod + b%mod)%mod;
}

lli sub(lli a,lli b){
  return (a%mod-b%mod+mod)%mod;
}
 
//############################ENDOFTEMPLATE############################
int n;

void dfs(string s,char mx){
  if(s.length()==n){
    cout<<s<<endl;


  }

  
  else{
    for(char c = 'a';c<=mx;c++){
      dfs(s+c,((c==mx)?(char)(mx+1):mx));
    }
  }
}


void solve(){
  
  cin>>n;

  
  dfs("",'a');
}

 
 
 
 
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  int t = 1;
  //cin>>t;
  while(t--){
    solve();
  }
}

Measured memory_bytes: 3668
#include<iostream>
using namespace std;
int asc(const void *a, const void *b) {
  return *(int *)a - *(int *)b;
}

int main(){
    int k,n;
    cin>>n>>k;
    int h[110000];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int tmp,min=1999999999;
    qsort(h,n,sizeof(int),asc);
    for(int i=0;i<=n-k;i++){
        tmp=abs(h[i]-h[i+k-1]);
        if(min>tmp)min=tmp;
    }
    cout<<min<<endl;
    return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define newl "\n"
using namespace std;
using lli = long long int;
using vvint = vector <vector <int>>;
using pii = pair <int,int>;
const int mod = 1e9 + 7;

const int N = 2e5 + 1;

int h,w;
pair <int,int> s,d;
vector <string> a;
vector <vector <pair <int,int>>> adj;
vector <int> dist;

void add(int n1,int n2){
	for(int i = -2;i <= 2;++i){
		for(int j = -2;j <= 2;++j){
			if(i == 0 and j == 0) continue;
			else if(i == -1 and j == 0 and n1 - 1 >= 0 and a[n1 - 1][n2] == '.') adj[n1 * w + n2].push_back({(n1 - 1) * w + n2,0});
			else if(i == 1 and j == 0 and n1 + 1 < h and a[n1 + 1][n2] == '.') adj[n1 * w + n2].push_back({(n1 + 1) * w + n2,0});
			else if(i == 0 and j == -1 and n2 - 1 >= 0 and a[n1][n2 - 1] == '.') adj[n1 * w + n2].push_back({n1 * w + n2 - 1,0});
			else if(i == 0 and j == 1 and n2 + 1 < w and a[n1][n2 + 1] == '.') adj[n1 * w + n2].push_back({n1 * w + n2 + 1,0});
			else if(n1 - i >= 0 and n1 - i < h and n2 - j >= 0 and n2 - j < w and a[n1 - i][n2 - j] == '.') adj[n1 * w + n2].push_back({(n1 - i) * w + n2 - j,1});
		}
	}
}

void dij(int src){
	dist[src] = 0;
	priority_queue <pii,vector <pii>,greater<pii>> q;
	q.push({0,src});
	vector <bool> vis(h * w,0);
	while(q.size() > 0){
		int u = q.top().second;
		q.pop();
		if(vis[u]) continue;
		vis[u] = 1;
		for(auto v : adj[u]){
			int dd = v.second;
			int vv = v.first;
			if(dist[u] + dd < dist[vv]){
				dist[vv] = dist[u] + dd;
				q.push({dist[vv],vv});
			}
		}
	}
	
	return;
}

void solve(){
	cin >> h >> w;
	cin >> s.first >> s.second;
	--s.first;--s.second;
	cin >> d.first >> d.second;
	--d.first;--d.second;
	a = vector <string> (h);
	for(int i = 0;i < h;++i) cin >> a[i];
	adj = vector <vector <pair <int,int>>>(h * w);
	for(int i = 0;i < h;++i){
		for(int j = 0;j < w;++j){
			add(i,j);
		}
	}
	dist = vector <int> (h * w,mod);
	dij(s.first * w + s.second);
	if(dist[d.first * w + d.second] == mod) cout << -1 << newl;
	else cout << dist[d.first * w + d.second] << newl;
	return;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(10);
	#ifdef EXECUTE_LOCALLY
		   freopen("in.txt","r",stdin);
	#endif
	int t = 1;
	//cin >> t;
	while(t--) solve();
	#ifdef EXECUTE_LOCALLY
    	cout << setprecision(3) << "program time: " << (double)clock() / CLOCKS_PER_SEC << newl;
	#endif
	return 0;
}


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

int main()
{
    int a, b;
    cin >> a >> b;

    if(a < 0)
    {
        if(b < 0)
        {
            if((b - a) % 2 == 0)cout << "Negative" << endl;
            else cout << "Positive" << endl;
        }
        else
        {
            cout << "Zero" << endl;
        }
    }
    else if(a == 0 || b == 0)
    {
        cout << "Zero" << endl;
    }
    else
    {
        cout << "Positive" << endl;
    }
    
    
}

Measured memory_bytes: 256
/* 
 * Project: AtCoder Beginners Contest 176 C - Step
 * Author: toms74209200 <https://github.com/toms74209200>
 *
 * Created on 2020/08/22
 * Copyright (c) 2020 toms74209200
 * 
 * This software is released under the MIT License.
 * http://opensource.org/licenses/mit-license.php
 */
#include <cstdio>
#include <cstdint>
#include <vector>
using namespace std;

uint32_t n;
vector<uint32_t> a;

void solve() {

    uint64_t sum = 0;
    uint32_t max_height = 0;
    for (int i=0;i<n-1;i++) {
        max_height = max(max_height, a[i]);
        if (max_height > a[i+1]) {
            sum += max_height - a[i+1];
        }
    }
    printf("%llu\n",sum);
}

int main() {

    scanf("%d", &n);
    for (int i=0;i<n;i++) {
        uint32_t tmp = 0;
        scanf("%d", &tmp);
        a.push_back(tmp);
    }

    solve();
}

Measured memory_bytes: 3860
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

enum State {
  TATE = 0,
  YOKO = 1
};

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n;
  cin >> n;
  vector<string> S(2);
  rep(i,2) cin >> S[i];
  int start, prestate;
  mint ans;
  if (S[0][0] == S[1][0]) { //縦のドミノ
    prestate = TATE;
    ans = 3;
    start = 1;
  }
  else { //横のドミノ
    prestate = YOKO;
    ans = 6;
    start = 2;
  }
  for (int x = start; x < n; ++x) {
    if (S[0][x] == S[1][x]) { //縦のドミノ
      if (prestate == TATE) ans *= 2;
      prestate = TATE;
    }
    else { //横のドミノ
      if (prestate == TATE) ans *= 2;
      else ans *= 3;
      x++; //横向きにおくので1増やす
      prestate = YOKO;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
V = list(map(int,input().split()))

ans = 0

for m1 in range(N+1):
    for m2 in range(N-m1+1):
        for l in range(m1+m2+1):
            if m1 + m2 + l > K: continue
            if m1 + m2 > N: continue
            tmp = V[0:m1] + V[N-m2:N]
            tmp.sort(reverse = True)
            ans = max(ans,sum(tmp[0:m1+m2-l]))
print(ans)

Measured memory_bytes: 3064
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int[] a=new int[3];
		int[] b=new int[3];
		for(int i=0;i<3;i++)
			a[i]=sc.nextInt();
		b[0]=Math.abs(a[0]-a[1]);
		b[1]=Math.abs(a[1]-a[2]);
		b[2]=Math.abs(a[2]-a[0]);
		Arrays.sort(b);
		int ans=b[0]+b[1];
		System.out.println(ans);
	}
}

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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    int N, M;
    cin >> N >> M;
    pair<int,int> A[100000];
    for(int i=0;i<M;i++){
        int a, b;
        cin >> a >> b;
        A[i] = {a,b};
    }
    sort(A, A+M);
    int ans = 0;
    int next = -1;
    int j=0;
    for(int i=0;i<N;i++){
        for(;A[j].first==i;j++){
            if(next<0) next = A[j].second;
            else next = min(next, A[j].second);
        }
        if(i+1 == next){
            ans++;
            next = -1;
        }
    }

    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <map>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++) 

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 30;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

dbl w, h, x, y;

void init()
{
	cin >> w >> h >> x >> y;
}


int main()
{
	init();

	dbl mx = w / 2, my = h / 2;

	bool ans = false;
	if (mx == x && my == y)
		ans = true;

	cout << setprecision(20) << w * h / 2 << " " << ans << endl;

}


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

int main() {
  int n, x;
  cin >> n >> x;
  vector<int> vec(n);
  rep(i, n) cin >> vec.at(i);
  int d = 0;
  int i = 0;
  int sum = 0;
  rep(i, n) sum += vec.at(i);
  if(sum > x) {
    while(d <= x) {
      d += vec.at(i);
      i++;
    }
    cout << i << endl;
  }
  else cout << n + 1 << endl;
}


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

#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
int val=0,ans=INT_MIN;
void dfs(int node,vector<vector<int>> &adj,vector<bool> &visited)
{
    visited[node]=true;
    val++;
    for(auto u:adj[node])
        if(!visited[u])
            dfs(u,adj,visited);
}
int main(){
	fast;
    int n,m;
    cin>>n>>m;
    vector<vector<int>> adj(n+1);
    vector<bool> visited(n+1,false);
    for(int i=0;i<m;i++)
    {
        int a,b;
        cin>>a>>b;
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    for(int i=1;i<=n;i++)
    {
        val=0;
        if(!visited[i])
           dfs(i,adj,visited);
        ans=max(ans,val);
    }
    cout<<ans;
	return 0;
}


Measured memory_bytes: 23396
import math

a, b, x = map(int, input().split())

if x > a * a * b / 2:
    # 溢れるとき水の形が台形になってる
    # 溢れるときの台形の辺の長さ
    c = 2 * x / a ** 2 - b
    cos = (b - c) / math.sqrt((b - c) ** 2 + a ** 2)
    print(90 - math.degrees(math.acos(cos)))
else:
    # 溢れるとき水の形が三角形になってる
    # 溢れるときの底辺
    c = (x * 2) / a / b
    # print(c)
    cos = c / math.sqrt(c ** 2 + b ** 2)
    # print(cos)
    print(math.degrees(math.acos(cos)))


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
int main()
{
  long long int s=0,i,j,n;
  cin>>n;
  long long int arr[n];
  for(i=0;i<n;i++)
  {
    cin>>arr[i];
  }
  for(i=0;i<n;i++)
  {
    for(j=i+1;j<n;j++)
    {
      s+=arr[i] * arr[j];
    }
  }
  cout<<s<<endl;
  return 0;
}

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

int main(){
    string S;
    cin >> S;
    ll a = 0, b = 0;
    rep(i, 0, 3){
        if(S[i] == 'A') a++;
        else b++;
    }
    if(a == 0 || b == 0) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}

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

class Main
{
	static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                     InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

	public static void main (String[] args)
	{
		FastReader reader = new FastReader();
		int n = reader.nextInt();
		long[] arr = new long[n];
		long[] ori = new long[n];

		for (int i=0; i<n; i++)
		{
			arr[i] = reader.nextLong();
			ori[i] = arr[i];
		}

		Arrays.sort (arr);

		long mid2 = arr[n/2];
		long mid1 = arr[(n-1)/2];

		PrintWriter writer = new PrintWriter (System.out);
		for (int i=0; i<n; i++)
		{
			if (ori[i] <= mid1)
				writer.println (mid2);
			else
				writer.println (mid1);
		}

		writer.close();
	}
}


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

#define ll long long
using namespace std;

ll mod = 1000000007;

int main() {
    int h, w, k;
    cin >> h >> w >> k;
    vector<vector<ll>> transition(w, vector<ll>(w));
    for (int i = 0; i < 1 << (w - 1); i++) {

        vector<bool> change(w - 1);
        for (int j = 0; j < w - 1; j++)change[j] = (1 & (i >> j)) > 0;
        bool isok = true;
        for (int j = 1; j < w - 1; j++)
            if (change[j - 1] && change[j])isok = false;

        if (isok) {
            for (int j = 0; j < w; j++) {
                int to = j;
                if (j > 0 && change[j - 1])to = j - 1;
                if (j < w - 1 && change[j])to = j + 1;
                transition[j][to]++;
            }
        }
    }

    vector<ll> dp(w);
    dp[0] = 1;
    for (int i = 0; i < h; i++) {
        vector<ll> after(w);
        for (int from = 0; from < w; from++) {
            for (int to = 0; to < w; to++) {
                after[to] += dp[from] * transition[from][to];
                after[to] %= mod;
            }
        }
        dp = after;
    }

    cout << dp[k - 1] << endl;
    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define N 100005
#define mod 1000000007
#define boost ios_base::sync_with_stdio(false);cin.tie(0)
#define prec(n) fixed<<setprecision(n)

#define pii pair<int,int> 
#define pll pair<ll,ll> 
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int> 
#define vll vector<ll>
#define all(c) c.begin(),c.end()
#define tr(it,c) for( typeof(c.begin()) it = c.begin() ; it!=c.end() ; it++)

ll modulo(ll num){ return ((num%mod)+mod)%mod;} // for negative integer
ll power(ll b,ll e,ll MOD=mod){ll ans=1; while(e){if(e%2) ans=(ans*b)%MOD; b=(b*b)%MOD; e/=2;} return ans;}
ll inv(ll num,ll MOD=mod){ return power(modulo(num),mod-2,MOD); }

bool comp(pair<ll,ll> p1, pair<ll,ll> p2)
{
    return p1.se < p2.se ; 
}

int main()
{
    boost;
    
    ll n,i,j,l,r ; 
    
    pair<ll,ll> p1[N],p2[N];
    
    cin>>n;
    
    for(i=0;i<n;i++)
    {
        cin>>l>>r; p1[i] = mp(l,r) ; p2[i] = p1[i];
    }
    
    sort(p1,p1+n) ;
    reverse(p1,p1+n);
    
    sort(p2,p2+n,comp);
    
    
    ll ans,ind1,ind2,cur,ans2 ;
    
    ans = ans2 =  ind1 = ind2 = cur = 0 ;
    
    while(ind1<n and ind2<n)
    {
        if(p2[ind2].se < cur)
        {
            ans = ans + (cur - p2[ind2].se) ; 
            cur = p2[ind2].se ; 
            
        }
        ind2++;
        if(p1[ind1].fi > cur )
        {
            ans = ans + (p1[ind1].fi - cur) ;
            cur = p1[ind1].fi ; 
            
        }
        ind1++;
        
    }
  //  cout<<cur<<endl;
    ans = ans + abs(cur)    ;
    
    ind1 = ind2 = cur = 0 ;
    
    while(ind1<n and ind2<n)
    {
        if(p1[ind1].fi > cur )
        {
            ans2 = ans2 + (p1[ind1].fi - cur) ;
            cur = p1[ind1].fi ; 
            
        }
        ind1++;
        if(p2[ind2].se < cur)
        {
            ans2 = ans2 + (cur - p2[ind2].se) ; 
            cur = p2[ind2].se ; 
            
        }
        ind2++;
    }
    
    ans2 = ans2 + abs(cur);
    
    cout<<max(ans,ans2);
    
//    cout<<ans<<endl;    
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MAXN=220000;

vector<int> A;
 
int findPos(int x) {
	return int(upper_bound(A.begin(),A.end(),x)-A.begin()) - 1; 
}
 
struct fenwick {
	static const int SZ=2*MAXN;
	int cnt[SZ];
	ll sum[SZ];
	int totalCount;
	ll totalSum;
	
	void update(int pos,int d) {
		totalCount+=d;
		totalSum+=d*A[pos];
		for (int i=pos; i<SZ; i|=i+1) {
			cnt[i]+=d;
			sum[i]+=d*A[pos];
		}
	}
	
	void add(int x) {
		update(findPos(x),+1);
	}
	
	int queryCount(int x) const {
		int c=0;
		for (int i=findPos(x); i>=0; i&=i+1, i--) c+=cnt[i];
		return c;
	}
	
	ll querySum(int x) const {
		ll s=0;
		for (int i=findPos(x); i>=0; i&=i+1, i--) s+=sum[i];
		return s;
	}
};

int Q;
vector<tuple<int,int,int>> query;
fenwick F;

int main() {
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	cout<<fixed<<setprecision(10);

	
	cin>>Q;
	rep(i,0,Q) {
		int q,a=0,b=0;
		cin>>q;
		if (q==1) cin>>a>>b;
		query.emplace_back(q,a,b);
		A.push_back(a);
	}
	
	sort(A.begin(),A.end());
	A.resize(int(unique(A.begin(),A.end())-A.begin()));
	
	ll totalB=0;
	rep(i,0,Q) {
		int q,a,b;
		tie(q,a,b)=query[i];
		
		if (q==1) {
			F.add(a);
			totalB+=b;
		} else {
			int l=-int(1e9+1),r=int(1e9+1);
			while (l<r) {
				int m=l+(r-l)/2;
				if (2*F.queryCount(m)<F.totalCount) l=m+1; else r=m;
			}
			
			int x=l;
			ll cnt=F.queryCount(x);
			ll sum=F.querySum(x);
			ll val=cnt*l-sum + (F.totalSum-sum)-(F.totalCount-cnt)*x + totalB;
			cout<<x<<" "<<val<<"\n";
		}
	}
}


Measured memory_bytes: 10160
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;
typedef unsigned int uint;
typedef long long ll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

const int MAXBITS=11;

int bitcount(int val) {
    int ans=0;
    int bit=1;
    fori(MAXBITS)  {
        if(val&bit)
            ans++;
        bit<<=1;
    }
    return ans;
}

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
int n, m;
    cin>>n>>m;
    vector<vector<int>> k(m);
    fori(m) {
        int s; cin>>s;
        for(int j=0; j<s; j++) {
            int x;
            cin>>x;
            k[i].push_back(x);
        }
    }
    vector<int> p(m);
    fori(m) {
        cin>>p[i];
        p[i]%=2;
    }

/* For each bulb we can create set of bits (M bits) where the bulb is "on". 
 * Intersection of all sets is ans;
 */

    const int N=1<<(n);   // max 1024
    vector<bool> gmask(N, true);
    fori(m) {
        /* create mask for bulb i */
        int mask=0;
        for(auto b : k[i]) 
            mask|= 1<<(b-1);

        for(int j=0; j<N; j++)
            gmask[j]= gmask[j] && bitcount(mask&j)%2==p[i];
    }
    
    int ans=0;
    fori(N)
        if(gmask[i])
            ans++;
    cout<<ans<<endl;
}



Measured memory_bytes: 256
//#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

typedef pair<long long, long long> pl;

long long N, M, k, a, b, c, d, e, H, W,X;
long long A[200000] = {};
long long B[200002] = {};
long long tt[20000] = {};
bool f;
bool ff;
string S, SS;
set <long long>sll;
pl buf;
vector <long long>vpl[100002];
vector <long long>vl;


int main() {

	cin >> N;
	a = 2000000000000000;
	for (int i = 0; i < 5; i++) {
		cin >> A[i];
		if (A[i] < a) {
			a = A[i];
			b = i;
		}
	}

	d = N / a;
	if (N%a != 0) {
		d++;
	}

	cout <<d + 4<< endl;


	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
	int n, i, j, tmpa, tmpx, tmpy;
	ll it;
	cin >> n;
	vector< vector< pair <int, int> > > tale(n);
	int ans = 0;
	ll pattern = 0;
	int counter;

	
	for (i = 0; i < n; i++) {
		cin >> tmpa;
		for (j = 0; j < tmpa; j++) {
			cin >> tmpx >> tmpy;
			tale[i].push_back(make_pair(tmpx, tmpy));
		}
	}

	// cout << "OK input is:" << endl;
	// cout << "N : " << n << endl;
	// for (i = 0; i < n; i++) {
	// 	cout << "A(" << i + 1 << ") : " << tale[i].size() << endl;
	// 	for (j = 0; j < tale[i].size(); j++) 
	// 		cout << tale[i][j].first << " " << tale[i][j].second << endl;
	// }

	for (pattern = 1; pattern < pow(2, n); pattern++) {
		bool ok = true;
		ll checker, tmp_pattern;
		int index;
		tmp_pattern = pattern;
		for (checker = 1, index = 0; checker < pow(2, n); checker = checker << 1, index++) {
			if (checker & tmp_pattern) {
				for (i = 0; i < tale[index].size(); i++) {
					if ((((tmp_pattern >> (tale[index][i].first - 1)) & 1) ^
						 tale[index][i].second) == 1) {
						
						ok = false;
						break;
					}
				} 	
			}
			if (!ok)
				break;
		}					

		if (ok) {
			counter = 0;
			while (tmp_pattern != 0) {
				if (tmp_pattern & 1)
					counter++;
				tmp_pattern = tmp_pattern >> 1;
			}
			ans = max(ans, counter);
		}	   
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define loop(i,L,R) for(int i=(L);i<=(R);i++)
const int maxn=1e3+5;
ll a[maxn];
int main()
{
    ll n;
    cin>>n;
    loop(i,0,4) cin>>a[i];
    int pos=min_element(a,a+5)-a;
    ll ans=(n+a[pos]-1)/a[pos]+4;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string st,x,y;
	int maxv=0;
	cin>>n>>st;
	for(int i=0;i<n;i++){
		x=st.substr(0,i+1);
		y=st.substr(i+1,n-x.size());
		bool f[26]={false};
		int sum=0;
		for(int j=0;j<x.size();j++){
			f[x[j]-'a']=true;
		}
		for(int j=0;j<y.size();j++){
			if(f[y[j]-'a']==true){
				sum++;
				f[y[j]-'a']=false;
			} 
		}
		if(sum>maxv) maxv=sum;
	} 
	cout<<maxv;
	return 0;
}


Measured memory_bytes: 384
N, M = map(int, input().split())
A = sorted(list(map(int, input().split())))
BC = [None] * M
for i in range(M):
    BC[i] = tuple(map(int, input().split()))
BC.sort(key=lambda tpl: tpl[1], reverse=True)  # sort by C descendant

D = [0] * N
i = 0
j = 0
while i < N and j < M:
    b, c = BC[j]
    for k in range(i, min(i + b, N)):
        D[k] = c
    i += b
    j += 1

for i in range(N):
    A[i] = max(A[i], D[i])

print(sum(A))


Measured memory_bytes: 74776
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<58);

vec memo(ll(2e+5), -1);
ll dfs(ll n){
    if(n == 0) return 0;
    if(memo[n] != -1) return memo[n];
    ll temp = n, res = 0;
    while(temp){
        res += temp&1;
        temp /= 2;
    }
    return memo[n] = dfs(n % res) + 1;
}


int main() {
    cin>>N;
    vec a(N), res(2);
    mat two(2, vec(N, 0));
    rep(i,N){
        char c;
        cin>>c;
        a[i] = (c == '1');
    }
    ll sum = accumulate(ALL(a), 0LL);
    two[0][N - 1] = 1;
    if(sum > 1) two[1][N - 1] = 1;
    Rrep(i, N){
        if(i != N - 1) {
            two[0][i] = (two[0][i+1] * 2) % (sum + 1);
            if(sum > 1) two[1][i] = (two[1][i+1] * 2) % (sum - 1);
        }
        if(a[i]){
            (res[0] += two[0][i]) %= sum + 1;
            if(sum > 1) (res[1] += two[1][i]) %= sum - 1;
        }
    }
    rep(i,N){
        ll out = res[a[i]];
        //cout<<out<<endl;
        if(a[i]) (out += sum - 1 - two[1][i]) %= max(sum - 1, 1LL);
        else (out += two[0][i]) %= sum + 1;
        if(sum == 1 && a[i]){
            cout<<0<<endl;
        }else{
            cout<<dfs(out) + 1<<endl;
        }
    }
}


Measured memory_bytes: 11176
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define ll long long 
#define PB push_back
#define FAST ios::sync_with_stdio(false);cin.tie(0);
 
const int MAXN = 5e3 + 100;


int main() {
    FAST
    long long int n; cin >> n;
    long long int ans = pow(n , 2);
    cout << ans << endl;
}

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

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

  int road[6];
  for(int i = 0; i < 6; i++) {
    cin >> road[i];
  }
  sort(road, road+6);
  int count = 0;
  for(int i = 1; i < 6; i++) {
    if(road[i-1] == road[i]) count++;
    else count = 0;
    if(count >= 2) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << "YES" << endl;

}


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

#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdint.h>
#include <string.h>

#define _USE_MATH_DEFINES
#include <math.h>

#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <string>

#include <algorithm>
#include <functional>
#include <bitset>
#include <functional>
#include <chrono>
#include <random>

#define sqr(x) (x) * (x)

typedef unsigned int u32;
typedef int i32;
typedef unsigned long long int u64;
typedef int i64;
typedef uint16_t u16;
typedef int16_t i16;
typedef uint8_t u8;
typedef int8_t i8;

using namespace std;
using namespace std::chrono;

const i64 mod = 1'000'000'000ll + 7;
//const i64 smod = 998244353ll;
//const i64 inf = 1'000'000'000'000'000'000ll + 7;
//const i64 inf = 1'000'000'007;

const long double eps = 1e-8;

const i64 MAXN = 100'000 + 6;



void bfs() {

}

int main(int argc, char* argv[]) {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(15); cout.setf(ios::fixed);

    i64 n, m;
    cin >> n >> m;
    vector<vector<i64>> e;
    e.resize(n + 1);
    for (i64 i = 0; i < m; i++) {
        i64 u, v;
        cin >> u >> v;
        e[u].push_back(v);
        e[v].push_back(u);
    }


    vector<i64> q;
    vector<i64> z(n + 1);
    vector<i64> p(n + 1);

    q.push_back(1);
    z[1] = 1;
    for (i64 i = 0; i < q.size(); i++) {
        i64 u = q[i];

        for (auto v : e[u]) {
            if (z[v]) {
                continue;
            }

            z[v] = 1;
            q.push_back(v);
            p[v] = u;
        }
    }

    for (i64 i = 2; i <= n; i++) {
        if (p[i]) {
            continue;
        }
        cout << "No" << endl;
        return 0;
    }

    stringstream ss;
    for (i64 i = 2; i <= n; i++) {
        ss << p[i] << endl;
    }
    cout << "Yes" << endl;
    cout << ss.str();
    return 0;
}

Measured memory_bytes: 12140
def main(piece, c):
    for h in range(n-m+1):
        for w in range(n-m+1):
            if f(piece, h, w):
                break
    if c != 4:
        move(piece, c)

def f(piece, h, w):
    global ans
    coordinate = None
    for _h in range(m):
        for _w in range(m):
            if piece[_h][_w] != '-1':
                if piece[_h][_w] == picture[h+_h][w+_w]:
                    if coordinate is None:
                        coordinate = (int(w+_w+1), int(h+_h+1))
                else:
                    return
    else:
        if ans is None:
            ans = coordinate
        elif coordinate[1] < ans[1]:
            ans = coordinate
        elif coordinate[1] == ans[1]:
            if coordinate[0] < ans[0]:
                ans = coordinate
        return True
    
def move(piece, c):
    _piece = []
    for w in range(m):
        lis = []
        for h in range(m):
            lis.append(piece[h][w])
        else:
            lis.reverse()
            _piece.append(lis)
    else:
        main(_piece, c+1)

while True:
    n, m = map(int, raw_input().split())
    if n == m == 0: break
    picture = [raw_input().split() for i in range(n)]
    piece = [raw_input().split() for i in range(m)]
    ans = None
    main(piece, 1)
    if ans:
        print ans[0], ans[1]
    else:
        print 'NA'

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

using namespace std;

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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> P(D + 1), C(D + 1);
  for (int i = 1; i <= D; i++) {
    cin >> P[i] >> C[i];
  }
  vector<vector<int>> dp(15, vector<int>(2005));
  for (int i = 1; i <= D; i++) {
    for (int j = 0; j <= 1000; j++) {
      chmax(dp[i + 1][j], dp[i][j]);
      for (int k = 1; k <= P[i]; k++) {
        int s = dp[i][j] + 100 * i * k;
        if (k == P[i]) s += C[i];
        chmax(dp[i + 1][j + k], s);
      }
    }
  }
  for (int i = 0; i <= 1000; i++) {
    if (dp[D + 1][i] >= G) {
      cout << i << endl;
      break;
    }
  }

  return 0;
}
/* vim:set fdm=marker: */


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define lowbit(a) ((a)&(-(a)))
using namespace std;



int n;
int a[100000 + 5];

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	int flag = 0;
	for (int i = 0; i < n; i++)
	{
		flag ^= a[i];
	}
	if (flag==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>


int main(){
  int N; cin >> N;
  string S; cin >> S;
  int r[N] = {}, l[N] = {};

  for (int i=N-1;i>=0;i--){
    if (i==N-1) r[i] = 0;
    else r[i] = r[i+1] + (S[i+1]=='.');
  }
  for (int i=0;i<N;i++){
    if (i==0) l[i] = 0;
    else l[i] = l[i-1] + (S[i-1]=='#');
  }

  int ans = N;
  rep(i,N){
    ans = min(ans, l[i]+r[i]);
  }
  cout << ans << endl;



  

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 5304
/*   Author : Rshs
 *   Data : 2019-10-06-16.27
 */
#include<bits/stdc++.h>
using namespace std;
#define FI first
#define SE second
#define LL long long
#define MP make_pair
#define PII pair<int,int>
#define SZ(a) (int)a.size()
const double pai = acos(-1);
const double eps = 1e-10;
const LL mod = 1e9+7;
const int MXN = 1e6+5;
int n;
char mp[205][205];
int col[205];
int g[205][205];
int notbg(int u,int nowcol){
    int re=0;
    for(int v=1;v<=n;v++){
        if(mp[u][v]=='0')continue;
        if(col[v]==nowcol) re++;
        if(col[v]==0) col[v]=-nowcol,re+=notbg(v,-nowcol);
    }
    return re;
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++)scanf("%s",mp[i]+1);
    if(notbg(1,1)) return puts("-1"),0;
    for(int i=1;i<=n;i++)for(int j=1;j<=n;j++) {
        g[i][j]=mp[i][j]-'0';
        if(g[i][j]==0) g[i][j]=INT_MAX/2;
    }
    for(int i=1;i<=n;i++) g[i][i]=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++) g[j][k]=min(g[j][k],g[j][i]+g[i][k]);
        }
    }
    int dis=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) dis=max(dis,g[i][j]);
    }
    cout<<dis+1;
    return 0;
}


Measured memory_bytes: 512
/*

#      #      #####   ##   ##  #####      ##     #  #      #   #  #####
#      #      #   #  #  ###  # #          # ##   #  #      #   #  #   #
#      #      #   #  #   #   # #          #  ##  #  #      #   #  #   #
#      #      #   #   #     #  #####      #   #  #  #       ###   #####
#      #      #   #    #   #   #          #  ##  #  #        #    #   #
#      #      #   #     ###    #          # ##   #  #        #    #   #
#      #####  #####      #     #####      ##     #  #####    #    #   #

*/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <llong> vl;
typedef vector <string> vs;
typedef vector <vector <llong>> matrix;

typedef pair <llong, llong> pll;

typedef map <llong, llong> mll;

typedef set <llong> sl;

const llong MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

llong n;
llong a[MXN];

llong get (llong x) {
    for (llong i = 1; i <= n; ++ i) {
        x -= x % a[i];
    }
    return x;
}

int main () {
    android;
    random_device rand;
    #ifdef I_LOVE_DILYA
        freopen ("input.txt", "r", stdin);
    #endif
    cin >> n;
    for (llong i = 1; i <= n; ++ i) cin >> a[i];
    llong l = 2, r = 2;
    for (llong i = n; i >= 1; -- i) {
        llong x = (l + a[i] - 1) / a[i] * a[i];
        llong y = r / a[i] * a[i];
        if (x > y) return cout << -1, 0;
        l = x;
        r = y + a[i] - 1;
    }
    cout << l << ' ' << r;
    return 0;
}

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

int main(){
    long n,a,b,cnt=0,cnt2=0;
    string s;
    cin>>n>>a>>b>>s;
    for(int i=0; i<s.size(); i++){
        if(s[i]=='a'){
            if(cnt<a+b){
                cout<<"Yes"<<endl;
                cnt++;
            }else{
                cout<<"No"<<endl;
            }
            // cout<<cnt<<endl;
        }else if(s[i]=='b'){
            if(cnt<a+b && cnt2<b){
                cout<<"Yes"<<endl;
                cnt++;
                cnt2++;
            }else{
                cout<<"No"<<endl;
            }
            // cout<<cnt<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
}

Measured memory_bytes: 896
import sys

N,K=map(int, sys.stdin.readline().split()) 
T=[ map(int, sys.stdin.readline().split()) for i in range(N) ]
T=sorted(T, key=lambda x:(x[0],-x[1]))

KI=[]	#KIND
A=[]	#Nokori

x=None
for t,d in T:
	if t != x:
		KI.append(d)
		x=t
	else:
		A.append(d)

KI.sort(reverse=True)
A.sort(reverse=True)

KI_S=[0]		#KI Ruiseki sum
A_S=[0]		#A Ruiseki sum

for x in KI: KI_S.append( KI_S[-1]+x )
for x in A:  A_S.append( A_S[-1]+x )


la=len(A_S)
lk=len(KI_S)

ans=0
for k in range(1,K+1):
	if K-k<la and k<lk:
		ans=max (ans , KI_S[k]+k**2+A_S[K-k] )

print ans


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

int main(void) {
        int a, b;
        
        cin >> a >> b;
        
        cout << a / b << " " << a % b << " " << fixed << setprecision(5) << 1.0 * a / b << endl;
        
        return 0;
}

Measured memory_bytes: 1248
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!

#include <bits/stdc++.h>
using namespace std;

#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

using ll = int64_t; using vll = vector<ll>; using vvll = vector<vll>;
using pll = pair<ll, ll>; using vpll = vector<pll>; using vvpll = vector<vpll>;

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

ll n;
vll a, b;

void func() {
    cin >> n;
    a.resize(n + 1);
    b.assign(n + 1, 0);
    for (ll i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (ll i = n; i >= 1; i--) {
        for (ll j = i; j <= n; j += i) {
            b[i] ^= b[j];
        }
        b[i] ^= a[i];
    }
    cout << accumulate(b.begin(), b.end(), 0) << endl;
    for (ll i = 1; i <= n; i++) {
        if (b[i] == 1) {
            cout << i << ' ';
        }
    }
    cout << endl;
}

int main() {
    fast_io; cout.precision(32);
    ll t = 1; // cin >> t;
    for (ll i = 1; i <= t; i++) {
        func();
    }
}


Measured memory_bytes: 3968
a_str = input()
r_str = a_str[::-1]
n = (len(a_str) - 1) // 2

head = a_str[0:n]
back = a_str[len(a_str) - n:]

if a_str == r_str:
    if head == head[::-1] and back == back[::-1]:
        print('Yes')
    else:
        print('No')
else:
    print('No')


Measured memory_bytes: 2940
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <bitset>
using namespace std;
using ll = long long;
constexpr ll INF = 1010000000000000017LL;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define all(v) v.begin(), v.end()

ll GCD(ll a, ll b) { if(b==0) return a; else return GCD(b, a%b); }
ll LCM(ll a, ll b) { return a/GCD(a,b)*b; }

class AAirplane {
public:
	void solve(std::istream& in, std::ostream& out) {
	    ll p,q,r;in>>p>>q>>r;
	    out<<min(p+q,min(q+r,r+p));

	}
};


int main() {
	AAirplane solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

int main() {
  int N, K, d, A, x = 0;
  cin >> N >> K;
  vector<int> v(N, 1);
  for (int i = 0;i < K;i++) {
    cin >> d;
    for (int j = 0;j < d;j++) {
      cin >> A;
      v[A - 1] = 0;
    }
  }
  for (int i = 0;i < N;i++) {
    x = x + v[i];
  }
  cout << x << endl;
}

Measured memory_bytes: 3636
n,t=map(int,input().split())
ct=[list(map(int,input().split())) for _ in range(n)]
mc=100000
for i in range(n):
    if ct[i][1]<=t:
        if ct[i][0]<mc:
            mc=ct[i][0]
if mc==100000:
    print("TLE")
else:
    print(mc)

Measured memory_bytes: 3060
package main

import (
  "fmt"
  "strconv"
  "math"
)

func main() {
  var a, b int
  fmt.Scan(&a, &b)
  num, _ := strconv.Atoi(strconv.Itoa(a) + strconv.Itoa(b))
  // fmt.Println(num)
  root := math.Sqrt(float64(num))
  // fmt.Println(root)
  if math.Ceil(root) == root{
    fmt.Println("Yes")
  }else{
    fmt.Println("No")
  }
}


Measured memory_bytes: 512
Q = int(input())
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
MAX = 10**5
sum = [0] * (MAX+2)

is_prime = [1] * (MAX+1)
is_prime[0] = 0
is_prime[1] = 0
for i in range(2, MAX+1):
    if is_prime[i]:
        for j in range(i*2, MAX+1, i):
            is_prime[j] = 0

for i in range(MAX+1):
    if is_prime[i] and is_prime[(i+1)//2]:
        sum[i+1] = sum[i] + is_prime[i]
    else:
        sum[i+1] = sum[i]
        
for i in range(Q):
    print(sum[r[i]+1] - sum[l[i]])


Measured memory_bytes: 13344
//written by libra9z
#include <algorithm>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cmath>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define repit(it,a) for (__typeof(a.begin()) it=a.begin();it!=a.end();++it)
#define ITR(...) __VA_ARGS__::iterator
#define all(a) (a).begin(),(a).end()
#define reunique(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define sz(a) (int)a.size()
#define MP(...) make_pair(__VA_ARGS__)
#define X first
#define Y second
#define sqr(x) ((x)*(x))
const int inf=1e9;
const long long lnf=1e18;
const int mod=1e9+7;
int n;
string s;
int main()
{
	ios_base::sync_with_stdio(0);cin.tie();cout.tie();
	cout<<setprecision(15);
	cin>>s>>n;
	if (sz(s)>=5)
	{
		string t=s;
		reunique(t);
		int uy=max(5,sz(t));
		set <string> st[uy];
		for (int jk=0;jk<uy;++jk) for (int i=0;i<sz(s);++i)
		{
			if (s[i]==t[jk]) for (int j=1;j+i<=sz(s) && j<=6;++j) st[jk].insert(s.substr(i,j));
		}
		int jk=0;
		while (n)
		{
			if (n>st[jk].size()) n-=st[jk].size();
			else
			{
				int i=1;
				for (auto &x:st[jk])
				{
					if (i==n)
					{
						cout<<x<<endl;
						return 0;
					}
					i++;
				}
			}
			jk++;
		}
		return 0;
	}
	set <string> st;
	for (int i=0;i<sz(s);++i) for (int j=1;j+i<=sz(s);++j) st.insert(s.substr(i,j));
	int i=1;
	for (ITR(set<string>) it=st.begin();it!=st.end();++it)
	{
		if (i==n)
		{
			cout<<*it<<endl;
			return 0;
		}
		i++;
	}
	return 0;
}

Measured memory_bytes: 2176
#include "bits/stdc++.h"
using namespace std;
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=(int)(n1);i<(int)(n2);i++)
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define RREP(i,n) for(ll i=((ll)(n)-1);i>=0;i--)
#define FOR(i,n1,n2) for(ll i=(ll)(n1);i<(ll)(n2);i++)
#define put(a) cout<<a<<"\n"
#define all(a)  (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
constexpr auto oorret = 0;
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
template<typename T1, typename T2> inline bool chmin(T1& a, T2 b) { if (a > b) { a = b; return 1; }return 0; }
template<typename T1, typename T2> inline bool chmax(T1& a, T2 b) { if (a < b) { a = b; return 1; }return 0; }

int main() {
	vector<int> n(4);
	vector<int> a = { 1,4,7,9 };
	REP(i, 4) {
		cin >> n[i];
	}
	SORT(n);
	if (a == n) {
		put("YES");
	}
	else {
		put("NO");
	}
	return 0;
}


Measured memory_bytes: 256