akhauriyash/Code-Regression huggingface dataset:
N = int(input())
H = list(map(int, input().split()))
ans = 0
i = 0
while i < N - 1:
    temp = 0
    if H[i] >= H[i + 1]:
        while H[i] >= H[i + 1]:
            temp += 1
            i += 1
            if i == N - 1:
                break
    else:
        i += 1
    if temp > ans:
        ans = temp
print(ans)

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

int main(){
    int ans = 0;
    int N;
    cin >> N;
    
    int H[N];    
    for(int i = 0; i < N; i++){
        cin >> H[i];
    }

    for(int i = 0; i < N; i++){
        if(*max_element(H, H + i) <= H[i]){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MOD 998244353

int a,b,c;
long long int fact[200010];

long long int power(long long int a, long long int b)
{
	long long int ans = 1;
	long long int k = a;
	while(b)
	{
		if(b%2==1) ans*=k, ans%=MOD;
		b/=2;
		k*=k, k%=MOD;
	}
	return ans;
}
long long int inv(long long int a)
{
	return power(a,MOD-2);
}
long long int comb(long long int a, long long int b)
{
	long long int s = fact[a];
	s *= inv(fact[b]), s%=MOD;
	s *= inv(fact[a-b]), s%=MOD;
	return s;
}
long long int func(long long int s, long long int t)
{
	return comb(s,t)*power(b-1,s-t) % MOD;
}

int main()
{
	fact[0] = 1;
	for(int i=1;i<=200000;i++)
	{
		fact[i] = fact[i-1]*i;
		fact[i] %= MOD;
	}
	
	scanf("%d%d%d",&a,&b,&c);
	
	long long int ans = 0;
	for(int i=0;i<=c;i++)
	{
		ans += b*func(a-1,i);
		ans %= MOD;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 3260
# include <iostream>

//https://atcoder.jp/contests/abc080/tasks/abc080_a

using namespace std;

int main(){
    int N,A,B;

    cin >> N >> A >> B;
    
    if( N * A < B) {
        cout << N * A << endl;
    }
    else if(N * A >= B){
        cout << B << endl;
    }
    return 0;
}

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


int main(){
    int n;
    cin >> n;
    int ans = 0;
    int is_min = 999999;
    rep(i, n) {
        int p;
        cin >> p;
        if (p <= is_min) {
            ans++;
            is_min = p;
        }
    }
    cout << ans << "\n";

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
   int ar[100009],br[100009],i,j,n;
   cin>>n;
   for(i=1; i<=n; i++)
   {
   	 scanf("%d",&ar[i]);
   }
    
   for(i=1; i<=n; i++)
   {
   	 br[ar[i]]=i;
   } 
   printf("%d", br[1]);
   for(i=2; i<=n; i++)
   {
   	 printf(" %d",br[i]);
   }
   printf("\n");

   return 0;
}

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

int main(){
  int n;
  cin >> n;
  
  if(n==1||n==2||n==3||n==5||n==6||n==9||
     n==10||n==13||n==17){
    cout << "No" << endl;
  }else{
    cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
#!/usr/bin/python3
# abc061_a
"""
Between Two Integers
"""

def main():
    """
    こたえ。
    """
    A, B, C = map(int, input().split())

    if A <= C <= B:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
N = int(input())




def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


## [[2, 3], [3, 1]] 
##  24 = 2^3 * 3^1

def ruisekiwa(n):
	if n<3:
		return 1
	elif n<6:
		return 2
	elif n<10:
		return 3
	elif n<15:
		return 4
	elif n<21:
		return 5
	elif n<28:
		return 6
	elif n<36:
		return 7
	else:
		return 8


a=factorization(N)
ans=0
#print(a)

for insu in a:
	#print(insu[1])
	#print(ruisekiwa(insu[1]))
	ans+=ruisekiwa(insu[1])

if N==1:
	print(0)
else:
	print(ans)




# 2darray [[0] * 4 for i in range(3)]

Measured memory_bytes: 9512
#include<stdio.h>
int main(void){
	int a,b,c,d,f,g;
	char e='#';
	while(1){
		scanf("%d %d",&a,&b);
		f=a;
		g=b-1;
		
		if(a==0&&b==0){goto hata;
		}
		else{
			for(c=0;c<f;c++){
				for(d=0;d<=g;d++){
							printf("%c",e);
				}
				putchar('\n');
			}
			putchar('\n');
		}
	}
	hata:
	return 0;
}

Measured memory_bytes: 576
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;
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; }

typedef unsigned int uint;
typedef long long llong;
typedef unsigned long long ullong;
typedef long double ldouble;

typedef vector<llong> vecllong;
typedef vector<vecllong> vvecllong;

const llong MOD = 1e9 + 7;
const llong INF = 1e17;

#define FOR(i, n) for (llong i = 0; i < n; i++)
#define FORS(i, a, b) for (llong i = a; i < b; i++)
#define FORR(i, n) for (llong i = n; i > 0; i++)

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

    string S, T;
    cin >> S >> T;

    vvecllong dp(S.length() + 1, vecllong(T.length() + 1, 0));  // dp[sIndex][tIndex]

    FOR(s, S.length()) {
        FOR(t, T.length()) {
            if(S[s] == T[t]) {
                chmax(dp[s + 1][t + 1], dp[s][t] + 1);
            }
            chmax(dp[s + 1][t + 1], dp[s + 1][t]);
            chmax(dp[s + 1][t + 1], dp[s][t + 1]);
        }
    }

    string ans = "";
    llong s = S.length();
    llong t = T.length();

    while(s > 0 && t > 0) {
        if(dp[s][t] == dp[s - 1][t]) {
            s--;
        } else if (dp[s][t] == dp[s][t - 1]) {
            t--;
        } else {
            ans = S[s - 1] + ans;
            s--;
            t--;
        }
    }

    cout << ans << endl;

    return 0;
}

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

typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

string solve(string& s, int K) {
	int n = s.size();

	if (K == 0) {
		return s;
	}

	pii u = mp(0, 0);

	for (int i = n-1; i >= 0; --i) {
		if (u.se == 0) {
			u = mp(s[i], 1);
		} else {
			if (u.fi == s[i]) {
				++u.se;
			} else {
				break;
			}
		}
	}

	int c = u.fi;
	int num = u.se;

	int len = num;
	rep(i, K) {
		len *= 2;
		if (len >= n) {
			string res;
			rep(j, n) res.pb(c);
			return res;
		}
	}

	len = num;

	rep(i, K) {
		string p = s, q = s;
		reverse(ALL(q));
		p += q;

		if (i != K-1) {
			s = p.substr(len, n);
		} else {
			s = p.substr(n - len, n);
		}
		len *= 2;
	}
	return s;
}

int main() {
	int N, K;
	string S;
	cin >> N >> K >> S;

	string T = S;
	reverse(ALL(T));
	S += T;

	string ans;

	for (int i = 0; i <= N; ++i) {
		string s = S.substr(i, N);
		string cand = solve(s, K-1);

		if (i == 0 || ans > cand) {
			ans = cand;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            string line = Console.ReadLine();
            string[] strs = line.Split(' ');
            long A = long.Parse(strs[0]);
            long B = long.Parse(strs[1]);
            long N = long.Parse(strs[2]);

            if (N >= B) N = B - 1;

            long x = (long)(A * N / (double)B);

            Console.WriteLine(x);
        }

    }
}


Measured memory_bytes: 27512
#include<bits/stdc++.h>
#define lll double
#define fr(a,b) for(int i = a; i < b; i++)
#define mod 1000000007
#define triplet pair<int,pair<int,int>>
#define ll long long int
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
ll md = pow(10,9)+7;
ll dp[301][301][301];

int main(){
    fast_io;
    //cin>>t;
    int n,k;
    cin>>n>>k;
    vector<int>dp(k+1,0);
    dp[0]=1;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin>>v[i];
        vector<int>f(k+1,0);
        for(int j = 0;j<=k;j++){
            ll t = dp[j], l = j+1;
            ll r = j+min(v[i],k-j);
            if(l<=r)
                f[l] = (f[l]+t)%md;
            if(r+1<=k){
                f[r+1] = (f[r+1]-t);
                if(f[r+1]<0){
                    f[r+1] = (f[r+1]+md)%md;
                }
            }
        }
        ll s=0;
        for(int x = 0;x<=k;x++){
            s = (s+f[x])%md;
            dp[x] = (s+dp[x])%md;
        }
    }
    
    cout<<dp[k];
    return 0;
}

Measured memory_bytes: 1024
A1 = list(map(int,input().split()))
A2 = list(map(int,input().split()))
A3 = list(map(int,input().split()))
bingo = [A1,A2,A3]
N = int(input())
for _ in range(N):
    b = int(input())
    for k in bingo:
        if b in k:
            k[k.index(b)] = 0

clear = False
for k in bingo:
    if sum(k) == 0:
        clear = True
for i in range(3):
    if bingo[0][i] + bingo[1][i] + bingo[2][i] == 0:
        clear = True
if bingo[0][0] + bingo[1][1] + bingo[2][2] == 0:
    clear = True
if bingo[0][2] + bingo[1][1] + bingo[2][0] == 0:
    clear = True

if clear == True:
    print("Yes")
else:
    print("No")

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

int main(){
  string S;
  cin >> S;
  int N=S.size();
  vector<long long> A(N);
  vector<long long> B(N);
  long long black=0;
  for(int i=0; i<N; i++){
    if(S.at(i)=='B') black++;
    A.at(i)=black;
    if(S.at(i)=='W') B.at(i)=1;
  }
  long long ans=0;
  for(int i=0; i<N; i++){
    if(B.at(i)==1) ans+=A.at(i);
  }
  cout << ans << endl;
}

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

const int N=110;
int n,m,a[N];

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

Measured memory_bytes: 256
import java.util.*;
public class Main
{
    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); int [] a = new int [n+1]; long k = sc.nextLong();
        for (int i = 1; i <= n; i++) a[i] = sc.nextInt();
        Set<Integer> seen = new HashSet<>();
        ArrayList<Integer> st = new ArrayList<>();
        int cur = 1;
        while (!seen.contains(cur)) {
            st.add(cur);
            seen.add(cur);
            cur = a[cur];
        }
        int offset = 0; int cycle = -1; int temp = st.size();
        for (int i = 0; i < temp; i++) {
            if (st.get(i) == cur) {
                offset = i; cycle = temp - offset; break;
            }
        }
        if (k < st.size()) {
            System.out.println(st.get((int)k));
        } else {
            int mod = (int) ((k - offset)%cycle) + offset;
            System.out.println(st.get(mod));
        }
    }


}

Measured memory_bytes: 66984
k = int(input())
mod = 7 % k
counter = 1
memo = 1
mod_map = set()
mod_map.add(mod)
while mod != 0:
    memo = ((memo % k) * (10 % k)) % k
    mod = (mod + 7 * memo) % k
    if mod not in mod_map:
        mod_map.add(mod)
    else:
        counter = -1
        break
    counter += 1
    if mod == 0:
        break
print(counter)


Measured memory_bytes: 200680
#include <iostream>
#define MAX_N 1299709 + 1
using namespace std;

bool t[MAX_N];
int k;

bool isPrime(int x) {
  if(x == 2) return true;
  if(x < 2 || x % 2 == 0) return false;
  int i = 3;
  while(i * i <= x) {
    if(x % i == 0) return false;
    i += 2;
  }
  return true;
}

void table() {
  for(int i = 1; i < MAX_N; ++i) {
    if (isPrime(i)) t[i] = 1;
  }
}

void solve() {
  int p = k, n = k;
  while(t[p] != 1) p--;
  while(t[n] != 1) n++;
  cout << n - p << endl;
}

int main() {
  table();
  while(cin >> k && k) {
    solve();
  }
  return 0;
}



Measured memory_bytes: 4248
/*  -*- coding: utf-8 -*-
 *
 * i.cc: I - Coins
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 3000;

/* typedef */

/* global variables */

double dp[2][MAX_N + 1];

/* subroutines */

/* main */

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

  dp[0][0] = 1.0;
  int cur = 0, nxt = 1;

  for (int i = 0; i < n; i++) {
    double pi;
    scanf("%lf", &pi);

    fill(dp[nxt], dp[nxt] + i + 2, 0.0);
    for (int j = 0; j <= i; j++) {
      dp[nxt][j + 1] += dp[cur][j] * pi;
      dp[nxt][j] += dp[cur][j] * (1.0 - pi);
    }

    cur ^= 1, nxt ^= 1;
  }

  double sum = 0.0;
  for (int i = n / 2 + 1; i <= n; i++) sum += dp[cur][i];
  printf("%.12lf\n", sum);
  return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    long long N, A, B;
    cin >> N >> A >> B;
    if(A > B ){
        cout << 0 << endl;
    }else if(N == 2){
        cout << 1 << endl;
    }else if(N == 1){
        if(A == B){
            cout << 1 << endl;
        } else {
            cout << 0 << endl;
        }
    } else {
        cout << B*(N-2) - A*(N-2) + 1 << endl;
    }
}

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

#define ll long long
#define NIL 0
#define INF 2e9
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define vl vector<ll>
#define vvl vector<vector<ll>> 
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define pb push_back
#define F first
#define S second
#define pp pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<n;i++)
#define rpk(i,k,n) for(int i=k;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++) 
#define RPK(i,k,n) for(int i=k;i<=n;i++) 
#define ritr(i,gr) for(auto i=gr.begin();i!=gr.end();i++)

const int M = 1e9+7;

int V, E, i, j, k, u, v, x, y, p, q, r, t, n,w;
vi *g;
vb sn;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>w;
    v = 1e5;
    ll wt[n], val[n], dp[n+1][v+1];
    rep(i,n) cin>>wt[i]>>val[i];
    
    
    rep(i,v+1) dp[0][i] = INF;
    rep(i,n+1) dp[i][0] = 0;
    dp[0][0]= 0;
    
    REP(i,n) {
        REP(j,v) {
            if(j>=val[i-1])
            {
                dp[i][j] = min(dp[i-1][j-val[i-1]]+wt[i-1], dp[i-1][j]);
                if(dp[i][j]>INF) dp[i][j] = INF;
                
            }
            else 
            dp[i][j] = dp[i-1][j]<wt[i-1] ? dp[i-1][j] : wt[i-1];
        }        
    }
    
    int res = 0;
    rep(i,v+1) if(dp[n][i]<=w) res = max(res, i);
    cout<<res<<endl;
}
    

Measured memory_bytes: 82504
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            var data = new List<int> { };
            var input = Console.ReadLine().Split(' ');

            for (int i = 0; i < n; i++)
                data.Add(int.Parse(input[i]));

            int res = 0;

            data.Sort();

            int[] checks = new int[data[n - 1] + 1];

            foreach (int thisdata in data)
            {
                int ctr = 1;
                while (true)
                {
                    int multiplied = thisdata * ctr;
                    if (multiplied > data[n - 1])
                        break;
                    checks[multiplied]++;
                    ctr++;
                }
            }

            for (int i = 0; i < n; i++)
            {
                if (checks[data[i]] == 1)
                    res++;
            }

            Console.WriteLine(res);

        }

    }
}



Measured memory_bytes: 48124
#include<stdio.h>
int main()
{
	int h, m, s;
	scanf("%d", &s);
	m = s / 60;
	s = s % 60;
	h = m / 60;
	m = m % 60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 2676
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int maxn=100005;
const int logn=20;

int n,q,l;
int dep[maxn];
int up[maxn][logn];
vector<int>G[maxn];

void dfs(int u,int p) {
    dep[u]=dep[p]+1;
    up[u][0]=p;
    for (int i=0;i<l;i++) up[u][i+1]=up[up[u][i]][i];
    for (int v:G[u])
        if (v!=p) dfs(v,u);
}

int lca(int u,int v) {
    if (dep[u]<dep[v]) swap(u,v);
    for (int i=l;i>=0;i--) {
        if (dep[up[u][i]]>=dep[v]) u=up[u][i];
        if (u==v) return u;
    }
    for (int i=l;i>=0;i--)
        if (up[u][i]!=up[v][i]) {
            u=up[u][i];
            v=up[v][i];
        }
    return up[u][0];
}

int main() {
    cin>>n;
    for (int i=0;i<n;i++) {
        int m; cin>>m;
        for (int j=0;j<m;j++) {
            int v; cin>>v;
            G[i].pb(v);
        }
    }
    while ((1<<l)<=n) ++l;
    dfs(0,0);
    cin>>q;
    for (int i=0;i<q;i++) {
        int u,v; cin>>u>>v;
        cout<<lca(u,v)<<'\n';
    }
}


Measured memory_bytes: 21364
#include <cstdio>
using namespace std;

int N, P;
long long mod[2];
long long C[55][55];
long long pow[55];
long long ans;

int main() {
    for (int i = 0; i <= 50; ++i) C[i][0] = C[i][i] = 1;
    for (int i = 1; i <= 50; ++i)
        for (int j = 0; j != i; ++j)
            C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    pow[0] = 1;
    for (int i = 1; i <= 50; ++i) pow[i] = pow[i - 1] * 2;
    scanf("%d%d", &N, &P);
    for (int i = 0; i != N; ++i) {
        int A; scanf("%d", &A); ++mod[A & 1];
    }
    for (int i = P; i <= mod[1]; i += 2)
            ans += C[mod[1]][i] * pow[mod[0]];
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

void normal(int pos,int size,int* letter,int max)
{
    int j,k,max1=max;
    for (j=1;(j<=pos+1)&&(j<=max+1);j++)
    {
        *(letter)=j;
        //printf("%d\n%d\n%d\n",*(letter),pos,max);
        if(j>max) max1=j;
        if(pos==size-1)
        {
            for(k=0;k<size;k++) printf("%c",96+*(letter-size+1+k));
            printf ("\n");
        }
        else
        {
            normal(pos+1,size,letter+1,max1);
        }
    }
}
int main() 
{
    int n; 
	scanf("%d",&n);
	//printf("%d\n",n);
	int letter[n];
	normal(0,n,letter,1);
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const ll MOD = 1e9+7;

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

int64_t lcm(int64_t a, int64_t b)
{
   return a * b / gcd(a, b);
}

int main(){
  int64_t a, b, c, d, e, ec, ed, ecd, cd, ac, ad, acd;
  cin >> a >> b >> c >> d;
  int64_t epc, epd, epcd;
  e = b-a+1;
  cd = lcm(c, d);
  
  epc = e%c;
  epd = e%d;
  epcd = e%cd;
  
  ec = e/c;
  ed = e/d;
  ecd = e/cd;
  
  ac = a%c;
  ad = a%d;
  acd = a%cd;
  int64_t bc, bd, bcd;
  bc = b%c;
  bd = b%d;
  bcd = b%cd;
  
  
  if(epc==0) ec = ec;
  else if(ec==0){
    if(ac==0||bc==0) ec++;
    else if(ac>bc) ec++;
  }
  else if(ac==0||bc==0) ec++;
  else if(ac>bc+1) ec++;
  
  if(epd==0) ed = ed;
  else if(ed==0){
    if(ad==0||bd==0) ed++;
    else if(ad>bd) ed++;
  }
  else if(ad==0||bd==0) ed++;
  else if(ad>bd+1) ed++;
  
  if(epcd==0) ecd = ecd;
  else if(ecd==0){
    if(acd==0||bcd==0) ecd++;
    else if(acd>bcd) ecd++;
  }
  else if(acd==0||bcd==0) ecd++;
  else if(acd>bcd+1) ecd++;
  cout << e - ec - ed + ecd << endl;
  /*ca = a; 
  //cb = b;
  int chc=0, chd=0;
  rep(i, c){
    if(ca%c==0){
      chc++;
      break;
    } 
  }
  ca = a;
  rep(i, c){
    if(ca%d==0){
      chd++;
      break;
    } 
  }
  ec += chc;
  ed += chd;*/
}

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

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

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

  /* しゃくとり法の時間 */
  long long res = 0;

  int right = 0;
  int sum = 0;

  for (int left = 0; left < n; left++){
    while (right < n && (sum^a[right]) == (sum + a[right])){
      sum ^= a[right];
      right++;
    }

    res += right - left;
    
    if (right == left) right++;
    else sum-= a[left];
  }


  cout << res << endl;  
}

Measured memory_bytes: 1792
#include<iostream>

using namespace std;

int n, A[20];

int solve(int i, int m) {
  int res;

  if (m == 0)
    return 1;

  if (i >= n)
    return 0;

  res = solve(i + 1, m) || solve(i + 1, m - A[i]);

  return res;
}

int main() {
  int q, M, i;

  cin >> n;

  for (i = 0; i < n; i++)
    cin >> A[i];

  cin >> q;

  for (i = 0; i < q; i++) {
    cin >> M;

    if (solve(0, M))
      cout << "yes" << endl;
    else
      cout << "no" << endl;
  }

  return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <map>
#include <cmath>
#include <string>
using namespace std;

#define rep(i, n) for (int i = 1; i < (n); ++i)
#define REP(i,a,b)for(int i=(int)(a);(i)<(int)(b);i++)
#define SAME_NUM 111
typedef long long ll;


ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll c, ll d) { return c / gcd(c, d) * d; }

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

  int ans = SAME_NUM;
  rep(i, 10) {
    ans = SAME_NUM * i;
    if (n == ans ||
        n%(SAME_NUM*i) == n) break;
    // cout << n % (SAME_NUM * i) << endl;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <iterator>
#include <set>
#include <sstream>
using namespace std;

#define FOR(it,c) for(__typeof((c).begin())it=(c).begin(); it!=(c).end();++it)

const int MAX_LENGTH = 201;
string s;
set<int> dp[MAX_LENGTH][MAX_LENGTH];

int stoi(string str) {
	istringstream is(str);
	int res;
	is >> res;
	return res;	
}

set<int> expr(int l, int r) {
	if(dp[l][r].size())
		return dp[l][r];

	int depth = 0;
	bool found = false;
	for(int i = l; i < r; ++i) {
		switch(s[i]) {
		case '(': ++depth; break;
		case ')': --depth; break;
		case '+':
		case '-':
		case '*':
		case '/':
			if(depth == 0) {
				found = true;
				set<int> left = expr(l, i);
				set<int> right = expr(i + 1, r);
				FOR(it, left) {
					FOR(it2, right) {
						switch(s[i]) {
						case '+': dp[l][r].insert(*it + *it2); break;
						case '-': dp[l][r].insert(*it - *it2); break;
						case '*': dp[l][r].insert(*it * *it2); break;
						case '/': if(*it2) dp[l][r].insert(*it / *it2);
						}
					}
				}
			}
		}
	}

	if(!found) {
		if(s[l] == '(')
			dp[l][r] = expr(l + 1, r - 1);

		else
			dp[l][r].insert(stoi(s.substr(l, r - l)));
	}

	return dp[l][r];
}

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

	while(cin >> s, s != "#") {
		for(int i = 0; i < MAX_LENGTH; ++i)
			for(int j = i + 1; j < MAX_LENGTH; ++j)
				dp[i][j].clear();

		cout << expr(0, s.size()).size() << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 3244
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>

using namespace std;
using ll = long long int; 

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}


ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

ll keta(ll a){
  ll ans = 1;
  while(1){
    if(a/10 > 0){
      ans++;
      a = a/10;
    }
    if(a<10) break;
  }
  return ans;
}

const int MAX = 50;
const int MOD = 1000000007;

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(void){

  int a, b;
  cin>>a>>b;

  if(a==b){
    for(int i=0;i<a;i++){
      cout<<a;
    }
    cout<<endl;
  }else if(a>b){
    for(int i=0;i<a;i++){
      cout<<b;
    }
    cout<<endl;
  }else{
    for(int i=0;i<b;i++){
      cout<<a;
    }
    cout<<endl;
  }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i , n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
#include <bits/stdc++.h>
int main() {
    int n , k;
    cin >> n >> k;
    vector <int> a(n + 1);
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        a[x]++;
    }
    sort(a.begin() , a.end());
    int ans = 0;
    for(int i = 0; i < n - k + 1; i++){
        ans+=a[i];
    }
    cout << max(0 , ans) << endl;
}


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

 enum{ Nothing , Barrier , Start, Goal, Failure = 100 };

 int d[] = {1, 0, -1, 0, 1};
 int result = Failure;

 int state[22][22];

 int dfs(int x, int y, int c){
    if (c > 10) return Failure; 

    for (int i = 0; i < 4; i++){
        int nx = x + d[i], ny = y + d[i+1];
        if (state[nx][ny] == Barrier) continue;

        while(state[nx][ny] == Nothing){
            nx += d[i], ny += d[i+1];
        }

        if (state[nx][ny] == Goal){
            return c+1;
        }else if (state[nx][ny] == Barrier){
            state[nx][ny] = Nothing;
            int temp = dfs(nx - d[i],ny - d[i+1], c+1);
            result = min(result, temp);
            state[nx][ny] = Barrier;
        }
    }
    return result;
 }

 int main(){
     while(1){
         int w,h;cin >> w >> h;
         if(w == 0 && h == 0)  break;

         result = Failure;
         int sx, sy;

         memset(state,-1,sizeof(state));
         
         for(int i = 1; i <= h; i++){
             for(int j = 1; j <= w; j++){
                 cin >> state[i][j];

                 if(state[i][j] == Start){
                     sx = i; sy = j;
                     state[i][j] = Nothing;
                 }
             }
         }
         int cnt = dfs(sx, sy, 0);
         if(cnt <= 10) cout << cnt << endl;
         else cout << -1 << endl;
     }
 }


Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n) ;i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b){ a = b; return 1; } return 0; }
 
 
 
int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  cout << 180*(n-2) << endl;
  return 0;
}


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

int main() {
  int N = 0;
  int K = 0;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  
  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += p.at(i);
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define int long long
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
	string s;
  	cin>>s;
  	if(s=="AAA" || s=="BBB")
      cout<<"No";
 	else
      cout<<"Yes";
}

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

int main(){
    int x;
    int y;
    
    cin >> x >> y;
    if (x > y){
        cout << "a > b" << endl;
    }else if (x < y){
        cout << "a < b" << endl;
    }else if (x == y){
        cout << "a == b" << endl;
    }
    return 0;
}


Measured memory_bytes: 3100
#include<iostream>
using namespace std;
int main() {
	int k, a, b;
	int l[1001];
	int x;
	for (int i = 0;; i++){
		cin >> k;
		if (k == 0){
			x = i;
			break;
		}
		for (int i = 0; i < 9; i++){
			cin >> a;
			k -= a;
		}
		l[i] = k;
	}
	for (int i = 0; i < x; i++){
		cout << l[i] << endl;
	}
}

Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
int n,ans,a[105];
bool func(int x,int y,int z)
{
	if(x==y||y==z||x==z)
		return false;
	if(x+y<=z||y+z<=x||x+z<=y)
		return false;
	return true;
}
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			for(int k=j+1;k<=n;k++)
				if(func(a[i],a[j],a[k]))
					ans++;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    int l,r,sum=0;
    for(int i=0;i<n;++i){
        scanf("%d%d",&l,&r);
        sum+=r-l+1;
    }
    printf("%d\n",sum);
    return 0;
}



Measured memory_bytes: 256
#import<bits/stdc++.h>
#define endl '\n'
using namespace std;
int i,j,k,m,n,p=1,x,y,z,a[1000005],b[1000005],c[1000005];
string s;
main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>s;
	for(;i<n;i++)z+=s[i]&1;
	if(z==n)
	{
		p=2;
		for(;i--;)a[i]=(s[i]&2)>>1;
	}
	else
	{
		for(;i--;)a[i]=!(s[i]&1);
	}
	for(i=0;++i<n;)
	{
		if(i&1)
		{
			c[i]=c[i-1];
		}
		else
		{
			b[i]=b[i>>1]+1;
			c[i]=c[i-1]+b[i];
		}
		//cout<<b[i]<<' '<<c[i]<<endl;
	}
	k=n-1;
	//for(i=0;i<n;i++)cout<<a[i];cout<<endl;
	for(i=0;i<n;i++)
	{
		if(a[i])
		{
			if(c[k]-c[i]==c[k-i])m=!m;
		}
		//cout<<i<<' '<<c[k]<<' '<<c[i]<<' '<<c[k-i]<<' '<<m<<endl;
	}
	cout<<m*p;
}

Measured memory_bytes: 13084
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define REP(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n;
  int a[101]={};
  cin >> n;
  REP(i,n)cin>>a[i];

  sort(a, a+n, greater<int>());
  int alice=0;
  int bob=0;
  REP(i,n){
    if (i%2==0){
      alice += a[i];
    }
    else{
      bob += a[i];
    }
  }
  cout << alice - bob << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String t = sc.next();
		int n = sc.nextInt();
		String[] list = new String[n];
		for(int i = 0; i < n; i++) {
			list[i] = sc.next();
		}
		int sum = 0;
		for(int i = 0; i < n; i++) {
			IN:for(int j = 0; j < list[i].length(); j++) {
				for(int k = 0; k < t.length(); k++) {
					if(list[i].charAt((j+k)%list[i].length()) != t.charAt(k)) {
						continue IN;
					}
				}
				sum++;
				break;
			}
		}
		System.out.println(sum);
		
		
		
		
		
		
	}
}

Measured memory_bytes: 17364
N,M,C = map(int,input().split())
B = [int(i) for i in input().split()]
A = [[int(i) for i in input().split()] for _ in range(N)]

ans = 0
for i in range(N):
    culc = C
    for j in range(M):
        culc += A[i][j] * B[j]
    if culc>0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
from collections import defaultdict
import bisect

N,M = map(int, input().split())
PY = [tuple(map(int, input().split())) for _ in range(M)]

prefs = defaultdict(list)


for p, y in PY:
    # ここで実際の誕生年をつめてから、あとで県ごとにソートして単なる順番に座標圧縮
    prefs[p].append(y)

for k in prefs.keys():
    # 順に並び替えたので、後にbisectで位置を探せば誕生年から順番で取り出せる
    prefs[k].sort()

for p, y in PY:
    idx = bisect.bisect_left(prefs[p], y)
    print(str(p).zfill(6) + str(idx+1).zfill(6))

Measured memory_bytes: 35568
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, a, b) for(int i = a; a < b; i++);
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v) cerr << #v << ":"; rep(i, v.size()) cerr << " " << v[i]; cerr << endl
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n, m, x;
    int ans = INF;
    cin >> n >> m >> x;
    int C[12], A[12][12];
    rep(i, n) {
        cin >> C[i];
        rep(j, m) cin >> A[i][j];
    }
    rep(bit, 1 << n) {
        int money = 0;
        vector<int> U(m, 0);
        rep(i, n) {
            if (bit >> i & 1) {
                money += C[i];
                rep(j, m) {
                    U[j] += A[i][j];
                }
            }
        }
        bool f = 1;
        rep(i, m) {
            if (U[i] < x) f = 0;
        }
        if (f) chmin(ans, money);
    }
    cout << (ans == INF ? -1 : ans) << endl;
}

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



Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define rep(i,a,b) for(int (i) = (a); (i) <= (b); i++)
#define repd(i,a,b) for(int (i) = (a); (i) >= (b); i--)
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define mp make_pair
#define pb push_back
#define countbits __builtin_popcount
using namespace std;
#define is_digit(c) ((c) >= '0' && (c) <= '9')
#define is_upper(c) ((c) >= 'A' && (c) <= 'Z')
#define is_lower(c) ((c) >= 'a' && (c) <= 'z')
#define readchar() ((char)fgetc(stdin))
#define printchar(c) fputc((c), stdout)
void readline(char *s) {int len=0;char c;for(c=readchar(); c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void readstr(char *s) {int len=0;char c;for(c=readchar(); c!=' '&&c!='\n'; s[len++]=c, c=readchar());s[len]=0;}
void printstr(const char *s) {int len=strlen(s);rep(i,0,len-1) printchar(s[i]);}
void to_lower(char *s, int L, int R) {rep(i,L,R) if (is_upper(s[i])) s[i]=s[i]-'A'+'a';}
void to_upper(char *s, int L, int R) {rep(i,L,R) if (is_lower(s[i])) s[i]=s[i]-'a'+'A';}
ll readll() {
	char c;ll ans=0, x=1;for (c=readchar(); !is_digit(c)&&c!='-'; c=readchar());
	if (c=='-') x=-1, c=readchar();for (; is_digit(c); ans=ans*10+c-'0', c=readchar());return ans*x;
}
void printll(ll x) {
	int a[25], cnt=0;if (x==0) { printchar('0'); return; }if (x<0) printchar('-'), x=-x;
	for (; x; a[cnt++]=x-x/10*10, x/=10);repd(i,cnt-1,0) printchar(a[i]+'0');
}
#define readint() ((int)readll())
#define printint(x) printll((ll)(x))
int n, a[100005], k;
int main() {
	n=readint();k=readint();
	rep(i,1,n) a[i]=readint();
	sort(a+1,a+1+n);
	if (k>a[n]) {
		printstr("IMPOSSIBLE");
		return 0;
	}
	rep(i,1,n) {
		if (a[i]==k) {
			printstr("POSSIBLE");
			return 0;
		}
	}
	rep(i,1,n-1) {
		if (a[i+1]-a[i]==1) {
			printstr("POSSIBLE");
			return 0;
		}
	}
	rep(i,1,n-1) {
		if (a[i+1]!=a[i]&&(a[i+1]-k)%(a[i+1]-a[i])==0) {
			printstr("POSSIBLE");
			return 0;
		}
	}
	printstr("IMPOSSIBLE");
	return 0; 
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
string str;
void solve()
{
    int i,len=str.length(),w;
    cin>>w;
    for (i=0;i<len;i+=w)
        cout<<str[i];
    cout<<endl;
}
int main()
{
    while(cin>>str)
        solve();
}

Measured memory_bytes: 256
import math
#import numpy as np
import queue
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
    d = defaultdict(int)
    for i in range(n):
        s1 = list(input())
        d[tuple(sorted(s1))] += 1
    ans = 0
    for i in d.values():
        ans += i*(i-1)//2
    print(ans)

    return

if __name__ == '__main__':
    main()


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

#define MP make_pair
#define PB push_back
#define ALL(x)  (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define RANGEBOX(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
#define RANGE(x, l, r) ((l) <= (x) && (x) <= (r))
#define rep(i, N)  for (int i = 0; i < (int)(N); i++)
#define rrep(i, N) for (int i = N - 1; i >= 0; i--)
#define REP(i, init, N)  for (int i = (init); i < (int)(N); i++)
#define RREP(i, N, last) for (int i = (init - 1); i >= last; i--)
#define PB push_back

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVi;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int    INF  = 0x3f3f3f3f;
const LL     INFL = 0x3f3f3f3f3f3f3f3fLL;
const double DINF = 0x3f3f3f3f;

int main(){
	ios::sync_with_stdio(false);
    int k,x,y,n;
    int ans=0;
    cin>>n>>k>>x>>y;
    int i=0;
    for(i=0;i<n;i++){
        if(i<k){
            ans+=x;
        }
        else
            ans+=y;
    }
    cout<<ans<<endl;


    return 0;
}


Measured memory_bytes: 256
use std::io;

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

fn main() {
    let line = gets();
    let mut v: Vec<i32> = line
        .trim()
        .split_whitespace()
        .map(|x| x.parse::<i32>().unwrap())
        .collect();
    v.sort();
    println!("{}", v[0] + v[1]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    int n;
    cin >> n;
    for (int i = n * 100; i <= n * 100 + 99; i++) {
        if (i % 108 == 0) {
            cout << i / 108 << endl;
            return 0;
        }
    }
    cout << ":(" << endl;
    return 0;
}

Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<set>
#include<unordered_set>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef unordered_set<ll> uset;
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=0;i<=n;i++)
#define chmin(a,b) a=min(a,b)
#define chmax(a,b) a=max(a,b)
#define all(x) x.begin(),x.end()
#pragma gcc optimize("O3")
#pragma gcc optimize("unroll-loops")
#pragma gcc target("avx2,see4")
int ask(ll a,ll b,ll c,ll d){
	cout<<"? "<<a<<" "<<b<<" "<<c<<" "<<d<<"\n"<<flush;
	int res;
	cin>>res;
	return res;
}
int main(){
	ll h,w,n,K;
	cin>>h>>w>>n>>K;
	ll ans[55][55];
	rep(i,h)rep(j,w){
		ans[i][j]=ask(i,j,i,j);
	}
	ll fans=0,po2=1;
	rep(i,h)rep(j,w){
		fans=(fans+po2*ans[i][j])%K;
		po2=po2*2%K;
	}
	cout<<"! "<<fans<<"\n"<<flush;
}


Measured memory_bytes: 724
def modelAnswer(A:int,B:int,C:int,X:int,Y:int) -> int:
   ans = 10**9
   for i in range(10**5+1):
      total = i * 2 * C + max(0,X-i) * A + max(0,Y-i) * B
      ans = min(ans,total)
   return ans

def main():
   A,B,C,X,Y=map(int,input().split())
   print(modelAnswer(A,B,C,X,Y))
if __name__ == '__main__':
   main()

Measured memory_bytes: 3064
from collections import deque

def main():
    n, q = map(int, input().split())
    a = [[] for _ in range(n)]
    for i in range(n - 1):
        x, y = map(int, input().split())
        a[x - 1].append(y - 1)
        a[y - 1].append(x - 1)
    p = [0] * n
    for i in range(q):
        x, y = map(int, input().split())
        p[x - 1] += y
    c = [0] * n
    c[0] = 1
    que = deque([])
    que.append(0)
    while len(que) > 0:
        e = que.popleft()
        for i in a[e]:
            if c[i] > 0:
                continue
            c[i] = 1
            p[i] += p[e]
            que.append(i)
    for i in range(n):
        print(p[i])
main()

Measured memory_bytes: 105164
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> nums(N + 1, -1);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        if (nums[s] != -1 && nums[s] != c) {
            cout << -1 << endl;
            return 0;
        }
        nums[s] = c;
    }
 
    if (nums[1] == 0 && N != 1) {
        cout << -1 << endl;
        return 0;
    }
 
    for (int i = 1; i <= N; i++) {
        if (nums[i] == -1) {
            if (i == 1 && N != 1) {
                cout << 1;
            } else {
                cout << 0;
            }
        } else {
            cout << nums[i];
        }
    }
 
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.12f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll N;
    string S;
    cin >> N >> S;
    ll ans = 0;
    reps(i,0,9){
        reps(j,0,9){
            reps(k,0,9){
                string t = to_string(i) + to_string(j) + to_string(k);
                int pt = 0;
                bool flag = false;
                rep(i,0,N){
                    if(pt >= 3){
                        flag = true;
                        break;
                    }
                    if(S[i] == t[pt]) pt++;
                }
                if(pt >= 3) flag = true;
                if(flag) ans++;
            }
        }
    }

    cout << ans << enld;
    return 0;
}


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


void solve(long long N, std::vector<long long> a){
    map<ll, ll> R;
    for(ll i=0; i< N; i++){
        if(!R.count(a[i])) R[a[i]]=1;
        else R[a[i]]++;
    }
    ll ans=0;
    map<ll,ll>::iterator it1, it2;
    for(it1=R.begin(); it1!=R.end(); it1++){
        ll cnt = it1->second;
        it2 = it1;
        it2++;
        if(it2!= R.end() && it2->first == it1->first +1) 
            cnt += it2->second;
        if(it2!= R.end()) 
            it2++;
        if(it2!= R.end() && it2->first == it1->first +2) 
            cnt += it2->second;
        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

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


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

int main(){
  int n,d,x;
  cin >> n >> d >> x;
  vector<int>kosu(n);
  for(int i=0;i<n;i++)
    cin >> kosu.at(i);
  int ans=x;
  for(int i=0;i<n;i++){
    ans+=d/kosu.at(i);
    if(double(d)/kosu.at(i)!=d/kosu.at(i))
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;

//////////////////ここの値は必ず確認！！！！！////////////////////
//---------------------------------------------------------//
const int MOD = 1e9+7;
const int MAXR = 510000;
//---------------------------------------------------------//

template<ll mod> class modint{
public:
    ll val=0;
    //コンストラクタ
    modint(ll x=0){while(x<0)x+=mod;val=x%mod;}
    //コピーコンストラクタ
    modint(const modint &r){val=r.val;}
    //算術演算子
    modint operator -(){return modint(-val);} //単項
    modint operator +(const modint &r){return modint(*this)+=r;}
    modint operator -(const modint &r){return modint(*this)-=r;}
    modint operator *(const modint &r){return modint(*this)*=r;}
    modint operator /(const modint &r){return modint(*this)/=r;}
    //代入演算子
    modint &operator +=(const modint &r){
        val+=r.val;
        if(val>=mod)val-=mod;
        return *this;
    }
    modint &operator -=(const modint &r){
        if(val<r.val)val+=mod;
        val-=r.val;
        return *this;
    }
    modint &operator *=(const modint &r){
        val=val*r.val%mod;
        return *this;
    }
    modint &operator /=(const modint &r){
        ll a=r.val,b=mod,u=1,v=0;
        while(b){
            ll t=a/b;
            a-=t*b;swap(a,b);
            u-=t*v;swap(u,v);
        }
        val=val*u%mod;
        if(val<0)val+=mod;
        return *this;
    }
    //等価比較演算子
    bool operator ==(const modint& r){return this->val==r.val;}
    bool operator <(const modint& r){return this->val<r.val;}
    bool operator !=(const modint& r){return this->val!=r.val;}
};

using mint = modint<MOD>;

//入出力ストリーム
istream &operator >>(istream &is,mint& x){//xにconst付けない
    ll t;is >> t;
    x=t;
    return (is);
}
ostream &operator <<(ostream &os,const mint& x){
    return os<<x.val;
}

//累乗
mint modpow(const mint &a,ll n){
    if(n==0)return 1;
    mint t=modpow(a,n/2);
    t=t*t;
    if(n&1)t=t*a;
    return t;
}

//二項係数の計算
mint fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];
//テーブルの作成
void com_init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    FOR(i,2,MAXR){
        fac[i]=fac[i-1]*mint(i);
        inv[i]=-inv[MOD%i]*mint(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}
//演算部分
mint com(ll n,ll k){
    if(n<k)return 0;
    if(n<0)return 0;
    if(k==0) return 1;
    return fac[n]*finv[k]*finv[n-k];
}

int main() {
    ll N,M; cin >> N >> M;
    vector<ll> X(N);
    vector<ll> Y(M);
    REP(i,N) cin >> X[i];
    REP(i,M) cin >> Y[i];
    mint ans = 0;
    mint tate = 0;
    FOR(i,1,M){
        tate += (mint)(i*(M-i)) * (mint)(Y[i]-Y[i-1]);
    }
    FOR(i,1,N){
        ans += (mint)(i*(N-i)) * (mint)(X[i]-X[i-1]) * tate;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16656