akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
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;}
using Int = long long;
const char newl = '\n';


template<typename T>
struct Rint{
  static T mod;
  static void set_mod(T nmod){mod=nmod;}

  T v;
  Rint():v(0){}
  Rint(signed v):v(v){}
  Rint(long long t){v=t%mod;if(v<0) v+=mod;}

  Rint pow(long long k){
    Rint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Rint add_identity(){return Rint(0);}
  static Rint mul_identity(){return Rint(1);}

  Rint inv(){return pow(mod-2);}

  Rint& operator+=(Rint a){v+=a.v;if(v>=mod)v-=mod;return *this;}
  Rint& operator-=(Rint a){v+=mod-a.v;if(v>=mod)v-=mod;return *this;}
  Rint& operator*=(Rint a){v=1LL*v*a.v%mod;return *this;}
  Rint& operator/=(Rint a){return (*this)*=a.inv();}

  Rint operator+(Rint a) const{return Rint(v)+=a;}
  Rint operator-(Rint a) const{return Rint(v)-=a;}
  Rint operator*(Rint a) const{return Rint(v)*=a;}
  Rint operator/(Rint a) const{return Rint(v)/=a;}

  Rint operator-() const{return v?Rint(mod-v):Rint(v);}

  bool operator==(const Rint a)const{return v==a.v;}
  bool operator!=(const Rint a)const{return v!=a.v;}
  bool operator <(const Rint a)const{return v <a.v;}
};
template<typename T> T Rint<T>::mod;
template<typename T>
ostream& operator<<(ostream &os,Rint<T> m){os<<m.v;return os;}

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

  Int n;
  cin>>n;
  string x;
  cin>>x;

  Int base=count(x.begin(),x.end(),'1');

  const Int MAX = 3e5;
  vector<Int> dp(MAX);
  for(Int i=1;i<MAX;i++)
    dp[i]=dp[i%__builtin_popcount(i)]+1;

  vector<Int> ans(n);
  using R = Rint<Int>;
  {
    Int cnt=base+1;
    R::set_mod(cnt);
    R res=0;
    for(Int i=0;i<n;i++)
      res=res*2+R(x[i]-'0');

    for(Int i=0;i<n;i++){
      if(x[i]!='0') continue;
      R tmp=res+R(2).pow(n-(i+1));
      ans[i]=dp[tmp.v]+1;
    }
  }
  {
    Int cnt=base-1;
    if(cnt==0){
      for(Int i=0;i<n;i++){
        if(x[i]!='1') continue;
        ans[i]=0;
      }
    }else{
      R::set_mod(cnt);
      R res=0;
      for(Int i=0;i<n;i++)
        res=res*2+R(x[i]-'0');
      for(Int i=0;i<n;i++){
        if(x[i]!='1') continue;
        R tmp=res-R(2).pow(n-(i+1));
        ans[i]=dp[tmp.v]+1;
      }
    }
  }
  for(Int i=0;i<n;i++) cout<<ans[i]<<newl;
  return 0;
}


Measured memory_bytes: 7568
use proconio::{input, fastout};

const MOD: usize = 1_000_000_007;

#[fastout]
fn main() {
    input! {
        n: usize,
        mut arr: [usize; n],
    }

    arr.sort();
    let mut it = arr.iter();

    let mut ans = 1;

    let r = if n%2==0 {
        n/2
    } else {
        match *it.next().unwrap() {
            0 => (n-1)/2,
            _ => { ans = 0; 0 },
        }
    };

    for _ in 0..r {
        let a_2i = it.next().unwrap();
        let a_2i1 = it.next().unwrap();
        if a_2i != a_2i1 { ans=0; break; }
        ans = ans*2 % MOD;
    }

    println!("{}", ans);
}


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

int main(){
  int n,m; cin>>n>>m;
  vector<int> h(n);
  for (int i=0; i<n; i++) cin>>h[i];
  
  vector<vector<int>> tree(n);
  for (int i=0; i<m; i++){
    int a,b; cin>>a>>b;
    a-=1;
    b-=1;
    tree[a].push_back(h[b]);
    tree[b].push_back(h[a]);
  }
  
  int ans=0;
  for (int i=0; i<n; i++){
    int h_i=h[i];
    bool ok=true;
    for (int t_h : tree[i]) if (h_i<=t_h) ok=false;
    if (ok) ans+=1;
  }
  cout<<ans<<endl;
}

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

int main(){
  int a, b, c, tmp;

  cin >> a >> b >> c;

  if (b > c) {
    tmp = b;
    b = c;
    c = tmp;
  }

  if (a > b) {
    tmp = a;
    a = b;
    b = tmp;
  }

  if (b > c) {
    tmp = b;
    b = c;
    c = tmp;
  }

  cout << a << " " << b << " " << c << endl;

  return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#include<iterator>
using namespace std;
typedef long long int lli;
int main()
{
   string s,t;
   cin >> s >> t;
   lli n = s.length();
   lli m = t.length();
//    cout << n <<m;
   int arr[n+2][m+2];
   int m1 =0;
   for(lli i=0;i<= n ;i++)
   {
       for(lli j=0;j<=m;j++)
       {
           if(i ==0 || j==0)
           {
               arr[i][j]=0;
           }
           else
           {
               lli f=0;

               if(s[i-1] == t[j-1] )
               {
                   f=1;
               }
               int y1 = arr[i-1][j-1]+f;
               int y2 = max(arr[i-1][j] , arr[i][j-1]);
        
               arr[i][j]= max(y1,y2);
          
           }
        //   cout << arr[i][j]<<" ";
       }
    //    cout << endl;
   }
   vector <char > ans;
   int i= n,j=m,a=0;
   while(1)
   {
       if(s[i-1] == t[j-1])
       {
           ans.push_back(s[i-1]);
           a++;
        //    cout << s[i-1];
           i-=1;j-=1;
       }
       else
       {
           if(arr[i-1][j] >= arr[i][j-1])
           {
               i-=1;
           }
           else
           {
               j-=1;
           }
           
       }
       if(i<1 || j<1)
       {
           break;
       }
       
   }
   for(int i=a-1;i>=0;i--)
   {
       cout << ans[i];
   }
   cout << endl;
    
}
   


Measured memory_bytes: 35456
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,d,a,sum=0;
    cin>>n;
    a=n;
    while(a>0){
    d=a%10;
    sum=sum+d;
    a=a/10;
    }
    if(n%sum==0)
    printf("Yes\n");
    else
    printf("No\n");
    return 0;
}


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

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	vector<int> a(n + 1);
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	int ans[100][100];
	int sum = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= a[i]; j++) {
			ans[sum / w][sum % w] = i;
			sum++;
		}
	}
	for (int i = 0; i < h; i++) {
		if (i % 2 == 0)
			for (int j = 0; j < w; j++)
				cout << ans[i][j] << " ";
		else
			for (int j = w - 1; j >= 0; j--)
				cout << ans[i][j] << " ";
		cout << endl;
	}
	return 0;
}

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

int main() {
  string s;
  cin >> s;
  
  reverse(s.begin(), s.end());
  
  while(s.size() >= 5){
    if(s.substr(0, 5) == "maerd" || s.substr(0, 5) == "esare"){
      s = s.substr(5, s.size() - 5);
    }
    else if(s.substr(0, 6) == "resare"){
      s = s.substr(6, s.size() - 6);
    }
    else if(s.substr(0, 7) == "remaerd"){
      s = s.substr(7, s.size() - 7);
    }
    else break;
  }
  
  if(s.size() == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <random>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define repp(i,n,m) for (int i = m; i < (n); ++i)
#define repl(i,n) for (long long i = 0; i < (n); ++i)
#define reppl(i,n,m) for (long long i = m; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PL = pair<long long, long long>;
using Pxy = pair<double, double>;
using T = tuple<int, int, bool>;
const int INF = 1001001007;
const int MOD = 1000000007;
//const int MOD = 998244353;
const ll inf = 1e18;
template <typename AT>
void printvec(vector<AT> &ar){
    rep(i,ar.size()-1) cout << ar[i] << " ";
    cout << ar[ar.size()-1] << endl;
}
template <typename Q>
void printvvec(vector<vector<Q>> &ar){
    rep(i,ar.size()){
        rep(j,ar[0].size()-1) cout << ar[i][j] << " ";
        cout << ar[i][ar[0].size()-1] << endl;
    }
}
template <typename S>
bool range(S a, S b, S x){
    return (a <= x && x < b);
}

int main() {
    int n; cin >> n;
    int a = n % 10;
    if(n % 10 == 3) cout << "bon" << endl;
    else if (a == 0 || a == 1 || a == 6 || a == 8) cout << "pon" << endl;
    else cout << "hon" << endl;
}

Measured memory_bytes: 3624
#include "bits/stdc++.h"
#include <set>

using namespace std;
#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 rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}


signed main(void) {
	int n;
	cin >> n;
	vector<int>a(n);
	rep(i, n) {
		cin >> a[i];
	}
	int ans = 0;
	rep(i, n) {
		if (i % 2 == 0 && a[i] % 2 == 1)ans++;
	}
	print(ans);
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}
	cout << accumulate(p.begin(), p.end(), 0) - *max_element(p.begin(), p.end()) / 2 << endl;
	return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  const int L = 40000;

  int N;
  cin >> N;
  ++N;
  vint p(N);
  reps(i, 1, N) cin >> p[i];
  vint a(N);
  vint b(N);
  reps(i, 1, N) {
    a[i] = L*i;
    b[i] = L*(N-i);
  }
  reps(i, 1, N) a[p[i]] += i;
  /*
  reps(i, 1, N) {
    cout << a[p[i]]+b[p[i]] << endl;
  }
  */
  reps(i, 1, N) cout << a[i] << " \n"[i==N-1];
  reps(i, 1, N) cout << b[i] << " \n"[i==N-1];

  return 0;
}


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

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

int n,t,c,pos,vis[200010],sz=0;
string s;
vector <int> v;

int main()
{
	cin>>n>>t>>c>>s;
	pos=0;
	while(s[pos]=='x') pos++;
	while(pos<n)
	{
		sz++;
		vis[pos]=sz;
		pos+=c+1;
		while(pos<n&&s[pos]=='x') pos++;
	}
	pos=n-1;
	while(s[pos]=='x') pos--;
	while(pos>=0)
	{
		v.pb(pos);
		pos-=c+1;
		while(pos>=0&&s[pos]=='x') pos--;
	}
	reverse(v.begin(),v.end());
	rep(i,n)
	{
		if(vis[i]==0) continue;
		int cur=vis[i]-1,pos=upper_bound(v.begin(),v.end(),i)-v.begin();
		if(cur+v.size()-pos<t) cout<<i+1<<endl;
	}
	return 0;
}

Measured memory_bytes: 3448
#include <bits/stdc++.h>
#define endl '\n'
#define FAST_IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define IT set<node>::iterator
#define mem(a) memset(a,0,sizeof(a))
typedef long long LL;
typedef long long ll;
using namespace std;
const int N = 1e6 + 5;
const int mod = 1e9 + 7;
bool isprime[N];
int prime[N], tot;
void init() {
  for(int i = 2; i <= 1e6; i++) {
    if(!isprime[i]) {
      prime[++tot] = i;
      for(int j = 2 * i; j <= 1e6; j += i) {
        isprime[j] = true;
      }
    }
  }
}
ll vis[N], a[N];
int main() {
  init();
  ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  int n; cin >> n;
  isprime[1] = 1;
  for(int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  ll d = __gcd(a[1], a[2]);
  for(int i = 3; i <= n; i++) d = __gcd(d, a[i]);
  if(d > 1) {
    cout << "not coprime\n";
    return 0;
  }
  for(int i = 1; i <= n; i++) {
    if(!isprime[a[i]]) {
      vis[a[i]]++;
      continue;
    }
    int len = sqrt(a[i]);
    for(int j = 1; j <= tot && prime[j] <= len; j++) {
      if(a[i] % prime[j] == 0) {
        vis[prime[j]]++;
        if(!isprime[a[i] / prime[j]] && a[i] / prime[j] != prime[j]) {
          vis[a[i] / prime[j]]++;
        }
      }
    }
  }
  int flag1 = 0, flag2 = 0;
  for(int i = 1; i <= tot; i++) {
    //cout << vis[prime[i]] << ' ' << prime[i] << "\n";
    if(vis[prime[i]] > 1) {
      flag1 = 1;
    }
    if(vis[prime[i]] == n) {
      flag2 = 1;
    }
  }
  if(!flag1) {
    cout << "pairwise coprime\n";
  } else if(flag1 && !flag2) {
    cout << "setwise coprime\n";
  }

  return 0;
}


Measured memory_bytes: 20400
#include <cstdio>

int main() {
	int A, B, C, D;
	scanf("%d %d %d %d", &A, &B, &C, &D);
	if (A+B > C+D)
		printf("Left\n");
	else if (C+D > A+B)
		printf("Right\n");
	else
		printf("Balanced\n");
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int r,g,b,nm;
    cin >> r >> g >> b;
    nm = 100*r + 10*g + b;
    if(nm%4==0) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 256
import numpy as np
N, K = map(int, input().split())
mod = 1000000007

m = N ** 0.5
cnt = [N // i - N // (i + 1) for i in range(1, int(m) + 1)] 
cnt = np.array((cnt + [1 for _ in range(N - sum(cnt))])[::-1])
nxt = cnt[:]
for _ in range(K - 1):
    cnt = nxt * np.cumsum(cnt)[::-1] % mod

print(sum(cnt) % mod)


Measured memory_bytes: 14680
import java.util.*

fun main(vararg args: String) {
    val scanner = Scanner(System.`in`)
    val pieces = scanner.nextInt()
    val numOfObjectives = scanner.nextInt()
    val coordinateList = mutableListOf<Int>()
    val distances = mutableListOf<Int>()
    for (i in 0 until numOfObjectives) {
        coordinateList.add(scanner.nextInt())
    }
    coordinateList.sort()

    if (pieces >= numOfObjectives) {
        println(0)
        return
    }

    for ( i in 0 until coordinateList.size - 1) {
        distances.add(coordinateList[i + 1] - coordinateList[i])
    }
    distances.sort()

    val answer = distances.subList(0, distances.size - (pieces - 1)).sum()
    println(answer)
}

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

int main() {
  int a, b;
  cin >> a >> b;
  a *= 10;
  b *= 10;
  int x = (a + b) / 2;
  if (x % 10 > 0) {
    x = x + 10 - x % 10;
  }
  x /= 10;
  cout << x << endl;
  return 0;
}


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

ll INF = 1LL << 60;

int 
main() {

  int H, W;
  cin >> H >> W;
  vector<vector<char>> vec(H);
  vector<vector<int>> up(H, vector<int>(W)), down(H, vector<int>(W)), left(H, vector<int>(W)), right(H, vector<int>(W));

  rep(i, 0, H){
    rep(k, 0, W){
      char c; cin >> c;
      vec[i].push_back(c);
    }
  }

  rep(k, 0, W){
    int nup = 0;
    rep(i, 0, H - 1){
      if(vec[i][k] == '#') nup = 0;
      else ++nup;
      if(vec[i + 1][k] == '#') up[i + 1][k] = 0;
      else up[i + 1][k] = nup;
    }
  }

  rep(k, 0, W){
    int ndown = 0;
    for(int i = H - 1; i > 0 ; --i){
      if(vec[i][k] == '#') ndown = 0;
      else ++ndown;
      if(vec[i - 1][k] == '#') down[i - 1][k] = 0;
      else down[i - 1][k] = ndown;
    }
  }

  rep(i, 0, H){
    int nleft = 0;
    rep(k, 0, W - 1){
      if(vec[i][k] == '#') nleft = 0;
      else ++nleft;
      if(vec[i][k + 1] == '#') left[i][k + 1] = 0;
      else left[i][k + 1] = nleft;
    }
  }

  rep(i, 0, H){
    int nright = 0;
    for(int k = W - 1; k > 0; k--){
      if(vec[i][k] == '#') nright = 0;
      else ++nright;
      if(vec[i][k - 1] == '#') right[i][k - 1] = 0;
      else right[i][k - 1] = nright;
    }
  }


  int maxi = 0;
  rep(i, 0, H){
    rep(k, 0, W){
      if(vec[i][k] == '#') continue;
      int comp = 1 + up[i][k] + down[i][k] + left[i][k] + right[i][k];
      if(maxi < comp) maxi = comp;
    }
  }

  cout << maxi << endl;

}

Measured memory_bytes: 70392
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define LLINF 9223372036854775807
#define MOD ll(1e9+7)

int main() {
    double a, b, c;
    cin >> a >> b >> c;
    double s = (a+b+c)/2;
    cout << int(sqrt(s*(s-a)*(s-b)*(s-c))) << endl;

    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
int inf = numeric_limits<int>::max() / 2;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> a(n);
	for(int i = 0;i < n; i++){
		cin >> a[i];
		a[i] -= i;
	}
	sort(a.begin(), a.end());
	int b = a[n/2];
	ll ans = 0;
	for(int i = 0; i < n; i++){
		ans += abs(a[i] - b);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
N,K = map(int, input().split())
A = list(map(int, input().split()))
L = 46
cnt = [0] * L

for a in A:
    for i in range(L):
        if a & (1 << i):
            cnt[i] += 1


# dp[i+1][j] : Kの左からi番目まで見たときに、j=1でK未満にXを設定、そこまでのf()の最大値。その状況があり得ない場合を考えて、-1で初期化した。
dp = [[-1 for _ in range(2)] for _ in range(L + 1)]
dp[0][0] = 0

for i in range(L):

    p0 = pow(2, L-1 - i) * cnt[L-1 - i]
    p1 = pow(2, L-1 - i) * (N - cnt[L-1 - i])

    if K & (1 << (L-1 - i)):
        is_one = True
    else:
        is_one = False

    # 未満　→　未満：01両方OK
    if dp[i][1] != -1:
        dp[i+1][1] = dp[i][1] + max(p0, p1)

    # 一致　→　未満：一致しないように気を付ける
    if dp[i][0] != -1:
        if is_one:
            dp[i+1][1] = max(dp[i+1][1], dp[i][0] + p0)

    # 一致　→　一致：一致させるだけ
    if dp[i][0] != -1:
        if is_one:
            dp[i+1][0] = dp[i][0] + p1
        else:
            dp[i+1][0] = dp[i][0] + p0


print(max(dp[-1]))


Measured memory_bytes: 68696
use std::vec::Vec;
use std::cmp;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (x, y, z, k) = {
      let v: Vec<i64> = read_vec();
      (v[0], v[1], v[2], v[3])
    };


    let a: Vec<i64> = read_vec();
    let b: Vec<i64> = read_vec();
    let c: Vec<i64> = read_vec();
    let mut v: Vec<i64> = Vec::new();

    for &e1 in &a {
      for &e2 in &b {
        v.push(e1+e2);
      }
    }
    v.sort_by(|a, b| b.cmp(a));

    let mut res: Vec<i64> = Vec::new();
    let vup: usize = cmp::min(v.len(), k as usize);
    let cup: usize = cmp::min(c.len(), k as usize);

    for i in 0..vup {
      for j in 0..cup {
          res.push(v[i] + c[j]);
      }
    }
    res.sort_by(|a, b| b.cmp(a));

    for i in 0..k as usize {
      println!("{}", res[i]);
    }

}


Measured memory_bytes: 44276
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    float ans;
    for (int i = 0; i < n; ++i) {
        float mon = 0;
        string jj;
        cin >> mon >> jj;
        if(jj == "JPY"){
            ans += mon;
        } else{
            ans += mon * 380000;
        }
    }

    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdint>
#include <bitset>

using i64 = int64_t;
using i32 = int32_t;

void run() {
    i32 h, w;
    std::cin >> h >> w;
    std::vector<std::vector<i32>> a;
    for (i32 i = 0; i < h; ++i) {
        std::vector<i32> b;
        for (i32 j = 0; j < w; ++j) {
            i32 v;
            std::cin >> v;
            b.emplace_back(v);
        }
        a.push_back(b);
    }
    for (auto& b : a) {
        for (auto& c : b) {
            i32 d;
            std::cin >> d;
            c -= d;
            c = std::abs(c);
        }
    }
    const i32 m = (80 + 80) * 80;
    using bits = std::bitset<2 * m + 1>;
    std::vector<bits> now(w);
    now.at(0).set(m);
    for (const auto& b : a) {
        std::vector<bits> next;
        bits prev(0);
        for (i32 i = 0; i < w; ++i) {
            i32 d = b.at(i);
            bits val = prev | now.at(i);
            bits ans = (val << d) | (val >> d);
            next.push_back(ans);
            prev = ans;
        }
        now = next;
    }
    i32 ans = m;
    bits& cond = now.at(w - 1);
    for (i32 i = 0; i <= 2 * m; ++i) {
        if (cond.test(i)) {
            ans = std::min(ans, std::abs(m - i));
        }
    }
    std::cout << ans << '\n';
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    run();
    return 0;
}


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

int main()
{
	ll N;
	cin >> N;
	for (int i = 1; i <= 3500; i++) {
		for (int j = 1; j <= 3500; j++) {
			if (4 * i * j - N * i - N * j != 0) {
				if ((N * i * j) % (4ll * i * j - N * i - N * j) == 0) {
					if ((N * i * j) / (4 * i * j - N * i - N * j) > 0) {
						cout << i << " " << j << " " << (N * i * j) / (4 * i * j - N * i - N * j) << endl;
						return 0;
					}
				}
			}
		}
	}
}


Measured memory_bytes: 256
"use strict";
function Main(input) {
    var lines = input.split("\n");
    var N = lines.shift() - 0;
    var ab = new Array(N);
    for (var n = 0; n < N; n++) {
        var nums = lines[n].split(" ");
        ab[n] = {
            t : nums[0] - 0,
            a : nums[1] - 0,
        };
        ab[n].wa = ab[n].t + ab[n].a;
    }
    ab.sort(function(a, b) { return b.wa - a.wa; });
    var ans = 0;
    for (var n = 0; n < N; n++) {
        ans += (n % 2 == 0) ? ab[n].t : - ab[n].a;
    }
    console.log(ans);
}

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


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

int gcd(int a,int b){
    int c;
    if(a<b){
        a+=b;
        b=a-b;
        a-=b;
    }
    while(b!=0){
        c=a%b;
        a=b;
        b=c;
    }
    return a;
}
 
int main(){
    int data0,data1;
    int answer;
    while(cin>>data0>>data1){
        answer=gcd(data0,data1);
        cout<<answer<<" "<<data0/answer*data1<<endl;
    }
}

Measured memory_bytes: 3036
n = int(input())
T = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
p = 10 ** 9 + 7

B = [10**9] * n

h = 0

for i, t in enumerate(T):
    if h < t:
        B[i] = 1
        h = t
    else:
        B[i] = h

h = 0

for i, a in zip(range(n-1, -1, -1), A[::-1]):
    if h < a:
        if a > T[i] or (B[i] == 1 and a != T[i]):
            print(0)
            exit(0)
        B[i] = 1
        h = a
    elif B[i] == 1 and T[i] > a:
        print(0)
        exit(0)
    elif B[i] > h:
        B[i] = h

ans = 1

for b in B:
    ans *= b
    ans %= p

print(ans)

Measured memory_bytes: 19776
#include <iostream>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <chrono>
#include <math.h>
using namespace std;

using lli = long long int;
using Vint = std::vector<int>;
using Vlli = std::vector<lli>;
using Wint = std::vector<Vint>;
using Wlli = std::vector<Vlli>;
using Vbool = std::vector<bool>;
using pii = std::pair<int, int>;
using pll = std::pair<lli, lli>;

constexpr int MOD = 1e9 + 7;
constexpr int INFi = 2e9 + 1;
constexpr lli INFl = (lli)(9e18) + 1;
const vector<pii> DXDY = {std::make_pair(1, 0), std::make_pair(-1, 0), std::make_pair(0, 1), std::make_pair(0, -1)};
constexpr char BR = '\n';

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); (i)++)
#define FOReq(i, a, b) for(int (i) = (a); (i) <= (b); (i)++)
#define rFOR(i, a, b) for(int (i) = (b); (i) >= (a); i--)
#define FORstep(i, a, b, step) for(int (i) = (a); i < (b); i += (step))
#define REP(i, n) FOR(i, 0, n)
#define rREP(i, n) rFOR(i, 0, (n-1))
#define vREP(ele, vec) for(auto &(ele) : (vec))
#define vREPcopy(ele, vec) for(auto (ele) : (vec))
#define SORT(A) std::sort((A).begin(), (A).end())
// 座標圧縮 (for vector) : ソートしてから使うのが一般的 ; SORT(A) => COORDINATE_COMPRESSION(A)
#define COORDINATE_COMPRESSION(A) (A).erase(unique((A).begin(),(A).end()),(A).end())



template <class T> inline int argmin(std::vector<T> vec){return min_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline int argmax(std::vector<T> vec){return max_element(vec.begin(), vec.end()) - vec.begin();}
template <class T> inline void chmax(T &a, T b){a = max(a, b);}
template <class T> inline void chmin(T &a, T b){a = min(a, b);}
inline int toInt(string &s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline int toInt(const string s){int res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(string &s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
inline long long int toLong(const string s){lli res = 0; for(char a : s) res = 10 * res + (a - '0'); return res;}
template <class T> inline std::string toString(T n){
  if(n == 0) return "0";
  std::string res = "";
  if(n < 0){n = -n;while(n != 0){res += (char)(n % 10 + '0'); n /= 10;}
  std::reverse(res.begin(), res.end()); return '-' + res;}
  while(n != 0){res += (char)(n % 10 + '0'); n /= 10;} std::reverse(res.begin(), res.end()); return res;
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~



int main(void){
  std::map<std::string, int> Data;
  int n, m; std::string s;
  cin >> n;
  REP(_, n){
    cin >> s;
    Data[s]++;
  }
  cin >> m;
  REP(_, m){
    cin >> s;
    Data[s]--;
  }
  int res = 0;
  vREP(ele, Data) if(ele.second > res) res = ele.second;
  printf("%d\n", res);
  return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

int main(int argc, char *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N;
    cin >> N;

    int ans = 0;
    rep (i, N) {
        int a;
        cin >> a;

        ans ^= a;
    }

    if (ans) {
        No;
    } else {
        Yes;
    }
    return 0;
}

Measured memory_bytes: 892
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;

int main(){

  string a;
  cin>>a;

  cout<<"2018/01/";
  for(int i=8;i<10;i++){
    cout<<a[i];
  }
  cout<<endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
using namespace std;
#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
typedef long long ll;
typedef pair<ll,ll> pll;
typedef long double ld;
const ll inf=1e9+7;
const ll mod=1e9+7;
signed main(){
    string x;cin>>x;
    ll cnt=0;
    ll n=x.size();
    ll now=0;
    rep(i,n){
        if(x[i]=='S')now++;
        else{
            if(now==0)cnt++;
            else{
                now--;
            }
        }
    }
    cout<<cnt*2<<endl;
}

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

#define  BeatMeScanf  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define  tc(x)        int x; cin >> x; while(x--)
#define  ll           long long
#define  vi           vector<int>
#define  pii          pair<int,int>
#define  mii          map<int,int>
#define  inf          1<<28
#define  mem(x,y)     memset(x, y, sizeof(x))
#define  ps(x,y)      fixed<<setprecision(y)<<x
#define  show(val)    cout<< #val << " -> " << val << endl
#define  Case         cout<< "Case "<< ++cs << ": "
#define  all(v)       (v).begin(), (v).end()
#define  rall(v)      (v).rbegin(), (v).rend()
#define  MOD          1000000007
#define  MAX          100005

int main()
{
    BeatMeScanf;
    string str;
    cin >> str;
    
    int sz = str.size() - 1;

    if(str[sz] == '3') cout << "bon" << '\n';
    else if(str[sz] == '0' || str[sz] == '1' || str[sz]=='6' || str[sz]=='8') cout << "pon" << '\n';
    else cout << "hon" << '\n';
    return 0;
}


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


using namespace std;


int main() {
    int d, l, r;
    cin >> l >> r >> d;
    int cnt = 0;
    for (int i = l; i <= r; ++ i) {
        if (i % d == 0) {
            cnt += 1;
        }
    }
    cout << cnt << '\n';
    return 0;
}

Measured memory_bytes: 3620
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
count = 0
for i in range(N):
    num = 0
    A = list(map(int, input().split()))
    for i in range(M):
        num += A[i]*B[i]
    num += C
    if num > 0:
        count += 1
print(count)   

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

int main() {
  string s;
  cin >> s;
  int ans = 0;
  char prev = s[0];
  rep(i, 1, 3) {
    if (prev == s[i] && s[i] == 'R') ans++;
    prev = s[i];
  }
  int r_cnt = 0;
  for (char c : s)
    if (c == 'R') r_cnt++;
  if (r_cnt > 0)
    cout << ans + 1 << endl;
  else
    cout << ans << endl;
  return 0;
}


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

#define int           long long
#define S             second
#define F             first
#define pb            push_back
#define ppb           pop_back()
#define ppb           pop_back()
#define B(c)          (c).begin()
#define E(c)          (c).end()
#define all(c)        (c).begin(),(c).end()
#define rall(c)       (c).rbegin(),(c).rend() 
#define lb            lower_bound
#define si(c)         (int)((c).size())
#define lcm(a,b)      (a * (b / __gcd(a,b)))  
#define inf           (int)(2e18)
#define err           cerr << "move" << '\n';
#define endl          '\n'
#define pow(x, n)     (int)(pow(x, n))
#define mp            make_pair

typedef vector<int>                           vi;
typedef pair<int,int>                         pii;
typedef vector<pii>                           vpi;
typedef priority_queue<pii, vector<pii>, greater<pii> > pq;

clock_t start;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

const int N = 1e6+10;
int dp[N];

struct lline{
    int m, c;
}line[4*N], nw_line;

int fun(lline nw_line, int x){
    return nw_line.m*x + nw_line.c;
}

struct LiChao{
    LiChao(){
        for(int i = 0; i < N; i++){
            line[i].m = 0, line[i].c = inf;
        }
    }
    void add_line(int v, int l, int r, lline nw_line){
        int m = (l+r)/2;
        bool md = fun(nw_line, m) < fun(line[v], m);
        bool lf = fun(nw_line, l) < fun(line[v], l);
        if(md) swap(nw_line, line[v]);
        if(r-l == 1) return;
        if(lf != md)add_line(2*v, l, m, nw_line);
        else add_line(2*v+1, m, r, nw_line);
    }

    int get_min(int v, int l, int r, int x){
        int m = (l+r)/2;
        if(r-l == 1)return fun(line[v], x);
        if(x >= m) return min (fun(line[v], x), get_min(2*v+1, m, r, x));
        else return min(fun(line[v], x), get_min(2*v, l, m, x));
    }
    
}Lct;

void solve(){
    int n, c;
    cin >> n >> c;
    int h[n+1];
    for(int i = 1; i <= n; i++){
        cin >> h[i];
    }
    lline nw_line = {-2*h[1], h[1]*h[1]};
    Lct.add_line(1, 1, n, nw_line);
    for(int i = 2; i <= n; i++){
        dp[i] = c+h[i]*h[i] + Lct.get_min(1, 1, N, h[i]);
        nw_line = {-2*h[i], dp[i]+h[i]*h[i]};
        Lct.add_line(1, 1, N, nw_line);
    }
    cout << dp[n] << endl;
}

signed main(){

    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);   

    int t = 1;
    start = clock(); 

    cout << fixed << setprecision(15);

    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin); 
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif*/
    
    // cin >> t;
    
    while(t--){
        solve();
    }

    double time_taken = double(clock() - start) / double(CLOCKS_PER_SEC); 
    cerr << time_taken;
}

Measured memory_bytes: 40704
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            int mod = 1000000007;
            long[] dp = new long[2010];
            long[] sumdp = new long[2010];
            var s = int.Parse(Console.ReadLine());
            long sum = 0;
            for (int i = 0; i < s; i++)
            {
                sum += dp[i];
                sum %= mod;
                sumdp[i] += sum;
                sumdp[i] %= mod;
                dp[i + 3] = sumdp[i] + 1;
            }
            Console.WriteLine(dp[s]);
        }
    }
}

Measured memory_bytes: 27512
###template###
import sys
def input(): return sys.stdin.readline().rstrip()
def mi(): return map(int, input().split())
###template###

N, Q = mi()

Events = []
#イベントを格納する配列
#各要素はタプルで、(s-x or t-x, 1or-1, x)が入っている
#意味は、「時間s-xもしくはt-xに出発する人が」「座標xで」
# 「1:通行止めにぶつかる -1:通行止めにぶつかりそうだったが、助かる」を表す

for _ in range(N):
  s, t, x = mi()
  #1つめの要素がマイナスになることはないので、max(0, hoge)をとる。
  #どちらもマイナスといったコーナーケースでも、「0で通行止めになり0で解除される」となってから時間0に出発する人が処理されるので、影響は出ない
#……と思っていたけど、0になるイベントが複数あると、集合への出し入れがおかしくなる（0を複数入れたあと複数回だそうとするから、無いキーを出そうとしてしまう）
#時間がマイナスでもコード上全く問題無いんだから、外した！
  Events.append((s-x, 1, x))
  Events.append((t-x, -1, x))

#イベント配列は「影響を受ける人（の出発時間）」で降順ソートする
#降順ソートなので、pop()でとっていく
from operator import itemgetter
Events = sorted(Events, key=lambda x:-x[1])
Events = sorted(Events, key=lambda x:-x[0])
#発生タイミング（x[0]）が同じイベントは、集合からのout→inでも並び替える（x[1]について降順）。
#outより先にinが行われると、集合操作がおかしくなる

#イベント配列ができたので、今度は各人について処理していく
#出力する答えはAnss配列に入れていき、最後にfor文で一気に出力する
Anss = []

#制約より、Diは最初から昇順ソートされている
Ds = [int(input()) for _ in range(Q)]

nowkeptout = set() #今通行止めになっている座標を格納するset。常に昇順ソートする
nextevent = Events.pop()  #次に見るイベント
minstop = 10**9+1
for d in Ds:
  #各ループにおいて、「未処理の人のうち、最も出発時間が早い人」がdに入る
  #ということは、時間dまでのEventsを全て処理すれば、その人がぶつかる場所が分かる
  while nextevent[0]<=d: #dを越えたら止まるし、イベントがなくなっても番兵で止まる
    a, b, c = nextevent
    if b==1: #座標xが通行止めになる
      nowkeptout.add(c)
      minstop = min(c, minstop)
    else: #座標xの通行止めが解除される
      nowkeptout.remove(c)
      if c==minstop and nowkeptout: minstop = min(nowkeptout)
      elif not nowkeptout: minstop = 10**9+1
    try: nextevent = Events.pop()
    except:
      nextevent = (10**9+1, 1, 1) #要素がなくなったらもう処理が起きないようにする
      break
  #この時点で、nowkeptoutに値が入っている場合も、入っていない場合もある
  #値が入っていれば、dはその最小値の座標で通行止めにぶつかる
  #値が入っていなければ歩き続けるので、-1にする
  if nowkeptout: Anss.append(minstop)
  else: Anss.append(-1)

for ans in Anss:
  print(ans)



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

    string S;
    cin >> S;
    int N=S.size();
    int flag=0;
    for(int i=0; i<N/2; i++){
        if(S.at(i) != S.at(N-1-i) || S.at(i) != S.at((N+1+(2*i))/2)){
        flag=1;
        break;
        }
        
    }

    if(flag==1){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }

}



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

using namespace std;

typedef long long ll;

int r,c,tujuan,x;
ll temp;

int main(){
		cin>>r>>c;
		int dist[10];
		int w[10][10];
        memset(w,-1,sizeof(w));
		for (int i = 0; i <= 9; ++i)
		{
			dist[i] = INT_MAX;
		}
		for (int i = 0; i <= 9; ++i)
		{
			for (int j = 0; j<=9; j++ ){
				cin>>w[i][j];
			}
		}
		priority_queue<pair<ll,ll>> pq;
		dist[1] = 0;
		pq.push(make_pair(-dist[1],1));
		while(!pq.empty()){
			x = pq.top().second;
			pq.pop();
            for (int i = 0; i<=9; i++){
                if (dist[i]>w[i][x] + dist[x]){
                    dist[i] = w[i][x]+dist[x];
                    pq.push(make_pair(-dist[i],i));
                }
            }
		}
		ll res = 0;
		for (int i = 0; i < r; ++i)
		{
			for (int j=0; j<c; j++){
				cin>>tujuan;
				if (tujuan!=-1){
					if (tujuan != 1) res+=dist[tujuan];
				}
			}
		}
		cout<<res<<endl;



	return 0;

}


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

int main() {

	int temp;
	int time = 0, min = 10;
	for (int i = 0; i < 5; i++) {
		cin >> temp;
		int mod10 = temp % 10;
		if (mod10 && mod10 < min) min = mod10;

		time += temp / 10 * 10;
		if (mod10) time += 10;
	}

	time = time - 10 + min;
	cout << time;
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const ll mod = 1000000007;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	if(abs(n - m) > 1){
		cout<<0<<endl;
		exit(0);
	}
	ll ans = 1;
	for(int i = 1; i <= n; i++){
		(ans *= i) %= mod;
	}
	for(int i = 1; i <= m; i++){
		(ans *= i) %= mod;
	}
	if((n^m)%2 == 0){
		ans <<= 1;
		if(ans >= mod)ans -= mod;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 505;

int n, p[N * N], x[N], k[N], prior[N];

bool cmp(int A,int B){
	return x[A] < x[B];
}

int main(){
	scanf("%d", &n);
	for(int i = 1;i <= n;i++){
		scanf("%d", x + i), x[i]--;
		prior[i - 1] = i;
	}
	sort(prior, prior + n, cmp);
	for(int i = 0;i < n * n;i++){
		int mora = 0;
		for(int j = 1;j <= n;j++){
			if(i == x[j])
				mora = j;
		}
		if(mora){
			k[mora]++; p[i] = mora;
			continue;
		}
		int naso = 0;
		for(int jj = 0;jj < n;jj++){
			int j = prior[jj];
			if(k[j] < j - 1){
				k[j]++; naso = j;
				break;
			}
		}
		if(!naso){
			for(int j = 1;j <= n;j++){
				if(k[j] != j - 1 && k[j] < n){
					k[j]++; naso = j;
					break;
				}
			}
		}
		if(!naso){
			printf("No\n");
			return 0;
		}
		p[i] = naso;
	}
	printf("Yes\n");
	for(int i = 0;i < n * n;i++)
		printf("%d ", p[i]);
	printf("\n");
}

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

int quant(int x)
{
    if(x<105) return 0;
    int cont = 0,aux;
    rep(i,105,x+1) {
        aux = 0;
        rep(j,1,i+1) {
            if(i%j == 0) aux++;
        }
        if(aux == 8 && i%2 == 1) cont++;
    }
    return cont;
}
int main() {
    int n;
    cin>>n;
    cout<<quant(n)<<endl;

    return 0;
}


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

int main() {
	int m,n,r;
	cin >> m >> n;
	 if (m<n){
	 	swap(m,n);
	 }
	while(n>0){
        r = m % n;
        if(r==0) break;
        m = n;
        n = r;
	}
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define optimizar_io ios_base::sync_with_stdio(false);cin.tie(0);

struct UnionFind {
	
	int numSets;
	int *padre;
	int *rango;
	int *numVertices;

	UnionFind(int N) : numSets(N) {		
		padre = new int[N + 1];
		rango = new int[N + 1];
		numVertices = new int[N + 1];
		for (int i = 0; i <= N; ++i) {
			padre[i] = i;
			rango[i] = 0;
			numVertices[i] = 1;
		}
	}

	int findSet(int x) {
        return (x == padre[x]) ? x : (padre[x] = findSet(padre[x]));
    }

    bool isSameSet(int x, int y) {
       	return findSet(x) == findSet(y);
    }

    void unionSet(int x, int y) {
        int xRoot = findSet(x);
        int yRoot = findSet(y);
		if (!isSameSet(xRoot, yRoot)) {
			if (rango[xRoot] > rango[yRoot]) {
				padre[yRoot] = xRoot;
				numVertices[xRoot] += numVertices[yRoot];
			}
			else {
				padre[xRoot] = yRoot;
				numVertices[yRoot] += numVertices[xRoot];
				if (rango[xRoot] == rango[yRoot])
					rango[yRoot]++;
			}
            numSets--;
        }
    }

    int sizeOfSet(int x) {
    	return numVertices[findSet(x)];
    }
};

int main() {
	optimizar_io
	int N, M, u, v;

	cin >> N >> M;
	UnionFind ds(N);
	for (int i = 0; i < M; i++) {
		cin >> u >> v;
		ds.unionSet(u, v);
	}
	int ans = 1;
	for (int i = 1; i <= N; i++)
		ans = max(ans, ds.sizeOfSet(i));
	cout << ans << "\n";
	return 0;
}

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

using namespace std;

int main(){
    int a, b, k;
    cin >> a >> b >> k;
    int num = 0;
    for(int i = max(a, b); i > 0; i--){
        if (a % i == 0 && b % i == 0) {
            num++;
        }
        if (num == k) {
            cout << i << "\n";
            return 0;
        }
        
    }
    
}

Measured memory_bytes: 256
alpha = ['a', 'b', 'c', 'd', 'e',
         'f', 'g', 'h', 'i', 'j',
         'k', 'l', 'm', 'n', 'o',
         'p', 'q', 'r', 's', 't',
         'u', 'v', 'w', 'x', 'y', 'z']

n = int(input())

ans = n - 1
name = ''
while ans >= 0:
  name += alpha[ans % 26]
  ans //= 26
  ans -= 1

print(name[::-1])

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

int main(void)
{
 int str[3];
 for(int i=0;i<3;i++) cin >> str[i];
 for(int i=0;i<3;i++){
  for(int j=i+1;j<3;j++){
   if(str[i] > str[j]) swap(str[i],str[j]);
  }
 }
 cout << str[0] << " " << str[1] << " "<< str[2] << endl;
 return 0;
}

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

int main()
{
	string x;
	cin >> x;
	int ans = 0;
	for (int i = 0; i < x.size() - 1; i++)
	{
		if (x[i] == x[i + 1])
			ans++;
		else
		{
			if (ans+1 >= 3)
			{
				cout << "Yes" << endl;
				return 0;
			}
			ans = 0;
		}

	}
	if (ans+1 >= 3)
	{
		cout << "Yes" << endl;
		return 0;
	}
	else
		cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	while(true){
		int N;
		cin >> N;
		if (N == 0) break;
		int count = 0;
		bool na =true;
		for (int i = 0; i < N; i++){
			int k;
			cin >> k;
			if(k > 1)
				na = false;
			if (k > 0)
				count++;
		}
		if (na == true)
			cout << "NA" <<endl;
		else
			cout << count + 1 << endl;
	}
  return 0;
}

Measured memory_bytes: 1160
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

auto solve(immutable int n)
{
    int s=0;
    foreach(a;0..10)
        foreach(b;0..10)
            foreach(c;0..10)
                foreach(d;0..10)
                    if(a+b+c+d==n)
                        ++s;
    return s;
}

void main()
{
    stdin.byLine().map!(to!int).map!solve().map!(to!string).join("\n").writeln();
}

Measured memory_bytes: 1084
n = int(input())
arr = list(map(int, input().split()))
e = {-1:0}
o = {-1:0}
for i in range(0, n, 2):
    e[arr[i]] = e.get(arr[i], 0) + 1

for i in range(1, n, 2):
    o[arr[i]] = o.get(arr[i], 0) + 1

#print(n - (max(e.values()) + max(o.values())))

ek = 0
ev = 0
for k in e:
    if ek == 0 or e[k] > ev:
        ek = k
        ev = e[k]

ok = 0
ov = 0
for k in o:
    if ok == 0 or o[k] > ov:
        ok = k
        ov = o[k]

if ok != ek:
    print(n-ev-ov)
else:
    del e[ek]
    del o[ok]
    print(n-max(max(e.values()) + ov, max(o.values()) + ev))

Measured memory_bytes: 58860
// clang-format off
#include <bits/stdc++.h>
#define int long long
#define main signed main()
// #define main int main()
#define loop(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) loop(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define prec(n) fixed << setprecision(n)
#define stlice(from, to) substr(from, (to) - (from) + 1)
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vb> vvb;
typedef vector<vpii> vvpii;
const int INF = sizeof(int) == sizeof(long long) ? 1000000000000000000LL : 1000000000;
const int MOD = 1000000007;
const double PI = acos(-1);
template<typename A, typename B> bool cmin(A &a, const B &b) { return a > b ? (a = b, true) : false; }
template<typename A, typename B> bool cmax(A &a, const B &b) { return a < b ? (a = b, true) : false; }
bool odd(const int &n) { return n & 1; }
bool even(const int &n) { return !odd(n); }
void solve();
main { solve(); return 0; }
// clang-format on

typedef pair<pii, int> ppi;

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

void solve() {
  int h, w, n;
  cin >> h >> w >> n;
  vs s(h);
  vpii v(n + 1);
  rep(i, h) {
    cin >> s[i];
    rep(j, w) {
      if (s[i][j] == 'S') v[0]                               = mp(i, j);
      if ('1' <= s[i][j] && s[i][j] <= '9') v[s[i][j] - '0'] = mp(i, j);
    }
  }
  int c    = 0;
  auto bfs = [&](vs s, pii f, pii t) {
    queue<ppi> q;
    q.push(mp(f, 0));
    while (q.size()) {
      int i = q.front().fi.fi, j = q.front().fi.se, d = q.front().se;
      q.pop();
      if (i < 0 || j < 0 || i >= h || j >= w || s[i][j] == 'X') continue;
      if (i == t.fi && j == t.se) return d;
      s[i][j] = 'X';
      d++;
      rep(k, 4) q.push(mp(mp(i + di[k], j + dj[k]), d));
    }
  };
  loop(i, 1, v.size()) c += bfs(s, v[i - 1], v[i]);
  cout << c << endl;
}

Measured memory_bytes: 4860
using System;
using System.Linq;
namespace ITP1_7_C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] size = Console.ReadLine().Split(' ');
            int r = int.Parse(size[0]);
            int c = int.Parse(size[1]);
            int[] result = new int[r];
            int[][] factor = new int[r][];
            int[] all_factor = new int[c];
            for (int i = 0; i < r; i++)
            {
                factor[i] = Console.ReadLine().Split(' ').Select(x => Convert.ToInt32(x)).ToArray();
                result[i] = MyStruct.AddAll(factor[i]);
            }
            for(int i = 0; i < r; i++)
            {
                foreach (var f in factor[i])
                    Console.Write(f + " ");
                Console.WriteLine(result[i]);
            }
            foreach(var f in factor)
                for (int i = 0; i < c; i++)
                    all_factor[i] += f[i];
            foreach (var a in all_factor)
                Console.Write(a + " ");
            Console.WriteLine(MyStruct.AddAll(result));
        }
    }
    class MyStruct
    {
        static public int AddAll(params int[] data)
        {
            int ret = 0;
            foreach (var d in data)
                ret += d;
            return ret;
        }
    }
}

Measured memory_bytes: 9924