akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.NothingToLearn
{
    class ABC054_B
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int[] nm = ReadInts();
            int n = nm[0];
            int m = nm[1];
            string[] aStrs = new string[n];
            string[] bStrs = new string[m];
            for (int i = 0; i < n; i++)
            {
                aStrs[i] = Read();
            }
            for (int i = 0; i < m; i++)
            {
                bStrs[i] = Read();
            }

            for (int i = 0; i < n - m + 1; i++)
            {
                for (int j = 0; j < n - m + 1; j++)
                {
                    bool ok = true;
                    for(int k = 0; k < m; k++)
                    {
                        for(int l = 0; l < m; l++)
                        {
                            if (aStrs[i + k][j + l] != bStrs[k][l])
                            {
                                ok = false;
                            }
                        }
                    }
                    if (ok)
                    {
                        WriteLine("Yes");
                        return;
                    }
                }
            }
            WriteLine("No");
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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


int main(){

 long long int N,M,C,K;
  scanf("%lld %lld %lld %lld",&N,&M,&C,&K);

/*
  char A[];
  scanf("%s",A);
  */

  /*
  long long int A[N+1];
  long long int i;
  for(i=1;i<=N;i++){
   scanf("%lld",&A[i]);
   }
  */
if(N>=K){
  printf("%lld",K);
}

else if(N+M>=K){
  printf("%lld",N);
}
else{
  printf("%lld",N-(K-(N+M)));
}








 return(0);
 }


Measured memory_bytes: 1732
program main
  implicit none
  integer :: n, m, i, j
  integer, allocatable :: ab(:, :), cd(:, :)
  read (*, *) n, m
  allocate (ab(2, n), cd(2, m))
  do i = 1, n
    read (*, *) ab(:, i)
  end do
  do i = 1, m
    read (*, *) cd(:, i)
  end do

  do i = 1, n
    write (*, "(i0)") closest_index(ab(:, i))
  end do
  contains

  integer function closest_index(student)
    integer, intent(in) :: student(2)
    integer :: mdmin, i, md
    mdmin = 2 * 10 ** 9 + 1
    do i = 1, m
      md = abs(student(1) - cd(1, i)) + abs(student(2) - cd(2, i))
      if (md < mdmin) then
        closest_index = i
        mdmin = md
      end if
    end do
  end function closest_index
end program main


Measured memory_bytes: 256
mod = int(1e9+7)
def add(a, b):
    c = a + b
    if c >= mod:
        c -= mod
    return c

def main():
    n = int(raw_input())
    
    arr = [int(x) for x in raw_input().split()]
    
    s = set(arr)
    
    if len(s) == len(arr):
        print('YES')
    else:
        print('NO')
    

main()

Measured memory_bytes: 120148
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct path {
	int v, w;
};
struct info {
	int cnt, run, i;
	bool operator< (const info& t) const {
		return make_pair(cnt, run) > make_pair(t.cnt, t.run);
	}
};
vector<path> adj[301];
vector<pair<int, int>> qry[301]; // v, i
pair<int, int> dist[301];
const int MX = 301*302;
int ans[MX];
int INF = 0x3f3f3f3f3f3f3f3fll;

int32_t main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int n, m, l;
	cin >> n >> m >> l;
	for(int i=0; i<m; i++) {
		int a, b, c;
		cin >> a >> b >> c;
		if(c > l) continue;
		adj[a].push_back({b, c});
		adj[b].push_back({a, c});
	}
	int q;
	cin >> q;
	for(int i=0; i<q; i++) {
		int s, t;
		cin >> s >> t;
		qry[s].push_back({t, i});
	}
	for(int i=1; i<=n; i++) {
		memset(dist, 0x3f, sizeof dist);
		dist[i] = {0,0};
		priority_queue<info> pq;
		pq.push({0,0,i});
		while(!pq.empty()) {
			auto p = pq.top();
			int cnt = p.cnt, run = p.run, k = p.i;
			//printf("pop at k=%lld. dist is {%lld, %lld}\n", k, cnt, run);
			pq.pop();
			if(dist[k] > make_pair(cnt, run)) continue;
			for(auto a: adj[k]) {
				int v = a.v, w = a.w;
				pair<int, int> now = {cnt, run};
				now.second += w;
				if(now.second > l)
					now = {cnt+1, w};
				if(now < dist[v]) {
					dist[v] = now;
					pq.push({now.first, now.second, v});
				}
			}
		}
		for(auto qr: qry[i]) {
			ans[qr.second] = dist[qr.first].first == INF ? -1 : dist[qr.first].first;
		}
	}
	for(int i=0; i<q; i++) {
		cout << ans[i] << '\n';
	}
}

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

using namespace std;

#define REP(i,n)	for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPS(i,s,n)	for(int i=(s), i##_len=(n); i<i##_len; ++i)

#define ALL(obj)	(obj).begin(),(obj).end()

typedef unsigned int 			uint;
typedef unsigned long long int	ull;
typedef long long int 			ll;

typedef pair<int,int>			P;

#define LINF		((ll)1 << 63 -1)
#define INF 		(1<<29)
#define MINF		-2000000007
#define MAX 		205

const int MOD = 1e9+7;
// テンプレ終了
//====================================================================//

int d[MAX][MAX];
//
int main(){
	int N,M,R;cin>>N>>M>>R;
	vector<int> r(R);
	REP(i,R){cin>>r[i];r[i]--;}
	REP(i,N)REP(j,N)d[i][j] = (i!=j ? INF : 0);
	REP(i,M){
		int a,b,c;
		cin >> a >> b >> c;
		--a,--b;
		d[a][b] = min(d[a][b],c);
		d[b][a] = min(d[b][a],c);
	}

	REP(i,N)
		REP(j,N)
			REP(k,N)
				d[j][k] = min(d[j][k],d[j][i] + d[i][k]);

	sort(ALL(r));
	ll ans = INF;
	do{
		ll suml=0;
		REP(i,R-1)suml += d[r[i]][r[i+1]];
		ans = min(ans,suml);
	}while(next_permutation(ALL(r)));
	cout << ans << endl;

	return 0;
}




Measured memory_bytes: 384
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        int n,m; cin >> n >> m;
        string up(m+2,'#');
        string s;
        cout<<up<<endl;
        for(int i = 0; i<n; i++){
            cout<<"#"; cin >> s; cout<<s;cout<<"#"<<endl;
        }
        cout<<up<<endl;

return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
// #include<bits/stdc++.h>
using namespace std;
#define ll long long
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INFI = 1000000007;



vector<bool> arr(60000,false);
vector<int> price;
void isPrice(){
  arr[0] = true;
  arr[1] = true;
  for(int i=2; i*i<=60000; i++){
    if(arr[i]){
      continue;
    }
    for(int j=2; i*j<=60000; j++){
      arr[i*j] = true;
    }
  }
}

int main(){
  isPrice();
  int N;
  cin >> N;
  for(int i=31; i<=60000; i++){
    if(!arr[i] && i%5==1){
      cout << i << " ";
      N--;
    }
    if(N == 0){
      break;
    }
  }
  cout << endl;


  return 0;
}


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

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

#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define rrep(i,a) for(ll i=a-1;i>=0;i--)
#define MOD 1000000007

//debug
#define debug(arr) cerr<<#arr<<"(l"<<__LINE__<<") : ";for(auto x:arr)cerr<<x<<" ";cerr<<endl;

int main(){
  ll n, m, k;
  ll time = 0, n_book = 0, ans, aidx, bidx;
  cin >> n >>  m >> k;
  ll A[n], B[m];
  rep(i, n) cin >> A[i];
  rep(i, m) cin >> B[i];

  rep(i, n){
    if(time + A[i] > k) break;
    time += A[i];
    n_book++;
  }
  aidx = n_book - 1;
  bidx = 0;
  ans = n_book;

  while(bidx < m){
    if(time + B[bidx] <= k){
      time += B[bidx];
      n_book++;
      if(n_book > ans) ans = n_book;
      bidx++;
    }
    else if(aidx >= 0){
      time -= A[aidx--];
      n_book--;
    }
    else{
      break;
    }
  }
  cout << ans << endl;
  return 0;
}



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

void solve(std::istream &ist, std::ostream &ost)
{
    /* ------- 宣言と入力 ------- */

    int N;
    string S;

    ist >> N;
    ist >> S;

    /* ------- 計算 ------- */

    unordered_set<int> R;
    unordered_set<int> G;
    unordered_set<int> B;

    for (int i = 0; i < N; i++)
    {
        if (S[i] == 'R')
        {
            R.emplace(i);
        }
        else if (S[i] == 'G')
        {
            G.emplace(i);
        }
        else if (S[i] == 'B')
        {
            B.emplace(i);
        }
    }

    // unordered_set<int> maxsize;
    long long ans = R.size() * G.size() * B.size();

    for (auto g : G)
    {
        for (auto b : B)
        {
            if (R.find(min(g, b) - abs(g - b)) != R.end())
            {
                ans--;
            }

            if (R.find(max(g, b) + abs(g - b)) != R.end())
            {
                ans--;
            }

            if (abs(g - b) % 2 == 0)
            {
                if (R.find(max(g, b) - abs(g - b) / 2) != R.end())
                {
                    ans--;
                }
            }
        }
    }

    cout << ans << endl;
}

#ifndef WOMAIN
int main()
{
    solve(std::cin, std::cout);
    return 0;
}
#endif


Measured memory_bytes: 3752
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {

    static int N;
    static String[] W;

    public static void main(String[] args) {
        FastScanner sc = new FastScanner(System.in);
        N = sc.nextInt();
        W = new String[N];
        for (int i = 0; i < N; i++) {
            W[i] = sc.next();
        }

        System.out.println(solve() ? "Yes" : "No");
    }

    static boolean solve() {
        String prev = W[0];
        for (int i = 1; i < N; i++) {
            if( prev.charAt(prev.length()-1) != W[i].charAt(0) ) {
                return false;
            }
            prev = W[i];
        }

        Set<String> set = new HashSet<>(Arrays.asList(W));
        return set.size() == N;
    }

    @SuppressWarnings("unused")
    static class FastScanner {
        private BufferedReader reader;
        private StringTokenizer tokenizer;

        FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken("\n");
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 22740
N, K = map(int, input().split())

# 問題:aをbで割った余りがK以上
# bを固定(これにより、可能性のある余りの値は0,1,...b-1に限られる)して、aの数を数える
# N=pb+rとする
# 余りは、0,1,2,...,b-1のループを(p=0,1,...,p-1)とp回繰り返し、0,1,2,...rで終わる
# p = N//b, r = N%b
# ループ部分はp * max(0,b-K)個、最後の部分はmax(0,r-K+1)個が条件を満たす
# K >= b (ex. 3で割った余りが5以上ですとか言われた時)に0を返すためにmaxを使っている

ans = 0
# bを固定
# bで割って余りがK以上なので、bはK+1からNまでのみ考えても良い
for b in range(1, N + 1):
    p = N // b
    r = N % b
    # K=0だとここでa=0の場合も含んでしまう、a>1という条件なので調整が必要
    # これは各bについて1通りなので最後にN引けば良い
    ans += p * max(0, b - K) + max(0, r - K + 1)
    # print(b, ans)

if K == 0:
    print(ans - N)
else:
    print(ans)


Measured memory_bytes: 9164
#include<bits/stdc++.h>
#include<assert.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;
		ans += 2 * min(x, k - x);
	}
	cout << ans << endl;

	return 0;
}


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

using namespace std;

typedef long long ll;
#define int ll
typedef long double ld;

typedef pair<int,int> pii;
#define x first
#define y second

const int D=365,A=26;

int d;
int c[A],s[D][A];

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin>>d;
    for(int j=0;j<A;j++)
        cin>>c[j];
    for(int i=0;i<d;i++)
        for(int j=0;j<A;j++)
            cin>>s[i][j];
    for(int i=0;i<d;i++)
    {
//        int best=0;
//        for(int j=0;j<A;j++)
//            if(s[i][j]>s[i][best])
//                best=j;
        cout<<rand()%A+1<<"\n";
    }
}


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

const int MAX_S = 101000;

bool p[MAX_S];

void prime() {
  fill(p, p+MAX_S, true);
  p[0] = false;
  p[1] = false;
  for(int i = 2; i < MAX_S; i++) {
    if(p[i]) {
      for(int j = 2; i*j < MAX_S; j++) {
	p[i*j] = false;
      }
    }
  }
}

int main() {
  int n;
  prime();
  while(cin >> n, n) {
    int ans;
    for(int i = 5; i <= n; i++) {
      if(p[i] && p[i-2]) ans = i;
    }
    cout << ans-2 << ' ' << ans << endl;
  }
}

Measured memory_bytes: 1256
import java.util.*;
import java.util.stream.Collectors;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int k = sc.nextInt();
		
		char[] string = new char[n];
		String line = sc.next();
	    for (int i = 0; i < n; i++) {
	      string[i] =line.charAt(i);
	    }
		
		string[k-1] = Character.toLowerCase(string[k - 1]);
		
		for(int tmp = 0; tmp < string.length ; tmp++) {
			System.out.print(string[tmp]);
		}
	  }
}

Measured memory_bytes: 21844
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
#define int long long
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000000000000;

int N,W;
int w[110],v[110];
int dp[110][100010];

int DP(int a,int b){
	if(a>=0&&dp[a][b]!=-1)return dp[a][b];
	int res=-INF;
	if(a==N){
		return 0;
	}
	if(b+w[a+1]<=W){
		res=DP(a+1,b+w[a+1])+v[a+1];
	}
	int res2=max(DP(a+1,b),res);
	if(a>=0){
		dp[a][b]=res2;
	}
	return res2;
}

signed main(){
	cin>>N>>W;
	REP(i,N){
		cin>>w[i]>>v[i];
	}
	REP(i,100)REP(j,100000){
		dp[i][j]=-1;
	}
	cout<<DP(-1,0)<<endl;
	return 0;
}


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

int main(){
  vector<int> a(5);
  for(int i=0;i<5;i++){
    cin>>a.at(i);
  }
  vector<int> A(5);
  int sum=10;
  for(int i=0;i<5;i++){
    A.at(i)=a.at(i)%10;
    if(A.at(i)==0)A.at(i)=10;
    sum=min(sum,A.at(i));
  }
  int k;
  for(int i=0;i<5;i++){
    if(sum==A.at(i)){
      k=i;break;
    }
  }
  int suma=0;
  for(int i=0;i<5;i++){
    if(i==k){
      suma=suma+a.at(i);
    }else{
      if(a.at(i)%10==0){
        suma+=a.at(i);
      }else{
        suma=suma+a.at(i)-A.at(i)+10;
      }
    }
  }
  cout<<suma<<endl;
  
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
 
int main(void)
{
  int n,i,ans;
  double t,temp,a,h,min=1000;
  scanf("%d%lf%lf",&n,&t,&a);
  for(i=0;i<n;i++){
    scanf("%lf",&h);
    temp=t-h*0.006;
    if(fabs(a-temp)<min){
      min=fabs(a-temp);
      ans=i;
    }
  }
  printf("%d",ans+1);
  return 0;
 
}

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

#define endl '\n'
#define fi first
#define se second
#define fast ios_base::sync_with_stdio(0);cin.tie(0);
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define deb cout<<"HOLA\n";
#define UNIQUE(v) (v).resize(unique(ALL(v))-(v).begin())
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define bs(v,f) binary_search(ALL(v),f)
#define lb(v,f) lower_bound(ALL(v),f)
#define ub(v,f) upper_bound(ALL(v),f)
#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef string str;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;

struct tri{
    ll w,v;
};
vector<tri>v;
ll n,w;
ll dp[101][100005];

ll ans(ll x,ll l){
    if(x>=n or l<=0)return 0;
    if(dp[x][l]!=-1)return dp[x][l];
    return dp[x][l]=max(l-v[x].w>=0?ans(x+1,l-v[x].w)+v[x].v:INT_MIN,ans(x+1,l));
}

void solve(){
	cin>>n>>w;
	v.resize(n);
	forn(i,n)
        cin>>v[i].w>>v[i].v;
    forn(i,101){
        forn(j,100004){
           dp[i][j]=-1;
        }
    }
	cout<<ans(0,w);
}
int main(){
    fast
	/*int t;
	cin>>t;
	while(t--)*/
		solve();
	return 0;
}



Measured memory_bytes: 79232
N = int(input())
As = list(map(int, input().split()))

#負の数カウントと絶対値リスト作成
abs_As = []
negative_count = 0

for A in As:
    if(A <= 0):
        abs_As.append(abs(A))
        negative_count += 1
    
    else:
        abs_As.append(A)

#print(As)
#print(abs_As)
#print(negative_count)

if(negative_count % 2 == 0):
    print(sum(abs_As))

else:
    print(sum(abs_As) - 2 * min(abs_As))

Measured memory_bytes: 19916
#include <bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()

using namespace std;

int main(int argc, char const *argv[]) {
  int N;
  double temp=0;
  scanf("%d",&N);
  std::vector<int> v(N);
  for (size_t i = 0; i < N; i++) {
    std::cin >> v[i];
    temp+=v[i];
  }
  temp=temp/N;
  int calc=(int)round(temp);
  ll cost=0;
  for (size_t i = 0; i < N; i++) {
    cost+=pow(v[i]-calc,2);
  }
  printf("%lld\n",cost);

  return 0;
}


Measured memory_bytes: 512
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
using namespace std;
typedef long long LL;
typedef pair<LL,LL> P;


const int L=2e5+2;
vector<int> es[L];
void solve(long long N, std::vector<long long> a, std::vector<long long> b){

}

int N;
int p[L];
int c[2];
bool ok=true;
void f(int r,int q,int i){
	p[r]=i;
	c[i]++;
	for(auto e:es[r]){
		if(e==q)continue;
		f(e,r,i^1);
	}
}
int ret[L];
int main(){
    scanf("%d",&N);
    for(int i = 0 ; i < N-1 ; i++){
		int a,b;
        scanf("%d",&a);
        scanf("%d",&b);
		a--;
		b--;
		es[b].push_back(a);
		es[a].push_back(b);
    }
	int v[3]={1,2,3};
	LL r=N/3;
	f(0,-1,0);
	if(c[0]<=r){
		for(int i=0;i<N;i++){
			if(p[i]==0){
				ret[i]=v[2];
				v[2]+=3;
			}
			else if(v[0]<=N){
				ret[i]=v[0];
				v[0]+=3;
			}
			else if(v[1]<=N){
				ret[i]=v[1];
				v[1]+=3;
			}
			else{
				ret[i]=v[2];
				v[2]+=3;
			}
		}
	}
	else if(c[1]<=r){
		for(int i=0;i<N;i++){
			if(p[i]==1){
				ret[i]=v[2];
				v[2]+=3;
			}
			else if(v[0]<=N){
				ret[i]=v[0];
				v[0]+=3;
			}
			else if(v[1]<=N){
				ret[i]=v[1];
				v[1]+=3;
			}
			else{
				ret[i]=v[2];
				v[2]+=3;
			}
		}
	}
	else{
		for(int i=0;i<N;i++){
			if(v[p[i]]<=N){
				ret[i]=v[p[i]];
				v[p[i]]+=3;
			}
			else{
				ret[i]=v[2];
				v[2]+=3;
			}
		}
	}
	
	auto sp="";
	for(int i=0;i<N;i++){
		cout << sp << ret[i];
		sp=" ";
	}
	cout << endl;
    return 0;
}


Measured memory_bytes: 19072
#include<stdio.h>
 
int main (void){
 
	int a,b;
  
    scanf("%d %d",&a,&b);
    if(0<=a && a<=8 && 0<=8 && b<=8){
      printf("Yay!");
    }
    else{
      printf(":(");
    }
      
  
	return 0;
}

Measured memory_bytes: 128
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    return

#B
def B():
    return

#C
def C():
    return

#D
def D():
    x,y,z = LI()
    for i in range(1000000)[::-1]:
        if i*y+(i+1)*z <= x:
            print(i)
            quit()
    return

#E
def E():
    d = [(1,0),(-1,0),(0,1),(0,-1)]
    h,w = LI()
    s = SR(h)
    for i in range(h):
        for j in range(w):
            if s[i][j] == "#":
                su = 0
                for dy,dx in d:
                    y = i+dy
                    x = j+dx
                    if 0 <= y < h and 0 <= x < w:
                        if s[y][x] == "#":
                            su += 1
                if su == 0:
                    print("No")
                    quit()
    print("Yes")
    return

#F
def F():
    a,b,c,X,Y = LI()
    ans = float("inf")
    for z in range(300001):
        if z%2 == 0:
            m = c*z
            x = z//2
            y = z//2
            m += a*max(0,X-x)
            m += b*max(0,Y-y)
            if m < ans:
                ans = m
    print(ans)
    return

#G
def G():
    n = I()
    x = LI()
    f = [(i,x[i]) for i in range(n)]
    f.sort(key = lambda x:x[1])
    g = [(f[i][0],i) for i in range(n)]
    g.sort(key = lambda x:x[0])
    for i in range(n):
        if g[i][1] < n//2:
            print(f[n//2][1])
        else:
            print(f[n//2-1][1])
    return

#H
def H():
    return

#I
def I_():
    return

#J
def J():
    return

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


Measured memory_bytes: 40816
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define PI 3.141592653589793
#define MOD 1000000007


int main(){
	int h, a;
	scanf("%d%d", &h, &a);
	int count =0;
	while(h>0){
		h = h-a;
		count++;
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 128
a,b,c=map(int,input().split())
count=0
if b>=c:
    count+=b+c
elif b<c:
    count+=b*2
    if a>0:
        if c-b>a:
            count+=a+1
        elif c-b==a:
            count+=a
        else:
            count+=c-b
print(count)
        

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

ll GCD(ll x, ll y) {
    if (y == 0) return x;
    else return GCD(y, x % y);
}

ll LCM(ll x, ll y) {
    return x * y / GCD(x, y);
}


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


Measured memory_bytes: 256
#!/usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from bisect import bisect_left, bisect_right
import sys, random, itertools, math
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
sqrt = math.sqrt
def LI(): return list(map(int, input().split()))
def LF(): return list(map(float, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def IF(): return float(input())
def S(): return input().rstrip()
def LS(): return S().split()
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = 1e10

#solve
def solve():
    h, w, n = LI()
    sr, sc = LI()
    s = S()[::-1]
    t = S()[::-1]
    
    plus = 0
    minus = 1

    def f(l, start, end):
        tmp = [1, end]
        for i in range(n):
            if t[i] == l[plus]:
                tmp[0] -= 1
                tmp[0] = max(tmp[0], 1)
            elif t[i] == l[minus]:
                tmp[1] += 1
                tmp[1] = min(end, tmp[1])
            if s[i] == l[plus]:
                tmp[1] -= 1
            elif s[i] == l[minus]:
                tmp[0] += 1
            if tmp[1] < tmp[0]:
                return False
        return tmp[0] <= start <= tmp[1]
    
    print("YES" if f(["R", "L"], sc, w) and f(["D", "U"], sr, h) else "NO")
    return


#main
if __name__ == '__main__':
    solve()


Measured memory_bytes: 45424
s = input()

xx = s[0] + s[1]
yy = s[2] + s[3]
xx = int(xx)
yy = int(yy)

if 1 <= xx <= 12:
    if yy >= 13 or yy == 0:
        print("MMYY")
    else:
        print("AMBIGUOUS")

if xx == 0 or 13 <= xx <= 99:
    if 1 <= yy <= 12:
        print("YYMM")
    else:
        print("NA")

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>
#include <cstring>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define all(c) begin(c),end(c)

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 long long int ll;
using ll = long long int;
using ull = long long unsigned int;
using namespace std;
#define INF (1 << 30) - 1
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007


//ここから編集する
class Solve {
public:
    void solve() {
        int a, b, c;
        cin >> a >> b >> c;
        int ans = max(c - a + b, 0);
        cout << ans << endl;

    }
};


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    Solve().solve();


    return 0;
}


Measured memory_bytes: 256
// In the name of God 
#include <bits/stdc++.h>

using namespace std ;


#define int long long
#define all(v) v.begin() , v.end()

template<typename T> inline bool smin(T &a, const T &b){ return b < a ? a = b,1:0;}
template<typename T> inline bool smax(T &a, const T &b){ return a < b ? a = b,1:0;}

const int N = ( int ) 1e5 + 10 ;

int n , a [ N ] ; 

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n ;
	for ( int i = 1 ; i <= n ; ++i )
		cin >> a [ i ] ;
	sort ( a + 1 , a + n + 1 ) ;
	reverse ( a + 1 , a + n + 1 ) ; 
	int id = 0 ;
	for ( int j = 1 ; j <= n ; ++j )
		if ( a [ j ] >= j )
			id = j ;
	//cout << id << '\n' ; 
	int res = 0 , rem = a [ id ] - id + 1 ;
	res |= rem % 2 == 0 ;
	int found = 0 ; 
	for ( int i = id + 1 ; i <= n ; ++i ) {
		if ( a [ i ] >= id ) {
			found = i ; 
		}
	}
	//cout << rem << ' ' << found << '\n' ; 
	if ( found ) 
		res |= ( found - id + 1 ) % 2 == 0 ;
	cout << ( res ? "First" : "Second" ) << '\n' ; 
}


Measured memory_bytes: 1024
<>=~$";$G=$';for(<>){$i+=100;for$k(reverse@a=/ /..1e3){$p[$k]+=$-=$_>$k?0:$p[$k-$_]+$i*$_+($_==$`&&$')-$p[$k]for 1..$`}}printf grep$p[$_]>=$G,@a

Measured memory_bytes: 768
#include <stdio.h>
#include <string.h>

int main(void){
  char str[21];
  int i, len;

  scanf("%s", str);
  len = (int)strlen(str);
  for(i = len-1; i >= 0; i--){
    printf("%c", str[i]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 524
while(True):
    H,W = map(int, input().split())
    if(H==0 and W == 0): exit()
    print('#'*W)
    for i in range(H-2):
        print("#", end="")
        print("."*(W-2), end="")
        print("#")
    print("#"*W)
    print("")


Measured memory_bytes: 5632
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    double takasa = 0;
    double teihen = 0;
    double syahen = 0;
    takasa = sc.nextInt();
    teihen = sc.nextInt();
    syahen = sc.nextInt();
    syahen = 0.5;
      
    double menseki = 0;
    menseki = (teihen * takasa) * syahen;
    int intmenseki = (int)menseki;
    System.out.println(intmenseki);
  }
}

Measured memory_bytes: 23124
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
//typedef long long int;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  vi a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  sort(a.begin(), a.end());
  vii c(1, pii(a[0], 1));
  for (int i = 1; i < n; ++i) {
    if (a[i] == a[i-1]) ++c.back().second;
    else c.emplace_back(a[i], 1);
  }
  ll ma = 0, pr = 0;
  for (int i = c.size() - 1; i >= 0; --i) {
    if (c[i].second >= 4) ma = max(ma, c[i].first * (ll)c[i].first);
    if (c[i].second >= 2) {
      ma = max(ma, c[i].first * pr);
      pr = c[i].first;
    }
  }
  cout << ma << endl;
  return 0;
}

Measured memory_bytes: 1784
import java.util.Scanner;

public class Main {

     static Scanner scanner;

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

         int N=gi();
         int[] a=new int[N];

         for(int i=0; i<N;i++) {
        	 a[i]=gi();
         }

         long ans=0;
         for (int i=0; i<N;i++) {
        	 if(a[i]%2==0) {
        		 ans+=a[i]/2;
        		 a[i]=0;
        	 } else {
        		 ans+=Math.floorDiv(a[i], 2);
        		 if (i+1<N && a[i+1]>0) {
        			 ans++;
        			 a[i]=0;
        			 a[i+1]--;
        		 }
        	 }
         }

         System.out.println(ans);
         //System.out.println(ans);
     }

     public static class Edge {
    	    private int from;
    	    private int to;
    	    private long cost;

    	    public Edge(int f, int t, long c) {
    	    	this.from=f;
    	    	this.to=t;
    	    	this.cost=c;
    	    }
    	}
     // 文字列として入力を取得
     public static String gs() {
          return scanner.next();
     }

     // intとして入力を取得
     public static int gi() {
          return Integer.parseInt(scanner.next());
     }

     // longとして入力を取得
     public static long gl() {
          return Long.parseLong(scanner.next());
     }

     // doubleとして入力を取得
     public static double gd() {
          return Double.parseDouble(scanner.next());
     }
}

Measured memory_bytes: 59908
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vl vector<long long int>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vb vector<bool>
#define vvl vector<vector<ll> >
#define vvi vector<vector<int> >
#define pl pair<ll,ll>
#define pb push_back
#define PI 3.14159265
#define mod 998244353
#define pb push_back
#define mp make_pair
#define fri(s,n) for(int i=s;i<n;i++)
#define frj(s,n) for(int j=s;j<n;j++)
#define T(i) int i=1;cin>>i;while(i--)
#define vsi vector<set<int> >
#define pii pair<int,int>
#define inf 1e9
#define vpii vector<pair<int,int> >


ll power(ll a,ll b){
    if(b==0)
        return 1;
    if(b&1)
        return a*power(a,b-1);
    ll temp=power(a,b/2);
    return temp*temp;
    }
bool mycompare(ll a,ll b){
    return a>b;
    }
ll dp[3005][3005];
ll solve(vector<int> &a,int i,int j){
    if(i==j)
        return a[i];
    if(dp[i][j]!=-1)
        return dp[i][j];
    return dp[i][j]=max(a[i]-solve(a,i+1,j),a[j]-solve(a,i,j-1));

    }
int main(){
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    fast;
    int n;
    cin>>n;
    vi a(n);
    memset(dp,-1,sizeof dp);
    fri(0,n)
        cin>>a[i];
    dp[0][n-1]=solve(a,0,n-1);
    cout<<dp[0][n-1];

}


Measured memory_bytes: 74452
#include <bits/stdc++.h>
       
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
  int X;
  cin >> X;
  cout << (X / 500) * 1000 + ((X % 500) / 5) * 5 << endl;
  return 0;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            uint X = uint.Parse(Console.ReadLine());
            bool flag;
            while (true)
            {
                flag = true;

                if(X == 2)
                {
                    break;
                }

                for (int i = 2; i <= X; i++)
                {
                    if(X == i)
                    {
                        break;
                    }

                    if(X % i == 0)
                    {
                        flag = false;
                        break;
                    }
                }

                if (flag) break;
                X++;
            }

            Console.WriteLine(X);

            return;
        }
    }
}


Measured memory_bytes: 13140
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
INF = float("inf")


def solve(N: int, M: int):
    print(N*(N-1)//2+M*(M-1)//2)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    solve(N, M)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
package main

import (
	"fmt"
)

func main() {

	var room [4][3][10]int

	var a int

	fmt.Scan(&a)

	for i := 0; i < a; i++ {
		var b, c, d, e int
		fmt.Scanf("%d%d%d%d", &b, &c, &d, &e)
		b--
		c--
		d--

		room[b][c][d] += e

		if room[b][c][d] < 0 {
			room[b][c][d] = 0
		}

		if room[b][c][d] > 9 {
			room[b][c][d] = 9
		}

	}

	for i, v := range room {

		if i != 0 {
			fmt.Println("####################")
		}

		for _, v2 := range v {
			for _, v3 := range v2 {
				fmt.Printf(" %d", v3)
			}
			fmt.Println("")
		}
	}
}



Measured memory_bytes: 1188
// AOJ ITP2_1_C List
// 2019.3.8 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()    // 整数入力（マイナス値でもOK）
{
	int n = 0, c = gc();
	if (c == '-') {
		c = gc();
		do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
		return -n;
	}
	do n = 10 * n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)   // 整数表示（マイナス値でもOK）、最後に改行あり
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) ob[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}

#define END 1000000001
typedef struct { int x, pre, nxt; } T;
T tbl[500002]; int top, cur, sz;

int main()
{
	int q, c, x, pre, nxt;

	sz = 1, tbl[0].pre = tbl[0].nxt = -1, tbl[0].x = END, top = cur = 0;
	q = in();
	while (q--) {
		c = gc() & 0xf, gc();
		if (c == 0) {
			x = in();
			nxt = cur, pre = tbl[cur].pre, cur = sz++;
			tbl[cur].x = x;
			if (pre < 0) tbl[cur].pre = -1, top = cur;
			else tbl[cur].pre = pre, tbl[pre].nxt = cur;
			if (nxt < 0) tbl[cur].nxt = -1;
			else tbl[cur].nxt = nxt, tbl[nxt].pre = cur;
		}
		else if (c == 1) {
			x = in();
			if (x < 0) { x = -x; while (x--) cur = tbl[cur].pre; }
			else while (x--) cur = tbl[cur].nxt;
		}
		else {   // c == 2
			pre = tbl[cur].pre, nxt = tbl[cur].nxt;
			if (pre < 0) tbl[nxt].pre = -1, cur = top = nxt;
			else if (nxt < 0) tbl[pre].nxt = -1, cur = pre;
			else tbl[pre].nxt = nxt, tbl[nxt].pre = pre, cur = nxt;
		}
	}
	cur = top;
	while (tbl[cur].x != END) {
		out(tbl[cur].x);
		cur = tbl[cur].nxt;
	}
	return 0;
}


Measured memory_bytes: 7412
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <inttypes.h>
using namespace std;
#define INF 0x3f3f3f3f

int main(){
    int n;
    scanf("%d", &n);
    printf("ABC%d\n",n);
    return 0;
}


Measured memory_bytes: 128
integer1, integer2 = map(int, input().split())
if integer1 + integer2 >= integer1 - integer2:
    if integer1 + integer2 >= integer1 * integer2:
        print(integer1 + integer2)
    else:
        print(integer1 * integer2)
elif integer1 - integer2 >= integer1 * integer2:
    print(integer1 - integer2)
else:
    print(integer1 * integer2)

Measured memory_bytes: 9164
#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<map>
#include<tuple>
#include<algorithm>
#include<numeric>
#include<math.h>

#define REPS(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;

const int mod = 1e9 + 7;
const long double pi = 3.141592653589793238462643383279502884197;
const long double eps = 1e-7;

int main() {
	cin.tie(0);
	ll N, K;
	cin >> N >> K;
	ll ans = 0;

	if (K == 0) ans = N*N;
	else {
		REPS(b, K+1, N + 1) {
			ll p = N / b;
			ll r = N%b;

			ans += p*max(b - K, 0LL);
			ans += max(r - K + 1, 0LL);
		}
	}
	cout << ans;
	system("pause");
	return 0;
}

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

#define mem( arr, i ) fill( arr, arr + sizeof (arr), i )
#define MEM( arr, i ) memset( arr, i, sizeof (arr) )
#define Push push_back
#define Pair make_pair
typedef unsigned long long ull;
typedef long long lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vcI;
typedef vector<lli> vcL;
typedef vector<pii> vPI;
typedef vector<pll> vPL;
//typedef priority_queue<T> prior_S<T>;
//typedef priority_queue< T, vector<T>, greater<T> > prior_B<T>;
const double PI = 3.141592653589793;
const lli I_MAX = 1LL << 60;
const lli mod = 1000000007;


void precal() {

	return;
}

void solve() {
	lli n, A = 0, B = 0, C = 0, D = 0;
	cin >> n;
	
	string s[n];
	for (int i = 0; i < n; ++i) {
		cin >> s[i];
		
		for (int j = 1; j < s[i].size(); ++j) {
			if ( s[i][ j-1 ] == 'A' and s[i][j] == 'B' ) D++ ;
		}
		
		if ( *s[i].begin() == 'B' and *s[i].rbegin() == 'A' ) C++ ;
		else if ( *s[i].begin() == 'B' ) B++ ;
		else if ( *s[i].rbegin() == 'A' ) A++ ;
	}
	
	if ( A and B ) {
		A-- ;
		B-- ;
		D += C + 1;
	}
	else if ( A ) {
		A-- ;
		D += C;
	}
	else if ( B ) {
		B-- ;
		D += C;
	}
	else {
		D += max( 0LL, C-1 );
	}
	
	D += min( A, B );
	
	cout << D << '\n';
}

int main() {
	precal();
	int t = 1;
//	cin >> t;
	for (int i = 1; i <= t; ++i) {
//		printf("Case #%d: ", i );
		solve();
	}
	return 0;
}


Measured memory_bytes: 768
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, K = map(int, readline().split())
    point = list(map(int, readline().split()))
    T = readline().strip()

    T = list(map(int, T.translate(str.maketrans('rsp', '012'))))

    ans = 0
    for i in range(K):
        M = (N - i + K - 1) // K
        dp = [[0] * 3 for _ in range(M + 1)]
        for j in range(M):
            for k in range(3):
                dp[j + 1][k] = max(dp[j][(k + 1) % 3], dp[j][(k + 2) % 3])
                if (k + 1) % 3 == T[i + j * K]:
                    dp[j + 1][k] += point[k]
        ans += max(dp[M])

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 22764
#include<stdio.h>
int main()
{
	int a,b;
	scanf("%d%d",&a,&b);
	int a1,a2,a3;
	a1=a+b;
	a2=a-b;
	a3=a*b;
	int max=-9999999;
	if(a1>max) max=a1;
	if(a2>max) max=a2;
	if(a3>max) max=a3;
	printf("%d",max);
}

Measured memory_bytes: 128
from sys import stdin


def main():
    n = int(stdin.readline())
    a = [int(stdin.readline()) for _ in range(n)]
    l = {}
    for ai in a:
        if ai not in l:
            l[ai] = 1
        else:
            l[ai] = l[ai] + 1
    ans = 0
    for key in l:
        if l[key] % 2 == 1:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

#define int long long
using namespace std;

char a[100];
int b;

int EXP(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return EXP(x - 1) * 10;
	}
}

signed main()
{
	for (int i= 9; i >=0; i--) {
		cin >> a[i];
	}
	for (int i = 0; i<10; i++) {
		if (i == 2 || i == 5) {
			continue;
		}
		b += (a[i] - '0') * EXP(i);
	}

	if (b <= 2019004030) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}

	//system("pause");

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int i,j,k;
  int flag=1;
  int N;
  int a[200];
  int t;
  int count=0;
  scanf("%d",&N);
  for(i=0;i<N;i++)  scanf("%d",&a[i]);

  while(flag==1){
    flag=0;
    for(j=N-1;j>=1;j--){
      if(a[j]<a[j-1]){
        t=a[j];
        a[j]=a[j-1];
        a[j-1]=t;
        flag=1;
        count++;
      }
    }

  }
  for(i=0;i<N-1;i++)  printf("%d ",a[i]);
  printf("%d\n",a[N-1]);
  
  printf("%d\n",count);


  return 0;
}

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

using namespace std;


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

    vector <pair<int, int> > a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].first;
        a[i].second = i + 1;
    }
    sort(a.begin(), a.end());
    for (auto x: a) {
        cout << x.second << " ";
    }
	return 0;
}


Measured memory_bytes: 1536
"use strict";
function I(t,i){this._s=t.split("\n"),this._c=0,this._l=0,this._f=i||Number}I.prototype.a=function(t){var i=this._s[this._l];if(i){var s=i.trim().split(" "),h=s[this._c];return this._c++,s.length===this._c&&(this._c=0,this._l++),t?t(h):this._f(h)}},I.prototype.l=function(t){var i=this._s[this._l];if(i)return this._c=0,this._l++,i.split(" ").map(t||this._f)},module.exports=I;
function Queue(e){this._queue=e?e.slice():[],this._tail=this._queue.length,this._head=0,this._maxLength=100000}Queue.prototype.enqueue=function(e){this._tail+1===this._head||0===this._head&&this._tail===this._maxLength-1?console.error("===queue overflow==="):(this._queue[this._tail]=e,this._tail+=1,this._tail===this._maxLength&&(this._tail=0))},Queue.prototype.dequeue=function(){if(this._tail!==this._head){var e=this._queue[this._head];return this._head+=1,this._head===this._maxLength&&(this._head=0),e}console.error("===queue underflow===")},Queue.prototype.size=function(){var e=this._tail-this._head;return e<0&&(e+=this._maxLength),e};

function main(input) {
  var o = new I(input);

  var n = o.a();
  var m = o.a();

  var x = [], y = [], z = [];
  for (var i = 0; i < m; i++) {
    x.push(o.a());
    y.push(o.a());
    z.push(o.a());
  }

  var adj = [];
  for (var i = 1; i <= n; i++) {
    adj[i] = [];
  }

  for (var i = 0; i < m; i++) {
    adj[x[i]].push(y[i]);
    adj[y[i]].push(x[i]);
  }
  
  var count = 0;
  var color = [];
  for (var i = 1; i <= n; i++) {
    if (color[i] === undefined) {
      color[i] = 1;
      bfs(i, color, adj);
      count += 1;
    }
  }
  console.log(count);
}

function bfs(i, color, adj) {
  var queue = new Queue();
  queue.enqueue(i);
  while (queue.size() > 0) {
    var cur = queue.dequeue();
    adj[cur].forEach(v => {
      if (color[v] === undefined) {
        color[v] = 1;
        queue.enqueue(v);
      }
    })
  }
}


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


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

ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll bunsi(ll a,ll b){
  ll cz=1,dz=1;
  if(a<0){
    cz=-1;
    a*=-1;
  }
  if(b<0){
    dz=-1;
    b*=-1;
  }
  return (a/gcd(a,b))*cz;
}
ll bunbo(ll a,ll b){
  ll cy=1,dy=1;
  if(a<0){
    cy=-1;
    a*=-1;
  }
  if(b<0){
    dy=-1;
    b*=-1;
  }
  return (b/gcd(a,b))*dy;
}
ll mpower(ll a,ll b,ll c){
  int z;
  if(b==0){
    z=1;
    z%=c;
    return z;
  }
  if(b==1){
    z=a;
    z%=c;
    return z;
  }
  else{
    return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
  }
}

int main() {
  ll mod=1e9+7;
  ll ans=1;
  int n;
  cin>>n;
  pair<ll,ll> vec[n];
  ll a,b;
  map<pair<ll,ll>,ll> ma;
  map<ll,ll> mab;
  map<pair<ll,ll>,int> seen;
  ll k=0;
  for(int i=0;i<n;i++){
    cin>>a>>b;
    if(a==0&&b==0){
      vec[i]={0,0};
      k++;
      continue;
    }
    if(a==0){
      vec[i]={0,0};
      mab[1]++;
      continue;
    }
    if(b==0){
      vec[i]={0,0};
      mab[2]++;
      continue;
    }
    if(a<0&&b<0){
      a*=-1;
      b*=-1;
    }
    if(a<0&&b>0){
      a*=-1;
      b*=-1;
    }
    vec[i].first=bunsi(a,b);
    vec[i].second=bunbo(a,b);
    ma[vec[i]]++;
  }
  ll q;
  pair<ll,ll> t;
  for(int i=0;i<n;i++){
    q=0;
    if(vec[i].first==0&&vec[i].second==0)continue;
    if(seen[vec[i]]!=0)continue;
    t.first=vec[i].second;
    t.second=(vec[i].first)*-1;
    if(t.first<0&&t.second<0){
      t.first*=-1;
      t.second*=-1;
    }
    q+=mpower(2,ma[vec[i]],mod);
    q%=mod;
    q+=mpower(2,ma[t],mod);
    q--;
    while(q<0){
      q+=mod;
    }
    q%=mod;
    ans*=q;
    ans%=mod;
    ma[vec[i]]=0;
    ma[t]=0;
    seen[vec[i]]++;
    seen[t]++;
  }
  q=0;
  q+=mpower(2,mab[1],mod);
  q%=mod;
  q+=mpower(2,mab[2],mod);
  q%=mod;
  q--;
  while(q<0){
    q+=mod;
  }
  ans*=q;
  ans%=mod;
  if(k>0){
    ans+=k;
  }
  ans%=mod;
  ans--;
  while(ans<0){
    ans+=1e9+7;
  }
  ans%=mod;
  cout<<ans<<endl;
}

Measured memory_bytes: 56568