akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,s,n) for(int i = s; i < (int)(n); i++)

int main() {
  string s;
  cin >> s;
  cout << s;
  if(s[s.size()-1] == 's') cout << "es" << endl;
  else cout << "s" << endl;
}

Measured memory_bytes: 3624
import java.util.*;
import java.util.stream.*;

public class Main{
	public static void main(String[] $){
		Scanner s = new Scanner(System.in);
		int n=s.nextInt(),m=s.nextInt(),q=s.nextInt();
		long[]a=new long[n+2],b=new long[m+2];
		for(int i=1;i<=n;++i)
			a[i]=s.nextLong();
		for(int i=1;i<=m;++i)
			b[i]=s.nextLong();
		a[0]=b[0]=-40_000_000_000L;
		a[n+1]=b[m+1]=40_000_000_000L;
//		System.err.println(Arrays.toString(a));
//		System.err.println(Arrays.toString(b));
		for(int p=0;p<q;++p){
			long v=s.nextLong();
			int ab=~Arrays.binarySearch(a,v);
			int bb=~Arrays.binarySearch(b,v);

			long al=a[ab-1],ar=a[ab];
			long bl=b[bb-1],br=b[bb];
			System.out.println(
					LongStream.of(
							f(v,al,bl,br),
							f(v,ar,bl,br),
							f(v,bl,al,ar),
							f(v,br,al,ar)
					).min().getAsLong()
			);
		}
	}
	private static long f(long v,long w,long... e){
		return Math.abs(v-w)+Arrays.stream(e).map(i->Math.abs(w-i)).min().getAsLong();
	}
}

Measured memory_bytes: 163976
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int, int >
#define F first
#define S second
#define int  long long int
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int N=2e5+100;
ll a[N][2];
int32_t main(){
    ll n;
    cin >> n;
    vector <int> b;
    for (int i=1;i<=n;i++){
        cin >> a[i][0] >> a[i][1];
        b.pb(i);
    }
    ld s=1;
    for (int i=1;i<=n;i++){
        s*=i;
    }
    ld ans=0;
    do{
        ld cnt=0;
        for (int i=1;i<n;i++){
            ll x=abs(a[b[i]][0]-a[b[i-1]][0]);
            ll y=abs(a[b[i]][1]-a[b[i-1]][1]);
            x*=x;
            y*=y;
            x+=y;
          //  cout << x << endl;
            cnt+=pow((ld)x,0.5);
        }
      //  cout << cnt << endl;
        ans+=cnt/s;

    }while(next_permutation(b.begin(),b.end()));
    cout << fixed << setprecision(20) << ans;
}



Measured memory_bytes: 512
n,k=map(int,input().split())
arr=list(map(int,input().split()))
ans=10**18
for i in range(2**n):
  flags=[0]*n
  pos=0
  while i!=0:
    if i%2==1:
      flags[pos]=1
      i-=1
    i=i//2
    pos+=1
  cost=0
  tmp=[0]*n
  tmp[0]=arr[0]
  maxs=arr[0]
  for j in range(1,n):
    if flags[j]==1:
      tmp[j]=max(maxs+1,arr[j])
    else:
      tmp[j]=arr[j]
    cost+=(tmp[j]-arr[j])
    maxs=max(maxs,tmp[j])
  if flags.count(1)>=k:
    ans=min(ans,cost)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n, k;
    cin >> n >> k;

    vl v(n);
    rep(i, k) {
        ll d;
        cin >> d;
        rep(j, d) {
            ll a;
            cin >> a;
            a--;
            v[a]++;
        }
    }

    ll ans = 0;
    rep(i, n) {
        if(v[i] == 0) {
            ans++;
        }
    }
    
    out(ans);
    re0;
}

Measured memory_bytes: 3628
from heapq import *
h, w = map(int, input().split())

char = [0]*26
for i in range(h):
    a = input()
    for j in range(w):
        char[ord(a[j])-97] -= 1

heapify(char)

q = []
if h % 2 == 1 and w % 2 == 1:
    for i in range((h//2)*(w//2)):
        q.append(4)
    for i in range((h+w-2)//2):
        q.append(2)
    q.append(1)

elif h % 2 == 1:
    for i in range((h//2)*(w//2)):
        q.append(4)
    for i in range(w//2):
        q.append(2)

elif w % 2 == 1:
    for i in range((h//2)*(w//2)):
        q.append(4)
    for i in range(h//2):
        q.append(2)

else:
    for i in range((h//2)*(w//2)):
        q.append(4)

flag = 1
for i in q:
    a = heappop(char)
    if -a >= i:
        a += i
        heappush(char, a)
    else:
        flag = 0
        break

if flag == 1:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3188
//author-micheal corleone
//the godfather
#include <bits/stdc++.h>
#include <set> 
#include<algorithm>
#include <set> 
#include<algorithm>
#define ll long long int
#define in(n) scanf("%lld",&n)
#define in2(a,b) scanf("%lld %lld",&a,&b)
#define out(n) printf("%lld\n",n)
#define inf 100000000000000
#define endl "\n"
#define precise(x) fixed << setprecision(x) 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
const int MOD =998244353;
#define f(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
 
using namespace std;

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
}
 ll mod_pow(int a,int b,int M = MOD)
{
    int res = 1;
    
    while(b)
    {
        if(b&1) res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
    }
    
    return res;
}
 //ll power(ll x, ll y) 
//{ 
  //  ll temp; 
    //if( y == 0) 
     //   return 1; 
    //temp = power(x, y/2); 
    //temp=temp%MOD;
    //if (y%2 == 0) 
     //   return (temp%MOD)*(temp%MOD); 
    //else
      //  return (x%MOD)*(temp%MOD)*(temp%MOD); 
//} 
 
 
ll ncr(ll n,ll r){if(n==1 || r==0)return 1;if(r>n/2)r=n-r;
	ll ans=1;for(ll i=1;i<=r;i++){ans=((ans * n )/i);n--;}return ans;
}
ll ncrsum(ll n,ll r, ll mod){
    if(n==1 || r==0)return 1;
  //  ll ans=1,sum=1;for(ll i=1;i<=r;i++){ans=((((ans * n)%MOD )*modinv(i,MOD))%mod);n--;sum+=ans;sum%=mod;}return sum;
}
 //diamond[2000005],ans[1000006];
 const int maxn=2e5+100;
 

int main()
{
	ios_base::sync_with_stdio(0);
   cin.tie(0);
    cout.tie(0);
     ll t;
   //cin>>t;
   
   t=1;	
   while(t--)
    {
        ll i1,i2,k,j,j1,a1,i31,i3,j2,i5,i4,i6,i7,i,n,m;
        ll x,y,z;
        ll total=0,cnt=0;
        ll flag=0;
        y=0;
        ll res,res1,ans,res2,q;
        ans=0;
        res1=0,res=0;
        ll s1,s2,s3;
        s2=0;
        ll sum=0,flag1=0;
        s1=0;
        ll k1,k2,k3;
        k1=0,k2=0;
        ll d,required,days;
        //cin>>h>>c>>required;
        cin>>n>>k;
      
        long long int dp[n+1][k+1];
        ll a[n+1],w[n+1];
        for(i=1;i<=n;i++)
        {
        	cin>>w[i]>>a[i];
		}
		for(i=0;i<=n;i++)
		{
			for(j=0;j<=k;j++)
			{
				if(i==0 || j==0) dp[i][j]=0;
				else
				{
					if(w[i]<=j)
					{
						x=dp[i-1][j];
						y=dp[i-1][j-w[i]]+a[i];
						dp[i][j]=max(x,y);
					}
					else dp[i][j]=dp[i-1][j];
				}
			}
		}
        cout<<dp[n][k]<<endl;
	
     }
    
}
	

Measured memory_bytes: 79232
/**
       ������������    ������������
		Author : Avi J Patel
		University : DA-IICT
       ������������    ������������
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair 
#define N 100000
#define mod 1000000007
int main()
{
    int n,m;
    cin>>n>>m;
    vector<pair<int,int>> a;
    int max1=-1,min1=100000;
    for(int i=0;i<m;i++)
    {
    	int a1,b1;
    	cin>>a1>>b1;
    	a.pb(mp(a1,b1));
    	if(a1>max1)
    	max1=a1;
    	if(b1<min1)
    	min1=b1;
	}
	int cnt=0;
	//cout<<max1<<" "<<min1<<endl;
	for(int i=max1;i<=min1;i++)
	{
		cnt++;
	}
	cout<<cnt;
    return 0;
}



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

import sys
import math

sys.setrecursionlimit(10 ** 6)

input_line = input()
N, X, Y = map(int, input_line.split(" "))

ans = [0] * (N-1)
for i in range(1, N):
    for j in range(i+1, N+1):
        d = j - i
        d2 = d
        if j>X or i>Y:
            d2 = abs(X-i)+abs(Y-j)+1
        d = min(d,d2)
        ans[d-1] += 1

for d in ans:
    print(d)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
//
bool dfs(vector<vector<int> > &g,vector<bool> &used,vector<bool> &use,int now){
	if(!used[now]) return false;
	used[now] = false;
	//use[now] = false;
	bool flag = true;
	for(int i=0;i<g[now].size();i++)if(flag){
		int next = g[now][i];
		if(!use[now]) continue;
		flag = dfs(g,used,use,next);
	}
	use[now] = false;
	used[now] = true;
	return flag;
}

int main(){
	int v,e;
	cin>>v>>e;
	vector<vector<int> > g(v);
	for(int i=0;i<e;i++){
		int s,t;
		cin>>s>>t;
		g[s].push_back(t);
	}
	vector<bool> used(v,true);
	vector<bool> use(v,true);
	bool f = true;
	for(int i=0;i<v;i++){
		if(f&&use[i]){
			f = dfs(g,used,use,i);
		}
	}
	if(!f){
		cout<<1<<endl;
	}else{
		cout<<0<<endl;
	}

	return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);++(i))
#define EACH(e,v) for(auto& e:v)

template<typename T> struct Edge {
  int from, to;
  T weight;
  Edge() : from(0), to(0), weight(0) {}
  Edge(int f, int t, T w) : from(f), to(t), weight(w) {}
};
template<typename T> using Edges = vector< Edge< T > >;
template<typename T> using Graph = vector< Edges< T > >;
template<typename T> void     add_edge(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); g[to].emplace_back(to,from,w); }
template<typename T> void      add_arc(Graph< T > &g, int from, int to, T w = 1) { g[from].emplace_back(from,to,w); }
template<typename T> void add_to_edges(Edges< T > &e, int from, int to, T w = 1) { e.emplace_back(from,to,w); }

template< typename T > pair< T, int > dfs(const Graph< T > &g, int idx, int par)
{
  pair< T, int > ret(0, idx);
  for(auto &e : g[idx]) {
    if(e.to == par) continue;
    auto cost = dfs(g, e.to, idx);
    cost.first += e.weight;
    ret = max(ret, cost);
  }
  return ret;
}

template< typename T > T tree_diameter(const Graph< T > &g)
{
  auto p = dfs(g, 0, -1);
  auto q = dfs(g, p.second, -1);
  return (q.first);
}

int N;
bool dp[202020];

signed main() {

  cin >> N;

  Graph<int> g(N);

  REP(i, N - 1) {
    int a, b;
    cin >> a >> b;
    --a, --b;
    add_edge(g, a, b);
  }

  int dia = tree_diameter(g);

  dp[0] = true;
  dp[1] = false;
  FOR(i, 2, 202020) dp[i] = !dp[i - 1] | !dp[i - 2];

  if (dp[dia]) cout << "First" << endl;
  else cout << "Second" << endl;

}


Measured memory_bytes: 27008
"use strict";
function main(input) {
  let s = input[0];
  let q = parseInt(input[1]);

  let tag = false;

  let f = "";
  let c = "";

  for(let i=0;i<q;i++){
    let kari = input[i+2].trim().split(" ");
    let query = kari[0];

    if(query==="1"){
      tag = !tag;
    }else{
      f = kari[1];
      c = kari[2];
      if(f === "1"){
        if(tag){
          s = s + c;
        }else{
          s = c + s;
        }
      }else{
        if(tag){
          s = c + s;
        }else{
          s = s + c;
        }
      }
    }
  }

  if(tag){
    s = s.split("").reverse().join("");
  }
  console.log(s);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"));

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  string s;
  cin >> s;
  int n = sz(s);
  vi32 cnt(2);
  rep(i, n) cnt[s[i] - '0']++;
  cout << n - (max(cnt[0], cnt[1]) - min(cnt[0], cnt[1])) << endl;
}

Measured memory_bytes: 512
<?php
$n = intval(fgets(STDIN));
$A = array_map("intval", explode(" ", trim(fgets(STDIN))));

$min = 2;
$max = 2;
for($i = $n-1; $i >= 0; $i--){
    $a = $A[$i];
    if(ceildiv($min, $a) > intdiv($max, $a)){
        echo -1,"\n";exit;
    }
    $min = ceildiv($min, $a)*$a;
    $max = intdiv($max, $a)*$a + $a - 1;
}
echo "$min $max\n";

function ceildiv($a, $b){
    return intdiv($a+$b-1, $b);
}

Measured memory_bytes: 16884
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		char[] c = new char[10];
		String s;
		HashMap<String, Long> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			c = sc.next().toCharArray();
			Arrays.sort(c);
			s = new String(c);
			if (map.get(s) == null) {
				map.put(s, 1L);
			} else {
				map.put(s, map.get(s) + 1);
			}
		}

		long ans = 0;
		for (Long v : map.values()) {
			ans += v * (v - 1) / 2;
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 55936
import copy

N, x = map(int,input().split())
a = list(map(int, input().split()))
a.append(0) # たぶん要らないけど念の為にダミー
b = copy.deepcopy(a) # bに対して操作して最後にaと比較

if b[0] > x:
    b[0] = x

for i in range(N - 1): # 左から順に和がx以下になるように数字を変える
    if (b[i] + b[i + 1]) > x:
        b[i + 1] = x - b[i]

ans = 0
for i in range(N): # 操作したbと元のaの差を比較
    ans += a[i] - b[i]

print(str(ans))


Measured memory_bytes: 15228
#include<bits/stdc++.h>
using namespace std;
int R[100010], L[100010], ans[100010];
int main()
{
	string s;
	cin >> s;
	for(int i=1; i<=s.length(); i++)
	{
		if(s[i-1] == 'R')
		{
			R[i] = 1;
		}
		else
		{
			L[i] = 1;
		}
	}

	for(int i=1; i<=s.length(); i++)
	{
		if(R[i])
		{
			R[i] += R[i-1];
		}
	}

	for(int i=s.length(); i>=1; i--)
	{
		if(L[i])
		{
			L[i] += L[i+1];
		}
	}

	for(int i=1; i<=s.length(); i++)
	{
		if(R[i+1])
		{
			R[i] = 0;
		}
	}

	for(int i=s.length(); i>=1; i--)
	{
		if(L[i-1])
		{
			L[i] = 0;
		}
	}

	// for(int i=1; i<=s.length(); i++)
	// {
	// 	cout << i << " " << L[i] << " " << R[i] << endl;
	// }

	for(int i=1; i<=s.length(); i++)
	{

		if(R[i])
		{
			if(R[i]&1)
			{
				ans[i] += R[i]/2 + 1;
				ans[i+1] += R[i] / 2;
			}
			else
			{
				ans[i] += R[i]/2;
				ans[i+1] += R[i]/2;
			}
		}
		else if(L[i])
		{
			if(L[i]&1)
			{
				ans[i] += L[i]/2 + 1;
				ans[i-1] += L[i]/2;
			}
			else
			{
				ans[i] += L[i]/2;
				ans[i-1] += L[i]/2;
			}
		}
	}

	for(int i=1; i<=s.length(); i++)
	{
		cout << ans[i] << " ";
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1792
import sys
from collections import defaultdict, Counter, deque
from itertools import accumulate, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right, bisect
from heapq import heappop, heappush
from fractions import gcd
from math import ceil, floor, sqrt, cos, sin, pi
from copy import deepcopy

# If you use recursive call, uncomment this code
#sys.setrecursionlimit(10**6)

def main():
    k = int(input())
    a,b = map(int, input().split())
    ans = k*(a//k + (a%k!=0))
    if ans <= b:
        print("OK")
    else:
        print("NG")
        

if __name__ == '__main__':
    main()


Measured memory_bytes: 10580
//
//  main.cpp
//  ProCon
//
//  Created by hashimotoryoma on 2017/08/20.
//  Copyright © 2017年 hashimotoryoma. All rights reserved.
//

#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <vector>

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

using namespace std;

typedef long long ll;



int main() {
    // insert code here...    return 0;
    //////
    // input from txt
    /*
     std::ifstream in("input.txt");
     std::cin.rdbuf(in.rdbuf());
     std::ofstream out("output.txt");
     std::cout.rdbuf(out.rdbuf());
     ////
     */
    int a,b,c;
    cin >> a >> b >> c;
    int sum = a+b+c;
    if(a*2 == sum || b*2 == sum || c*2 == sum){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define x 100000

int main(){

  int n,q,S[x],T[x],left,right,mid;
  int i,j,c=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  } 
  for(i=0;i<q;i++){

    left=0;
    right = n;  

    while(left<right){

      mid = (left + right)/2;

      if(S[mid]==T[i]){
	c++;
	break;
      }
      else if(T[i]<S[mid]){
	right = mid;
      }
      else if(T[i]>S[mid]) { left = mid + 1; }
    }
    
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1e18;
const int INF = 1e18;

int n;
vector<P> G[50];

long long mod_pow(long long x, long long n){
	if(n == 0) return 1;
	long long res = mod_pow(x*x % mod, n / 2);
	if(n & 1) res = res*x % mod;
	return res;
}

vector<P> pre;

void dfs(int u, int p){
	for(auto i : G[u]){
		if(i.first == p) continue;
		pre[i.first] = {u, i.second};
		dfs(i.first, u);
	}
}

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cin >> n;
	rep(i, 0, n - 1){
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back({b, i});
		G[b].push_back({a, i});
	}
	int m;
	cin >> m;
	vector<int> u(m), v(m);
	rep(i, 0, m){
		cin >> u[i] >> v[i];
		u[i]--; v[i]--;
	}
	vector<vector<bool> > use(m, vector<bool>(n - 1, false));
	rep(i, 0, m){
		pre.clear();
		pre.resize(n, {-1, -1});
		dfs(u[i], -1);
		int now = v[i];
		// cout << v[i] << ' ';
		while(now != -1){
			if(pre[now].second == -1) break;
			use[i][pre[now].second] = true;
			now = pre[now].first;
			// cout << now << ' ';
		}
		// cout << endl;
	}
	int ans = mod_pow(2, n - 1);
	for(int i = 1; i < (1 << m); i++){
		vector<bool> tmp(n - 1, false);
		int cnt = __builtin_popcountll(i);
		rep(j, 0, m){
			if(i & (1 << j)){
				rep(k, 0, n - 1){
					tmp[k] = tmp[k] | use[j][k];
				}
			}
		}
		int sum = 0;
		// cout << i << " : ";
		rep(j, 0, n - 1){
			if(tmp[j]){
				sum++;
				// cout << j << ' ';
			}
		}
		// cout << endl;
		int now = mod_pow(2, n - 1 - sum);
		if(cnt % 2) ans = (ans + mod - now) % mod;
		else ans = (ans + now) % mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
import collections
import heapq

def set_debug(debug_mode=False):
    if debug_mode:
        fin = open('input.txt', 'r')
        sys.stdin = fin


def int_input():
    return list(map(int, input().split()))


if __name__ == '__main__':
    # set_debug(True)

    # t = int(input())
    t = 1

    for ti in range(1, t + 1):
        n = int(input())

        for i in range(1000, 11000, 1000):
            if i >= n:
                print(i - n)
                break



Measured memory_bytes: 9280
#include <iostream>
#include <fstream>
#include <string>
#include <stdlib.h>
#include <vector>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <ctime>
#include <map>

using namespace std;

#define int int64_t

signed main()
{
    //freopen("../input.txt", "r", stdin);
    int n;
    cin >> n;
    vector<int> a(n);
    map<int, int> cnt;

    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        cnt[a[i]]++;
    }

    int ans = 0;

    for (const auto el : cnt) {
        ans += (el.second) * (el.second - 1) / 2;
    }

    for (int i = 0; i < n; ++i) {
        int curr = a[i];
        int val = cnt[curr];
        int sub = (val) * (val - 1) / 2;
        ans -= sub;
        cout << ans + (val - 1) * (val - 2) / 2 << "\n";
        ans += sub;
    }

    return 0;
}


Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
const int N = 10;
char str[N];

int main()
{
    cin>>str;
    int len = strlen(str);
    for(int i=0;i<len-1;i++) {
        if(str[i] == 'A' && str[i + 1] == 'C') {
            puts("Yes");
            return 0;
        }
    }
    puts("No");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

string signs = "+-";

int main()
{
    int N;

    cin >> N;

    int A = N / 1000;
    int B = (N % 1000) / 100;
    int C = (N % 100) / 10;
    int D = N % 10;

    for (int i = 0; i <= 1; i++)
    {
        for (int j = 0; j <= 1; j++)
        {
            for (int k = 0; k <= 1; k++)
            {
                int sum = 0;
                sum = A;
                sum = signs[i] == '+' ? sum + B : sum - B;
                sum = signs[j] == '+' ? sum + C : sum - C;
                sum = signs[k] == '+' ? sum + D : sum - D;
                if (sum == 7)
                {
                    string ans = to_string(A) + signs[i] + to_string(B) + signs[j] + to_string(C) + signs[k] + to_string(D) + "=7";
                    cout << ans << endl;
                    goto a;
                }
            }
        }
    }
a:

    return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

int main()
{
	double num,flt;
	while (cin >> num, num > 0) {
		string ans="";
		int F[5] = {0}, I[10] = { 0 };
		int i = 0, j = 7;
		int n = (int)num;
		flt = num - n;

		if (n > 255) ans = "NA";
		else {
			rep(i, 4) {
				flt *= 2;
				F[i] = flt >= 1.0 ? 1 : 0;

				if (flt == 1.0)break;
				else if (flt > 1.0)
					flt = flt-1.0;
			}

			if (flt != 1.0)ans = "NA";
			if (flt == 0)ans = "";

			if (ans == "NA")cout << ans << endl;
			else {
				while (1) {
					I[j--] = n % 2;
					n /= 2;
					if (n == 0)break;
				}
				rep(i, 8)cout << I[i];
				cout << ".";
				rep(i, 4)cout << F[i];
				cout << endl;
			}
		}
	}
	return	0;
}

Measured memory_bytes: 3192
package main

import (
	"fmt"
)

func sums(n int) int {
	var sum int
	for n > 0 {
		sum += n%10
		n/=10
	}
	return sum
}

func main() {
	var (
		n, a, b, sum int
	)
	fmt.Scan(&n, &a, &b)
	for i := 1; i<n+1; i++{
		if v := sums(i); a<=v && v<=b {
			sum += i
		} 
	}
	
	fmt.Println(sum)
}


Measured memory_bytes: 512
n,m = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
q = []
for i in range(m):
    b, c = map(int,input().split())
    q.append([b,c])
q.sort(key=lambda x:x[1], reverse=True)
l = 0
for i in range(m):
    if l >= n:
        print(sum(a))
        exit()
    for j in range(l, min(l + q[i][0], n)):
        if a[j] < q[i][1]:
            a[j] = q[i][1]
        else:
            print(sum(a))
            exit()
    l += q[i][0]
print(sum(a))





Measured memory_bytes: 25672
#include <stdio.h>
int main(void){
    int a, b, c;
    int i;
    int count = 0;
    
    1 <= a,b,c <= 10000;
    a <= b;
    
    scanf("%d %d %d", &a, &b, &c);
    
    for(i = a; i <= b; i++){
        if(c % i == 0) count++;
    }
    
    printf("%d\n", count);
    
    return 0;
}
    



Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define repp(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ppb pop_back()
#define ALL(a) (a).begin(),(a).end()

using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;


signed main(){
    ll n,m; cin >> n >> m;
    if(2*n>=m){
        cout << m/2 << endl;
    }else{
        m-=2*n;
        cout << n+m/4 << endl;
    }
}


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

using namespace std;

typedef long long int ll;
 
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 pair<int,int> pair;

int main(){
  int x; cin >> x;
  if(x==0) x=1;
  else x=0;
  cout << x << endl;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#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 (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
#define equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;
const ll INF = 1e18;
const long double EPS = 1e-10;
const int MAX = 1e6;

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

vector<bool> IsPrime;

void sieve(int max) {
  if (max+1 > IsPrime.size()) {
    IsPrime.resize(max+1, true);
  }
  IsPrime[0] = false;
  IsPrime[1] = false;

  for (int i = 2; i*i <= max; i++) {
    if (IsPrime[i]) {
      for (int j = 2; i*j <= max; j++) {
        IsPrime[i*j] = false;
      }
    }
  }
}

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

  sieve(MAX);

  ll lcm = 1;
  vector<ll> l(MAX + 1, 0), ac = a;
  rep(i, n) {
    for (ll j = 2; j * j <= a[i]; j++) {
      if (ac[i] == 1) break;
      if (!IsPrime[j]) continue;
      ll d = 0;
      while (ac[i] % j == 0) {
        d++;
        ac[i] /= j;
      }
      if (d > l[j]) {
        lcm = (lcm * modpow(j, d - l[j])) % mod;
        l[j] = d;
      }
    }
    if (ac[i] != 1 && l[ac[i]] == 0) {
      lcm = (lcm * ac[i]) % mod;
      l[ac[i]] = 1;
    }
  }

  ll ans = 0;
  rep(i, n) {
    ll res = (lcm * modpow(a[i], mod - 2)) % mod;
    ans = (ans + res) % mod;
  }
  cout << ans << endl;



  
  return 0;
}

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

int main(){
    vector<int> p;
    bool np[1120] = {};
    for(int i = 2; i < 1120; i++){
        if(np[i])   continue;
        p.push_back(i);
        for(int j = i+i; j < 1120; j+=i) np[j] = true;
    }
    vector<vector<int>> dp(15, vector<int>(1121, 0));
    dp[0][0] = 1;
    for(int prime : p){
        for(int i = 14; i >= 1; i--){
            for(int j = prime; j <= 1120; j++){
                dp[i][j] += dp[i-1][j-prime];
            }
        }
    }
    int n, k;
    while(cin >> n >> k, n+k)   cout << dp[k][n] << endl;
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll C[5][5];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    REP(i, 3) {
        REP(j, 3) {
            cin >> C[i][j];
        }
    }

    for (ll a1 = -100; a1 <= 200; a1++) {
        ll b1 = C[0][0] - a1;
        ll b2 = C[0][1] - a1;
        ll b3 = C[0][2] - a1;
        ll a2 = C[1][0] - b1;
        ll a3 = C[2][0] - b1;
        ll A[3] = {a1, a2, a3};
        ll B[3] = {b1, b2, b3};

        bool e = true;
        REP(i, 3) {
            REP(j, 3) {
                if (A[i] + B[j] != C[i][j])
                    e = false;
            }
        }
        if (e) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i ++)
#define rep1(i, n) for (int i=1; i <= n; i ++)
#define _min(x, y) x = min(x, y)
#define _max(x, y) x = max(x, y)
using namespace std;


int main() {
  int n; cin >> n;
  vector<int> V;
  rep(i, n) {
    int v; cin >> v;
    V.push_back(v);
  }
  sort(V.begin(), V.end());
  double prev = V[0];
  rep1(i, n - 1) {
    prev += V[i];
    prev /= 2;
  }
  cout << prev << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <numeric>
#include <cmath>
#include <tuple>
#include <bitset>
#include <utility>
#include <climits>
#include <iomanip>
 
#define push emplace_back
#define each(i, x) for (auto i=0; i < x; i++)
using ull = unsigned long long;
constexpr auto mod = 1000000007;
constexpr auto INF = ULLONG_MAX;
 
using namespace std;
template <typename T> inline void dump(const T& x) { cout << "[" << x << "]" << endl; }
template <typename T> inline void dump(const vector<T>& x) { for (const auto v : x) { cout << v << " "; } cout << endl; }
template <typename T> inline void sort_asc(vector<T>& x) { std::sort(x.begin(), x.end()); }
template <typename T> inline void sort_desc(vector<T>& x) { std::sort(x.begin(), x.end(), greater<T>()); }
template <typename T> inline T max_value(vector<T>& x) { return *max_element(x.begin(), x.end()); }
template <typename T> inline T min_value(vector<T>& x) { return *min_element(x.begin(), x.end()); }
template <typename T> inline T sum_value(vector<T>& x) { return accumulate(x.begin(), x.end(), 0ULL); }
 
int main() {
  ull k, x;
  cin >> k >> x;

  ull res = 500 * k;
  if (res >= x) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

 
  return 0;
}


Measured memory_bytes: 256
def count_doubled(i, n):
	count=0
	while(i<n):
		count+=1
		i = i<<1
	return count

N, K = map(int, input().split())

result = 0

for i in range(1, N+1):
	result += pow(0.5, count_doubled(i, K))/N

print("{:.12f}".format(result))

Measured memory_bytes: 3060
from collections import defaultdict
V, E = map(int, raw_input().split())
ans = 0
parent = [i for i in range(V)]
v = defaultdict(set)
for i in range(V):
    v[i].add(i)
edges = [map(int, raw_input().split()) for i in range(E)]
edges.sort(key = lambda x:x[2])
cnt = 0
while edges:
    if cnt == V - 1: break
    s, t, d = edges.pop(0)
    a, b = parent[s], parent[t]
    if a != b:
        if a > b: a, b = b, a
        v[a] = v[a] | v[b]
        for i in v[b]: parent[i] = a
        ans += d
        cnt += 1
print ans

Measured memory_bytes: 33624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; rep(i_debug, v.size()) { cout << v[i_debug] << ",";}cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; rep(i_debug, m.size()) { rep(j_debug, m[i_debug].size()) { cout << m[i_debug][j_debug] << ","; } cout << endl; } }

int main() {
    int X,Y,A,B,C;
    cin >> X >> Y >> A >> B >> C;
    vector<int> p(A);
    vector<int> q(B);
    vector<int> r(C);
    rep(i,A) cin >> p[i];
    rep(i,B) cin >> q[i];
    rep(i,C) cin >> r[i];
    sort(all(p),greater<int>());
    sort(all(q),greater<int>());
    sort(all(r),greater<int>());
    vector<int> anss;
    for(int i = 0;i<X;i++) anss.push_back(p[i]); 
    for(int i = 0;i<Y;i++) anss.push_back(q[i]); 
    for(int i = 0;i<C;i++) anss.push_back(r[i]); 
    sort(all(anss),greater<int>());
    ll ans = 0;
    rep(i,X+Y){
        ans += anss[i];
    }
    cout << ans << endl;
}


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

int main() {
  int K, S;
  cin >> K >> S;
  int ans = 0;
  for (int X = 0; X <= K; X++) {
    for (int Y = 0; Y <= K; Y++) {
      if (0 <= S - X - Y && S - X - Y <= K) ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
a = sorted([int(input()) for i in range(5)])
mina = 10
minban = 0
for i in range(5):
    b = a[i]%10
    if b != 0 and b <= mina:
        mina = b
        minban = i
time = 0
for i in range(5):
    if i == minban:
        time += a[i]
    else:
        time += (-(-a[i]//10))*10
print(time)

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

int main() {
  long long H, N; cin >> H >> N;
  long long A;
  bool hp = false;

  for(int ni=0; ni<N; ++ni) {
    cin >> A;
    H-=A;
  }

  if(H<=0) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<stack>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pII;
#define pb push_back
#define X first
#define Y second
#define mp make_pair
#define clr(x,y) memset(x,y,sizeof(x))
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
const int inf=0x3f3f3f3f;
const ll mod=1e9+7;
const int maxn=1e6+5;
//ll fmod(ll x,ll y){ll res=1;while(y){if(y&1)res=res*x%mod;y>>=1;x=x*x%mod;}return res;}
//ll gcd(ll x,ll y){return y==0?x:gcd(y,x%y);}
char s[maxn];
int main()
{
    while(~scanf("%s",s))
    {
        ll now = 0;
        ll ans = 0;
        int n = strlen(s);
        for(int i = 0; i < n; ++i)
        {
            if(s[i] == 'W')
                ans += now;
            else
                now++;
        }
        cout<<ans<<endl;
    }
}












Measured memory_bytes: 384
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n,k;
ll a[100005];
ll dp[42];
int main()
{
        cin >> n >> k;
        for(ll i=1;i<=n;i++) {
                cin >> a[i];
        }
        for(ll i=40;i>=0;i--) {
                for(ll j=1;j<=n;j++) {
                        if(a[j]&(1LL << i)) dp[i]++;
                }
        }
        ll curn = 0;
        ll ans = 0LL;
        for(ll i = 40;i>=0;i--) {
                ll yo = (1LL << i);
                if(curn + yo > k) {
                        ans = (ans + yo*dp[i]);
                }else {
                        ll antis = n - dp[i];
                        if(dp[i] > antis) {
                                ans = (ans + yo*dp[i]);
                        }else {
                                ans = (ans + yo*(antis));
                                curn += yo;
                        }
                }
        }
        cout << ans << endl;
        return 0;
}


Measured memory_bytes: 1024
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

void solve (int n, int m, int h, int w)
{
    if (n % h == 0 && m % w == 0)
    {
        cout << "No" << endl;
        return;
    }

    bool sw = false;
    if (n % h == 0)
    {
        assert(m % w != 0);
        swap(n, m);
        swap(h, w);
        sw = true;
    }

    vvi grid(n, vi(m));
    const int X = (int)1e8;

    forn (i, n)
    {
        forn (j, m) if (j)
            grid[i][j] = -1;

        if (i % h == 0)
            grid[i][0] = X;
        else if (i % h == h - 1)
            grid[i][0] = -X - 1;
        else
            grid[i][0] = -1;
    }

    if (sw)
    {
        vvi ngrid(m, vi(n));
        forn (i, n) forn (j, m)
            ngrid[j][i] = grid[i][j];
        grid = ngrid;
        swap(n, m);
        swap(h, w);
    }

//    ll sum = 0;
//    forn (i, n) forn (j, m)
//        sum += grid[i][j];
//    assert(sum > 0);
//
//    forn (x, n - h + 1) forn (y, m - w + 1)
//    {
//        ll csum = 0;
//        forn (i, h) forn (j, w)
//            csum += grid[x + i][y + j];
//        assert(csum < 0);
//    }

    cout << "Yes" << endl;
    forn (i, n)
    {
        forn (j, m)
            cout << grid[i][j] << " \n"[j + 1 == m];
    }
}

int main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, m, h, w;
    while (cin >> n >> m >> h >> w)
//    forn (n, 10) if (n)
//    forn (m, 10) if (m)
//    forn (h, n + 1) if (h)
//    forn (w, m + 1) if (w)
        solve(n, m, h, w);
}


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

using namespace std;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n=0, k=0;
	int count=0;
	double times=0;
	double prob=0;
	
	cin >> n >> k;
	
	for(int i=1; i<=n; i++){
		count = i;
		while(k>count){
			count = count * 2;
			times++;
		}

		prob = prob + ( (double)1/n * (pow((double)1/2, times)) );
		count=0;
		times=0;
	}
	cout << setprecision(12) <<prob;
	return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize("-Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef int in;
#define int long long
#define pb push_back
#define f first
#define s second
#define double long double
const int MAX=2e5+5;
const int MAX2=2e6+4;
const int MAAX=2e9+5;
const int MOD=1e9+7;
in main()
{
   int n;
   cin>>n;
   int p[10],q[10];
   for(int i=0;i<n;i++)
   {
       cin>>p[i];
   }
   for(int i=0;i<n;i++)
   {
       cin>>q[i];
   }
   int per[10];
   for(int i=0;i<n;i++)
        per[i]=i+1;
        int ans=0,ans2=0;
        int idx=0;
   do
   {
       bool ok=0,ok2=0;
       for(int i=0;i<n;i++)
        if(per[i]!=p[i])
            ok=1;
       if(!ok) ans=idx;
         for(int i=0;i<n;i++)
        if(per[i]!=q[i])
            ok2=1;
       if(!ok2) ans2=idx;
       idx++;

   }while(next_permutation(per,per+n));
   
   cout<<abs(ans-ans2)<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using Pt = pair<int, int>;


void Heuristics_Introduction_B()
{
	int D;
	cin >> D;
	vi c(26);
	for (auto& x : c)
		cin >> x;
	vvi s(D, vi(26));
	for (int i = 0; i < D; ++i)
	{
		for (int j = 0; j < 26; ++j)
			cin >> s[i][j];
	}

	vi t(D);
	for (auto& x : t)
	{
		cin >> x;
		--x;
	}

	int v = 0;
	vi ld(26, -1);
	for (int i = 0; i < D; ++i)
	{
		int x = t[i];
		for (int j = 0; j < 26; ++j)
		{
			if (j == x)
			{
				v += s[i][j];
				ld[j] = i;
			}
			else
				v -= c[j] * (i - ld[j]);
		}
		cout << v << endl;
	}

}

int main()
{
	Heuristics_Introduction_B();
	return 0;
}


Measured memory_bytes: 3648
#include <iostream>
#include <complex>

#include<string>
using namespace std;
int main(void){
    int N , L;
    cin >> N >> L;
    int sum = 0;
    if(L+1 > 0){
        for(int i = 1; i < N;i++){
            sum += L+i;
            // cout <<sum << endl;
        }
    }else{
        if(abs(N)>abs(L)){
            // cout <<"bb" << endl;
            for(int i = 0; i < N;i++){
                 sum += L+i;
            }
        }else{
            // cout <<"aa" << endl;
            for(int i = 0; i < N-1;i++){
                 sum += L+i;
                 
            }
            
            
        }
    }
    cout << sum << endl;
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, k;
  cin >> n >> k;
  
  int ans = 0;
  for(int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x < k - x)
      ans += x * 2;
    else
      ans += (k - x) * 2;
  }
  cout << ans << endl;
}

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

using namespace std;
#define BUF (1000)
#define ll long long 

int n;

int c[BUF];
int s[BUF];
int f[BUF];

int main(void){
	cin >> n;
	for(int i=1;i<n;i++) cin >> c[i] >> s[i] >> f[i];


	int t=0;
	for(int i=1;i<n;i++){
		t=0;
		for(int j=i;j<n;j++){
			//cout << t;
			if(t<=s[j]){ 
				t=s[j];
			}
			else{
				int tmp = t/f[j];
				if(t%f[j]!=0)tmp++;
				t=tmp*f[j];
			}
			t+=c[j];
		}
		cout << t << "\n";
	}
	cout << 0 <<  endl;	
	return 0;
}


Measured memory_bytes: 256
n = int(input())


def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors


r = make_divisors(n)

i = len(r)//2
j = i-1

if len(r) % 2 == 1:
    print(r[i]-1+r[i]-1)
    exit()

print(r[i]-1+r[j]-1)


Measured memory_bytes: 3264
from collections import Counter


def main():
    n = int(input())
    A = [int(e) for e in input().split()]
    q = int(input())
    BC = [[int(e) for e in input().split()] for i in range(q)]

    s = sum(A)
    D = Counter(A)
    for bc in BC:
        b, c = bc
        s -= b * D[b]
        s += c * D[b]
        D[c] += D[b]
        D[b] = 0

        print(s)


if __name__ == '__main__':
    main()


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

int main()
{
    long long a, b, v, w, t;
    cin >> a >> v >> b >> w >> t;
    if (abs(a - b) <= (v - w) * t)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#define rng(x1, y1, x2, y2) (sum[y2][x2] + sum[y1][x1] - sum[y2][x1] - sum[y1][x2])
using namespace std;
int H, W, ra, o, a[40][40], sum[40][40], dp[40][40][40][40];
int solve(int x1, int y1, int x2, int y2) {
	if (dp[y1][x1][y2][x2] != -1) return dp[y1][x1][y2][x2];
	int rng_ = rng(x1, y1, x2, y2);
	int ret = 1048576 + rng_;
	for (int i = x1 + 1; i < x2; i++) {
		int petl = rng(x1, y1, i, y2);
		int petr = rng(i, y1, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, i, y2);
			int resr = solve(i, y1, x2, y2);
			int res = ((resl + resr) >> 20 << 20) + min(resl & 1048575, resr & 1048575);
			ret = max(ret, res);
		}
	}
	for (int i = y1 + 1; i < y2; i++) {
		int petl = rng(x1, y1, x2, i);
		int petr = rng(x1, i, x2, y2);
		if (min(petl, petr) >= o) {
			int resl = solve(x1, y1, x2, i);
			int resr = solve(x1, i, x2, y2);
			int res = ((resl + resr) >> 20 << 20) + min(resl & 1048575, resr & 1048575);
			ret = max(ret, res);
		}
	}
	return dp[y1][x1][y2][x2] = ret;
}
int main() {
	while (scanf("%d%d%d", &H, &W, &ra), H) {
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) scanf("%d", &a[i][j]);
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) sum[i + 1][j + 1] = sum[i + 1][j] + sum[i][j + 1] - sum[i][j] + a[i][j];
		}
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				for (int k = i + 1; k <= H; k++) {
					for (int l = j + 1; l <= W; l++) dp[i][j][k][l] = -1;
				}
			}
		}
		o = sum[H][W] - ra;
		int ret = solve(0, 0, W, H);
		printf("%d %d\n", (ret >> 20), ((ret - o) & 1048575));
	}
}

Measured memory_bytes: 9176
n = int(input())
a = input().split()

def qqq(x):
    if x % 2 == 0 and x % 3 != 0 and x % 5 != 0:
            return 1
    return 0

p = 0

for i in range(n):
    p = p + qqq(int(a[i]))
    
if p == 0:
    print('APPROVED')
    
else:
    print('DENIED')

Measured memory_bytes: 3060
#D

#デバッグ
debug=1
def pront(*n):
    if debug==1:
        print(n)
        
#10**9+7を底とした処理

base=10**9+7

def add(a,b):#a+b
    return (a+b)%base

def sub(a,b):#a-b
    return (a-b)%base

def multi(a,b):#a*b
    return (a*b)%base

def exp(a,b):#a**b
    x=1
    c=a
    d=b
    while d!=0:
        if d%2==1:
            x=multi(x,c)
        c=(c**2)%base
        d=d//2
    return x

def div(a,b):#a/b
    return(multi(a,exp(b,base-2)))

#入力
N,K=map(int,input().split())

A=list(map(int,input().split()))
B=[0 for i in range(len(A))]
#処理
x=[]
y={}
i=0
j=1
while True:
    if B[i]!=0:
        p=B[i]
        break
    else:
        B[i]=j
        x.append(A[i])
    i=A[i]-1
    j+=1

T=len(x)-p+1

if K<=p:
    print(x[K-1])
else:
    print(x[((K-p+1)%T)+p-2])

#print(x,B,K,p,((K-p+1)%T)+p-2)

Measured memory_bytes: 32416
// In the name of god
#include <bits/stdc++.h>
#pragma GCC optimze("02")
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(),x.end()
#define use_file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
using namespace std;
using ll = long long;
const ll N=5e5+5,inf=1e18+18,mod=1e9+7;
ll n,num[N],k,l,r,m[N],po[N];
pair<ll,ll> p[N],p2[N];
set <ll> s;
int main(){
	ios::sync_with_stdio(false) , cin.tie(0) ,  cout.tie(0);
	cin>>n;
	for(int i=0;i<n;i++)cin>>p[i].F>>p[i].S;
	for(int i=0;i<n;i++)p2[i].F=p[i].F;
	for(int i=0;i<n;i++)p2[i].S=p[i].S;
	sort(p,p+n);
	for(int i=0;i<n;i++)po[p[i].S]=i;
	ll y=1,z=0;
	p[n].S=inf;
	for(int i=n;i>0;i--){
		ll x=po[i];
		s.insert(x);
		while(p[z].S>i && z<n)z++;
		if(i==n){
			l=x;
			r=x;
			num[0]++;
			continue;
		}
		else{
			if(r>x){
				m[p[x].F]=m[p[r].F];
				num[m[p[x].F]]++;
			}
			else if(l==0 && r==y-1){
				k++;
				m[p[x].F]=k;
				num[k]++;
			}
			else{
				ll x2=(*s.lower_bound(z));
				m[p[x].F]=m[p[x2].F];
				num[m[p[x].F]]++;
			}
			l=min(l,x);
			r=max(r,x);
		}
		y++;
	}
	for(int i=0;i<n;i++)cout<<num[m[p2[i].F]]<<endl;
}


Measured memory_bytes: 22448