akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.List;
import java.util.Scanner;
import java.util.Comparator;
import java.util.ArrayList;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author Silviase
 */
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);
    CFennecVsMonster solver = new CFennecVsMonster();
    solver.solve(1, in, out);
    out.close();
  }

  static class CFennecVsMonster {

    public void solve(int testNumber, Scanner in, PrintWriter out) {
      int n = in.nextInt();
      int k = in.nextInt();
      List<Integer> al = new ArrayList<>();
      long ans = 0;
      for (int i = 0; i < n; i++) {
        al.add(in.nextInt());
      }
      al.sort(Comparator.reverseOrder());

      if (k >= n) {
        out.println(0);
      } else {
        for (int i = 0; i < n; i++) {
          if (i >= k) {
            ans += al.get(i);
          }
        }
        out.println(ans);
      }

    }

  }
}



Measured memory_bytes: 67500
import java.util.Scanner;

class Solver{

    private final int W;
    private final int H;
    private final int x;
    private final int y;

    Solver(Scanner in){
        W = in.nextInt();
        H = in.nextInt();
        x = in.nextInt();
        y = in.nextInt();
    }

    void solve(){
        System.out.printf("%f %d", 0.5 * W * H, x * 2 == W && y * 2 == H ? 1 : 0);
    }
}

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

        new Solver(in).solve();

        in.close();
    }
}

Measured memory_bytes: 21844
import os,io
input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
r,c,k=map(int,input().split())
dp = [0]*(r*c*4)
m=[0]*(r*c)
for i in range(k):
  ri,ci,v=map(int,input().split())
  m[(ri-1)*c+ci-1]=v
dp[0*r*c+0*c+0]=0
dp[1*r*c+0*c+0]=m[0]
dp[2*r*c+0*c+0]=m[0]
dp[3*r*c+0*c+0]=m[0]
for i in range(r):
  for j in range(c):
    if j+1<c:
      dp[0*r*c+i*c+j+1]=max(dp[0*r*c+i*c+j+1],dp[0*r*c+i*c+j])
      dp[1*r*c+i*c+j+1]=max(dp[1*r*c+i*c+j],max(dp[1*r*c+i*c+j+1],dp[0*r*c+i*c+j]+m[i*c+j+1]))
      dp[2*r*c+i*c+j+1]=max(dp[2*r*c+i*c+j],max(dp[2*r*c+i*c+j+1],dp[1*r*c+i*c+j]+m[i*c+j+1]))
      dp[3*r*c+i*c+j+1]=max(dp[3*r*c+i*c+j],max(dp[3*r*c+i*c+j+1],dp[2*r*c+i*c+j]+m[i*c+j+1]))
    if i+1<r:
      a=dp[3*r*c+i*c+j]
      b=a+m[(i+1)*c+j]
      dp[0*r*c+(i+1)*c+j]=a
      dp[1*r*c+(i+1)*c+j]=b
      dp[2*r*c+(i+1)*c+j]=b
      dp[3*r*c+(i+1)*c+j]=b
print(dp[3*r*c+(r-1)*c+c-1])
    


Measured memory_bytes: 431148
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  char first = '1';
  int keta = 0;
  FOR(i,0,s.length()) {
    if(s[i] != '1') {
      first = s[i];
      keta = i + 1;
      break;
    }
  }
  int K;
  cin >> K;
  if(keta > K) {
    cout << '1' << endl;
  } else {
    cout << first << endl;
  }
}

Measured memory_bytes: 256
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int N = Integer.parseInt(sc.next());
        String[] S = sc.next().split("");
        
        int count = 0;
        int ans = 0;
        
        for(int i=0; i<N; i++){
            if(S[i].equals("I")){
                count++;
            }
            if(S[i].equals("D")){
                count--;
            }
            
            ans = Math.max(ans, count);
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        PrintWriter pw = new PrintWriter(System.out);

        double l = Integer.parseInt(br.readLine());

        pw.println((l/3)*(l/3)*(l-((l/3)+(l/3))));
        
        
        
        
        
        pw.flush();
        pw.close();
    }
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n; cin >> n;
    map<ll, ll> m;
    REP(i, n) {
        ll a, b; cin >> a >> b;
        m[a]++;
        m[b] = m[b];
        m[b+1]--;
    }
    ll ans = 1;
    ll cnt = 1;
    EACH(p, m) {
        ll need, d; tie(need, d) = p;
        cnt += d;
        if (cnt >= need) {
            // cout << need << " " << d << " " << cnt << endl;
            ans = max(ans, need);
        }
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 9052
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
int n,tot=0;
const int INF=1e9;
struct data {
	int next,num;
}edge[200005];
int head[200001],d[200001];
void add(int u,int v) {
	edge[++tot].next=head[u];
	edge[tot].num=v;
	head[u]=tot;
}
int dfs(int x,int fa) {
	int cnt=0;
	int sum=0;
	for (int i=head[x];i!=-1;i=edge[i].next) {
		int kx=edge[i].num;
		if (kx==fa) continue;
		cnt++;
		sum+=dfs(kx,x);
	}
	if (x==1) return sum-cnt/2;
	if (cnt%2) return sum-cnt/2;
	return sum-cnt/2+1;
}
int calc(int x,int fa,int lim) {
	vector <int> v;
	for (int i=head[x];i!=-1;i=edge[i].next) {
		int kx=edge[i].num;
		if (kx==fa) continue;
		int now=calc(kx,x,lim);
		if (now==INF) return INF;
		v.push_back(now);
	}
	int sz=v.size();
	sort(v.begin(),v.end());
	if (sz%2==0) {
		bool judge=1;
		for (int i=0;i<sz;i++)
			if (v[i]+v[sz-i-1]>lim) {
				judge=0;
				break;
			}
		if (judge) return 1;
		if (x==1) return INF;
		sz--;
	}
	int l=0,r=sz;
	while (l<r) {
		int mid=(l+r)/2;
		bool judge=1;
		vector <int> v2;
		for (int i=0;i<sz;i++) if (i!=mid) v2.push_back(v[i]);
		for (int i=0;i<sz-1;i++) if (v2[i]+v2[sz-i-2]>lim) {
			judge=0;
			break;
		}
		if (judge) r=mid;
			else l=mid+1;
	}
	if (l==sz) return INF;
	if (x==1&&v[l]>lim) return INF;
	if (x==1) return 0;
	if (v[l]+1>lim) return INF;
	return v[l]+1;
}
int work() {
	int l=1,r=2e5;
	while (l<r) {
		int mid=(l+r)/2;
		if (calc(1,-1,mid)!=INF) r=mid;
			else l=mid+1;
	}
	return l;
}
int main() {
	memset(head,-1,sizeof(head));
	scanf("%d",&n);
	for (int i=1;i<n;i++) {
		int u,v;
		scanf("%d%d",&u,&v);
		add(u,v);
		add(v,u);
		d[u]++;
		d[v]++;
	}
	int ans=dfs(1,-1);
	printf("%d ",ans);
	int ans2=work();
	printf("%d\n",ans2);
	return 0;
}

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

#define ll long long
#define endl "\n"
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define f first
#define s second
#define vecll vector<ll>
#define pairll pair<ll,ll>
#define vecpairll vector<pair<ll,ll>>
#define mapllll map<ll,ll>
#define mapstrll map<string,ll>
#define mapllvecll map<ll,vecll>
#define setll set<ll>
#define fio ios_base::sync_with_stdio (false); cin.tie (NULL); cout.tie(NULL);

using namespace std;

ll const N=1e5+5;
ll const inf=1e18+5;
ll const MOD=1e9+7;

ll t,n,m,x,y,z,w,k;

int main()
{
    fio

    cin>>x>>y;

    if(x<=y)    cout<<"unsafe";
    else        cout<<"safe";
    return 0;
}



Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
typedef long long ll;
using namespace std;
//#define int long long

//素数判定
inline bool IsPrime(int p) {
	if (p == 1) return false;
	for (int i = 2; i <= sqrt(p); i++) {
		if (p%i == 0) return false;
	}
	return true;
}

//10進数の自然数の桁数を返す
inline int GetDigit(int num) {
	return (int)log10(num) + 1;
}

//各位の和を返す
int GetDigitsSum(int num) {
	int N = 0;
	while (num > 0) {
		N += num % 10;
		num /= 10;
	}
	return N;
}

//互除法
ll gcd(ll a, ll b) {
	if (a < b) {
		return gcd(b, a);
	}
	else if (a%b) {
		return gcd(b, a%b);
	}
	else {
		return b;
	}
}

//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b; // Be careful not to overflow

}

//異なるn個からr個の整数を取り出す組合せの数を求める
int combination(int n, int r) {
	if (r == 0 || n == r) {
		return 1;
	}
	else if (r == 1) {
		return n;
	}
	else {
		return combination(n - 1, r - 1) + combination(n - 1, r);
	}

}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor(int n) {
	map<int, int> res; // map[i]:=ｎを素因数分解したときiは何乗か。
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n] = 1;
	return res;
}

//Ｏ(√n)
//素因数分解
map<int, int> prime_factor_ver2(int n, map<int, int> res) {
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0) {
			while (n % i == 0) {
				res[i]++;
				n /= i;
			}
		}
	}
	if (n != 1)
		res[n]++;
	return res;
}


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

	int N;
	int cnt = 0;
	string s, t;
	cin >> N >> s >> t;

	if (s == t) {
		cout << N << endl;
		return 0;
	}

	for (int i = 1; i < N; i++)
	{
		if (s.substr(N - i) == t.substr(0, i)) {
			cnt = i;
		}
	}

	cout << N * 2 - cnt << endl;

	return 0;
}


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

using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;
const ll Lmax=ll(1e18);
const ll INF=1e6;
const int Nmax=2e5+1;
const int Nd=61;



int main(){
  int k;cin>>k;
  if(k%2==0){
    cout<<-1<<endl;
    return 0;
  }
  bool ok=true;
  int i=1;
  int now1=0;
  int now2=7;
  int start=now2%k;
  int ans=0;
  while(ok){//
    now2=now2%k;
    now1=(now1+now2)%k;
    if(now1==0){
      ans=i;
      cout<<i<<endl;
      ok=false;
      break;
    }
    now2*=10;
    if(now1==start && i>1){
      cout<<-1<<endl;
      return 0;
    }
    i++;
    if(i>k){
      cout<<-1<<endl;
      return 0;
    }
  }


}


Measured memory_bytes: 3616
#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>;

const int mod = 1000000007;
class mint {
    long long x;
public:
    mint(long long 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(long long t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    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;
    }
    mint choose(int n, int a){
        mint x = 1 ,y = 1;
        for(int i=0; i<a; ++i){
            x *= n-i;
            y *= i+1;
        }
        return x / y;
    }
    friend istream& operator>>(istream& is, mint& m){
        is >> m.x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};

int c[200010],p[200010];
mint dp[200010];

int main(){
    int n;
    cin>>n;
    for(int i=1; i<=n; ++i)cin>>c[i];
    rep(i,200010)p[i]=-1;
    dp[0]=1;
    for(int i=1; i<=n; ++i){
        if(p[c[i]]==-1)dp[i]=dp[i-1];
        else if(p[c[i]]==i-1)dp[i]=dp[i-1];
        else dp[i]=dp[i-1]+dp[p[c[i]]];
        p[c[i]]=i;
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using piii = pair<int, pair<int, int>>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;

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

    int H, W;
    cin >> H >> W;
    vector<vector<bool>> isblack(H, vector<bool>(W));
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            char c;
            cin >> c;
            isblack[i][j] = (c == '#');
        }
    }

    deque<pii> que;
    vector<vector<int>> dist(H, vector<int>(W, 1e9));
    dist[0][0] = isblack[0][0];
    que.push_front({0, 0});

    int dy[] = {0, 1};
    int dx[] = {1, 0};
    while (!que.empty()) {
        pii p = que.front();
        int y = p.first, x = p.second;
        que.pop_front();
        for (int i = 0; i < 2; ++i) {
            int ny = y + dy[i];
            int nx = x + dx[i];
            if (ny < 0 || nx < 0 || ny >= H || nx >= W)
                continue;
            if (!isblack[ny][nx] || (isblack[ny][nx] == isblack[y][x])) {
                if (dist[ny][nx] > dist[y][x]) {
                    dist[ny][nx] = dist[y][x];
                    que.push_front({ny, nx});
                }
            } else {
                if (dist[ny][nx] > dist[y][x] + 1) {
                    dist[ny][nx] = dist[y][x] + 1;
                    que.push_back({ny, nx});
                }
            }
        }
    }

    cout << dist[H - 1][W - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
HW_list = list()
count = 0

while True:
    HW_list.append(list(map(int, input().split())))
    if HW_list[count][0] == 0 and HW_list[count][1] == 0:
        break
    count += 1

for i in range(count):
    for H in range(HW_list[i][0]):
        print("#"*HW_list[i][1])
    print("")



Measured memory_bytes: 5620
use proconio::input;

fn main() {
    input! {
        a: usize,
        b: usize,
        c: usize,
        x: usize,
    }
    let x = x / 50;

    let mut dp = vec![0 as usize; x + 1];
    dp[0] = 1;

    for i in (0..=x).rev() {
        for j in 1..=a {
            if j * 10 <= i {
                dp[i] += dp[i - j * 10]
            }
        }
    }

    for i in (0..=x).rev() {
        for j in 1..=b {
            if j * 2 <= i {
                dp[i] += dp[i - j * 2]
            }
        }
    }

    for i in (0..=x).rev() {
        for j in 1..=c {
            if j <= i {
                dp[i] += dp[i - j]
            }
        }
    }

    println!("{}", dp[x])
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
#include <vector> 
# include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

#define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

vector<int> fac(300001); //n!(mod M)
vector<int> ifac(300001); //k!^{M-2} (mod M)

long long fpow(long long a,long long n){
  long long ret=1;
  if(n==1) return a;
  if(n%2==0) {
      ret = fpow(a*a%mod, n/2) %mod ;
  }else {
      ret = (a%mod)*fpow(a*a%mod, n/2) %mod;
  }
  return ret %mod;
}
int comb(int a, int b){ //aCbをmod計算
    if(a == 0 && b == 0)return 1;
    if(a < b || a < 0)return 0;
    int tmp = ifac[a-b]* ifac[b] % mod;
    return tmp * fac[a] % mod;
}
const int D = 60;
int to[D][MX];


signed main(){
    int a, b, k;
    cin >> a >> b >> k;
    int cnt = 0;
    deque<int> arr;
    FOR(i,1,min(a,b)+1) {
        if(a%i==0&&b%i==0) arr.push_back(i);
    }
    cout << arr[arr.size()-k] << endl;
    return 0;
}

Measured memory_bytes: 4992
#include <bits/stdc++.h>
#include <string.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m; i < n; i++) 
typedef long long int ll;
int main(){
    int N,M;
    cin>>N>>M;
    vector<pair<int,int>>A(N);
    rep(i,N){
        int a,b;
        cin>>a>>b;
        A.at(i)=make_pair(a,b);
    }
    sort(A.begin(),A.end());
    int count=0;
    ll nedan=0;
    rep(i,N){
        if(count+A.at(i).second<=M){
            nedan+=(ll)A.at(i).first*A.at(i).second;
            count+=A.at(i).second;
        }else{
            nedan+=(ll)A.at(i).first*(M-count);
            count+=M-count;
        }
        if(count==M){
            break;
        }
        
    }
    cout<<nedan<<endl;

    return 0;
}

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

x_plus_y = []
x_minus_y = []

for i in range(n):
    x, y = map(int, input().split())
    x_plus_y.append(x+y)
    x_minus_y.append(x-y)

x_plus_y_max = max(x_plus_y)
x_plus_y_min = min(x_plus_y)
x_minus_y_max = max(x_minus_y)
x_minus_y_min = min(x_minus_y)

print(max(x_plus_y_max - x_plus_y_min,
          x_minus_y_max - x_minus_y_min))



Measured memory_bytes: 24984
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
#define db(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<'\n'
const ll inf = 1e18+7;
const int N = 1e6+9;

int main() {
    ios_base::sync_with_stdio(0);
    ll a,b,c,d;
    ll A[5];
    cin>>A[0]>>A[1]>>A[2]>>A[3];
    ll mx=-inf;
    for(int i=0;i<2;++i) {
        for(int j=2;j<4;++j) {
            ll tmp = A[i]*A[j];
            mx = max(mx, tmp);
        }
    }
    cout<<mx<<endl;
    return 0;
}

Measured memory_bytes: 3612
/**
 * 
 */
import java.util.*;
/**
 * @author afterCmidday
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan = new Scanner(System.in);
		int cnt = 0, ans1 = 0, sumNum = 0;
		while(scan.hasNext()){
			String str = scan.next();
			int x1 = Integer.parseInt((str.substring(0,str.indexOf(","))));
			int x2 = Integer.parseInt((str.substring(str.indexOf(",") + 1,str.length()))); 
			ans1 += x1 * x2;
			sumNum += x2;
			cnt++;
		}
		double ans2 = (double)sumNum / cnt;
		System.out.format("%d\n%d\n",ans1,(int)(ans2 + 0.5));
	}

}

Measured memory_bytes: 17308
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

int P[100001];

int Find(int A) {
	if (P[A] < 0) return A;
	return P[A] = Find(P[A]);
}

int getint() {
	char C;
	while (!isdigit(C = getchar()));
	int A = C - '0';
	while (isdigit(C = getchar())) A = A * 10 + C - '0';
	return A;
}

void putll(ll X) {
	if (X == 0) putchar('0');
	int keta = 0;
	char C[20];
	while (X) {
		C[keta] = '0' + X % 10;
		X /= 10;
		keta++;
	}
	for (int i = keta - 1; i >= 0; i--) putchar(C[i]);
	putchar('\n');
}

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


	int N, M;
	N = getint();
	M = getint();

	int A[100000], B[100000];
	rep(i, M) {
		A[i] = getint();
		B[i] = getint();
	}

	ll sum = (ll)N * (N - 1) / 2;
	ll kotae[100001];
	kotae[M] = sum;

	rep1(i, N) P[i] = -1;

	for (int i = M - 1; i > 0; i--) {
		int ap = Find(A[i]);
		int bp = Find(B[i]);
		if (ap != bp) {
			sum -= (ll)P[ap] * P[bp];
			if (P[ap] > P[bp]) swap(ap, bp);
			P[ap] += P[bp];
			P[bp] = ap;
		}
		kotae[i] = sum;
	}
	
	rep1(i, M) putll(kotae[i]);

	Would you please return 0;
}

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

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

  LL ans = 0;
  ans += (n / (a + b)) * a;
  ans += min(a, n % (a + b));

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<string, string> sP;
typedef pair<ll, pair<ll, ll>> PP;

const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

ll rui[200010], rx[200010];

int main() {
	ll n, a[200010], ans = 0;
	cin >> n;
	for (int i = 1;i <= n;i++) {
		cin >> a[i];
		rui[i] = rui[i - 1] + a[i];
		rx[i] = rx[i - 1] ^ a[i];
	}
	int l = 1;
	for (int r = 1;r <= n;) {
		if (rui[r] - rui[l - 1] != (rx[r] ^ rx[l - 1]))l++;
		else {
			ans += r - l + 1;
			r++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n=0,best_n=0,T=0,A=0,height_i[1001]={0},temp_average=0,temp_diff_from_a=0,new_temp_diff_from_a=0;
    scanf("%d",&n);
    scanf("%d %d",&T,&A);
    for(int i=0;i<n;i++)
	scanf("%d",&height_i[i]);


    for(int i=0;i<n;i++){
	temp_average=1000*T-height_i[i]*6;
	new_temp_diff_from_a=abs(1000*A-temp_average);

	if(i==0 || new_temp_diff_from_a<temp_diff_from_a){
	    temp_diff_from_a=new_temp_diff_from_a;
	    best_n=i;
	}

    }
    printf("%d",best_n+1);
    return 0;
}



Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <map>
using namespace std;
#define ll long long

int main() {
	int n, s, hoge;
	cin >> n;
	s = 0;
	hoge = n;
	while (hoge > 0) {
		s += hoge % 10;
		hoge = hoge / 10;
	}
	if (n % s == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

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;
int main(){
    string s; ll k;
    cin>>s>>k;
    int cnt=0;
    int ans=0;
    for(int i=0; i<s.length(); ++i){
        if(s[i]=='1'){
            cnt++;
        }
        else{
            ans=(s[i]-'0');
            break;
        }
    }
    if(cnt>=k)cout<<1<<endl;
    else cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys

N = int(sys.stdin.readline())
data = sys.stdin.readlines()

for i in range(2):
    data[i] = data[i].split(' ')
    data[i] = [int(j.replace('\n', '')) for j in data[i]]

set = [0]*N
for i in range(N):
    candy = 0
    candy = sum(data[0][0:i+1]) + sum(data[1][i:N])
    set[i] = candy

print(max(set))





Measured memory_bytes: 3064
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
#define MAX_V 300
#define INF 1000000000

struct edge { int to, cap, rev; };
vector<edge> G[MAX_V];
bool used[MAX_V]; 
int V;
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});
}
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;
    }
}
void resetG(int ver){
    V = ver;
    REP(i,V)
        G[i].clear();
}

int n;
int a[200],b[200],c[200],d[200];


int main(){
	cin >> n;
	REP(i,n) {
		cin >> a[i] >> b[i] ;
	}
	REP(i,n) {
		cin >> c[i] >> d[i];
	}
	resetG(2 * n + 2);

	REP(i,n) {
		REP(j,n) {
			if(a[i] < c[j] && b[i] < d[j]) {
				add_edge(i,j + n,1);
			}
		}
	}

	REP(i,n) {
		add_edge(2 * n,i,1);
	}
	REP(i,n) {
		add_edge(i + n,2 * n + 1,1);
	}
	cout << max_flow(2 * n,2 * n + 1) << endl;;
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vel;
typedef vector<string> ves;
typedef vector<int> vei;
typedef vector<vector<ll>> vvel;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

int main() {
    int k;
    cin >>k;
    string s;
    cin >>s;
    if (k>=s.size()) {
        cout<<s<<endl;
    }
    else {
        rep(i,k){
            cout <<s[i];
        }
        cout <<"..."<<endl;
    }
    
}

Measured memory_bytes: 3592
import java.util.Scanner;

public class Main {

	public static void main(String[] args) 
	{
		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		if(n==0)
		{
			System.out.println(0);
			return;
		}
		int[] num = null;
		int digs = 0;
		boolean neg = false;
		if(n<0)
		{
			n *= -1;
			neg = true;
		}
		{
			String s = Long.toBinaryString(n);
			digs = s.length();
			num = new int[digs+3];
//			System.out.println(s);
			for(int i = 0; i < digs; i++)
			{
				if(s.charAt(digs - 1 - i) == '1')
				{
					num[i]++;
					if(i%2==1 ^ neg)
					{
						num[i+1]++;
					}
				}
				while(num[i] >= 2)
				{
					if(num[i+1] > 0)
					{ //collide
						num[i+1]--;
						num[i] -= 2;
					}
					else
					{
						num[i+1]++;
						num[i+2]++;
						num[i]-= 2;
					}
				}
			}
//			System.out.println(Arrays.toString(num));
		}

		
		StringBuilder sb = new StringBuilder();
		boolean go = false;
		for(int i = digs+2; i>=0; i--)
		{
			if(num[i] == 1)go = true;
			if(go)sb.append(num[i]);
		}
		System.out.println(sb);
	}

}


Measured memory_bytes: 23764
package main

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

func main() {
	X := ReadInt()
	fx := 0
	x := X
	for x > 0 {
		fx += x % 10
		x /= 10
	}
	if X%fx == 0 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1840
#include <bits/stdc++.h>
#define lsb(x) (x & (-x))
#define ll long long

using namespace std;


map <int, int> mp;

int v[1000000];

int main() {
    //ifstream cin("A.in");
    //ofstream cout("A.out");
    int i, n;
    ios::sync_with_stdio(false);
    cin >> n;
    for(i = 1; i <= n; i++) {
        cin >> v[i];
        mp[v[i]]++;
    }
    int ans = 0;
    for(i = 1; i <= n; i++) {
        if(mp[v[i]] < v[i]) {
            ans++;
            mp[v[i]]--;
        }
        if(mp[v[i]] > v[i]) {
            mp[v[i]]--;
            ans++;
        }
    }
    cout << ans;
    //cin.close();
    //cout.close();
    return 0;
}


Measured memory_bytes: 5120
#include <cmath>
#include <iostream>
#include <vector>

using namespace std;

u_int make_prime_list(u_int a[], u_int size)
{
	a[0] = 2;
	a[1] = 3;
	
	u_int i = 2;

	for (u_int q = 5; q <= size; q+=2) {
		u_int threshold = (u_int)sqrt(q);
		bool is_prime = true;
		
		for (u_int j = 1; a[j] <= threshold; j++)
			if (q % a[j] == 0) {
				is_prime = false;
				break;
			}

		if (is_prime)
			a[i++] = q;
	}

	return i;
}

void prime_factorize(u_int const *prime_list, vector<u_int> *a,
					 u_int n, u_int size)
{
	u_int p = 2, i = 1;

	while (p <= n) {
		if (n % p == 0) {
			a->push_back(p);
			n /= p;
		} else if (i < size)
			p = prime_list[i++];
		else
			break;
	}

	if (a->empty() || n != 1)
		a->push_back(n);
}

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

	u_int prime_list[100000];
	u_int size = make_prime_list(prime_list, (u_int)sqrt(n));

	vector<u_int> a;
	prime_factorize(prime_list, &a, n, size);

	cout << n << ":";
	for (auto x : a)
		cout << " " << x;
	cout << endl;

	return 0;
}

Measured memory_bytes: 1236
# frozen_string_literal: true

n, x, m = gets.split.map(&:to_i)

a = x

h = Hash.new { false }
l = -1
b = []
n.times do
  if h[a]
    l = a
    break
  end
  h[a] = true
  b.push a
  a = (a * a) % m
end

b1, b2 = b.slice_before(l).to_a
b1 = [] if b1.nil?
b2 = [] if b2.nil?
remain = n - b.size
if l == b[0]
  b2 = b1
  b1 = []
end
d = 0
dd = 0
if remain.positive? && !b2.empty?
  d = remain / b2.size
  dd = remain % b2.size
end

sum1 = b1.sum
sum2 = b2.sum * (d + 1)
sum = sum1 + sum2 + b2.take(dd).sum
puts sum


Measured memory_bytes: 17212
#include <bits/stdc++.h>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define M   1000000007 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,double> pdd;
inline int mod(int n, int m){int ret = n%m; if(ret < 0) ret += m; return ret;}
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }    else return mod(k*k,m);
}

int ok[30];

int32_t main(){
	fastio;
	int n;
	cin>>n;
	
	for(int i=1;i<=100;i++){
		if(n%i==0){
			if(i<=9 && n/i<=9)return cout<<"Yes"<<endl,0;
		}
	}
	cout<<"No"<<endl;
		
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
co=0
for i in range(n):
    co=co+b[i]
for i in range(n-1):
    if a[i]+1==a[i+1]:
        co+=c[a[i]-1]

print(co)

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


int main()
{
  int n;
  cin>>n;
  int x[n],y[n];
  for(int i=0;i<n;i++)
  {
    cin>>x[i]>>y[i];
  }
  
  double d=0.0;
  for(int i=0;i<n;i++)
  {
    for(int j=i+1;j<n;j++)
    {
    	double a=(x[i]-x[j]);
    	double b=(y[i]-y[j]);
    
    	double r=a*a+b*b;
      d+=pow(r, 0.5)*2/n;
    }
  }
  

  cout << fixed << setprecision(10) << d << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <cassert>

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

using namespace std;
typedef long long int ll;
const ll INF = 1000000000000000000;
const double PI = acos(-1);
const ll mod = 1000000007;

int main()
{
    int d;
    int c[26];
    int s[365][26];
    int t[365];
    cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) rep(j, 26) cin >> s[i][j];
    rep(i, d) cin >> t[i];

    int last[26] = {};
    int v = 0;
    rep(i, d) {
        v += s[i][t[i]-1];
        last[t[i]-1] = i + 1;
        rep(j, 26) {
            v -= c[j] * (i + 1 - last[j]);
        }
        cout << v << endl;
    }
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
int LMS(int n, int k) 
{ 
if (n == 1) 
	return 1; 
else
	/* The position returned by josephus(n - 1, k) is adjusted because the 
	recursive call josephus(n - 1, k) considers the original position 
	k%n + 1 as position 1 */
	return (LMS(n - 1, k) + k-1) % n + 1; 
} 
int main(){
	

	int t = 1;
	//cin >> t;
	while(t--){
		int n;
		cin >> n;
		set<int> s;
		int a;
		for(int i = 0; i < n; ++i){
			cin >> a;
			s.insert(a);
		}
		if(s.size() == n) cout << "YES";
		else cout << "NO";
	}
	return 0;
}

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

int main() {
	int a, b;
	bool cnt = false;
	while (cin >> a >> b, a | b) {
		bool flag = true;
		if (cnt)cout << endl;
		for (int i = a; i <= b; i++) {
			bool uruu = false;
			if (!(i % 4))uruu = true;
			if (!(i % 100))uruu = false;
			if (!(i % 400))uruu = true;
			if (uruu) {
				flag = false;
				cout << i << endl;
			}
		}
		if (flag)puts("NA");
		cnt = true;
	}
}

Measured memory_bytes: 3136
#include <cstdio>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);++i)
inline char tc(){
  static char fl[100],*A=fl,*B=fl;
  return A==B&&(B=(A=fl)+fread(fl,1,100,stdin),A==B)?EOF:*A++;  
}

inline int read(){
  int a=0;static char c;
  while((c=tc())<48||c>57);
  while(c>=48&&c<=57)a=a*10+c-48,c=tc();
  return a;
}

static const int buf_size = 4096;
static int write_pos = 0;
static char write_buf[buf_size];

inline void writeChar( int x ) {
    if (write_pos == buf_size)
        fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
    write_buf[write_pos++] = x;
}

template <class T> 
inline void writeInt( T x, char end ) {
    if (x < 0)
        writeChar('-'), x = -x;
     
    char s[24];
    int n = 0;
    while (x || !n)
        s[n++] = '0' + x % 10, x /= 10;
    while (n--)
        writeChar(s[n]);
    if (end)
        writeChar(end);
}

struct Flusher {
    ~Flusher() {
        if (write_pos)
            fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
    }
} flusher;

int a[2000001];
int main(){
  int n=read(),i;
  rep(i,n)a[i]=read();
  for(i=n-1;i>=0;i-=2)writeInt(a[i], ' ');
  for(i=n%2;i<=n-1;i+=2)writeInt(a[i], ' ');
  writeChar('\n');
  return 0;
}

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

int main()
{
    int n, m;
    cin>>n>>m;
    int A[n][m], x[m], b[n]={0};
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            cin>>A[i][j];
        }
    }
    for(int i=-0;i<m;i++)
    {
        cin>>x[i];
    }
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
             b[i] += A[i][j]*x[j];
        }
    }
    for(int i=0;i<n;i++)cout<<b[i]<<endl;
    return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
int main(){
    long k,n,cnt=0;
    cin >> n >> k;
    long a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    sort(a,a+n);
    reverse(a,a+n);
    for(int i=k;i<n;i++){
        cnt += a[i];
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long int n,W,i,j;
	cin>>n>>W;
	long long int w[n],v[n];
	for(i=0;i<n;i++){
	cin>>w[i]>>v[i];}
	long long int dp[n+1][W+1];

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


Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
template<class t,class u> inline bool chmax(t&a,u b){if(a<b){a=b;return true;}return false;}
template<class t,class u> inline bool chmin(t&a,u b){if(b<a){a=b;return true;}return false;}

int main(){
    unordered_map<char, int> cnt;
    int n;cin >> n;
    rep(i,3) cin >> cnt[i+'A'];
    vector<string> s(n);
    rep(i,n) cin >> s[i];

    bool flag = true;
    vector<char> ans;
    
    auto fnc = [&](const string& s1, const string& s2){
        if(cnt[s1[0]] == 0 && cnt[s1[1]] == 0){
            flag = false;
            return false;
        }
        else if(cnt[s1[0]] == 1 && cnt[s1[1]] == 1){
            if(s1 == s2){
                ans.push_back(s1[0]);
                cnt[s1[0]]++;
                cnt[s1[1]]--;
            }
            else if(s1[0] == s2[0]){
                // AB AC
                ans.push_back('A');
                cnt[s1[0]]++;
                cnt[s1[1]]--;
            }else if(s1[1] == s2[1]){
                // AC BC
                ans.push_back('C');
                cnt[s1[1]]++;
                cnt[s1[0]]--;
            }else{
                if(s1[0] == 'A'){
                    // s1 = AB , s2 = BC
                    ans.push_back('B');
                    cnt['B']++;
                    cnt['A']--;
                }else{
                    // s1 = BC , s2 = AB
                    ans.push_back('B');
                    cnt['B']++;
                    cnt['C']--;
                }
            }
        }
        else if(cnt[s1[0]] >= cnt[s1[1]]){
            ans.push_back(s1[1]);
            cnt[s1[1]]++;
            cnt[s1[0]]--;
        }else/* if(cnt[s1[0]] < cnt[s1[1]])*/{
            ans.push_back(s1[0]);
            cnt[s1[0]]++;
            cnt[s1[1]]--;
        }
        return true;
    };

    rep(i,n-1){
        if(!fnc(s[i], s[i+1])) break;
        //cerr << i << " : ";
        //for(char c = 'A';c<='C';++c) cerr << cnt[c] << " ";
        //cerr << endl;
    }

    // last 
    if(cnt[s[n-1][0]] > 0){
        ans.push_back(s[n-1][1]);
    }else if(cnt[s[n-1][1]] > 0){
        ans.push_back(s[n-1][0]);
    }else{
        flag = false;
    }
    
    if(flag){
        cout << "Yes\n";
        rep(i,n) cout << ans[i] << "\n";
    }else{
        cout << "No\n";
    }
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  long double A,B;
  cin>>A>>B;
  ll l=0,r=10000000000000000,m;
  while(r-l>1){
    m=(r+l)/2;
    if(m<=A*B)l=m;
    else r=m;
  }
  cout<<l<<endl;
  return 0;
}


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

int main() {
  int m, f, r, score;
  char grade;
  while (true) {
    cin >> m >> f >> r;

    if (m == -1 && f == -1 && r == -1)
      break;
    else if (m == -1 || f == -1) {
      cout << 'F' << endl;
      continue;
    } else
      score = m + f;

    if (score >= 80)
      cout << 'A' << endl;
    else if (score >= 65)
      cout << 'B' << endl;
    else if (score >= 50)
      cout << 'C' << endl;
    else if (score >= 30 && r >= 50)
      cout << 'C' << endl;
    else if (score >= 30)
      cout << 'D' << endl;
    else
      cout << 'F' << endl;
  }
}



Measured memory_bytes: 3088
#include <map>
#include <cstdio>
#include <vector>
#pragma warning(disable : 4996)
using namespace std;
std::map<unsigned long long, unsigned> prime_factorize(unsigned long long x) {
	std::map<unsigned long long, unsigned> ret;
	for (unsigned i = 2; 1ULL * i * i <= x; i++) {
		while (x % i == 0) x /= i, ret[i]++;
	}
	if (x != 1) ret[x]++;
	return ret;
}
bool k_cycle(vector<int> &v, int k) {
	for (int i = k; i < v.size(); i++) {
		if (v[i] != v[i - k]) return false;
	}
	return true;
}
int n;
int main() {
	scanf("%d", &n);
	vector<int> v(n);
	for (int i = 0; i < n; i++) scanf("%d", &v[i]);
	std::map<unsigned long long, unsigned> res = prime_factorize(n);
	int ret = n;
	for (pair<unsigned long long, unsigned> i : res) {
		for (int j = 0; j < i.second; j++) {
			if (!k_cycle(v, ret / i.first)) break;
			ret /= i.first;
		}
	}
	printf("%d\n", n / ret);
	return 0;
}

Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmin(T &a, T b){ if (a > b){ a = b; return true;} return false;}

const long long INF = 1LL << 30;

int main(){
  int n; cin >> n;
  int dp[100010];
  for(int i = 0; i <= n; i++){
    dp[i] = INF;
  }
  dp[0] = 0;
  for(int i = 0; i < n; i++){
    int a = 6, b = 9;
    chmin(dp[i + 1], dp[i] + 1);
    while((i + a) <= n){
      chmin(dp[i + a], dp[i] + 1);
      a *= 6;
    } 
    while((i + b) <= n){
      chmin(dp[i + b], dp[i] + 1);
      b *= 9;
    }
  }
  cout << dp[n] << endl;
}
   

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

int main(int argc, char const *argv[])
{
	string s;
	cin>>s;
	int a=0,b=0;
	for(auto v:s)
	{
		if (v=='0')
		{
			++a;
		}
		else
		{
			++b;
		}
	}
	cout<<2*min(a,b)<<endl;
	return 0;
}


Measured memory_bytes: 512
import math
T = []

class Vect:
    def __init__(self,x,y):
        self.x = x
        self.y = y


def hoge(p,q):
    ax = q.x-p.x
    ay = q.y-p.y
    bx = ax/2 - ay*math.sqrt(3)/2
    by = ax*math.sqrt(3)/2 + ay/2
    nb = Vect(p.x+bx,p.y+by)
    return nb

def koch(p,q,n):
    if n == 0:
        T.append(p)
    else:
        s = Vect(p.x+(q.x-p.x)/3,p.y+(q.y-p.y)/3)
        t = Vect(p.x+2*(q.x-p.x)/3, p.y+2*(q.y-p.y)/3)
        u = hoge(s,t)
        koch(p,s,n-1)
        koch(s,u,n-1)
        koch(u,t,n-1)
        koch(t,q,n-1)
        
n = int(input())

koch(Vect(0,0),Vect(100,0),n)
T.append(Vect(100,0))

for i in T:
    print("%.8f %.8f"%(i.x,i.y))
        
        

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

using namespace std;

signed main() {
    string s;
    cin >> s;
    bool ok = false;
    for (size_t i = 0; i <= 9; i++) {
      string check = to_string(i) + to_string(i) + to_string(i);
      if (s.find(check) != string::npos) {
        ok = true;
        break;
      }
    }

    cout << (ok ? "Yes" : "No") << endl;
}


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

int main(){
 long long N,M,f,g,p;
  string S;
  cin>>S;
  N=S.size();
  f=1;
  g=0;
  p=0;
  for(int i=2;i<N;i+=2){
    f=(N-i)/2;
    for(int j=0;j<f;j++){
      if(S[j]==S[j+f]){
        p++;
      }
      else{
        break;
      }
    }
    if(p==f){
      cout<<N-i<<endl;
    return 0;
    }
    else{
      p=0;
    }
}
}

Measured memory_bytes: 256
def euclid(x, y):
    c0, c1 = x, y
    a0, a1 = 1, 0
    b0, b1 = 0, 1
 
    while c1 != 0:
        m = c0 % c1
        q = c0 // c1
 
        c0, c1 = c1, m
        a0, a1 = a1, (a0 - q * a1)
        b0, b1 = b1, (b0 - q * b1)
 
    return a0, b0

n=int(input())
n=n*2
soinsu=[]

num=n


for i in range(2,max(20,n)):
    if(i*i>n):
        if(num!=1):
            soinsu.append([num,1])
        break
    if(num%i!=0):
        continue
    cnt=0
    while(num%i==0):
        cnt+=1
        num//=i
    soinsu.append([i,cnt])

kazu=len(soinsu)


ans=[]
for i in range(2**(kazu-1)):
    a=1
    for j in range(kazu):
        if((i&1<<j)!=0):
            a*=soinsu[j][0]**soinsu[j][1]
    b=n//a
    c,d=euclid(a,b)
    if(c*d==0):
        c+=b
        d+=a
    ans.append(max(a*c,b*d))
    
if(kazu==1):
    print(min(ans)-2)
else:
    print(min(ans)-1)

Measured memory_bytes: 68656
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using ld = long double;  using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
const ld PI = 3.1415926535897932;
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define mp make_pair
#define mt make_tuple
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define ULL(...) ull __VA_ARGS__;in(__VA_ARGS__)
#define STR(...) string __VA_ARGS__;in(__VA_ARGS__)
#define CHR(...) char __VA_ARGS__;in(__VA_ARGS__)
#define DBL(...) double __VA_ARGS__;in(__VA_ARGS__)
#define LD(...) ld __VA_ARGS__;in(__VA_ARGS__)
void in() {}
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
void vout(vl V) {
	for (ll i = 0; i < (ll)V.size(); i++) cout << V[i] << " ";
	cout << endl;
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//bitSearch, bitList, nod, gcdlcm, isPrime, primeFactorize, Npow, divisor, modinv, dfs, bfs, eratos//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z, R, Q;
ll MOD = 1000000007; ll INF = 1LL << 62; ll ans = 0; ll z = 0, o = 1;
vl flag, color; vll path; vl A; vl dp; vl Ans;
int main(){
	cin >> N;
	vl T(N), A(N);
	for (i = 0; i < N; i++) cin >> T[i];
	for (i = 0; i < N; i++) cin >> A[i];
	vl M(N);
	ll t = -1;
	for (i = 0; i < N; i++) {
		if (t < T[i]) {
			M[i] = -1;
			t = T[i];
		}
		else {
			M[i] = T[i];
		}
	}
	//debug(M);
	ll a = -1;
	for (i = N - 1; i >= 0; i--) {
		if (a < A[i]) {
			if (M[i] == -1 && A[i] != T[i]) {
				cout << 0;
				exit(0);
			}
			else if (M[i] != -1 && M[i] < A[i]) {
				cout << 0;
				exit(0);
			}
			else {
				M[i] = -1;
				a = A[i];
			}
		}
		else {
			M[i] = min(A[i],M[i]);
		}
	}
	//debug(M);
	ans = 1;
	for (i = 0; i < N; i++) {
		if (M[i] >= 1) {
			(ans *= M[i]) %= MOD;
		}
	}
	cout << ans;
}

Measured memory_bytes: 2560
N=int(input())
A=list(map(int,input().split()))
B=[0]*3
mod=10**9+7

ans=1
for i in range(N):
    cnt=0
    idx=-1
    for j in range(3):
        if A[i]==B[j]:
            cnt+=1
            idx=j
    ans=ans*cnt
    ans=ans%mod
    B[idx]+=1
print(ans)


Measured memory_bytes: 20820