akhauriyash/Code-Regression huggingface dataset:
N=int(input())
a=[]
cnt=[]

for i in range(N):
    b=[]
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        
        c=[x,y]
        b.append(c)
    
    a.append(b)

    #リスト完成      
for i in range(2**N):
    honest=[]
    hantei=[]
    for j in range(N):
        if ((i >>j)& 1):
            honest.append(j+1)
    hantei1=[[x,0] for x in honest] 
    hantei2=[[x,1] for x in honest]
    for k in honest:
        if [m for m in hantei1 if m in a[k-1]]:
            break
        for l in a[k-1]:
            
            if l[1]==1:
                if l[0] in honest:
                    continue
                else:
                    break
        else:
            continue
        break
                
    else:
        cnt.append(len(honest))
        
            
    
    
    
ans=max(cnt)  
print(ans)


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

#define MOD 1000000007

// Extended Euclidean algorithm
long int xGCD(long int a, long int b, long int &x, long int &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }

    long int x1, y1, gcd = xGCD(b, a % b, x1, y1);
    x = y1;
    y = x1 - (long long)(a / b) * y1;
    return gcd;
}

// factorial of n modulo MOD
long int modfact(long int n) {
    long int result = 1;
    while (n > 1) {
        result = (long long)result * n % MOD;
        n -= 1;
    }
    return result;
}

// multiply a and b modulo MOD
long int modmult(long int a, long int b) {
    return (long long)a * b % MOD;
}

// inverse of a modulo MOD
long int inverse(long int a) {
    long int x, y;
    xGCD(a, MOD, x, y);
    return x;
}

// binomial coefficient nCk modulo MOD
long int bc(long int n, long int k)
{
    return modmult(modmult(modfact(n), inverse(modfact(k))), inverse(modfact(n - k)));
}

int main(){
	long int X, Y;
	
	cin >> X >> Y;
	
	long int a, b;
	
	long int ans;
	
	if((X+Y)%3 != 0){
		cout << 0 << endl;
		return 0;
	}
	
	if((2*X - Y)%3 == 0){
		a = (2*X - Y)/3;
	} else {
		cout << 0 << endl;
		return 0;
	}
	
	if((2*Y - X)%3 == 0){
		b = (2*Y - X)/3;
	} else {
		cout << 0 << endl;
		return 0;
	}
	
	if(a < 0 || b < 0){
		cout << 0 << endl;
		return 0;
	}
	
	ans = bc(a+b, a);
	
	if(ans < 0){
		ans = 1000000007 + ans;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)

{

 int a[10000], min, max, n, i;

 long long sum = 0;

 scanf("%d", &n);

 for(i = 0; i < n; i++){

 scanf("%d", &a[i]);

 sum += a[i];

 }

 max = min = a[0];

 for(i = 1; i < n; i++){

 if(a[i] > max){

 max = a[i];

 }

 if(a[i] < min){

 min = a[i]; 

 }

 }

 printf("%d %d %lld\n", min, max, sum);

 return 0;

}

Measured memory_bytes: 640
import java.util.Scanner;
import java.util.Arrays;

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

        int x = sc.nextInt();
        int n = sc.nextInt();
        int[] p = new int[n];
        for(int i = 0; i<n; i++){
            p[i] = sc.nextInt();
        }

        Arrays.sort(p);
        int ans = -100000000;
        int ansLow, ansHigh;
        int count = 0;
        int matchNotAns = -1000000000;

        for(int j = 0; j<1000; j++){
            for(int k = 0; k<n; k++){
                if(x - j == p[k]){
                    count++;
                    matchNotAns = p[k];
                }
                else if(x + j == p[k]){
                    count++;
                    matchNotAns = p[k];
                }
            }
            if(count == 1 && j!=0){
                if(matchNotAns == x - j){
                    ans = x + j;
                }
                else if(matchNotAns == x + j){
                    ans = x - j;
                }
                break;
            }
            else if(count == 0){
                ans = x - j;
                break;
            }
            count = 0;
        }

        System.out.println(ans);
    }
}

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

long long n, a[200009], b[200009];

int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) { cin >> a[i]; b[i] = b[i - 1] + a[i]; }
	sort(b, b + n + 1);
	long long c = 1, s = 0;
	for (int i = 1; i <= n; i++) {
		if (b[i] == b[i - 1]) c++; else c = 1;
		s += c - 1;
	}
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main() {

    int N, M;
    cin >> N >> M;
    vector<int> p(M);
    vector<string> S(M);
    for(int i = 0; i < M; i++) cin >> p.at(i) >> S.at(i);

    vector<bool> AC(N, false);
    vector<int> WA(N, 0);
    for(int i = 0; i < M; i++) {
        if(AC.at(p.at(i) - 1)) continue;
        if(S.at(i) == "AC") AC.at(p.at(i) - 1) = true;
        if(S.at(i) == "WA") WA.at(p.at(i) - 1)++;
    }

    int AC_num = 0, WA_num = 0;
    for(int i = 0; i < N; i++) {
        if(AC.at(i)) {
            AC_num++;
            if(WA.at(i)) WA_num += WA.at(i);
        }
    }

    cout << AC_num << " " << WA_num << endl;

    return 0;
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int cnt[26];
  ll ans = 1;
  for (int i = 0; i < 26; i++) {
    cnt[i] = 0;
  }

  for (int i = 0; i < n; i++) {
    cnt[s[i] - 'a']++;
  }

  for (int i = 0; i < 26; i++) {
    if (!cnt[i]) continue;

    ans *= (ll)(cnt[i] + 1);
    ans %= 1000000007;
  }

  cout << ans - 1 << endl;
}


Measured memory_bytes: 3728
N = int(input())
def keta(n):
    if n<10:return 1
    return 1 + keta(n//10)
def yakusuu(n):
    for i in range(int(n**(0.5)),0,-1):
        if n%i == 0:return n//i
print(keta(yakusuu(N)))

Measured memory_bytes: 2940
#include <stdio.h>
int main(void){
    int i,n,a[1000];
    scanf("%d",&n);
    
    for ( i = 0; i < n; i++ ){
        scanf("%d",&a[i]);
    }
    for( i = n-1; i > 0; i--){
        printf("%d ",a[i]);
    }
    printf("%d\n",a[0]);
    
    return 0;
}



Measured memory_bytes: 2068
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[10]={1,2,3,4,5,6,7,8};
	int b[10]={1,2,3,4,5,6,7,8},c[10],d[10];
	int n,count1=0,count2=0,sum;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>c[i]; 
	}
	for(int i=0;i<n;i++){
		cin>>d[i];
	}
	do{
		sum=0;
		for(int i=0;i<n;i++){
			if(a[i]==c[i]) sum++;
			else break;
		}count1++;
		if(sum==n) {
			break;
		}
	}while(next_permutation(a,a+n));
	do{
		sum=0;
		for(int i=0;i<n;i++){
			if(b[i]==d[i]) sum++;
			else break;
		}count2++;
		if(sum==n) {
			break;
		}
	}while(next_permutation(b,b+n));
	printf("%d\n",abs(count2-count1));
}

Measured memory_bytes: 3748
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
#define max(a,b)  (((a) > (b)) ? (a) : (b))
#define min(a,b)  (((a) < (b)) ? (a) : (b))
typedef long long ll;
int main()
{
    int a[51],b[51],ans=0,n,i;
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        b[i]=a[i];
    }
    sort(a,a+n);
    for(i=0; i<n; i++)
    {
        if(b[i]!=a[i])
            ans++;
    }
    if(ans==2||ans==0)
        printf("YES\n");
    else
        printf("NO\n");
}


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

int main(){
  	long N, sum=0;
  	cin >> N;
  	for(long i=1; i<=N; i++){
    	if(i%3==0 || i%5==0){
        	
        }else{
        	sum+=i;
        }
    }
  	cout << sum << endl;
 	return 0;
}

Measured memory_bytes: 3164
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define len length
#define mp make_pair
#define pq priority_queue
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define forn(i,n) for (int i = 0; i < int(n); ++i)
#define take(v) for(int i=0;i<(int)v.size();i++){cin>>v[i];}
#define printvec(v) for(int i=0;i<(int)v.size();i++){cout<<v[i]<<" ";}
#define speed ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define printds(x) while(!x.empty()){cout<<x.top()<<" ";x.pop();}
#define input(n) int n;cin>>n;
#define PI 3.141592653589793238463
#define lnput(n) long long int n;cin>>n;
#define fr(i,s,e) for(int i=s;i<e;i++)
#define ms(arr,val) memset(arr,val,sizeof(arr))
using namespace std;
int main()
{
  speed;
  string a,b;
  cin>>a>>b;
  int n = (int)a.length();
  int m = (int)b.length();
  int dp[n+1][m+1];
  char ans[n+1][m+1];
  ms(dp,0);
  for(int i = 1;i<=n;i++) {
    for(int j = 1;j<=m;j++) {
      if(a[i-1] == b[j-1]) {
        dp[i][j] = 1+dp[i-1][j-1];
        ans[i][j] = '/';
      }else {
        dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
        if(dp[i][j-1] > dp[i-1][j]) {
          ans[i][j] = '_';
        }else {
          ans[i][j] = '|';
        }
      }
    }
  }
  // cout<<dp[n][m]<<endl;
  // for(int i = 0;i<=n;i++) {
  //   for(int j = 0;j<=m;j++) {
  //     cout<<dp[i][j]<<" ";
  //   }
  //   cout<<endl;
  // }
  string res = "";
  int x = n,y = m;
  while(x>0 && y>0) {
    if(a[x-1] == b[y-1]) {
      res.pb(a[x-1]);
    }
    if(ans[x][y] == '/') {
      x--;
      y--;
    }else if(ans[x][y] == '_') {
      y--;
    }else {
      x--;
    }
  }
  reverse(all(res));
  cout<<res<<endl;
  return 0;
}


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

int main() {
	string s;cin>>s;
    int l,r;
    for(int i=0;i<s.size();i++){
        if(s[i]=='Z')r=i;
    }
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]=='A')l=i;
    }
    cout<<r-l+1<<endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const ll MOD = 1e9 + 7;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")


int main(){
    int n,x,t; cin >> n >> x >> t;

    cout << t * (n/x + (n%x == 0? 0:1));
}

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
    }

    vector<ll> sum(N + 1);
    sum[0] = 0;
    rep(i, N) {
        sum[i + 1] = sum[i] + A[i];
    }

    map<ll, int> m;
    rep(i, N + 1) {
        m[ sum[i] ]++;
    }

    ll ans = 0;
    for (auto i : m) {
        int c = i.second;
        ans += (ll)c * (c - 1) / 2;
    }

    cout << ans << endl;
}

Measured memory_bytes: 15104
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define br cout << endl;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
using Graph = vector<vector<ll>>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

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

    if(s == "hi" || s =="hihi" || s == "hihihi" || s == "hihihihi" || s == "hihihihihi"){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    /*
    if(s.size() == 1){
        cout << "No" << endl;
        return 0;
    }

    string ans = "Yes";
    rep(i, s.size()){
        if(i % 2 == 0){
            if(s.at(i) == 'h'){
                continue;
            }else{
                ans = "No";

            }
        }else{
            if(s.at(i) == 'i'){
                continue;
            }else{
                ans = "No";
            }
        }
    }
    cout << ans << endl;
    return 0;
    */

}

Measured memory_bytes: 256
import java.io.*;
import java.util.Scanner;
public class Main{
    public static void main(String args[]){
      Scanner sc=new Scanner(System.in);
      double r=sc.nextDouble();
      double S=(double)Math.PI*r*r;
      double M=(double)2.0*Math.PI*r;
      System.out.printf("%f %f",S,M);
    }
}


Measured memory_bytes: 28200
n,k,q=map(int,input().split())
cnt={}
for i in range(q):
    per=input()
    cnt.setdefault(per,0)
    cnt[per]+=1
for i in range(1,n+1):
    if cnt.get(str(i),0)+k-q>0:
        print('Yes')
    else:
        print('No')
    


Measured memory_bytes: 10396
#include <bits/stdc++.h>
using namespace std;
int read();
int n;
char s[1000006];
int a[1000006];
void calc() {
    for (int i = 1; i < n; ++i) a[i] = abs(a[i] - a[i + 1]);
    --n;
}
int main() {
    n = read(), scanf("%s", s + 1);
    for (int i = 1; i <= n; ++i) a[i] = s[i] - '0';
    if (n == 2) return calc(), printf("%d\n", a[1]), 0;
    calc(), calc();
    int res = 0;
    for (int i = 1; i <= n; ++i) res ^= ((n - 1 | i - 1) == n - 1) * (a[i] & 1);
    if (res == 1) return puts("1"), 0;
    for (int i = 1; i <= n; ++i)
        if (a[i] == 1) return puts("0"), 0;
    res = 0;
    for (int i = 1; i <= n; ++i)
        res ^= ((n - 1 | i - 1) == n - 1) * (a[i] >> 1 & 1);
    printf("%d\n", res << 1);
    return 0;
}

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/b.in", "r", stdin);
//  freopen("../IO/b.in", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}


void solve(std::istream &in, std::ostream &out) {
  int a, b, c, d;
  in >> a >> b >> c >> d;
  int z = 0;
  while (a > 0 && c > 0) {
    if (!z) c -= b;
    else a -= d;
    z ^= 1;
  }
  out << (z ? "Yes\n" : "No\n");
}


Measured memory_bytes: 3640
import java.util.*;

class Main{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
      int x = scan.nextInt();
      int left = -k+x+1;
        int right = k+x-1;
      for(int i=left;i<=right;i++){
        System.out.print(i+" ");
      }
	}
}


Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath> 

using namespace std;

int gcd(int a,int b)
{
	if(b)
		return gcd(b,a % b);
	else
		return a;
}

int main()
{
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(c % gcd(a, b))
		printf("NO\n");
	else
		printf("YES\n");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const int INF=0x3f3f3f3f;
const int MOD=1e9+7;
const int N=200005;

int n,X,Y,S,ans=1;
int c[N],w[N];
int siz[N],mn[N];
int jc[N],inv[N];
int m1=0,m2=0;

LL Pow(LL x,int p) {
	if(p==0) return 1;
	if(p&1) return x*Pow(x*x%MOD,p/2)%MOD;
	return Pow(x*x%MOD,p/2);
}
LL C(int n,int m) {
	return 1ll*jc[n]*inv[m]%MOD*inv[n-m]%MOD;
}
int main() {
	memset(mn,0x3f,sizeof(mn));
	scanf("%d %d %d",&n,&X,&Y);
	jc[0]=1;
	for(int i=1;i<=n;i++) {
		scanf("%d %d",&c[i],&w[i]);
		mn[c[i]]=min(mn[c[i]],w[i]);
		jc[i]=1ll*i*jc[i-1]%MOD;
	}
	jc[n+1]=jc[n]*(n+1ll)%MOD;
	inv[n+1]=Pow(jc[n+1],MOD-2);
	for(int i=1;i<N;i++) {
		if(mn[i]<mn[m1])
			m2=m1,m1=i;
		else if(mn[i]<mn[m2])
			m2=i;
	}
	for(int i=n;i>=1;i--) {
		inv[i]=(i+1ll)*inv[i+1]%MOD;
		if(c[i]==m1) {
			if(w[i]+mn[m1]<=X||w[i]+mn[m2]<=Y)
				siz[c[i]]++;
		}
		else if(w[i]+mn[c[i]]<=X||w[i]+mn[m1]<=Y)
			siz[c[i]]++;
	}
	S=siz[m1];
	for(int i=1;i<N;i++) {
		if(i==m1||mn[i]>=INF) continue;
		if(mn[i]+mn[m1]<=Y) {
			S+=siz[i];
			ans=ans*C(S,siz[i])%MOD;
		}
	}
	printf("%d\n",ans);
	return 0;
}
/*
x1+x2+...+xm+1=n (x>=0)
x1+x2+...+xm+1=n+m+1 (x>=1)
C(n+m,m)
*/

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

using namespace std;

typedef long long ll;

const int maxn = 100010;

int n, m, ans = 0x3f3f3f3f;

int tot, cnt;
int eu[maxn], ev[maxn], ec[maxn], vis[maxn], deg[maxn];
int tag[maxn], cid[maxn]; // 边是否在初始未锁定连通块中，边所在连通块编号
vector<int> to[maxn], fr[maxn];
vector<int> vv[maxn], ve[maxn];

int ex[maxn]; // 连通块大小，有无 deg > 1 的点

void dfs(int u) {
	vis[u] = 1;
	if (deg[u] > 1) ex[tot] = 1;
	vv[tot].push_back(u);
	for (int i = 0; i < to[u].size(); i++) {
		int v = ev[to[u][i]], e = to[u][i];
		ve[tot].push_back(e); cid[e] = tot;
		if (!vis[v]) {
			dfs(v);
		}
	}
	for (int i = 0; i < fr[u].size(); i++) {
		int v = eu[fr[u][i]];
		if (!vis[v]) {
			dfs(v);
		}
	}
}

int main() {
	// freopen("data.txt", "r", stdin);
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++) {
		int u, v, c; scanf("%d%d%d", &u, &v, &c);
		cnt += (u != v);
		eu[i] = u, ev[i] = v, ec[i] = c;
		to[u].push_back(i), fr[v].push_back(i);
		++ deg[u];
	}
	int flag1 = 0;
	for (int i = 1; i <= n; i++) {
		if (!vis[i]) {
			++ tot;
			dfs(i);
			if (vv[tot].size() > 1 && !ex[tot]) {
				++ flag1;
			}
			if (ex[tot]) {
				for (int j = 0; j < ve[tot].size(); j++) {
					tag[ve[tot][j]] = 1;
				}
			}
		}
	}
	if (!flag1) {
		ans = cnt;
	} else {
		ll sum = 0;
		int flag2 = 0; // 是否存在一个 tag = 1 的非自环边 (不含 0 收益边)
		for (int i = 1; i <= m; i++) {
			if (ec[i] == 1) continue;
			if (eu[i] != ev[i] && tag[i]) {
				flag2 = 1;
			}
			if (eu[i] != ev[i]) sum += ec[i] - 1;
		}
		vector<int> v0, v1; // tag = 0 的自环和 tag = 1 的自环
		for (int i = 1; i <= m; i++) {
			if (ec[i] == 1 || eu[i] != ev[i]) continue;
			if (!tag[i]) v0.push_back(ec[i] - 1);
			else v1.push_back(ec[i] - 1);
		}
		sort(v0.begin(), v0.end(), greater<int>()); sort(v1.begin(), v1.end(), greater<int>());
		vector<ll> s0(v0.size(), 0), s1(v1.size(), 0);
		for (int i = 0; i < v0.size(); i++) {
			if (!i) s0[i] = v0[i];
			else s0[i] = s0[i-1] + v0[i];
		}
		for (int i = 0; i < v1.size(); i++) {
			if (!i) s1[i] = v1[i];
			else s1[i] = s1[i-1] + v1[i];
		}
		if (flag2) {
			// 无需强制选一个正收益的 tag = 1 自环
			for (int i = 0; i <= v0.size(); i++) {
				// 选取几个 tag = 0 自环
				int k = flag1 + i; // 需要解锁的块数
				ll need = k - sum;
				if (i > 0) need -= s0[i-1];
				if (need <= 0) {
					ans = min(ans, k + cnt + i);
				} else {
					int p = int (lower_bound(s1.begin(), s1.end(), need) - s1.begin());
					if (p < s1.size()) {
						ans = min(ans, k + cnt + i + (p + 1));
					}
				}
			}
		} else {
			// 必须选一个正收益的边
			for (int i = 0; i <= v0.size(); i++) {
				// 选取几个 tag = 0 自环
				int k = flag1 + i; // 需要解锁的块数
				ll need = k - sum;
				if (i > 0) need -= s0[i-1];
				int p = int (lower_bound(s1.begin(), s1.end(), need) - s1.begin());
				if (p < s1.size()) {
					ans = min(ans, k + cnt + i + (p + 1));
				}
			}
		}
	}
	if (ans >= 0x3f3f3f3f) puts("-1");
	else printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 27068
#include <stdio.h>

int main(void){
    // Your code here!
    int N,K;
    int ans = 1;
    
    scanf("%d%d",&N,&K);
    
    for(int i = 0; i < N; i++){
        int tmpA = ans*2;
        int tmpB = ans + K;
        
        if(tmpA <= tmpB){
            ans = tmpA;
        }
        else{
            ans = tmpB;
        }
    }
    
    printf("%d\n",ans);
    
}


Measured memory_bytes: 1708
# -*- coding: utf-8 -*-

"""
参考：https://atcoder.jp/contests/abc060/submissions/3958560
・前から普通にDPもdictでやってみる。
"""

import sys
def input(): return sys.stdin.readline().strip()
sys.setrecursionlimit(10 ** 9)

from collections import defaultdict

N, W = map(int, input().split())
wN = [0] * N
vN = [0] * N
for i in range(N):
    wN[i], vN[i] = map(int, input().split())

# 重さの添字にはdictを使う
dp = [defaultdict(int) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for k, v in dp[i].items():
        # 重さの条件がOKなら、今回の値を足したケースを次のステップに送る
        if k + wN[i] <= W:
            dp[i+1][k+wN[i]] = max(dp[i][k] + vN[i], dp[i+1][k+wN[i]])
        # 足さないケースを送る
        dp[i+1][k] = max(dp[i][k], dp[i+1][k])

# 最適が重さWを全て使った場合とは限らないのでNステップ目のmaxを取る
print(max(dp[N].values()))


Measured memory_bytes: 12332
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }
fn main() {
    input!(n: usize, _c: String);
    let c: Vec<char> = _c.as_str().chars().collect();

    let mut l_itr = 0;
    let mut r_itr = c.len() - 1;

    while (c[l_itr] == 'R') && (l_itr < c.len() - 1) {
        l_itr += 1;
    }
    while (c[r_itr] == 'W') && (r_itr > 0) {
        r_itr -= 1;
    }

    let mut counter = 0;
    while l_itr < r_itr {
        counter += 1;

        l_itr += 1;
        r_itr -= 1;

        while (c[l_itr] == 'R') && (l_itr < c.len() - 1) {
            l_itr += 1;
        }
        while (c[r_itr] == 'W') && (r_itr > 0) {
            r_itr -= 1;
        }
    }

    println!("{:?}", counter);
}


Measured memory_bytes: 3120
cards = [input() for i in range(3)]

now = 0
index =[0,0,0]
dic={"a":0,"b":1,"c":2}

while True:
    if index[now] == len(cards[now]):
        break
    idx = index[now]
    index[now] += 1
    now = dic[cards[now][idx]]
    

print("ABC"[now])


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _dbg(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _dbg(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_dbg(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}
const int N=1e5+1;
vector<pii> g[N];
int c[N],u[N];
void dfs(int v,int p=0){
    u[v]=1;
    for(pii to:g[v]){
        if(!u[to.f]){
            c[v]-=to.s;
            c[to.f]-=to.s^1;
            dfs(to.f,v);
        }else if(to.f!=p&&to.s)cout<<v<<' '<<to.f<<'\n';
    }
    if(p){
        if(c[v]&1)cout<<v<<' '<<p<<'\n';
        else{
            cout<<p<<' '<<v<<'\n';
            c[p]++;
        }
    }
}
int32_t main(){
    int n,m;
    cin>>n>>m;
    forn(i,m){
        int a,b;
        cin>>a>>b;
        g[a].pb(b,1);
        g[b].pb(a,0);
        c[a]++;
    }
    if(m%2==1){
        cout<<"-1\n";
        return 0;
    }
    dfs(1);
    return 0;
}


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

int main() {
	string S;
	cin >> S;
	if(S=="AAA" || S=="BBB"){
		cout << "No" << endl;
	} else {
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

long double ans;
int N, K;
long double S[200005];

int main(void) {
    scanf("%d %d", &N, &K);
    rep(i, 1, N+1) {
        long double p;
        scanf("%Lf", &p);
        long double t = ((p*(p+1))/2) / p;
        S[i] = S[i-1] + t;
    }

    ans = -1;
    rep(i, 1, N-K+2) ans = max(ans, S[i+K-1]-S[i-1]);

  
    printf("%0.10Lf\n", ans);

	return 0;
}


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

using namespace std;

using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;

#ifdef WIN32
    #define LLD "%I64d"
#else
    #define LLD "%lld"
#endif

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

const int maxn = 2005;

int a[maxn], best[maxn];
int n, X;

int main()
{
	scanf("%d%d", &n, &X);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < n; i++) best[i] = a[i];
	ll answer = 1e18;
	for (int i = 0; i < n; i++)
	{
		ll curans = 0;
		for (int j = 0; j < n; j++)
		{
			best[j] = min(best[j], a[(j - i + n) % n]);
			curans += best[j];
		}
		answer = min(answer, curans + (ll)X * i);
	}
	cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace AtCoder.ABC112
{
    public class A
    {
        public static void Solve()
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            if (n == 1)
            {
                Console.WriteLine("Hello World");
            } else if (n == 2)
            {
                int a, b;
                a = int.Parse(Console.ReadLine());
                b = int.Parse(Console.ReadLine());
                Console.WriteLine(a + b);
                
            }
        }    
    }
}

namespace AtCoder {
    class Program
    {
        static void Main(string[] args)
        {
            ABC112.A.Solve();
        }
    }
}


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

using namespace std;

#define ll long long int

int main()
{
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=floor((a*n)/b)-a*(floor(n/b)),z=b*(n/b)-1;
    ll y=floor((a*z)/b)-a*(floor(z/b));
    cout<<max(x,y);
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
namespace FAST_IO
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
long long n,a,b;
int main()
{
	cin>>n>>a>>b;
	cout<<(n/(a+b)*a)+min(a,n%(a+b));
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

int main(){
    int n;
    cin >> n;
    vector<int> a(n+1), b(n+1), ans;
    rep(i,n) cin >> a[i+1];
    for(int i = n; i > 0; i--){
        ll sum = 0;
        for(int j = i; j <= n; j += i) sum += b[j];
        if (sum % 2 != a[i]){
            b[i]++;
            ans.push_back(i);
        }
    }
    int sz = ans.size();
    reverse(all(ans));
    cout << sz << endl;
    for(int i = 0; i < sz; i++){
        printf("%d%c", ans[i], i == sz-1 ? '\n': ' ');
    }
    return 0;
}

Measured memory_bytes: 5244
//ALDS1_10_A:Fibonacci Number
#include <bits/stdc++.h>
using namespace std;
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807

int main(){
    int n;
    cin >> n;
    int fib[44];
    fib[0] = 1; fib[1] = 1;
    for(int i=2; i<=n; i++) fib[i] = fib[i-1] + fib[i-2];
    cout << fib[n] << endl;
}


Measured memory_bytes: 3136
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<vector>
#include<cstdio>
 
using namespace std;
 
int main()
{
	int N, m6, m9;
	cin >> N;
 
	int ans = N;
	vector<int> v6, v9;
	
	v6.push_back(1);
	v9.push_back(1);
 
	int count = 6;
	while (count <= N) {
		v6.push_back(count);
		count *= 6;
	}
 
	count = 9;
	while (count <= N) {
		v9.push_back(count);
		count *= 9;
	}
 
	/*
	int  n = N;
	for (int i = v.size()-1; i >= 0; i--) {
		while (v[i] <= n) {
			n -= v[i];
			ans++;
		}
	}
	
	for (int i = 0; i < v.size(); i++) {
		cout << v[i] << endl;
	}*/
	/*
	int i = 1;
	while (pow(6, i) <= 10000) {
		mems.push_back(N/((int)pow(6, i)));
		memz.push_back(N%((int)pow(6, i)));
		i++;
	}
 
	int i = 1;
	while (pow(9, i) <= 10000) {
		mems.push_back(N / ((int)pow(9, i)));
		memz.push_back(N % ((int)pow(9, i)));
		i++;
	}
	*/
 
 
	for (int i = 0; i <= N; i++) {
		int count = 0;
 
		int res = i;
		for (int j = v6.size()-1; j >= 0; j--) {
			count += res/v6[j];
			res = res%v6[j];
 
			if (j == 1) m6 = res; //1の数
		}
 
		res = N - i;
		for (int j = v9.size() - 1; j >= 0; j--) {
			count += res / v9[j];
			res = res%v9[j];
 
			if (j == 1) m9 = res; //1の数
		}
 
		if (ans > count) ans = count;
	}
 
	cout << ans;
 
	char qq;
	cin >> qq;
	return 0;
}

Measured memory_bytes: 256
x=int(input())
a=[]
ans=0

for i in range(1,32):
            for j in range(2,10):
                        ans=i**j
                        if ans<=x:
                                    a.append(ans)   
                                    #i+=1
                        else:
                                    break
                        
            #print(a)
print(max(a))
"""
while ans<x:
"""
            
         
                   



Measured memory_bytes: 2940
n,m = map(int,input().split())
xlist = sorted(list(map(int,input().split())))

dlist = [0]*(m-1)
for i in range(m-1):
  dlist[i] = xlist[i+1]-xlist[i]
dlist.sort()
ans = 0

for i in range(m-n):
  ans += dlist[i]

print(ans)


Measured memory_bytes: 53672
#include <iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<=b;i++)
template <typename T>
void read(T &x){
    x=0;
    int flag=1;
    char c=getchar();
    while(c=='-'){
        flag=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=x*10+c-'0';
        c=getchar();
    }
    x*=flag;
}
struct node{
    int x,y,id;
}q[1000010];
    int n,m,cnt=0,head=0;
    char mp[1010][1010]={'\0'};

int main()
{
    cin>>n>>m;
    rep(i,1,n)rep(j,1,m){
        cin>>mp[i][j];
        if(mp[i][j]=='#'){
            q[cnt].x=i;
            q[cnt].y=j;
            q[cnt++].id=0;
        }
    }
    while(head<cnt){
        if(q[head].x>1&&mp[q[head].x-1][q[head].y]=='.'){
            mp[q[head].x-1][q[head].y]='#';
            q[cnt].x=q[head].x-1;
            q[cnt].y=q[head].y;
            q[cnt++].id=q[head].id+1;
        }
        if(q[head].x<n&&mp[q[head].x+1][q[head].y]=='.'){
            mp[q[head].x+1][q[head].y]='#';
            q[cnt].x=q[head].x+1;
            q[cnt].y=q[head].y;
            q[cnt++].id=q[head].id+1;
        }
        if(q[head].y>0&&mp[q[head].x][q[head].y-1]=='.'){
            mp[q[head].x][q[head].y-1]='#';
            q[cnt].x=q[head].x;
            q[cnt].y=q[head].y-1;
            q[cnt++].id=q[head].id+1;
        }
        if(q[head].y<m&&mp[q[head].x][q[head].y+1]=='.'){
            mp[q[head].x][q[head].y+1]='#';
            q[cnt].x=q[head].x;
            q[cnt].y=q[head].y+1;
            q[cnt++].id=q[head].id+1;
        }
        head++;
    }
    cout<<q[head-1].id;
    return 0;
}


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

using namespace std;


long calc(int start, int end, vector<long>& sumA, int split) {
    return abs((sumA[split] - sumA[start]) - (sumA[end] - sumA[split]));

}

long localMin(int start, int end, vector<long>& sumA) {
    long offset = sumA[start];
    long val = (sumA[end] - sumA[start]) / 2;

    int a = lower_bound(sumA.begin() + start, sumA.begin() + end, offset + val) - sumA.begin();
    //cout << start << " " << end << " " << a << " " << min(calc(start,end,sumA,a-1),calc(start,end,sumA,a)) << endl;
    return min(calc(start, end, sumA, a), calc(start, end, sumA, a - 1));

}


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

    int N;
    cin >> N;
    vector<int> A;
    vector<long> sumA;
    sumA.push_back(0);
    for (int i = 0; i < N; ++i) {
        int tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    long sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += A[i];
        sumA.push_back(sum);
    }

    long ans = 1000000000000000000L;
    for (int center = 2; center <= N - 2; ++center) {
        long left_val = localMin(0, center, sumA);
        long right_val = localMin(center, N, sumA);
        long left_max = (sumA[center] + left_val) / 2;
        long left_min = (sumA[center] - left_val) / 2;
        long right_max = (sumA[N] - sumA[center] + right_val) / 2;
        long right_min = (sumA[N] - sumA[center] - right_val) / 2;
        //cout << "res" << left_max << " " << left_min <<  " "  <<  right_max << " " <<  right_min << endl;
        ans = min(ans, max(left_max, right_max) - min(left_min, right_min));
    }
    cout << ans << endl;
}

Measured memory_bytes: 3188
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.List
import           Data.Maybe

readInt = fst . fromJust . BS.readInteger
readIntList = map readInt . BS.words

getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

solve :: Integer -> [Integer] -> Integer
solve n p = sum (take (fromInteger n) t) - h
  where
    h = head p
    t = concatMap (replicate 2) p

main = do
  n  <- getInt
  p <- getIntList
  let p' = sortBy (flip compare) p
  print $ solve n p'


Measured memory_bytes: 33164
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<N;i++)
#define p(S) cout<<(S)<<endl
using namespace std;

int main(){
	int n;
	while(cin>>n,n){
		int w[310];
		int dp[310][310]={};
		REP(i,0,n) cin>>w[i];
		for(int k=1;k<n;k++){
			for(int i=0;i+k<=n;i++){
				if(dp[i+1][i+k-1]==k-1)
					dp[i][i+k]=dp[i+1][i+k-1]+(abs(w[i]-w[i+k])<=1 ? 2 : 0);
				for(int j=i+1;j<i+k;j++)
					dp[i][i+k]=max(dp[i][i+k],dp[i][j]+dp[j+1][i+k]);
			}
		}
		p(dp[0][n-1]);
	}
	return 0;
}

Measured memory_bytes: 3464
/*input
4049
red
*/
/**
    Author: Kristopher Paul
    Date Created: 18-08-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200){
        cout << s << endl;
    }else{
        cout << "red" << endl;
    }
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 256
H, W = map(int, input().split())

S = [list(input()) for _ in range(H)]

check = [[0] * W for _ in range(H)]

ans = 0

move = [[1, 0], [-1, 0], [0, 1], [0, -1]]

for h in range(H):
    for w in range(W):
        if check[h][w] == 1:
            continue
        black = 0
        white = 0

        stack = [[h, w]]
        check[h][w] = 1
        if S[h][w] == '#':
            black += 1
        elif S[h][w] == '.':
            white += 1

        while len(stack) != 0:
            x, y = stack.pop()
            tmp = S[x][y]
            for dx, dy in move:
                nx = x + dx
                ny = y + dy
                if 0 <= nx < H and 0 <= ny < W and tmp != S[nx][ny] and check[nx][ny] == 0:
                    check[nx][ny] = 1
                    stack.append([nx, ny])
                    if S[nx][ny] == '#':
                        black += 1
                    elif S[nx][ny] == '.':
                        white += 1
        
        ans += black * white

print (ans)

Measured memory_bytes: 60508
#include <cstdio>
#define S 5010
using namespace std;
int l[S][S]={0};

int main(){
    int N,M,a,b,x,i,j;
    scanf("%d %d",&N,&M);
    for(i=0;i<M;i++){
        scanf("%d %d %d",&a,&b,&x);
        l[a][b]++;
        l[a][b+1]--;
        l[a+x+1][b]--;
        l[a+x+2][b+1]++;
        l[a+x+2][b+x+2]--;
        l[a+x+1][b+x+2]++;
    }
    for(i=1;i<N+4;i++){
        for(j=1;j<N+4;j++){
            l[i][j]+=l[i][j-1];
        }
    }
    for(j=1;j<N+4;j++){
        for(i=1;i<N+4;i++){
            l[i][j]+=l[i-1][j]; 
        }
    }
    for(i=1;i<N+4;i++){
        for(j=1;j<N+4;j++){
            if(i+j-1<S){
                l[i+j-1][j]+=l[i+j-2][j-1]; 
            }
        }
    }
    int cnt=0;
    for(i=0;i<N+4;i++){
        for(j=0;j<N+4;j++){
            if(l[i][j]>0){cnt++;}
        }
    }
    printf("%d\n",cnt);
    return 0;
}
    



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

const int MAX_N = 100005;

pair<int, int> A[MAX_N];

int main() {
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++) {
        cin >> A[i].first >> A[i].second;
    }
    sort(A + 1, A + 1 + n);
    long long wynik = 0;
    for(int i = 1; i <= n; i++) {
        long long ile_kupuje = min(A[i].second, m);
        m -= ile_kupuje;
        wynik += ile_kupuje * A[i].first;
    }
    cout << wynik;
    return 0;
}

Measured memory_bytes: 1024
import sys

readline = sys.stdin.readline
n, m = map(int, readline().split())
lr = [map(int, readline().split()) for _ in range(m)]

max_l = 1
min_r = n
for l, r in lr:
    max_l = max(max_l, l)
    min_r = min(min_r, r)
    if min_r - max_l < 0:
        print(0)
        exit()
print(min_r - max_l + 1)


Measured memory_bytes: 48884
using System;

namespace abc094A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            int X = int.Parse(str[2]);
            if (A + B >= X && X >= A)
                Console.WriteLine("YES");
            else
                Console.WriteLine("NO");
        }
    }
}


Measured memory_bytes: 13140
N = int(input())
Ws = [int(i) for i in input().split()]

s = sum(Ws)

a = Ws[0]
b = 0

for i in range(1, N):
    a += Ws[i]
    if a > s / 2:
        b = i
        break

ans1 = abs(a - (s - a))
ans2 = abs(a-Ws[b] - (s - (a-Ws[b])))

print(min([ans1, ans2]))


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

int const nmax = 300;
char v[1 + nmax][1 + nmax];

int main() {
  int n;
  std::cin >> n;
  for(int i = 0; i < n; i++) 
    for(int j = 0; j < n; j++)
      std::cin >> v[i][j];
  int result = 0;
  for(int h = -n + 1; h <= n - 1; h++) {
    int valid = 1;
    for(int i = 0; i < n; i++) 
      for(int j = 0; j < n; j++) 
        valid &= (v[i][(n + j - h) % n] == v[j][(n + i - h) % n]);

    if(valid == 1)
      for(int i = 0; i < n; i++)
        result += (0 <= (i + h) && (i + h) < n);
  }
  std::cout << result;
  return 0;
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin>>S;
  vector<char> s(S.length());
  for(int i=0;i<S.length();i++){
    s[i]=S.at(i);
  }
  int cnt=0;
  int ans=0;
  for(int i=0;i<S.length();i++){
    if(s[i]=='A'){
      cnt++;
      continue;
    }
    if(s[i]=='C'){
      cnt++;
      continue;
    }
    if(s[i]=='G'){
      cnt++;
      continue;
    }
    if(s[i]=='T'){
      cnt++;
      continue;
    }
    else{
      if(ans<cnt){
        ans=cnt;
      }
      cnt=0;
    }
  }
  if(ans<cnt){
    ans=cnt;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using vvl = vector<vector<long>>;
using pii = pair<int, int>;
using pil = pair<int, long>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20)
#define YES cout << "Yes" << endl
#define NO cout << "No" << endl
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define REP(i,s,t) for(int i=s; i<t; i++)
#define RNG(i,s,t,u) for(int i=s; i<t; i+=u)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
  int n;
  string s;
  cin >> n >> s;
  vvl dp(n+1,vl(n+1,0));
  rep(i,n) dp[0][i] = 1;
  rep(i,n-1){
    vl sum(n+1,0);
    rep(j,n){
      sum[j+1] = (sum[j] + dp[i][j]) % MOD;
    }
    rep(j,n-i-1){
      if(s[i] == '<'){
        dp[i+1][j] = (sum[n] - sum[j+1] + MOD) % MOD;
      }else{
        dp[i+1][j] = sum[j+1] % MOD;
      }
    }
  }
  /*rep(i,n){
    rep(j,n) cout << dp[i][j] << " ";
    cout << endl;
  }*/
  cout << dp[n-1][0] << endl;
}

Measured memory_bytes: 73748
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;
template <typename A, size_t N, typename T> void Fill(A (&array)[N], const T& val) {
    std::fill((T*)array, (T*)(array + N), val);
}
// long long mod = 998244353;
#define REP(i, n) for (long long i = 0; i < (n); i++)
#define rep(i, a, n) for (long long i = a; i < (n); i++)
typedef long long ll;
typedef pair<ll, ll> P;
long long mod = 1000000007;
long long modpow(long long m, long long n, long long modvalue) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2, modvalue);
        return t * t % modvalue;
    } else {
        return modpow(m, n - 1, modvalue) * m % modvalue;
    }
}

long long moddiv(long long a, long long b, ll modvalue) { return (a * modpow(b, mod - 2, modvalue)) % modvalue; }

const ll INF = 1LL << 60;

string change_binary(long long a) {
    string ret;
    for (int i = 31; i >= 0; i--) {
        ret += (a >> i & 1) + '0';
    }
    return ret;
}

ll nCkmod(ll n, ll k, ll modvalue) {
    ll numera = 1;
    for (int i = n; i > n - k; i--) {
        numera *= i;
        numera %= modvalue;
    }
    ll denomi = 1;
    REP(i, k) {
        denomi *= (i + 1);
        denomi %= modvalue;
    }
    return moddiv(numera, denomi, modvalue);
}

map<ll, ll> cnt;
void primeFactors(long long n) {
    while (n % 2 == 0) {
        cnt[2]++;
        n = n / 2;
    }
    for (int i = 3; i <= sqrt(n); i = i + 2) {
        while (n % i == 0) {
            cnt[i]++;
            n = n / i;
        }
    }
    if (n > 2) {
        cnt[n]++;
    }
}
int main() {
    string s, t;
    cin >> s >> t;
    map<char, char> cnt;
    REP(i, s.size()) {
        if (cnt[s[i]] == 0) {
            cnt[s[i]] = t[i];
        } else if (t[i] != cnt[s[i]]) {
            cout << "No" << endl;
            return 0;
        }
    }
    map<char, char> cnt1;
    REP(i, t.size()) {
        if (cnt1[t[i]] == 0) {
            cnt1[t[i]] = s[i];
        } else if (s[i] != cnt1[t[i]]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 3736
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t c[3][3];
  for (int32_t i = 0; i < 3; ++i) {
    for (int32_t j = 0; j < 3; ++j) {
      cin >> c[i][j];
    }
  }
  const int32_t d1 = c[1][0] - c[0][0];
  const int32_t d2 = c[2][0] - c[0][0];
  bool is_okay = true;
  for (int32_t j = 1; j <= 2; ++j) {
    if (c[1][j] - c[0][j] != d1) {
      is_okay = false;
    }
    if (c[2][j] - c[0][j] != d2) {
      is_okay = false;
    }
  }
  if (is_okay) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{
	srand(201910577);
	rand(); rand(); rand(); rand(); rand();
	int d;
	scanf("%d", &d);
	int c[30];
	int i, j, k, f, max;
	for (i = 0; i < 26; i++)
		scanf("%d", &c[i]);
	int s[400][30];
	for (i = 0; i < d; i++)
		for (j = 0; j < 26; j++)
			scanf("%d", &s[i][j]);
	int l[400][30];
	for (i = 0; i < 26; i++)
		l[0][i] = 0;
	int t[400];
	int ans = 0;
	for (i = 0; i < d; i++)
	{
		for (t[i] = 0; t[i] < 26; t[i]++)
		{
			f = ans;
			f += s[i][t[i]];
			l[i + 1][t[i]] = i + 1;
			for (j = 0; j < 26; j++)
				f -= c[j] * (i + 1 - l[i + 1][j]);
			if (t[i] == 0 || max < f)
			{
				max = f;
				k = t[i];
			}
		}
		t[i] = k; 
		ans += s[i][t[i]];
		l[i + 1][t[i]] = i + 1;
		for (j = 0; j < 26; j++)
			ans -= c[j] * (i + 1 - l[i + 1][j]);
	}
	int dd, q;
	int a;
	for (i = 1; i <= d; i++)
	{
		for (j = 0; j < 26; j++)
			l[i][j] = l[i - 1][j];
		l[i][t[i - 1]] = i;
	}
	ans = 0;
	for (i = 0; i < d; i++)
	{
		ans += s[i][t[i]];
		for (j = 0; j < 26; j++)
			ans -= c[j] * (i + 1 - l[i + 1][j]);
	}
	int ans2;
	for (k = 0; k < 250000; k++)
	{
		dd = rand() % d;
		q = rand() % 26;
		ans2 = ans;
		a = t[dd];
		ans -= s[dd][a];
		ans += s[dd][q];
		t[dd] = q;
		for (i = 0; i < d; i++)
		{
			ans += c[a] * (i + 1 - l[i + 1][a]);
			ans += c[q] * (i + 1 - l[i + 1][q]);
			l[i + 1][a] = l[i][a];
			l[i + 1][q] = l[i][q];
			l[i + 1][t[i]] = i + 1;
			ans -= c[a] * (i + 1 - l[i + 1][a]);
			ans -= c[q] * (i + 1 - l[i + 1][q]);
		}
		if (ans2 > ans)
		{
			t[dd] = a;
			ans = ans2;
			for (i = 1; i <= d; i++)
			{
				for (j = 0; j < 26; j++)
					l[i][j] = l[i - 1][j];
				l[i][t[i - 1]] = i;
			}
		}
	}
	for (i = 0; i < d; i++)
		printf("%d\n", t[i] + 1);
	return 0;
}

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

int main(){
  int a,b;
  cin >> a >> b;
  int ans = 0;
  ans = a*b;
  if( a > 9 || b > 9 ) ans = -1;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256