akhauriyash/Code-Regression huggingface dataset:
inputted = list(map(int, input().split()))
N = inputted[0]
M = inputted[1]

LR = [list(map(int, input().split())) for i in range(M)]

left = 1
right = N
for LRi in LR:
    left = max(left, LRi[0])
    right = min(right, LRi[1])

    if left > right: break
    
answer = max(0, right - left + 1)
print(answer)


Measured memory_bytes: 27336
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n, k;
	cin>>n>>k;
	int long long a=n, b=0, c=0, d=0, e=0;
	for(int i=1;i<=n+1;i++){
		b+=a;
		e+=d;
		if(i>=k){
			c+=b-e+1;
		}
		a--;
		d++;
	}
	cout<<c%1000000007<<endl;
	return 0;
}

Measured memory_bytes: 3592
S=input()
T=input()

nS=len(S)
nT=len(T)

N=nS-nT+1
dfmin=1000
for i in range(N):
    df=0
    for j in range(nT):
        if S[i+j]!=T[j]:
            df+=1
    if df < dfmin:
        dfmin=df
print(dfmin)

Measured memory_bytes: 9052
/**
 * C - Takahashi's Information
 * https://atcoder.jp/contests/abc088/tasks/abc088_c
 * 
 * 解法
 * 計算量: 
 * a1+b1        a1+b2        a1+b3          => 3a1+b1+b2+b3
 * a2+b1        a2+b2        a2+b3          => 3a2+b1+b2+b3
 * a3+b1        a3+b2        a3+b3          => 3a3+b1+b2+b3
 * 3b1+a1+a2+a3 3b2+a1+a2+a3 3b3+a1+a2+a3   => a1+a2+a3+b1+b2+b3
 **/
#include<iostream>
#include<vector>

using namespace std;

int main() {
    vector<vector<int>> c(3, vector<int>(3, 0));
    for(int i=0; i<3; i++) {
        cin >> c[i][0] >> c[i][1] >> c[i][2];
    }

    int sum = 0;
    for(int i=0; i<3; ++i) {
        for(int j=0; j<3; ++j) {
            sum += c[i][j];
        }
    }
    if((float)(c[0][0]+c[1][1]+c[2][2]) != (float)sum/3) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int number=0;
  for (int i = 1;i < N+1; i++){
    int count = 0;
    int a = i;
    while(a != 0){
    	a /= 10;
    	count ++;
  	}
    if (count % 2 == 1){
      number++;
    }
  }
  cout << number << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
    cin.tie(0);
    int b;cin>>b;
    int a;cin>>a;
    string s;cin>>s;

    s[a-1] = s[a-1]+32;

    cout<<s<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <stack>
#include <list>
#include <deque>
using namespace std;
long long n, m, i, j, k, t, u, x=0, y=0, a[10010], b[10010], s1=0, s2=0;
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>a[i];
		s1+=a[i];
	}
	for(i=1;i<=n;i++){
		cin>>b[i];
		s2+=b[i];
	}
	t=s2-s1;
	if(t<0){
		cout<<"No";
		return 0;
	}
	u=0;
	for(i=1;i<=n;i++){
		x=b[i]-a[i];
		if(x<=0) y=-x;
		else{
			if(x%2==0) y=x/2;
			else y=(x+3)/2;
		}
		u+=y;
	}
	if(u<=t*2) cout<<"Yes";
	else cout<<"No";
	return 0;
}

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


int main(){
    int D, G, p[11], c[11];
    cin >> D >> G;
    for(int i = 0; i < D; ++i){
        cin >> p[i] >> c[i];
    }
 
    int ans = 1e9;
    for(int mask = 0; mask < (1 << D); ++mask){
        int s = 0, num = 0, rest_max = -1;
        for(int i = 0; i < D; ++i){
            if(mask >> i & 1){
                s += 100 * (i+1) * p[i] + c[i];
                num += p[i];
            }else{
                rest_max = i;
            }
        }
        if(s < G){
            int s1 = 100 * (rest_max + 1);
            int need = (G - s + s1 - 1) / s1;
            if(need >= p[rest_max]){
                continue;
            }
            num += need;
        }
        ans = min(ans, num);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
// global
static long fact[];
static long inverse[];
static int mod = 1_000_000_007;
static long pow(long a,int n) {
    long res=1;
    while (n>0) {
        if ((n-n/2*2)==1) {
            res=res*a%mod;
        }
        a=a*a%mod;
        n>>=1;
    }
    return res;
}

static long modinv(long n) {
    return pow(n, mod-2);
}

static long comb(int n,int k){
    if(n<0 || k<0 || n<k)return 0;
    return fact[n]*(inverse[k]*inverse[n-k]%mod) %mod;
}
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        // main method
        fact=new long[300000];
        fact[0]=1;
        inverse=new long[300000];
        inverse[0]=1;
        for(int i=1;i<300000;i++){
            fact[i]=(fact[i-1]*(long)i)%mod;
            inverse[i]=modinv(fact[i]);
        }
        int H = Integer.parseInt(sc.next())-1;
        int W = Integer.parseInt(sc.next())-1;
        int A = Integer.parseInt(sc.next());
        int B = Integer.parseInt(sc.next());
        long ans = 0L;
        for (int i=B;i<=W;i++) {
            ans = (ans+(comb(H-A+i, H-A)*comb(A-1+W-i, A-1)))%mod;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 26068
#include <iomanip>
#include <iostream>
using namespace std;
int main(void) {
  while(1) {
    char c;
    scanf("%c", &c);
    if('a' <= c && c <= 'z')
      c += 'A' - 'a';
    else if('A' <= c && c <= 'Z')
      c -= 'A' - 'a';
    cout << c;
    if(c == '\n')
      break;
  }

  return 0;
}



Measured memory_bytes: 3148
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);

  public void solve() {
    char[] x = in.next().toCharArray();
    int[] cnt = new int[2019];
    long result = 0;
    int rem = 0;
    cnt[rem]++;
    int[] ten = new int[x.length];
    ten[0] = 1;
    for (int i = 1; i < ten.length; i++) {
      ten[i] = ten[i - 1] * 10;
      ten[i] %= 2019;
    }
    for (int i = x.length - 1; i >= 0; i--) {
      int add = ten[x.length - i - 1] * (x[i] - '0');
      add %= 2019;
      rem = (rem + add) % 2019;
      result += cnt[rem];
      cnt[rem]++;
    }
    out.println(result);
  }

  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int ni() {
      return Integer.parseInt(next());
    }

    public long nl() {
      return Long.parseLong(next());
    }

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (Main instance = new Main()) {
      instance.solve();
    }
  }
}


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

const int INF = 1 << 29;
const int M_MAX = 100;
int m;
int ccs[M_MAX+1][M_MAX+1];
int tcs[M_MAX+1][M_MAX+1];

void floyd() {
    for (int k = 1; k <= m; k++) {
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= m; j++) {
                ccs[i][j] = min(ccs[i][j], ccs[i][k] + ccs[k][j]);
                tcs[i][j] = min(tcs[i][j], tcs[i][k] + tcs[k][j]);
            }
        }
    }
}

int main() {
    int n;
    while (cin >> n >> m, n|m) {
        for (int i = 1; i <= m; i++) {
            for (int j = 1; j <= m; j++) {
                ccs[i][j] = tcs[i][j] = (i == j) ? 0 : INF;
            }
        }
        for (int i = 0; i < n; i++) {
            int a, b, c, t;
            cin >> a >> b >> c >> t;
            ccs[a][b] = ccs[b][a] = c;
            tcs[a][b] = tcs[b][a] = t;
        }
        floyd();
        int k;
        cin >> k;
        for (int i = 0; i < k; i++) {
            int p, q, r;
            cin >> p >> q >> r;
            if (r == 0) {
                cout << ccs[p][q] << endl;
            } else {
                cout << tcs[p][q] << endl;
            }
        }
    }
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;
const lint mod = 1e9 + 7;

lint dp[2][55][2600];

int main(){
    int n, K;
    scanf("%d%d", &n, &K);
    rep(i, 2)rep(j, n+1)rep(k, n*n) dp[i][j][k] = 0;
    dp[0][0][0] = 1;
    rep(i, n){
        rep(j, n+1)rep(k, n*n)if(dp[0][j][k]){
            dp[1][j][k+2*j] = (dp[1][j][k+2*j] + dp[0][j][k]*(2*j+1) % mod) % mod;
            if(j) dp[1][j-1][k+2*j] = (dp[1][j-1][k+2*j] + dp[0][j][k]*j%mod*j%mod) % mod;
            dp[1][j+1][k+2*j] = (dp[1][j+1][k+2*j] + dp[0][j][k]) % mod;
        }
        rep(j, n+1)rep(k, n*n){
            dp[0][j][k] = dp[1][j][k];
            dp[1][j][k] = 0;
        }
    }
    printf("%lld\n", dp[0][0][K]);
}

Measured memory_bytes: 2304
#include <stdio.h>

int main(void){
	int a[5]={100001,100001,100001,100001,100001};
	int i,o,temp,p;
	scanf("%d",&a[4]);
	for(i=0;i<4;i++){
		scanf("%d",&a[0]);
		o=0;
		while(a[o] <a[o+1]){
			temp=a[o];
			a[o]=a[o+1];
			a[o+1]=temp;
			o++;
			if(o+1 == 5)
			       break;	
		}
	}
	for(i=0;i<5;i++){
		printf("%d",a[i]);
		if(i != 4)
			printf(" ");
	}
	printf("\n");
	return 0;
}

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

int main() {
	ll D,N;
	cin >> D >> N; 
	ll ans = N;
	// ちょうど100でD回割り切れる数を求める...ということは,Nが100のときは除外しなければならない...
	// 101にする.
	if (N == 100) {
		ans = 101;
	}
	for (ll i=0;i<D;++i) {
		ans *= 100;
 	}
	cout << ans << endl;	
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		boolean isAllPlus = true;
		boolean isAllMinus = true;
		for (int i = 0; i < n; i++) {
			arr[i] = sc.nextInt();
			if (arr[i] < 0) {
				isAllPlus = false;
			}
			if (arr[i] > 0) {
				isAllMinus = false;
			}
		}
		int count = 0;
		StringBuilder sb = new StringBuilder();
		if (isAllPlus) {
			for (int i = 0; i < n - 1; i++) {
				if (arr[i] > arr[i + 1]) {
					sb.append(i + 1 + " " + (i + 2) + "\n");
					arr[i + 1] += arr[i];
					count++;
				}
			}
			System.out.println(count);
			System.out.println(sb.toString());
			return;
		}
		if (isAllMinus) {
			for (int i = n - 1; i > 0; i--) {
				if (arr[i] < arr[i - 1]) {
					arr[i - 1] += arr[i];
					sb.append(i + 1 + " " + (i) + "\n");
					count++;
				}
			}
			System.out.println(count);
			System.out.println(sb.toString());
			return;
		}
		int maxIndex = 0;
		int maxAbs = 0;
		for (int i = 0; i < n; i++) {
			if (Math.abs(arr[i]) > maxAbs) {
				maxIndex = i;
				maxAbs = Math.abs(arr[i]);
			}
		}
		if (arr[maxIndex] > 0) {
			for (int i = 0; i < n; i++) {
				if (arr[i] < 0) {
					arr[i] += arr[maxIndex];
					sb.append(maxIndex + 1 + " " + (i + 1) + "\n");
					count++;
				}
			}
			for (int i = 0; i < n - 1; i++) {
				if (arr[i] > arr[i + 1]) {
					arr[i + 1] += arr[i];
					sb.append(i + 1 + " " + (i + 2) + "\n");
					count++;
				}
			}
			System.out.println(count);
			System.out.println(sb.toString());
			return;

		} else {
			for (int i = 0; i < n; i++) {
				if (arr[i] > 0) {
					arr[i] += arr[maxIndex];
					sb.append(maxIndex + 1 + " " + (i + 1) + "\n");
					count++;
				}
			}
			for (int i = n - 1; i > 0; i--) {
				if (arr[i] < arr[i - 1]) {
					arr[i - 1] += arr[i];
					sb.append(i + 1 + " " + (i) + "\n");
					count++;
				}
			}
			System.out.println(count);
			System.out.println(sb.toString());
			return;
		}
	}
}

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N;
  string S;
  cin>>N>>S;
  
  vector<bool> isstart(2*N,false);
  
  LL cnt = 0;
  
  REP(i,2*N){
    if(S[i]=='B'){
      //odd
      if(cnt%2==0){
        cnt++;
        isstart[i]=true;
      }else{
        cnt--;
        isstart[i]=false;
      }
    }else{
      //even
      if(cnt%2==0){
        cnt--;
        isstart[i]=false;
      }else{
        isstart[i]=true;
        cnt++;
      }
    }
  }
  
  if(cnt!=0){
    cout<<0<<endl;
    return 0;
  }
  
  LL ans = 1;
  FOR(i,1,N+1){
    ans *= i;
    ans %= mod;
  }
  
  LL starts = 0;
  
  REP(i,2*N){
    if(isstart[i]){
      starts++;
    }else{
      ans *= starts;
      ans %=mod;
      starts --;
    }
    if(starts<0){
      cout<<0<<endl;
      return 0;
    }
  }
  
  cout<<ans<<endl;
}
// BWBBWWWB
// s--g sg
//  s-----g
//   s-g

// sssggsgg

// 3*2*2*1*4*3*2*1


Measured memory_bytes: 720
//abc136_d.cpp
//Sun Aug  4 21:32:13 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;

	int ans[s.size()];
	fill(ans,ans+s.size(),0);
	for (int i=0;i<s.size()-1;i++){
		if (s[i]=='R'&&s[i+1]=='L'){
			ans[i]++;
			ans[i+1]++;
			for (int j=i-1;j>=0;j--){
				if (s[j]=='R'){
					if ((i-j)%2==1){
						ans[i+1]++;
					}else{
						ans[i]++;
					}
				}else{
					break;
				}
			}
			for (int j=i+2;j<s.size();j++){
				if (s[j]=='L'){
					if ((j-i-1)%2==1){
						ans[i]++;
					}else{
						ans[i+1]++;
					}
				}else {
					i=j-1;
					break;
				}
			}
		}
	}

	for (int i=0;i<s.size();i++){
		cout << ans[i] << " ";
	}
	printf("\n");
//	printf("%.4f\n",ans);
}

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

int main() {
    int n;
    cin >> n;
    map<string, int> mp;
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
    return 0;
}

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

ll x;

int main()
{
    scanf("%lld",&x);
    for(ll i=-120;i<=120;i++)
        for(ll j=-120;j<=120;j++)
        {
            ll a=i*i*i*i*i;
            ll b=j*j*j*j*j;
            if(a-b==x)
            {
                printf("%lld %lld",i,j);
                return 0;
            }
        }
    return 0;
}


Measured memory_bytes: 3844
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll T,N;
#define p(i,n,vect) for(ll i=0;i<(ll)n;++i) {cout<<vect[i]<<" ";} cout<<"\n";
void solve()
{
 
   ll D,T,S;
    cin>>D>>T>>S;
   if(D<=(T*S))
   cout<<"Yes\n";
   else
   {
       cout<<"No\n";
   }
}
signed main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
   
     
    solve();
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define let auto const

int main() {
  i64 N;
  cin >> N;
  string s;
  cin >> s;
  vector<i64> A(2 * N);
  vector<i64> B(2 * N);
  i64 now = 0;
  i64 ans = 1;
  i64 mod = 1e9 + 7;
  i64 cnt = N;
  rep(i,0,2 * N) {
    if(s[i] == 'W') A[i] = 1;
    else A[i] = 0;
    if(((now ^ A[i]) & 1) == 0) {
      B[i] = 1;
      now++;
    }
    else {
      B[i] = 0;
      ans = (ans * now % mod) * cnt % mod;
      now--;
      cnt--;
    }
    if(now < 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  if(now > 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
 
int main() {
    string s;
    cin >> s;
    for(int i=0;i<s.size();i+=2){
        cout << s.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 512
//参考：http://ehafib.hatenablog.com/entry/2015/12/23/164517
//インクルード
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

int main(int argc, char const *argv[]) {
  std::string str;
  bool flag = true;
  std::cin >> str;

  if (str == "AAA" || str == "BBB") {
    flag = false;
  }

  if (flag) {
    std::cout << "Yes" << '\n';
  } else {
    std::cout << "No" << '\n';
  }
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn = 100005;
const int mod = 1e9 + 7;
int n,k,a[maxn],ans,h[maxn];
vector<int> son[maxn];
void dfs(int x) {
    h[x] = 0;
    for (int i=0; i<son[x].size(); i++) {
        dfs(son[x][i]);
        h[x] = max(h[x], h[son[x][i]] + 1);
    }
    if (a[x] != 1 && h[x] == k-1) {
        ans++;
        h[x] = -1;
    }
}
int main() {
    cin>>n>>k;
    cin>>a[1];
    for (int i=2; i<=n; i++) {
        cin>>a[i];
        son[a[i]].push_back(i);
    }
    if (a[1] != 1) {
        ans++;
        a[1] = 1;
    }
    dfs(1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11136
#include<stdio.h>

int main()
{
    int S;
    int h,m,s;
    scanf("%d",&S);
    h = S/3600;
    m = (S-(h*3600))/60;
    s = S-(m*60)-((h*3600));
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}



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

const ll MAX = 200000;
const ll INF = 1001001001001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, K, ans=0, tmp=0, d=0;
vector<ll> A, P, S, ct;

signed main(){
    cin >> N >> K;
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        a--;
        P.push_back(a);
    }
    for(int i=0;i<N;i++) {
        ll a;
        cin >> a;
        A.push_back(a);
    }
    vector<ll> color(N,-1), Q(N,-INF), Q2(N, -INF);
    for(int i=0;i<N;i++) {
        tmp = i;
        ll num=0;
        ll now=0;
        while(color[tmp]==-1) {
            color[tmp] = d;
            now++;
            tmp = P[tmp];
            num += A[tmp];
            if(tmp==i) {
                S.push_back(num);
                ct.push_back(now);
                d++;
            }
        }
    }
    for(int i=0;i<N;i++) {
        ans = 0;
        tmp = i;
        ll cos = K%ct[color[i]];
        if(cos<0) cos += ct[color[i]];
        for(int j=0;j<cos;j++) {
            tmp = P[tmp];
            ans += A[tmp];
            if(ans>Q[color[i]]) Q[color[i]] = ans;
        }
        ans = 0;
        tmp = i;
        for(int j=0;j<ct[color[i]];j++) {
            tmp = P[tmp];
            ans += A[tmp];
            if(ans>Q2[color[i]]) Q2[color[i]] = ans;
        }
    }
    ans = -INF;
    for(int i=0;i<d;i++) {
        tmp = Q[i];
        ll rt = K/ct[i];
        if(S[i]>0) {
            tmp += rt*S[i];
        }
        ans = max(ans, tmp);
        if(rt>0) {
            rt--;
            tmp = Q2[i];
            if(S[i]>0) tmp += rt*S[i];
            ans = max(ans, tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3752
import heapq
import sys

def main():

    n,m,s = map(int,input().split())
    uvab = [list(map(int,input().split())) for _ in range(m)]
    cd = [list(map(int,input().split())) for _ in range(n)]

    edges = [[[] for _ in range(n)] for _ in range(2501)]

    for u,v,a,b in uvab:
        for i in range(a,2501):
            edges[i][u-1].append(((v-1, i-a), b))
            edges[i][v-1].append(((u-1, i-a), b))

    for i in range(n):
        c,d = cd[i]
        for j in range(2501):
            edges[j][i].append(((i, min(j+c, 2500)), d))

    def dijkstra(edges, c):
        hq = []
        d = [[10**20] * n for _ in range(c)]
        d[min(2500, s)][0] = 0
        heapq.heappush(hq, (0, (0, min(2500, s))))
        while hq:
            d1, p = heapq.heappop(hq)
            for p2, d2 in edges[p[1]][p[0]]:
                if d[p2[1]][p2[0]] == -1 or d[p2[1]][p2[0]] > d1 + d2:
                    d[p2[1]][p2[0]] = d1 + d2
                    heapq.heappush(hq, (d1+d2, p2))
        return d

    dis = dijkstra(edges, 2501)
    ans = [10**20]*n
    for i in range(2501):
        for j in range(n):
            ans[j] = min(ans[j], dis[i][j])

    for i in ans[1:]:
        print(i)

if __name__ == '__main__':
    main()


Measured memory_bytes: 133200
import math
N = int(input())
x, y = [], []
for i in range(N):
  tmp = list(map(int, input().split()))
  x.append(tmp[0])
  y.append(tmp[1])
  
num = 1
for i in range(N, 0, -1):
  num *= i
total1 = num*(N-1)
total2 = N*(N-1)/2
b = total1/total2

avg = 0
for i in range(0,N-1,1):
  for j in range(i+1,N,1):
    avg += math.sqrt((x[i]-x[j])**2+(y[i]-y[j])**2)*b
avg /= num
print(avg)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

#define LET(name, value) __typeof(value) name = value
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define FOREQ(i, a, b) for (int i = (a); i <= (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOREACH(i, c) for (LET(i, (c).begin()); i != (c).end(); ++i)

int c[30];
int deps[30];

inline unsigned next_set(unsigned x)
{
  unsigned smallest = x & -x;
  unsigned ripple = x + smallest;
  unsigned new_smallest = ripple & -ripple;
  unsigned ones = ((new_smallest / smallest) >> 1) - 1;
  return ripple | ones;
}

inline int bsf(int x)
{
  __asm__("bsf %1, %0;" :"=r"(x) :"r"(x));
  return x;
}

int main() {
  int n, U;
  while (scanf("%d%d", &n, &U), n|U) {
    memset(deps, 0, sizeof(deps));
    REP(i, n) {
      int k; scanf("%d%d", &c[i], &k);
      REP(j, k) {
        int r; scanf("%d", &r);
        deps[i] |= 1 << r;
      }
    }
    FOREQ(bits, 1, n) {
      for (int S = (1<<bits)-1; S < (1<<n); S = next_set(S)) {
        int sum = 0;
        bool ok = true;
        for (int T = S; T; T &= T-1) {
          int i = bsf(T);
          sum += c[i];
          if ((S | deps[i]) != S) {
            ok = false;
            break;
          }
        }
        if (sum >= U && ok) {
          printf("%d\n", bits);
          goto next;
        }
      }
    }
next:;
  }
}

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

const ll maxn=1e3+5, mod=1e9+7; 
ll n,m,dp[maxn][maxn];
string a[maxn];

int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    
    cin>>n>>m;
    rep(i,0,n) cin>>a[i];
    dp[0][0]=1;
    rep(i,1,m) dp[0][i]=a[0][i]=='.'?dp[0][i-1]:0;
    rep(i,1,n) dp[i][0]=a[i][0]=='.'?dp[i-1][0]:0;
    rep(i,1,n) rep(j,1,m) dp[i][j]=a[i][j]=='.'?(dp[i-1][j]+dp[i][j-1])%mod:0;
    cout<<dp[n-1][m-1]<<"\n";
}

Measured memory_bytes: 9216
#include<cstdio>
#include<cmath>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
typedef long long LL;
#define int LL
const int mo=1e9+7;
typedef pair<int,int> pii;
#define gc() getchar()
template<typename _T>
void read(_T &x){
	_T f=1;x=0;char s=gc();
	while(s>'9'||s<'0'){if(s=='-')f=-1;s=gc();}
	while(s>='0'&&s<='9'){x=(x<<3)+(x<<1)+(s^48);s=gc();}
	x*=f;
}
template<typename _T>
_T Fabs(_T x){return x<0?-x:x;}
int a,b,n;
signed main(){
	read(a);read(b);read(n);
	printf("%lld\n",min(n,b-1)*a/b-a*(min(n,b-1)/b));
	return 0;
}

Measured memory_bytes: 3696
n=int(input())
a=list(map(int,input().split()))
for i in range(1,n+1):
    a[i-1]-=i
a.sort()
if n%2==1:
    ans=0
    b=a[n//2]
    for i in a:
        ans+=abs(i-b)
    print(ans)
else:
    ans1,ans2=0,0
    b1=a[n//2-1]
    b2=a[n//2]
    for i in a:
        ans1+=abs(i-b1)
        ans2+=abs(i-b2)
    print(min(ans1,ans2))

Measured memory_bytes: 26180
#include <stdio.h>
#include <math.h>

int main(int argc, char *argv[])
{
    int n;
    int a[100];

    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d", &a[i]);
    }
    for (int i = 0; i < n; i++) {
        printf("%s%d", i == 0 ? "" : " ", a[n - i - 1]);
    }
    printf("\n");

    return 0;
}


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

public class Main {
    public static final int numMax = 300000;

    private static int[] primes = new int[10000];

    public static void main(String[] argv) throws IOException {
        boolean[] primeFlag = new boolean[numMax];
        Arrays.fill(primeFlag, true);
        int primesIndex = 0;
        for (int i = 2; i < numMax; i++) {
            if (primeFlag[i]) {
                primes[primesIndex++] = i;
                if (primesIndex >= 10000) {
                    break;
                }
                for (int j = i + i; j < numMax; j += i) {
                    primeFlag[j] = false;
                }
            }
        }
        //*
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String s = in.readLine();
            if (s == null || s.equals("0")) {
                break;
            }
            f(s);
        }
        //*/
    }

    public static void f(String s) {
        int sum = 0;
        int loop = Integer.parseInt(s);
        for (int i = 0; i < loop; i++) {
            sum += primes[i];
        }
        System.out.println(sum);
    }
}

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

int main() {
  int a,b,c,d;
  cin >> a>>b>>c>>d;
  if (a+b>c+d) {cout <<"Left" << endl;}
  else if (a+b==c+d) {cout << "Balanced" << endl;}
  else {cout << "Right"<<endl;}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
typedef long long ll;
#define vint vector<int>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000

int main(){
  int n;
  cin >> n;
  string ans = "";
  while(n != 0){
    if(n % 2 == 0){
      ans = "0" + ans;
    }
    else{
      n--;
      ans = "1" + ans; 
    }
    n /= -2;
  }
  if(ans == "") cout << 0 << endl;
  else cout << ans << endl;
}



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

int main(){
  string s;
  cin >> s;
  string ans = "AC";
  
  if(s.at(0) != 'A'){
    ans = "WA";
  }
  int count = 0;
  for(int i = 1; i < s.size(); i++){
    if(isupper(s.at(i))){
      if(i == 1 || i == s.size() - 1 || s.at(i) != 'C'){
        ans = "WA";
      }
      count++;
    }
  }
  if(count != 1){
    ans = "WA";
  }
  cout << ans << endl;
}


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

using namespace std;

int n, m;
char n1[10], n2[10];


int main()
{ /**
    #ifndef ONLINE_JUDGE

        ifstream cin("test.in");

    #endif // ONLINE_JUDGE
*/
    cin>>n >> m;



    for(int i = 0; i < n; i++)
        n1[i] = m + '0';

    for(int i = 0; i < m; i++)
        n2[i] = n + '0';

    if(strcmp(n1, n2) < 0)
        cout << n1 << "\n";
    else
        cout << n2 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main()
{
	char N[5];
	scanf("%s", N);
	if (N[1] != N[2]) printf("No\n");
	else if (N[0] != N[1] && N[2] != N[3]) printf("No\n");
	else printf("Yes\n");
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
REP(i,v.size()){if(i)os<<" ";os<<v[i];}return os;}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
REP(i,v.size()){if(i)os<<endl;os<<v[i];}return os;}

int main() {
            ll a;cin>>a;
            set<string>s;
            rep(i,a){
                     string b;cin>>b;
                     if(b=="insert"){
                                     string c;cin>>c;
                                     s.insert(c);
                                     }
                     else{
                          string d;cin>>d;
                          if(s.count(d)==1){
                                         cout<<"yes"<<endl;
                                         }
                          else{
                               cout<<"no"<<endl;
                               }
                           }
                      }
                     
                     
}




Measured memory_bytes: 32196
#include<cstdio>
int a,b,ans;
int main()
{
	scanf("%d%d",&a,&b);
	if(a==1)ans+=3;
	else if(a==2)ans+=2;
	else if(a==3)ans++;
	if(b==1)ans+=3;
	else if(b==2)ans+=2;
	else if(b==3)ans++;
	if(ans==6)ans+=4;
	ans*=100000;
	printf("%d",ans);
	return 0;
}

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

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define int long long


class AChristmasEveEveEve {
public:
    void solve(std::istream &in, std::ostream &out) {
      int d;
      in >> d;
      switch (d) {
        case 25:
          out << "Christmas" << endl;
          break;
        case 24:
          out << "Christmas Eve" << endl;
          break;
        case 23:
          out << "Christmas Eve Eve" << endl;
          break;
        case 22:
          out << "Christmas Eve Eve Eve" << endl;
          break;
      }
    }
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
  AChristmasEveEveEve solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  solver.solve(in, out);
  return 0;
}


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

#define ll long long
#define mod 1000000007

int cache[100010] = {0};

ll fibo(int n){
    if (n == 1 || n == 2) return 1;

    if (cache[n]) return cache[n];

    cache[n] = (fibo(n-1) %mod + fibo(n-2) %mod)%mod;

    return cache[n];
}

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

    int n, m;
    cin >> n >> m;

    int a[m+1];
    if (m!= 0)
        cin >> a[1];

    for (int i = 2; i <= m; i++){
        int x;
        cin >> x;
        if ((x - a[i-1]) == 1){
            cout << 0 << endl;
            return 0;
        }
        a[i] = x;
    }

    int prefix[m+2];
    if (m != 0)
        prefix[1] = a[1] - 1;
    else 
        prefix[1] = n;

    for (int i = 2; i <= m; i++){
        prefix[i] = a[i] - a[i-1] - 2;
    }

    if (m != 0)
        prefix[m+1] = n - a[m] - 1;

    ll count = fibo(prefix[1]+1) % mod;
    for (int i = 2; i <= m+1; i++){
        count = ((count%mod) * (fibo(prefix[i]+1) %mod))%mod;
    }

    cout << count << endl;

    return 0;
}




Measured memory_bytes: 3712
import bisect
from collections import deque
n=int(input())
A=list(map(int,input().split()))
S=[A[0]]
for i in range(n-1):
  S.append(S[-1]+A[i+1])
ans=10**15
A1=deque([A[0]])
A2=deque(A[1:n])
for i in range(2,n-1):
  A1.append(A[i-1])
  A2.popleft()
  if len(A1)==2:
    M1=max(A1)
    m1=min(A1)
  else:
    x=bisect.bisect_left(S,S[i-1]//2,lo=0,hi=i+1)
    M11=max(S[x-1],S[i-1]-S[x-1])
    m11=min(S[x-1],S[i-1]-S[x-1])
    M12=max(S[x],S[i-1]-S[x])
    m12=min(S[x],S[i-1]-S[x])
    M1=min(M11,M12)
    m1=max(m11,m12)
  if len(A2)==2:
    M2=max(A2)
    m2=min(A2)
  else:
    x=bisect.bisect_left(S,S[i-1]+(S[-1]-S[i-1])//2,lo=0,hi=n)
    M21=max(S[x-1]-S[i-1],S[-1]-S[x-1])
    m21=min(S[x-1]-S[i-1],S[-1]-S[x-1])
    M22=max(S[x]-S[i-1],S[-1]-S[x])
    m22=min(S[x]-S[i-1],S[-1]-S[x])
    M2=min(M21,M22)
    m2=max(m21,m22)
  a=max(M1,M2)-min(m1,m2)
  if a<ans:
    ans=a
print(ans)

Measured memory_bytes: 25928
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

typedef tuple<int, int, int> rec;

int main()
{
	cin.sync_with_stdio(false);
	int h, w;
	vector<rec> v;
	FOR(i, 1, 151)FOR(j, 1, i)
	{
		v.emplace_back(i*i+j*j, j, i);
	}
	sort(ALL(v));
	while (cin >> h >> w, h)
	{
		REP(i, v.size())
		{
			rec tmp = make_tuple(h*h + w*w, h, w);
			if (v[i] == tmp)
			{
				cout << get<1>(v[i + 1]) << " " << get<2>(v[i + 1]) << endl;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3220
function main(input) {
    var X = input[0].split(" ")[0]-0;
    var Y = input[0].split(" ")[1]-0;
    var ans = 0;
    if(X==1 && Y==1) ans += 400000;
    if(X<=3) ans += (4-X)*100000;
    if(Y<=3) ans += (4-Y)*100000;
    console.log(ans);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
#include <iostream>
#include <algorithm>
#include <cmath>
#define MAX 1000000007
using namespace std;

long long int fct(int n)
{
	if(n==1)	return 1;
	return (n*fct(n-1))%MAX;
}

int main() 
{
	int n,m;
	
	cin>>n>>m;
	
	if(abs(n-m)>1)
	{
		cout<<0<<endl;
		return 0;
	}
	
	if(abs(n-m)==1)
	{
		cout<<(fct(n)*fct(m))%MAX<<endl;
		return 0;
	}
	
	cout<<(2*fct(n)*fct(m))%MAX<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++) 
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
typedef vector<int> vi;
typedef pair<int, int> pii;



int main() {


	string s,t="";
	cin >> s;

	rep(i, s.size()) t+="x";

	cout << t << endl;

}

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

int main() {
  vector<vector<int>> a(3,vector<int>(3));
  rep(i,3)rep(j,3)cin>>a[i][j];
  int n;cin>>n;
  rep(i,n){
    int b;cin>>b;
    rep(j,3)rep(k,3){
      if(b==a[j][k])a[j][k]=0;
    }
  }
  bool ans=false;
  rep(i,3){
    if(a[i][0]==0&&a[i][1]==0&&a[i][2]==0)ans=true;
  }
  rep(i,3){
    if(a[0][i]==0&&a[1][i]==0&&a[2][i]==0)ans=true;
  }
  if(a[0][0]==0&&a[1][1]==0&&a[2][2]==0)ans=true;
  if(a[0][2]==0&&a[1][1]==0&&a[2][0]==0)ans=true;
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


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

const int Max=100005;
int n,ans;
char ch[Max],pre;

int main()
{
	scanf("%s",ch+1);
	n=strlen(ch+1);
	for(int i=2;i<=n;i++)
	  if(ch[i]!=ch[i-1]) ans++;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
q, h, s, d = map(int, input().split())
n = int(input())
h = min(q*2, h)
s = min(h*2, s)
d = min(s*2, d)
if n % 2 == 0:
  print(min(s*n, d*(n//2)))
else:
  print(min(s*n, d*(n//2)+s))

Measured memory_bytes: 3060
import numpy as np
import sys
N = int(input())
A = np.zeros(N, dtype=np.int64)
B = np.zeros(N, dtype=np.int64)
for i in range(N):
    A[i], B[i] = map(int,input().split())
if all(A == B):
    print(0)
    sys.exit()
ans = A.sum() - B[A > B].min()
print(ans)

Measured memory_bytes: 27484
#include <iostream>
#include <bits/stdc++.h>
#define ll long long

using namespace std;
const ll Mod = 1e9 + 7;
map < ll, int > mp;
ll a[100100],n;

void Add(ll x)
{

    map < ll, int > temp;
    for(ll i = 2 ; i * i <= x; i++)
    {
        if(x % i == 0)
        {
            temp[i]++;
            x/=i;
            i--;
        }
    }
    if(x != 1)  temp[x]++;
    for(auto it : temp)   mp[it.first] = max(mp[it.first], it.second);
}

long long fastpower(long long a,long long b)
{
    if(b==0)
        return 1;
    if(b==1)
        return a;
    long long res = fastpower(a,b/2)%Mod;
    res = (res %Mod  * res % Mod )%Mod;
    if(b%2!=0)
        res*=a;
    return res % Mod;
}

vector < int > v[1000100];
ll Ans = 0;

ll Solve(ll x)
{
    map < ll, int > temp;
    for(ll i = 2 ; i * i <= x; i++)
    {
        if(x % i == 0)
        {
            temp[i]++;
            x/=i;
            i--;
        }
    }
    if(x != 1)  temp[x]++;
    ll Res = 1;
    for(auto it : temp)  Res*=fastpower(it.first , it.second) , Res%=Mod;
    return Res;
}

int main()
{
    int n;
    cin >> n;
    for(int i = 0; i<n; i++)   cin >> a[i], Add(a[i]);
    ll x = 1;
    for(auto it : mp)  x*=fastpower(it.first , it.second) , x%=Mod;
    for(int i = 0;i<n;i++)  Ans+=x * fastpower(Solve(a[i]) , Mod - 2) , Ans%=Mod;
    cout << Ans;
    return 0;
}


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

#define ll long long

inline ll read() {
    ll x = 0, f = 1; char ch = getchar();
    for(; ch < '0' || ch>'9'; ch = getchar())
        if(ch == '-') f = -f;
    for(; ch >= '0' && ch <= '9'; ch = getchar())
        x = x * 10 + ch - '0';
    return x * f;
}

inline void chkmin( int &a, int b ) { if(a > b) a = b; }

inline void chkmax( int &a, int b ) { if(a < b) a = b; }

#define _ read()

#define ln endl

int main()
{
	int a = _, b = _;
	cout << (a <= 9 && b <= 9 ? a * b : -1) << ln;
}

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

#define  range(i, l, r) for (int i = (int)(l); i < (int)(r); ++(i))
#define rrange(i, l, r) for (int i = (int)(r) - 1; i >= (int)(l); --(i))

#define  whole(f, x, ...) ([&](decltype((x)) container) { return (f)(  begin(container),  end(container), ## __VA_ARGS__); })(x)
#define rwhole(f, x, ...) ([&](decltype((x)) container) { return (f)( rbegin(container), rend(container), ## __VA_ARGS__); })(x)

#define debug(x) cerr << "(" << __LINE__ << ")" << #x << ": " << (x) << endl

using int32 = int;
using int64 = long long;

const int   mod   = 1e9 + 7;
const int32 inf   = 1001001001;
const int64 infll = 1001001001001001001ll;

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

struct IoSetup { IoSetup(){ cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); cerr << fixed << setprecision(10); } } iosetup;

template <typename T = int64> T input() { T x; cin >> x; return x; }

template <typename T> ostream &operator<<(ostream &os, vector<T> &v) { range(i, 0, v.size()) { os << v[i] << (i + 1 != v.size() ? " " : ""); } return os; } 
template <typename T> istream &operator>>(istream &is, vector<T> &v) { for (T &in : v) is >> in; return is; }
template <typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream &operator>>(istream &is, pair<T1, T2> &p) { is >> p.first >> p.second; return is; }

template <typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template <typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }

template <typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template <typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void solver() {
  int D = input(), G = input() / 100;
  vector< int > p(D), c(D);
  range(i, 0, D) {
      p[i] = input();
      c[i] = input() / 100;
  }

  vector< int > dp(G + 1, inf);
  dp[0] = 0;
  
  range(i, 0, D) {
      auto dpc = dp;
      rrange(j, 1, p[i] + 1) {
          int score = (i + 1) * j;
          if (j == p[i]) score += c[i];

          rrange(k, 0, dp.size()) {
              chmin(dp[min(k + score, (int)dp.size() - 1)], dpc[k] + j);
          }
      }
  }

  cout << dp.back() << endl;
}

signed main(int argc, char *argv[]) {
  solver();
}

Measured memory_bytes: 1120
#include<stdio.h>

int main(){
	int i, a, b = 0;
	for (i = 0; i < 5; i++){
		scanf("%d", &a);
		if (a < 40) a = 40;
		b += a;
	}
	printf("%d\n", b / 5);
	return 0;
}

Measured memory_bytes: 600
#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 "functional"

using namespace std;

//constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;

int Search(const vector<vector<int>>&edge, vector<int>&num, int node=0) {
	int sz = 0;
	for (int i = 0; i < 27; i++) {
		if (edge[node][i] != -1)num[node] += Search(edge, num, edge[node][i]);
	}
	num[node] = max(num[node], 1);
	return num[node];
}

void Search(const vector<vector<int>>&edge, vector<vector<pair<int, int>>>&nx,const vector<int>&sz ,int node = 0) {
	//cout << "node " << node << endl;
	for (int i = 0; i < 27; i++) {
		int nn = edge[node][i];
		if (nn == -1)continue;
		Search(edge, nx, sz, nn);
		int num = 0;
		for (int j = 0; j < 27; j++) {
			num += edge[nn][j] != -1;
		}
		if (num==1) {
			for (int j = 0; j < 27; j++) {
				if (nx[nn][j].first != -1) {
					nx[node][i] = nx[nn][j];
					nx[node][i].second++;
				}
			}
		}
	}
	return;
}

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

	cin >> N;
	vector<vector<int>>edge(1, vector<int>(27, -1));
	vector<vector<int>>v(N);
	for (int i = 0; i < N; i++) {
		string s;
		cin >> s;
		for (auto j : s) {
			v[i].push_back(j - 'a' + 1);
		}
		v[i].push_back(0);
		int node = 0;
		for (auto j : v[i]) {
			if (edge[node][j] == -1) {
				edge[node][j] = edge.size();
				edge.push_back(vector<int>(27, -1));
			}
			node = edge[node][j];
			//cout << node << endl;
		}
	}
	vector<vector<pair<int, int>>>nx(edge.size(), vector<pair<int, int>>(27, make_pair(-1, -1)));
	vector<int>sz(edge.size());
	for (int i = 0; i < edge.size(); i++) {
		int num = 0;
		for (int j = 0; j < 27; j++) {
			if (edge[i][j] == -1)continue;
			num++;
			nx[i][j] = { edge[i][j],1 };
		}
		if (!num)sz[i] = 1;
	}
	Search(edge, sz);
	Search(edge, nx,sz);
	cin >> K;
	for (int i = 0; i < edge.size(); i++) {
		for (int j = 0; j < 27; j++) {
			//if (nx[i][j].first != -1)cout << i << " " << j << " " << nx[i][j].first << endl;
		}
	}
	while (K--) {
		cin >> M;
		M--;
		string s;
		cin >> s;
		vector<int>w;
		w.push_back(0);
		for (auto i : s)w.push_back(i - 'a' + 1);
		int index = 0;
		int ans = 0;
		int nn = 0;
		while (index < v[M].size()) {
		//	cout << "index " << index << " " << nn << endl;
			for (auto i : w) {
				if (i == v[M][index])break;
				if (edge[nn][i] == -1)continue;
				ans += sz[edge[nn][i]];
			}
			//cout << ans << endl;
			int nnn =  nx[nn][v[M][index]].first;
			int nindex = index+nx[nn][v[M][index]].second;
			index = nindex;
			nn = nnn;
		}
		cout << ans+1 << endl;
	}
}


Measured memory_bytes: 186240
from collections import Counter


def solve(string):
    n, k, q, *a = map(int, string.split())
    a = Counter(a)
    return "\n".join(["Yes" if a.get(i + 1, 0) > q - k else "No" for i in range(n)])


if __name__ == '__main__':
    n, m, q = map(int, input().split())
    print(solve('{} {} {}\n'.format(n, m, q) + '\n'.join([input() for _ in range(q)])))


Measured memory_bytes: 15036
/*
 * atcoder/abc105_2nd/c.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }

// -9
// 1  0 0 1
// 4 -2 1 0
ll N;
void solve() {
  cin >> N;
  if (N == 0) {
    cout << 0 << endl;return;
  }
  string s = "";
  while (N) {
    ll r = N % -2;
    if (r<0) r+=2;
    s += to_string(r);
    N = (N-r) / -2;
  }
  reverse(s.begin(), s.end());
  cout << s << endl;
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int health,attack,swing,left;
	
	scanf("%i %i",&health,&attack);
	
	swing = health/attack;
	left = health%attack;
	
	left > 0 ? printf("%i",swing + 1) : printf("%i",swing);
	
	return 0;
}

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

int main()
{
    int n, k;
    cin>>n>>k;
    ll v[n];
    for(int i=0;i<n;i++)    cin>>v[i];
    ll maxe=0;
    for(int i=0;i<=min(k,n);i++)
    {
        for(int j=0;j<=min(n,k)-i;j++)
        {
            ll sum=0;
            vector<ll> item;
            for(int l=0;l<i;l++)
                item.push_back(v[l]);
            for(int l=0;l<j;l++)
                item.push_back(v[n-1-l]);
            sort(item.begin() , item.end());
            sum =accumulate(item.begin() , item.end() , (ll)0);
            for(int l=0;l<min(k-i-j, i+j);l++)
            {
                if(item[l]>0)
                    break;
                else
                    sum-=item[l];

            }
            maxe=max(maxe, sum);
        }
    }
    cout<<maxe;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;

int main(){
    int N,H,W;
    cin >> N >> H >> W;

    cout << (N-H+1)*(N-W+1) << endl;
}

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

int main() {

	int N;
	cin >> N;

	vector<int> a;

	for(int i = 0;i<N;i++) {
		int h;
		cin >> h;
		a.push_back(h);
	}

	int dp[N];
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	for(int i = 2;i<N;i++) {
		dp[i] = min(dp[i-1]+ abs(a[i]-a[i-1]), dp[i-2]+abs(a[i]- a[i-2]));
	}
	// for(int i = 0;i<N;i++)
	// 	cout << dp[i] << endl;
	cout << dp[N-1] ;
}

Measured memory_bytes: 1144