akhauriyash/Code-Regression huggingface dataset:
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0620?year=2016

#include <bits/stdc++.h>

using namespace std;

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

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

    for (int k = 1; k <= m; ++k) {
        for (int j = 0; j < n - 1; ++j) {
            if (a[j] % k > a[j + 1] % k) {
                swap(a[j], a[j + 1]);
            }
        }
    }

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

/*
 *
 */


Measured memory_bytes: 3088
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

ll q,h,s,d;
ll n;

int main(){
  cin>>q>>h>>s>>d;
  cin>>n;

  ll min1 = min(q*4,h*2);
  min1 = min(min1,s);
  ll min2 = min(q*8,h*4);
  min2 = min(min2,s*2);
  min2 = min(min2,d);

  cout<<min2*(n/2)+min1*(n%2)<<endl;

  return 0;
}


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

int main() {
  int N, M, s, c, c1 = 10, c2 = 10, c3= 10;
  cin >> N >> M;
  for (int i=0; i<M;i++){
    cin >> s >> c;
    if (s==1){
      if ((c == 0)&&(N>=2)){
        c1 = -1;
      }
      else if (c1==10){
        c1 = c;
      }
      else{
        if (c1 == c){

        }
        else{
          c1 = -1;
        }
      }
    }
    else if (s==2){
      if (c2==10){
        c2 = c;
      }
      else{
        if (c2== c){

        }
        else{
          c2 = -1;
        }
      }
    }
    else{
      if (c3==10){
        c3 = c;
      }
      else{
        if (c3 == c){

        }
        else{
          c3 = -1;
        }
      }
    }
  }
  if ((c1==-1)||(c2==-1)||(c3==-1)){
    cout << "-1"<<endl;
  }
  else if (!(c1 == 10)){
    cout << c1;
    if (!(c2 ==10)&&(N>=2)){
      cout << c2;
      if (!(c3 ==10)&&(N>=3)){
        cout << c3;
      }
      else if ((c3==10)&&(N>=3)){
        cout << 0;
      }
      else{}
    }
    else if ((c2==10)&&(N>=2)){
      cout <<0;
      if (!(c3 ==10)&&(N>=3)){
        cout << c3;
      }
      else if ((c3==10)&&(N>=3)){
        cout << 0;
      }
      else{}
    }
    else{}
  }
  else{
    if (N == 1){
      cout << 0;
    }
    else{
      cout <<1;
    }
    if (!(c2 ==10)&&(N>=2)){
      cout << c2;
      if (!(c3 ==10)&&(N>=3)){
        cout << c3;
      }
      else if ((c3==10)&&(N>=3)){
        cout << 0;
      }
      else{}
    }
    else if ((c2==10)&&(N>=2)){
      cout <<0;
      if (!(c3 ==10)&&(N>=3)){
        cout << c3;
      }
      else if ((c3==10)&&(N>=3)){
        cout << 0;
      }
      else{}
    }
    else{
      
    }
  }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int IsPrime(int);
int main() {
  int i,count=0,n,*sosu;
    scanf("%d",&n);
    
    sosu = (int *)malloc(n * sizeof (int));
    
   
    
    for(i=n-1;i>=0;i--){
        scanf("%d",&sosu[i]);
        if(IsPrime(sosu[i]) == 1) count++;
    }
    printf("%d\n",count);
    return 0;
}

 int   IsPrime(int n){


    


   int i;

    if (n < 2)
        return 0;
    else if (n == 2)
        return 1;

    if (n % 2 == 0)
        return 0;

    for (i = 3; i <= n / i; i += 2)
         if (n % i == 0)
            return 0;
    return 1;

}



Measured memory_bytes: 2100
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int sum[300005][2];
int main(){
    int i, j, n, ans=0x7fffffff;
    char ch;
    scanf("%d", &n);
    for(i=1; i<=n; i++){
        scanf(" %c", &ch);
        sum[i][ch=='E']=1;
    }
    for(i=2; i<=n; i++) sum[i][0]+=sum[i-1][0];
    for(i=n-1; i; i--) sum[i][1]+=sum[i+1][1];
    for(i=1; i<=n; i++) ans=min(ans, sum[i-1][0]+sum[i+1][1]);
    printf("%d", ans);
    return 0;
}
//W - E

Measured memory_bytes: 2560
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

void solve(ll a, ll b) {
  cout << a - (a>b) << endl;
}

int main() {
  ll a;
  cin >> a;
  ll b;
  cin >> b;
  solve(a, b);
  return 0;
}


Measured memory_bytes: 256
n=int(input())
c = []
s = []
f = []
for i in range(n-1):
    x,y,z = map(int,input().split())
    c.append(x)
    s.append(y)
    f.append(z)


for i in range(0,n-1):
    t = s[i] + c[i]
    i = i + 1
    while i < n -1:
        if t < s[i]:
            t = s[i] + c[i]
            i = i + 1
        else:
            if t%f[i] == 0:
                t = t + c[i]
                i = i + 1
            else:
                t = (t//f[i]+1)*f[i] + c[i]
                i = i + 1
    print(t)
print(0)

Measured memory_bytes: 3188
#include <string>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <cmath>
#include <limits>
#include <tuple>
#include <queue>
#include <stack>

using namespace std;
typedef long long ll;

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()


int main()
{
	ll X, Y;
	cin >> X >> Y;
	int ans = 0;
	for (ll y = Y; y >= X; y /= 2)
		ans++;
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int binarySerch( const vector<int>& data, int target )
{
	int low, high;
	int answer = 0;
	low = 0;
	high = data.size() - 1;

	while( low <= high ){
		int ix = ( low + high ) / 2;
		answer++;
		
		if( data[ix] > target ){
			high = ix - 1;
		}else if( data[ix] < target ){
			low = ix + 1;
		} else {
			return answer;
		}
	}

	return answer;
}

int main(int argc, char const* argv[])
{
	int n;
	vector<int> data;
	int target;

	while( cin >> n && n != 0 ){
		data.clear();
		for( int i = 0;i < n;i++ ){
			int input;
			cin >> input;
			data.push_back( input );
		}
		cin >> target;

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

		cout << binarySerch( data, target ) << endl;
	}
	return 0;

}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
#define ll long long 
#define pb push_back
#define mk make_pair
#define x first
#define y second
#define deb(x) cout<< #x <<" "<<x<<"\n";
#define deb1(x,y) cout<< #x<<" "<<x<<" "<<#y<<" "<<y<<"\n";
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(a) (int)a.size()
const ll MOD=1e9+7;
const int MAX=1e3;
const int MAX2=1025;
const ll inf=LLONG_MAX;
const double EPS=1e-6;
int dcmp(double x,double y)
{return (fabs(x-y)<=EPS)?0:(x<y)?1:-1;}
void init(){
	ios
	///cout << fixed << setprecision(15);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
}

int main()
{	init();
	int l;
	cin>>l;
	vector<int>s;
	for(int i=0;i<25;i++)
		if((l&(1ll<<i))!=0)
		s.pb(i);
	int node,edge;
	node=s[sz(s)-1]+1;
	edge=2*(node-1)+sz(s)-1;
	cout<<node<<" "<<edge<<"\n";
	for(int i=1;i<node;i++)
	{
		cout<<i<<" "<<i+1<<" "<<0<<"\n";
		cout<<i<<" "<<i+1<<" "<<(1ll<<(i-1))<<"\n";
	}
	int x=(1ll<<s[sz(s)-1])-1;
	for(int i=0;i<sz(s)-1;i++)
	{

		cout<<1+s[i]<<" "<<node<<" "<<(x+1)<<"\n";
		x+=(1<<s[i]);
	}

	
	
	


}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
int maxt=0;
int main()
{
	string a;
	cin>>a;
	for(int i=1;i<a.size()-1;i+=2)
	{
		int flag=true;
		for(int j=0;j<=i/2;j++)
		{
			if(a[j]!=a[j+i/2+1])
			{	
			flag=false;
				break;
			
			}
		}
		if(flag)
		{
			maxt=i+1;
		}
	}
	cout<<maxt;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		if (A.endsWith(String.valueOf(B.charAt(0))) && B.endsWith(String.valueOf(C.charAt(0)))) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


Measured memory_bytes: 20820
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
main(){
	int n;
	cin>>n;
	int a[n],cnt=1,ans=0;
	r(i,n)cin>>a[i];
	vector<int>v;
	r(i,n-1){
		if(a[i]!=a[i+1])cnt++;
		else{
			v.push_back(cnt);
			cnt=1;
		}
		if(i==n-2)v.push_back(cnt);
	}
	r(i,v.size()){
		int x=0;
		r(j,3){
			if(i+j>=(int)v.size())break;
			x+=v[i+j];
		}
		ans=max(ans,x);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
using namespace std;
string reverseStr(string& str);
int main(){
    int flg,strsize;
    string str,str2,str3,kaibun,kaibun2,kaibun3;
    cin >> str;
    strsize = str.size();
    //cout << str << strsize << endl;
    kaibun = str;
    kaibun = reverseStr(kaibun);
    str2 = str;
    str3 = str;
    str2 = str2.substr(0,(strsize-1)/2);
    str3 = str3.substr((strsize+3)/2-1);
    //cout << str3 << endl;
    kaibun2 = str2;
    kaibun3 = str3;
    reverse(kaibun2.begin(),kaibun2.end());
    reverse(kaibun3.begin(),kaibun3.end());

    if(str == kaibun){
        flg++;
        //printf(("%s","1 is OK\n"));
    }
    if(str2 == kaibun2){
        flg++;
        //printf(("%s","2 is OK\n"));
    }if(str3 == kaibun3){
        flg++;
        //printf(("%s","3 is OK\n"));
    }
    //printf("%d",flg);
    flg == 3 ? printf("%s","Yes") : printf("%s","No");
    return 0;
}

string reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
    return str;
}

Measured memory_bytes: 256
a= [int(x) for x in input().split()]
if a[0]>a[1]:
    a[0],a[1]=a[1],a[0]
if a[1]>a[2]:
    a[1],a[2]=a[2],a[1]
if a[0]>a[1]:
    a[0],a[1]=a[1],a[0]
print("{0} {1} {2}".format(a[0],a[1],a[2]))

Measured memory_bytes: 7680
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;
 
 
  

int main()  
{  
    int a,b,k;
    cin>>a>>b>>k;
    int x=min(a,b);
    int p[100]={0};
    int j=0;
    for(int i=1;i<=x;i++){
        if(a%i==0 && b%i==0){
            p[j]=i;
            j++;
        }
    }
    
    cout<<p[j-k];
   
  
    return 0;  
}  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
using ll = long long;

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

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

struct Info {
	ll w;
	ll v;
};

///
/// 与えられた最大wに対する最大価値を返す
///
void update_one_step(ll i, vector<vector<ll> > &dp, const vector<Info> &info, ll w_max) {
	if (i == 0) {
		for (ll w = 0; w < w_max; ++w) {
			dp[i][w] = 0;
		}
		return;
	}
	for (ll w = 0; w <= w_max; ++w) {
		chmax(dp[i][w], dp[i - 1][w]);
		if (w - info[i].w >= 0) {
			chmax(dp[i][w], info[i].v + dp[i-1][w - info[i].w]);
		}
	}
}

int main()
{
	ll N, W;
	cin >> N >> W;
	vector<Info> info(N+1);
	for (ll i = 1; i <= N; ++i) {
		cin >> info[i].w >> info[i].v;
	}
	// 制約条件: 重量の総和がW以下
	// 目的: 価値の総和の最大化
	vector<ll> space_W(W+1, 0);
	vector<vector<ll> > dp(N+1, space_W);
	for (ll i = 0; i <= N; ++i) {
		update_one_step(i, dp, info, W);
		/*
		for (ll w = 0; w <= W; ++w) {
			cout << dp[i][w] << ",";
		}
		cout << endl;
		*/
	}
	ll ans = dp[N][W];
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 80256
n, a, b = map(int, input().split())
S = input()

passed = 0
foreigners = 0
for s in S:
  if s == "a" and passed < a+b:
    print("Yes")
    passed += 1
  elif s == "b":
    foreigners += 1
    if passed < a+b and foreigners <= b:
      print("Yes")
      passed += 1
    else:
      print("No")
  else:
    print("No")

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

int main(){
	int r1;
	vector<int> a;
	for(int i=0;i<3;++i){
		cin>>r1;
		a.push_back(r1);
	}
	sort(a.begin(),a.end());
	cout<<a[0]+a[1];

	return 0;
}

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

dic = {}
s = ""
for i in range(N):
    s = input()
    if s in dic:
        dic[s] += 1
    else:
        dic[s] = 1

max = 0
for i in dic.values():
    if (max < i):
        max = i

mojiSet = set()
for moji in dic.keys():
    if (max == dic[moji]):
        mojiSet.add(moji)

for k in sorted(mojiSet):
    print(k)


Measured memory_bytes: 44124
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <cmath>
#include <numeric>
#include <tuple>

using namespace std;

int64_t MOD = 1000000007;

int main() {
	int n;
	cin >> n;
	vector<vector<int>> v(n, vector<int>(n, 0));
	vector<tuple<int, int, int>> data;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			int a;
			cin >> a;
			v[i][j] = a;
			if (i < j)
				data.push_back(make_tuple(a, j, i));
		}
	}
	sort(data.begin(), data.end());
	int64_t inf = 10000000000000LL;
	vector<vector<int64_t>> u(n, vector<int64_t>(n, inf));
	for (int i = 0; i < n; ++i) {
		u[i][i] = 0;
	}
	int64_t cost=0;
	for (auto item : data) {
		int dist = get<0>(item);
		int n1 = get<1>(item);
		int n2 = get<2>(item);
		if (u[n1][n2] > dist) {
			u[n1][n2] = u[n2][n1] = dist;
			cost += dist;
			for (int i = 0; i < n; ++i) {
				for (int j = 0; j < n; ++j) {
					int64_t nc = u[i][n1] + u[n1][n2] + u[n2][j];
					if (nc < u[i][j]) {
						u[i][j] = u[j][i] = nc;
					}
				}
			}
		}
	}
	bool okay = true;
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			if (u[i][j] != v[i][j]) okay = false;
		}
	}

	if (!okay) cout << -1 << endl;
	else cout << cost << endl;
	return 0;
}

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

int main() {
  string a,b;
  cin >> a >> b;
  string ans="";
  int al=a.size(),bl=b.size();
  int n=al+bl;
  int ai=0,bi=0;
  for ( int i=1; i<=n; i++ ) {
    if ( i%2 ) {
      ans+=a[ai++];
    } else{
      ans+=b[bi++];
    }
  }
  cout << ans << '\n';
  return 0; 
}

Measured memory_bytes: 3648
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
#include <cassert>
#include <functional>
#include <random>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vvvl> vvvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vvb> vvvb;
typedef vector<vvvb> vvvvb;
typedef vector<string> vs;
typedef vector<vs> vvs;
typedef vector<vvs> vvvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<vvd> vvvd;
typedef long double LD;
typedef vector<LD> vld;
typedef vector<pair<LD, LD>> vpld;
typedef pair<ll, ll> PL;
typedef vector<PL> vpl;
typedef vector<vector<PL>> vvpl;
typedef vector<vvpl> vvvpl;
typedef pair<ll, PL> TL;
typedef vector<TL> vtl;
typedef vector<vtl> vvtl;
typedef long double ld;
typedef vector<ld> vld;
const ll LINF = 1e17;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define RFOR(i, a, b) for(ll i = (a); i > b; i--)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n-1; i > -1; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back
#define epb emplace_back
#define ALL(X) (X).begin(),(X).end()

template <typename T> T gcd(T a, T b) {return (a == 0) ? b : gcd(b%a, a);}
template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b;}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec /* copy */){
    sort(ALL(vec)); vec.erase(unique(vec.begin(), vec.end()), vec.end()); return vec;
}

inline ll popcnt(ll x){return __builtin_popcountll((unsigned long long)x);};
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
//friend bool operator<(const tpl& lhs, const tpl& rhs){
//    return std::tie(lhs.l, lhs.r) < std::tie(rhs.l, rhs.r);
//}

bool bit(ll st, ll b){return ((st>>b)&1) == 1;}


int main(){
#ifdef __DEBUG_LOCAL__
    ifstream file("../../../../../in.txt"); if(file.is_open()) cin.rdbuf(file.rdbuf());
#endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
    
    string S; cin >> S;
    rep(i, S.size()){
        cout << 'x';
    }
    cout << endstr;
    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>

int main(){
    int n,i;
    scanf("%d",&n);
    for(i=1;i<=n;i++) {
        if(i%3==0)printf(" %d",i);
        else if(i%10==3)printf(" %d",i);
        else if(i/10%10==3)printf(" %d",i);
        else if(i/100%10==3)printf(" %d",i);
        else if(i/1000%10==3)printf(" %d",i);
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2104
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
 
int main(void)
{
long N, M, p[100000], index;
char S[100000][3];
long sei[100000], pen[100000];
long total_sei = 0;
long total_pen = 0;
memset(sei, 0, sizeof(long) * 100000);
memset(pen, 0, sizeof(long) * 100000);
 
  scanf("%ld %ld", &N, &M);
  for (index = 0; index < M; ++index) {
    scanf("%ld %s", &p[index], &S[index]);
    if (S[index][0] == 'W') {
      if (sei[p[index] - 1] == 0) {
        pen[p[index] - 1]++;
      }
    } else {
      sei[p[index] - 1] = 1;
    }
  }
  
  for (index = 0; index < N; ++index) {
    total_sei += sei[index];
    if (sei[index] == 1) {
      total_pen += pen[index];
    }
  }
  printf("%ld %ld\n", total_sei, total_pen);
    
  return 0;
}

Measured memory_bytes: 2816
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define itn int
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>=1;i--)
#define all(vec) vec.begin(),vec.end()
#define sort(vec) sort((vec).begin(),(vec).end())
#define rsort(vec) sort((vec).rbegin(), (vec).rend())
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=2e9;
const ll lnf=9e18;

ll kiri(ll a,ll b){return a%b==0?a/b:a/b+1;}

int main(){
  itn n; cin >> n;
  vector<ll> a(n);
  vector<ll> b(n);
  rep(i,n) cin >> a[i] >> b[i];
  rep(i,n-1){
    if(a[i]<=a[i+1]&&b[i]<=b[i+1]) continue;
    ll mx=max(kiri(a[i],a[i+1]),kiri(b[i],b[i+1]));
    a[i+1]=a[i+1]*mx;
    b[i+1]=b[i+1]*mx;
  }
  cout << a[n-1]+b[n-1] << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int X;

signed main(){
	cin>>X;
	if(X>=30){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
#define rep(i, s, n) for(int i = (int)(s); i < (int)(n); i++)

int main(){
  int n;
  cin >> n;
  
  vl f(10010, 0);
  
  rep(x, 1, 110){
    if(x*x > 10010)
      break;
    rep(y, 1, 110){
      if(y*y > 10010)
        break;
      rep(z, 1, 110){
        int sum = x*x + y*y + z*z + x*y + y*z + z*x;
        if(sum < 10010){
          f[sum]++;
        }
        else
          break;
      }
    }
  }
  
  rep(i, 1, n+1)
    cout << f[i] << endl;
  
  return 0;
  
}

Measured memory_bytes: 3672
use proconio::input;
use proconio::marker::{Bytes, Chars};

// x ** n % mods を求める
pub fn mod_pow(x: i64, n: i64, mods: i64) -> i64 {
    if n == 0 {
        return 1;
    }
    let mut res = mod_pow(x * x % mods, n / 2, mods);
    if n % 2 == 1 {
        res = res * x % mods;
    }
    return res;
}

// (1/n) % mods を求める
pub fn mod_inv(n: i64, mods: i64) -> i64 {
    return mod_pow(n, mods-2, mods);
}

// nCk % mods を求める
pub fn mod_comb(n: i64, k: i64, mods: i64) -> i64 {
    let sum1 = (n-k+1..n+1).fold(1, |ac, x| ac * x % mods);
    let sum2 = (1..k+1).fold(1, |ac, x| ac * x % mods);
    return sum1 * mod_inv(sum2, mods) % mods;
}

// nCk の組み合わせを列挙する
pub fn combination(n: usize, k: usize) -> Vec<Vec<usize>> {
    let mut ans = Vec::new();
    if k == 1 {
        for i in 1..n+1 {
            let mut tmp = Vec::new();
            tmp.push(i);
            ans.push(tmp);
        }
    }
    else {
        for iter in combination(n-1, k-1) {
            let max = iter.iter().max().unwrap();
            for j in *max+1..n+1 {
                let mut tmp = iter.clone();
                tmp.push(j);
                ans.push(tmp);
            }
        }
    }
    ans
}


fn main() {
    input!{
        x: i32,
        n: usize,
        mut p: [i32; n],
    }
    p.sort();
    let mut ans = x;
    let mut min = 1000;
    let mut count = 0;
    for i in -100..201 {
        if count < n {
            if i < p[count] {
                if (x-i).abs() < min {
                    ans = i;
                    min = (x-i).abs();
                }
            }
            else {
                count += 1;
            }
        }
        else {
            if (x-i).abs() < min {
                ans = i;
                min = (x-i).abs();
            }
        }
    }
    // for i in 0..n-1 {
    //     if x >= p[i] && x < p[i+1] {
    //         println!("{} {}", p[i], p[i+1]);
    //         for j in p[i]+1..p[i+1] {
    //             if (x-j).abs() < min {
    //                 ans = j;
    //                 min = (x-j).abs();
    //             }
    //         }
    //     }
    // }
    println!("{}", ans);
}


Measured memory_bytes: 2112
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=(b);++i)
#define mem(a,x) memset(a,x,sizeof(a))
#define pb push_back
#define pi pair<int, int>
#define mk make_pair
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
const ll p=1e9+7;
ll pow(ll a, ll b, ll m)
{
    ll ans = 1;
    a %= m;
    while(b)
    {
        if(b & 1)ans = (ans % m) * (a % m) % m;
        b /= 2;
        a = (a % m) * (a % m) % m;
    }
    ans %= m;
    return ans;
}
ll inv(ll x, ll p)//x关于p的逆元，p为素数
{
    return pow(x, p - 2, p);
}
ll C(ll n, ll m, ll p)//组合数C(n, m) % p
{
    if(m > n)return 0;
    ll up = 1, down = 1;//分子分母;
    for(int i = n - m + 1; i <= n; i++)up = up * i % p;
    for(int i = 1; i <= m; i++)down = down * i % p;
    return up * inv(down, p) % p;
}
ll Lucas(ll n, ll m, ll p)
{
    if(m == 0)return 1;
    return C(n % p, m % p, p) * Lucas(n / p, m / p, p) % p;
}
const int N=4e5+10;
char pp[N];
int main()
{
    ll n,a,b;
    cin>>n>>a>>b;
    ll ans=pow(2,n,p)-1;
    ll c1=Lucas(n,a,p)+Lucas(n,b,p);
    c1%=p;
    ans=ans-c1+p;
    ans%=p;
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 384
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll tmp=v[0];
  ll ans=1;
  rep(i,n-1){
    if(tmp<=v[i+1]) ans++;
    chmax(tmp,v[i+1]);
  }
  cout<<ans<<endl;
}

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

int main(){
    int n;
    cin >> n;
    bool f = false;
    for(int i = 1; i <= 9; i++){
        for (int j = 1; j <= 9; j++){
            if (n == i * j) f = true;
        }
    }
    if(f) cout << "Yes" << "\n";
    else cout << "No" << "\n";

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w;
	int cnt = 0;
	char str[52][52];
	cin >> h >> w;
	for (int i = 0; i < 52; i++) str[i][0] = '.';
	for (int i = 0; i < 52; i++) str[0][i] = '.';
	for (int i = 0; i < 52; i++) str[i][51] = '.';
	for (int i = 0; i < 52; i++) str[51][i] = '.';
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			cin >> str[i][j];
		}
	}
	for (int i = 1; i <= h; i++) {
		for (int j = 1; j <= w; j++) {
			if (str[i - 1][j - 1] == '#') cnt++;
			if (str[i-1][j ] == '#') cnt++;
			if (str[i-1][j +1] == '#') cnt++;
			if (str[i][j - 1] == '#') cnt ++;
			if (str[i][j + 1] == '#') cnt++;
			if (str[i + 1][j - 1] == '#') cnt++;
			if (str[i+1][j ] == '#') cnt++;
			if (str[i+1][j + 1] == '#') cnt++;

			if (str[i][j] == '.') cout << cnt;
			else cout << '#';
			cnt = 0;
		}
		cout << endl;
	}
}



Measured memory_bytes: 256
def GetPoint(U,D):
    N = 0
    if U >= D:
        N += D*(D-1)/2 + U*(U+1)/2
    else:
        N += D*(D+1)/2 + U*(U-1)/2
    return N
S = input()
N = 0
U = 0
D = 0
for i in range(len(S)):
    if S[i] == "<":
        U += 1
    elif S[i] == ">":
        D += 1
    if i<len(S)-1:
        if (S[i]==">" and S[i+1]=="<"):
            N += GetPoint(U,D)
            U=0
            D = 0
N += GetPoint(U, D)
    # elif S[i] == "<" and S[i+1] == ">":

print(int(N))
    


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

A_list = []
for i in range(N):
    A = int(input())
    A_list.append([list(map(int, input().split())) for _ in range(A)])


def judge(mask):
    for i in range(N):
        if (mask>>i & 1)==0:
            continue
        for xy in A_list[i]:
            x = xy[0]-1
            y = xy[1]
            if y==0 and (mask>>x & 1):
                return False
            if y==1 and (mask>>x & 1)==0:
                return False
    return True


num_max = 0
for mask in range(1<<N):
    if judge(mask):
        num = 0
        for i in range(N):
            num += mask>>i & 1
        num_max = max(num, num_max)

print(num_max)

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

int main() {
#ifdef LOCAL_EXEC
//    freopen("sample.in", "r", stdin);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
#endif

  string s;
  cin >> s;
  cout << s[0] << s[1] << s[2] << '\n';

	return 0;
}

Measured memory_bytes: 3652
#include <set>
#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
int Q, x, y; char b[4];
int main() {
	while (scanf("%d", &Q), Q) {
		vector<vector<int> > v;
		while (Q--) {
			scanf("%s", b);
			if (b[0] == 'W') {
				scanf("%d%d", &x, &y);
				for (int i = -1; i + 1 < v.size() && y > 0; i++) {
					int r1 = (i != -1 ? v[i][1] : 0), r2 = v[i + 1][0];
					if (r1 == r2) continue;
					if (r2 - r1 < y) {
						v.insert(v.begin() + 1 + i, { r1, r2, x });
						y -= r2 - r1;
					}
					else {
						v.insert(v.begin() + 1 + i, { r1, r1 + y, x });
						y = 0;
					}
				}
				if (y > 0) {
					if (v.size() == 0) v.push_back({ 0, y, x });
					else v.push_back({ v.back()[1], v.back()[1] + y, x });
				}
			}
			else if (b[0] == 'D') {
				scanf("%d", &x);
				vector<vector<int> > w;
				for (int i = 0; i < v.size(); i++) {
					if (v[i][2] != x) w.push_back(v[i]);
				}
				v = w;
			}
			else {
				scanf("%d", &x);
				int ret = -1;
				for (int i = 0; i < v.size(); i++) {
					if (v[i][0] <= x && x < v[i][1]) ret = v[i][2];
				}
				printf("%d\n", ret);
			}
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 2908
#include<stdio.h>
#include<limits.h>

int INF = 999999999;

int count;

void merge(int S[], int left, int mid, int right){
	int i=0, j=0;
	int n1 = mid-left;
	int n2 = right - mid;
	int L[n1], R[n2];
	for(i=0; i<n1; i++){
		L[i] = S[left + i];
	}
	for(i=0; i<n2; i++){
		R[i] = S[mid + i];
	}
	L[n1] = INF;
	R[n2] = INF;
	i=0; j=0;
	for(int k=left; k<right; k++){
		count++;
		if(L[i]<=R[j]){
			S[k] = L[i];
			i++;
		}
		else{
			S[k] = R[j];
			j++;
		}
	}
}

void mergeSort(int S[], int left, int right){
	int mid;
	mid = (left + right)/2;
	if( left+1<right ){
		mid = (left + right)/2;
		mergeSort(S, left, mid);
		mergeSort(S, mid, right);
		merge(S, left, mid, right);
	}
}

int main(void){
	int n, i, S[500000];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%d", &S[i]);
	}
	mergeSort(S, 0, n);
	
	for(i=0; i<n-1; i++){
		printf("%d ", S[i]);
	}
	printf("%d\n", S[i]);
	printf("%d\n", count);
	return 0;
}


Measured memory_bytes: 5596
#include <stdio.h>


int main() {
    char a, b, current;
    current = 'A';
    while (scanf("%c,%c", &a, &b) != EOF) {
        if (a == current)
            current = b;
        else if (b == current)
            current = a;
    }
    printf("%c\n", current);

    return 0;
}

Measured memory_bytes: 544
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define ll long long
#define M 1000000007
#define all(a) a.begin(), a.end()

char s[2][60];
int n;
int f[60][3][3];

int main(){
	scanf("%d", &n);
	scanf("%s", s[0] + 1);
	scanf("%s", s[1] + 1);
	int bg;
	if(s[0][1] == s[1][1]){
		f[1][0][0] = f[1][1][1] = f[1][2][2] = 1;
		bg = 1;
	}else{
		f[2][0][1] = f[2][1][0] = f[2][0][2] = f[2][2][0]	= f[2][1][2] = f[2][2][1] = 1;
		bg = 2;
	}
	for(int i = bg + 1; i <= n;){
		if(s[0][i] == s[1][i]){
			for(int j = 0; j < 3; ++j)
				for(int k = 0; k < 3; ++k)
					for(int l = 0; l < 3; ++l)
						if(l != j && l != k){
							f[i][l][l] = (f[i][l][l] + f[i - 1][j][k]) % M;
						}
			++i;
		}else{
			for(int j = 0; j < 3; ++j)
				for(int k = 0; k < 3; ++k)
					for(int l = 0; l < 3; ++l)
						for(int p = 0; p < 3; ++p)
							if(l != j && k != p && l != p){
								f[i + 1][l][p] = (f[i + 1][l][p] + f[i - 1][j][k]) % M;
							}
			i += 2;
		}
	}
	int res = 0;
	for(int i = 0; i < 3; ++i)
		for(int j = 0; j < 3; ++j)
			res = (res + f[n][i][j]) % M;
	printf("%d\n", res);
				 
			

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 300 + 5;
int n,m,ans = maxn;
int cnt[maxn];
int mapp[maxn][maxn];
int vis[maxn];
vector <int> vec[maxn];
int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
            scanf("%d", &mapp[i][j]);
        vec[mapp[i][cnt[i]++]].emplace_back(i);
    }
    int flag = 1;
    while (flag)
    {
        int v = 0, ii = 0;
        for (int i = 1; i <= m; ++i)
            if (vec[i].size() > v)
            {
                v = vec[i].size();
                ii = i;
            }
        if (!v)
            break;
        ans = min(ans, v);
        for (int i = 0; i < v; ++i)
        {
            int p = vec[ii][i];
            while (cnt[p] < m && vis[mapp[p][cnt[p]]])
                ++cnt[p];
            if (cnt[p] > m)
            {
                flag = 0;
                break;
            }
            vec[mapp[p][cnt[p]++]].emplace_back(p);
        }
        vec[ii].clear();
        vis[ii] = 1;
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 1280
import java.util.Scanner;

public class Main {


	public static void main(String[] args) {
		 Scanner sc = new Scanner(System.in);
		long n = getLong(sc);
		long a = getLong(sc);
		long b = getLong(sc);

		long blueBall = 0;
		blueBall += n / (a + b)*a;
		n = n % (a + b);
		if (n < a) {
			blueBall += n;
		} else {
			blueBall += a;
		}
		System.out.println(blueBall);
	}

	/**
	 * *汎用メソッド <br>
	 * スキャナーからの入力値をlongで返却
	 *
	 * @return
	 */
	public static long getLong(Scanner sc) {

		return Long.parseLong(sc.next());
	}

}


Measured memory_bytes: 23892
N = int(input())
S = input()

leftWest = 0
rightEast = list(S).count("E")

ans = 10 ** 6
for si in S:
    if si == "E":
        rightEast -= 1
    
    ans = min(ans, leftWest + rightEast)

    if si == "W":
        leftWest += 1

print(ans)

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

int main(){
    int n, rate, ans=0, max0;
    cin >> n;
    vector<int> a(9);

    for(int i=0; i<n; i++)
    {
        cin >> rate;
        rate = min(rate/400, 8);
        a[rate]++;
    }

    for(int i=0;i<8; i++) if(a[i]>0) ans++;
    if (ans == 0){
        ans = 1;
        max0 = n; 
    }else max0 = ans+a[8];
    cout << ans << ' ' << max0 << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
# Your code here!
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
k = int(input())

print(l[k-1])

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

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using LL = long long;
using VL = vector<LL>;
using VVL = vector<VL>;
using PLL = pair<LL, LL>;
using VS = vector<string>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}
template<class S, class T>
ostream& operator<<(ostream& os, const pair<S,T>& p){
  return os << p.FF << " " << p.SS;
}
template<class T>
void maxi(T& x, T y){
  if(x < y) x = y;
}
template<class T>
void mini(T& x, T y){
  if(x > y) x = y;
}


const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;
const int INF = 1e7;

struct EdgeEx{
  int to, cap, rev;
  EdgeEx(int to_=0, int cap_ = 0, int rev_ = 0)
	:to(to_), cap(cap_), rev(rev_){}
};


vector< vector<EdgeEx> > G; // (V, E)
void add_edge(int from, int to, int cap){
  G[from].push_back(EdgeEx(to, cap, G[to].size()));
  G[to].push_back(EdgeEx(from, 0, G[from].size()-1));
}

int max_flow_dfs(int u, int t, int f, vector<bool>& finished, vector<int>& level){
  if (u == t || f == 0) return f;
  if (finished[u]) return 0;
  finished[u] = true;
  for(auto& e: G[u]){
	if(level[e.to] > level[u]){
	  int fp = max_flow_dfs(e.to, t, min(f, e.cap), finished, level);
	  if(fp > 0) {
		e.cap -= fp;
		G[e.to][e.rev].cap += fp;
		finished[u] = false;
		return fp;
	  }
    }
  }
  return 0;
}
int maximumFlow(int s, int t) {
  int N = G.size();
  int total = 0;
  for(bool up=true;up;){
	up = false;
    vector<int> level(N, -1); level[s] = 0;
    queue<int> Q; Q.push(s);
    for(int d = N; !Q.empty() && level[Q.front()] < d; ) {
      int u = Q.front(); Q.pop();
      if (u == t) d = level[u];
      for(auto& e: G[u])
		if (e.cap > 0 && level[e.to] == -1)
		  Q.push(e.to), level[e.to] = level[u] + 1;
    }
    vector<bool> finished(N);
    for(int f = 1; f > 0; ) {
      f = max_flow_dfs(s, t, INF, finished, level);
      if (f == 0) break;
      total += f; up = true;
    }
  }
  return total;
}

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

  int H, W;
  cin >> H >> W;
  VS vs(H);
  REP(y,H){
	cin >> vs[y];
  }

  int S = H+W, T = S + 1;
  G.assign(T+1, vector<EdgeEx>());
  REP(y,H) REP(x,W){
	if(vs[y][x] == 'S'){
	  add_edge(S, y, INF);
	  add_edge(S, H+x, INF);
	}
	else if(vs[y][x] == 'T'){
	  add_edge(y, T, INF);
	  add_edge(H+x, T, INF);
	}
	else if(vs[y][x] != '.'){
	  add_edge(y, H+x, 1);
	  add_edge(H+x, y, 1);
	}
  }
  int res = maximumFlow(S, T);
  cout << (res >= INF? -1: res) << endl;

  return 0;
}


Measured memory_bytes: 896
#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include<bits/stdc++.h>
using namespace std;
int main(){
    int h,a;
    cin >> h>>a;
    h = h+a-1;
    cout << (int)h/a<<endl;
    return 0;
}

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

#define rep(i,n) for(int i=0 ; i<(n) ; i++)
#define repr(i,n) for(int i=(n) ; i>=0 ; i--)
#define ALL(x) (x).begin(),(x).end()

using ll = long long;
using ull = unsigned long long;
 
const ll INF = 1LL<<60;
const int MINF = 1e9;
const int MOD = 1e9+7;

using vi = vector<int>;
using vii = vector<vi>;

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

template<typename T>
T GCD(T a,T b){ return b ? GCD(b,a%b) : a ;}
template<typename T>
T LCM(T a,T b){ return a*b / GCD(a,b) ;}

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

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

Measured memory_bytes: 256
fun main(args: Array<String>) {
    
    var (a,b) = readLine()!!.split(" ").map(String::toInt)
    var c = 0
    (a..b).map{
        var s = it.toString().toList()
        (0..2).map{i->
            s[i] == s[s.size-1-i]
        }.all{it==true}
    }.filter{it==true}.size.let{println(it)}
        
}


Measured memory_bytes: 42360
//06, 10, 2018, 09:03:03 Rafaelcs cpp
#include <bits/stdc++.h>

using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, t;

    scanf("%d %d", &n, &t);

    int r = -1;

    for(int i = 0 ; i < n ; i++){
        int c, x;

        scanf("%d %d", &c, &x);

        if(t >= x){
            if(r == -1){
                r = c;
            }else{
                r = min(r, c);
            }
        }
    }

    if(r == -1){
        printf("TLE\n");
    }else{
        printf("%d\n", r);
    }
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,n,j) for(int i=(j);i<(n);++i)
#define ssort(n) sort((n).begin(),(n).end())
#define rsort(n) sort((n).begin(),(n).end(),greater<int>())
#define mp make_pair
using ll=long long;
using ld=long double;
typedef pair<int,int> P;
typedef pair<P,int> COST;
#define repl(i,n) for(ll i=0;i<(n);++i)
#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
using Graf=vector<vector<ll>>;
#define MAX 1000000007

int main()
{
    int a,b,t;
    cin >> a >> b >> t;
    int time=0;
    time=t/a;
    if(t%a!=0){
        time+=0.5;
    }
    cout << time*b << endl;
}

Measured memory_bytes: 3604
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

#define INF 1e18
#define MOD 1000000007

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

ll n, p;
string s;
ll mul(ll a, ll b) {
    return ((a % p) * (b % p)) % p;
}

ll expMod(ll a, ll b) {
    if(b == 0) return 1;
    if(b == 1) return a;
    if(b & 1LL) return mul(a, expMod(a, b-1));
    ll aux = expMod(a, b/2);
    return mul(aux, aux);
}

ll add(ll a, ll b) {
    return ((a % p) + (b % p)) % p;
}

void solve_esp(int x) {
    ll ans = 0;
    for(int i = 0; i < n; i++) {
        if((s[i] - '0') % x == 0) ans += i+1;
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> p;
    cin >> s;

    if(p == 2 || p == 5) {
        solve_esp(p);
        return 0;
    }

    int pref[n];
    int suf[n];
    pref[0] = (s[0] - '0') % p;
    suf[n-1] = (s.back() - '0') % p;
    map<ll,ll> sufm;
    sufm[0]++;
    ll ans = 0;
    ans += sufm[suf[n-1]];
    sufm[suf[n-1]]++;
    for(int i = 1; i < n; i++) {
        pref[i] = (pref[i-1] + (s[i] - '0')) % p;
        suf[n-i-1] = add(mul(s[n-i-1] - '0', expMod(10, i)), suf[n-i]);
        ans += sufm[suf[n-i-1]];
        //cout << "i: " << i << " add: " << sufm[suf[n-i-1]] << endl;
        sufm[suf[n-i-1]]++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 2580
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)

int main()
{
    ll N;
    cin >> N;
    set<ll> D;
    repi(i, N, 0)
    {
        ll tmp;
        cin >> tmp;
        D.insert(tmp);
    }
    cout << D.size() << endl;
    return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize("Ofast",3,"inline")
//#include<bits/stdc++.h>
//using namespace std;
//#define fir first
//#define sec second
//#define m_p make_pair
//#define y1 ygftgfgcdtfgxffgx
//#define y2 yfdsesgvtyghftfvv
//#define x1 xvyr6cf6fgcfgf676
//#define x2 xcr6rfc5r66y6r6fr
//#define up_bound upper_bound
//#define low_bound lower_bound
//#define next_per next_permutation
//#define pb push_back
//#define i_to_s to_string
//typedef priority_queue<int> p_queue;
//typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
//typedef long long ll;
//typedef long double ld;
//typedef pair<int,int> pii;
//typedef pair<ll,ll> pll;
//int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
//ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
//ll n,a[100010];
//ll num[100010];
//ll ans,last;
//int main(){
//	ios_base::sync_with_stdio(false);
//	cin.tie(0);
////	freopen(".in","r",stdin);
////	freopen(".out","w",stdout);
//	cin>>n;
//	for(int i=0;i<=n;i++)cin>>a[i];
//	if(n==0){if(a[0]==0)cout<<-1;if(a[0]==1)cout<<1;if(a[0]>1)cout<<-1;return 0;}num[0]=1;
//	if(a[0]==1){cout<<-1;return 0;}
//	for(int i=1;i<n;i++){
//		num[i]=num[i-1]*2-a[i];
////		cout<<num[i]<<'\n';
//		if(num[i]<=0){
//			cout<<-1;
//			return 0;
//		}
//	}
////	cout<<'\n';
//	num[n]=num[n-1]*2;
//	if(num[n]<a[n]){
//		cout<<-1;
//		return 0;
//	}
//	ans=a[n],last=a[n];
//	for(int i=n-1;i>=0;i--){
////		cout<<ans<<'\n';
//		last=min(last,num[i])+a[i];
//		ans+=last;
//	}
//	cout<<ans;
//	return 0;
//}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 4000000000000000000;
ll a[100005];
ll b[100005];
ll c[100005];
ll mxbc[100005];
ll ans = 0;
int n;
int main(){
    scanf("%d",&n);
    for (int i = 0; i <= n; i++){
        scanf("%lld",&a[i]);
    }
    mxbc[0] = 1-a[0];
    for (int i = 1; i <= n; i++){
        mxbc[i] = min(2*mxbc[i-1] - a[i], INF);
        if (mxbc[i] < 0ll){
            printf("-1"); return 0;
        }
    }
    for (int i = n-1; i >= 0; i--){
        ///b + c <= mxbc
        ///b + 2*c = sum
        ///c >= sum - mxbc
        ll sum = a[i+1]+b[i+1]+c[i+1];
        ll C = max(0ll,sum-mxbc[i]);
        ll B = sum-2*C;
        b[i] = B, c[i] = C;
        if (B < 0ll || B + 2*C != sum){
            printf("-1\n");
            return 0;
        }
        ans += a[i] + B + C;
    }
    ans += a[n];
    if (n == 0 && a[0] != 1) printf("-1\n");
    else printf("%lld",ans);
}



Measured memory_bytes: 6884