akhauriyash/Code-Regression huggingface dataset:
using System;
using static System.Console;

class Program
{
    public static void Main()
    {
        string s = ReadLine();
        if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
        {
            WriteLine("Yes");
        }
        else
        {
            WriteLine("No");
        }
    }
}


Measured memory_bytes: 11092
import java.io.PrintWriter;
import java.util.*;

public class Main {
    PrintWriter out = new PrintWriter(System.out);
    public static void main(String[] args) {
        Main main = new Main();
        System.out.println(main.solve());
    }
    long solve(){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n+1];
        long ans = 0;
        for(int i=1;i<=n;i++) {
            a[i]=sc.nextLong();
            ans += a[i]*(i%2==1?1:-1);
        }
        // find y1
        long[] y = new long[n+1];
        y[1] = ans/2;
        for(int i=2;i<=n;i++){
            y[i] = a[i-1]-y[i-1];
        }
        for(int i=1;i<=n;i++) out.print(String.format("%d ",2*y[i]));
        out.flush();
        System.exit(0);
        return 0;
    }
}

Measured memory_bytes: 89160
K, N = map(int, input().split())
l = list(map(int, input().split()))
s = [l[i+1]-l[i] for i in range(N-1)]
c1 = max(s)
c2 = (K-l[-1])+l[0]
d = K - max(c1, c2)
print(d)

Measured memory_bytes: 26420
while True:
    p=0
    n,x=map(int,input().split())
    if n==0 and x==0:
        break
        
    for a in range(1,n-1):
        for b in range(a+1,n):
            for c in range(b+1,n+1):
                s=a+b+c
                if s==x:
                    p=p+1
    print(p)


Measured memory_bytes: 5596
N = input()
N = int(N)
Fs =  [list(map(int,input().split(" "))) for _ in range(N)]
Ps =  [list(map(int,input().split(" "))) for _ in range(N)]
ans = -(10**10)
for flag in range(1,2 ** 10): #開店スケジュールに対応
    temp = 0
    for shop in range(N):
        op = 0

        for i in range(10): #曜日に対応
            if flag & (1 << i):
                c = 1#ある曜日にやっているか
            else:
                c = 0
            if Fs[shop][i] * c == 1:
                op += 1

        temp +=Ps[shop][op]
    if temp > ans:
        ans =temp
print(ans)

Measured memory_bytes: 3188
n, k = map(int, input().split())
aa = []
for _ in range(n):
    a, b = map(int, input().split())
    aa.append([a, b])
aa.sort()
c = 0
for a, b in aa:
    if c < k:
        c += b
        if c >= k:
            ans = a
            break
print(ans)

Measured memory_bytes: 20192
/*
Author : Xinyuan
*/
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef long long int  ll;
const int INF = 1e9 + 7;
const int mod = 1e9 + 7;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
int nxt() {int x;scanf("%d", &x);return x;}


int main(){
    string x;
    cin >> x;
    int y = 0;
    for (int i = 0; i < x.length(); i++) {
        y += x[i] - '0';
    }
    if (y % 9 == 0) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
}



Measured memory_bytes: 3736
import java.io.*;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    
    String[] data = br.readLine().split(" ");
    long w = Integer.parseInt(data[0]);
    long h = Integer.parseInt(data[1]);
    double x = Integer.parseInt(data[2]);
    double y = Integer.parseInt(data[3]);
    int multipleAns = (x==w/2.0 && y==h/2.0 ? 1 : 0);
    
    System.out.println(w*h/2.0 + " " + multipleAns);
  }
}


Measured memory_bytes: 22996
function main( args ) {
  let N = BigInt(args);
  if ( N < 2n ) return console.log('0');
  let count = 0;
  for ( let p = 2n; p*p <= N; p++ ) {
    if ( N % p === 0n ) {
      let z = p;
      while(N%z===0n)N/=z,z*=p,count++;
      while(N%p===0n)N/=p;
    }
  }
  if ( N > 1n ) count++;
  console.log(count.toString());
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

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

    int n, m;
    cin >> n >> m;
    set<int> st1;
    set<int> stn;
    for (int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        if (a == 1)
        {
            st1.insert(b);
        }
        else if (b == 1)
        {
            st1.insert(b);
        }

        if (a == n)
        {
            stn.insert(b);
        }
        else if (b == n)
        {
            stn.insert(a);
        }
    }

    bool ans = false;
    for (auto i : st1)
    {
        if (stn.find(i) != stn.end()) ans = true;
        if (ans) break;
    }

    if (ans)
    {
        cout << "POSSIBLE" << endl;
    }
    else 
    {
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

Measured memory_bytes: 9600
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let o = get!(String).chars().collect::<Vec<_>>();
    let e = get!(String).chars().collect::<Vec<_>>();
    let len = o.len();
    let mut s = Vec::new();
    for i in 0..len {
        s.push(o[i]);
        if i < e.len() { s.push(e[i]) };
    }
    println!("{}", s.into_iter().collect::<String>());
}

Measured memory_bytes: 4352
#include<stdio.h>

int main() {
  int i, j, a[1000], n, temp, cnt=0;

  scanf("%d", &n);
  for(i = 0; i < n; i++) scanf("%d", &a[i]);

  for(i = 0; i < n; i++){
    for(j = n - 1; j != i; j--){
      if(a[j] < a[j - 1]){
        temp = a[j];
        a[j] = a[j-1];
        a[j-1] = temp;
	cnt++;
      }
    }
  }
  for(i = 0; i < n; i++){
      printf("%d", a[i]);
      if(i < n-1) printf(" ");
      else printf("\n%d\n", cnt);
  }
  return 0;
}



Measured memory_bytes: 2144
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

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

bool check(vector<string>S,int x,int y){
    if(S[y][x]=='.') return true;
    for(int i=0;i<4;i++){
        int nx,ny;
        nx = x+dx[i];
        ny = y+dy[i];
        if(nx>=0&&nx<W&&ny>=0&&ny<H){
            if(S[ny][nx]=='#') return true;
        }
    }
    return false;
}

int main(){
    cin >> H >> W;
    vector<string> S(H);
    rep(i,H) cin >> S[i];
    bool flg = true;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            flg = check(S,j,i);
            if(!flg){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    if(flg) cout <<"Yes"<<endl;
    return 0;
}

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

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

 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    int N;
    ll K;
    cin >> N >> K;
    ll P[N],C[N];
    rep(i,N) {
        ll p;
        cin >> p;
        p--;
        P[i] = p;
    }
    rep(i,N) {
        ll c;
        cin >> c;
        C[i] = c;
    }
    ll ans = -1e18;
    
    rep(i,N) {
        //i = 1;
        set<ll> seen;
        vector<ll> A;
        ll psum = 0;
        ll s = i;
        ll c = 0;

        while(1) {
            A.push_back(C[P[s]]);
            psum += C[P[s]];
            c++;
            s = P[s];
            if (s==i) break; 
        }

        ll tmp = 0;
        rep(j,c) {
            if (j+1>K) break;
            tmp += A[j];
            ans = max(tmp,ans);
            int e = (K-(j+1))/c;
            if (e>0) {
                ans = max(ans,tmp+psum*e);
            }
        }
    }
    cout << ans << endl;


}


Measured memory_bytes: 3816
import re
N = int(input())
s = [input() for i in range(N)]

count_AB = 0
count_A = set()
count_B = set()

for i in range(N):
    _s = s[i]
    if _s[0] == "B":
        count_B.add(i)
    if _s[len(_s)-1] == "A":
        count_A.add(i)
    count_AB += len(re.findall("AB", _s))


inter = (count_A & count_B)
count_max = max(len(count_A), len(count_B))
count_min = min(len(count_A), len(count_B))
cnt = 0
if len(inter) == 0:
    cnt = count_min
elif len(inter) == count_max:
    cnt = len(inter) - 1
else:
    cnt = count_min


print(count_AB + cnt)


Measured memory_bytes: 5868
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
#define rep(i, n) for(int i=0;i<(int)n;i++)
#define PI acos(-1)
#define fast_io ios_base::sync_with_stdio(false) ; cin.tie(0); cout.tie(0);
ll mod=1e9+7;

int main(){
    fast_io

    int n;
    cin >> n;
    vector<ll> A(n), B(n), C(n);
    rep(i,n) cin >> A[i];
    rep(i,n) cin >> B[i];
    rep(i,n) cin >> C[i];
    sort(A.begin(), A.end());
    // sort(B.begin(), B.end());
    sort(C.begin(), C.end());
    ll ans = 0;
    rep(i,n){
        ll num = B[i];
        auto iter_a = upper_bound(A.begin(), A.end(), num-1);
        auto iter_c = lower_bound(C.begin(), C.end(), num+1);
        ans += (iter_a - A.begin()) * (C.end() - iter_c);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5568
/*#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>*/
#include <bits/stdc++.h>

using namespace std;
//using namespace __gnu_pbds;
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound

const int MOD = 1000000007;
double PI = 4*atan(1);

int N, c1, c2, c3;

int main() {
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> N; 
	F0R(i,N) {
	    int x; cin >> x;
	    if (x % 4 == 0) c1 ++;
	    else if (x % 2 == 0) c2 ++;
	    else c3 ++;
	}
	if (c3 <= c1) cout << "Yes";
	else if (c3 == c1+1) {
	    if (c2 == 0) cout << "Yes";
	    else cout << "No";
	} else if (c3 > c1+1) cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int h, w;
    cin >> h >> w;

    rep(i, h) {
        string c;
        cin >> c;
        rep(j, 2) put(c);
    }
    
    return 0;
}

Measured memory_bytes: 3592
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<n;i++)
#define REP(i,n) for(int (i)=1;(i)<=n;i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=2005;
int n,k;
int a[maxn];
vector<int>edge[maxn],child[maxn];
bool vis[maxn];

class Array{
public:
	int len;
	int a[maxn];
	Array(){len=0;}
	Array operator + (const Array &o)const{
		Array res=*this;
		rep(i,o.len)res.a[res.len++]=o.a[i];
		return res;
	}
	Array operator * (const Array &o)const{
		Array res;
		int p1=0,p2=0;
		while(p1<len||p2<o.len){
			if(p2==o.len||(p1<len&&a[p1]>o.a[p2]))res.a[res.len++]=a[p1++];
			else res.a[res.len++]=o.a[p2++];
		}
		return res;
	}
	void print(){
		REP(i,len-1)printf("%d%c",a[i],i==len-1?'\n':' ');
	}
}val[maxn];

int gcd(int a,int b){
	return !b?a:gcd(b,a%b);
}

void dfs(int x){
	vis[x]=true;
	rep(i,edge[x].size()){
		if(!vis[edge[x][i]]){
			dfs(edge[x][i]);
			child[x].pb(edge[x][i]);
		}
	}
}

void work(int x){
	Array tmp;
	tmp.len=1;
	tmp.a[0]=a[x];
	rep(i,child[x].size()){
		work(child[x][i]);
		val[x]=val[x]*val[child[x][i]];
	}
	val[x]=tmp+val[x];
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d",&n);
	REP(i,n)scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	REP(i,n)for(int j=i;j<=n;j++)if(gcd(a[i],a[j])!=1){
		edge[i].pb(j);
		edge[j].pb(i);
	}
	REP(i,n)sort(edge[i].begin(),edge[i].end());
	REP(i,n)if(!vis[i])dfs(i),child[0].pb(i);
	work(0);
	val[0].print();
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 61056
h,w=map(int,input().split())
m=[]
for _ in range(h):
    l=input()
    if '#' in l:
        m.append(l)
m=list(zip(*m))
n=[]
for i in m:
    if '#' in i:
        n.append(i)
n=list(zip(*n))
for i in n:
    for j in i:
        print(j,end='')
    print('')


Measured memory_bytes: 4596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll N; cin>>N;
    vector<vector<ll>>a(N-1,vector<ll>(3));
    rep(i,N-1){
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    }
    ll ans;
    for(int i=0;i<N-1;i++){
        ans=0;
        ans+=a[i][1];
        ans+=a[i][0];
        for(int j=i+1;j<N-1;j++){
            ans=max(a[j][1],(ans+a[j][2]-1)/a[j][2]*a[j][2]);
            ans+=a[j][0];
        }
        cout<<ans<<endl;

    }
    cout<<0<<endl;
}




Measured memory_bytes: 384
n = int(input())
arr = list(map(int, input().split()))

while len(arr) > 1:
    m = len(arr)
    if m & 1:
        arr.append(1)
        m += 1

    left, right = arr[:m // 2], arr[m // 2:]
    arr = [x * y for x, y in zip(left, right)]

x = arr[0]
if x > 10 ** 18:
    print(-1)
else:
    print(x)


Measured memory_bytes: 21644
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <iomanip>

typedef long double ld;
typedef long long ll;

using namespace std;

ll MOD = ((ll)1e9 + 7);

struct mod {
	ll x;

	mod(ll tx = 0) {
		x = tx;
	}
	
	mod& operator=(const ll & tx) {
		x = tx;
		return *this;
	}
	
	mod& operator=(const mod & m2) {
		x = m2.x;
		return *this;
	}

	mod operator+(const mod& m2) const {
		return (x + m2.x) % MOD;
	}

	mod& operator+=(const mod& m2) {
		x += m2.x;
		x %= MOD;
		return *this;
	}

	mod operator-(const mod & m2) const {
		return (x - m2.x + MOD) % MOD;
	}

	mod& operator-=(const mod & m2) {
		x -= m2.x;
		x = (x + MOD) % MOD;
		return *this;
	}

	mod operator*(const mod & m2) const {
		return (x * m2.x) % MOD;
	}

	mod& operator*=(const mod & m2) {
		x *= m2.x;
		x %= MOD;
		return *this;
	}

	mod mypow(ll k) const {
		mod ret = 1;
		mod cur = x;
		while (k) {
			if (k & 1) {
				ret *= cur;
			}
			cur *= cur;
			k >>= 1;
		}
		return ret;
	}

	mod inv() const {
		return mypow(MOD - 2);
	}

	mod operator/(const mod & m2) const {
		return mod(((*this).x * (*this).inv().x) % MOD);
	}

	mod& operator/=(const mod & m2) {
		x *= m2.inv().x;
		x %= MOD;
		return *this;
	}

	bool operator<(const mod & m2) const {
		return x < m2.x;
	}
};

ostream &operator<<(ostream & os, const mod & m) {
	return os << m.x;
}

/* TEMPLATE ENDS HERE */

multiset<ld> s;

#define EPS 1e-9

int main() {
	cout << fixed << setprecision(12);	
	int n, m;
	cin >> n >> m;
	for (int i = 0, t; i < n; i++) {
		cin >> t;
		s.insert(t);
	}
	for (int i = 0; i < m; i++) {
		ld t = *s.rbegin();
		s.erase(s.find(t));
		s.insert(t/2);
	}
	ll ret = 0;
	for (auto& e: s) {
		ret += (ll)(e + EPS);
	}
	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 9876
#include<stdio.h>
main(){
  int height[20];
  int i,j,temp;

  for(i=0;i<10;i++){
    scanf("%d",&height[i]);
  }

  for(i=0;i<3;i++){
    for(j=9;j>i;j--){
      if(height[i]<height[j]){
	temp=height[i];
	height[i]=height[j];
	height[j]=temp;
      }
    }
  }

  printf("%d\n%d\n%d\n",height[0],height[1],height[2]);

  return 0;
}

Measured memory_bytes: 600
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define MOD 1000000007
signed main(){
	int n,m;
	cin>>n>>m;
	int ans=0;
	int a=0,b=0;
	bool bef=false;
	int d=1;
	for(int i=0;;i++){
		if(a==n&&b==m){
			ans+=d;
			break;
		}
		else if(a>n||b>m){
			break;
		}
		if(bef==false){
			a++;
			d*=a;
			d%=MOD;
			bef=true;
		}
		else{
			b++;
			d*=b;
			d%=MOD;
			bef=false;
		}
	}
	d=1;
	bef=true;
	a=0,b=0;
	for(int i=0;;i++){
		if(a==n&&b==m){
			ans+=d;
			break;
		}
		else if(a>n||b>m){
			break;
		}
		if(bef==false){
			a++;
			d*=a;
			d%=MOD;
			bef=true;
		}
		else{
			b++;
			d*=b;
			d%=MOD;
			bef=false;
		}
	}
	cout<<ans%MOD<<endl;
	return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;
    vector<int> arr(n);
    vector<int> dp(n);
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }

    dp[0] = 0;
    dp[1] = abs(arr[0] - arr[1]);

    for (int i = 2; i < n; i++) {
        dp[i] = min(dp[i - 1] + abs(arr[i] - arr[i - 1]),
                    dp[i - 2] + abs(arr[i] - arr[i - 2]));
    }
    cout << dp[n - 1];
    return 0;
}


Measured memory_bytes: 1024
def cz(A):
    N = len(A)
    F = [0]
    for i in range(N):
        if A[i] == 0:
            F.append(0)
        else:
            F.append(1)

    res = 0
    for i in range(N):
        if F[i] == 0 and F[i+1] == 1:
            res += 1

    return(res)

N = int(input())
H = list(map(int,input().split()))

cnt = 0
while sum(H) > 0:
    cnt += cz(H)
    for i in range(N):
        if H[i] == 0:
            continue
        else:
            H[i] -= 1

print(cnt)


Measured memory_bytes: 9120
a,v = map(int,input().split())
b,w = map(int,input().split())
t = int(input())

if a < 0:
    b += abs(a)
    a = 0
if b < 0:
    a += abs(b)
    b = 0

if abs(a-b) <= (v-w)*t:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 9192
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
template <typename T> using posteriority_queue = priority_queue<T, vector<T>, greater<T> >;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
template <typename T> void unique(vector<T> &a) { a.erase(unique(ALL(a)), a.end()); }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

template <typename Abelian>
struct BITRangeAdd {
  BITRangeAdd(int n_, const Abelian UNITY = 0) : n(n_), UNITY(UNITY) {
    ++n;
    dat_const.assign(n, UNITY);
    dat_linear.assign(n, UNITY);
  }

  void add(int left, int right, Abelian val) {
    if (--right < left) return;
    for (int i = left; i < n; i += i & -i) {
      dat_const[i] -= val * (left - 1);
      dat_linear[i] += val;
    }
    for (int i = right + 1; i < n; i += i & -i) {
      dat_const[i] += val * right;
      dat_linear[i] -= val;
    }
  }

  Abelian sum(int idx) {
    --idx;
    Abelian res = UNITY;
    for (int i = idx; i > 0; i -= i & -i) res += dat_linear[i];
    res *= idx;
    for (int i = idx; i > 0; i -= i & -i) res += dat_const[i];
    return res;
  }

  Abelian sum(int left, int right) {
    if (right <= left) return UNITY;
    return sum(right) - sum(left);
  }

  Abelian operator[](const int idx) { return sum(idx, idx + 1); }

private:
  int n;
  const Abelian UNITY;
  vector<Abelian> dat_const, dat_linear;
};

int main() {
  int n, d, a; cin >> n >> d >> a;
  vector<pair<int, int> > xh(n); REP(i, n) cin >> xh[i].first >> xh[i].second;
  sort(ALL(xh));
  BITRangeAdd<ll> bit(n + 1);
  FOR(i, 1, n + 1) bit.add(i, i + 1, xh[i - 1].second);
  vector<ll> x(n);
  REP(i, n) x[i] = xh[i].first;
  ll ans = 0;
  REP(i, n) {
    ll pos = xh[i].first + d;
    int idx = upper_bound(ALL(x), pos + d) - x.begin();
    ll cnt = max((bit[i + 1] + a - 1) / a, 0LL);
    ans += cnt;
    bit.add(i + 1, idx + 1, -cnt * a);
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 6528
#include<iostream>
#include<algorithm>

using namespace std;

int main() {
	int N,A[110];
	cin>>N;
	for(int i=0;i<N;++i){
		cin>>A[i];
	}

	int ans=0,num=0;
	for(int i=0;i<N;++i){
		if(A[i]==1){
			num++;
		}
		else{
			ans=max(ans,num);
			num=0;
		}
	}
	ans=max(ans,num);

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



Measured memory_bytes: 3092
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():

    return

#B
def B():

    return

#C
def C():
    def bfs(s,g,n):
        bfs_map = [-1 for i in range(n)]
        bfs_map[s] = 0
        q = deque()
        q.append(s)
        fin = False
        while q:
            x = q.popleft()
            for y in range(n):
                if c[x][y] > 0 and bfs_map[y] < 0:
                    bfs_map[y] = bfs_map[x]+1
                    if y == g:
                        fin = True
                        break
                    q.append(y)
            if fin:
                break

        if bfs_map[g] == -1:
            return [None,0]
        path = [None for i in range(bfs_map[g]+1)]
        m = float("inf")
        path[bfs_map[g]] = g
        y = g
        for i in range(bfs_map[g])[::-1]:
            for x in range(n+1):
                if c[x][y] > 0 and bfs_map[x] == bfs_map[y]-1:
                    path[i] = x
                    if c[x][y] < m:
                        m = c[x][y]
                    y = x
                    break
        return [path,m]

    def ford_fulkerson(s,g,c,n):
        while 1:
            p,m = bfs(s,g,n)
            if not m:break
            for i in range(len(p)-1):
                c[p[i]][p[i+1]] -= m
                c[p[i+1]][p[i]] += m
        return sum(c[g])

    n = I()
    a = LI()
    e = n+2
    ma = 10**9
    c = [[0]*e for i in range(e)]
    for i in range(n):
        d = i+1
        j = 2*d
        c[0][d] = ma
        c[d][n+1] = ma-a[i]
        while j <= n:
            c[j][d] = float("inf")
            j += d
    print(ma*n-ford_fulkerson(0,n+1,c,e))
    return

#D
def D():

    return

#E
def E():

    return

#F
def F():

    return

#Solve
if __name__ == "__main__":
    C()


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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);

//	int p[1000006]={};
//	reps(i,2,1000006) if(!p[i]) for(int j=i; j<1000006; j+=i) p[j] = i;
//
//	auto ps = [&](int value){
//		vector<int> v;
//		v.push_back(1);
//		v.push_back(value);
//		while(p[value]){
//			v.push_back(p[value]);
//			value /= p[value];
//		}
//		return v;
//	};


	ll N, ans=0;
	ll s[100005];

	cin >> N;
	rep(i, N) cin >> s[i];

	reps(k,1,N){
		ll sum = 0;
		int l=0, r=N-1;
		while(l<r || (l-r)%k != 0){
			sum += s[l] + s[r];
			chmax(ans, sum);
			//cout << l << ":" << r << " " << sum << endl;
			l += k;
			r -= k;
			if( l >= N-1-k || r <= k ) break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1024
/* --- author: dxm --- */
#include<bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;

#define INF 1e9
#define Inf 1e18
#define rep(i,n) for(int (i)=0;(i)<(n);i++)
#define REP(i,n) for(int (i)=1;(i)<=(n);i++)
#define mp make_pair
#define pb push_back
#define fst first
#define snd second
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;

void qread(int &x){
	int neg=1;x=0;
	char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')neg=-1;c=getchar();}
	while(c>='0'&&c<='9')x=10*x+c-'0',c=getchar();
	x*=neg;
}

const int maxn=18;
int n,a,b;

vector<int>solve(int mask,int st,int fin,int len){
	if(len==1)return vector<int>{st,fin};
	int pos=-1;
	rep(i,n)if((mask>>i)&1)if(((st>>i)&1)!=((fin>>i)&1))pos=i;
	assert(pos>=0);
	int a=(st>>pos)&1,b=(fin>>pos)&1;
	int st2=st-a*(1<<pos),fin2=fin-b*(1<<pos),mid=st2;
	rep(i,n)if(i!=pos&&((mask>>i)&1)){
		mid^=(1<<i);
		break;
	}
	vector<int>l=solve(mask^(1<<pos),st2,mid,len-1);
	vector<int>r=solve(mask^(1<<pos),mid,fin2,len-1);
	vector<int>res;
	rep(i,1<<len-1)res.pb(l[i]+a*(1<<pos));
	rep(i,1<<len-1)res.pb(r[i]+b*(1<<pos));
	return res;
}

int main(){
#ifdef FILE
	freopen("FILE.in","r",stdin);
	freopen("FILE.out","w",stdout);
#endif
	scanf("%d%d%d",&n,&a,&b);
	if(__builtin_popcount(a^b)%2==0)puts("NO");
	else{
		puts("YES");
		vector<int>ans=solve((1<<n)-1,a,b,n);
		rep(i,ans.size())printf("%d ",ans[i]);
	}
#ifdef TIME
	printf("Running Time = %d ms\n",int(clock()*1000.0/CLOCKS_PER_SEC));
#endif
	return 0;
}

/*
Input:
-----------------
Output:
*/


Measured memory_bytes: 1756
#![allow(unused)]

use std::{cmp, collections, fmt, io, iter, ops, str};
use cmp::Ordering::{Equal, Greater, Less};
use collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque};
use io::{Read, Write};

#[cfg(feature = "debug")]
macro_rules! debug {
    ($fmt: expr) => { eprintln!($fmt) };
    ($fmt: expr, $($arg: tt)*) => { eprintln!($fmt, $($arg)*) };
}

#[cfg(not(feature = "debug"))]
macro_rules! debug {
    ($fmt: expr) => {};
    ($fmt: expr, $($arg: tt)*) => {};
}

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().to_owned()
}

fn read_word() -> String {
    const CAPACITY: usize = 16;

    let mut stdin = io::stdin();
    let mut byte: [u8; 1] = [0];

    loop {
        let mut buf = Vec::with_capacity(CAPACITY);

        loop {
            let res = stdin.read(&mut byte);

            if res.unwrap_or(0) == 0 || byte[0] <= b' ' {
                break;
            } else {
                buf.push(byte[0]);
            }
        }

        if buf.len() > 0 {
            return String::from_utf8(buf).unwrap();
        }
    }
}

fn parse_line<T: str::FromStr>() -> T {
    read_line().parse().ok().unwrap()
}

fn parse_word<T: str::FromStr>() -> T {
    read_word().parse().ok().unwrap()
}

fn parse_vec<T: str::FromStr>() -> Vec<T> {
    read_line()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn flush() {
    io::stdout().flush();
}

fn main() {
    // (string, count) pair
    let mut strings = HashMap::new();

    let blue_num = parse_line::<usize>();
    for _ in 0..blue_num {
        let s = read_line();
        let e = strings.entry(s).or_insert(0);
        *e += 1;
    }

    let red_num = parse_line::<usize>();
    for _ in 0..red_num {
        let s = read_line();
        let e = strings.entry(s).or_insert(0);
        *e -= 1;
    }

    debug!("{:?}", strings);

    let (mut max_string, mut max_count) = (None, 0);
    for (s, c) in &strings {
        if *c > max_count {
            max_string = Some(s);
            max_count = *c;
        }
    }

    if let Some(max_string) = max_string {
        println!("{}", max_count);
    } else {
        println!("0");
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test() {
        //
    }
}


Measured memory_bytes: 4352
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }

fn ask(q: &[bool]) -> i32 {
    let mut s = String::new();
    for &c in q.iter() {
        s.push(if c { '1' } else { '0' });
    }
    println!("? {}", s);
    get()
}

fn solve() {
    let n: usize = get();
    // n == 200
    // n * (n - 1) / 2 queries
    let mut pool = Vec::new();
    for i in 0 .. n {
        for j in 0 .. i {
            if pool.len() >= n - 1 {
                break;
            }
            let mut v = vec![false; n];
            v[i] = true;
            v[j] = true;
            if ask(&v) == 1 {
                pool.push((i, j));
            }
        }
    }
    print!("!");
    for (u, v) in pool {
        print!(" ({},{})", u, v);
    }
    println!("");
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 9168
/*
AizuOnline A2260
Title (iwi)
6/26 WA 15/20
*/
#include <stdio.h>
#include <string.h>

char buf[12];
int char_symm(char c1,char c2)
{
        if(c1 == 'i' && c2 == 'i')
                return(-1);
        if(c1 == 'w' && c2 == 'w')
                return(-1);
        if(c1 == '(' && c2 == ')')
                return(-1);
        if(c1 == ')' && c2 == '(')
                return(-1);
        return(0);
}
int solve(char *s,int len)
{
        int i;

        if(len==0)
                return(0);
        if(len==1)
                if(s[0]=='i' || s[0]=='w')
                        return(0);
                else
                        return(1);
        if(char_symm(s[0],s[len-1]))
                return(solve(s+1,len-2));
        else
                return(1+solve(s+1,len-2));
}

main()
{
        int ret;

        scanf("%s",buf);
        ret=solve(buf,strlen(buf));
        printf("%d\n",ret);

return(0);
}

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

int N;
int x[10], y[10];

double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}

int main() {
    cin >>N;
    for (int i = 1; i <= N; i++) cin >>x[i] >>y[i];
    double ans = 0.0;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) ans += dist(i, j) * 2 / N;
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vpii = vector<pii>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvpii = vector<vpii>;
template<typename A> using fn = function<A>;
constexpr int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
constexpr int MOD = 1000000007;
constexpr double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
constexpr bool odd(const int &n) { return n & 1; }
constexpr bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

template<typename V>
constexpr string join(const V &v, const string &sep) {
  stringstream ss;
  if (v.size()) ss << v[0];
  loop(i, 1, v.size()) ss << sep << v[i];
  return ss.str();
}

void solve() {
  int n;
  while (cin >> n, n) {
    vi v(n);
    rep(i, n) cin >> v[i];
    sort(all(v));
    int s = 0, p = 0;
    for (auto &x : v) {
      s += p;
      p += x;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 3176
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define rn return
#define fi first
#define se second
typedef std::pair<int,int> P;
using namespace std;
using ll = long long;

int main(){
    int A, B ;
    cin >> A >>B;
    if(A>=1 && A <=9 && B>=1 && B <=9){
        cout << A*B; rn 0;
    }
    
    cout << "-1";
    rn 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
A = list(map(int, input().split()))
mod = 10**9+7
comb = [0] * (N+1)
comb[K-1] = 1
for i in range(K-1, N):
    comb[i+1] = comb[i] * (i+1) * pow(i-K+2, -1, mod) % mod
# print(comb)
A.sort()
# mi = sum(a*comb[i]%mod for a, i in zip(reversed(A[:N-K+1]), range(K-1, N)))
# ma = sum(a*comb[i]%mod for a, i in zip((A[K-1:]), range(K-1, N)))
ans = sum((a-b)*comb[i]%mod for b, a, i in zip(reversed(A[:N-K+1]), A[K-1:], range(K-1, N)))
# print(mi%mod, ma%mod)
print(ans%mod)

Measured memory_bytes: 19936
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

static const int MAX = 100000;
static const int WHITE= 0;
static const int GRAY = 1;
static const int BLACK = 100000;

int n;
vector<pair<int, int> > adj[MAX];

void dijkstra() {
    priority_queue<pair<int, int> > pq;
    int color[MAX];
    int d[MAX];
    for(int i = 0; i < n; i++) {
        d[i] = INF;
        color[i] = WHITE;
    }

    d[0] = 0;
    pq.push(make_pair(0, 0));
    color[0] = GRAY;

    while(!pq.empty()) {
        pair<int, int> f = pq.top(); pq.pop();
        int u = f.second;
        color[u] = BLACK;

        if(d[u] < f.first * (-1)) continue;

        for(int j = 0; j < adj[u].size(); j++) {
            int v = adj[u][j].first;
            if(color[v] == BLACK) continue;
            if(d[v] > d[u] + adj[u][j].second) {
                d[v] = d[u] + adj[u][j].second;
                pq.push(make_pair(d[v] * (-1), v));
                color[v] = GRAY;
            }
        }
    }

    for(int i = 0; i < n; i++) {
        cout << i << " " << (d[i] == INF ? -1 : d[i]) << endl;
    }

}

signed main() {
    int k, u, v, c;
    cin >> n;

    for(int i = 0; i < n; i++) {
        cin >> u >> k;
        for(int j = 0; j < k; j++) {
            cin >> v >> c;
            adj[u].push_back(make_pair(v, c));
        }
    }

    dijkstra();

    return 0;
}



Measured memory_bytes: 14228
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(void){
    long int N, K;
    long int min = 0;

	cin >> N;
    min = N-1;

    for (long int i = 2; i*i <= N; i++)
    {
        if ((N % i) == 0)
        {
            K = i + (N / i) - 2;
            if (K < min)
            {
                min = K;
            }
        }
    }
    cout << min << endl;
    return 0;
}


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

int main(){
    ll n,m;
    std::cin >> n>>m;
    vector<bool> red(n);
    vector<ll> cou(n,1);
    red[0] = true;

    for (int i = 0; i < m; i++) {
        ll x,y;
        std::cin >> x>>y;
        x--;
        y--;
        if(red[x]){
            red[y] = true;
        }
        cou[y]++;
        cou[x]--;
        if(cou[x] == 0){
            red[x] = false;
        }
    }
    ll result = 0;
    for (int i = 0; i < n; i++) {
        if(red[i])result++;
    }
    std::cout << result << std::endl;
    
}



Measured memory_bytes: 1152
#include<iostream>
#include<math.h>
 using namespace std ;
 int main()
{
short int a,b,c,d;

cin>>a;
cin>>b;
cin>>c;
cin>>d;
if((abs(c-a))<=d) cout<< "Yes";
else
 if((abs(c-b)<=d)&& ( abs(b-a)<=d) ) cout<< "Yes";
else
cout<< "No";




}

Measured memory_bytes: 3544
#include <stdio.h>

int length(int *A) {
	return A[0];
}

void swap(int *a, int *b) {
	int t = *a;
	*a = *b;
	*b = t;
}

int BubbleSort(int *A) {
	int i, j, n = 0;
	for (i = 1; i <= length(A); i++) {
		for (j = length(A); j >= i + 1; j--) {
			if (A[j] < A[j - 1]) {
				swap(&A[j], &A[j - 1]);
				n++;
			}
		}
	}
	return n;
}

int SelectionSort(int *A) {
	int i, j, mini, n = 0;
	for (i = 1; i <= length(A); i++) {
		mini = i;
		for (j = i; j <= length(A); j++) {
			if (A[j] < A[mini]) {
				mini = j;
			}
		}
		if (i != mini) {
			swap(&A[i], &A[mini]);
			n++;
		}
	}
	return n;
}

int main(void) {
	int A[101] = {0};
	int N, c;
	int i;
	
	scanf("%d", &N);
	A[0] = N;
	for (i = 1; i <= N; i++) {
		scanf("%d", &A[i]);
	}
	
	c = SelectionSort(A);
	
	for (i = 1; i <= N; i++) {
		if (i > 1) {
			putchar(' ');
		}
		printf("%d", A[i]);
	}
	
	printf("\n%d\n", c);
	
	return 0;
}

Measured memory_bytes: 604
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>
#include<random>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
using P=pair<int,int>;
using lint=long long;
using ll=long long;
const lint inf=1e18+7;
const int MOD=1000000007;
int d;
int c[30]={};
int s[370][30];
int num=100000;
int calc(vector<int>const& t,vector<vector<int>>& last_list){
  int res=0;
  vector<int> last(30,0);
  rep1(i,d){
    res+=s[i][t[i]];
    last[t[i]]=i;
    last_list[i]=last;
    int buf=0;
    rep1(j,26){
      buf+=c[j]*(i-last[j]);
    }
    res-=buf;
    //cout<<res<<"\n";
  }
  return res;
}
int change(int nd,int nq,int& res,vector<int>& t,vector<vector<int>>& last_list){
  int flag_t=false;
  int flag_q=false;
  int x=t[nd];
  t[nd]=0;
  res+=s[nd][nq];res-=s[nd][x];
  for(int i=nd;i<=d;++i){
    if(flag_t&&flag_q)break;
    if(t[i]==x||flag_t)flag_t=true;
    else{
      res+=c[x]*(i-last_list[i][x]);
      last_list[i][x]=last_list[i-1][x];
      res-=c[x]*(i-last_list[i][x]);
    }
    if(t[i]==nq||flag_q)flag_q=true;
    else{
      res+=c[nq]*(i-last_list[i][nq]);
      last_list[i][nq]=nd;
      res-=c[nq]*(i-last_list[i][nq]);
    }
  }
  t[nd]=nq;
  return res;
}
vector<int> greedy(int d){
  vector<int> res(d+1,0);
  vector<int> last(30,0);
  rep1(i,d){
    int mx=-inf;
    int mx_ind=0;
    rep1(j,26){
      int tmp=s[i][j];
      rep1(k,26){
        if(k==j)continue;
        tmp-=c[k]*(i-last[k]);
      }
      if(mx<tmp){
        mx=tmp;
        mx_ind=j;
      }
    }
    last[mx_ind]=i;
    res[i]=mx_ind;
  }
  return res;
}
signed main(){
  cin>>d;
  rep1(i,26)cin>>c[i];
  rep1(i,d){
    rep1(j,26)cin>>s[i][j];
  }
  vector<int> t=greedy(d);
  vector<vector<int>> last_list(d+1,vector<int>(30,0));
  int res=calc(t,last_list);
  //cout<<res<<"\n";
  int param=2;
  rep(xx,num){
    random_device rand;
    mt19937 mt(rand());
    vector<int> nd(param);rep(i,param)nd[i]=mt()%d+1;
    vector<int> nq(param);rep(i,param)nq[i]=mt()%26+1;
    vector<int> bq(param);rep(i,param)bq[i]=t[nd[i]];
    int bval=res;
    rep(i,param){
      change(nd[i],nq[i],res,t,last_list);
    }
    int yakinamasi=mt()%100;
    //if(yakinamasi<10)continue;
    if(bval>res){
      rep(i,param){
        change(nd[i],bq[i],res,t,last_list);
      }
    }
  }
  rep(xx,num){
    random_device rnd;
    mt19937 mt(rnd());
    int nd=mt()%d+1;
    int nq=mt()%26+1;
    int bq=t[nd];
    int bval=res;
    int hoge=change(nd,nq,res,t,last_list);
    if(hoge<bval){
      change(nd,bq,res,t,last_list);
    }
  }
  rep1(i,d){
    cout<<t[i]<<"\n";
  }
  //cout<<res<<"\n";
  return 0;
}
/*
int m;cin>>m;
  vector<int> bres(m);
  rep(i,m){
    int d,q;cin>>d>>q;
    bres[i]=change(d,q,res,t,last_list);
  }
  rep(i,m){
    cout<<bres[i]<<"\n";
  }
  */

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

int main() {
  int A,B,amount=0;
  cin>>A>>B;
  for(int i=A;i<=B;i++){
    int n1,n2,n3,n4,n5;
    n1=i/10000;
    n2=i/1000-n1*10;
    n3=i/100-n1*100-n2*10;
    n4=i/10-n1*1000-n2*100-n3*10;
    n5=i-n1*10000-n2*1000-n3*100-n4*10;
    if(n1==n5&&n2==n4){
    amount++;
    }
  }
  cout<<amount<<endl;

}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for(int i = 0; i < N; i++){
        cin >> L[i];
    }

    int ans = 1;
    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += L[i];
        if(sum <= X){
            ans++;
        }
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <queue>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stack>
#include <queue>
using namespace std;
#define sd(n) scanf("%d", &n)
#define sdd(n, m) scanf("%d%d", &n, &m)
#define sddd(n, m, k) scanf("%d%d%d", &n, &m, &k)
#define pd(n) printf("%d\n", n)
#define pc(n) printf("%c", n)
#define pdd(n, m) printf("%d %d\n", n, m)
#define pddd(n, m, z) printf("%d %d %d\n", n, m, z)
#define pld(n) printf("%lld\n", n)
#define pldd(n, m) printf("%lld %lld\n", n, m)
#define plddd(n, m, z) printf("%lld %lld %lld\n", n, m, z)
#define sld(n) scanf("%lld", &n)
#define sldd(n, m) scanf("%lld%lld", &n, &m)
#define slddd(n, m, k) scanf("%lld%lld%lld", &n, &m, &k)
#define sf(n) scanf("%lf", &n)
#define sc(n) scanf("%c", &n)
#define sff(n, m) scanf("%lf%lf", &n, &m)
#define sfff(n, m, k) scanf("%lf%lf%lf", &n, &m, &k)
#define ss(str) scanf("%s", str)
#define rep(i, a, n) for (int i = a; i <= n; i++)
#define per(i, a, n) for (int i = a; i >= n; i--)
#define mem(a, n) memset(a, n, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define ce i == n ? '\n' : ' '
#define mod(x) ((x) % MOD)
#define gcd(a, b) __gcd(a, b)
#define lowbit(x) (x & -x)
typedef pair<int, int> PII;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int MOD = 1e9 + 7;
const double eps = 1e-9;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const int inf = 0x3f3f3f3f;
inline int read()
{
	int ret = 0, sgn = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9')
	{
		if (ch == '-')
			sgn = -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9')
	{
		ret = ret * 10 + ch - '0';
		ch = getchar();
	}
	return ret * sgn;
}
inline void Out(int a) //ê?3?ía1ò
{
	if (a > 9)
		Out(a / 10);
	putchar(a % 10 + '0');
}

ll gcd(ll a, ll b)
{
	return b == 0 ? a : gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
///快速幂m^k%mod
ll qpow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n)
	{
		if (n & 1)
			res = (res * x) % mod;
		x = x * x % mod, n >>= 1;
	}
	return res;
}

const int N = 2e5 + 10;

int main()
{
	int t;
	string s;
	cin >> s;
	if (s == "ABC")
		puts("ARC");
	else
	{
		puts("ABC");
	}
	return 0;
}

Measured memory_bytes: 3552
s=input()
n=len(s)
s = int(s, 2)
s_10 = '1' * (n % 2) + '01' * (n // 2)
s_01 = '0' * (n % 2) + '10' * (n // 2)
s_10 = int(s_10, 2)
s_01 = int(s_01, 2)
r = bin(s ^ s_01)
l = bin(s ^ s_10)
print(min(r.count('1'), l.count('1')))


Measured memory_bytes: 3316
A,B,C,X=map(int,open(0))
ans=0

i=0
while i<=C:
    j=0
    while j<=B:
        k=0
        while k<=A:
            ans+=1*(500*k+100*j+50*i==X)
            k+=1
        j+=1
    i+=1

print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << c-d+b << " " << d+c-a << " " << a-d+b << " " << b + c-a << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N,M=map(int,input().split())
A=list(map(int,input().split()))

dd = defaultdict(int)#あまりをカウント
S=[0]*(N+1)

for i in range(N):
    S[i+1]=S[i]+A[i]
    S[i+1]%=M
    
ans=0
for i in range(N+1):
    ans+=dd[S[i]]
    dd[S[i]]+=1
    
print(ans)
    

Measured memory_bytes: 62576