akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "win" << endl;
    } else {
        cout << "bust" << endl;
    }   
}

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    bool res = ((a + b + c) <= 21);
    print_ans(res);
    return 0;
}


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

int main() {
char a;
  cin >> a;
  if(a == 'A' || a == 'B' || a == 'C' || a == 'D' || a == 'E' || a == 'F' || a == 'G' || a == 'H' || a == 'I' || a == 'J' || a == 'K' || a == 'L' || a == 'M' || a == 'N' || a == 'O' || a == 'P' || a == 'Q' || a == 'R' || a == 'S' || a == 'T' || a == 'U' || a == 'V' || a == 'W' || a == 'X' || a == 'Y' || a == 'Z'){
     cout << 'A' << endl;
     }
     else cout << 'a' << endl;   


}

Measured memory_bytes: 3616
// /usr/local/bin/g++ Main.cpp -std=c++14
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int H, W, K, C[30*30];

ll calc(int idx) {
	int _c[30*30];
	set<int> d; // deleted blocks
	for (int k = 0; k < 30*30; k++) {
		_c[k] = C[k];
	}
	d.insert(idx);
	int cnt = 0;
	ll res = 0;

	// Continue until there is no deleted block.
	while (d.size()) {
		// Move blocks when block is deleted.
		for (int l : d) {
			int _h = l/W;
			int _w = l%W;
			for (int i = _h; i > 0; i--) {
				_c[i*W+_w] = _c[(i-1)*W+_w];
			}
			_c[_w] = 0;
		}
		d.clear();

		// Calculate scores
		for (int i = 1; i < H; i++) {
			for (int j = 0; j < W - K + 1; j++) {
				bool judge = true;
				for (int k = 1; k < K; k++) {
					judge = (judge && _c[i*W+j] != 0 && _c[i*W+j] == _c[i*W+j+k]);
				}
				if (!judge) continue;
				for (int k = 0; k < K; k++) {
					d.insert(i*W+j+k);
				}
			}
		}

		// Add score
		if (d.size()) {
			int _res = 0;
			for (int l : d) {
				_res += _c[l];
			}
			for (int i = 0; i < cnt; i++) {
				_res *= 2;
			}
			res += _res;
		}
		cnt++;
	}

	return res;
}

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

	// Dummy input
//	ifstream in("input.txt");
//	cin.rdbuf(in.rdbuf());

	// Read input
	cin >> H >> W >> K;
	for (int i = 0; i < H; i++) {
		string s;
		cin >> s;
		int j = 0;
		for (char& c : s) {
			C[i*W+(j++)] = (int)(c - '0');
		}
	}

	ll res = 0;
	for (int i = 1; i < H; i++) {
		for (int j = 0; j < W; j++) {
			ll _res = calc(i*W+j);
			if (res < _res) res = _res;
		}
	}
	cout << res << endl;
}

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

using namespace std;

int arr[100];

int main()
{
  int n;
  cin >> n;
  for(int i=1;i<=n;i++)cin >> arr[i];
  int pos1=0,pos2=0;
  for(int i=1;i<n;i++)
  {
    if(arr[i]>arr[i+1])
    {
      if(!pos1)pos1=i;
      else if(!pos2)pos2=i+1;
      else 
      {
        cout << "NO";
        return 0;
      }
    }
  }
  swap(arr[pos1],arr[pos2]);
  for(int i=1;i<n;i++)
  {
    if(arr[i]>arr[i+1])
    {
      cout << "NO";
      return 0;
    }
  }
  cout << "YES";
}


Measured memory_bytes: 256
#include <cstdio>

using namespace std;

int main(){
  int n;
  scanf("%d", &n);
  int aa,aaa;
  int sum = 0;
  for(int i = 0; i < n; i++){
    scanf("%d%d", &aa, &aaa);
    sum += aaa - aa + 1;
  }
  printf("%d", sum);
  return 0;
}

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

bool isLeapYear(int y);
int main(){
  int a,b;
  vector<int> A,B;
  while(1){
    cin>>a>>b;
    if(a<0||b<0||a>b||a>3000||b>3000)
      return 1;
    if(a==0&&b==0)
      break;
    A.push_back(a),B.push_back(b);

  }
  for( int i=0;i<A.size();i++ ){
    int leapnum=0;
    for( int j=A[i];j<=B[i];j++ ){
      if(isLeapYear(j)){
	leapnum++;
	cout<<j<<endl;
      }
    }
    if(!leapnum){
      cout<<"NA"<<endl;
    }
    if( i!=A.size()-1 )cout<<endl;
  }
  return 0;
}

bool isLeapYear(int y){
  if(!(y%4)&&(y%100))
    return true;
  if( !(y%400) )
    return true;
  return false;
}

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

int main() {
  int N, K, X = 1;
  cin >> N >> K;
  
  rep(i,N){
    if(X < K){
      X *= 2;
    }
    else{
      X += K;
    }
  }
    
    cout << X << endl;
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;

struct student {
	int id;
	double weight;
	double height;
	char ch;
};

int main() {
	
	student a;
	while(cin >> a.id >> a.ch >> a.weight >> a.ch >> a.height) {
	
	if( a.weight / a.height / a.height >= 25.0)
		cout << a.id << "\n";
}
	return 0;
}


Measured memory_bytes: 3040
from collections import deque

def main():
    S = deque(list(input()))
    stack = deque([0])
    ans = 0
    while len(S) != 0:
        tmp = ""
        while len(S) != 0:
            before = stack.pop()
            tmp += S.popleft()
            if before != tmp:
                stack.append(tmp)
                ans += 1
                break
            else:
                stack.append(before)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 63344
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) {
    
    int num;
    try ( BufferedReader br =
        new BufferedReader(new InputStreamReader(System.in)) ) {
      num = Integer.parseInt( br.readLine() );

      System.out.println( num * num * num );
    } catch( IOException e) {
      System.out.println("IOException!");
    }
  }
}


Measured memory_bytes: 24216
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<iomanip>
#include<math.h>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 1e9
#define MOD 1000000007
#define LINF (long long)4e18

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N; cin >> N;
    vector<int> A(N);
    vector<int> nums(100010);
    rep(i,N){
        cin >> A[i];
        nums[A[i]]++;
    }
    int cnt = 0;
    int num = 0;
    rep(i,100010){
        if(nums[i] > 1){
            cnt = abs(cnt-nums[i]+1);
        }
        if(nums[i] > 0) num++;
    }
    int ans = 0;
    if(cnt % 2 == 0) ans = num;
    else ans = num-1;
    cout << ans << endl;

}


Measured memory_bytes: 1024
#include <stdio.h>
int main() {
  int r,c,counter;
  scanf("%d %d", &r, &c);
  int arr[r + 1][c + 1] = {{0}};
  for (int i = 0; i < r; i++) {
    counter = 0;
    for (int j = 0; j < c; j++) {
      scanf("%d", &arr[i][j]);
      counter += arr[i][j];
    }
    arr[i][c] = counter;
  }
  for (int k = 0; k <= r; k++) {
    for (int l = 0; l <= c; l++) {
      printf("%d", arr[k][l]);
      if (l < c) printf(" ");
      if (k < r) arr[r][l] += arr[k][l];
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2684
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Diagnostics;

class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }

    Scanner cin;


    void calc()
    {
        cin = new Scanner();
        long n=cin.nextLong();
        long[] abcde=new long[5];
        long ans=0;
        for(int i=0;i<5;i++)
        {
          abcde[i]=long.Parse(Console.ReadLine());
        } 
      Array.Sort(abcde);//(N + ABCDE.Min() - 1) / ABCDE.Min()+4
      Console.WriteLine((n+abcde.Min()-1)/abcde.Min()+4);
    }
}



class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 13396
N,Y=map(int,input().split())
for i in range(N+1):
    for j in range(N-i+1):
        if 10000*i+5000*j+1000*(N-i-j)==Y:
            print(i,j,(N-i-j))
            exit()
else:
    print("-1 -1 -1")


Measured memory_bytes: 2940
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var map = {};
	var submap = new Set();
	var sameSet = new Set();
	for(var i = 0; i < N; i++){
		if(submap.has(list[i])){
			sameSet.add(list[i]);
			continue;
		}
		submap.add(list[i]);
		if(map[list[i]] == null){
			map[list[i]] = getDivisorList(list[i]);
		}
	}
	var output = 0;
	for(var i = 0; i < N; i++){
		if(sameSet.has(list[i])){
			continue;
		}
		var getDiv = map[list[i]];
		var isOK = true;
		for(var j = 0; j < getDiv.length; j++){
			if(getDiv[j] != list[i] && submap.has(getDiv[j])){
				isOK = false;
				break;
			}
		}
		if(isOK){
			output++;
		}
	}
	myout(output);
}
function getDivisorList(val){
  var list = [];
  for(var i = 1; i * i <= val; i++){
    if(val % i == 0){
      list.push(i);
      if(i * i != val){
        list.push(val / i);
      }
    }
  }
  //list.sort(function(a,b){ return a - b; });
  return list;
}


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

const ll MOD = 1e9 + 7;

struct mint {
    ll x;  // cout << ans.x << endl; で出力する
    mint(ll x = 0) : x((x % MOD + MOD) % MOD) {
    }
    mint operator-() const {
        return mint(-x);
    }
    mint &operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((x += MOD - a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime MOD
    mint inv() const {
        return pow(MOD - 2);
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    mint t   = 2;
    mint ans = t.pow(n).x;
    mint now = 1;
    mint ma, mb = 0;
    for (int i = 1; i <= b; i++) {
        now = now * (n - i + 1);
        now /= i;
        if (i == a) ma = now;
        if (i == b) mb = now;
    }
    ans = ans - ma - mb - 1;
    cout << ans.x << endl;
}

Measured memory_bytes: 256
def tool_gate(now: int, gate_list: list) -> int:
    back_count = sum(i < now for i in gate_list)
    forward_count = sum(i > now for i in gate_list)
    return min(back_count, forward_count)


if __name__ == "__main__":
    n, m, now = map(int, input().split())
    gate_list = list(map(int, input().split()))
    print(tool_gate(now, gate_list))


Measured memory_bytes: 9052
#include<bits/stdc++.h>
using namespace std;
 
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cout << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
#define int long long int
#define fi first
#define se second
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define pow10(n) stoll("1"+string(n,'0'))
//fill(all(arr),1)
//if(map.count(key)){}
//bitset<20>(n);
//int mini=min({a,b,c,d,e});
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef long double ld;

int32_t main(){
	FIO
	int n,m,x,y;
	cin>>n>>m;
	int a[n];
	forn(i,n)cin>>a[i];
	int cnt=0;
	int high[n];
	forn(i,n)high[i]=1;
	//forn(i,n)cout<<high[i]<<endl;
	forn(i,m)
	{
		cin>>x>>y;
		//cout<<a[x-1]<<a[y-1]<<endl;
		if(a[x-1]<=a[y-1]){high[x-1]=high[x-1]*0;}
		if(a[y-1]<=a[x-1])high[y-1]*=0;
	}
	forn(i,n)
	{
		if(high[i]==1){cnt++;}
	}
	cout<<cnt;
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    map<char, int> mp;
    rep(i, 4) mp[s.at(i)]++;
    bool flag = true;
    for(pair<char, int> p : mp) if(p.second != 2) flag = false;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x1,x2,x3,x4,x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0)
    cout<<"1"<<endl;
  else if(x2==0)
    cout<<"2"<<endl;
  else if(x3==0)
    cout<<"3"<<endl;
  else if(x4==0)
    cout<<"4"<<endl;
  else
    cout<<"5"<<endl;
}
  
  
  

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

int main(){
    string s;cin>>s;char z;int a=0;
    vector<int> l(26);
    for(int i=0;i<s.size();i++) l.at(s.at(i)-'a')++;
    for(int i=0;i<26;i++){
        if(l.at(i)==0){
            z='a'+i;
            break;
        }
        else if(l.at(i)!=0) a++;
    }
    if(a!=26) cout<<z<<endl;
    else cout<<"None"<<endl;
}

Measured memory_bytes: 512
#include <math.h>
#include <ctype.h>
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, n) for (int i = a; i < n; i++)
#define REP(i, n) for(int i = 0; i < n; i++)
struct omt{omt(){ios::sync_with_stdio(false);cin.tie(0);}}star;

int main(){
    int n, w;
    cin >> n >> w;
    int V[n], W[n];
    REP(i, n) cin >> V[i] >> W[i];

    int dp[n + 1][w + 1];
    for(int i = 0; i <= w; i++) dp[0][i] = 0;
    

    for(int i = 0; i < n; i++){
        for(int j = 0; j <= w; j++){
            if(j >= W[i]) dp[i + 1][j] = max(dp[i][j - W[i]] + V[i], dp[i][j]);
            else dp[i + 1][j] = dp[i][j];
        }
    }
    cout << dp[n][w] << endl;
    


    return 0;
}


Measured memory_bytes: 7136
#include <bits/stdc++.h>
#include <random>
//-------------------------------------------------------------------------
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define prv(v) for (auto i : v) { cout << i << " ";}
#define prmat(v) for (auto i : v) { prv(i); cout << "\n";}
#define cout(x) cout << fixed << setprecision(x)
#define read(v) for (int i_ = 0; i_ < v.size(); i_++) { cin >> v[i_];}
#define fast_io ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define all(v) (v.begin()), (v.end())
#define rall(v) (v.rbegin()), (v.rend())
#define pii pair<ll, ll>
//------------------------------------------------------------------------
int main(){
    fast_io;
#ifdef LOCALKA
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    string s;
    cin >> s;
    ll cnt = 0;
    ll ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'B'){
            cnt++;
        }
        else{
            ans += cnt;
        }
    }
    cout << ans;
}


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

int main(){
    int n; cin >> n;
    for(int i = 0; i < 21; i++){
        for(int j = 0; j < 15; j++){
            if(n == 4 * i + 7 * j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
int main(){
    int y,m,d,x;
    while(std::cin>>y>>m>>d){
        x=y*10000+m*100+d;
        if(x<18680908)printf("pre-meiji\n");
        else if(x<19120730)printf("meiji %d %d %d\n",y-1867,m,d);
        else if(x<19261225)printf("taisho %d %d %d\n",y-1911,m,d);
        else if(x<19890108)printf("showa %d %d %d\n",y-1925,m,d);
        else printf("heisei %d %d %d\n",y-1988,m,d);
    }
}

Measured memory_bytes: 3052
def numba_compile(numba_config):
    import os, sys
    if sys.argv[-1] == "ONLINE_JUDGE":
        from numba import njit
        from numba.pycc import CC
        cc = CC("my_module")
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature)(func)
            cc.export(func.__name__, signature)(func)
        cc.compile()
        exit()
    elif os.name == "posix":
        exec(f"from my_module import {','.join(func.__name__ for func, _ in numba_config)}")
        for func, _ in numba_config:
            globals()[func.__name__] = vars()[func.__name__]
    else:
        from numba import njit
        for func, signature in numba_config:
            globals()[func.__name__] = njit(signature, cache=True)(func)
        print("compiled!", file=sys.stderr)

import sys
import numpy as np

def z_algo(S):  # [z_algo, "i8[:](i8[:])"],
    # Z-algoirhm  O(n)
    # Z[i] := S と S[i:] で prefix が何文字一致しているか
    # 検証: https://atcoder.jp/contests/abc150/submissions/15829530
    i, j, n = 1, 0, len(S)
    Z = np.zeros(S.shape, dtype=np.int64)
    Z[0] = n
    while i < n:
        while i+j < n and S[j] == S[i+j]:
            j += 1
        if j == 0:
            i += 1
            continue
        Z[i] = j
        d = 1
        while i+d < n and d+Z[d] < j:
            Z[i+d] = Z[d]
            d += 1
        i += d
        j -= d
    return Z

def solve(N, S):
    ans = 0
    for i in range(N):
        Z = z_algo(S[i:])
        for idx_Z, z in enumerate(Z):
            an = min(z, idx_Z)
            ans = max(ans, an)
    return ans

numba_compile([
    [z_algo, "i8[:](u1[:])"],
    [solve, "i8(i8,u1[:])"]
])

def main():
    N = int(sys.stdin.buffer.readline())
    S = np.frombuffer(sys.stdin.buffer.readline(), dtype=np.uint8).copy()
    ans = solve(N, S)
    print(ans)

main()


Measured memory_bytes: 27220
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = Integer.parseInt(in.next());
            int h = Integer.parseInt(in.next());
            int w = Integer.parseInt(in.next());
            int a[] = new int[n];
            int b[] = new int[n];
            int ans = 0;
            for (int i = 0; i < n; i++) {
                a[i] = Integer.parseInt(in.next());
                b[i] = Integer.parseInt(in.next());
                if (a[i] >= h && b[i] >= w) ans++;
            }
            out.println(ans);

        }

    }
}



Measured memory_bytes: 23124
a,b = map(int,input().split())
if a*12.5 >= (b+1) *10 or b*10 >= (a+1)*12.5:
  print(-1)
else:
  m = max([a*12.5,b*10])
  M = min([(b+1) *10, (a+1)*12.5])
  i = m//1
  if m == i:
    print(int(i))
  else:
    print(int(i+1))
    

Measured memory_bytes: 9156
N, M = [int(str) for str in input().strip().split()]
A = [int(str) for str in input().strip().split()]

ssum = 0
B = {}
for i in range(N):
    ssum += A[i]
    key = ssum % M
    B[key] = B.get(key, 0) + 1

print(B.get(0, 0) + sum([i * (i - 1) for i in B.values()]) // 2)

Measured memory_bytes: 14424
# -*- coding: utf-8 -*-
from itertools import product
import numpy as np
def inpl():return list(map(int,input().split()))
N,M=inpl()
A,a=np.zeros((N,3),dtype=np.int64),0
for i in range(N):A[i]=np.array(inpl())
for X in product([1,-1],repeat=3):a=max(a,abs(sum(sorted((A*np.array(X)).sum(axis=1))[:M])))
print(a)

Measured memory_bytes: 21272
n = int(input())
bn_1 = [int(i) for i in input().split()]
an_sum = bn_1[0]
for i in range(1, n - 1):
    an_sum += min(bn_1[i - 1], bn_1[i])
an_sum += bn_1[n - 2]
print(an_sum)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
 
int main() {
  double A, B, H, M;
  cin >> A >> B >> H >> M;
  double x;
  const double pi = 3.141592653589793;
  
  double thetaA = M_PI * (H + M / 60) / 6;
  double thetaB = 2 * M_PI * M / 60;
  
  double theta = thetaB - thetaA;
  
  if (theta > M_PI) {
    theta = 2 * M_PI - theta;
  }
  
  x = sqrt(A*A + B*B - 2 * A * B * cos(theta));
  cout << fixed << setprecision(20) << x << endl;
}

Measured memory_bytes: 4212
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, h[100100], cost[100200]={0}, k, i;
    cin >> n >> k;
    for(i=0;i<n;i++){
        cin >> h[i];
    }

    for(i=1;i<n;i++){
        cost[i]=cost[i-1]+abs(h[i-1]-h[i]);
        for(int j=2;j<=k;j++){
            if(i-j<0) break;
            cost[i]=min(cost[i], cost[i-j]+abs(h[i-j]-h[i]));
        }
    }

    cout << cost[n-1] <<endl;
    return 0;
}


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

int main() {
    int sum1 = 0, sum2 = 0;
    for(int i=0; i<4; ++i) {
        int a; cin >> a;
        sum1 += a;
    }
    for(int i=0; i<4; ++i) {
        int a; cin >> a;
        sum2 += a;
    }
    cout << max(sum1, sum2) << endl;
}


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

int main() {
  int N;
  int ans = 1;
  string S;
  cin >> N >> S;
  for (int i=0; i < N - 1; i++) {
    if (S.at(i) != S.at(i+1)) {
      ans++;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 512
n=int(input())
h=list(map(int,input().split()))

now = h[0]
cnt_tmp = 0
cnt_max = 0

for i in range(1,n):
    if now > h[i]:
        cnt_tmp+=1
        now = h[i]
    elif now == h[i]:
        cnt_tmp+=1
    #高くなった場合
    else:
        cnt_max=max(cnt_tmp,cnt_max)
        cnt_tmp=0
        now = h[i]

#最後の分
cnt_max=max(cnt_tmp,cnt_max)

print(cnt_max)
            
        

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

int main() {
  int n,m;
  cin >> n >> m;
  vector<int> h(n);
  vector<bool> H(n,true);

  int count = 0;
  for(int i = 0; i < n; i++){
    cin >> h[i];
  }
  pair<int,int> p[m-1];
  for(int i = 0; i < m; i++){
    cin >> p[i].first >> p[i].second;
  }
  
  for(int i = 0; i < m; i++){
    if(h[p[i].first-1]>h[p[i].second-1]){
      H[p[i].second-1] = false;
    }
    else if(h[p[i].first-1]<h[p[i].second-1]){
      H[p[i].first-1] = false;
    }
    else{
      H[p[i].second-1] = false;
    H[p[i].first-1] = false;
    }
  }
  for(int i = 0; i < n; i++){
    if(H[i]){
      count++;
    }
  }
cout << count << endl;
}
 

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

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

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

    return arr

import fractions as fs

def main():
  a, b = map(int, input().split())
  arr = factorization(fs.gcd(a, b))
  if arr[0][0] == 1:
    print(len(arr))
  else:
    print(len(arr) + 1)

if __name__ == "__main__":
  main()


Measured memory_bytes: 5048
n, m = gets.split.map(&:to_i)

par = Array.new(n+1) {[0, []]}
chi = Array.new(n+1) {[]}
(n-1+m).times do
    a, b = gets.split.map(&:to_i)
    chi[a] << b
    par[b][0] += 1
    par[b][1] << a
end

que = [par.rindex{|e| e[0] == 0}]
t = Array.new(n+1)
rt = []
i = -1
while now = que.shift
    t[now] = i += 1
    rt << now
    chi[now].each {|x| (par[x][0] -= 1).zero? and que << x}
end

1.upto(n) {|i| p rt[0] == i ? 0 : rt[par[i][1].map{|e| t[e]}.max]}

Measured memory_bytes: 40312
#include <bits/stdc++.h>
#define read(FILE)  freopen(FILE, "r", stdin);
#define out(FILE) freopen(FILE, "w", stdout);
#define all(x) x.begin(),x.end()
#define clr(v,val) memset(v,val,sizeof(v))
#define rep(i,m,n) for(int i=m ; i<n ; i++)
#define forr(i,m,n) for(int i=m ; i<=n ; i++)
#define endl '\n'
#define pb push_back
#define pff push_front
#define re return
#define cmod(x,y) cout<<x%y;
#define bit __builtin_popcountll
#define pii pair<int, int>
#define vi vector<int>
#define vll vector<ll>
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const int N = 1e5 + 5;
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
int freq[N] = {},a[N];
int main()
{
	IO;
	int n, k, q; cin >> n >> k >> q;
	forr(i, 1, n) {
		a[i] = k;
	}
	rep(i, 0, q) {
		int x; cin >> x;
		freq[x]++;
	}
	forr(i, 1, n) {
		if (freq[i] == 0) {
			a[i] -= q;
		}
		else
		{
			a[i] -= (q - freq[i]);
		}
	}

	forr(i, 1, n) {
		if (a[i] <= 0) {
			cout << "No" << endl;
		}
		else
		{
			cout << "Yes" << endl;
		}
	}
	
	
}

Measured memory_bytes: 1408
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;
 
 int main()
 {
   int travel;
   while(cin>>travel&&travel)
   {
     int sum=0;
     int sign;
     bool flag=false;
     for(int i=0;i<12;i++)
     {
       int a,b;
       cin>>a>>b;
       sum+=(a-b);
       if((sum>=travel)&&(!flag)) 
       {
         flag=true;
         sign=i+1;          
       }        
     }            
     if(flag) cout<<sign<<endl;
     else cout<<"NA"<<endl;                
   }
   //while(1);
   return 0;
 }

 

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b;
    if(a<b){
        for(int i=0;i<b;i++)
            cout<<a;
    }
    else if(a>=b){
        for(int i=0;i<a;i++)
            cout<<b;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <cstdio>
#include <ctime>
#include <assert.h>
#include <chrono>
#include <random>
#include <numeric>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	ll a,b,d;
	while(cin >> a >> b >> d,a){
		int g=__gcd(__gcd(a,b),d);
		a/=g; b/=g; d/=g;
		pair<ll,ll> res;
		res=make_pair(1e9,1e9);
		ll sum=res.first+res.second;
		ll ans=res.first*a+res.second*b;
		for(ll x=0;x<=50000;x++){
			if(sum<=x)break;

			if((a*x-d)%b==0){ 
				ll y=abs((a*x-d)/b);
				if((sum>x+y)||(sum==x+y&&ans>x*a+b*y)){
					sum=x+y;
					res=make_pair(x,y);
					ans=res.first*a+res.second*b;
				}
			}
			if((a*x+d)%b==0){
				ll y=abs((a*x+d)/b);
				if((sum>x+y)||(sum==x+y&&ans>x*a+b*y)){
					sum=x+y;
					res=make_pair(x,y);
					ans=res.first*a+res.second*b;
				}
			}
		}
		printf("%lld %lld\n",res.first,res.second);
	}
}


Measured memory_bytes: 3156
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  let sum = 0;

  for (let i = 1; i <= N; i++) {
    if (i % 3 !== 0 && i % 5 !== 0) {
      sum += i;
    }
  }

  return sum;
};

console.log(main(read()));


Measured memory_bytes: 35196
#
#　　　　　　　　　　　　　　,. -─────────‐- .、
#　　　　　　　　　　　　 ／／￣￣＼　　　　　　／￣￣＼＼
#　　　　　　　　　　　／　　　　　　　　　　　　　　　　　　　　 ＼
#　　　　　　　　　 ／　　　　　　　　::::::::::::::::::::::::::::::::　　　　　　　＼
#　　　　　　　　／ 　　／ ／￣＼＼::::;;;;;;;;;;;;;;;;;:::::／／￣＼＼　　＼
#　　　　　　 ／　　　　|　 |.　┃　.|　| ::::;;;;;;;;;;;;;::::｜ |.　┃　.|　|　　　 ＼　　　　　　　　　　　　　　　　　　　　　
#　　　　　／ 　　　　　＼ ＼＿／／　::::::::::::::::::　＼＼＿／／　　　　　 ＼　　　　
#　　　 ／　　　　　..／￣￣＼　／　　　::｜::　　　＼　／￣￣＼..　　　　　＼
#　　 / 　 　 　 　 :::::　　　　　　|　　　　　 |　　　　　 |　　　　　　 :::::　　　　　 ヽ.　　　
#　　| 　　　　　　　　　　　　　　|　　　　　 |　　　　　 |　　　　　　　　　　　　　　|.
#　　| 　　　　　　　　　　　　　　＼＿＿／＼＿＿／ 　　　　　　　　　　　　　　|　　　　　　　　　　　　　　　　　
#　　| 　　　　　　　　　　　　　　　｜　　　　　　　｜　　　　　　　　　　　　　　　|
#　　| 　　　　　　　　　　　　　　　｜r─‐┬──､|　　　　　　　　　　　　　　　 |
#　　ヽ　　　　　　　　　　　　　　　 |/　　　|　　 　｜　　　　　　　　　　　　　　/
#　　　 ＼　　　　　　　　　　　　　 ＼　　　　　　／　　　　　　　　　　　　　／
#　　　　　＼ 　　　　　　　　　　　　　￣￣￣￣　　　　　　　　　　　　　／
#
#
import sys
input=sys.stdin.readline
inf=float('inf')
mod = 10**9+7
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [input() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S = ST()
    x, y = MI()
    to_x_y = [[], []]
    deleted = False
    for i,s in enumerate(S):
        if s == "T":
            S = S[i:]
            deleted = True
            break
        else:
            x -= 1
    if not deleted:
        S=""
    toY = False
    contin = False
    #run length 
    for i, s in enumerate(S):
        if s == "F":
            if contin:
                to_x_y[toY][-1] += 1
            else:
                to_x_y[toY].append(1)
                contin = True
        else:
            toY = not toY
            contin = False

    #print((x,y),*to_x_y,sep="\n")

    #xについてdp
    now_x = set([0])
    for distanse in to_x_y[0]:    
        next_x = set()
        for i, X in enumerate(now_x):
            next_x.add(X + distanse)
            next_x.add(X - distanse)
        now_x = next_x
    
    #yについてdp
    now_y = set([0])
    for distanse in to_x_y[1]:    
        next_y = set()
        for i, Y in enumerate(now_y):
            next_y.add(Y + distanse)
            next_y.add(Y - distanse)
        now_y = next_y

    #print(now_x,now_y)
    print("YNeos"[x not in now_x or y not in now_y::2] )


if __name__ == '__main__':
    main()

Measured memory_bytes: 47708
import sys

input = sys.stdin.readline


def main():
    N, K = map(int, input().split())

    ans = 0
    for b in range(K + 1, N + 1):
        q, r = divmod(N, b)
        ans += (b - K) * q
        ans += max(0, min(b - 1, r) - max(1, K) + 1)

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 9040
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define debug(x) cout << #x << " = " << (x) << endl;
#define SUM(x) accumulate(rng(x),0)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = 1<<30;
const ll INFLL = 1LL<<60;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

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 () {
  int n, m;
  cin >> n >> m;

  int ans = 1;
  for (int a = 1; a*a <= m; ++a) {
    if (m%a != 0) continue;
    int b = m/a;
    if ((ll)a*n <= m) ans = max(ans, a);
    if ((ll)b*n <= m) ans = max(ans, b);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

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; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int a, b, c, k;
  cin >> a >> b >> c >> k;

  int r = 0;
  while (b <= a) {
    b = b * 2;
    r++;
  }
  while (c <= b) {
    c = c * 2;
    r++;
  }

  cout << (r <= k ? "Yes" : "No");
}
#endif


Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val N = nextInt()
    val A = listOfInt()
    val M = LongArray(N + 1)
    A.forEach { M[it] += 1L }
    fun c2(x: Long) = x * (x - 1) / 2
    var total = M.sumByLong { c2(it) }
    val ans = LongArray(N)
    A.forEachIndexed { index, a ->
        ans[index] = total - c2(M[a]) + c2(M[a] - 1)
    }
    println(ans.joinToString("\n"))
}
inline fun LongArray.sumByLong(selector: (Long) -> Long): Long {
    var sum = 0L
    for (element in this) sum += selector(element)
    return sum
}
 
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun nextInt(offset: Int = 0) = nextInt() + offset
fun nextLong() = java.lang.Long.parseLong(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }

Measured memory_bytes: 98180
#include <bits/stdc++.h>
 using namespace std;
 int main() 
{
  ios_base::sync_with_stdio(0);
   cin.tie(NULL);
   
   int n;
   cin>>n;
   int arr[n];
   for(int i=0;i<n;i++)
     cin>>arr[i];
     
    long long sum=arr[0];
    for(int i=1;i<n;i++)
     {  if(i%2==0)
         sum=sum+arr[i];
         else
          sum=sum-arr[i];
     }
    
     
     vector<int> v;
     v.push_back(sum);
     
     for(int i=0;i<n-1;i++)
      {
          v.push_back(arr[i]*2-sum);
         sum=arr[i]*2-sum;
      }
     for(auto i:v)
       cout<<i<<" ";
   return 0;
}
 
 

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

int main() {

	int N;
	cin >> N;
	vector<int> a(N);
	REP(i, N) cin >> a[i];

	int ans = 5000000;
	for(int x = -100; x <= 100; x++) { // xにそろえる
		int cost = 0;
		for(int y : a) {
			cost += (x-y)*(x-y);
		}
		ans = min(ans, cost);
	}

	cout << ans << endl;
}

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

const int M = 1e9+7;

vector<vector<int>>dp;

void solve(){
	int n;
	cin>>n;
	dp.assign(n+2,vector<int>(4,0));
	dp[0][0] = 1;

	for(int i=1;i<=n;++i){
		dp[i][3] = ((dp[i-1][1]+dp[i-1][2])%M+10*dp[i-1][3]%M)%M;
		dp[i][2] = (dp[i-1][0] + 9*dp[i-1][2]%M)%M;
		dp[i][1] = (dp[i-1][0] + 9*dp[i-1][1]%M)%M;
		dp[i][0] = 8*dp[i-1][0]%M;
	}

	cout << dp[n][3] << endl;
	return;
}

int32_t main(){
	int t=1;
	while(t--){
		solve();
	}
	return 0;
}

Measured memory_bytes: 73248
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

ll n;
ll a, b;

int main(){
	rll3(n,a,b);
	ll times = n / (a + b);
	ll ans = times * a + min(a, n - times * (a + b));
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N;
    char c;
    vector<int> R,G,B;
    cin >> N;
    for(int i=1; i<=N; i++){
        cin >> c;
        switch (c){
            case 'R':
                R.push_back(i);
                break;
            case 'G':
                G.push_back(i);
                break;
            case 'B':
                B.push_back(i);
                break;
        }
    }
    long long ans=0;
    int m,r,g,b,big,small;
    int target[3];
    int from,to;
    int flag=0;
    for(int i=0; i<R.size(); i++){
        r=R.at(i);
        for(int j=0; j<G.size(); j++){
            g=G.at(j);
            if(r>g){
                big=r;
                small=g;
            }else{
                big=g;
                small=r;
            }
            if((r+g)%2){
                target[0]=-1;
            }else{
                target[0]=(r+g)/2;
            }
            target[1]=2*big-small;
            target[2]=2*small-big;
            flag=0;
            for(int k=0; k<3; k++){
                //if(target[k]<0) continue;
                from=0;
                to=B.size()-1;
                if(to<0) break;
                while(1){
                    if(B.at((to+from)/2)==target[k]){
                        flag++;
                        break;
                    }else if(to-from<1){
                        break;
                    }else if(B.at((to+from)/2)>target[k]){
                        to=(to+from)/2;
                    }else{
                        from=(to+from+1)/2;
                    }
                }
            }
            ans+=B.size()-flag;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a, b;
	cin >> n >> a >> b;
	string s;
	cin >> s;
	int now = 0;
	int nowb = 0;
	rep(i, n) {
		if (s[i] == 'a') {
			if (now < a + b) {
				cout << "Yes" << endl;
				now++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else if (s[i] == 'b') {
			if (now < a + b && nowb < b) {
				cout << "Yes" << endl;
				now++;
				nowb++;
			}
			else {
				cout << "No" << endl;
			}
		}
		else {
			cout << "No" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 848
#include<stdio.h>
int main (){
	int a, b, c;
	int s;
	scanf("%d\n%d\n%d", &a, &b, &c);
	if(a == b && b == c){
		s = 1;
		}
		else if(a == b && b != c ||
			a == c && b != c ||
			b == c && b != a)
		{
			s = 2;
			}
			else 
			{
				s = 3;
				}
	printf("%d\n",s);
	return 0;
	}

Measured memory_bytes: 128
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Random;

public class Main {

    public static void main(String[] args) throws Exception {
        try (BufferedInputStream in = new BufferedInputStream(System.in);
             PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out))) {

            _Scanner sc = new _Scanner(in);
            int s = sc.nextInt();
            int w = sc.nextInt();

            out.println(w >= s ? "unsafe" : "safe");
        }
    }

    private static void reverse(int[] vs) {
        for (int i = 0; i < vs.length / 2; i++) {
            swap(vs, i, vs.length - 1 - i);
        }
    }

    static class _Scanner {
        InputStream is;
        _Scanner(InputStream is) {
            this.is = is;
        }
        byte[] bb = new byte[1 << 15];
        int k, l;
        byte getc() {
            try {
                if (k >= l) {
                    k = 0;
                    l = is.read(bb);
                    if (l < 0) return -1;
                }
                return bb[k++];
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        byte skip() {
            byte b;
            while ((b = getc()) <= 32)
                ;
            return b;
        }

        int nextInt() {
            int n = 0;
            int sig = 1;
            for (byte b = skip(); b > 32; b = getc()) {
                if (b == '-') {
                    sig = -1;
                } else {
                    n = n * 10 + b - '0';
                }
            }
            return sig * n;
        }

        long nextLong() {
            long n = 0;
            long sig = 1;
            for (byte b = skip(); b > 32; b = getc()) {
                if (b == '-') {
                    sig = -1;
                } else {
                    n = n * 10 + b - '0';
                }
            }
            return sig * n;
        }

        public String next() {
            StringBuilder sb = new StringBuilder();
            for (int b = skip(); b > 32; b = getc()) {
                sb.append(((char) b));
            }
            return sb.toString();
        }
    }

    private static void shuffle(int[] ar) {
        Random rnd = new Random();
        for (int i = 0; i < ar.length; i++) {
            int j = i + rnd.nextInt(ar.length - i);
            swap(ar, i, j);
        }
    }

    private static void shuffle(Object[] ar) {
        Random rnd = new Random();
        for (int i = 0; i < ar.length; i++) {
            int j = i + rnd.nextInt(ar.length - i);
            swap(ar, i, j);
        }
    }

    private static void swap(int[] ar, int i, int j) {
        int t = ar[i];
        ar[i] = ar[j];
        ar[j] = t;
    }

    private static void swap(Object[] ar, int i, int j) {
        Object t = ar[i];
        ar[i] = ar[j];
        ar[j] = t;
    }


}


Measured memory_bytes: 32568