akhauriyash/Code-Regression huggingface dataset:
N, M = map(int, input().split())
WAC = [0 for i in range(N)]
TF = [0 for i in range(N)]
for i in range(M):
    p, S = input().split()
    p = int(p)-1
    if S == 'AC':
        TF[p] = 1
    if TF[p] == 0 and S == 'WA':
        WAC[p] += 1
count = 0
for i in range(N):
    count += TF[i] * WAC[i]
print(sum(TF), count)



Measured memory_bytes: 4696
N, M = map(int, input().split())
A = set([int(input()) for i in range(M)])
mod = 10 ** 9 + 7
dp = [0] * (N + 1)
dp[0] = 1
for i in range(1, N + 1):
    if not i in A:
         dp[i] = (dp[i - 1] + dp[i - 2]) % mod
print(dp[-1] % mod)

Measured memory_bytes: 56664
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>

using namespace std;
#define int long long int

void solve() {
    int P, Q, R;
    cin >> P >> Q >> R;

    cout << min({P + Q, Q + R, P + R}) << endl;
}

signed main() {
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> v;

int main(){
    v.resize(3);
    for(int i=0;i<3;i++) cin >> v[i];
    sort(v.begin(),v.end());
    int sum = 0;
    sum += v[2]-v[1];
    v[0] += (v[2]-v[1]);
    if((v[2]-v[0])%2 == 1){
        v[2]++;
        sum++;
    }
    sum += (v[2]-v[0]) / 2;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect
N = int(input())
S = [int(item) for item in input().split()]
q = int(input())
T = [int(item) for item in input().split()]

cnt = 0


for i in range(q):
    temp_index = bisect.bisect_left(S, T[i])
    if len(S) != temp_index:
        if T[i] == S[temp_index]:
            cnt += 1
print(cnt)


Measured memory_bytes: 16928
import bisect

n = int(input())
l = list(map(int, input().split()))
l = sorted(l)

cnt = 0
for i in range(n-1):
    for j in range(i+1,n):
        up = l[j] + l[i]
        #l[k] = up となるようなkのうち最小のものを見つけろ
        k = bisect.bisect_left(l, up)
        cnt += k - j - 1
print(cnt)




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

def solve():
    N = int(input())
    A = list(map(int, input().split()))

    ans = float("inf")
    for i in range(N):
        ans1 = 0
        while True:
            if A[i]%2 == 0:
                A[i] /= 2
                ans1 += 1
            else:
                break
        ans = min(ans, ans1)
    
    print(ans)

if __name__ == "__main__":
    solve()


Measured memory_bytes: 3060
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <regex> //正規表現
#include <map>
#include <set>
#include <cassert> //assart
#include <numeric>
#include <iterator>
#include <list>

using namespace std;
#define ll long long int
#define FOR(i,min,max) for(int i=(min);i<(max);i++)
#define FOReq(i,min,max) for(int i=(min);i<=(max);i++)
#define FORREV(i,max,min) for(int i=(max)-1;i>=(min);i--)
#define FORREVeq(i,max,min) for(int i=(max);i>=(min);i--)
const int  MOD=1e9+7;
const int  INF=2000000000;
const int INF2=  10000000;
const double  Micro=1e-5;

int UnUsedVariable(){
    if(INF || Micro || MOD || INF2){;}
    return 0;
}

#define pf printf
#define sf scanf
#define inarray(array,min,max) FOR(i,min,max){cin>>array[i];}
#define inarrayW(arrayA,arrayB,min,max) FOR(i,min,max){cin>>arrayA[i]>>arrayB[i];}
inline int isEven(int x){return x%2==0;}
inline int isOdd (int x){return x%2==1;}
#define br printf("\n");
#define OutputAndReturn0(x) {cout<<(x)<<endl;return 0;}

int EintN(int array[],const int num){
    for(int i=0;i<num;i++){printf("%d ",array[i]);}
    br;
    return 0;
}
int EintNN(const int heighth,const int width,int array[heighth][width]){
    FOR(i, 0, heighth){
        FOR(k, 0, width){
            {printf("%d ",array[i][k]);}
        }
        br;
    }
    br;
    return 0;
}
int Eint(string str,const int num){
    cerr<<str<<" is "<<num<<" now."<<endl;
    return 0;
}


int test(){
    return 0;
}

int Ap(){
    int ans;ans=0;
    
    return 0;
}

int Bp(){
    int ans;ans=0;
    
    return 0;
}

ll gcd(ll a,ll b){//最大公約数 なお一方が0なら答えは他方になるので番兵は０で良い また、負の数もOK -4%3=-1となるため
    if(b==0){
        return a;
    }else{
        return gcd(b,a%b);
    }
}

int Cp(){
    ll ans;ans=0;
    ll N,A,B,C,D,E;
    cin>>N>>A>>B>>C>>D>>E;
    ll minimal=min({A,B,C,D,E});
    OutputAndReturn0((N+minimal-1)/minimal +4);
    return 0;
}

int Dp(){
    int ans;ans=0;
    
    return 0;
}

signed main(){
    //test();
    //Ap();
    //Bp();
    Cp();
    //Dp();
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

#define HEIGHT 12
#define WIDTH 12

enum { YET, ALREADY };

int calcIsland( void );
void findIsland( int, int );
void findIsland_body( int, int, int );

typedef struct {
	char type;
	int state;
} FIELD;

FIELD field[ HEIGHT ][ WIDTH ];
const int dx[ 4 ] = { -1, 0, 1, 0 };
const int dy[ 4 ] = { 0, -1, 0, 1 };

int main( void ) {
	int i, j;

	do {
		for ( i = 0; i < HEIGHT; i++ ) {
			for ( j = 0; j < WIDTH; j++ ) {
				scanf( "%c", &field[ i ][ j ].type );
				field[ i ][ j ].state = YET;
			}

			scanf( "%*c" );
		}

		printf( "%d\n", calcIsland() );
	} while ( scanf( "%*c" ) != EOF );

	return 0;
}

int calcIsland( void ) {
	int i, j, tmp;

	tmp = 0;
	for ( i = 0; i < HEIGHT; i++ )
		for ( j = 0; j < WIDTH; j++ )
			if ( field[ i ][ j ].type == '1' && field[ i ][ j ].state == YET ) {
				findIsland( i, j );
				tmp++;
			}

	return tmp;
}

void findIsland( int i, int j ) {
	field[ i ][ j ].state = ALREADY;

	findIsland_body( i, j + 1, 0 );
	findIsland_body( i + 1, j, 1 );
}

void findIsland_body( int i, int j, int comeDir ) {
	int d;

	if ( i < 0 || i >= HEIGHT || j < 0 || j >= WIDTH || field[ i ][ j ].state == ALREADY || field[ i ][ j ].type == '0' )
		return;

	field[ i ][ j ].state = ALREADY;

	for ( d = 0; d < 4; d++ )
		if ( d != comeDir )
			findIsland_body( i + dy[ d ], j + dx[ d ], d + 2 & 3 );
}

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

using namespace std;
using ll = long long;
using v1 = vector<int>;
using v2 = vector<vector<int>>;
using v3 = vector<vector<char>>;

int main(){
	int N;
	cin >> N;
	v1 a(N);
	rep(i, N){
		cin >> a.at(i);
	}
	int c = 0;
	rep(i, N-1){
		int minj = i;
		for(int j= i+1; j < N; j++){
			if(a.at(j)< a.at(minj)) minj = j;
		}
		if(i != minj){
			int b = a.at(minj);
			a.at(minj) = a.at(i);
			a.at(i) = b;
			c++;
		}
	}
	rep(i,N){
		if(i != N-1){
			cout << a.at(i) << " ";
		}else{
			cout << a.at(i) << endl;
		}
	}
	cout << c << endl;
}



Measured memory_bytes: 3096
# https://atcoder.jp/contests/abc058/tasks/arc071_a

n=int(input())
s=[sorted(input()) for _ in range(n)]
alfa=[float('inf')]*26

for e in s:
    for i in range(26):
        cnt=e.count(chr(97+i))
        alfa[i]=min(alfa[i],cnt)
ans=[]
for i in range(26):
    ans.append(chr(97+i)*alfa[i])
print(*ans,sep='')

Measured memory_bytes: 3064
#include <iostream>
#include <cmath>

using namespace std;

long long gcd(long long a, long long b) {
    if (a == 0) {
        return b;
    } else if (b == 0) {
        return a;
    }
    
    long long r = a % b;
    if (r != 0) {
        return gcd(b, r);
    } else {
        return b;
    }
}


int main()
{
    cin.tie(0);
   	ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    long long a[n], l[n + 1], r[n + 1];
    
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    l[0] = 0;
    r[n] = 0;
    
    for (int i = 1; i <= n; i++) {
        l[i] = gcd(l[i - 1], a[i - 1]);
    }
    for (int i = n - 1; i > 0; i--) {
        r[i] = gcd(r[i + 1], a[i]);
    }
    
    long long maxg = 0;
    for (int i = 0; i < n; i++) {
        long long g = gcd(l[i], r[i + 1]);
        maxg = max(maxg, g);
    }
    cout << maxg << endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const ll N = 1e6 + 5, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0);
    ll n, s = 0, ss = 0, d;
    cin >> n;
    for (ll i = 0; i < n; i++)
        cin >> d, s += d, ss += d * d;
    cout << (s * s - ss) / 2;
}

Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <complex>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include  <unordered_set>
#include <unordered_map>
#define ll long long int
#define INF (ll)1e9
#define INFL (ll)1e15
#define MAXN (int)1e6
#define err 1e-15
#define sz size
int getInt(char ch) {
    return (int)(ch - '0');
}
using namespace std;

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

    int N;
    cin >> N;

    vector<int> A(N);

    vector<pair<int, pair<int, int> > > B(N);

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

    B[0] = make_pair(abs(A[0]), make_pair(abs(A[1] - A[0]), abs(A[1])));

    for(int i = 1; i < N-1; i++) {
        B[i] = make_pair(abs(A[i-1] - A[i]), make_pair(abs(A[i+1] - A[i]), abs(A[i+1] - A[i-1])));
    }

    B[N-1] = make_pair(abs(A[N-2] - A[N-1]), make_pair(abs(A[N-1]), abs(A[N-2])));

    int cost = 0;

    int prev = 0;

    for(int i = 0; i < N; i++) {
        cost += abs(prev - A[i]);
        prev = A[i];
    }

    cost += abs(A[N-1]);

    for(int i = 0; i < N; i++) {
        int t = cost - B[i].first - B[i].second.first + B[i].second.second;
        cout << t << endl;
    }

}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007 

ll a[100010];
bool b[100010];
int main() {
	ll n,k;
	cin>>n>>k;
	for(int i=0;i<k;i++){
		ll z;
		cin>>z;z--;
		b[z]=1;
	}
	if(b[0]!=1){
		a[0]=1;
	}
	if(b[1]!=1){
		a[1]=1+a[0];
	}
	for(int i=2;i<=n;i++){
		a[i]=a[i-1]+a[i-2];
		a[i]%=inf;
		if(b[i]==1){
			a[i]=0;
		}
	}
	n--;
	cout << a[n];
}

Measured memory_bytes: 1152
#include<bits/stdc++.h>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ll long long int
#define ALL(x) x.begin(),x.end()
using namespace std;
ll ans = 0, sum = 0, n, k, counter = 0, w, h;
string s;
vector<ll> v;
vector < pair<ll, ll > > vp;
vector<vector<ll> > vv(50, vector<ll>(50, INF));
vector<string> vs;
vector<char> vc;
vector<ll> vi;
/*--------------------template--------------------*/

int main() {
	ll a, b, c, d, e, f;
	cin >> a >> b >> c >> d;
	e = a*b;
	f = c*d;
	cout << max(e, f) << endl;
}

Measured memory_bytes: 256
import math

N = int(input())

# a,b=map(int,input().split())
sum = 100
i = 0

# while	sum < N:
# 	sum += count
# 	i += 1

while sum < N:
	sum += sum * 0.01
	i += 1
	sum = int(sum)

print(i)


Measured memory_bytes: 9164
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int a = sc.nextInt();
          int b = sc.nextInt();
          int ga = 0;
          int gb = 0;
          if(a == 2){
            ga = 3;
          } else if(a == 4 || a == 6 || a == 9|| a == 11){
            ga = 2;
          } else {
            ga =1;
          }
          if(b == 2){
            gb = 3;
          } else if(b == 4 || b == 6 || b == 9|| b == 11){
            gb = 2;
          } else {
            gb =1;
          }
          if(ga == gb){
            System.out.println("Yes");
          } else {
            System.out.println("No");
          }
        }
      }

Measured memory_bytes: 21460
n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
sum = a.inject(:+)

bc = []
m.times {bc << gets.split.map(&:to_i)}
bc.sort_by!{|b, c| -c}

i = 0
j = 0
k = 1
while a[i] < bc[j][1]
    sum += bc[j][1] - a[i]
    break if (i += 1) >= n

    if k == bc[j][0]
        k = 1
        break if (j += 1) >= m
    else
        k += 1
    end
end

puts sum

Measured memory_bytes: 21032
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
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() {
    ll n, a, b;
    cin >> n >> a >> b;

    ll ans;
    if (a > b) ans = 0;
    else if (n == 1 && a != b) ans = 0;
    else ans = (n - 2) * (b - a) + 1;
    cout << ans << endl;
}


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

int i,j,k;
int n,a[5],x,ans;
char d[10];
int comp(const void *p,const void *q){
	return *(int *)p-*(int *)q;
}

int main(){
	scanf("%d",&n);
	while(n!=0){
		a[0]=1;a[1]=2;a[2]=3;ans=a[0];
		for(i=0;i<n;i++){
			scanf("%s",d);
			if(strcmp(d,"North")==0)x=a[0],a[0]=a[1],a[1]=7-x;
			if(strcmp(d,"South")==0)x=a[1],a[1]=a[0],a[0]=7-x;
			if(strcmp(d,"West")==0) x=a[0],a[0]=a[2],a[2]=7-x;
			if(strcmp(d,"East")==0) x=a[2],a[2]=a[0],a[0]=7-x;
			if(strcmp(d,"Right")==0)x=a[1],a[1]=a[2],a[2]=7-x;
			if(strcmp(d,"Left")==0) x=a[2],a[2]=a[1],a[1]=7-x;
			ans+=a[0];
		}
		printf("%d\n",ans);
		scanf("%d",&n);
	}
	
	return 0;
}

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

using namespace std;

int main() {
    int n;
    cin >> n;
    bool prev = false;
    int cnt=0;
    for (int i=1; i<=n; i++) {
        int p;
        cin >> p;
        if (p == i) {
            if (!prev) cnt++;
            prev = !prev;
        } else
            prev = false;
    }
    cout << cnt << '\n';
    return 0;
}

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


int main()
{
   ll n,rem;
   cin>>n;
   string s;

   while(n)
   {
       n--;
    rem=n%26;
    s+=(char)('a'+rem);

    n/=26;
   }
    reverse(s.begin(),s.end());
    cout<<s<<endl;

}



Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  if(n%2==0 || n%5==0)
    cout<<-1;
  else 
  {
  	long long count =1;
    long long a = 7;
  	while(1)
    {
      if(a%n==0)
      {
        cout<<count;
        break;
      }
      count++;
      a = (a*10+7) % n;
    }
  }
  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LLI long long int
#define LI long int 
const LI MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.
long long int binarySearch(LLI arr[],long long int end, long long int target)  
{  
    long long int start = 0;  
    end--;
    long long int ans = -1;  
    while (start <= end)  
    {  
        long long int mid = (start + end) / 2;  
        if (arr[mid] > target) 
        {  
            end = mid - 1;  
        } 
        else 
        {  
            ans = mid;  
            start = mid + 1;  
        }  
    }  
    return ans;  
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LLI n,m,k,i;cin>>n>>m>>k;
      LLI a[n],b[m],ans=0;
      fo(i,0,n) cin>>a[i];
      fo(i,0,m) cin>>b[i];
      fo(i,1,m) b[i]+=b[i-1];
      LLI sum=0;
      fo(i,0,n+1){
        if(i==0){
          LLI in1=binarySearch(b,m,k);
          if(in1==-1) in1=0;
          else in1++;
          ans=max(ans,i+in1);
        }
        else{
          sum+=a[i-1];
          LLI in1=binarySearch(b,m,k-sum);
          if(in1==-1) in1=0;
          else in1++;
          if(sum>k) break;
          ans=max(ans,i+in1);
        }
      }
      cout<<ans;
    }
    return 0;
}

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int n,w;
    cin>>n>>w;
    vector<int> dp(w+1,0ll);
    int i;
    f1(i,0,n)
    {
    	int weight,value;
    	cin>>weight>>value;
    	int j;
    	for(int j=w-weight; j>=0; j--)
    	{
    		dp[j+weight]=max(dp[j+weight],dp[j]+value);
    	}
    	// f1(j,0,w+1)
    	// cout<<dp[j]<<gp;
    	// cout<<endl;
    }
    int ans=0ll;
    f1(i,0,w+1)
    {
    	ans=max(ans,dp[i]);
    }
    
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
#define MAXC 100000
int n;
double f[305][305][305], ev[305][305][305];
inline long double dp(int a, int b, int c){
	if(a==0&&b==0&&c==0) return (long double)0.0;
	if(f[a][b][c]>(long double)0.0) return f[a][b][c];
	
	if(a>0)f[a][b][c] += (long double)a/(long double)(a+b+c)*dp(a-1,b,c);
	if(b>0)f[a][b][c] += (long double)b/(long double)(a+b+c)*dp(a+1,b-1,c);
	if(c>0)f[a][b][c] += (long double)c/(long double)(a+b+c)*dp(a,b+1,c-1);
	f[a][b][c] += (long double)n/(long double)(a+b+c);
	return f[a][b][c];
}
int main()
{
// 	int n;
	cin>>n;
	vector<int> cnt(4);
	for(int i=1;i<=n;i++){
		int x;cin>>x;
		cnt[x]++;
	}
	int a = cnt[1];
	int b = cnt[2];
	int c = cnt[3];
	cout<<setprecision(15)<<double(dp(a,b,c));
}

Measured memory_bytes: 219520
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
using pair = Pair<long, long>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    readonly Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int N = cin.nextint;
        var A = new long[N];
        var B = new long[N];
        var P = new pair[N];
        for (int i = 0; i < N; i++)
        {
            A[i] = cin.nextlong;
            B[i] = cin.nextlong;
            P[i] = new pair(A[i], B[i]);
        }

        P = P.OrderByDescending(i => i.f + i.s).ToArray();

        long sum = 0;
        for (int i = 0; i < N; i++)
        {
            if (i % 2 == 0)
            {
                sum += P[i].f;
            }
            else
            {
                sum -= P[i].s;
            }
        }

        WriteLine(sum);
    }

}


class Pair<T, U> : IComparable<Pair<T, U>> where T : IComparable<T> where U : IComparable<U>
{
    public T f;
    public U s;
    public Pair(T f, U s)
    {
        this.f = f;
        this.s = s;
    }
    public int CompareTo(Pair<T, U> a)
    {
        return f.CompareTo(a.f) != 0 ? f.CompareTo(a.f) : s.CompareTo(a.s);
    }
    public override string ToString()
    {
        return f + " " + s;
    }
}
class Scanner
{
    string[] s; int i;
    readonly char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
    public void join<T>(IEnumerable<T> values) { WriteLine(string.Join(" ", values)); }
}

Measured memory_bytes: 27456
#include <bits/stdc++.h>
#define ll long long int 
#define endl '\n'
#define INF 1000000000
#define MOD 1000000007
#define MAX 200001 
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,x,t,ans;
    cin>>n>>x>>t;
    if(n%x==0)
    {
    	n=n/x;
    	ans=n*t;
    }
    else
    {
    	n=n/x;
    	n++;
    	ans=n*t;
    }
    cout<<ans<<endl;
}

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

int main(){
  int n; cin>> n;
  int ans=0;
  vector<int> vec;
  for(int i=0;i<n;i++){
    int tmp;cin >> tmp;
    vec.push_back(tmp);
  }
  for(int i=0;i<n;i++){
    int tmp;cin >> tmp;
    ans += max(0,vec.at(i)-tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printa2(x,m,n) for(int i = 0; i < m; i++){ for(int j = 0; j < n; j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

typedef struct{
    int to;
    int cost;
} edge;

using namespace std;
int N;
ll a[100010], b[100010], c[100010];
ll Q,K;
ll x[100010], y[100010];
ll dist[100010];
vector<edge> tree[100010];

void dfs(ll v, ll p, ll d){
    // v: 現在位置 p: 親ノード d: 基準点からの距離
    dist[v] = d;
    for(auto &e : tree[v]){
        if(e.to == p){
            continue;
        }
        dfs(e.to, v, d + e.cost);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    rep(i,0,N-1){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--; b[i]--;
    }
    cin >> Q >> K;
    K--;
    rep(i,0,Q){
        cin >> x[i] >> y[i];
        x[i]--; y[i]--;
    }
    rep(i,0,N-1){
        edge ed = {b[i], c[i]};
        tree[a[i]].push_back(ed);
        ed.to = a[i];
        tree[b[i]].push_back(ed);
    }
    dfs(K, -1, 0);
    rep(i,0,Q){
        print(dist[x[i]] + dist[y[i]]);
    }


}


Measured memory_bytes: 16640
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>
#include<list>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

ll mypow(ll x,ll n,ll mod = MOD){
    ll ret = 1;
    while(n > 0){
        if(n&1){
            ret = (ret*x)%mod;
        }
        x = (x*x)%mod;
        n >>= 1;
    }
    return ret;
}

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

ll twoPow(ll shiftNum){
    return (1LL << (shiftNum - 1));
}

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

    ll k;
    cin >> k;

    vector<bool> used(26,false);

    for(int i = 0; i < str.size(); i++){
        used[str[i] - 'a'] = true;
    }

    ll num = 0;
    for(int i = 0; i < 26; i++){
        if(used[i])num++;
    }

    if(num == 1){
        cout << (k*str.size())/2 << endl;
    }else{
        auto tmp1 = str + str;
        auto tmp2 = tmp1 + str;

        ll tmp1ans = 0;
        ll tmp2ans = 0;

        for(int i = 1; i < tmp1.size(); i++){
            if(tmp1[i] == tmp1[i-1]){
                tmp1[i] = '?';
                tmp1ans++;
            }
        }

        for(int i = 1; i < tmp2.size(); i++){
            if(tmp2[i] == tmp2[i-1]){
                tmp2[i] = '?';
                tmp2ans++;
            }
        }

        auto dist = tmp2ans - tmp1ans;

        ll ans = dist * (k - 1);
        for(int i = 1; i < str.size(); i++){
            if(str[i] == str[i-1]){
                str[i] = '?';
                ans++;
            }
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 2000005
using namespace std;
char str1[maxn],str2[maxn];
int Next[maxn],vis[maxn],kmpcount;
struct Node{
    int to,next;
}q[maxn<<1];
int head[maxn],cnt=0,inde[maxn];
void add_edge(int from,int to){
    q[cnt].to=to;
    q[cnt].next=head[from];
    head[from]=cnt++;
}
void init(){
    memset(head,-1,sizeof(head));
    cnt=0;
}
void kmp_pre(char x[],int m,int next[]){
    int i,j;
    j=next[0]=-1;
    i=0;
    while(i<m){
        while(j!=-1&&x[i]!=x[j]) j=next[j];
        next[++i]=++j;
    }
}
int kmp(char x[],int m,char y[],int n){
    int i,j;
    int ans=0;
    kmp_pre(x,m,Next);
    i=j=0;
    while(i<n){
        while(j!=-1&&y[i]!=x[j]) j=Next[j];
        i++,j++;
        if(j>=m){
            ans++;
            j=Next[j];
            vis[i-m]=1;
        }
    }
    return ans;
}
vector<int>vec;
int dp[maxn];
bool topsort(int n){
    int cnt=0;
    queue<int>que;
    for(int i=0;i<n;i++) if(!inde[i]&&vis[i])que.push(i);
    while(!que.empty()){
        int x=que.front();
        vec.push_back(x);
        cnt++;
        que.pop();
        for(int i=head[x];i!=-1;i=q[i].next){
            int to=q[i].to;
            inde[to]--;
            if(inde[to]==0) que.push(to);
        }
    }
    return kmpcount==cnt;
}
int main()
{
    scanf("%s%s",str1,str2);
    int len1=strlen(str1),len2=strlen(str2);
    int Len1=len1,Len2=len2;
    while(Len2>0){
        for(int i=0;i<Len1;i++){
            str1[len1++]=str1[i];
        }
        Len2-=Len1;
    }
    str1[len1]='\0';
    kmpcount=kmp(str2,len2,str1,len1);
    init();
    for(int i=0;i<len1;i++){
        int k=(i+len2)%Len1;
        if(vis[k]&&vis[i]) inde[k]++,add_edge(i,k);
    }
    if(!topsort(len1)) puts("-1");
    else{
        for(int i=0;i<vec.size();i++){
            int x=vec[i];
            if(dp[x]==0) dp[x]=1;
            for(int i=head[x];i!=-1;i=q[i].next){
                int to=q[i].to;
                dp[to]=max(dp[to],dp[x]+1);
            }
        }
        int res=0;
        for(int i=0;i<vec.size();i++){
            res=max(res,dp[vec[i]]);
        }
        printf("%d\n",res);
    }
    return 0;
}


Measured memory_bytes: 45292
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1);
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 n; cin >> n;

    map<ll, ll> m;
    ll sum = 0;
    rep(i, n) {
        ll a; cin >> a;
        sum += a;
        m[a]++;
    }

    int q; cin >> q;
    rep(i, q) {
        ll b, c; cin >> b >> c;
        if (m[b] == 0) {
            cout << sum << endl;
        } else {
            sum -= b * m[b];
            sum += c * m[b];
            cout << sum << endl;
            m[c] += m[b];
            m[b] = 0;
        }
    }
}


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

typedef long long ll;

void solve()
{
    string str;
    cin >> str;
    int n = str.length();
    int digitSum = 0;
    for (int i = 0; i < n; i++)
        digitSum += (str[i] - '0');

    // Check if sum of digits is divisible by 9.
    if (digitSum % 9 == 0)
    {
        cout << "Yes" << endl;
    }
    else
        cout << "No" << endl;
}

int main()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; i++)
    {
        // cout << "Case #" << i << ": ";
        solve();
    }
}

Measured memory_bytes: 3664
#include <iostream>
#include <numeric>
#include <cmath>
#include <limits>
#include <stdio.h>
#include <iomanip>
#include <cstdlib>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;
using ll = long long;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
ll Max(ll(a), ll(b), ll(c)) {
	return max(max(a, b), c);
}
ll Min(ll(a), ll(b), ll(c)) {
	return min(min(a, b), c);
}

vector<ll> fact, factinv, inv;
ll mod = 998244353;
void prenCkModp(ll n) {
	fact.resize(n + 5);
	factinv.resize(n + 5);
	inv.resize(n + 5);
	fact.at(0) = fact.at(1) = 1;
	factinv.at(0) = factinv.at(1) = 1;
	inv.at(1) = 1;
	for (ll i = 2; i < n + 5; i++) {
		fact.at(i) = (fact.at(i - 1) * i) % mod;
		inv.at(i) = mod - (inv.at(mod % i) * (mod / i)) % mod;
		factinv.at(i) = (factinv.at(i - 1) * inv.at(i)) % mod;
	}

}
ll nCk(ll n, ll k) {
	return (fact.at(n) * ((factinv.at(k) * factinv.at(n - k)) % mod)) % mod;
}
int modPow(long long a, long long n, long long p) {
	if (n == 0) return 1; // 0乗にも対応する場合
	if (n == 1) return a % p;
	if (n % 2 == 1) return (a * modPow(a, n - 1, p)) % p;
	long long t = modPow(a, n / 2, p);
	return (t * t) % p;
}

int main() {
	ll X, N;
	cin >> X >> N;
	vector<ll> P(102);
	rep(i, 102) {
		P.at(i) = 0;
	}
	rep(i, N) {
		ll A;
		cin >>A;
		P.at(A)++;
		
	}
	ll an = 99999;
	for (ll i = 0; i <= 101; i++) {
		if (P.at(i) == 0) {
			if (abs(an - X) > abs(i - X)) {
				an = i;
			}
		}
	}
	

	cout << an << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
signed main() {
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    if (s[k - 1] == 'A') {
        s[k - 1] = 'a';
    } else if (s[k - 1] == 'B') {
        s[k - 1] = 'b';
    } else if (s[k - 1] == 'C') {
        s[k - 1] = 'c';
    }
    cout << s << endl;
    r0
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

n, k = [int(x) for x in input().split()]

n_k = n // k
n_mod_k = n % k

def mod_k(x):
    res = n_k
    if x != 0 and x <= n_mod_k:
        res += 1
    elif x == 0 and n_mod_k == k:
        res += 1
    return res

ans = 0

for i in range(k):
    a_mod = i
    b_mod = -i % k
    c_mod = -i % k
    if (b_mod +c_mod) % k == 0:
        ans += mod_k(a_mod) * mod_k(b_mod) * mod_k(c_mod)

print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

const int N=1e6+5;

ll mod=1e9+7,n,m,ans=1,f[N],inv[N],d[N];

ll p(ll a,ll b)
{
	ll r=1;
	while(b)
	{
		if(b%2)r=(r*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return r;
}

ll ncr(ll n,ll r)
{
	if(r>n||r<0)return 0;
	ll ans=(f[n]*inv[r])%mod;
	return (ans*inv[n-r])%mod;
}

int main()
{ios_base::sync_with_stdio(false);
cin.tie(0);
f[0]=1;
rep(i,1,N-1)f[i]=(f[i-1]*i)%mod;
inv[N-1]=p(f[N-1],mod-2);
ren(i,N-2,0)inv[i]=(inv[i+1]*(i+1))%mod;
d[0]=1;
d[1]=0;
rep(i,2,N-1)d[i]=((d[i-1]+d[i-2])*1ll*(i-1))%mod;
cin>>n>>m;
for(ll i=0;i<n;i++)
{
	ans=(ans*(m-i))%mod;
}
ll ans2=0;

for(ll i=0;i<=n;i++)
{
	ll kk=(f[m-i]*inv[m-n])%mod;
	kk=(kk*ncr(n,i))%mod;
	if(i%2)ans2=(ans2-kk)%mod;
	else ans2=(ans2+kk)%mod;
}

ans2=(ans2+mod)%mod;
ans=(ans*ans2)%mod;
ol(ans);
return 0;
}



Measured memory_bytes: 27044
function Main(input) {

	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split("\n");
    
    let s = input[0];
    if (s[s.length-1] == "s") s += "es";
    else s += "s";
    
    console.log(s);
    
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29552
#include<iostream>
using namespace std;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a!=b&&b==c)cout<<a<<"\n";
    else if(a!=b&&b!=c)cout<<b<<"\n";
    else if(a==b&&b!=c)cout<<c<<"\n";

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define int long long
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define inf 1000000000000000007
#define f first
#define s second
#define mini(c,a,b) *min_element(c+a,c+b)
#define maxi(c,a,b) *max_element(c+a,c+b)
//printf("%.12Lf\n",c);
int keta(int x){
	rep(0,i,30){
		if(x<10){
			return i+1;
		}
		x=x/10;
	}
}
int gcd(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return bb;
		}	
		bb=bb%aa;
		if(bb==0){
			return aa;
		}
	}
}	
int lcm(int x,int y){
	int aa=x,bb=y;
	rep(0,i,1000){
		aa=aa%bb;
		if(aa==0){
			return x/bb*y;
		}	
		bb=bb%aa;
		if(bb==0){
			return x/aa*y;
		}
	}
}
bool p(int x){
	if(x==1)return false;
	rep(2,i,sqrt(x)+1){
		if(x%i==0&&x!=i){
			return false;
		}
	}	
	return true;
}
int max(int a,int b){
	if(a>=b)return a;
	else return b;
}
int min(int a,int b){
	if(a>=b)return b;
	else return a;
}	
int n2[41];		
int nis[41]; 
int nia[41];
int mody[41];
int nn;
int com(int n,int y){
	int ni=1;
	for(int i=0;i<41;i++){
		n2[i]=ni;
		ni*=2;
	}
	int bunsi=1,bunbo=1;
	rep(0,i,y)bunsi=(bunsi*(n-i))%mod;
	rep(0,i,y)bunbo=(bunbo*(i+1))%mod;
	mody[0]=bunbo;
	rep(1,i,41){
		bunbo=(bunbo*bunbo)%mod;
		mody[i]=bunbo;
	}
	rep(0,i,41)nis[i]=0;
	nn=mod-2;
	for(int i=40;i>=0;i-=1){
		if(nn>n2[i]){
			nis[i]++;
			nn-=n2[i];
		}
	}
	nis[0]++;
	rep(0,i,41){
		if(nis[i]==1){
			bunsi=(bunsi*mody[i])%mod;
		}
	}
	return bunsi;
}
int yakuwa(int n){
	int sum=0;
	rep(1,i,sqrt(n+1)){
		if(n%i==0)sum+=i+n/i;
		if(i*i==n)sum-=i;
	}
	return sum;
}	
bool hei(int n){
	rep(0,i,100){
		if(i*i==n){
			return true;
		}
	}
	return false;
}
int pow(int b,int a){	
	int aa=1;
	rep(0,i,a)aa*=b;	
	return aa;
}		
int ma[1026][10];
int k[10];
int s[10][10];
int pp[10];
signed main(){
	ic(n) ic(m)
	rep(0,i,m){
		cin>>k[i];
		rep(0,j,k[i]){
			cin>>s[i][j];
		}
	}
	rep(0,i,m)cin>>pp[i];	
	for(int bit=0;bit<(1<<n);bit++)rep(0,i,n)if(bit&(1<<i))ma[bit][i]=1;
	int sum=0;
	rep(0,i,pow(2,n)){
		int aa=0;	
		rep(0,j,m){
			int ans=0;
			rep(0,l,k[j])if(ma[i][s[j][l]-1]==1)ans++;
			if(ans%2==pp[j])aa++;
		}
		if(aa==m)sum++;
	}			
	c(sum)		
}	

Measured memory_bytes: 384
import java.util.Scanner;

public class Main{
	public static void main(String[] args)
	{
		Scanner sc =new Scanner(System.in);
		int x=sc.nextInt();
		int a=sc.nextInt();
		int b=sc.nextInt();
		
		if(Math.abs(x-a)<Math.abs(x-b)) System.out.println("A");
		else System.out.println("B");
	}
} 

Measured memory_bytes: 23892
#include <iostream>
#include <iomanip>
#include <cassert>

#include <algorithm>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < n; ++i)
#define rep(i, n) rep_init(i, 0, n)
#define rep_reverse(i, init, n) for(int i = (init); i > n; --i)

void Main()
{
	string s;
	cin >> s;

	int start, end;
	rep(i, s.size())
	{
		if (s[i] == 'A')
		{
			start = i;
			break;
		}
	}
	
	rep_reverse(i, s.size()-1, -1)
	{
		if (s[i] == 'Z')
		{
			end = i;
			break;
		}
	}

	cout << end - start + 1 << endl;
}

int main()
{
	std::cin.tie(nullptr);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);

	Main();
	return 0;
}

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

int main(){
    int A, B;
    cin >> A >> B;
    int charge;
    if(A >= 13){
        charge = B;
    }else if(A >= 6){
        charge = B / 2;
    }else{
        charge = 0;
    }
    cout << charge;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> w(n);
  rep(i,n) cin >> w[i];
  // sort(w.begin(), w.end());
  int r = 0;
  rep(i,n) r+=w[i];
  int l = 0;
  int sa = (int)1e10;
  rep(i,n){
    if(abs(r-l) < sa)
      sa = abs(r-l);
    r-=w[i];
    l+=w[i];
  }
  cout << sa << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    int h, w;
    cin >> h >> w;
    vector<vector<char>> s(h+2, vector<char>(w+2));
    vector<vector<char>> ans(h, vector<char>(w));
    for(int i = 0; i < w +2; i++) {
        s[0][i] = 'a';
        s[h+1][i] = 'a';
    }
    for(int i = 1; i <=h; i++) {
        s[i][0] = 'a';
        string str;
        cin >> str;
        for(int j = 1; j <=w; j++) s[i][j] = str[j-1];
        rep(k, w) ans[i-1][k] = str[k];
        s[i][w+1] = 'a';
    }
    for(int i = 1; i <= h; i++) {
        for(int j = 1; j <= w; j++) {
            if(s[i][j] == '.') {
                int count = 0;
                for(int k = -1; k < 2; k++){
                    for(int l = -1; l < 2; l++) {
                        if(s[i + k][j + l] == '#') {
                            count ++;
                        }
                    }
                }  
            ans[i-1][j-1] = (char)(count + '0');
            }
        }
    }
    for(int i = 0; i < h; i++) {
        for(int j = 0; j < w; j++) {
            if( j == w-1 ) {
                cout << ans[i][j] << endl;
                break;
            }
            cout << ans[i][j];
           
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int a, b, c;
    cin>>a>>b>>c;
    int ans=0;
    for(int i=b; i>0; i-=a){
        if(i<a) break;
        ans++;
    }
    if(ans>c){
        cout<<c<<endl;
    }else{
        cout<<ans<<endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#define LEN 100001

int main(void){
  int N;
  scanf("%d",&N);
  int A[LEN]={0},a;
  long long int S=0;
  int i,j;
  for(i=0;i<N;i++){
    scanf("%d",&a);
    A[a]++;
    S+=a;
  }

  int Q;
  scanf("%d",&Q);

  int b,c;
  for(i=0;i<Q;i++){
    scanf("%d%d",&b,&c);
    S+=(c-b)*A[b];
    A[c]+=A[b];
    A[b]=0;
    printf("%lld\n",S);
  }

  return 0;
}
  
  
  


Measured memory_bytes: 2120
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, temp, ans = 0;
    cin>>n;
    vector<int> in;
    for(int i =0; i<2*n; i++)
    {
        cin>>temp;
        in.push_back(temp);
    }
    sort(in.begin(),in.end());
    for(int i=0; i<in.size(); i+=2)
    {
        ans+=in[i];
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	bool success = false;
	if(abs(a-c) <= d) success = true;
	if(abs(a-b) <= d && abs(b-c) <= d) success = true;
	println(((success) ? "Yes" : "No"));
}


Measured memory_bytes: 256
n=int(input())
a,b=map(int,input().split())
li=[int(i) for i in input().split()]

under=0
middle=0
upper=0

for i in li:
    if i<=a:
        under+=1
    elif a+1 <=i <= b:
        middle+=1
    else:
        upper+=1
print(min(under,middle,upper))

Measured memory_bytes: 3064
# 3,2,1
a, b, c = map(int, input().split())
if a > b:
    t = a
    a = b
    b = t

if b > c:
    t = b
    b = c
    c = t

if a > b:
    t = a
    a = b
    b = t

print(a, b, c)

Measured memory_bytes: 7636
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        while (true) {
            int N = sc.nextInt();
            int M = sc.nextInt();
            if ((N | M) == 0)
                break;
            int r = sc.nextInt();
            int tt[][] = new int[M + 1][1261];
            @SuppressWarnings("unchecked")
            Stack<Integer>[] ss = new Stack[N + 1];
            for (int i = 0; i <= N; i++) {
                ss[i] = new Stack<Integer>();
            }
            for (int i = 0; i < r; i++) {
                int t = sc.nextInt();
                int n = sc.nextInt();
                int m = sc.nextInt();
                int s = sc.nextInt();
                if (s == 1) {
                    ss[n].add(t);
                } else {

                    for (int j = ss[n].pop() + 1; j <= t; j++) {
                        tt[m][j] = tt[m][j - 1] + 1;
                    }
                    for (int j = t + 1; j <= 1260; j++) {
                        tt[m][j] = tt[m][t];
                    }
//                    System.out.println(m + ":");
//                    System.out.println(Arrays.toString(tt[m]));
                }
            }

            int q = sc.nextInt();
            for (int i = 0; i < q; i++) {
                int ts = sc.nextInt();
                int te = sc.nextInt();
                int m = sc.nextInt();
                System.out.println(tt[m][te] - tt[m][ts]);
            }
        }
    }

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

Measured memory_bytes: 89000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >>N;
    vector<string> vec(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    int A=0,W=0,T=0,R=0;
    for(int i=0;i<N;i++){
        if(vec.at(i)=="AC"){
            A++;
        }
        else if(vec.at(i)=="WA"){
            W++;
        }
        else if(vec.at(i)=="TLE"){
            T++;
        }        
        else if(vec.at(i)=="RE"){
            R++;
        }
    }
    cout<<"AC"<<" "<<"x"<<" "<<A<<endl;
    cout<<"WA"<<" "<<"x"<<" "<<W<<endl;
    cout<<"TLE"<<" "<<"x"<<" "<<T<<endl;
    cout<<"RE"<<" "<<"x"<<" "<<R<<endl;
}

Measured memory_bytes: 6424
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    cout<<setprecision(16);
    ll n;
    cin>>n;


    for(ll h=1;h<=3500;h++){
        for(ll w=1;w<=3500;w++){

            ll b=4*h*w-n*(w+h);
            ll a = n*h*w;
            if(b<=0){}
            else{

                if(a%b==0&&a/b<=3500){
                 cout<<h<<" "<<w<<" "<<a/b<<endl;
//                 cout<<"debag"<<endl;
//                 cout<<4/double(n)<<endl;
//                 cout<<1/double(h)+1/double(w)+1/double(a/b)<<endl;

                 return 0;
                }
            }


        }
    }


    return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
)

func solution(n int, a []int) int {
        out := 0
        d := 0
        for i := 1; i < n; i++ {
                d = a[i] - a[i-1]
                if d <= 0 {
                        out += d * -1
                        a[i] += d * -1
                }
        }
        return out
}

func main() {
        var n int
        fmt.Scan(&n)
        a := make([]int, n)
        for i := range a {
                fmt.Scan(&a[i])
        }
        fmt.Println(solution(n, a))
}

Measured memory_bytes: 6484
N, C = map(int, input().split())
program = []
program_list = [False for _ in range((((10 ** 5) * 2) + 10))]
for _ in range(C + 1):
    program.append(program_list.copy())

for _ in range(N):
    s, t, c = map(int, input().split())
    s2 = (t * 2) - ((s * 2) - 1)
    program[c][(s * 2) - 1:t * 2] = [True] * s2

max_c = 0
for i in range(len(program_list)):
    c = 0
    for j in range(1, C + 1):
        if program[j][i]:
            c += 1
        if c > max_c:
            max_c = c
print(max_c)


Measured memory_bytes: 55208
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000009
)

var buf []byte = make([]byte, maxBufSize)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf, maxBufSize)
}
func main() {
	var N, An int
	N = nextInt()
	for i := 0; i < N; i++ {
		An = nextInt()
		// if An%2 == 1 {
		// 	continue
		// }
		if An%2 != 1 && An%3 != 0 && An%5 != 0 {
			fmt.Println("DENIED")
			return
		}
	}
	fmt.Println("APPROVED")
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}


Measured memory_bytes: 32128
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int s[110];
int main()
{
	int N;
	cin >> N;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> s[i];
		ans += s[i];
	}
	sort(s, s + N);
	if (ans % 10 == 0) {
		for (int i = 0; i < N; i++) {
			if (s[i] % 10 != 0) {
				cout << ans - s[i] << endl;
				return 0;
			}
		}
		cout << 0 << endl;
	}
	else cout << ans << endl;
}


Measured memory_bytes: 256