akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        int i,j,k,n,b,f,r,v;
        int build[][][]=new int[4][3][10];
        for(i=0;i<4;i++){
        	for(j=0;j<3;j++){
        		for(k=0;k<10;k++){
        			build[i][j][k]=0;
        		}
        	}
        }
        n=scan.nextInt();
        for(i=0;i<n;i++){
        	b=scan.nextInt()-1;
        	f=scan.nextInt()-1;
        	r=scan.nextInt()-1;
        	v=scan.nextInt();
        	build[b][f][r]+=v;
        }
        for(i=0;i<4;i++){
        	for(j=0;j<3;j++){
        		for(k=0;k<10;k++){
        			if(k==9){
        				System.out.println(" "+ build[i][j][k]);
        			}
        			else{
        				System.out.print(" " + build[i][j][k]);
        			}
        		}
        	}
        	if(i!=3){
        		System.out.println("####################");
        	}
        }
    }
}



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

#define IOS {ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
#define ll long long 

ll powermod(ll x,ll ex,ll md){ll ans=1ll;while(ex>0){if(ex&1ll) ans=(ans*x)%md; ex>>=1ll;x=(x*x)%md;}return ans;}
inline ll gcd(ll a,ll b) {if(b==0)return a;a%=b;return gcd(b,a);}
inline ll max(ll a,ll b) {return((a>b)?a:b);}
inline ll min(ll a,ll b) {return((a>b)?b:a);}

ll ans=0,mod=1e9+7;

int main(){
        IOS;
        ll n;
        cin>>n;
        vector<ll> dp(n+11,0);
        dp[0]=1;
        for(ll i=3;i<=n;i++){
                for(ll j=3;j<=i;j++){
                        dp[i]+=dp[i-j];
                }
                dp[i]%=mod;
        }
        cout<<dp[n]<<"\n";
}


Measured memory_bytes: 3644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			bool flg = false;
			while (true)
			{
				int n = int.Parse(Console.ReadLine());
				if (n == 0)
					break;

				if (flg)
					Console.WriteLine();
				else
					flg = true;

				var t = new Dictionary<string, int>();

				while (n-- != 0)
				{
					string[] l = Console.ReadLine().Split(' ');
					t.Add(l[0], int.Parse(l[1]) * 3 + int.Parse(l[3]));
				}
				var tt = new List<KeyValuePair<string, int>>(t);
				BubbleSort(tt);

				for (int i = 0; i < tt.Count; i++)
				{
					Console.WriteLine(tt[i].Key + "," + tt[i].Value);
				}
			}
		}

		private static void BubbleSort(List<KeyValuePair<string, int>> a)
		{
			int n = a.Count;
			for (int i = 0; i < n - 1; i++)
			{
				for (int j = n - 1; j > i; j--)
				{
					if (a[j].Value.CompareTo(a[j - 1].Value) > 0)
					{
						var temp = a[j];
						a[j] = a[j - 1];
						a[j - 1] = temp;
					}
				}
			}
		}
	}
}

Measured memory_bytes: 5764
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

map<P,bool> m;
int dx[] = {0,0,1,1,1,0,-1,-1,-1};
int dy[] = {0,1,1,0,-1,-1,-1,0,1};
int main() {
  ll h,w,n;
  cin >> h >> w >> n;
  auto f = [&](int x,int y){
    if(x<=1||h<=x||y<=1||w<=y) return -1;
    int res = 0;
    rep(i,9) if(m[P(x+dx[i],y+dy[i])]) ++res;
    return res;
  };
  vector<ll> ans(10);
  ans[0] = (h-2)*(w-2);
  rep(_,n){
    int a,b;
    cin >> a >> b;
    rep(i,9){
      int x = f(a+dx[i],b+dy[i]);
      if(x!=-1) --ans[x], ++ans[x+1];
    }
    m[P(a,b)] = true;
  }
  rep(i,10) cout << ans[i] << endl;
}

Measured memory_bytes: 159844
#include <iostream>
#include <vector>
#define MAX_N 50
using namespace std;
typedef vector<vector<int> > mat;
int M;

mat mul(mat &A, mat &B) {
	mat C(A.size(), vector<int>(B[0].size()));

	for (int i = 0; i < A.size(); ++i) {
		for (int k = 0; k < B.size(); ++k) {
			for (int j = 0; j < B[0].size(); ++j) {
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
			}
		}
	}
	return C;
}

mat pow(mat A, long long int n) {
	mat B(A.size(), vector<int>(A.size()));
	for (int i = 0; i < A.size(); ++i) B[i][i] = 1;

	while (n > 0) {
		if (n & 1) B = mul(B, A);
		A = mul(A, A);
		n >>= 1;
	}
	return B;
}

int main() {
	int N, A, B, C;
	long long int T;

	while (cin >> N >> M >> A >> B >> C >> T, !(N == 0 && M == 0 && A == 0 && B == 0 && C == 0 && T == 0)) {
		mat S(MAX_N, vector<int>(1));
		mat CM(MAX_N, vector<int>(MAX_N));

		for (int i = 0; i < N; ++i) cin >> S[i][0];

		for (int i = 0; i < N; ++i) {
			for (int j = 0; j < N; ++j) {
				if (i == j + 1) CM[i][j] = A;
				else if (i == j) CM[i][j] = B;
				else if (i == j - 1) CM[i][j] = C;
			}
		}

		CM = pow(CM, T);
		S = mul(CM, S);

		cout << S[0][0] % M;
		for (int i = 1; i < N; ++i) cout << " " << S[i][0] % M;
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<cassert>
#include<cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;

const ll MOD = INF + 7;



int main(){
    int n;
    cin >> n;
    Graph G(n);
    rep(i, n - 1){
        int a, b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    VEC(int, c, n);
    sort(ALL(c), greater<int>());

    queue<int>que;
    que.push(0);

    vector<int>r(n, -1);
    int now = 0;
    while(!que.empty()){
        int v = que.front();
        r[v] = c[now];
        now++;
        que.pop();

        for(int nv : G[v]){
            if(r[nv] != -1)continue;
            que.push(nv);
        }
    }

    reverse(ALL(c));
    int sum = 0;
    rep(i, n - 1)sum += c[i];
    cout << sum << endl;
    rep(i, n)cout << r[i] << " ";
}

Measured memory_bytes: 1144
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define sigma_size 30
#define max_size (int)(1e6+10)


LL minx = 1ll << 60;
int main ()
{
	ios::sync_with_stdio(0);
	LL N;
	cin >> N;
	for ( LL i = 1 ; i*i <= N ; i++ )
		if ( N % i == 0 )
			minx = min ( minx , N/i + i - 2 );
	cout << minx << endl;

}

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e9;

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

int main() {
  ll n, X;
  cin >> n >> X;
  vector<ll> x(n);
  rep(i, n) cin >> x[i], x[i] -= X;

  ll g = abs(x[0]);
  for (int i = 0; i < n; ++i) g = gcd(g, abs(x[i]));
  cout << g << endl;
  return 0;
}


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

int main()
{
    int s1, s2, s3, s;
    cin >> s;
    s1 = s / 100;
    s2 = (s - s1 * 100) / 10;
    s3 = (s - s1 * 100 - s2 * 10);
    cout << s1 + s2 + s3 << endl;
}


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



int main() {
    int n;
    cin >> n;
    priority_queue<double, vector<double>, greater<double>> v;
    rep(i,n) {
        double a;
        cin >> a;
        v.push(a);
    }
    rep(i,n-1) {
        double x = v.top(); v.pop();
        double y = v.top(); v.pop();
        v.push((x+y)/2);
    }
    double ans = v.top();
    printf("%.10f\n", ans);
    return 0;
}

Measured memory_bytes: 3832
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var nq=arr[0].split(" ").map(Number);
var s = arr[1];
var a=[0,0];
var cnt=0;
for(var i=1;i<s.length;i++){
   if(s[i]=="C" && s[i-1]=="A")cnt++;
   a.push(cnt);
}
var ans=[];
for(var i=2;i<nq[1]+2;i++){
   var lr=arr[i].split(" ");
   ans.push(a[lr[1]-0]-a[lr[0]-0]+"\n");
}
console.log(ans.join("").trim());

Measured memory_bytes: 47944
import java.util.*;

public class Main{
    public static void main(String args[]){
        
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        List<Work> list = new ArrayList<>();
        for(int i = 0; i < N; i++){
            list.add(new Work(sc.nextLong(), sc.nextLong()));
        }
        long totalWork = 0;
        boolean flg = true;
        list.sort(Comparator.comparingLong(Work::getB));
        for(int i = 0; i < list.size(); i++){
            totalWork += list.get(i).getA();
            if(totalWork > list.get(i).getB()){
                flg = false;
                break;
            }
        }
        System.out.println(flg ? "Yes" : "No");
        
    }
    
    public static class Work{
        private long A;
        private long B;
        public Work(long A, long B){
            this.A = A;
            this.B = B;
        }
        public long getA(){
            return A;
        }
        public long getB(){
            return B;
        }
    }
}


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

class Solve
{
	const int mod = 1000000007;
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		int[] s = new int[N];
		long ans = 0;
        for(int i = 0; i < N; i++)
		{
			s[i] = int.Parse(Console.ReadLine());
			ans += s[i];
		}
		if (ans % 10 == 0)
		{
			long ansc = ans;
			Array.Sort(s);
            for(int i = 0; i < N; i++)
			{
				if (s[i] % 10 != 0)
				{
					ans -= s[i];
					break;
				}
				
			}
			if (ans == ansc) { ans = 0; }
			
		}
		Console.WriteLine(ans);
        
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
#define invrep(i,n) for(int64_t i=n-1;i >= 0;i--)
#define _GLIBCXX_DEBUG
using namespace std;

int main(){
  string s;
  cin >> s;
  if(s[2]==s[3] && s[4]==s[5]){
  	cout << "Yes"<< endl;
  }else{
    cout << "No" << endl;
  }
}

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

int main() {

	int n; cin >> n;

	for (int i = 0; i < 100; i++) {
		for (int j = 0; j < 100; j++) {
			if (4 * i + 7 * j == n) {
				cout << "Yes" << endl;
				return 0;
			}
		}
	}

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

Measured memory_bytes: 256
import math
n, m = map(int, input().split())
res = 1
max_res = m//n
for i in range(1, math.ceil(math.sqrt(m)) + 1):
  if m % i == 0:
     if i <= max_res:
        res = max(res, i)
     x = m//i
     if x <= max_res:
        res = max(res, x)
print(res)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <string>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <map>
#include <bitset>
#include <cmath>
#include <set>
#include <utility>

#define INF 1000000000000
#define MOD 1000000007 //10^9+7:合同式の法

using namespace std;
typedef long long ll;

//マクロ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)


int main(){
    int N;
    cin >> N;
    vector<int>A(N);
    for(int i = 0;i < N;i++)
        cin >> A.at(i);

    sort(A.begin(),A.end());

    cout << A.at(N-1) - A.at(0) << endl;

}

Measured memory_bytes: 3548
#include<bits/stdc++.h>
#include<string>
#include<iostream>
#define ll long long int
#define ld long double
using namespace std;
int len=0;
string lcs(string s1,string s2)
{
	int n1=s1.length();
	int n2=s2.length();

	int a[n1+1][n2+1];
	memset(a,0,sizeof(a));
	for(int i=0;i<=n1;i++)
	{
		for(int j=0;j<=n2;j++)
		{
			if(i==0 || j==0)
			{
				a[i][j]=0;
			}
			else{
				if(s1[i-1]==s2[j-1])
				{
					a[i][j]=1+a[i-1][j-1];
				}
				else{
					a[i][j]=max(a[i-1][j],a[i][j-1]);
				}
			}

		}
	}
	//cout<<a[n1][n2];
	char ans[a[n1][n2]];
	int index=a[n1][n2];
	len=index;
	if(a[n1][n2]==0) return "";
	int i=n1,j=n2;
	while(i>0 && j>0)
	{

			if(s1[i-1]==s2[j-1])
			{
				ans[index-1]=s1[i-1];
				i--;j--;index--;
			}
			else if(a[i-1][j]>=a[i][j-1])
			{
				i--;
			}
			else if(a[i-1][j]<a[i][j-1])
			{
				j--;
			}
		
	}
	return ans;
}
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
   	string ans=lcs(s1,s2);
   	if(ans!="")
   	{
   		cout<<ans.substr(0,len);
   	}	
   	else cout<<"";
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010];
    cin >> N;
    rep(i,0,N) cin >> A[i];
    ll sum = 0;
    rep(i,0,N) sum += abs(A[i]);
    ll cnt = 0;
    rep(i,0,N){
        if(A[i] < 0) cnt++;
    }
    if(cnt % 2 == 0){
        print(sum);
        return 0;
    }
    ll tt = INF;
    rep(i,0,N){
        tt = min(tt, abs(A[i]));
    }
    print(sum - 2*tt);

}

Measured memory_bytes: 1024
n = int(input())
can = []
for i in range(n):
  now = input()
  for j in range(len(can)):
    if now == can[j][0]:
      can[j][1] += 1
      break
  else:
    can.append([now,1])
m = int(input())
for i in range(m):
  now = input()
  for j in range(len(can)):
    if now == can[j][0]:
      can[j][1] -= 1
      break
maxi = 0
for j in range(len(can)):
  if can[j][1] > maxi:
    maxi = can[j][1]
print(maxi)

Measured memory_bytes: 3064
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
using namespace std;
using ll=long long;
using ld=long double;
//#define int long long
#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for (int i = 0; i < n; i++)
#define _GLIBCXX_DEBUG
#define ALL(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7;
const int INF = 1e18 + 9;
constexpr long double pi = 3.141592653589793238462643383279;
int fact(int i) {
    if (i == 0) return 1;
    return (fact(i - 1)) * i;
}
int gcd(int a, int b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
int lcm(int a, int b) {
    return a * b / gcd(a, b);
}
int keta(int n) {
    if (n == 0) return 1;
    int count = 0;
    while (n != 0) {
        n /= 10;
        count++;
    }
    return count;
}
int ketasum(int n) {
    int sum = 0;
    while (n != 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
char toSmall(char c) { // 大文字を小文字へ
    return (c + 0x20);
}
char toLarge(char c) { // 小文字を大文字へ
    return (c - 0x20);
}
float myPower(int a, int n) { // aのn乗の計算
    float x = 1;
    while (n > 0) { // 全てのbitが捨てられるまで
        if (n & 1) { // 一番右のbitが１のとき
            x *= a;
        }
        a *= a;
        n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
    }
    return x;
}
bool is_prime(const unsigned n) {
    switch (n) {
    case 0: // fall-through
    case 1: return false;
    case 2: // fall-through
    case 3: return true;
    } // n > 3 が保証された

    if (n % 2 == 0 || n % 3 == 0) return false;
    // n は 2 と 3 のいずれの倍数でもないことが保証された
    // これより n は (6の倍数)-1 か (6の倍数)+1 である
    // 6の倍数前後の数を使って試し割りをする
    for (unsigned i = 5; i * i <= n; i += 6) {
        if (n % i == 0) return false; // (6の倍数)-1
        if (n % (i + 2) == 0) return false; // (6の倍数)+1
    }

    return true;
}
string a, b;
int i, c;
int main(void){
    cin >> a >> b;
    c = stoi(a + b);
    while (true) {
        if (i * i == c) {
            cout << "Yes" << endl;
            return 0;
        }
        if (i * i >= c) {
            cout << "No" << endl;
            return 0;
        }
      ++i;
    }
    return 0;
}


Measured memory_bytes: 3620
n, k = map(int, input().split())
s = input()
l=list()
s = s.replace("10","1,0")
s = s.replace("01","0,1")

l = [len(i) for i in s.split(",")]
r = 0
ans = 0

if s[0] == "1":
    r = min(k, len(l) - 1)
else:
    r = min(k-1, len(l) - 1)

t = l[r]

for j in range(1, k+1):
    #print(r,j,t,l[r-j],l[r+j])
    if r-j >= 0:
        #print("r-j >= 0:")
        t += l[r-j]
    if r+j < len(l):
        #print("r+j < len(l):")
        t += l[r+j]
ans = t
for i in range(r+2, len(l) ,2):
    for j in range(1, 3):
        if i-j-k >= 0:
            #print("l[i-j-k]", i-j-k, l[i-j-k])
            t -= l[i-j-k]
        if i+j+k-2 < len(l):
            #print("l[i+k+j]", i+j+k-2, l[i+j+k-2])
            t += l[i+j+k-2]
    ans = max(ans, t)
print(ans)

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

using namespace std;

int main(){
  string a,b,c;
  cin >> a >> b >> c;
  char A,B,C;
  A = toupper(a[0]);
  B = toupper(b[0]);
  C = toupper(c[0]);
  cout << A << B << C << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <math.h>
#include <map>
#include <unordered_map>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define pb(s) push_back(s)
#define ci(x) cin >>x
#define co(x) cout<<x<<endl
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

long long fac(ll a) {
 long long ans=1;
 while(a>1){
 ans*=a;
 ans%=1000000007;
     a--;
    }
    return ans;
     }
int main() {
  string S;
  cin >>S;
  
  ll nor=0;
  ll sou=0;
  ll eas=0;
  ll wes=0;
  rep(i,S.size()) {
    if(S.at(i)=='N') {
      nor=1;
    }
    if(S.at(i)=='S') {
      sou=1;
    }
    if(S.at(i)=='E') {
      eas=1;
    }
    if(S.at(i)=='W') {
      wes=1;
    }
  }

 if((nor==0) &&(sou!=0))    {
cout<<"No"<<endl;
   return 0;
 }
  
   if((nor!=0) &&(sou==0))    {
cout<<"No"<<endl;
   return 0;
 }
   if((eas==0) &&(wes!=0))    {
cout<<"No"<<endl;
   return 0;
 }
   if((eas!=0) &&(wes==0))    {
cout<<"No"<<endl;
   return 0;
 }
  else {
    cout<<"Yes"<<endl;
    return 0;
  }
  
  
}
  
  

Measured memory_bytes: 256
package main

import "fmt"

import "sort"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	a2 := make([]int, n)

	for i := 0; i < n; i++ {
		fmt.Scan(&a[i])
	}
	copy(a2, a)
	sort.Ints(a2)

	for _, i := range a {
		if i != a2[n-1] {
			fmt.Println(a2[n-1])
		} else {
			fmt.Println(a2[n-2])
		}
	}
}


Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;
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 a,b,c;cin>>a>>b>>c;
	int ans = 0;

	while(a % 2 == 0 && b % 2 == 0 && c % 2 == 0){
		int a2 = a;
		int b2 = b;
		int c2 = c;
		vector<int> v = {a2,b2,c2};
		a = (b2/2 + c2/2 );
		b = (a2/2 + c2/2 );
		c = (b2/2 + a2/2 );
		vector<int> v2 = {a,b,c};
		sort(ALL(v));
		sort(ALL(v2));
		ans ++;
		for(int i = 0; i < 3; i++) {
			if (v[i] != v2[i])break;
			if (i == 2){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    vector<string> v(3);
    rep(i,3) cin >> v[i];
    printf("%c%c%c",v[0][0],v[1][1],v[2][2]);
}

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

int main() {
  int A, B;
  cin >> A >> B;
  
  int x = B * 2 + 1;
  
  if(A % x == 0){
    cout << A / x << endl;
  }
  
  else{
    cout << A / x + 1 << endl;
  }
  
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
#define N 100000+10

using namespace std;

typedef long long ll;

int main()
{
    int a[N];
    int n,Max,x;
    map<int,int>mp;
    int k=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>x;
        if(mp[x]==0)
            a[k++]=x;
        mp[x]++;
    }
    sort(a,a+k);
    int ans=1;
    for(int i=0;i<k;i++)
    {
        Max=mp[a[i]];
        for(int j=i+1;j<k;j++)
        {
            if(a[j]-a[i]<=2)
                Max+=mp[a[j]];
            else break;
        }
        ans=max(ans,Max);
    }
    ans=max(ans,Max);
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

struct event {
    ll t;
    ll type;
    ll pos;
};

void solve() {
    ll N, Q;
    cin >> N >> Q;
    vector<event> events;
    rep(i, N) {
        ll s, t, x;
        cin >> s >> t >> x;
        events.push_back(event{s - x, 0, x});
        events.push_back(event{t - x, 1, x});
    }
    auto f = [](event a, event b) {
        if (a.t == b.t) return a.pos < a.pos;
        return a.t < b.t;
    };
    sort(events.begin(), events.end(), f);
    multiset<ll> used;
    ll m = events.size();
    ll idx = 0;
    rep(i, Q) {
        ll d;
        cin >> d;
        while (idx < m && events[idx].t <= d) {
            event e = events[idx];
            if (e.type) {
                used.erase(used.lower_bound(e.pos));
            } else {
                used.insert(e.pos);
            }
            idx++;
        }
        if (used.empty()) {
            cout << -1 << '\n';
        } else {
            cout << *used.begin() << '\n';
        }
    }

}

int main() {
    cin.tie(nullptr);
    // ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 20712
#include <iostream>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

#define INF 1e9
#define MAXN 200005
#define MAXM 100005
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll N, A[MAXN], ans;
map<int, ll> mp;

void solve(){

    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
        ans += itr->second*(itr->second - 1)/2;
    }

    rep(i, N){
            cout << ans - (mp[A[i]]-1)<< endl;
    }

}

int main(){
    cin >> N;

    rep(i, N){
        cin >> A[i];
        mp[A[i]]++;
    }

    solve();
}


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

int main() {
  int a,b;
  cin >> a >> b;
  
  if(a*b%2 == 0) {
    cout << "No" << endl;
  }
  else if(a*b%2 == 1) {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int s = sc.nextInt();

        int a[] = new int[1000001];
        Set<Integer> set = new HashSet<>();
        set.add(s);
        a[1] = s;
        for (int i = 2 ; i < 1000001 ; i++) {
            if (a[i-1] % 2 == 0) {
                a[i] = a[i - 1]/2;
                if (set.contains(a[i])) {
                    System.out.println(i);
                    return;
                } else {
                    set.add(a[i]);
                }
            } else {
                a[i] = 3 * a[i-1] + 1;
                if (set.contains(a[i])) {
                    System.out.println(i);
                    return;
                } else {
                    set.add(a[i]);
                }
            }
        }


    }

}


Measured memory_bytes: 25812
N = int(input())
A = [int(i) for i in input().split()]

result = []
res = A[1]
for a in A[2:N]:
    res ^= a
result.append(str(res))

for i in range(0, N-1):
    res = A[i] ^ A[i+1] ^ res
    result.append(str(res))

print(" ".join(result))

Measured memory_bytes: 102636
#include<bits/stdc++.h>
using namespace std;
#define PI          acos(-1)
#define INF         100000000
#define sc(n)       scanf("%d",&n);
#define ssc(n)      scanf("%s",n);
#define lsc(n)      scanf("%lld",&n);
#define dsc(n)      scanf("%lf",&n);
#define csc(n)       scanf("%c",&n);
#define LL          long long int
#define UI          unsigned int
#define ULL         unsigned long long int
#define DB          double
#define pii         pair<int,int>
#define VI          vector<int>
#define MII         map<int,int>
#define PB          push_back
#define MP          make_pair
#define M(mx,a)     mx=max(mx,a)
#define IT          ::iterator
#define all(a)      a.begin(),a.end()
#define mems(a,b)   memset(a,b,sizeof(a))
#define F(i,a,b)    for(i=a;i<b;i++)
#define IN(n,aa)    for(i=0;i<n;i++)scanf("%d",&aa[i]);
#define PNT(n,aa)   for(i=0;i<n;i++)printf("%lld ",aa[i]);
#define mod         1000000007
#define NUM         10000009
#define NUM2        1000000000


int main()
{
    int T=1,QQ=0;
    //cin >> T ;
    while(T--)
    {
        int n,i,j,cnt=0;
        cin >> n;
        string ss;
        cin >> ss;
        for(i=1;i<n;i++)if(ss[i]!=ss[i-1])cnt++;
        cout << cnt+1 ;
    }
}

//printf("Case %d: ",++QQ);


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

int main()
{
    long long int n, k, i, sum=0;
    cin >> n >> k;
    long long int a[n];
    for(i=0; i<n; i++)
    {
        cin >> a[i];
    }
    if(k==0)
    {
        for(i=0; i<n; i++)
        {
            sum=sum+a[i];
        }
        cout << sum << endl;
    }
    else if(k>=n) cout << 0 << endl;
    else
    {
        sort(a, a+n);

        for(i=0; i<n-k; i++)
        {
            sum=sum+a[i];
        }
        cout << sum << endl;
    }

    return 0;
}


Measured memory_bytes: 1792
func :: String -> [String] -> Int
func s days | days == ["SUN"] = 0
            | s == head days = 1 + func (head (tail days)) (tail days)
            | otherwise = 0 + func s (tail days)
         
main :: IO()
main = do
  s <- getLine
  putStrLn $ show (func s a)
  where a = ["SUN","MON","TUE","WED","THU","FRI","SAT","SUN"]

Measured memory_bytes: 380
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int a,b,c,x,y;
    cin>>a>>b>>c>>x>>y;

    int res = 0;

    if(a >= 2 * c) {
        res += 2 * c * x;
        y = max(0, y - x);
        x = 0;
    }

    if(b >= 2 * c) {
        res += 2 * c * y;
        x = max(0, x - y);
        y = 0;
    }

    if(a + b >= 2 * c) {
        int z = min(x, y);
        res += 2 * c * z;
        x = max(0, x - z);
        y = max(0, y - z);
    }

    if(x > 0) {
        res += a * x;
        x = 0;
    }

    if(y > 0) {
        res += b * y;
        y = 0;
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int n,a[100];
    int i,b[20][10]={0};
    char c[100];
    scanf("%d",&n);
    for (i=0;i<n;i++){
        scanf("%*c%c %d",&c[i],&a[i]);
        if (c[i]=='S'){
            b[a[i]][1]=1;
        }else if(c[i]=='H'){
            b[a[i]][2]=1;
        }else if(c[i]=='C'){
            b[a[i]][3]=1;
        }else if(c[i]=='D'){
            b[a[i]][4]=1;
        }
    }
    
    for(i=1;i<=13;i++){
        if(b[i][1]==0){
            printf("S %d\n",i);
        }
    }
    for(i=1;i<=13;i++){
        if(b[i][2]==0){
            printf("H %d\n",i);
        }
    }
    for(i=1;i<=13;i++){
        if(b[i][3]==0){
            printf("C %d\n",i);
        }
    }
    for(i=1;i<=13;i++){
        if(b[i][4]==0){
            printf("D %d\n",i);
        }
    }    
    
    return 0;
}  



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

bool isp(string s)
{
	for (int i = 0, j = s.length() - 1; i < j; i++, j--) if (s[i] != s[j]) return false;
	return true;
}

int main()
{
	string s;
	cin >> s;

	bool p = isp(s);
	bool q = isp(s.substr(s.length() / 2 + 1));
	if (p && q) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3124
use List::Util qw(max min);
my ($N ,$M, $X) = split(/ /, <STDIN>);
my @A = split(/ /, <STDIN>);
my $n = 0;
foreach my $i (0..$X) {
        if ( grep {$_ ==  $i} @A ) {
                $n++;
        }
}
my $m = 0;
foreach my $i ($X..$N) {
        if ( grep {$_ ==  $i} @A ) {
                $m++;
        }
}
print min($n, $m);

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

using namespace std;

int pow10(int n) {
	int res = 1;
	for (int i = 0; i < n; ++i) {
		res *= 10;
	}
	return res;
}

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

	string s_N = to_string(N);
	int N_size = s_N.size();

	int res = 0;
	for (int i = 1; i <= N_size; ++i) {
		if (i % 2 == 0) continue;
		if (i == N_size) {
			res += N - pow10(i - 1) + 1;
			break;
		}
		res += 9 * pow10(i - 1);
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int
const int INF = 1001001001001001LL;
const int MOD = 1000000007;

int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

signed main(){
    
    string S; cin >> S;
    int n = (int)S.size();
    vector<vector<int> > dp(n + 1, vector<int> (2, 0));
    dp[0][0] = 1;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 2; j++){
            int nj;
            if(j == 1){
                nj = 1;
                dp[i + 1][nj] += dp[i][j] * 3;
                dp[i + 1][nj] %= MOD;   
            }else{
                if(S[i] == '0'){
                    nj = 0;
                    dp[i + 1][nj] += dp[i][j];
                    dp[i + 1][nj] %= MOD;
                }else{
                    nj = 0;
                    dp[i + 1][nj] += dp[i][j] * 2;
                    dp[i + 1][nj] %= MOD;
                    nj = 1;
                    dp[i + 1][nj] += dp[i][j];
                    dp[i + 1][nj] %= MOD;
                }
            }
        }
    }

    cout << (dp[n][0] + dp[n][1]) % MOD << endl;
    return 0;
}


Measured memory_bytes: 5760
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <numeric>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))

bool ok(string x)
{
    static const string str = "ACGT";
    bool ret = true;
    for (auto s : x)
    {
        bool found = false;
        rep (i, str.size())
        {
            if (s == str[i]) found = true;
        }
        ret &= found;
    }
    return ret;
}

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

    string s;
    cin >> s;

    for (int i = s.size(); i > 0; --i)
    {
        rep (j, s.size() - i + 1)
        {
            if (ok(s.substr(j, i)))
            {
                cout << i << "\n";
                return 0;
            }
        }
    }

    cout << "0\n";
    return 0;
}



Measured memory_bytes: 3668
local n, m = io.read("*n", "*n")
local t = {}
for i = 1, n do
  t[i] = -1
end
local valid = true
for i = 1, m do
  local s, c = io.read("*n", "*n")
  if s == 1 and c == 0 and 1 < n then
    valid = false
  end
  if 0 <= t[s] and t[s] ~= c then
    valid = false
  end
  t[s] = c
end
if not valid then
  print(-1)
else
  for i = 1, n do
    if t[i] == -1 then
      if i == 1 and n ~= 1 then io.write(1)
      else io.write(0)
      end
    else
      io.write(t[i])
    end
  end
  io.write("\n")
end


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

int main(){
  int N;
  int a;
  cin >> N;
  if(N < 105){
    a = 0; 
  }else if(105 <= N && N < 135){
    a = 1;
  }else if(135 <= N && N < 165){
    a = 2;
  }else if(165 <= N && N < 189){
    a = 3;
  }else if(189 <= N && N < 195){
    a = 4;
  }else if(195 <= N && N < 201){
    a = 5;
  }
  cout << a << '\n';
}

Measured memory_bytes: 256
N, Q = map(int, input().split())
S = input()
cnt_array = [0] * (N+1)
ans = [0] * Q
for i in range(N):
    if i != N-1 and S[i] == 'A' and S[i+1] == 'C':
        cnt_array[i+1] = 1 + cnt_array[i]
    else:
        cnt_array[i+1] = cnt_array[i]
for i in range(Q):
    l, r = map(int, input().split())
    ans[i] = cnt_array[r-1] - cnt_array[l-1]
for i in ans:
    print(i)

Measured memory_bytes: 10300
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  rep(i, 1000) {
    bool f1 = 0, f2 = 0, f3 = 0;
    rep(j, n) {
      if (!f1) {
        if (s[j]-'0' == i/100)
          f1 = 1;
      }
      else if (!f2) {
        if (s[j]-'0' == i/10%10)
          f2 = 1;
      } else {
        if (s[j]-'0' == i%10) {
          f3 = 1;
          break;
        }
      }
    }
    if (f1 && f2 && f3)
      ans++;
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;
typedef long long ll;

int n, k;
int a[111];
int dp[111][100100];
int md = 1e9+7;
void addMd(int &a, int b)
{
    if (b < 0) b += md;
    if (b >= md) b -= md;
    a += b;
    if (a >= md) a -= md;
}
int main()
{
    scanf("%d%d", &n, &k);
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]);
    for (int i = 0; i < n; ++i)
    {
        if (!i)
        {
            for (int j = 0; j <= a[i]; ++j)
                dp[i][j] = 1 + (j ? dp[i][j-1] : 0);
            for (int j = a[i]+1; j <= k; ++j)
                dp[i][j] = dp[i][j-1];
            continue;
        }
        for (int j = 0; j <= k; ++j)
        {
            int lft = max(0, j-a[i]);
            addMd(dp[i][j], dp[i-1][j] - (lft == 0? 0 : dp[i-1][lft-1]));
        }
        for (int j = 1; j <= k; ++j)
            addMd(dp[i][j], dp[i][j-1]);
    }
    addMd(dp[n-1][k], -(k ? dp[n-1][k-1] : 0));
    printf("%d\n", dp[n-1][k]);

    return 0;
}


Measured memory_bytes: 41216
import sys
import math
from collections import Counter


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = input()

S = Counter(s)
a = S["a"]
b = S["b"]
c = S["c"]

if abs(a-b) <= 1 and abs(a-c) <= 1 and abs(c-b) <= 1:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 73616
while True:

    #strings1 = []
    #strings2 = []

    k1 = []
    g1 = []
    k2 = []
    g2 = []
    check=input()
    if check == ".":
        break
    strings1 = list(map(str, check.split('"')))

    strings2 = list(map(str, input().split('"')))

    nagasa1 = len(strings1)
    nagasa2 = len(strings2)

    for i in range(nagasa1):
        if i % 2 == 0:
            g1.append(strings1[i])
        else:
            k1.append(strings1[i])

    for i in range(nagasa2):
        if i % 2 == 0:
            g2.append(strings2[i])
        else:
            k2.append(strings2[i])

    lengthk1 = len(k1)
    lengthg1 = len(g1)
    lengthk2 = len(k2)
    lengthg2 = len(g2)

    points = 0

    if lengthg1 == lengthg2:
        for i in range(lengthg1):
            if g1[i] == g2[i]:
                pass
            else:
                points += 2
    else:
        points += 2

    if lengthk1 == lengthk2:
        for i in range(lengthk1):
            if k1[i] == k2[i]:
                pass
            else:
                points += 1
    else:
        if lengthk1 - lengthk2 == 1 or lengthk1 - lengthk2 == -1:
            if lengthk1 < lengthk2:
                for i in range(lengthk1):
                    if k1[i] == k2[i]:
                        pass
                    else:
                        points += 1
            else:
                for i in range(lengthk2):
                    if k1[i] == k2[i]:
                        pass
                    else:
                        points += 1
        else:
            points += 2

    if points==0:
        print("IDENTICAL")
    elif points==1:
        print("CLOSE")
    else:
        print("DIFFERENT")





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

#define rep(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define repn(i, m, n) for (int (i) = (m) ; (i) < (int)(n) ; ++(i))
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define repn_rev(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= (m) ; --(i))

#define INF 2e9
#define ll long long
#define MOD 1e9+7
#define MAX_V 20005

/* 辺を表す構造体 */
struct edge {int to, cap ,rev; };

/* グラフの隣接リスト表現 */
vector<edge> G[MAX_V];
/* DFSですべに調べたかのグラフ */
bool used[MAX_V];

/* fromからtoへ向かう容量capの辺をグラフに追加する */
void add_edge(int from, int to, int cap){
    G[from].push_back((edge){to, cap, (int)G[to].size()});
    G[to].push_back((edge){from, 0, (int)G[from].size()-1});    
}


/* 増加パスをdfsで探す */
int dfs(int v, int t, int f){
    if(v==t) return f;
    used[v] = true;
    for(int i=0; i<G[v].size(); i++){
        edge &e = G[v][i];
        if(!used[e.to] && e.cap>0){
            int d = dfs(e.to, t, min(f, e.cap));
            if(d>0){
                e.cap -= d;
                G[e.to][e.rev].cap += d;
                return d;
            }
        }
    }
    return 0;
}

int max_flow(int s, int t){
    int flow = 0;
    for(;;){
        memset(used, 0, sizeof(used));
        int f = dfs(s, t, INF);
        if(f==0) return flow;
        flow += f;
    }
}

int main(){
    int h, w, s_x, s_y, t_x, t_y;
    cin>>h>>w;
    char a[h][w];

    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            cin>>a[i][j];
            if(a[i][j] == 'S'){
                add_edge(0, i+1, INF);
                add_edge(0, h+j+1, INF);
                s_x = j, s_y = i;
            }
            else if(a[i][j] == 'T'){
                add_edge(i+1, w+h+1, INF);
                add_edge(h+j+1, w+h+1, INF);
                t_x = j, t_y = i;
            }
            else if(a[i][j] == 'o'){
                add_edge(i+1, h+j+1, 1);
                add_edge(h+j+1, i+1, 1);
            }
        }
    }

    if(s_x == t_x){
        cout<<"-1"<<endl;
        return 0;
    }
    if(s_y == t_y){
        cout<<"-1"<<endl;
        return 0;
    }

    cout<<max_flow(0, w+h+1)<<endl;
    
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  int l=S.size(), i, x=1, y, z;
  vector<int> r(l,0);
  
  for(i=0; i<l-1; i++) {
    if(S.at(i)=='R' && S.at(i+1)=='L') {
      y=i;
      z=x;
      x++;
    } else if(S.at(i)=='L' && S.at(i+1)=='R') {
      if(x%2==0) {
        r.at(y) = x/2;
        r.at(y+1) = x/2;
      } else {
        if(z%2==0) {
          r.at(y) = x/2;
          r.at(y+1) = x/2+1;
        } else {
          r.at(y) = x/2+1;
          r.at(y+1) = x/2;
        }
      }
      x=1;
      y=0;
    } else
      x++;
  }
  
  if(x%2!=0)
  	if(z%2==0) {
    	r.at(y) = x/2;
    	r.at(y+1) = x/2+1;
  	} else {
    	r.at(y) = x/2+1;
    	r.at(y+1) = x/2;
  	}
  else {
    r.at(y) = x/2;
    r.at(y+1) = x/2;
  }
  
  for(i=0; i<l; i++)
    cout << r.at(i) << " ";
  cout << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    
    if (N < 105) cout << 0 << endl;
    else if (N < 135) cout << 1 << endl;
    else if (N < 165) cout << 2 << endl;
    else if (N < 189) cout << 3 << endl;
    else if (N < 195) cout << 4 << endl;
    else cout << 5 << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {
    resolve(System.in, System.out);
  }

  static void resolve(InputStream is, PrintStream pw) {
    Scanner sc = new Scanner(is);
    long a = Long.parseLong(sc.next());
    long b = Long.parseLong(sc.next());
    long n = Long.parseLong(sc.next());
    if (b == 1) {
      pw.println(0);
      return;
    }
    long maxX = Math.min(b - 1, n);
    double ad = (double) a;
    double bd = (double) b;
    pw.println(calc(ad, bd, maxX));
  }

  static long calc(double ad, double bd, long x) {
    return (long) Math.floor(ad * x / bd) - (long) ad * (long) Math.floor(x / bd);
  }
}


Measured memory_bytes: 35788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  ll dist = 1e10 ;
  ll N ;
  ll mid = 0 ;
  ll ans = 0 ;
  cin >> N ;
  vector<ll> A(N) ;
  rep(i,N) cin >> A.at(i) ;
  sort(A.begin(),A.end()) ;
  if( A.at(N-1)%2 == 0 ){
    mid = A.at(N-1)/2 ;
    rep(i,N-1){
      if( abs( A.at(i) - mid ) <= dist ){
        dist = abs( A.at(i) - mid ) ;
        ans = A.at(i) ;
      }
    }
  }
  else{
    mid = A.at(N-1)/2 ;
    ll mid2 = A.at(N-1)/2 + 1 ;
    rep(i,N-1){
      if( abs( A.at(i) - mid ) <= dist ){
        dist = abs( A.at(i) - mid ) ;
        ans = A.at(i) ;
      }
      if( abs( A.at(i) - mid2 ) <= dist ){
        dist = abs( A.at(i) - mid2 ) ;
        ans = A.at(i) ;
      }
    }
  }
  cout << A.at(N-1) << ' ' <<  ans << endl;    
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

typedef long long ll;

using namespace std;

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    int countA = 0;
    int countB = 0;
    for (char c : s) {
        if (c == 'a') {
            if (countA + countB < a + b) {
                cout << "Yes"
                     << "\n";
                countA++;
            } else {
                cout << "No"
                     << "\n";
            }
        }

        if (c == 'b') {
            if (countA + countB < a + b && countB < b) {
                cout << "Yes"
                     << "\n";
                countB++;
            } else {
                cout << "No"
                     << "\n";
            }
        }
        if (c == 'c') {
            cout << "No"
                 << "\n";
        }
    }
    return 0;
}

Measured memory_bytes: 896
import bisect
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans_list=[0]*(N-1)
ans_list[0]=A[0]
count=0
ind=1
for i in range(1,len(ans_list)):
    if count==2:
        count=0
        ind+=1
    ans_list[i]=A[ind]
    count+=1
print(sum(ans_list))



Measured memory_bytes: 31452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int INF = 1000000;

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

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

  vector<int> dp(n, -1);
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      dp[i] = 0;
      continue;
    }

    int acc1 = INF;
    if (i - 1 >= 0) {
      acc1 = abs(h[i] - h[i - 1]);
      acc1 += dp[i - 1];
    }

    int acc2 = INF;
    if (i - 2 >= 0) {
      acc2 = abs(h[i] - h[i - 2]);
      acc2 += dp[i - 2];
    }

    dp[i] = min(acc1, acc2);
  }

  cout << dp.back() << endl;

  return 0;
}


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

int main(){
	string s;
	cin>> s;

	if(s.size() < 4){
		cout<<"No"<<endl;
	}
	else{
		if(s[0] == 'Y' && s[1] == 'A' && s[2] == 'K' && s[3] == 'I'){
			cout<<"Yes"<<endl;
		}
		else{
			cout<<"No"<<endl;
		}
	}
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

	private void execute() {
		Scanner sc = new Scanner(System.in);
		final String s = sc.next();
		final int N = s.length();

		final char BLACK = 'B';
		final char WHITE = 'W';
		int wth = 0;
		long ops = 0;
		for (int i = 0; i < N; i++) {
			if (s.charAt(i) == WHITE) {
				ops += i - wth;
				wth++;
			}
		}
		
		System.out.println(ops);
		sc.close();
	}
}


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

int main()
{
    int n, m;
  cin >> n >> m;
  int sum = 0, x;
  for (int i = 0; i < m; i++) {
    cin >> x;
    sum += x;
  }
  if (sum > n)
    cout << "-1\n";
  else
    cout << n - sum <<  "\n";
return 0;
}

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

class Program
{
    public Program()
    {
        switch(Console.ReadLine())
        {
            case "1":
                Console.WriteLine("Hello World");
                break;
            case "2":
                Console.WriteLine(int.Parse(Console.ReadLine()) +
                    int.Parse(Console.ReadLine()));
                break;
        }

    }
    static void Main(string[] args)
    {
        var p = new Program();
    }
}


Measured memory_bytes: 11092