akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cstring>
#include <cstdio>

using namespace std;

int a[3005];
vector <int> v[3005];

int memo[3005];

int dp(int x) {
	if (memo[x] != -1) return memo[x];
	int sol = 0;
	for (int i=0 ; i<v[x].size() ; i++) {
		if (dp(v[x][i]) == 0) sol = 1;
	}
	return memo[x] = sol;
}

int main() {
	memset(memo, -1, sizeof memo);
	int n;
	scanf("%d", &n);
	for (int i=1 ; i<=n ; i++) {
		scanf("%d", a+i);
	}
	for (int i=0 ; i<n-1 ; i++) {
		int x, y;
		scanf("%d%d", &x, &y);
		if (a[x]>a[y]) v[x].push_back(y);
		if (a[y]>a[x]) v[y].push_back(x);
	}
	for (int i=1 ; i<=n ; i++) {
		if (dp(i)) printf("%d ", i);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
signed main() 
{ 
    int n;
    cin>>n;
    vector<pii> adj[n];
    for(int i=0;i<n;i++)
    {
        int m;
        cin>>m;
        for(int j=0;j<m;j++)
        {
            int x,y;
            cin>>x>>y;
            adj[i].pb({x,y});
        }
    }
    int ans = 0;
    for(int i=0;i<((int)1<<n);i++)
    {
        int flag = 1;
        int cnt = __builtin_popcount(i);
        for(int j=0;j<n;j++)
        {
            if(i&((int)1<<j))
            {
                for(auto it:adj[j])
                {
                    int x = it.first;
                    int y = it.second;
                    x--;
                    if(((i>>x)&1)^y)
                    {
                        flag = 0;
                       // cout<<x<<" "<<y<<endl;
                    }
                }
            }
        }
        if(flag)
        {
            //cout<<i<<" "<<cnt<<endl;
            ans = max(ans,cnt);
        }
    }
    cout<<ans;
} 



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

int main(){
   int n,a;
   cin >> n;
   
   double bunbo = 0;
  
  rep(i,n){
    cin >> a;
    bunbo += 1.0/a;
  }
  double ans = 1.0/bunbo;
  cout << ans << endl;
}

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

int main()
{
  string s;
  cin >> s;
  
  bool app[27];
  rep(i,27) app[i] = false;
  
  int n = s.size();
  rep(i,n){
    if(!app[s[i] - 'a']){
      app[s[i] - 'a'] = true;
    }else{
      cout << "no" << endl;
      return 0;
    }
  }
  
  cout << "yes" << endl;
}


Measured memory_bytes: 3484
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Graphi = vector<vi>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};

int main(){

    int n; cin >> n;
    vi a(n),b(n);
    rep(i,n){
        cin >> a.at(i) >> b.at(i);
    }
    sort(all(a));
    sort(all(b));
    int ans;
    if(n%2 == 1){
        int s = a.at(n/2);
        int e = b.at(n/2);
        ans = e-s+1;
    }
    else{
        double s = (a.at(n/2)+a.at(n/2-1))/2.0;
        double e = (b.at(n/2)+b.at(n/2-1))/2.0;
        ans = (e-s)*2+1;
    }
    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 4840
N,M = map(int, input().split())
edge= [[] for i in range(N+1)]
for i in range(M):
    a,b = map(int, input().split())
    edge[a].append(b)
    edge[b].append(a)

import itertools
per = itertools.permutations([i for i in range(1,N+1)])
ans = 0
for item in per:
    if item[0] != 1:
        continue
    f = True
    for ind,num in enumerate(item):
        if ind + 1<= N-1:
            nnum = item[ind+1]
            if nnum not in edge[num]:
                f = False

    if f:
        ans += 1

print(ans)


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

// typedef
// -----------------------------------------------------------------------------
typedef long long ll;
typedef long double ld;

// container util
// -----------------------------------------------------------------------------
#define ALL(c)  (c).begin(),(c).end()
#define SZ(c) ((ll)(c).size())
#define MAX(c) *max_element(ALL(c))
#define MIN(c) *min_element(ALL(c))
#define SORT(c) sort((c).begin(),(c).end())

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

// constant
// -----------------------------------------------------------------------------
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);

// debug
// -----------------------------------------------------------------------------
#define DUMP(x)  cerr << #x << " = " << (x) << endl


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    int N; cin >> N;
    int ans = 0;
    FOR(i, 1, N + 1) {
        int x; cin >> x;
        if (i % 2 == 0) {
            continue;
        }
        if (x % 2 == 0) {
            continue;
        }
        ans++;
    }
    cout << ans << "\n";
}

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for (int i=0; i<N; i++) cin >> l.at(i);
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  int ans = accumulate(l.begin(), l.begin()+K, 0);
  cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sun Jun 16 20:56:35 2019

@author: Yamazaki Kenichi
"""

W, H, x, y = map(int,input().split())

print(W*H/2)

if W / 2 == x and H / 2 == y:
    print(1)
else:
    print(0)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

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

		//System.out.prlong("2x3行列と3x2行列の積を求めます\n");

		int n = sc.nextInt(); // 3
		int m = sc.nextInt(); // 2
		int l = sc.nextInt(); // 3

		long a[][]=new long[n][m];
		long b[][]=new long[m][l];
		long c[][]=new long[n][l];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				long num=sc.nextInt();
				a[i][j]=num;
			}
		}
		for(int i=0;i<m;i++){
			for(int j=0;j<l;j++){
				long num=sc.nextInt();
				b[i][j]=num;

			}
		}

		sc.close();

		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++){
				long sum=0;
				for(int k=0;k<m;k++){
					sum+=a[i][k]*b[k][j];
				}
				c[i][j]=sum;

			}

		}
		for(int i=0;i<n;i++){
			for(int j=0;j<l;j++) {
				System.out.print(c[i][j]);
				if(j != l-1) System.out.print(" ");
			}
			System.out.println("");
		}
	}
}


Measured memory_bytes: 53632
#include <iostream>
#include <cmath>
using namespace std;
long long a, b, k, maxu, sum;
int final[100], t[100];
long long  f(long long x);
void add(int x);
void change(long long x);
int main()
{
	cin>>a>>b;
	if(a==0)
	{
		change(f(b));
		add(k);
	}	
	else
	{
		change(f(a-1));
		add(k);
		change(f(b));
		add(k);
	}
	for(int i=0;i<maxu;i++)
	{
		if(final[i]==1)
		{
			sum+=pow(2,i);
		}
	}
	cout<<sum;
	return 0;
	
}

long long  f(long long x)
{
	x++;
	if(x%2==0)
	{
	    if(x%4==0)
	    {
	    	return 0;
		}
		else
		{
			return 1;
		}
	}
	else
	{
		if((x-1)%4==0)
		{
			return x-1;
		}
		else
		{
			if((x-1)%2==0)
			{
				return x;
			}
			else
			{
				return x-2;
			}
		}
	}
}

void add(int x)
{
	for(int i=0;i<x;i++)
	{
		if(final[i]+t[i]==1)
		{
			final[i]=1;
		}
		else
		{
			final[i]=0;
		}
	}
}

void change(long long x)
{
	k=0;
	while(x)
	{
		t[k++]=x%2;
		x/=2;
	}
	if(k>maxu)
	{
		maxu=k;
	}
}

Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int n,m,a[100],i,j,x,b;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
	}
	x=0;
	b=0;
	while(1){
		b++;
		for(i=0;i<n-1;i++){
			// printf("a=%d a+1=%d  b=%d\n",a[i],a[i+1],b);
			if(a[i]%b>a[i+1]%b){
				x=a[i];
				a[i]=a[i+1];
				a[i+1]=x;
			}
		}
		if(b==m){
			break;
		}
	}
	
	// printf("\n");
	for(i=0;i<n;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}



Measured memory_bytes: 2760
D = int(input())
C = list(map(int, input().split()))
S = list(list(map(int, input().split())) for i in range(D))
T = list(int(input()) for i in range(D))
manzoku = 0
yasumi= [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
#1日目
for day in range(D):
  yasumi = list(map(lambda x: x + 1, yasumi))
  yasumi[T[day] - 1] = 0
  manzoku += S[day][T[day] - 1]
  for i in range(26):
    manzoku -= C[i] * yasumi[i]
  print(manzoku)

Measured memory_bytes: 9516
#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<iomanip>
#include<set>
#include<bitset>
#include<cmath>
#include<numeric>
#include<limits>

#define REP(i, m, n) for(int i = (m); i < (n); i++)
#define rep(i,n) REP(i,0,n)
#define NIL -1
using namespace std;
typedef long long ll;
typedef long long int lli;
static const int MOD = 10000007;
static const int MAX = 100005;

string s;
int N;


int gcd(int a, int b) {
  if ( b > a ) swap(a, b);
  int r = 1;
  while (r > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main(){
  cin >> N;
  cout << N*N*N << endl;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		final Scanner sc = new Scanner(System.in);
		
		while(true){
			final int k = sc.nextInt();
			
			if(k == 0){
				break;
			}
			
			int sum = 0;
			for(int i = 0; i < (k *(k - 1))/2; i++){
				sum += sc.nextInt();
			}
			
			System.out.println(k == 1 ? sum : sum / (k - 1));
		
		}
	}

}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mod 1000000007
#define int long long int
#define endl "\n"

void solve(int n, int k) {
  int nos = 0;
  int mins,maxs,diff;
  for(int i=k; i<=n+1; i++) {
    mins = i*(i-1)/2;
    maxs = i*(2*n-i+1)/2;
    diff = maxs - mins +1;
    nos = (nos%mod + diff%mod)%mod;
  }
  cout << nos << endl;
}

int32_t main() {
  FASTIO;
  int n,k; cin >> n >> k;
  solve(n, k);
  return 0;
}

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

static_assert(LDBL_MANT_DIG >=64);

int main()
{
    int64_t A;
    long double B;
    cin >> A >> B;
    int64_t b=(int64_t)(B*100.0L+0.5);

    cout << A*(b)/100 << endl;

}


Measured memory_bytes: 3696
import sys
input = sys.stdin.readline
ri = lambda: int(input())
#rl = lambda: [int(x) if x.isdecimal() else x for x in input().split()]
#rl = lambda: list(input().split()))
rl = lambda: map(int,input().split())
rr = lambda N: [list(l) for l in zip(*[rl() for _ in range(N)])]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18
MOD = 10**9+7

N=ri()
W=list(rl())
ans = INF
sW = [0]*(N+1)
for i in range(N):
    sW[i] = W[i]
    sW[i] += sW[i-1]

for i in range(N):
    ans = min(ans, abs(sW[i]-(sW[N-1]-sW[i])))

print(ans)

Measured memory_bytes: 3064
n,x,y=map(int,input().split())

from collections import deque
from collections import Counter

def bfs(i): # i番目の頂点を起点にしたbfs
    visited=[0]*n
    visited[i]=1
    que=deque([])
    que.append((i,1))
    
    while len(que)>0:
        di,c=que.popleft()
        nm=di-1
        np=di+1
        no=-1
        if di==x-1:
            no=y-1
        if di==y-1:
            no=x-1
        if 0<=nm and visited[nm]==0:
            visited[nm]=c+1
            que.append((nm,c+1))
        if np<=n-1 and visited[np]==0:
            visited[np]=c+1
            que.append((np,c+1))
        if no>=0 and visited[no]==0:
            visited[no]=c+1
            que.append((no,c+1))
    return visited

l=[0]
myc=Counter(l)
for i in range(n):
    myc += Counter(bfs(i))
ans=list(myc.values())
p=len(ans)
for i in range(2,n+1):
    if i>=p:
        print(0)
    else:
        print(ans[i]//2)

Measured memory_bytes: 94684
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector< int > vi;
typedef vector< ll > vll;
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define fi first
#define se second
#define endl '\n'
#define mod 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define all(c) (c).begin(),(c).end()
#define inf INT_MAX

int main(void) {
	boost
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	ll t;
	cin>>t;
    if(t>=30){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
	return 0;
}

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

int main(){
    long long int n,m,ans=0;
    cin>>n>>m;
    vector<long long int>a(200000);
    vector<long long int>b(200000);
    for(int i=0;i<m;i++){
        cin>>a[i];
        a[i]+=100000;
    }
    sort(a.begin(),a.end(),greater<>());
    for(int i=0;i<m-1;i++){
        b[i]=a[i]-a[i+1];
    }
    sort(b.begin(),b.end(),greater<>());
    for(int i=0;i<m-n;i++){
        ans+=b[m-2-i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3328
/*
------------------------------|بسم الله الرحمن الرحيم|------------------------------//
------------"IN THE NAME OF ALLAH, THE MOST GRACIUOS, THE MOST MERCIFUL"-------------//
__________________________________ShahnawazShaikh_____________________________________
*/
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] x) throws java.lang.Exception{
	Scanner sc=new Scanner(System.in);
    short a=sc.nextShort();
    System.out.println(a+a*a+a*a*a);
	

	}

}

Measured memory_bytes: 35656
#include<stdio.h>
int main(void){
int n,x,i,j,k,count;
while(1){
  scanf("%d %d",&n,&x);
  if(n==0&&x==0) break;
  else{
      count=0;
	for(i=1;i<=n-2;i++){
	  for(j=i+1;j<=n-1;j++){
	    for(k=j+1;k<=n;k++){
		if(i+j+k==x) count++;
	    }
	  }
	}
  printf("%d\n",count);
  }
}
return(0);
}


Measured memory_bytes: 2144
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long int lint;
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<vector<int>> graph(n);
    char temp;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            cin >> temp;
            if (temp == '1') {
                graph[i].push_back(j);
            }
        }
    }
    //二部グラフか判定
    vector<int> index(n, -1);
    queue<int> q_bip;
    q_bip.push(0);
    index[0] = 0;
    while (q_bip.size() > 0) {
        int target = q_bip.front();
        for (int i = 0; i < graph[target].size(); i++) {
            if (index[graph[target][i]] == -1) {
                index[graph[target][i]] = 1 - index[target];
                q_bip.push(graph[target][i]);
            } else if (index[graph[target][i]] == index[target]) {
                cout << -1 << endl;
                return 0;
            }
        }
        q_bip.pop();
    }
    int ans = 0;
    //各頂点ごとにもっとも遠い地点までの距離を求める
    for (int i = 0; i < n; i++) {
        int dist;
        queue<pair<int, int>> q_dist;
        q_dist.push(make_pair(i, 0));
        vector<int> arrived(n, 0);
        arrived[i] = 1;
        while (q_dist.size() > 0) {
            pair<int, int> target = q_dist.front();
            dist = target.second;
            for (int j = 0; j < graph[target.first].size(); j++) {
                int dest = graph[target.first][j];
                if (arrived[dest] == 0) {
                    arrived[dest] = 1;
                    q_dist.push(make_pair(dest, target.second + 1));
                }
            }
            q_dist.pop();
        }
        ans = max(ans, dist);
    }
    cout << ans + 1 << endl;
}

Measured memory_bytes: 512
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr ll INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<int> b(n+1, 0);
    vector<int> ans;
    for(int i=n; i>0; i--){
        int cntb = 0;
        for(int j=1; ; j++){
            if(n < j * i) break;
            
            cntb += b[j * i];
        }

        if(cntb % 2 != a[i]){
            b[i]++;
            ans.emplace_back(i);
        }
    }

    int sz = ans.size();
    cout << sz << endl;
    for(int i=0; i<sz; i++){
        cout << ans[i] << " \n"[i == sz - 1];
    }
}

Measured memory_bytes: 3192
#include <algorithm>
#include <iostream>
#include <string>
#include <random>
#include <cassert>
#include <cstring>
#include <chrono>
#include <set>
#include <map>

using namespace std;

typedef long long ll;
typedef vector<int> vi;

int DFS(int v, int cur, int mi, vi& d, vi& color, vi& len, vector<vector<pair<int, int>>>& g) {
  if (color[v] != -1) return 0;
  color[v] = cur;
  int result = 1;
  for (auto p : g[v]) {
    int w = p.first;
    if (d[w] != mi) continue;
    len[p.second] = mi;
    result += DFS(w, cur ^ 1, mi, d, color, len, g);
  }
  return result;
}

bool Solve(int v, vi& d, vi& color, vi& len, vector<vector<pair<int, int>>>& g) {
  if (color[v] != -1) return true;
  for (auto p : g[v]) {
    int w = p.first;
    if (color[w] != -1) { 
      len[p.second] = d[v];
      color[v] = color[w] ^ 1;
      return true;
    }                  
    if (d[w] == d[v]) {
      DFS(v, 0, d[v], d, color, len, g);
      return true;
    }
  }
  return false;
}

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> d(n), color(n, -1);
  int mi = 1e9;
  for (int i = 0; i < n; ++i) {
    cin >> d[i];
    mi = min(mi, d[i]);
  }
  vector<vector<pair<int, int>>> g(n);
  vector<int> a(m), b(m), len(m);
  for (int i = 0; i < m; ++i) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    g[a[i]].push_back(make_pair(b[i], i));
    g[b[i]].push_back(make_pair(a[i], i));
    len[i] = 1e9;
  }
  for (int i = 0; i < n; ++i) if (d[i] == mi && color[i] == -1) {
    int comp = DFS(i, 0, mi, d, color, len, g);
    if (comp == 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<pair<int, int>> v;
  for (int i = 0; i < n; ++i) v.push_back(make_pair(d[i], i));
  sort(v.begin(), v.end());
  for (auto q : v) {
    int i = q.second;
    if (!Solve(i, d, color, len, g)) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; ++i) {
    char cur = 'B';
    if (color[i]) cur = 'W';
    cout << cur;
  }
  cout << endl;
  for (int i = 0; i < m; ++i) cout << len[i] << endl;
  return 0;
}


Measured memory_bytes: 15476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pa;
#define MM 1000000000
#define MOD MM+7
#define MAX 10100000
#define INF 1e15
#define MAP 110
#define initial_value -1
#define LINF 1LL << 60
#define Pair pair<int,int>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
int dx[4] = {-1,0,1,0};
int dy[4] = {0,-1,0,1};
ll N,M;
ll A[100100],B[100100];
vector<pa> P;
int main(){
    cin >> N >> M;

    for(ll i = 0; i < N; i++){
        cin >> A[i] >> B[i];
        P.push_back(make_pair(A[i],B[i]));
    }
    sort(P.begin(),P.end());
    ll cnt = 0;
    ll m = M;
    for(ll i = 0; i < N; i++){
        if(P[i].second < m){
            cnt += P[i].first * P[i].second;
            m -= P[i].second;
        } else {
            cnt += P[i].first * m;
            m -= P[i].second;
            break;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3444
n , k = map(int,input().split())
a = list(map(int,input().split()))
f = list(map(int,input().split()))
a.sort()
f.sort(reverse=True)
lef = -1
rig = 10**13

while rig - lef != 1:
    now = (rig + lef) //2
    cou = 0
    for i in range(n):
        t = now // f[i]
        cou += max(0,a[i]-t)
    if cou <= k:
        rig = now
    elif cou > k:
        lef = now
print(rig)

Measured memory_bytes: 113672
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N,X = mi()

Ls = list(mi())

ichi = 0
ans = 1
for l in Ls:
  ichi += l
  if ichi <= X: ans += 1
  else: break

print(ans)



Measured memory_bytes: 38384
import sys
sys.setrecursionlimit(10 ** 6)

def main():
    N = int(input())
    A = list(map(int, sys.stdin.readline().rstrip().split()))

    x1 = sum([a if i % 2 == 0 else -a for i, a in enumerate((A))])
    X = [x1]
    for i in range(1, N):
        xi = 2 * A[i-1] - X[i-1]
        X.append(xi)
    
    print(*X)


if __name__ == '__main__':
    main()

Measured memory_bytes: 14028
#include<iostream>
using namespace std;
int main(){
    int a,b,c,i;
    int sum=0;
    cin>>a>>b>>c;
    for(i=1;sum<c;i++){
        sum+=a;
        if(i%7==0)
            sum+=b;
    }
    cout<<i-1<<endl;
}


Measured memory_bytes: 3076
//2008dC
I;int parse(char *p){switch(*p){
	case 'F':return 0;
	case 'T':return 1;
	case '-':return !parse(p+1);
	case '(':{
		int x=0;
		char *q=++p;
		for(;;p++){
			if(*p=='(')x++;
			if(*p==')')x--;
			if(x==0&&*p!='-')break;
		}
		switch(*(++p)){
			case '*':return parse(q)&parse(p+1);
			case '+':return parse(q)|parse(p+1);
			case '-':return !parse(q)|parse(p+2);
		}
	}
}return (I>>(*p-97))&1;}
char p[1001],*q;main(){for(;scanf("%s",p),*p-'#';puts(I==2048?"YES":"NO")){
for(q=strchr(p,'=')+1,I=0;I<2048;I++)if(parse(p)!=parse(q))break;
}exit(0);}

Measured memory_bytes: 552
N = int(input())
L = [[1]* 201 for _ in range(201)] 

def gcd (a,b):
  if a < b:
    a, b = b, a
  A, B = a, b
  if L[a][b] != 1:
    return L[a][b]
  while b:
    a,b = b, a % b
  L[A][B] = a
  return a

ans = 0
for x in range(1,N+1):
  for y in range(1,N+1):
    for z in range(1,N+1):
      t = gcd(x,y)
      u = gcd(t,z)
      ans += u
print (ans)

Measured memory_bytes: 70280
num_max,a,b = map(int,input().split())
total_count = 0
for num in range(1,num_max+1):
    count = 0
    num_str = str(num)
    for i in num_str:
        count += int(i)
    if count <= b and count >= a:
        total_count += num
print(total_count)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int main(void)
{
  int n;
  int cnt=0;

  cin >> n;
  
  for(int i=0; i<3 ;i++){
    if((n/10)%10 == n%10){
      cnt++;
      if(cnt>=2){
	break;
      }
    }
    else{
      cnt=0;
    }
    
    n/=10;
  }
  
  cout << ((cnt>=2) ? "Yes" : "No") << endl;

  return 0;
}   
 


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	int n, r;
	cin >> n >> r;
	int i;
	if (n >= 10)i = r;
	else i = r + 100 * (10 - n);
	cout << i;
	return 0;
}

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

int main(){
    int ans=0;
    vector<int> abc(3);
    for(int i=0;i<3;i++) cin >> abc[i];
    sort(abc.begin(),abc.end());
    if((abc[1]-abc[0])%2!=0){
        abc[0]++;abc[2]++;ans++;
    }
    ans+=(abc[1]-abc[0])/2;
    ans+=abc[2]-abc[1];
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
words = []
word = ""
for i in range(N):
  moji = input()
  if moji in words:
    print('No')
    exit()
  else:
    if word=="":
      word=moji
      words.append(moji)
    else:
      if word[-1]==moji[0]:
        words.append(moji)
        word=moji
      else:
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <numeric>//accumulate(v.begin(), v.end(), 0);
#include <algorithm>//sort(v.begin(),v.end());
#include <string>//
#include <cmath>
#include <iomanip> //setprecision(2)
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << min(b / a, c) << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define min(a, b) ((a)<(b) ? (a) : (b))
#define max(a, b) ((a)>(b) ? (a) : (b))
#define swap(a, b) do{ long long int t = a; a = b; b = t; }while(0)

long long int array[1000002] = {0};

void dfs(int d, long long int val, long long int luns[]){
  luns[++luns[0]] = val;
  //  printf("%lld\t%lld\n", luns[0], val);  

  if(d == 10)  return;

  for(int i=max(0, val%10-1); i<=min(9, val%10+1); i++){
    dfs(d+1, val*10+i, luns);
  }
}

void quick(long long int array[], int left, int right){
  int pl = left, pr = right;
  long long int x = array[(left + right) / 2];
  do{
    while(array[pl] < x)  pl++;
    while(array[pr] > x)  pr--;
    if(pl <= pr){
      swap(array[pl], array[pr]);
      pl++, pr--;
    }
  }while(pl <= pr);
  if(pl < right)  quick(array, pl, right);
  if(pr > left)  quick(array, left, pr);
}

int main(){
  int k;  scanf("%d", &k);

  for(int i=1; i<10; i++)  dfs(1, i, array);

  quick(array, 1, array[0]);

  printf("%lld\n", array[k]);

  return 0;
}


Measured memory_bytes: 1664
import java.util.*;

class Main {
	Scanner sc;
	String S;
	
	private void calc() {
		sc = new Scanner(System.in);
		S = sc.next();
		int c = 0;
		int l = S.length();
		for (int i = 0; i < l/2; i++) {
			if (S.charAt(i) != S.charAt(l-i-1)) c++;
		}
		System.out.println(c);
	}

	public static void main(String[] args) {
		new Main().calc();
	}
}

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

s=[[0]*W for i in range(H)]

for i in range(H):
    cnt = 0
    temp=input()

    for j in range(W):
        if temp[j]!="#":
            cnt+=1
        else:
            if j==0:
                continue
            else:
                for k in range(cnt):
                    s[i][j-(1+k)]=cnt
                cnt=0
    if cnt!=0:
        for k in range(cnt):
            s[i][W-1 - k] = cnt
        cnt = 0

ans=[]
mx=0
for i in range(W):
    cnt=0
    for j in range(H):
        if s[j][i]!=0:
            cnt+=1
            mx=max(mx,s[j][i])
        else:
            if j==0:
                continue
            else:
                ans.append(mx+cnt-1)
                cnt=0
                mx=0
    if cnt!=0:
        ans.append(mx+cnt-1)
        mx=0
print(max(ans))



Measured memory_bytes: 169396
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1000000007;
int main(){
  ll n;
  cin >> n;
  vector<ll> t(n),a(n),h(n);
  for(int i=0;i<n;i++){
    cin >> t[i];
  }
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  ll ans=1;
  h[0]=1;
  h[n-1]=1;
  for(int i=1;i<n-1;i++){
    if(t[i-1]==t[i]){
      if(a[i]==a[i+1]){
        h[i]=min(t[i],a[i]);
      }
      else{
        if(t[i]>=a[i]){
          h[i]=1;
        }
        else{
          h[i]=0;
        }
      }
    }
    else{
      if(a[i]==a[i+1]){
        if(t[i]<=a[i]){
          h[i]=1;
        }
        else{
          h[i]=0;
        }
      }
      else{
        if(t[i]==a[i]){
          h[i]=1;
        }
        else{
          h[i]=0;
        }
      }
    }
  }
  for(int i=0;i<n;i++){
    ans*=h[i];
    ans%=mod;
  }
  if(t[n-1]!=a[0]){
    ans=0;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


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


int main() {
    int r, D, x[2020];
    cin >> r >> D >> x[2000];
    for (int i = 2000; i < 2010; i++) {
        x[i + 1] = r * x[i] - D;
        cout << x[i + 1] << endl;
    }
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using P = pair<ll,ll>;
const ll mod = 1e9+7;
#define ALL(x) (x).begin(),(x).end()
#define pow(x,y) modpow(x,y)
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REPS(i,n) for(ll (i)=1;(i)<=(n);(i)++)
#define RREP(i,n) for(ll (i)=(n-1);(i)>=0;(i)--)
#define RREPS(i,n) for(ll (i)=(n);(i)>0;(i)--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());

template <class T = int>T in(){
    T x;
    cin >> x;
    return (x);
}

template<class T> inline void chmin(T& a, T b){
    if (a > b){
        a = b;
    }
}

template<class T> inline void chmax(T& a, T b){
    if (a < b){
        a = b;
    }
}

/* modつき二分累乗法 */
ll modpow(ll a, ll b) {
    ll res = 1;
    for (a = a; b; a = a * a , b >>= 1){
        if (b & 1) res = res * a;
    }
    return res;
}


signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    int N = in()-1, K = in();
    ll answer = K;
    answer *= modpow(K-1,N);
    cout << answer << "\n";
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<random>
#include<stdio.h>
using namespace std;

typedef long long ll;

int main(){
    ll N;
    cin>>N;
    vector<ll> A(N);
    vector<ll> B(N);

    for (ll i=0;i<N;i++){
        cin>>A[i];
    }
    for (ll i=0;i<N;i++){
        cin>>B[i];
    }

    std::priority_queue<pair<ll,ll>> que;
    for (ll i=0;i<N;i++){
        pair<ll,ll> P;
        P.first=B[i];
        P.second=i;
        que.push(P);
    }
    ll count=0;
    while (que.size()){
        ll val;ll index;
        pair<ll,ll> P;
        P=que.top();
        que.pop();
        val=P.first;index=P.second;
        if (index!=N-1 and index!=0){
            ll a,b,c;
            a=B[index-1];b=B[index];c=B[index+1];
            if (a==A[index-1] and c==A[index+1]){
                if (B[index]%(a+c)==A[index]%(a+c)){
                    count+=(b-A[index])/(a+c);
                    B[index]=A[index];
                }
                else{
                    count=-1;
                    break;
                }
            }
            else{
                if (B[index]>a+c){
                    count+=B[index]/(a+c);
                    B[index]%=a+c;
                    P.first=B[index];
                    que.push(P);
                }
            }
        }
        else if (index==N-1){
            ll a,b,c;
            a=B[index-1];b=B[index];c=B[0];
            if (a==A[index-1] and c==A[0]){
                if (B[index]%(a+c)==A[index]%(a+c)){
                    count+=(b-A[index])/(a+c);
                    B[index]=A[index];
                }
                else{
                    count=-1;
                    break;
                }
            }
            else{
                if (B[index]>a+c){
                    count+=B[index]/(a+c);
                    B[index]%=a+c;
                    P.first=B[index];
                    que.push(P);
                }
            }
        }
        else{
            ll a,b,c;
            a=B[N-1];b=B[index];c=B[index+1];
            if (a==A[N-1] and c==A[index+1]){
                if (B[index]%(a+c)==A[index]%(a+c)){
                    count+=(b-A[index])/(a+c);
                    B[index]=A[index];
                }
                else{
                    count=-1;
                    break;
                }
            }
            else{
                if (B[index]>a+c){
                    count+=B[index]/(a+c);
                    B[index]%=a+c;
                    P.first=B[index];
                    que.push(P);
                }
            }
        }
    }
    int flag=0;
    for (ll i=0;i<N;i++){
        if (A[i]!=B[i]){
            flag=1;
        }
    }
    if (flag==0){
        cout<<count<<endl;
    }
    else{
        cout<<-1<<endl;
    }
}

Measured memory_bytes: 9584
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i) = 0; (i) <(n); (i)++) 
#define so(v) sort(v.begin(),v.end())
using ll = long long;
using vi=vector<int>;
using vii=vector<vi>;
const int MAX = 510000;
const int MOD = 998244353;
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
  ll n;cin>>n;
  ll ans=0;
  rep(a,n){
    rep(b,n){
    rep(c,n){
    ans+=gcd(a+1,gcd(b+1,c+1));
  }
  }
  }
  cout<<ans<<endl;
}

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

typedef long long ll;

int main(){
  ll K;cin>>K;
  ll r=K%50, q=K/50;
  ll a[50];
  for (int i=0;i<50;++i){
    if (i<=r-1){a[i]=100+q-r-1;}else{
      a[i]=50+q-r-1;
    }
  }
  cout << 50 << endl;
  for (int i=0;i<50;++i){
    cout << a[i] << ' ';
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <string>
#include <array>
#include <cmath>
#include <queue>
#include <stack>
#include <numeric>
using namespace std;

int main(){
    string s,t;
    cin>>s>>t;
    int cnt = 0;
    for(int i=0; i<s.length(); i++){
        if(s[i] != t[i])cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 3892
#include <atcoder/lazysegtree>
#include <cstdio>

using namespace std;
using namespace atcoder;

struct S {
    // # of 0 / # of 1 / inversion number
    long long zero, one, inversion;
};

// swapping flag
using F = bool;

S op(S l, S r) {
    return S{
        l.zero + r.zero,
        l.one + r.one,
        l.inversion + r.inversion + l.one * r.zero,
    };
}

S e() { return S{0, 0, 0}; }

S mapping(F l, S r) {
    if (!l) return r;
    // swap
    return S{r.one, r.zero, r.one * r.zero - r.inversion};
}

F composition(F l, F r) { return (l && !r) || (!l && r); }

F id() { return false; }

int main() {
    int n, q;
    scanf("%d %d", &n, &q);

    vector<S> a(n);
    for (int i = 0; i < n; i++) {
        int x;
        scanf("%d", &x);
        if (x == 0)
            a[i] = S{1, 0, 0};
        else
            a[i] = S{0, 1, 0};
    }

    lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
    for (int i = 0; i < q; i++) {
        int t, l, r;
        scanf("%d %d %d", &t, &l, &r);
        l--;
        if (t == 1) {
            seg.apply(l, r, true);
        } else {
            printf("%lld\n", seg.prod(l, r).inversion);
        }
    }
}


Measured memory_bytes: 19720
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <cmath>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define SORT(c) sort((c).bigin(), (c).end())

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

    int ans = n;
    if (n == 100)
        ans = 101;
    if (d == 1)
        ans *= 100;
    if (d == 2)
        ans *= 10000;

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int n,q;

void solve(){
    int i,j;
    string str;
    cin >> n >> q;
    cin >> str;
    vector<char> t(q),d(q);
    for(i = 0;i < q;i++) cin >> t[i] >> d[i];
    long long ans = 0;
    int r,l;
    int s,e,m;
    int p,f;
    s = -1; e = n;
    while(e-s > 0){
        m = (s+e)/2;
        p = m; f = 0;
        for(i = 0;i < q;i++){
            if(str[p] == t[i]){
                if(d[i] == 'L'){
                    if(p == 0){
                        f = 1;
                        break;
                    }
                    else p--;
                }
                else{
                    if(p == n-1){
                        break;
                    }
                    else p++;
                }
            }
        }
        if(f){
            if(s == m) break;
            s = m;
        }
        else{
            if(e == m) break;
            e = m;
        }
    }
    r = s;
    s = -1; e = n;
    while(e-s > 0){
        m = (s+e)/2;
        p = m; f = 0;
        for(i = 0;i < q;i++){
            if(str[p] == t[i]){
                if(d[i] == 'L'){
                    if(p == 0){
                        break;
                    }
                    else p--;
                }
                else{
                    if(p == n-1){
                        f = 1;
                        break;
                    }
                    else p++;
                }
            }
        }
        if(f){
            if(e == m) break;
            e = m;
        }
        else{
            if(s == m) break;
            s = m;
        }
    }
    l = e;
    cout << l-r-1 << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 900
list = input().split(' ')
(A,B,K)=(int(list[0]),int(list[1]),int(list[2]))
if A >= K:
    A = A - K
elif 1 <= A < K:
    B = B - K + A
    if B < 0:
        B = 0
    A = 0
else:
    A = 0
    B = B - K
    if B < 0:
        B = 0
print(A,B)

Measured memory_bytes: 3064
#include <queue>
#include <cstdio>
#include <iostream>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;

#define EPS (1e-9)
#define INF (1e9)
#define PI (acos(-1))
#define REP(i,n) for(int i=0;i<n;i++)

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

ll beki(ll a, ll b) {
	ll tmp = 1;
	REP(i, b) tmp *= a;
	return tmp;
}

int N;
int A[100010];
vector<int> dp;

int main() {
	cin >> N;
	REP(i, N) {
		int tmp;
		cin >> tmp;
		A[i] = -tmp;
	}
	REP(i, N) dp.push_back(INF);

	int ans = 0;

	//最長増加列
	REP(i, N) {
		auto it = upper_bound(dp.begin(), dp.end(), A[i]);
		int index = it - dp.begin();
		if (dp[index] == INF) ans++;
		dp[index] = A[i];
	}
	cout << ans << endl;
}

Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n;;
  cin >> n;
  string s;
  vs VS;
  rep(_, n) {
    cin >> s;
    vc VC;
    rep(i, 10) VC.push_back(s[i]);
    sort(all(VC));
    string str;
    rep(i, 10) str += VC[i];
    VS.push_back(str);
  }
  sort(all(VS));
  vl cnt(n, 1);
  ll num=0;
  rep(i, n-1) {
    if(VS[i] == VS[i+1]) cnt[num]++;
    else num++;
  }
  ll ans=0;
  rep(i, n) ans += cnt[i]*(cnt[i]-1)/2;
  cout << ans << newl;
  return 0;
}

Measured memory_bytes: 8180
import collections

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

c = collections.Counter(a)

if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0 and c[i] == 0:
            continue
        elif i % 2 == 1 and c[i] == 2:
            continue
        else:
            print(0)
            exit(0)
else:
    for i in range(n):
        if i == 0 and c[i] == 1:
            continue
        if i % 2 == 0 and c[i] == 2:
            continue
        elif i % 2 == 1 and c[i] == 0:
            continue
        else:
            print(0)
            exit(0)

print(pow(2, n // 2, 10 ** 9 + 7))



Measured memory_bytes: 93628
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
    int h, w, H, W, i, j;
    scanf("%d%d%d%d",&H,&W,&h,&w);
    int t = (H/h)*(W/w);
    int p = (1e9-1)/(h*w-1);
    if(1ll*H*W*p-1ll*t*p-t*(1ll*(h*w-1)*p+1) <= 0){
        printf("No\n");
        return 0;
    }
    printf("Yes\n");
    for(i=1;i<=H;i++){
        for(j=1;j<=W;j++){
            if(i%h==0&&j%w==0)printf("%lld ",-(1ll*(h*w-1)*p+1));
            else printf("%d ",p);
        }
        printf("\n");
    }
}

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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cerr << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = 1 << 17;
int n;
int a[N];
LL s[2]; 
bool was[2];
bool bery[N];

vector<int> solve(bool odd)
{
	vector<int> ans;
	
	for(int i = odd; i < n; i += 2)
		if (a[i] > 0)
			bery[i] = 1;
	
	vector<int> x(n);
	FOR(i, 0, n) x[i] = bery[i];
	
	while(x.back() == 0)
	{
		ans.PB(SZ(x));
		x.pop_back();
	}
	
	while(x[0] == 0)
	{
		ans.PB(1);
		reverse(ALL(x));
		x.pop_back();
		reverse(ALL(x));
	}
	
	while (SZ(x) > 1) 
	{
		if (x[2] == 1)
		{
			ans.PB(2);
			reverse(ALL(x));
			x.pop_back();
			x.pop_back();
			reverse(ALL(x));
			continue;
		}
		
		ans.PB(3);
		reverse(ALL(x));
		x.pop_back();
		x.pop_back();
		x.pop_back();
		x.PB(1);
		reverse(ALL(x));
	}	
	
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n;
	FOR(i, 0, n) cin >> a[i];
	
	FOR(i, 0, n) if(a[i] >= 0) s[i & 1] += a[i], was[i & 1] = 1;
	
	FOR(i, 0, 2)
	{
		if (was[i]) continue;
		s[i] = -LINF;
		for(int j = i; j < n; j += 2) s[i] = max(s[i], (LL)a[j]);
	}
	
	cout << max(s[0], s[1]) << endl;
	if (max(s[0], s[1]) < 0)
	{
		int pos = -1;
		FOR(i, 0, n) if (a[i] == max(s[0], s[1]))
			pos = i;
		
		cout << n - 1 << endl;
		FOR(i, 0, pos) cout << 1 << endl;
		FOR(i, 0, n - pos - 1) cout << n - pos - i << endl;		
		return 0;
	}
	
	vector<int> ans;
	if (s[0] >= s[1])
		ans = solve(0);
	else
		ans = solve(1);
	
	cout << SZ(ans) << endl;
	for(auto i: ans) cout << i << endl;
	
	//cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}


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

using namespace std;

#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n)　for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
#define Eunique(v) v.erace(unique(all(v)),v.end())
#define pvec(v)　rep(i,v.size()){cout << v[i] << " ";}
#define INF 0x3f3f3f3f
#define mset(m,v) memset(m,v,sezeof(m))
#define mod 1e9 +7;

const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef deque<ll> dll;
typedef pair<ll,ll> P;
ll dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

ll gcd(ll x,ll y)
{
    ll r;
    while((r = x % y) != 0)
    {
        x = y;
        y = r;
    }
    return y;
}

ll lcm(ll x,ll y)
{
    x /= gcd(x,y);
    y /= gcd(x,y);
    return (x*y);
}

int main()
{
    
    ll n,a,b,sum=0;
    cin >> n >> a >> b;
    rep(i,n+1){
        ll j=0,digisum=0;
        while(i/(ll)pow(10,j) > 0){
            digisum += (i/(ll)pow(10,j))%10;
            j++;
        }
        if(digisum >= a && digisum <= b)sum += i;
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools
import math
import sys
from collections import Counter
from fractions import gcd
from functools import reduce
import sys
sys.setrecursionlimit(4100000)

INF = 1 << 60

# ここから書き始める
n, k = map(int, input().split())
h = list(map(int, input().split()))
dp = [INF] * n
dp[0] = 0
for i in range(n):
    for j in range(1, k + 1):
        if i + j == n:
            break
        dp[i + j] = min(dp[i + j], dp[i] + abs(h[i] - h[i + j]))
print(dp[-1])


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 1001001001;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef tuple<string, int, int> T;

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

    vector<ll> cards(n);
    rep(i, n) {
        cin >> cards[i];
    }
    sort(cards.begin(), cards.end());


    vector<P> changes(m);
    rep(i, m) {
        ll b, c;
        cin >> b >> c;
        changes.emplace_back(c, b);
    }
    sort(changes.rbegin(), changes.rend());

    int it = 0;
    [&] {
        for (auto p : changes) {
            for (int i = 0; i < p.second; i++) {
                if (cards[it] >= p.first)return;
                cards[it] = p.first;
                it++;
                if (it == n) {
                    return;
                }
            }
        }
    }();

    cout << accumulate(cards.begin(), cards.end(), 0ll) << endl;
}



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

using namespace std;


int main() {
    int n;
    cin >> n;
    string a, b, c;
    cin >> a >> b >> c;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        char A = a[i], B = b[i], C = c[i];
        if(A != B && B != C && C != A) {
            ans += 2;
        }
        else if(A == B && B != C) {
            ans++;
        }
        else if(A == C && C != B) {
            ans++;
        }
        else if(B == C && A != B) {
            ans++;
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3624