akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define fi first
#define se second
#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define rrep(i, n) for (int (i) = 1; (i) <= (n); (i++))
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define yn {puts("Yes");}else {puts("No");}
#define printd(x) printf("%.12f\n", x);
template<class T> bool chmin(T& a, const T& b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> bool chmax(T& a, const T& b) {if (a < b) {a = b; return 1;} return 0;}
using namespace std;
using ll = long long;
using P = pair<int, int>;

double dp[3005][3005];

int main() {
	int n;
	cin >> n;
	double p[n];
	rep (i, n) cin >> p[i];

	dp[0][0] = 1.0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j <= n; j++) {
			dp[i + 1][j + 1] += dp[i][j] * p[i];
			dp[i + 1][j] += dp[i][j] * (1 - p[i]);
		}
	}

	double ans = 0;
	for (int i = n / 2 + 1; i <= n; i++) ans += dp[n][i];

	printd(ans)
	return 0;
}

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

int main(){
   int N,M;
   cin >> N >> M;
   vector<int> A(N);
   int ans = N;
   for (int i = 0; i < N; i++){
       cin >> A.at(i);
       ans -= A.at(i);
   }
   cout << (ans >= 0 ? ans : -1) << endl;
}

Measured memory_bytes: 7164
/**********************************************************
* @Author: 			   Maple
* @Date:   			   2020-03-07 20:07:56
* @Last Modified by:   Maple
* @Last Modified time: 2020-03-07 20:11:32
* @Remark: 
**********************************************************/
#include <bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define CSE(x,y) memset(x,y,sizeof(x))
#define INF 0x3f3f3f3f
#define Abs(x) (x>=0?x:(-x))
#define FAST ios::sync_with_stdio(false);cin.tie(0);
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll , ll> pll;

const int maxn=1000;
ll n,a,b;

int main()
{
	// #ifndef ONLINE_JUDGE
	// freopen("in.in","r",stdin);
	// #endif
	FAST;
	cin>>n>>a>>b;
	ll t=a+b;
	ll num=n/t;
	ll ed=n%t;
	if(ed>=a)
	cout<<num*a+a<<endl;
	else
	cout<<num*a+ed<<endl;
	return 0;
}

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

int main(){
  char X, Y;
  cin >> X >> Y;
  if((int)X<(int)Y){
    cout << "<" << endl;
  }
  else if((int)X==(int)Y){
    cout << "=" << endl;
  }
  else{
    cout << ">" << endl;
  }
  
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(void)
{
    string s;
    int n;
    cin>>n;
    getchar();
    getline(cin,s);
    for(auto x:s)
    {
        x=(x+n-'A')%26+'A';
        cout<<x;
    }
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define digit(x) floor(log10(x))+1
#define mod 1000000007
typedef long long ll;
typedef long double ld;
typedef vector<vector<ll>> matrix;
typedef vector<ll> arr;
typedef vector<string> vs;
typedef vector<pair<ll,ll>> pv;
#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld %lld",&x,&y)
#define in3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define all(x) x.begin(),x.end()
#define debug(x) cerr << #x << " is " << x << endl;
int main(){
    fast;
    string s,s1;
    ll n,flag=0;
    cin>>s;
    s1=s;
    n=s.size();
    reverse(s1.begin(),s1.end());
    if(s==s1){
        string s2=s.substr(0,(n-1)/2);
        string s3=s.substr((n-1)/2+1,(n-1)/2);
       // cout<<s2<<" "<<s3<<endl;
        string s4=s2,s5=s3;
        reverse(s4.begin(),s4.end());
        reverse(all(s5));
        if(s2==s4&&s3==s5){
            flag=1;
        }
    }
    if(flag){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect

if __name__ == "__main__":
    n = int(input())
    a = [0]*18
    a[0] = 26
    b = 2
    alpa = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
    for i in range(1,18):
        a[i] = a[i-1] + 26**b
        b+=1
    d = bisect.bisect_left(a,n)
    ans = "a"*(d+1)
    n = n - a[d-1] -1
    ans = ""
    for i in range(d,-1,-1):
        if i == d:
            ans += alpa[n%(26)]
        else:
            ans += alpa[n%(26)]
        n = n//26
    ans2 = ""
    for i in range(len(ans)):
        ans2 += ans[len(ans)-i-1]
    print(ans2)

Measured memory_bytes: 9536
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */

int main(){
  char tail;
  REP(i,3){
    char s[11];
    cin>>s;
    if(i>0 && s[0]!=tail){
      cout<<"NO\n"<<endl;
      return 0;
    }
    tail = s[strlen(s)-1];
  }
  cout<<"YES\n";

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
class Main{
    /*
     * 整数 -> nextInt() (遅い場合は下のni())
     * 単語 -> next()
     * 1行 -> nextLine()
     * 注意 : nextLIneをnext(),nextInt()のあとに呼び出す場合、次が改行だと改行だけ取ってしまうので注意
     */
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int H = sc.nextInt();
        int W = sc.nextInt();
        int D = sc.nextInt();
        int[][] a = new int[H][W];

        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                a[i][j] = sc.nextInt() - 1;
            }
        }

        int Q = sc.nextInt();
        int[] L = new int[Q];
        int[] R = new int[Q];

        for(int i=0;i<Q;i++){
            L[i] = sc.nextInt() - 1;
            R[i] = sc.nextInt() - 1;
        }

        Map<Integer,Pair> mp = new HashMap<>();
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                mp.put(a[i][j],new Pair(i,j));
            }
        }

        int[][] sum = new int[D][H*W/D+10];

        for(int i=0;i<D;i++){
            for(int j=0;i+j*D<H*W;j++){
                if(j==0){
                    sum[i][j] = 0;
                }else{
                    Pair p1 = mp.get(i+(j-1)*D);
                    Pair p2 = mp.get(i+j*D);
                    sum[i][j] = sum[i][j-1] + Math.abs(p1.a-p2.a) + Math.abs(p1.b-p2.b);
                }
            }
        }


        for(int i=0;i<Q;i++){
            int l = L[i];
            int r = R[i];

            int li = l / D;
            int ri = r / D;

            System.out.println(sum[r%D][ri] - sum[l%D][li]);
        }
    }

    static class Pair{
        int a,b;
        public Pair(int a,int b){
            this.a = a;
            this.b = b;
        }
    }
}


Measured memory_bytes: 100704
/* ***************************************
Author        :Scau.ion
Created Time  :2017/01/22 20:03:33 UTC+8
File Name     :ion.cpp
*************************************** */

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

#define LL long long
#define ULL unsigned long long
#define PB push_back
#define MP make_pair
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<PII>
#define X first
#define Y second
#define IOS ios::sync_with_stdio(0);cin.tie(0);
#define IN freopen("in", "r", stdin);
#define OUT freopen("out", "w", stdout);

const int maxn=100010;

LL a[maxn],b[maxn];

int main()
{
    IOS;
    int n;
    cin>>n;
    for (int j=1;j<=n;++j)
    {
        cin>>a[j]>>b[j];
    }
    LL ans=0;
    for (int j=n;j>0;--j)
    {
        a[j]+=ans;
        LL duo=a[j]%b[j];
        if (duo==0) duo=b[j];
        ans+=b[j]-duo;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;
        for (int i = 0; i < m; i++) {
            sum += sc.nextInt();
            if (sum > n) {
                System.out.println(-1);
                System.exit(0);
            }
        }
        System.out.println(n-sum);
    }
}


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

int a, b;

int main() {
    scanf("%d%d", &a, &b);
    if(a <= 0 && b >= 0) printf("Zero\n");
    else if(a < 0 && b < 0) {
        if((b - a + 1) % 2 == 0) printf("Positive\n");
        else printf("Negative\n");
    } else if(a > 0 && b > 0) printf("Positive\n");
}

Measured memory_bytes: 256
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <random>
#include <utility>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
long long int INF = 1e18;
double Pi = 3.141592653589;
const int mod = 1000000007;
// memset(a,0,sizeof(a)); →全部０にする

struct edge{int to,cost;};
vector<int> G[100005];

 
ll n,m,ans=0;
int i,j;
int sx,sy,tx,ty;

int main(){
	cin>>sx>>sy>>tx>>ty;
	for(i=0;i<tx-sx;i++)cout<<"R";
	for(i=0;i<ty-sy;i++)cout<<"U";
	for(i=0;i<tx-sx;i++)cout<<"L";
	for(i=0;i<ty-sy;i++)cout<<"D";
	cout<<"DR";
	for(i=0;i<tx-sx;i++)cout<<"R";
	for(i=0;i<ty-sy;i++)cout<<"U";
	cout<<"UL";
	cout<<"UL";
	for(i=0;i<tx-sx;i++)cout<<"L";
	for(i=0;i<ty-sy;i++)cout<<"D";
	cout<<"DR";
	return 0;

}

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

const ll N = 1e5 + 70;
const ll base = 1e9 + 7;
vector< ll> factors;
ll fact[N], ifact[N];

ll bpow(ll a, ll b, ll base) {
    ll rv = 1;
    while(b) {
        if(b & 1) rv = rv * 1LL * a % base;
        a = a * 1LL * a % base;
        b /= 2;
    }
    return rv;
}

void pre() {
    fact[0] = 1;
    for (ll i = 1; i < N; i++) fact[i] = fact[i - 1] * 1LL * i % base;
    ifact[N - 1] = bpow(fact[N - 1], base - 2, base);
    for(ll i = N - 2; i >= 0; i--) ifact[i] = ifact[i + 1] * 1LL * (i + 1) % base;
}

ll ncr(ll n, ll r) {
    ll rv = fact[n];
    rv = rv * 1LL * ifact[r] % base;
    rv = rv * 1LL * ifact[n - r] % base;
    return rv;
}


int main() {
    pre();
    ll k, m;
    cin >> k >> m;
    for (long long i = 2; i * i <= m; i ++) {
        if (m % i == 0) {
            ll cnt = 0;
            while (m % i == 0) {
                m /= i;
                cnt++;
            }
            factors.emplace_back(cnt);
        }
    }
    if (m > 1) factors.emplace_back(1);

    ll res = 1;
    for (ll a : factors) {
        res = res * 1LL * ncr(a + k - 1, a) % base;
    }
    cout << res << endl;
}

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

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

int main() {
	ios::sync_with_stdio(false);
	
	int n, m;
	
	while(cin>>n,n) {
		char t[256] = {};
		char a, b;
		rep(i, n) {
			cin>>a>>b;
			t[a] = b;
		}
		cin>>m;
		rep(i, m) {
			cin>>a;
			if(t[a]==0)cout<<a;
			else cout<<t[a];
		}
		cout<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long N, vector<long long> A, vector<long long> B, vector<long long> C){
	ll now = -1, res = 0;
	rep(i, N) {
		res += B[A[i]-1];
		if (A[i+1]-1 == A[i]-1+1) res += C[A[i]-1];
	}
	cout << res << endl;
}

int main(){	
	long long N;
	scanf("%lld",&N);
	vector<long long> C((N-1)-1+1);
	vector<long long> A(N-1+1);
	vector<long long> B(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&A[i]);
	}
	for(int i = 0 ; i <= N-1 ; i++){
		scanf("%lld",&B[i]);
	}
	for(int i = 0 ; i <= (N-1)-1 ; i++){
		scanf("%lld",&C[i]);
	}
	solve(N, A, B, C);
	return 0;
}



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

int main(){
  int N, X;
  cin >> N >> X;
  vector<int> m(N);
  int powd=0;
  int ans=N;
  for(int i=0; i<N; i++){
    cin >> m.at(i);
    powd+=m.at(i);
  }
  sort(m.begin(),m.end());
  ans+=(X-powd)/m.at(0);
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys

def rev(t):
    if t == "S":
        return "W"
    else:
        return "S"

N = int(input())

s = input()

for p in range(2):

    for q in range(2):

        lis = []

        if p == 0:
            lis.append("S")
        else:
            lis.append("W")
        if q == 0:
            lis.append("S")
        else:
            lis.append("W")

        for i in range(N-2):

            if lis[-1] == "S":
                if s[i+1] == "o":
                    lis.append(lis[i])
                else:
                    lis.append(rev(lis[i]))

            else:
                if s[i+1] == "o":
                    lis.append(rev(lis[i]))
                else:
                    lis.append(lis[i])

        flag = True
        
        if lis[0] == "S":
            if s[0] == "o" and lis[-1] != lis[1]:
                flag = False
            elif s[0] == "x" and lis[-1] == lis[1]:
                flag = False

        else:
            if s[0] == "o" and lis[-1] == lis[1]:
                flag = False
            elif s[0] == "x" and lis[-1] != lis[1]:
                flag = False

        
        if lis[-1] == "S":
            if s[-1] == "o" and lis[-2] != lis[0]:
                flag = False
            elif s[-1] == "x" and lis[-2] == lis[0]:
                flag = False

        else:
            if s[-1] == "o" and lis[-2] == lis[0]:
                flag = False
            elif s[-1] == "x" and lis[-2] != lis[0]:
                flag = False

        if flag:
            print ("".join(lis))
            sys.exit()

print (-1)
           


Measured memory_bytes: 59564
#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 - 1; i >= 0; i--)
#define ALL(x) x.begin(),x.end()

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const ll INF = 1e18;
const int mod = 1e9+7;
const int MAX = 1e6;

// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

struct edge {int to, cost;}; // 辺
// vector<edge> graph[MAX]; // 隣接リスト
// bool visit[MAX]; // 訪問の有無

int n, m, ans = 1e5; // 変数
string s, t;

int main() {
// input
    cin >> s;
    cin >> t;
    n = s.size();
    m = t.size();
// solve
    rep(i, n-m+1) {
        int cnt = 0;
        rep(j, m) {
            if (s[i+j]!=t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }
// output
    cout << ans << "\n";
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
int y,z,b,n,i[4][13]={0},j;
char a,x[4]={'S','H','C','D'};
scanf("%d",&n);
for(b=0;b<n;b++){
    scanf("%s %d",&a,&y);
    if(a=='S'){
        i[0][y]=1;
    }else if(a=='H'){
        i[1][y]=1;
    }else if(a=='C'){
        i[2][y]=1;
    }else if(a=='D'){
        i[3][y]=1;
    }
}
for(j=0;j<4;j++){
        if(j==0){
            a='S';
        }else if(j==1){
            a='H';
        }else if(j==2){
            a='C';
        }else if(j==3){
            a='D';
        }
        for(y=1;y<14;y++){
                if(i[j][y] == 0){
            printf("%c %d\n",a,y);
        }}

}

return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(void)
{
	int N,l,r,i,T;

	scanf("%d",&N);

	T=0;
	for(i=0;i<N;i++){
		scanf("%d%d",&l,&r);
	          T=T+(r-l)+1;
	}
	printf("%d\n",T);

	return 0;
}


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

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 100000000
#define MOD 1000000007
#define writeln(n) cout<<n<<endl
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
//vector<tuple<long long, long long, long long>>vec;

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

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

llong pownew(llong m, llong n) {
    if (n == 0) { return 1; }
    if (n % 2 == 0) { return pow(m*m, n/2); }
    return pow(m, n-1) * m;
}

bool isprime(int p) {
    if (p == 1) return false;
    for (int i = 2; i < p; i++) {
        if (p%i == 0) return false;
    }
    return true;
}

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

const int inf=100000000;

long long modpow(long long a, long long n, long long mod)
{
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    llong W,H; cin>>W>>H;
    llong x,y; cin>>x>>y;
    double ans=(double)W*H/2.0;
    int cnt=0;
    if(W%2==0&&x==W/2&&H%2==0&&y==H/2) cnt=1;
    std::cout << std::fixed;
    cout<<std::setprecision(6)<<ans;
    cout<<" ";
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
using System;

// #ref http://red.cliff.jp/topcoder/dp_knapsack.html
//????????????1+2+4+8+...???????????????????????????????????????????????°????????????
// 0-1??????????????????????????????

namespace DPL1_F
{
    class Program
    {
        static int N, W;
        static int a, b, c;
        static int[] pow = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384 };
        static int[] dp;
        static int v, w;
        static int j;
        static void Main(string[] args)
        {
            var t = scan;
            N = t[0]; W = t[1];

            dp = new int[W + 1];

            for (int i = 0; i < N; i++)
            {
                t = scan;
                a = t[0]; b = t[1]; c = t[2];

                for (j = 0; pow[j + 1] <= c; j++)
                {
                    v = a * pow[j]; w = b * pow[j];
                    solve();
                }

                var d = c - pow[j] + 1;
                v = a * d; w = b * d;
                solve();              
            }

            Console.WriteLine(dp[W]);
        }
        static void solve()
        {
            for (int k = W; k >= w; k--)
            {
                dp[k] = Math.Max(dp[k], dp[k - w] + v);
            }
        }        
        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }    
}

Measured memory_bytes: 9288
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell1 1e9+7
#define hell2 1e9+9
#define pi 3.1415926535
#define ms(s, n) memset(s, n, sizeof(s))
#define prec(n) fixed<<setprecision(n)
#define eps 0.000001
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define ll long long
#define ld long double 
#define no_of_digits(n) floor(log10(n)) + 1
#define see(x) cout << (#x) << " is " << (x) << endl
#define INF 1e9

using namespace std;

ll mult(ll a,ll b, ll p=hell1){   return ((a%p)*(b%p))%p; }
ll multbig(ll a,ll b,ll mod=hell1){   if(a==0 or b==0) return 0;if(a==1 or b==1) return (a*b)%mod;ll cur=multbig(a,b/2,mod);cur=(2*cur)%mod;if(b%2) cur=(cur+a)%mod;return cur;
}
ll add(ll a, ll b, ll p=hell1){ if(a>=p) a%=p; if(b>=p) b%=p; if(a+b>p) return (a + b)%p; else return a+b;}
ll sub(ll a, ll b, ll p=hell1){return (a%p - b%p + p)%p;}
ll fpow(ll n, ll k, ll p = hell1) {ll r = 1; for (; k; k >>= 1) {if (k & 1) r = mult(r,n,p); n = mult(n,n,p);} return r;}
ll inv(ll a, ll p = hell1) {return fpow(a, p - 2, p);}
ll inv_euclid(ll a, ll m = hell1){ll m0 = m;ll y = 0, x = 1;if (m == 1)return 0;while (a > 1){ll q = a / m;ll t = m;m = a % m, a = t;t = y;y = x - q * y;x = t;}if (x < 0)x += m0;return x;}
int isPowerof2(ll x) { return (x && !(x & x-1)); } 
ll log2(ll x) { ll res = 0; while (x >>= 1) res++; return res; } 

// max({a, b, c, d})

vector<ll>adj[200005];
ll update[200005];
ll ans[200005];

int binaryToDecimal(string n) 
{ 
    string num = n; 
    int dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    int base = 1; 
  
    int len = num.length(); 
    for (int i = len - 1; i >= 0; i--) { 
        if (num[i] == '1') 
            dec_value += base; 
        base = base * 2; 
    } 
  
    return dec_value; 
} 

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

    int a[n+1];
    int b[n];

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

    for(int i=0;i<n;i++)
        cin >> b[i];

    ll ans = 0;

    for(int i=0;i<n;i++)
    {
        if(b[i] >= a[i])
        {
            b[i] -= a[i];
            ans += a[i];
            a[i] = 0;
        }
        else
        {
            ans += b[i];
            a[i] -= b[i];
            b[i] = 0;
        }

        if(b[i] >= a[i+1])
        {
            ans += a[i+1];
            b[i] -= a[i+1];
            a[i+1] = 0;
        }
        else
        {
            ans += b[i];
            a[i+1] -= b[i];
            b[i] = 0;
        }
    }

    cout << ans << "\n";
}




Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define rep(i,a,b) for(i=a;i<b;i++)
ll int large=(ll int)1e13+7;
ll int mod=(ll int)1e9+7;
ll int const N=(ll int)1e6+10;

ll int mod_exp(ll int x,ll int n)
{
    ll int result=1;
    while(n>0)
    {
        if(n%2==1)
            result=(result*x)%mod;
        x=(x*x)%mod;
        n=n/2;
    }
    return result;
}

ll int mod_inverse(ll int a)
{
    return mod_exp(a,mod-2);
}



int main()
{
ios_base::sync_with_stdio(false);
    cin.tie(NULL);
ll int T,i,j,ij;
T=1;
//cin>>T;
while(T--)
{
  ll int n;
  cin>>n;
  cout<<360/(__gcd(n,360ll));


}
return 0;
}
















Measured memory_bytes: 3580
import sys
from collections import defaultdict
readline = sys.stdin.buffer.readline
#sys.setrecursionlimit(10**8)


def geta(fn=lambda s: s.decode()):
    return map(fn, readline().split())


def gete(fn=lambda s: s.decode()):
    return fn(readline().rstrip())


def main():
    n = gete(int)
    s = gete()

    ans = 0
    for i in range(n - 2):
        if s[i:i + 3] == "ABC":
            ans += 1

    print(ans)


if __name__ == "__main__":
    main()

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

typedef long long ll;

int main(){
 int n, a, b, abroad, yosen;
 cin >> n >> a >> b;
 abroad = 0, yosen = 0;
 string s;
 cin >> s;
 rep(i, n){
   if(s.at(i) == 'a'){
     if (yosen < a+b){
       cout << "Yes" << endl;
       yosen++;
     }
     else {
       cout << "No" << endl;
     }
   }
   else if(s.at(i) == 'b'){
     abroad++;
     if (yosen < a+b && abroad<=b){
       cout << "Yes" << endl;
       yosen++;
     }
     else{
       cout <<"No" << endl;
     }
   }
   else {
     cout << "No" << endl;
   }
 }
}


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

vector<int> D(10,-1);

bool check(int price){
    while(price != 0){
        for( int k : D ){
            if( find( D.begin(), D.end(), price%10) != D.end() ){
                return false;
            }
        }
        price /= 10;
    }

    return true;
}

int main(){
    int N,K; cin >> N >> K;
    for( int i = 0; i < K; i++ )cin >> D[i];

    int ans = 0;
    for( int i = N; i <= 100000; i++ ){
        if(check(i)){
            ans = i;
            break;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main() {
	string s;
	cin >> s;
	int count_o = 0;
	int count_x = 0;
	int i;
	for(i=0; i<s.length();i++){
		if (s[i] == 'o') count_o++;
		else count_x++;
	}
	int remaining = 15-s.length();
	
	if((8-count_o) > remaining) cout << "NO" <<endl;
	else cout << "YES" << endl;  

	return 0;
	
} 

Measured memory_bytes: 256
#include <iostream>

using namespace std;

const int MAX = 1000000;

void sieve(bool isprime[]) {
	for (int i = 0; i < MAX + 1; i++) {
		isprime[i] = true;
	}
	isprime[0] = isprime[1] = false;

	for (int i = 2; i < MAX + 1; i++) {
		if (isprime[i]) {
			for (int j = i * 2; j < MAX + 1; j += i) {
				isprime[j] = false;
			}
		}
	}

	return;
}

int main() {
	int a, d, n;
	int num;
	int i;
	bool isprime[MAX + 1];
	sieve(isprime);

	while (true) {
		cin >> a >> d >> n;
		if (a == 0) {
			break;
		}
		
		num = 0;
		i = a;
		do {
			if (isprime[i]) {
				num++;
			}
			i += d;
		} while (num < n);

		cout << i - d << endl;
	}

	return 0;
}

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

int main(){
  string S;
  cin >> S;
  vector<string> vs(S.size(),"");
  vs.at(0)=S.at(0);
  int j;
  string T="";
  string U;
  for(int i=1;i<S.size();i++){
    j=i;
    U=vs.at(j-1);
    while(true){
      if(j>=S.size()){
        break;
      }
      T+=S.at(j);
      if(T!=U){
        vs.at(j)=T;
        i=j;
        break;
      }
      j++;
    }
    T="";
  }
  int K=0;
  for(int i=0;i<S.size();i++){
    if(vs.at(i)!=""){
      K++;
    }
  }
  cout << K << endl;
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  int p[n];
  rep(i,0,n) cin >> p[i];

  int count=0;
  rep(i,0,n) {
  if(p[i]!=i+1) count++;
  }
  if (count==0 || count==2) cout << "YES" << endl;
  else cout << "NO";
}

Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, gcd
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
# from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

K = I()

ans = 0
for a, b, c in combinations_with_replacement(range(1, K+1), 3):
    # print(a, b, c)
    score = gcd(a,gcd(b,c))
    # print(score)
    l = len({a, b, c})
    # print(l)
    if l == 3:
        ans += score*6
    elif l == 2:
        ans += score*3
    else:
        ans += score

print(ans)

Measured memory_bytes: 68800
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;

int a,b,k;
string s,t;
int q;

int search(){
  for(int i=a-1;i>=b-1;i--){
    k=i;
    for(int j=b-1;j>=0;j--){
      if(s[k]==t[j] || s[k]=='?'){
        if(j==0) {
          return k;
        }
        k--;
        continue;
      }
      else {
        break;
      }
    }
  }
  return -1;
}

int main(){

  cin >> s >> t;
  a=s.size();
  b=t.size();
  q=search();

  if(q==-1){
    cout <<"UNRESTORABLE";
    return 0;
  }
  else{
    for(int i=0;i<a;i++){
      if(i==q){
        cout << t;
        i=q+b-1;
        continue;
      }
      if(s[i]=='?'){
        cout <<'a';
        continue;
      }
      cout << s[i];
    }
  }
  return 0;
}


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

#define MOD 1000000007
#define pb push_back
#define mp make_pair

template<typename T>
void print(vector<T> &v)
{
    for_each(v.begin(), v.end(), [](auto i){cout << i << ' ';});
    cout << '\n';
}

void f(int testCase)
{
    long long S;
    cin >> S;
    vector<long long> dp(S+1);
    dp[0] = 1;
    for(int i = 3; i<=S; i++) {
        for(int j = 3; j<=i; j++) {
            dp[i] += dp[i-j];
            dp[i] %= MOD;
        }
    }
    cout << dp[S]%MOD << '\n';
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
    //cin >> t;

    for(int i = 1; i<=t; i++)
        f(i);
    return 0;
}

Measured memory_bytes: 3652
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <queue>
#include <algorithm> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll mod = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;


int main(){
    ll n;
    cin >> n;
    vector <ll> a(n*3);


    REP(i,n*3)
    {
        cin >> a[i];
    }
    sort(a.begin(),a.end());

    ll cnt = 0;
    ll i = n*3 - 2;
    ll res = 0;

    while(cnt < n)
    {
        res += a[i];
        ++cnt;
        i -= 2;
    }

    cout << res << endl;

    return 0;
}





Measured memory_bytes: 2560
module Main where

import Data.List
import Control.Monad
import Debug.Trace
import qualified Data.Vector as V
import Data.Maybe 
import qualified Data.Text as T
import qualified Data.Text.IO as TIO


makeGroup :: T.Text -> [Int]
makeGroup people = let 
    initialAccum = ([], 1, T.head people)
    (groupList, lastGroup, _) = T.foldl' inner initialAccum (T.tail people) 
    in 
        reverse $ lastGroup : groupList
        where
    inner :: ([Int], Int, Char) -> Char -> ([Int], Int, Char)
    inner (groupList, currentNumber, currentStat) person = 
        if person == currentStat then
            (groupList, currentNumber + 1, currentStat)
        else
            (currentNumber : groupList, 1, person)

solve :: T.Text -> Int -> Int
solve people orderTime = 
        fst $ foldl' inner (firstGroup, firstGroup) indexes
    where
    group =  if T.head people == '0'
        then 
            0 : makeGroup people
        else 
            makeGroup people
    groupLength = length group
    groupArr = V.fromList group
    getGroup i = fromMaybe 0 $ groupArr V.!? i
    joinableGroupNum = orderTime * 2 + 1
    firstGroup = sum $ V.take joinableGroupNum groupArr 
    indexes = [x| x<- [2..groupLength], even x]
    inner (biggest, current) index = let
        minus = getGroup (index - 1) + getGroup (index - 2)
        plus = getGroup (index + joinableGroupNum - 1) + getGroup (index + joinableGroupNum - 2)
        next = current + plus - minus
        in
            (max biggest next, next)

readLs :: Read a => IO [a]
readLs = fmap read . words <$> getLine

readTuple :: Read a  => IO (a, a)
readTuple = do
    [f, s] <- readLs
    pure (f, s)


main = do
    (_, k) <- readTuple
    people <- TIO.getLine
    print $ solve people k




Measured memory_bytes: 18044
#include<cstdio>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
int main(){
	int R,G,result;
	scanf("%d",&R);
	scanf("%d",&G);
	result=2*G-R;
	printf ("%d\n",result);
	return 0;
}

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

int main() {
    int n; // 支払金額
    int a; // 1円の枚数

    cin >> n >> a;

    // 支払金額から500円玉で支払える分だけ引く
    n = n - ((n / 500) * 500);
	
    // 残額が1円の枚数より多ければYes
    if (n <= a) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3504
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 200000;

int main(){
    int R[MAX], n;

    cin >> n;
    for(int i=0; i<n; i++) cin >> R[i];

    int maxv = -2000000000;
    int minv = R[0];

    for(int i=1; i<n; i++){
        maxv = max(maxv, R[i]-minv);
        minv = min(minv, R[i]);
    }

    cout << maxv << endl;


    return 0;
}


Measured memory_bytes: 3880
using System;
using System.Collections.Generic;
class C
{
    static void Main(string[] args)
    {
        long X = long.Parse(Console.ReadLine());
        long Y = 0;
        bool f = true;
        List<int> p = new List<int>();
        p.Add(2);
        if (X == 2)
        {
            Console.WriteLine(2);
            return;
        }
    
        for (int i = 2; f; i++)
        {
            for (int j = 0; j < p.Count; j++)
            {
                if (i % p[j] == 0)
                {   
                    break;
                }
                if (j == (p.Count - 1))
                {
                    p.Add(i);
                    if (X <= i)
                    {
                        Y = i;
                        f = false;
                    }
                }
            }
        }
        Console.WriteLine(Y);
    }
}

Measured memory_bytes: 13140
//Try until you reach your goal
#include <bits/stdc++.h>
using namespace std;
# define ll long long
# define endl "\n"
# define str string
# define vll vector<ll>
# define pb push_back
# define mll map<ll,ll>
# define mp make_pair
# define ff first
# define ss second
# define pll pair<ll,ll>
# define f(x,y) for(int x=0;x<y;x++)
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll a,b,c;
    cin>>a>>b>>c;
    ll k=b*c;
    if(k>=a){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

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

template <typename T, T (*op)(T, T), T id>
struct SegmentTree {
    int size;
    vector<T> node;

    SegmentTree(int n) {
        size = 1;
        while (size < n) size <<= 1;
        node.resize(2 * size, id);
    }

    void set(int k, const T& x) {
        node[k + size] = x;
    }

    T operator[](int k) const {
        return node[k + size];
    }

    void build() {
        for (int k = size - 1; k > 0; k--) node[k] = op(node[2 * k], node[2 * k + 1]);
    }

    void update(int k, const T& x) {
        k += size;
        node[k] = x;
        while (k >>= 1) node[k] = op(node[2 * k], node[2 * k + 1]);
    }

    T query(int l, int r) {
        T L = id, R = id;
        for (l += size, r += size; l < r; l >>= 1, r >>= 1) {
            if (l & 1) L = op(L, node[l++]);
            if (r & 1) R = op(node[--r], R);
        }
        return op(L, R);
    }

    int find_first(int l, const function<bool(T)>& cond) {
        T L = id;
        int r = 2 * size;
        for (l += size; l < r; l >>= 1, r >>= 1) {
            if (l & 1) {
                T nxt = op(L, node[l]);
                if (cond(nxt)) {
                    while (l < size) {
                        nxt = op(L, node[2 * l]);
                        if (cond(nxt)) l = 2 * l;
                        else L = nxt, l = 2 * l + 1;
                    }
                    return l - size;
                }
                L = nxt;
                l++;
            }
        }
        return -1;
    }

    int find_last(int r, const function<bool(T)>& cond) {
        T R = id;
        int l = size;
        for (r += size; l < r; l >>= 1, r >>= 1) {
            if (r & 1) {
                r--;
                T nxt = op(node[r], R);
                if (cond(nxt)) {
                    while (r < size) {
                        nxt = op(node[2 * r + 1], R);
                        if (cond(nxt)) r = 2 * r + 1;
                        else R = nxt, r = 2 * r;
                    }
                    return r - size;
                }
                R = nxt;
            }
        }
        return -1;
    }
};

int op(int a, int b) {
    return max(a, b);
}

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

    int N, Q;
    cin >> N >> Q;
    SegmentTree<int, op, 0> st(N);
    for (int i = 0; i < N; i++) {
        int A;
        cin >> A;
        st.set(i, A);
    }
    st.build();
    for (int i = 0; i < Q; i++) {
        int T;
        cin >> T;
        if (T == 1) {
            int X, V;
            cin >> X >> V;
            st.update(X - 1, V);
        } else if (T == 2) {
            int L, R;
            cin >> L >> R;
            cout << st.query(L - 1, R) << "\n";
        } else {
            int X, V;
            cin >> X >> V;
            int j = st.find_first(X - 1, [&](int v) { return v >= V; });
            cout << (j == -1 ? N + 1 : j + 1) << "\n";
        }
    }
}

Measured memory_bytes: 5272
n = int(input())
p = [int(i) for i in input().split()]

ans = 0
for i in range(1, n - 1):
    if (p[i - 1] < p[i] and p[i] < p[i + 1]) or (p[i + 1] < p[i] and p[i] < p[i - 1]):
        ans += 1
print(ans)

Measured memory_bytes: 3060
while True :
    m, f, r = map(int, input().split())
    
    if m == -1 and f == -1 and r == -1 :
        break
    else :
        if m == -1 or f == -1 or m + f < 30 :
            print("F")
        elif m + f >= 80 :
            print("A")
        elif m + f >= 65 and m + f < 80 :
            print("B")
        elif m + f >= 50 and m + f < 65 :
            print("C")
        else :
            if r >= 50 :
                print("C")
            else :
                print("D")




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

int main(){
    vector<string> output;
    string input;

    getline(cin, input);

    int i = 0;
    int begin = 0;
    while(i<input.size()){
        if(input[i] == ' ' || input[i] == ',' || input[i] == '.'){
            if(i-begin > 2 && i-begin < 7){
                output.push_back(input.substr(begin, i-begin));
            }
            begin = i + 1;
            i = begin;
        }
        else{
            i++;
        }
    }
    for(int i=0; i<output.size(); i++){
        if(i) cout << " ";
        cout << output[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 0
n = int(input())
A = [int(i) for i in input().split()]

cnt = 0
for _ in range(100):
    flag = 1
    for i in range(n):
        if A[i] != 0:
            A[i] -= 1
            if flag == 1:
                cnt += 1
                flag = 0
        else:
            flag = 1

print(cnt)

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

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

Measured memory_bytes: 3608
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i,n) for(int i = 0; i < n; i++)

bool isSquare(int n) {
	int p = sqrt(n);
	if (p * p == n) return true;
	else return false;
}

int main() {
	int n, d;
	cin >> n >> d;
	vector<vector<int>> x(n, vector<int>(d));
	rep(i, n) {
		rep(j, d) cin >> x[i][j];
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			int sum = 0;
			rep(k, d) {
				sum += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			if (isSquare(sum)) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

#define ll long long

ll N, K;
ll c, Max, Min;

int main() {
    cin >> N >> K;
    for (ll i = 1; i <= N + 1; i++) {
        Min += i - 1;
        Max += N - i + 1;
        if (i >= K)
            c += Max - Min + 1;
    }

    cout << c % 1000000007 << endl;
}

Measured memory_bytes: 3616
#include"bits/stdc++.h"
using namespace std;

int main(){
	string S;
	cin >> S;
	int zcount = 0;
	int ocount = 0;
	for(int i = 0; i < S.length(); i++){
		if(S[i] == '0'){
			zcount++;
		}else if(S[i] == '1'){
			ocount++;
		}
	}
	cout << 2*min(zcount, ocount) << endl;
	return 0;
}


Measured memory_bytes: 512
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":pass
a, b = i2()
c = min(a,b)
d = max(a,b)
for i in range(1,d+1):
    if (c*i)%d == 0:
        print(c*i)
        exit()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  int v[n];
  int ans=0;
  for(int i=0; i<n; i++){
    cin>>v[i];
  }
  for(int i=0; i<n; i++){
    while(v[i]){
      for(int j=i; j<n; j++){
        if(v[j]){
          v[j]--;
        }
        else{
          break;
        }
      }
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  int N,T;
  cin >> N >> T;
  int ans=1001;
  int cost,time;
  rep(i, N){
  cin >> cost >> time;
    if(time<=T)
      ans=min(cost,ans);
  }
  if(ans==1001){
  cout << "TLE" << endl;
    return 0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define out(a) cout<<a<<" "
#define all(a) (a).begin(), (a).end()
#define upper_index(v, a) (int)distance(v.begin(), upper_bound((v).begin(), (v).end(), a))
#define lower_index(v, a) (int)distance(v.begin(), lower_bound((v).begin(), (v).end(), a))
typedef long long ll;
const long long INF = 1e17;

int main(void){
    ll l=2,r=3;
    ll k;
    cin>>k;
    vector<int> a(k);
    rep(i,k) cin>>a[i];
    reverse(a.begin(),a.end());
    rep(i,k){
        ll p,q;
        p=l%a[i];
        q=r%a[i];
        l=(l/a[i]);
        r=(r/a[i]);
        if (p!=0) l+=1;
        if (q!=0) r+=1;
        l*=a[i];
        r*=a[i];
    }
    if (l==r){
        cout<<-1<<endl;
    }else{
        cout<<l<<" "<<r-1<<endl;
    }
    
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a[100001];
	int maxn=0;
	long long minn=0x7fffffff;
	int ans;
	int n,i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		maxn=max(maxn,a[i]);
	}
	for(i=0;i<n;i++)
	{
		if(abs(maxn/2-a[i])<minn&&a[i]!=maxn)
		{
			minn=fabs(maxn/2-a[i]);
			ans=a[i];
		}
	}
	printf("%d %d",maxn,ans);
	return 0;
}

Measured memory_bytes: 640
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n := scanInt()
	s := 0
	a := make([]int, n)
	for i := range a {
		a[i] = scanInt()
		s ^= a[i]
	}

	wr := bufio.NewWriter(os.Stdout)
	for i, v := range a {
		wr.WriteString(strconv.Itoa(s ^ v))
		if i < len(a)-1 {
			wr.WriteString(" ")
		} else {
			wr.WriteString("\n")
		}
	}
	wr.Flush()
}


Measured memory_bytes: 7252
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 200005;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int a[MAXN], b[MAXN];
int main() {
	int n; read(n);
	for (int i = 1; i <= n; i++)
		read(a[i]), b[i] = a[i];
	sort(b + 1, b + n + 1);
	int x = b[n / 2], y = b[n / 2 + 1];
	for (int i = 1; i <= n; i++)
		if (a[i] <= x) writeln(y);
		else writeln(x);
	return 0;
}

Measured memory_bytes: 3712
n = int(input())
print(0,flush=True)

prev = input()
if prev=='Vacant': exit()
zero = prev
now=[]

def isok(ans, odd_diff):
    print(ans,flush=True)
    now = input()

    if now == 'Vacant': exit()

    if (now==zero and odd_diff)or(now!=zero and not odd_diff):
        return True
    else:
        return False

ok = n-1 #ok以前にVacantが存在
ng = 0 #ng以前にVacantは存在しない

while ok - ng > 1:
    m = (ok+ng)//2
    odd_diff = (m%2==1)
    if isok(m, odd_diff):
        ok = m
    else:
        ng = m

print(ok,flush=True)
exit()


Measured memory_bytes: 3660
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
using namespace std;
const int NN = 11000;
typedef long long ll;

int k;
int a[100] = {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};
ll h, w, ans;

int main(){
	//freopen("a.in", "r", stdin);
	//freopen("a.out", "w", stdout);
	
	scanf("%lld%lld", &h, &w);
	//for (int i=0; i<20; i++) printf("%d ", a[i]);
	//ans = h * (w / 2);
	if (h % 2 == 1){
		if (w % 2 == 1){
			ans = (h / 2) * (w / 2) + (h / 2 + 1) * (w / 2 + 1);
		} else {
			ans = h * (w / 2);
		}
	} else {
		if (w % 2 == 1){
			ans = (h / 2) * (w / 2) + (h / 2) * (w / 2 + 1);
		} else {
			ans = h * w / 2;	
		}
	}
	if (h == 1 || w == 1) ans = 1;
	printf("%lld", ans);
	
	return 0;
} 

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

int main(){
	string s; cin>>s;
	int k=s.size();
	
	map<char,int> mp;
	rep(i,k){
		mp[s[i]]++;
	}
	bool flg=true;
	for(auto x:mp) if(x.second%2!=0) flg=false;
	cout<<(flg?"Yes":"No")<<endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repa(i, a, n) for (int i = (int)(a); i < (int)(n); i++)
#define PI (acos(-1))
#define _GLIBCXX_DEBUG

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

  ll ans = 0;

  vector<ll> l(86);
  l[0] = 2;
  l[1] = 1;

  repa(i, 2, n+1){
    l[i] = l[i-2] + l[i-1];
  }

  cout << l[n] << endl;

}

Measured memory_bytes: 256
#abc134c
import copy

n=int(raw_input())
a=[]
for i in xrange(n):
 a.append(int(raw_input()))
num1=sorted(a)[-1]
num2=sorted(a)[-2]
if a.count(num1)>1:
 for i in xrange(n):
  print num1
else:
 for i in xrange(n):
  if a[i]==num1:
   print num2
  else:
   print num1


Measured memory_bytes: 12804
#include<iostream>
using namespace std;
const long long mod=998244353;
long long a,b,n,m;
long long f[3005][3005];
int main(){
	cin>>a>>b>>n>>m;
	f[a][b]=1;
	for(long long i=a;i<=n;i++)
	for(long long j=b;j<=m;j++){
		if(i==a&&j==b) continue;
		if(b==j) {
			f[i][j]=f[i-1][j]*j%mod;
			continue;
		}
		if(a==i){
			f[i][j]=i*f[i][j-1]%mod;
			continue;
		}
		f[i][j]=(long long)j*f[i-1][j]+(long long)i*f[i][j-1]-(long long)(j-1)*(i-1)*f[i-1][j-1]%mod;
		f[i][j]=(long long)f[i][j]%mod;
	}
/*	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cout<<f[i][j]<<' ';
		}
		cout<<endl;
	}*/
	cout<<f[n][m]<<endl;
	return 0;
	
}

Measured memory_bytes: 74004