akhauriyash/Code-Regression huggingface dataset:
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define  mod 998244353
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0};
int dy[8]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int r;cin>>r;
    if(r<=1199)
        cout<<"ABC"<<endl;
    else if(r<=2799)
        cout<<"ARC"<<endl;
    else
        cout<<"AGC"<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------






Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    int a = 0;
    int b = 0;
    for(int i = 0; i < 3; i++){
        cin >> N;
        if(N == 5){
            a++;
        }
        if(N == 7){
            b++;
        }
    }
    if(a == 2 && b == 1){
        cout << "YES" << endl;
        return 0;
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
            int a = in.nextInt();
            int b = in.nextInt();
            int c = in.nextInt();
            int d = 0;

            for(int i = a; i < b + 1 ; i++) {
                if (c%i == 0) {
                d++;
            }

        }
        System.out.println(d);
    }
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  VI a(n);
  vector<PII> v;
  rep(i,n){
    cin >> a[i];
    v.emplace_back(PII(a[i],i));
  }
  sort(all(v));
  rep(i,n){
    a[v[i].second] = i;
  }
  ll ans = 0;
  // rep(i,n) cout << a[i] << " ";
  // cout << endl;
  rep(i,n){
    if( i%2 != a[i]%2 ) ans++;
  }
  cout << ans/2 << endl;

  return 0;
}


Measured memory_bytes: 1784
n=int(input())
s=input()
s=s

ll=0 #左側の黒い数を保持
rr=s.count(".") #右側の白い数を保持

result=ll+rr
for item in s:
    if item=="#":
        ll+=1
    else:
        rr-=1
    
    result=min(result,ll+rr)

print(result)


Measured memory_bytes: 41564
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <bitset>
#include <string>
#include <cmath>
#include <set>
#include <map>
#define Rep(i, x, y) for (int i = x; i <= y; i ++)
#define Dwn(i, x, y) for (int i = x; i >= y; i --)
#define RepE(i, x) for (int i = pos[x]; i; i = g[i].nex)
#define ev g[i].y
#define eps 1e-10
#define fr first
#define sd second
#define pb push_back
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
const int N = 3005;
int n, mod;
ll ans, res, f[N][N], c[N][N];
ll power(ll x, ll y, int mod = mod) {
	// x %= mod, y %= mod;
	ll z = 1;
	while (y) {
		if (y & 1) (z *= x) %= mod;
		y >>= 1; (x *= x) %= mod;
	}
	return z;
}
int main()
{
	cin >> n >> mod;
	ans = power(2, power(2, n, mod - 1));
	// cout <<0<<" "<< ans<<endl;
	c[0][0] = 1;
	Rep(i, 1, n) {
		c[i][0] = 1;
		Rep(j, 1, i) c[i][j] = (c[i - 1][j] + c[i - 1][j - 1]) % mod;
	}
	f[0][0] = 1;
	Rep(i, 1, n) {
		ll k = power(2, n - i), pk = 1, res = 0;
		Rep(j, 0, i) {
			f[i][j] = f[i - 1][j] * (j + 1) % mod;
			if (j) (f[i][j] += f[i - 1][j - 1]) %= mod;
		 	// cout <<i<<" "<< j<<" "<<f[i][j]<<endl;
			(res += f[i][j] * pk % mod) %= mod;
		 	pk = pk * k % mod;
		}
		res = res * c[n][i] % mod;
		res = res * power(2, power(2, n - i, mod - 1)) % mod;
		if (i & 1) ans -= res;
		else ans += res;
		// cout <<i<<" "<< res<<" "<<ans<<endl;
		ans %= mod;
	}
	cout << (ans % mod + mod) % mod << endl;

	return 0;
}

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

long long getSumOfDigit(long long n) {
    return (n ? (n % 10) + getSumOfDigit(n / 10) : 0);
}

double getNDivSum(long long n) {
    return (double)n / getSumOfDigit(n);
}

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

    vector<long long> ans;
    long long base = 1;

    for (int i = 0; i < 15; i++) {
        for (int j = 1; j < 9 * 15; j++) {
            ans.push_back((j + 1) * base - 1);
        }
        base *= 10;
    }
    sort(ans.begin(), ans.end());
    ans.erase(unique(ans.begin(), ans.end()), ans.end());

    for (long long i = 0; i < ans.size(); i++) {
        for (long long j = i + 1; j < ans.size(); j++) {
            if (getNDivSum(ans[i]) > getNDivSum(ans[j])) {
                ans.erase(ans.begin() + i);
                i--;
                break;
            }
        }
    }

    for (long long i = 0; i < k; i++) cout << ans[i] << endl;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
#define INF 1e9
#define rep(i, n) for(int i=0;i<n;i++)
#define ALL(x) (x).begin(), (x).end()  //昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
const long long mod = 1e9+7;
typedef long long ll;  //ll とdoubleは違う
typedef priority_queue<int> PQ;
typedef vector<long long> VL;
typedef vector<bool> VB;
typedef vector<int> VI;  // VI a(n);
typedef vector<double> VD;  
typedef vector<string> VS;  
typedef vector<char> VC; 
typedef vector<VS> VSS;
typedef vector<VC> VCC;    
typedef vector<VI> VII;   // VII a(n,vector<int>(m)) n * m 
typedef vector<VL> VLL;
typedef pair<int, int> PII;
typedef map<int, int> MP;   //MP a;
typedef vector<pair<ll, ll> > PS;
template <class T, class U>  // chmax(max, a);
bool chmax(T &a, U b){
    if (a < b){ a = b;return 1;}
    return 0;
}
template <class T, class U> //chmin(min,a)
bool chmin(T &a, U b){
    if (a > b){ a = b; return 1;}
    return 0;
}
template<typename T>   // operator << (cout,a);
ostream& operator << (ostream& os, vector<T>& v) {
    os << "{";
    rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
    os << "}";
    return os;
}

// g++ -std=c++11 prac.cpp 
int main(){
    ll x,y,z,n,m=0,k,h,w,sum=0,ans=0,Max=-1e9,count=0,Min=1e9+1;
    string s,t,u;
    bool ok=true;
    cin >> n >> k;
    if(k%2==0){
        for(int i=1; i<=n;i++){
            if(i%k==0){
                ans++;
            }
            if(i%k==k/2){
                sum++;
            }
        }
        ans =  pow(ans,3)+pow(sum,3);
        cout << ans << endl;
        return 0;
    }
    else {
        for(int i=1; i<=n;i++){
            if(i%k==0){
                ans++;
            }
        }
        ans = pow(ans,3);
        cout << ans << endl;
        return 0;
    }
}

Measured memory_bytes: 256
/*
17/10/2017
*/
#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int main()
{
int n;
cin>>n;
int ans=0;
for(int i=1;i<n;i++)
{
for(int j=1;j<=sqrt(i);j++)
{
if(i%j==0)
{
ans+=2;
if((i/j)==j)
{
ans--;
}
}
}
}
cout<<ans;
}

Measured memory_bytes: 3680
from functools import reduce

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

def cmb(n, r):
    INF = 10 ** 9 + 7
    r = min(n - r, r)
    if r == 0:  return 1
    numer = reduce(lambda x, y: (x * y) % INF, range(n, n - r, -1))
    denom = reduce(lambda x, y: (x * y) % INF, range(1, r + 1))
    return (numer * pow(denom, INF - 2, INF)) % INF

def nHr(n, r):  
    if n == 0:  return 1
    return cmb(n + r - 1, n)

N, K = cin()

INF = 10 ** 9 + 7

ans = [N - K + 1]
for i in range(2, K + 1):
    b = nHr(K - i, i)
    cnt = 0
    tmp = N - K - (i + 1)
    if tmp >= 0:
        cnt += b * nHr(tmp, i + 1)
        cnt %= INF
    tmp += 1
    if tmp >= 0:
        cnt += 2 * b * nHr(tmp, i)
        cnt %= INF
    tmp += 1
    if tmp >= 0:
        cnt += nHr(tmp, i - 1) * b
        cnt %= INF
    ans.append(cnt)

for i in range(K):  print(ans[i])

Measured memory_bytes: 69644
n=int(input())
S=[]
for i in range(n):
    S.append(input())

from collections import defaultdict
d = defaultdict(lambda:0)

for k in S:
    d[str(k)]+=1
    
ansn=max(d.values())
ans=[]
for i in set(S):
    if d[i]==ansn:
        ans.append(i)

ans=sorted(ans)
for i in range(len(ans)):
    print(ans[i])


Measured memory_bytes: 44304
import math

T1, T2 = map(int, input().split())
A1, A2 = map(int, input().split())
B1, B2 = map(int, input().split())

if A1 > B1:
    F1, F2 = A1, A2
    S1, S2 = B1, B2
else:
    F1, F2 = B1, B2
    S1, S2 = A1, A2

oi = F1 * T1 - S1 * T1
nuki = S2 * T2 - F2 * T2 - oi

if nuki == 0:
    print("infinity")
elif nuki > 0:
    enc = oi // nuki * 2
    if oi % nuki != 0:
        enc = enc + 1
    print(enc)
else:
    print(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  int n, k;
  cin >> n >> k;
  ll ans = 0;
  REP(i, n){
    int x;
    cin >> x;
    ans += min(2*x, 2*(k-x));
  }
  cout << ans << endl;
  return 0;
}

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

void dfs(const Graph &G, vector<bool> &seen, int v) {
    seen[v] = true;
    for (auto nv : G[v]) if (!seen[nv]) dfs(G, seen, nv);
}

int main() {
    int N, M;
    cin >> N >> M;
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].push_back(b), G[b].push_back(a);
    }
    int res = 0;
    vector<bool> seen(N, false);
    for (int v = 0; v < N; ++v) {
        if (seen[v]) continue;
        dfs(G, seen, v);
        ++res;
    }
    cout << res - 1 << endl;
}

Measured memory_bytes: 9576
#include<stdio.h>
int main()
{
    int n,a=0,t=0,r=0,w=0;
    char s[100];
    scanf("%d",&n);
    while(n--){
        scanf("%s",s);
        if(s[0]=='A') a++;
        else if(s[0]=='T') t++;
        else if(s[0]=='W') w++;
        else if(s[0]=='R') r++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d",a,w,t,r);
    return 0;

}



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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, int b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    set<int> s;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        int tp;
        cin >> tp;
        s.insert(tp);
    }

    cout << s.size() << endl;
}


Measured memory_bytes: 256
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output
def chkprint(*args):
    names = {id(v):k for k,v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' = '+repr(arg) for arg in args))

# Binary converter
def to_bin(x):
    return bin(x)[2:]

# Set 2 dimension list
def dim2input(N):
    li = []
    for _ in range(N):
        li.append(input().split())
    return li

# --------------------------------------------

dp = None

def main():
    C = []
    C.append(input())
    C.append(input())

    cond1 = C[0][0] == C[1][2]
    cond2 = C[0][1] == C[1][1]
    cond3 = C[0][2] == C[1][0]

    if cond1 and cond2 and cond3:
        print("YES")
    else:
        print("NO")

main()


Measured memory_bytes: 4700
/*template date:2019/12/27*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#include<limits.h>
typedef long long int ll;
typedef unsigned long long int ull;
int asc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp(const void* X,const void* Y){int x=*(int*)X,y=*(int*)Y;if(x<y)return 1;else if(x==y)return 0;else return -1;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
double to_deg(double r){return r*180.0/(atan(1.0)*4.0);}
typedef struct{
    int x;
    int y;
}pair_t;
int asc_cmp_t(const void* X,const void* Y){int x=(*(pair_t*)X).x,y=(*(pair_t*)Y).y;if(x<y)return -1;else if(x==y)return 0;else return 1;}
int desc_cmp_t(const void* X,const void* Y){int x=(*(pair_t*)X).x,y=(*(pair_t*)Y).y;if(x<y)return 1;else if(x==y)return 0;else return -1;}

int main(){
    ull n,a,b;
    ull x;
    scanf("%llu %llu %llu",&n,&a,&b);
    x=b-a;
    x%=2;
    if(x){
        if(n-b<a-1){
            x=n-b;
            x++;
            x+=(b-a)/2;
            printf("%llu\n",x);
        }else{
            x=a-1;
            x++;
            x+=(b-a)/2;
            printf("%llu\n",x);
        }
    }else{
        x=b-a;
        x/=2;
        printf("%llu\n",x);
    }
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define ArraySizeOf(array)     (sizeof(array) / sizeof(array[0]))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define REV(i,n) for(int i=n-1;i>0;i--)
#define req(i,n,m) for(int i=n;i<m;i++)
#define REQ(i,n,m,l) for(int i=n;i<m;i+=l) 
#define _GLIBCXX_DEBUG
int INF = 1e9 + 7;
unsigned NthDayOfWeekToDay(unsigned n, unsigned dow, unsigned dow1)
{
    unsigned day;
    if (dow < dow1) dow += 7;
    day = dow - dow1;
    day += 7 * n - 6;
    return day;
}
signed gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
signed lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
unsigned DayToWeekNumber(unsigned day)
{
    return (day - 1) / 7 + 1;
}
unsigned AnotherDayOfWeek(unsigned day, unsigned day0, unsigned dow0)
{
    return (dow0 + 35 + day - day0) % 7;
}
using namespace std;
signed main() {
    int N; cin >> N;
    vector<string>W(N);
    rep(i, N) {
        cin >> W[i];
        if (i != 0) {
            if (W[i - 1].at(W[i - 1].size()-1) != W[i].at(0)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    sort(W.begin(), W.end());
    REP(i, N){
        if (W[i] == W[i - 1]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3600
import sys
input = sys.stdin.readline

N, M = map(int, input().split())
A = list(map(int, input().split()))
total = sum(A)
cnt = 0
for a in A:
    if a * 4 * M >= total:
        cnt += 1
if cnt >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <stdio.h>
 
int main(void)
{
    float x[4];
    float y[4];
    float num1, num2;
    int n, i;
    scanf("%d", &n);
 
    while (n > 0){
        n--;
        for (i = 0; i < 4; i++){
            scanf("%f %f", &x[i], &y[i]);
        }
         
        num1 = (y[1] - y[0]) / (x[1] - x[0]);
        num2 = (y[3] - y[2]) / (x[3] - x[2]);
         
        if (num1 == num2){
            printf("YES\n");
        }
        else {
            printf("NO\n");
        }
    }
 
    return 0;
}

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

using namespace std;

#define x first
#define y second
#define mp make_pair
#define pb push_back

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e9+5;

ll f[2000005];

ll pot(ll x, ll y) {
	if (y == 0) return 1;
	ll sol = pot(x, y/2);
	sol = sol*sol%MOD;
	if (y%2) sol = sol*x%MOD;
	return sol;
}

ll div_(ll x, ll y) {
	return x*pot(y, MOD-2)%MOD;
}

ll choose(ll x, ll y) {
	return div_(f[x], (f[y]*f[x-y])%MOD);
}

ll calc(ll r, ll c) {
	if (!r or !c) return 0;
	ll sol = 0;
	for (int i=0 ; i<r ; i++) {
		sol = (sol+choose(c+i, i+1)) % MOD;
	}
	return sol;
}

int main() {
	f[0] = 1;
	for (int i=1 ; i<2000005 ; i++) {
		f[i] = f[i-1]*i%MOD;
	}
	int r1, r2, c1, c2;
	cin >>r1>>c1>>r2>>c2;
	r1++;
	r2++;
	c1++;
	c2++;
	ll sol = calc(r2, c2);
	sol = (sol + MOD - calc(r2, c1-1)) % MOD;
	sol = (sol + MOD - calc(r1-1, c2)) % MOD;
	sol = (sol + calc(r1-1, c1-1)) % MOD;
	cout <<sol<<endl;
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int Alice;
  int Bob;
  cin>>N;
  vector<int> vec(N);
  Alice=0;
  Bob=0;
 
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  if (N%2==0) { 
    for (int i = 0; i < N/2; i++) {
      Alice+=vec.at(2*i);
      Bob+=vec.at(2*i+1);
    }
  }
  else {
     for (int i = 0; i < N/2; i++) {
      Bob+=vec.at(2*i+1);
     }
     for (int i = 0; i < N/2+1; i++) {
      Alice+=vec.at(2*i);
    }
  }
    cout << Alice-Bob <<endl;
}

Measured memory_bytes: 256
n, m, X = map(int, input().split())
A = [[] for i in range(n)]
c = [0] * n

for i in range(n):
    c_as = list(map(int, input().split()))
    c[i], A[i] = c_as[0], c_as[1:]

INF = 10**9
ans = INF
    
for s in range(0, 1<<n):
    smart = [0] * m
    cost_sum = 0
    for i in range(n):
        if (s>>i) % 2 == 0: 
            continue
        cost_sum += c[i]
        for j in range(m):
            smart[j] += A[i][j]
    ok = True
    for j in range(m):
        if smart[j] < X:
            ok = False
    if ok:
        ans = min(ans, cost_sum)

if ans == INF:
    ans = -1

print(ans)

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

typedef unsigned long long ull;
typedef long long ll;
typedef double db;

const ll mod  = 1e9+7;
const db eps  = 1e-9 ;
const ll maxn = 1e5+1;
const ll inf  = LLONG_MAX;
const ll minf = LLONG_MIN;

#define mp make_pair
#define pb push_back
#define endl "\n"
#define deb(x) cerr << #x << " " << x << endl

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

    ll a,b,c,k;
    cin >> a >> b >> c >> k;

    if(k <= a)
    {
        cout << k;
    }
    else if( k <= a+b )
    {
        cout << a;
    }
    else
    {
        cout << a - ( k-(a+b));
    }
    return 0;
} 

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0,buf1=0,buf2=0,buf3=0,buf4=0,sum=0;
  ll l,r;
  bool judge = true;
  ll n;cin>>n;
  string s;cin>>s;
  for(i=0;i<n;i++){
    if(s[i]=='I')buf++;
    else buf--;
    chmax(res,buf);
  }
  cout<<res<<endl;
  return 0;
}

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

using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n); i > 0; i--)
#define print(n) cout << n << endl

const ll mod = 1000000007;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    
    int n,k;
    cin >> n >> k;
    ll ans = 0;
    for(ll i=k;i<=n+1;i++){
        ans += (n - i + 1) * i + 1;
        ans %= mod;
    }
    print(ans);

    return 0;
}

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

int main() {
    
    string str1,str2;
    cin>>str1;
    cin>>str2;

    if(str2.substr(0,str2.size()-1) == str1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;

    return 0;                          
}


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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define ALL(v) (v).begin(), (v).end()
typedef pair<ll, ll> P;

int main(){
    int n, time = 0, at;
    cin >> n;
    vector<int> c(n), s(n), f(n);
    REP(i, n-1) cin >> c[i] >> s[i] >> f[i];

    REP(start, n) {
        at = start;
        time = 0;
        while(1) {
            if(at == n-1) {
                cout << time << endl;
                break;
            }
            if(time >= s[at] && time % f[at] == 0) {
                time += c[at];
                at++;
            } else if (time < s[at]) {
                time = s[at] + c[at];
                at++;
            } else {
                time = ((time / f[at]) + 1) * f[at] + c[at];
                at++;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

bool judge(char a[3][3], char c)
{
	if(a[0][0] == c && a[0][1] == c && a[0][2] == c ||
	   a[1][0] == c && a[1][1] == c && a[1][2] == c ||
	   a[2][0] == c && a[2][1] == c && a[2][2] == c ||
	   a[0][0] == c && a[1][0] == c && a[2][0] == c ||
	   a[0][1] == c && a[1][1] == c && a[2][1] == c ||
	   a[0][2] == c && a[1][2] == c && a[2][2] == c ||
	   a[0][0] == c && a[1][1] == c && a[2][2] == c ||
	   a[0][2] == c && a[1][1] == c && a[2][0] == c)
	{
		return(true);
	}
	else
	{
		return(false);
	}
}

void solve()
{
	char a[3][3];
	while(cin >> a[0][0], a[0][0] != '0')
	{
		cin >> a[0][1] >> a[0][2];
		for(int i = 1; i < 3; ++i)
		{
			for(int j = 0; j < 3; ++j)
			{
				cin >> a[i][j];
			}
		}
		if(judge(a, 'b'))
		{
			cout << "b" << endl;
		}
		else if(judge(a, 'w'))
		{
			cout << "w" << endl;
		}
		else
		{
			cout << "NA" << endl;
		}
	}
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <math.h>
#include <map>
#include <queue>
#include <string>
using namespace std;

int n[99][50],m[99][50];
string s[100];

int main(){
	int l=0;
	while(getline(cin,s[l]))l++;
	for(int i=0;i<l;i++){
		int pos=0,cur=0;
		while(pos<s[i].size()){
		if(isdigit(s[i][pos]))n[i][cur]=n[i][cur]*10+s[i][pos]-'0';
		else cur++;
		pos++;
		}
	}
	m[0][0]=n[0][0];
	for(int i=1;i<=l/2;i++){
		m[i][0]=m[i-1][0]+n[i][0];
		m[i][i]=m[i-1][i-1]+n[i][i];
		for(int j=1;j<i;j++)m[i][j]=max(m[i-1][j-1],m[i-1][j])+n[i][j];
	}
	for(int i=l/2+1;i<l;i++){
		for(int j=0;j<l-i;j++){
			m[i][j]=max(m[i-1][j],m[i-1][j+1])+n[i][j];
		}
	}
	cout<<m[l-1][0]<<endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
const int INF = 0x3f3f3f3f;

int main()
{
	int n, m[105];
	cin >> n;
	for(int i = 0; i < n; i++)
		cin >> m[i];
	for(int i = 0; i < n; i++)
	{
		for(int j = i; j > 0; j--)
		{
			if(m[j] < m[j-1])
			{
				int temp = m[j];
				m[j] = m[j-1];
				m[j-1] = temp;
			}
			else
				break;
		}
		cout<<m[0];
		for(int k = 1; k <n; k++)
			cout<<" "<<m[k];
		cout<<endl;
	}
}

Measured memory_bytes: 3100
def main():
    S = input()
    N = len(S)
    ok = set(['dream','erase','dreamer','eraser'])
    if N < 8 and S not in ok:
        print("NO")
        exit()
    i = 0
    while i < N-5:
        tmp = S[i:i+5]
        if tmp == 'dream':
            if i+6 < N and S[i+5:i+7] == 'er':
                if i+7<N and S[i+7] == 'a':
                    i += 5
                else:
                    i += 7
            else:
                i += 5
        elif tmp == 'erase':
            if i+5<N and S[i+5] == 'r':
                i += 6
            else:
                i += 5
        else:
            print('NO')
            exit()
    if i < N and S[i:] not in ok:
        print('NO')
        exit()
    print('YES')

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
Scanf.(Array.(scanf " %d %d" @@ fun n m ->
  let e = make n [] in
  let e_rev = make n [] in
  init (n-1+m) (fun i -> scanf " %d %d" @@ fun u v ->
    let u,v = u-1,v-1 in
    e.(u) <- v :: e.(u);
    e_rev.(v) <- u :: e_rev.(v)
  ) |> ignore;
  let root = fst @@ fold_left (fun (root,i) ls ->
    (if List.length ls = 0 then i else root),i+1
  ) (0,0) e_rev in
  let topological_sort root =
    let state = make n `Todo in
    let res = ref [] in
    let rec visit i = match state.(i) with
    | `Done -> true
    | `Temp -> false (* cycle detected *)
    | `Todo -> (
      state.(i) <- `Temp;
      let f =
        List.fold_left (fun u j ->
          u && visit j
        ) true e.(i)
      in
      state.(i) <- `Done;
      res := i :: !res; f
    ) in
    assert (visit root); !res
  in
  let tp = topological_sort root in
  let mx = make n 0 in
  let res = make n 0 in
  List.iter (fun v ->
    List.iter (fun w ->
      if mx.(w) < mx.(v) + 1 then (
        mx.(w) <- mx.(v) + 1;
        res.(w) <- v + 1
      )
    ) e.(v)
  ) tp;
  res.(root) <- 0;
  iter (Printf.printf "%d ") res
))

Measured memory_bytes: 25728
#include <stdio.h>
#include <stdlib.h>
int qsort_90(const int *sys1 , const int *sys2){ //大きいのが上にくるやつ
    /*mainに以下のコード入れるとソート実行
    qsort(data,how_data,sizeof(int),(int (*)(const void *,const void *))qsort_90);
    */
    
    if(*sys1<*sys2){
        return 1;
    }else if(*sys1==*sys2){
        return 0;
    }else{
        return -1;
    }
}

int main (void){
    int n;
    int loop1;
    scanf("%d",&n);
    int data[2*n];
    for(loop1=0;loop1<2*n;loop1++){
        scanf("%d",&data[loop1]);
    }
    qsort(data,2*n,sizeof(int),(int (*)(const void *,const void*))qsort_90);
    int total=0;
    for(loop1=1;loop1<2*n;loop1+=2){
        total+=data[loop1];
    }
    printf("%d\n",total);
    return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 10;
int n, k;

struct ST {
	int st[4 * N];

	ST() {
		memset(st, 0, sizeof st);
	}

	void update(int v, int tl, int tr, int idx, int val) {
		if (tl == idx && tl == tr) {
			st[v] = max(st[v], val);
			return;
		}
		int tm = (tl + tr) / 2;
		if (idx <= tm) {
			update(v * 2, tl, tm, idx, val);
		}
		else {
			update(v * 2 + 1, tm + 1, tr, idx, val);
		}
		st[v] = max(st[v * 2], st[v * 2 + 1]);
	}

	int query(int v, int tl, int tr, int l, int r) {
		if (l > r) {
			return 0;
		}
		if (tl == l && tr == r) {
			return st[v];
		}
		int tm = (tl + tr) / 2;
		int ql = query(v * 2, tl, tm, l, min(tm, r));
		int qr = query(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
		return max(ql, qr);
	}

	int mx() {
		return st[1];
	}
};

ST st;

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

	cin >> n >> k;

	int a;
	for (int i = 1; i <= n; i++) {
		cin >> a;

		int li = max(a - k, 0);
		int ri = min(a + k, N - 1);
		int best = st.query(1, 0, N - 1, li, ri) + 1;
		st.update(1, 0, N - 1, a, best);
	}

	cout << st.mx() << '\n';

	return 0;
}


Measured memory_bytes: 8360
# DP(配るDP)
N = int(input())
h = list(map(int, input().split()))

dp = [float('inf')] * N
dp[0] = 0
for i in range(N - 2):
    dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
    dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]))
i = N - 2
dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]))
print(dp[N - 1])


Measured memory_bytes: 13900
from collections import deque

N = int(input())
adj = [[] for _ in range(N)]
S = [None for _ in range(N)]

for i in range(N):
    S[i] = input()
    for j in range(N):
        if S[i][j] == '1':
            adj[i].append(j)

# 各頂点からBFSで距離を求める、同じ距離の頂点間の辺がなければ答えの候補
ans = -1

for i in range(N):
    queue = deque([i])
    visit = [-1] * N
    visit[i] = 1

    while queue:
        now = queue.popleft()
        for u in adj[now]:
            if visit[u] < 0:
                queue.append(u)
                visit[u] = visit[now] + 1
    #print(visit,max(visit),adj)
    dist = [[] for _ in range(max(visit))]
    for j in range(N):
        dist[visit[j]-1].append(j)

    flag = True
    for d in dist:
        if len(d) < 2: continue
        for k in d:
            for l in d:
                if k == l: continue
                if S[k][l] == '1':
                    flag = False
                    break

    if flag:
        ans = max(ans,max(visit))

print(ans)

Measured memory_bytes: 75012
#include<iostream>
#include<algorithm>
#include<vector>
#define INF 10000000000000000
using namespace std;
typedef long long ll;
ll dis(ll x,ll fi,ll se){
  return abs(x-fi)+abs(fi-se);
}
int main(){
  ll a,b,q,ti,si,tmp;
  cin >> a >> b >> q;
  vector<ll> s,t;
  ll x;
  s.push_back(-INF);
  t.push_back(-INF);
  for(ll i=0;i<a;i++){
    cin >> tmp;
    s.push_back(tmp);
  }
  for(ll i=0;i<b;i++){
    cin >> tmp;
    t.push_back(tmp);
  }
  s.push_back(INF);
  t.push_back(INF);
  for(ll i=0;i<q;i++){
    cin >> x;
    vector<ll> tv;
    si = distance(s.begin(),
        lower_bound(s.begin(),s.end(),x));
    ti = distance(t.begin(),
        lower_bound(t.begin(),t.end(),x));
    tv.push_back(dis(x,s[si],t[ti]));
    tv.push_back(dis(x,s[si-1],t[ti]));
    tv.push_back(dis(x,s[si],t[ti-1]));
    tv.push_back(dis(x,s[si-1],t[ti-1]));

    tv.push_back(dis(x,t[ti],s[si]));
    tv.push_back(dis(x,t[ti-1],s[si]));
    tv.push_back(dis(x,t[ti],s[si-1]));
    tv.push_back(dis(x,t[ti-1],s[si-1]));
    cout << *min_element(tv.begin(),tv.end())<<endl;
  }
}


Measured memory_bytes: 3060
from collections import defaultdict, deque
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys


def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


def main():
    n = I()
    num = LI()
    for i in range(n):
        for j in range(n):
            tmp = num[:]
            tmp[i], tmp[j] = tmp[j], tmp[i]
            if tmp == sorted(num):
                return 'YES'
    return 'NO'


print(main())

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

int main(int argc, char const *argv[])
{
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	if (abs(a-c)<=d||(abs(a-b)<=d&&abs(b-c)<=d))
	{
		cout<<"Yes\n";
	}
	else
	{
		cout<<"No\n";
	}
	return 0;
}


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

int main() {
   string a,b,c;
  int x,y;
  cin >>a>>b;
  cin>>x>>y;
    cin>>c;
  if (a==c)
    cout <<x-1<<" "<<y<<endl;
  if(b==c)
    cout<<x<<" "<<y-1<<endl ;
}


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

#define eb emplace_back
#define sz(s) (int)(s.size())
#define all(s) s.begin(), s.end()
#define ll long long

const int N = 1e6 + 9;
const int INF = 1e9 + 9;
const int NN = 2005;

int p[NN][NN], p2[NN][NN], p3[NN][NN];

char s[NN][NN];

void solve() {
	int n, m, q;
	cin >> n >> m >> q;
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= m; ++ j) {
			cin >> s[i][j];
		}
	}
	for (int i = 1; i <= n; ++ i) {
		for (int j = 1; j <= m; ++ j) {
			p[i][j] = p[i-1][j] + p[i][j-1] - p[i-1][j-1] + (s[i][j] - '0') * ('1' - s[i-1][j] + '0' - s[i][j-1]);
			p2[i][j] = p2[i][j-1] + (s[i][j] - '0') * (s[i-1][j] - '0');
			p3[i][j] = p3[i-1][j] + (s[i][j] - '0') * (s[i][j-1] - '0');
		}
	}
	while(q--) {
		int a, b, c, d;
		cin >> a >> b >> c >> d;
		cout << p[c][d] + p[a-1][b-1] - p[c][b-1] - p[a-1][d] + p2[a][d] - p2[a][b-1] + p3[c][b] - p3[a-1][b] << '\n';
	}
}

int main () {
	solve();
	return 0;
}

Measured memory_bytes: 52864
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N;
  cin >> N;
  int wrong = 0;
  F0R(i, N) {
    int p;
    cin >> p;
    if (p != i + 1) wrong++;
  }

  cout << (wrong == 0 || wrong == 2 ? "YES" : "NO");
}
#endif


Measured memory_bytes: 3576
import math
x = int(input())

def prime(x):
    if x==2:
        return 2
    if x==3:
        return 3
    if x%2==0:
        x+=1
    while True:
        boo=False
        for i in range(2,x):
            if x%i==0:
                boo = True
                break
        if boo==False:
            return x
        else:
            x+=2
        

print(prime(x))
            


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000007;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	string s; cin >> s;
	if (s == "SUN")
		cout << 7;
	if (s == "MON")
		cout << 6;
	if (s == "TUE")
		cout << 5;
	if (s == "WED")
		cout << 4;
	if (s == "THU")
		cout << 3;
	if (s == "FRI")
		cout << 2;
	if (s == "SAT")
		cout << 1;
}

Measured memory_bytes: 256
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=200*1000;
int a[L];
int b[L];
int s[L];
int main() {
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		scanf("%d",a+i);
	}
	for(int i=0;i<N;i++){
		scanf("%d",b+i);
	}
	int r=0;
	for(int p=0;p<29;p++){
		int u=1<<p;
		for(int i=0;i<N;i++){
			s[i]=a[i]%(2*u);
		}
		sort(s,s+N);
		int c=0;
		for(int i=0;i<N;i++){
			int v=b[i]%(2*u);
			int z=lower_bound(s,s+N,2*u-v)-lower_bound(s,s+N,u-v);
			int y=lower_bound(s,s+N,4*u-v)-lower_bound(s,s+N,3*u-v);
			/*
			if(p==3){
				cerr << v << ": " << z << ", " << y << endl;
			}
			*/
			c+=z+y;
			c%=2;
		}
		//cerr << u << ", " << c << endl;
		r+=c%2*u;
	}
	printf("%d\n",r);


	return 0;
}



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

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



    int a[210000];
    int main(){
        int n;
        std::cin >> n;
        std::vector<int> p(n);
        rep(i, n) std::cin >> p[i];
        int ans = 0;
        int curMin = 1e9;
        rep(i, n){
            curMin = min(curMin, p[i]);
            if(curMin == p[i]) ans++;
            
        }
        std::cout << ans << "\n";
        return 0;
    }


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define maxn 300020
#define rep(i,l,r) for(register int i = l ; i <= r ; i++)
#define repd(i,r,l) for(register int i = r ; i >= l ; i--)
#define rvc(i,S) for(register int i = 0 ; i < (int)S.size() ; i++)
#define rvcd(i,S) for(register int i = ((int)S.size()) - 1 ; i >= 0 ; i--)
#define fore(i,x)for (register int i = head[x] ; i ; i = e[i].next)
#define pb push_back
#define prev prev_
#define stack stack_
#define mp make_pair
#define fi first
#define se second
#define inf 0x3f3f3f3f
typedef long long ll;
typedef pair<int,int> pr;

int p[maxn],n,tag[maxn],go[maxn],id[maxn];

bool check(){
	memset(go,-1,sizeof(go));
	memset(tag,-1,sizeof(tag));
	rep(i,1,n){
		if ( id[i] == i ) go[i] = 0;
		else if ( i > id[i] ) go[i] = 1;
		else go[i] = 2;
	}
	repd(i,n,1){
		if ( !go[i] ) continue; 
		if ( abs(id[i] - i) & 1 ) return 0;
		if ( id[i] > i ){
			go[i] = 2;
			for (int j = id[i] ; j > i ; j -= 2){
				if ( tag[j] != -1 && tag[j] != 0 ) return 0;
				if ( go[j] == 0 ) return 0;
				if ( tag[j] != -1 ) break;
				tag[j] = 0;
				tag[j - 1] = 1;
			}
			if ( go[i] == 0 || tag[i] == 1 ) return 0;
		}
		else{
			go[i] = 1;
			for (int j = id[i] ; j < i ; j += 2){
				if ( tag[j] != -1 && tag[j] != 0 ) return 0;
				if ( go[j] == 0 ) return 0;
				if ( tag[j] != -1 ) break;
				tag[j] = 0;
				tag[j + 1] = 1;
			}
			if ( go[i] == 0 || tag[i] == 1 ) return 0;
		}
	}
	int last = 0;
	rep(i,1,n) if ( go[p[i]] == 1 ){
		if ( last > p[i] ) return 0;
		last = p[i];
	}
	last = 0;
	rep(i,1,n) if ( go[p[i]] == 2 ){
		if ( last > p[i] ) return 0;
		last = p[i];
	}
	return 1;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",&p[i]) , id[p[i]] = i;
	if ( check() ) printf("Yes\n");
	else printf("No\n");
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using V2 = V<V<T>>;
template<class T> using V3 = V<V2<T>>;

// auto mod int
// https://youtu.be/L8grWxBlIZ4?t=9858
// https://youtu.be/ERZuLAxZffQ?t=4807 : optimize
// https://youtu.be/8uowVvQ_-Mo?t=1329 : division
const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x(x%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, score;
  cin >> n >> score;
  V2<mint> dp(n+5, V<mint>(score/2 + 50, 0) );
  dp[0][0] = 1;
  rep(i,n) {
    V2<mint> dp_pre(n+5, V<mint>(score/2+1 + 50, 0) );
    swap(dp, dp_pre);
    rep(j,i+1)rep(k,score/2+1) {
      {
        int nj = j;
        dp[nj][k+nj] += dp_pre[j][k];
      }
      {
        int nj = j+1;
        dp[nj][k+nj] += dp_pre[j][k];
      }
      {
        int nj = j;
        mint x = j*2;
        dp[nj][k+nj] += dp_pre[j][k]*x;
      }
      if (j >= 1) {
        int nj = j-1;
        mint x = j*j;
        dp[nj][k+nj] += dp_pre[j][k]*x;
      }
    }
  }
  mint ans = dp[0][score/2];
  if (score&1) ans = 0;
  cout << ans.x << endl;
  return 0;
}

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

#define cc(x) cout << (x) << endl
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); ++i)
typedef long long ll;

template<typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

const ll inf = 1LL<<58;
const int iinf = 1<<30;

int main(){
    int n;
    cin >> n;
    int h[n];
    rep(i,n){
        cin >> h[i];
    }
    int tmp=1;
    int ok=0;
    repi(i,1,n){
        repi(j,0,i){
            if(h[i]<h[j]){
                ok=1;
            }   
        }
        if(ok==0){
            tmp++;
        }
        ok=0;
    }   
    cc(tmp);
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
int n;
LL a[200050],cnt;
bool vis;
int main(){
	scanf("%d",&n);
	cnt=0;
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	if(a[1]!=0){
		printf("-1\n");
		return 0;
	}
	for(int i=n;i>=2;i--){
		if(a[i]==0) continue;
		if(a[i]-a[i-1]>1){
			vis=1;
			break;
		}
		if(a[i]<=a[i-1]){
			if(a[i]==1) cnt++;
			else cnt+=a[i];
		}
		else if(a[i]==a[i-1]+1) cnt++;
	}
	if(vis==1) printf("-1\n");
	else printf("%lld\n",cnt);
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
int64_t N, K;

int64_t dfs(int n, int i)
{
  if (i == N)
    return n;
  i++;
  return min(dfs(n * 2, i), dfs(n + K, i));
}

int main()
{
  cin >> N >> K;
  cout << dfs(1, 0) << endl;
}

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

using namespace std;

int n, m, d;

int main() {
    scanf("%d %d %d", &n, &m, &d);
    if(d == 0) printf("%f\n", 1.0 * (m - 1) / n);
    else printf("%f\n", 2.0 * (m-1) * (n - d) / n / n);

    return 0;
}

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

struct Rect {
  int h, w, diagonal;
  void norm() {
    diagonal = h*h+w*w;
  }
  bool operator< (const Rect &r) const {
    return diagonal != r.diagonal ? diagonal < r.diagonal : h < r.h;
  }
  bool operator== (const Rect &r) const {
    return diagonal == r.diagonal && h == r.h;
  }
  bool operator<= (const Rect &r) const {
    return (diagonal == r.diagonal && h == r.h)
      || (diagonal != r.diagonal ? diagonal < r.diagonal : h < r.h);
  }
};

int main() {
  Rect r[150][150];

  for(int i=0; i<150; i++) {
    for(int j=0; j<150; j++) {
      r[i][j].h = i+1, r[i][j].w = j+1;
      r[i][j].norm();
    }
  }

  sort(r[0], r[0]+150*150);
  // cout << r[0][0].h << ' ' << r[0][1].w << endl;
  // cout << r[0][0].h << ' ' << r[0][1].w << endl;

  Rect rin;
  while(cin >> rin.h >> rin.w, rin.h+rin.w) {
    rin.norm();
    for(int i=0; i<150; i++) {
      for(int j=0; j<150; j++) {
	if(rin<r[i][j] && r[i][j].h < r[i][j].w) {
	  cout << r[i][j].h << ' ' << r[i][j].w << endl;
	  goto Fin;
	}
      }
    }
  Fin:;
  }
  
  return 0;
}

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

typedef long long ll;
const ll mod=1e9+7;
typedef pair<ll,ll> pii;

#define fi first
#define se second
#define mp make_pair

ll n;
string s;
int main() {
    cin>>n>>s;
    for(ll i=0;i<s.size();i++)
    {
    	s[i]=char(ll(s[i])+n);
    	if(s[i]>'Z')
    		s[i]=char('A'+s[i]-'Z'-1);
    }
    cout<<s;
}


Measured memory_bytes: 256
from collections import Counter

n, m = map(int, input().split())
a = list(map(int, input().split()))

c = Counter()
ans = 0

c[a[0] % m] += 1
if a[0] % m == 0:
	ans += 1

cnt = a[0] % m

for i in range(1, n):
	cnt = (cnt + a[i]) % m
	ans += c[cnt]
	c[cnt] += 1
	if cnt == 0:
		ans += 1

print(ans)

Measured memory_bytes: 14920
#include <bits/stdc++.h>
#define rep(i,n)    for(long long i = 0; i < (n) ; ++i)
#define orep(i,n)   for(long long i = 1; i <= (n); ++i)   // one rep
#define drep(i,n)   for(long long i = (n)-1; i >= 0; --i) // down rep
#define srep(i,s,t) for(long long i = (s); i < (t); ++i)  // set rep
#define rng(x)  (x).begin(),(x).end()

  // range
#define rrng(a) (a).rbegin(),(a).rend() // reverse range
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define ru(x,y) (((x)+(y)-1)/(y)) // round up
#define fi first
#define se second
#define eb emplace_back
#define fcout cout << fixed << setprecision(15)


using namespace std;
using ll  = long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vvi = vector<vi>;
using vp  = vector<P>;
using vl  = vector<ll>;

template<typename T> void Yes(T flag) {
  cout << (flag ? "Yes" : "No") << endl;
}

template<typename T> void pv(vector<T> vec) {
  cout << "[";
  for(auto& v : vec) { cout << v << ","; }
  cout << "]" << endl;
}

template<>
void pv(vector<P> vec) {
  cout << "[";
  for(auto& v : vec) {
    cout << "<" << v.fi << ","<< v.se << ">" << ",";
  }
  cout << "]" << endl;
}

template<typename T> void pv2(vector<vector<T>> vec) {
  for(auto& v : vec) pv(v);
}

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int r=0,w=0;
  rep(i,s.size()) {
    if(s.at(i)=='R')r++;
  }

  int ans = 0;
  rep(i,r) {
    if(s.at(i)=='W') ans++;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3688