akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
class Timer
{
  private:
    double time_limit;
    //unsigned long long int cycle_per_sec = 2500000000; // Topcoder
    unsigned long long int cycle_per_sec = 2777777777; // AtCoder
    unsigned long long int beginCycle;
    unsigned long long int getCycle()
    {
        unsigned int low, high;
        __asm__ volatile("rdtsc"
                         : "=a"(low), "=d"(high));
        return ((unsigned long long int)low) | ((unsigned long long int)high << 32);
    }

  public:
    Timer(double time_limit) : time_limit(time_limit)
    {
        beginCycle = getCycle();
    }

    double elapsedTime()
    {

        return (double)(getCycle() - beginCycle) / cycle_per_sec;
    }
    bool isTLE()
    {
        return elapsedTime() >= time_limit;
    }
};

Timer gtimer(2.85);

struct NODE
{
    int to, cost, ticket;
    NODE(int to, int cost, int ticket) : to(to), cost(cost), ticket(ticket) {}
};
bool operator<(const NODE &a, const NODE &b)
{
    return a.cost > b.cost;
}
int main()
{
    int c, n, m, s, d;
    while (cin >> c >> n >> m >> s >> d && c)
    {
        vector<NODE> g[110];

        for (int i = 0; i < m; i++)
        {
            int a, b, f;
            cin >> a >> b >> f;
            --a, --b;
            g[a].push_back(NODE(b, f, 0));
            g[b].push_back(NODE(a, f, 0));
            g[a].push_back(NODE(b, f / 2, 1));
            g[b].push_back(NODE(a, f / 2, 1));
        }
        --s, --d;
        priority_queue<NODE> Q;
        Q.push(NODE(s, 0, c));
        int done[110][11] = {};
        while (Q.size())
        {
            auto q = Q.top();
            Q.pop();
            if (q.ticket < 0)
                continue;
            if (done[q.to][q.ticket]++)
                continue;
            if (q.to == d)
            {
                cout << q.cost << endl;
                break;
            }
            for (auto e : g[q.to])
            {
                Q.push(NODE(e.to, q.cost + e.cost, q.ticket - e.ticket));
            }
        }
    }

    std::cout.flush();
    return 0;
}

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

int main() {
	int a,b;
	cin>>a>>b;
	
	for(int n=0;n<1100;n++){
		int za=n*8/100;
		int zb=n*10/100;
		
		if(a==za&&b==zb){
			cout<<n<<endl;
			return 0;
		}
	}
	
	cout<<-1<<endl;
	return 0;
}


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

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


//cout<<"hoge1"<<endl;
    int l, i=0, a[100];
    int sum=0;
    while(cin>>l){
        //cout<<i<<":"<<l<<endl;
        //cout<<"sum:"<<sum<<endl;
        a[i] = l;
        sum+=l;
        //cout << a[i];
        i++;
        if(i==n){
            break;
        }
    }

    //cout<<"sum:"<<sum<<endl;
    int const_m = m;
    int j;
    for(j=0; j<i; j++){
        //cout<<"----"<<a[j]<<endl;
        //if(a[j] >= int(sum/(4*const_m))){
        if(a[j]*(4*const_m) >= sum){
            //cout<<"hit"<<endl;
            m--;
            if(m==0){
                cout<<"Yes"<<endl;
                return 0;
            }

        }
    }
    cout<<"No"<<endl;

} // end of main

//実行は、Opt + Ctl + N

Measured memory_bytes: 256
N,K = map(int,input().split())
A = list(map(int,input().split()))

#%%
divisor = []
SA = sum(A)
for i in range(1,int(SA**0.5+1)):
    if i*i == SA:
        divisor.append(i)
    elif SA%i==0:
        divisor.append(i)
        divisor.append(SA//i)

divisor.sort()

def judge(x):
    # 全てのAiをK回以下の操作で0(mod x)にできるか？
    modlist = []
    for a in A:
        b = a%x
        modlist.append([b, x-b])
    modlist.sort()
    sum1 = [0]*(N+1)
    sum2 = [0]*(N+1)
    idx = 0
    for b,c in modlist:
        sum1[idx+1] = sum1[idx] + b
        sum2[idx+1] = sum2[idx] + c
        idx += 1
    
    res = 10**10
    for i in range(1,N+1):
        tmp = max(sum1[i], sum2[N]-sum2[i])
        res = min(res, tmp)
    
    if res>K:
        return False
    else:
        return True
    
ok = 1
for d in divisor:
    if judge(d):
        ok = d


print(ok)






Measured memory_bytes: 43996
import java.util.Scanner;

public class Main {

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

        for (int i = 1; i <= 100; i++) {
            if (a*i%b == c) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");
    }

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ll long long int
#define MOD 1000000007
#define INF 1e18

using namespace std;

int main(void){
  vector<ll> a(4);
  for (int i = 0; i < 4; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  
  if (a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
    
    
  
  
  

  return 0;
}


Measured memory_bytes: 256
row, column = map(int, input().split())
matrix = [[0] * column for i in range(row)]
vector = [0]*column
for r in range(row):
    temporary = list(map(int, input().split()))
    for c in range(column):
        matrix[r][c] = temporary[c]
for c in range(column):
    vector[c] = int(input())

for r in range(row):
    ans=0
    for c in range(column):
        ans += matrix[r][c]*vector[c]
    print(ans)
    


Measured memory_bytes: 6012
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
using namespace std;
#define MOD 1000000007
#define EPS 10e-8

int main(){
    int N,D;
    cin  >> N >> D;
    if(N%(2*D+1)==0) cout << N/(2*D+1) << endl;
    else cout << N/(2*D+1)+1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int h[4][4],w[4][4];
char b[10][20];

int f(int n,int flag){
	if(!flag&&f(n+1,1))return 1;
	if(n==4)return 1;
	for(int i=0;i<4;i++)for(int j=0;j<10;j++){
		int cnt=0;
		for(int k=0;k<4;k++){
			if(b[i+h[n][k]][j+w[n][k]]=='.')cnt++;
			b[i+h[n][k]][j+w[n][k]]^=10;
		}
		if(cnt==4&&f(n+1,flag))return 1;
		for(int k=0;k<4;k++)b[i+h[n][k]][j+w[n][k]]^=10;
	}
	return 0;
}

int main(){
	for(int n=0;n<4;n++){
		int hh,ww,cnt=0;
		scanf("%d%d",&hh,&ww);
		for(int i=0;i<hh;i++){
			char s[10];
			scanf("%s",s);
			for(int j=0;j<ww;j++)if(s[j]=='#'){
				h[n][cnt]=i;
				w[n][cnt]=j;
				cnt++;
			}
		}
	}
	int q;
	scanf("%d",&q);
	while(q--){
		for(int n=0;n<4;n++)scanf("%s",b[n]);
		puts(f(0,0)?"Yes":"No");
	}
}



Measured memory_bytes: 2080
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

using namespace std;

const int INF = numeric_limits<int>::max() / 2;

int main(){
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    for(int i = 0; i < n; i++){
        cin >> c[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(v[i] - c[i] > 0) ans += v[i] - c[i];
    }
    cout << ans << endl;
}

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

int main(){

int a[5];
int l=10;
int h=0;
for(int i=0;i<5;i++){
	cin>>a[i];
	l=min(l,(a[i]-1)%10+1);
	h+=(a[i]-1)/10+1;
}

cout<<h*10+l-10<<endl;
return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ri register int
typedef long long ll;
const int N=20,S=(1<<16)+5,mod=1e9+7;
int dp[N][S],a[N],fac[S],ifac[S],cnt[S],sz[S];
inline void add(int &x,ri y){
	x=(x+=y)>=mod?x-mod:x; 
}
inline void del(int &x,ri y){
	x=(x-=y)<0?x+mod:x;
}
inline int C(ri n,ri m){
	return m<0||n<m?0:(ll)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
inline int fpow(ri a,ri b){
	ri ans=1;
	for(;b;b>>=1,a=(ll)a*a%mod)
		if(b&1) ans=(ll)ans*a%mod;
	return ans;
}
int main(){
	ri n,m,i,j,u,s,size,ans;
	scanf("%d%d",&n,&m);
	for(i=1;i<=m;++i) scanf("%d",&a[i]);
	sort(a+1,a+1+m,greater<int>());
	size=1<<n;
	fac[0]=1;
	for(i=1;i<=size;++i) fac[i]=(ll)fac[i-1]*i%mod;
	ifac[size]=fpow(fac[size],mod-2);
	for(i=size;i;--i) ifac[i-1]=(ll)ifac[i]*i%mod;
	u=(1<<n)-1;
	for(s=1;s<=u;++s)
		cnt[s]=cnt[s^(s&-s)]+(1<<__builtin_ctz(s&-s)),
		sz[s]=sz[s>>1]+(s&1);
	//	printf("%d %d %d\n",s,sz[s],cnt[s]);
	dp[0][0]=1;
	for(i=0;i<m;++i)
		for(s=0;s<=u;++s)
			if(dp[i][s]){
				add(dp[i+1][s],dp[i][s]);
				for(j=0;j<=n-1;++j)
					if(~s&(1<<j))
						add(dp[i+1][s|(1<<j)],(ll)C(size-a[i+1]-cnt[s],(1<<j)-1)*fac[1<<j]%mod*dp[i][s]%mod);
			}
//	for(i=1;i<=m;++i)
//		for(s=0;s<=u;++s)
//			if(dp[i][s])
//				printf("dp %d %d %d %d\n",i,s,dp[i][s],size-1-cnt[s]);
	ans=0;
	for(s=0;s<=u;++s){
	//	printf("ans %d %d %d\n",s,sz[s]&1,dp[m][s]);
		if(sz[s]&1)
			del(ans,(ll)dp[m][s]*fac[size-1-cnt[s]]%mod);
		else
			add(ans,(ll)dp[m][s]*fac[size-1-cnt[s]]%mod);
	}
	ans=(ll)ans*size%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 5632
<?php
  $n = intval(fgets(STDIN));
  $dic = [];

  $cnt = 0;
  for ($i = 1; $i <= $n; $i++) {
    $s = (string)$i;
    $first = $s[0];
    $end = $s[strlen($s) - 1];
    
    if (!isset($dic[$first])) $dic[$first] = [];
    if (!isset($dic[$first][$end])) $dic[$first][$end] = 0;
    
    $dic[$first][$end]++;
     
  }

for ($i = 1; $i <= $n; $i++) {
    $s = (string)$i;
    $first = $s[0];
    $end = $s[strlen($s) - 1];
    $cnt += $dic[$end][$first];   
}

echo $cnt;

Measured memory_bytes: 3700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define int ll
//const ll mod = 1000000007;

int n, sum;
signed main() {
    cin >> n;
    int r = n;
    while(r > 0) {
        sum += (r % 10);
        r /= 10;
    }
    if (n % sum == 0) cout << "Yes" << endl;
    else cout << "No" << endl; 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
const ll MAXN=3e3+51;
ll n,x,y,res;
ll dist[MAXN][MAXN],barrel[MAXN];
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
int main()
{
	n=read(),x=read(),y=read();
	for(register int i=1;i<=n;i++)
	{
		for(register int j=1;j<=n;j++)
		{
			dist[i][j]=abs(i-j);
		}
	}
	for(register int i=1;i<=n;i++)
	{
		for(register int j=1;j<=n;j++)
		{
			if(dist[i][j]>dist[i][x]+dist[y][j]+1)
			{
				dist[j][i]=dist[i][j]=dist[i][x]+dist[y][j]+1;
			}
			if(dist[i][j]>dist[i][y]+dist[j][x]+1)
			{
				dist[j][i]=dist[i][j]=dist[i][y]+dist[j][x]+1;
			}
		}
	}
	for(register int i=1;i<=n;i++)
	{
		for(register int j=i+1;j<=n;j++)
		{
			barrel[dist[i][j]]++;
		}
	}
	for(register int i=1;i<n;i++)
	{
		printf("%d\n",barrel[i]);
	}
}

Measured memory_bytes: 24832
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define SHIFT_LEFT(n) (1LL<<((ll)n))
#define SUBS(s,f,t) ((s).substr((f),(t)-(f)))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll a = 0,b = 0,c = 0,d = 0,e = 0,n = 0,ans = 0;
  string s,ss,sss;
  cin>>a>>b;
  ans = (a*b)/2;
  if(a == 1 || b == 1){cout<<1<<endl;return 0;}
  if(a%2 && b%2)cout<<ans+1<<endl;

  else  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

//削除する要素が存在するかチェック
NodePointer listSearch(int key){

  NodePointer n,dummy = malloc(sizeof(struct node));
  
  dummy->key = -1;
  
  for(n=nil->next;n != nil;n = n->next){
    if(n->key == key){
      //見つかった
      return n;
    }
  }

  //見つからなかった
    return dummy;
  
}


//番兵を作成
void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

//表示させる
void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

//リスト最初を削除
void deleteFirst(){
  NodePointer t = nil->next;

  nil->next = t->next;
  t->next->prev = nil;
}

//リストの最後を削除
void deleteLast(){

  NodePointer delnode = nil->prev;

  nil->prev = delnode->prev;
  delnode->prev->next = nil;
  free(delnode);
}

//入力されたkeyを削除
void delete(int key){
  NodePointer t;
  NodePointer n = nil->next;

  while(n != nil){
    if(n->key == key)
      break;
    n=n->next;
  }

      t = n->prev;
      t->next = n->next;
      t->next->prev = t;
      free(n);

}

//リストの先頭に挿入する
void insert(int key){
  NodePointer x;
  static int count = 0;
  x = malloc(sizeof(struct node));
  x->key = key;

  if(count == 0){
  x->next = nil;
  nil->next = x;
  x->prev = nil;
  nil->prev = x;
  count++;
  }

  else{
    x->next = nil->next;
    nil->next->prev = x;
    nil->next = x;
    x->prev = nil;
    count++;
  }
}


int main(){
  int key, n, i;
  char com[20];
  
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s", com);

    if ( com[0] == 'i' ) {
      scanf("%d",&key);
      insert(key);
    }
    else if ( com[0] == 'd' ) {
      if (strlen(com) > 6){
	if ( com[6] == 'F' )
	  deleteFirst();
	
	else if ( com[6] == 'L' )
	  deleteLast();
      }
      else{
	scanf("%d",&key);
	if(listSearch(key)->key != -1)
	  delete(key);
      }
    }
  }
  printList();
  return 0;
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-5;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
  for(auto &e:u) fill_v<T>(e,v...);
}
int64 N, M;
vector<int64> G[100];
int64 cnt = 0;
vector<int64> ord, low;
int64 res = 0;

int64 dfs(int64 v, int64 p) {
	ord[v] = cnt++;
	low[v] = ord[v];
	REP(i, G[v].size()) {
		if (G[v][i] == p) continue;
		if (ord[G[v][i]] != -1) {
			chmin(low[v], ord[G[v][i]]);
		} else {
			chmin(low[v], dfs(G[v][i], v));
		}
	}
	REP(i, G[v].size()) {
		if (G[v][i] == p) continue;
		if (ord[v] < low[G[v][i]]) res++;
	}
	return low[v];
}

int main(void) {
	cin >> N >> M;
	REP(i, M) {
		int64 a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	ord.resize(N, -1);
	low.resize(N, -1);
	dfs(0, -1);
	cout << res << endl;
}


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

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_INF = 2147483647;
const long long LL_INF = 1LL<<60;
const long long MOD = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main(void){
    string S; cin >> S;
    int ans = INT_INF;
    REP(i,S.size()-2){
        chmin(ans, abs(753-toInt(S.substr(i,3))));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<utility>
#include<queue>
#define x first
#define y second
using namespace std;
typedef pair<int, int> PII;

int w, h, ans = 0;
bool building[102][102], checked[102][102];
queue<PII> cunt;
int dx[2][6] = { { -1, -1, -1, 0, 1, 0 }, { 0, -1, 0, 1, 1, 1 } }, dy[6] = { -1, 0, 1, 1, 0, -1 };

bool judge(PII p){
	if (0 <= p.x && p.x <= w + 1 && 0 <= p.y && p.y <= h + 1) return true;
	return false;
}

int main()
{
	cin >> w >> h;
	for (int i = 1; i <= h; i++){
		for (int j = 1; j <= w; j++) cin >> building[i][j];
	}

	cunt.push(make_pair(0, 0));
	checked[0][0] = true;
	while (!cunt.empty()){
		PII now = cunt.front();
		cunt.pop();
		for (int i = 0; i < 6; i++){
			PII next = make_pair(now.x + dx[now.y % 2][i], now.y + dy[i]);
			if (judge(next) && !checked[next.y][next.x]){
				if (building[next.y][next.x]) ans++;
				else{
					checked[next.y][next.x] = true;
					cunt.push(next);
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1244
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {

  static int n;
  static int[] ans;
  static String res;

  public static void main(String[] args) throws Exception {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);
    ans = new int[4];

    for (int i = 0; i < n; i++) {
      res = br.readLine();
      if(res.equals("AC")){
        ans[0]++;
      }
      if(res.equals("WA")){
        ans[1]++;
      }
      if(res.equals("TLE")){
        ans[2]++;
      }
      if(res.equals("RE")){
        ans[3]++;
      }
    }

    br.close();

    out.println("AC x " + ans[0]);
    out.println("WA x " + ans[1]);
    out.println("TLE x " + ans[2]);
    out.println("RE x " + ans[3]);

    out.flush();

  }
}

Measured memory_bytes: 42924
#n,k=gets.split(' ').map(&:to_i)
n=gets.split('').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
#maze = h.times.map { gets.chomp }
if n.include?(7)
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 14320
#include<stdio.h>
int main(void)
{
	int a,s,d,z,x,c,f,k,v,b,n,i;
	
	scanf("%d %d %d",&a,&s,&d);
	while(!(a==-1 && s==-1 && d==-1)){
	for(i=1;i<=100;i++){
	f=(120*60-(s*60+a*3600+d))/60;
	k=(120*60-(s*60+a*3600+d))%60;
	
	x=f/60;
	c=f%60;
	
	z=(120*60*3-(s*60+a*3600+d)*3)/60;
	n=(120*60*3-(s*60+a*3600+d)*3)%60;
	v=z/60;
	b=z%60;

	}
	printf("%02d:%02d:%02d\n",x,c,k);
	printf("%02d:%02d:%02d\n",v,b,n);
	
	scanf("%d %d %d",&a,&s,&d);
	}
	return 0;
}

Measured memory_bytes: 1040
#include <bits/stdc++.h>
#define rep(i, to) for (int i = 0; i < (to); ++i)
#define repf(i, from, to) for (int i = (from); i < (to); ++i)
#define unless(cond) if (!(cond))
using namespace std;
using ll = long long;
template <typename T>
using V = vector<T>;
template <typename T, typename U>
using P = pair<T, U>;

int main() {
  int h, w;
  cin >> h >> w;
  V<string> canvas(h, "");
  V<int> dh = {-1, 0, 0, 1};
  V<int> dw = {0, -1, 1, 0};

  rep(i, h){
    cin >> canvas[i];
  }

  bool can = true;
  rep(hi, h) {
    rep(wi, w) {
      if(canvas[hi][wi] != '#') {
        continue;
      }

      bool have_adjacent_black = false;
      rep(i, dh.size()) {
        int hj = hi + dh[i];
        int wj = wi + dw[i];

        if(hj >= 0 && hj < h && wj >= 0 && wj < w) {
          if(canvas[hj][wj] == '#') {
            have_adjacent_black = true;
            break;
          }
        }
      }

      if(!have_adjacent_black) {
        can = false;
        break;
      }
    }
  }

  if(can) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 3644
#include<iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main(void)
{
	int N;
	cin >> N;
	vector<int> a(N);
	int alice = 0, bob = 0;
	for (auto& x : a){
		cin >> x;
	}
	sort(a.begin(), a.end(), greater<int>());
	for (int i = 0; i < N; i++){
		if (i % 2 == 0){
			alice += a[i];
		}
		else{
			bob += a[i];
		}
	}

	cout << alice - bob << endl;
}

Measured memory_bytes: 256
//Author: Pakhomovee 
#include <iostream> 
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <chrono>
#include <stdlib.h>

using namespace std;
using namespace std::chrono;

#define int long long

bool found = false;
vector<int> cycle;
int lol = 0;

void dfs(int v, vector<vector<int>> &g, vector<bool> &used, vector<int> &s, int k)
{
    if (k == 0)
    {
        cout << v + 1 << endl;
        exit(0);
    }
    used[v] = true;
    s.push_back(v);
    for(int u : g[v])
    {
        if (found)
        {
            return;
        }
        if (!used[u])
        {
            dfs(u, g, used, s, k - 1);
        }
        else
        {
            while(s.back() != u)
            {
                cycle.push_back(s.back());
                s.pop_back();
            }
            cycle.push_back(u);
            lol = s.size() - 1;
            found = true;
        }
    }
    s.pop_back();
}

void solve()
{
    int n, k;
    cin >> n >> k;
    vector<vector<int>> g(n);
    for(int i = 0; i < n; ++i)
    {
        int x;
        cin >> x;
        --x;
        g[i].push_back(x);
    }
    vector<bool> used(n, false);
    vector<int> x;
    dfs(0, g, used, x, k);
    reverse(cycle.begin(), cycle.end());
    k -= lol;
    int gg = k % (long long)(cycle.size());
    cout << cycle[gg] + 1 << endl;  
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	auto start = system_clock::now();

    solve();

	auto end = system_clock::now();
	cerr << "Time: " << duration_cast<milliseconds> (end - start).count() << "ms" << endl;
}

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

using namespace std;

const int N = 2e5 + 7;
int n;


int main() {
    std :: ios :: sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    long long ans = 0;
    cin >>  n;
    map < long long,long long > mp;
    for(int i = 0 ; i < n ; ++i) {
        long long p;
        cin >> p;
        mp[p]++;
        ans += p;
    }
    int q;
    cin >> q;
    while(q--) {
        long long x, y;
        cin >> x >> y;
        /// find all x and sum
        long long x_count = mp[x];

        ans -= 1LL * x_count * x;

        ans += 1LL * x_count * y;

        mp[x] = 0;

        mp[y] += x_count;

        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 9548
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int N = in.nextInt();
            int K = in.nextInt();
            out.println(N % K == 0 ? 0 : 1);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}



Measured memory_bytes: 21460
s=input()
d_in={'/':1,'\\':-1,'_':0}
stack_h=[]
pairs_x=[]
for i in range(len(s)):
  if d_in[s[i]]==-1:
    stack_h.append(i)
  elif d_in[s[i]]==1:
    if len(stack_h)!=0:
      pairs_x.append([stack_h.pop(),i+1])
stack_ans=[]
for i in range(len(pairs_x)):
  pair_i=pairs_x.pop()
  if len(stack_ans)==0:
    stack_ans.append(pair_i)
  elif pair_i[1]<=stack_ans[-1][0]:
    stack_ans.append(pair_i)
area=[0]*len(stack_ans)
sum_area=0
for i in range(len(stack_ans)):
  p=stack_ans.pop()
  h=0
  for j in range(p[0],p[1]):
    area[i]+=h
    h-=d_in[s[j]]
  sum_area+=area[i]

print(sum_area)
if len(area)==0:
  print(0)
else:
  print(len(area),end=' ')
  print(' '.join(map(str,area)))


Measured memory_bytes: 6972
total = int(input())
numbers = input().split()
time = 0
flag = False
while True:
  for number in numbers:
    if int(number)%2 != 0:
      flag = True
      break;
  else:
    numbers = [(int(j) / 2) for j in numbers]
    time = time + 1
  if flag:
    break
print(time)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <cmath>
#define Rint register int
#define LL long long
#define F(x,y,z) for(Rint x=y;x<=z;++x)
using namespace std;
inline LL R(){
    char c='!';LL x=0,z=1;
    for( ; c>'9'||c<'0';c=getchar()) if(c=='-')z=-1;
    for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
    return x*z;
}
int n,m;
LL anss;
int a[1000010];
 
int main(){
	n=R();
	F(i,1,n) a[i]=R();
	int la=0,too=0,lanow=0;
	F(i,1,n){
		int now=lanow-a[i-1];
		anss+=la-i+1;
		F(j,la+1,n){
			
			if ((now^a[j])==(now+a[j])) ++anss,now^=a[j];
			else break;
			too=j;
		}
		la=too;lanow=now;
	}
	printf("%lld\n",anss);
	return 0;
}
 

Measured memory_bytes: 896
//55
#include<iostream>
#include<string>

using namespace std;

int main(){
  int n;
  cin>>n;
  while(n--){
    int b=0,ans=0,out=0;
    for(string s;cin>>s;){
      if(s=="HIT"){
	b++;
	if(b==4){
	  ans++;
	  b=3;
	}
      }else if(s=="OUT"){
	out++;
	if(out==3)break;
      }else{
	ans+=b+1;
	b=0;
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main(){
    ft
    int i,l,r;
    for(i=1;i<6;i++){
        cin>>l;
        if(l==0){
            r=i;
        }
    }
    cout<<r<<"\n";
    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int *arr=new int[n];
    for(int i=0;i<n;i++)
        cin>>arr[i];
    int *dp=new int[n]();
 for(int i=1;i<n;i++)
 {if(i==1)
 {
     dp[i]=dp[i-1]+abs(arr[i]-arr[i-1]);
 }
  else
     dp[i]+=min(dp[i-1]+abs(arr[i]-arr[i-1]),dp[i-2]+abs(arr[i]-arr[i-2]));
 }
    //for(int i=0;i<n;i++)
      //  cout<<dp[i]<<" ";
    //cout<<endl;
    cout<<dp[n-1]<<endl;
}

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

int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;

    ll ans=a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);
    cout<<ans;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#define Ll long long
using namespace std;
const int N=2e5+5;
vector<int>h[N];
int n,m,x,y;
void dfs(int x,int y){
	if(y>2)return;
	if(x==n){cout<<"POSSIBLE";exit(0);}
	for(int k=0;k<h[x].size();k++)
		dfs(h[x][k],y+1);
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		h[x].push_back(y);
	}
	dfs(1,0);
	cout<<"IMPOSSIBLE"; 
}

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

template<typename T, typename U> void cmax(T &a, U b) { if (a < b) a = b; }
template<typename T, typename U> void cmin(T &a, U b) { if (a > b) a = b; }

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);

  int G = 0;
  long mx = LONG_MIN;
  for (auto a : A) G = gcd(G, a), cmax(mx, a);

  cout << ((K % G == 0 && K <= mx) ? "POSSIBLE" : "IMPOSSIBLE") << "\n";
}

Measured memory_bytes: 3648
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
bool is(int n, int a, int b) {
	int sum = 0;
	while (n > 0) {
		sum += n % 10;
		n /= 10;
	}
	bool res = (a <= sum && sum <= b);
	return res;
}

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int sum = 0;
	rep(i, n+1) {
		if (is(i, a, b)) sum += i;
	}
	cout << sum << endl;

	return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  srand((unsigned)time(NULL));
  int D;
  cin >> D;
  int c[26];
  int las[26];
  int choose[D];
  for (int i = 0; i < 26; i++) {
    cin >> c[i];
    las[i] = 0;
  }
  int s[D][26];
  for (int i = 0; i < D; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s[i][j];
    }
  }
  
  for (int i = 1; i <= D; i++) {
    int score[26];
    for (int j = 0; j < 26; j++) {
      score[j] = 0;
      score[j] += s[i-1][j];
      for (int k = 0; k < 26; k++) {
        if (j != k) {
          score[j] -= c[k] * (i - las[k]);
        }
      }
    }
    int chose = -1;
    int max_score = -99999999;
    for (int j = 0; j < 26; j++) {
      if (score[j] > max_score) {
        chose = j;
        max_score = score[j];
      }
    }
    las[chose] = i;
    choose[i-1] = chose + 1;
  }
  int ans = 0;
  for (int i = 1; i <= D; i++) {
    int scor = 0;
    scor += s[i-1][choose[i-1] - 1];
    for (int j = 0; j < 26; j++) {
      if (choose[i-1] - 1 != j) {
        scor -= c[j] * (i - las[j]);
      }
    }
    las[choose[i-1] - 1] = i;
    ans += scor;
    
  }
  for (int i = 0; i < 1000000; i++) {
    int d,q;
    d = rand() % D;
    q = rand() % 26;
    d++; q++;
    int oldchosen = choose[d-1];
    int diff = 0;
    diff -= s[d-1][choose[d-1]-1];
    diff += s[d-1][q-1];
    int p = choose[d-1];
    int nextp = D+1;
    int prevp = 0;
    int nextq = D+1;
    int prevq = 0;
    for (int i = d; i < D; i++) {
      if (choose[i] == p) {
        nextp = i+1;
        break;
      }
    }
    for (int i = d; i < D; i++) {
      if (choose[i] == q) {
        nextq = i+1;
        break;
      }
    }
    for (int i = d-2; i >= 0; i--) {
      if (choose[i] == p) {
        prevp = i+1;
        break;
      }
    }
    for (int i = d-2; i >= 0; i--) {
      if (choose[i] == q) {
        prevq = i+1;
        break;
      }
    }
    diff -= (d - prevp) * (nextp - d) * (c[p-1]);
    diff += (d - prevq) * (nextq - d) * (c[q-1]);
    if (diff > 0) {
      choose[d-1] = q; 
    } else {
      choose[d-1] = oldchosen;
    }
  }

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

Measured memory_bytes: 3680
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

int main()
{
    fast;
    int k;
    cin>>k;
    int a, b;
    cin>>a;
    cin>>b;
    
    if(((b/k)-((a-1)/k))>0)
        cout<<"OK";
    else
        cout<<"NG";
    
    return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end()))
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[8] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr int DX[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

std::vector<long long> get_divisors(long long n) {
    std::vector<long long> ret;
    long long i;
    for (i = 1; i * i < n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            ret.push_back(n / i);
        }
    }
    if (i * i == n) { ret.push_back(i); }
    std::sort(ret.begin(), ret.end());
    return ret;
}

int N;
int A[220000];
int ap[1100000];
signed main() {
    cin >> N;
    rep(i, N) { cin >> A[i]; }
    rep(i, N) {
        ap[A[i]]++;
    }
    int ans = 0;
    rep(i, N) {
        int cnt = 0;
        vint v = get_divisors(A[i]);
        rep(j, v.size()) { cnt += ap[v[j]]; }
        if (cnt == 1) { ans++; }
    }
    cout << ans << endl;
}


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

int a[100005],l[100005],r[100005];

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  int n;cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
  }
  l[0]=a[0];r[n-1]=a[n-1];
  for(int i=1;i<n;i++){
    l[i]=__gcd(a[i],l[i-1]);
    r[n-i-1]=__gcd(a[n-i-1],r[n-i]);
  }
  int ans=max(r[1],l[n-2]);
  for(int i=1;i<n-1;i++){
    ans = max(ans, __gcd(l[i-1],r[i+1]));
  }

  cout<<ans<<endl;

  
  return 0;
}


Measured memory_bytes: 4784
#include <iostream>
#include <vector>
#include<algorithm>
#include<string>
#include<stdio.h>
#include<map>
#include<math.h>
#include<queue>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
const int mod = 1000000007;
const int INF = 1000000001;
const long long LINF = 1e18;
const int MAX = 510000;

int main() {
	int n;
	long long int ans = 0;
	cin >> n;
	vector<int> a(n+1), b(n);
	for (int i = 0; i < n+1; i++) {
		cin >> a.at(i);
	}
	for (int i = 0; i < n; i++) {
		cin >> b.at(i);
	}
	for (int i = 0; i < n ; i++) {
		if (b.at(i) <= a.at(i))ans += b.at(i);
		else {
			ans += a.at(i);
			if (a.at(i + 1) >=b.at(i)- a.at(i)) {
				ans += b.at(i) - a.at(i);
				a.at(i + 1) = a.at(i + 1) -(b.at(i)- a.at(i));
			}
			else {
				ans += a.at(i + 1);
				a.at(i + 1) = 0;
			
			}
			
		}
	}
	cout << ans << endl;
		return 0;
	}


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

using namespace std;

long long a, b, c, d, f[4], h[3], k[2], n, g;

int main()
{
	cin >> a >> b >> c >> d >> n;
	f[0] = a * 8;
	f[1] = b * 4;
	f[2] = c * 2;
	f[3] = d;
	sort (f, f + 4);
	h[0] = a * 4;
	h[1] = b * 2;
	h[2] = c;
	sort (h, h + 3);
	g += (n / 2) * f[0];
	n = n % 2;
	g += (n) * h[0];
	cout << g;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>
#include <numeric>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

long long N;

long long count753(long long n)
{
    if(n > N) return 0;
    long long temp = n;
    bool flag[3];
    REP(i,3)
    {
        flag[i] = false;
    }
    while(temp > 0)
    {
        long long a = temp % 10;
        temp /= 10;
        if(a == 3) flag[0] = true;
        if(a == 5) flag[1] = true;
        if(a == 7) flag[2] = true;
    }
    if(flag[0]&&flag[1]&&flag[2]) 
    {
        return 1+count753(n*10+3)+count753(n*10+5)+count753(n*10+7);
    }
    else
    {
        return count753(n*10+3)+count753(n*10+5)+count753(n*10+7);
    }
    
}

int main(void)
{
    cin >> N;
    cout << count753(0) << endl;
}



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

typedef long long LL;

const LL mod = 1e9+7;

const int maxn = 400+10;

LL fac[maxn][maxn];
LL facsum[maxn][maxn];


int A[maxn],B[maxn];
int n,C;

LL dp[maxn][maxn];

int main()
{
 //  freopen("./test.txt","r",stdin);
    for(int i = 1;i < maxn;++i)
        fac[0][i] = 1;
    for(int i = 1;i < maxn;++i)
        for(int j = 1;j < maxn;++j)
            fac[i][j] = fac[i-1][j]*j%mod;

    for(int i = 0;i < maxn;++i)
    {
        facsum[i][0] = 0;
        for(int j = 1;j < maxn;++j)
            facsum[i][j] = (facsum[i][j-1] + fac[i][j])%mod;
    }

    scanf("%d %d",&n,&C);
    for(int i = 1;i <= n;++i)
        scanf("%d",&A[i]);
    for(int i = 1;i <= n;++i)
        scanf("%d",&B[i]);
    memset(dp,0,sizeof(dp));

    dp[0][C] = 1;
    for(int i = 0;i < n;++i)
        for(int j = C;j >= 0;--j)
        {
            if(dp[i][j] == 0) continue;
            for(int giv = j;giv >= 0;--giv)
            {

                int lft = j-giv;
                int L = A[i+1],R = B[i+1];

                LL t = (facsum[giv][R]-facsum[giv][L-1]+mod)%mod;
                t = t*dp[i][j]%mod;
                dp[i+1][lft] = (dp[i+1][lft] + t)%mod;

            }
        }


    LL res = dp[n][0];
    printf("%lld\n",res);
    return 0;

}


Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var inputs = Console.ReadLine().Split(' ');
        var i = 1;

        foreach(var item in inputs)
        {
            if(int.Parse(item) == 0)
            {
                Console.WriteLine(i);
            }
            i++;
        }

        Console.Read();
    }


}

Measured memory_bytes: 17852
from collections import deque

MAX_N = 400
di = (1, 0, -1, 0)
dj = (0, 1, 0, -1)

def can_extend(i, j, d, H, W, color):
    ni = i + di[d]
    nj = j + dj[d]
    if not (0 <= ni < H and 0 <= nj < W):
        return False
    if color[i][j] == color[ni][nj]:
        return False
    return True


def solve(H, W, color):
    ans = 0
    is_used = [[False] * MAX_N for i in range(MAX_N)]
    for i in range(H):
        for j in range(W):
            if is_used[i][j]:
                continue
            black = 0
            white = 0
            que = deque()
            is_used[i][j] = True
            que.append((i, j))
            while que:
                p = que.popleft()
                ci = p[0]
                cj = p[1]
                if color[ci][cj]:
                    black += 1
                else:
                    white += 1

                for d in range(4):
                    if not can_extend(ci, cj, d, H, W, color):
                        continue
                    ni = ci + di[d]
                    nj = cj + dj[d]
                    if is_used[ni][nj]:
                        continue
                    is_used[ni][nj] = True
                    que.append((ni, nj))

            ans += black * white

    return ans


H, W = [int(v) for v in input().split()]
s = [input() for i in range(H)]
color = []
for row in s:
    color.append([v == '#' for v in row])

print(solve(H, W, color))

Measured memory_bytes: 6124
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second
constexpr char ln =  '\n';

const int mx=100010;
const ll mod=1e9+7;


int main(){
  int n,w;
  cin >> n >> w;
  vector<ll> a(n),b(n);
  rep(i,n){
    cin >> a[i] >> b[i];
  }

  vector<vector<ll>> dp(110, vector<ll>(mx,longinf));
  dp[0][0]=0;
  rep(i,n)rep(j,mx){
    dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    if(j-b[i]>=0) dp[i+1][j] = min(dp[i+1][j], dp[i][j-b[i]]+a[i]);
  }
  int ans = -1;
  for(int i=mx-1; i>=0; i--){
    if(dp[n][i]<=w){
      ans = i; break;
    }
  }
  cout << ans << ln;
  return 0;
}

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

#include <fstream>

#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <tuple>
#include <queue>
#include <functional>
#include <stack>
#include <cassert>

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int,int>> vii;

class atB {
private:
    /*int dfs(int u, vector<vector<int>> &g, int ind) {
        int depth = 0;
        for (int v : g[u]) {
            depth = max(depth, dfs(v, g)+1);
        }
        if (ind < (int)g[u].size()) {
            depth = max(depth, dfs(u, g, ind+1)+1);
        }
        return depth;
    }*/
    
    int solve(int i, const vector<int> &dp, vector<int> &res, const vector<vector<int>> &g) {
        if (res[i] != -1) {
            return res[i];
        }
        
        if (dp[i] == 0) {
            return 0;
        }
        
        int ans = 0;
        vector<int> sz;
        for (int j = 0; j < (int)g[i].size(); ++j) {
            sz.push_back(solve(g[i][j], dp, res, g));
        }
        sort(sz.begin(), sz.end(), greater<int>());
        for (int j = 0; j < (int)sz.size(); ++j) {
            ans = max(ans, j+1 + sz[j]);
        }
        
        return (res[i] = ans);
        
    }
    
public:
    void solve(istream& in, ostream& out) {
        int N;
        in >> N;
        
        vector<int> a(N+1);
        for (int i = 2; i <= N; ++i) {
            in >> a[i];
        }
        vector<vector<int>> g(N+1);
        for (int i = 2; i <= N; ++i) {
            g[a[i]].push_back(i);
            //g[a[i]].push_back(a[i]);
        }
        vector<int> dp(N+1), res(N+1, -1);
        for (int i = 0; i <= N; ++i) {
            dp[i] = g[i].size();
        }
        int ans = solve(1, dp, res, g);
        /*sort(dp.begin(), dp.end());
        vector<int> dp2(N+1, 0);
        for (int i = 0; i <= N; ++i) {
            if (dp[i].first == 0) {
                dp2[dp[i].second] = 0;
            }
        }*/
        out << ans << endl;
        
    }
};


int main() {
	std::ios::sync_with_stdio(false);

	atB solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 14720
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n = I()
    k = I()
    num = 1
    for i in range(n):
        num = min(num+k, num*2)
    ans = num
    print(ans)

main()


Measured memory_bytes: 74608
#include<iostream>
using namespace std;
int n,k,ans=1;
int main()
{
    cin>>n>>k;
    for(int i=1;i<=n;i++)
      {
          if(k<ans)ans+=k;
             else ans*=2;
      }
    cout<<ans<<endl;
    return 0;
}
/*
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
  int ans=1,n,k; 
  scanf("%d%d",&n,&k);
  while(n--)
	  ans+=min(ans,k);
  printf("%d",ans);
  return 0;
}*/


Measured memory_bytes: 384
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<long long>;
using pll = pair<long long, long long>;
#define rep(i,n) for(long long i(0);(i)<(n);(i)++)
ll INF = 1LL << 60;

const string YES = "YES";
const string NO = "NO";

void solve(long long N, std::vector<long long> D, long long M, std::vector<long long> T){
    map<ll, ll> rec;
    rep(i, N){
        rec[D[i]]++;
    }
    rep(i, M){
        if(rec.count(T[i]) && rec[T[i]]>0)
            rec[T[i]] --;
        else{
            cout << NO << endl;
            return ;
        } 
    }
    cout << YES << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> D(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&D[i]);
    }
    long long M;
    scanf("%lld",&M);
    std::vector<long long> T(M);
    for(int i = 0 ; i < M ; i++){
        scanf("%lld",&T[i]);
    }
    solve(N, std::move(D), M, std::move(T));
    return 0;
}


Measured memory_bytes: 15872