akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

ll water[100000];
ll d[100000];

int main(){
    ll n,sum=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>water[i];
        sum += water[i];
    }
    
    //１つ目を決定する
    d[0] = sum;
    for(int i=1;i<=n-1;i=i+2)
    {
        d[0] -= 2*water[i];   
    }
    cout<<d[0]<<" ";
    for(int i=0;i<n-1;i++)
    {
        d[i+1] = 2*water[i] - d[i];
        cout<<d[i+1]<<" ";
    }

}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
int n , m , q , a[55] , b[55] , c[55] , d[55] , ans , sum , A[11]; 

void dfs(int x , int y){
    if(x > n){
        sum = 0;
        for(int i=0; i<q ;i++ ){
            if(A [ b[i]] - A[ a[i]] == c[i]){
                sum+=d[i];
            }
        }
        ans = max(ans , sum);
    } else {
        for(int i=y; i<=m ;i++ ){
            A[x] = i;
            dfs(x+1 , i);
        }
    }
}

signed main(){
    cin >> n >> m >> q;
    for(int i=0 ;i<q ;i++ ){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    
    dfs(1,1);
    
    cout << ans << endl;
    
    return(0);
}

Measured memory_bytes: 3640
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <new>

using namespace std;

typedef long long ll;

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

int main(){
	ll x,a=0,b=0,c=0,d=0;
	cin >> x;
	a = x/500;
	b=x-a*500;
	c=b/5;
	d=c*5;
	
	cout << a*1000+d << endl;

	return 0;

}

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


int main(){

  int b , r , g , c , s , t , medal = 100;

  while(1){

    cin >> b >> r >> g >> c >> s >> t;
    if( b == 0 && r == 0 && g == 0 && c == 0 && s == 0 && t == 0 ) break;

    medal += 65 * b + 15 * b;
    medal += 39 * r + 15 * r;
    medal += 4 * g;
    medal -= 1 * c;
    medal -= ( t - s - (b * 5) - (r * 3) - g - c ) * 3;

    cout << medal << endl;
    medal = 100;
  }


  return 0;
}

Measured memory_bytes: 1160
import os
from functools import reduce
from operator import mul

import itertools
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


# MOD = 998244353


def ncr(n, r, mod=None):
    """
    組み合わせの数 nCr
    :param int n:
    :param int r:
    :param int mod: 3 以上の素数であること
    :rtype: int
    """
    if n < r:
        return 0

    # 何度も呼ぶ場合は combination.py をつかう
    r = min(n - r, r)
    if r == 0:
        return 1
    if mod:
        return reduce(mul, range(n, n - r, -1)) * mod_inv(reduce(mul, range(r, 0, -1)), mod) % mod
    else:
        # math.factorial よりこっちのが速い
        # https://atcoder.jp/contests/abc110/submissions?f.Task=&f.Language=&f.Status=&f.User=nohtaray
        return reduce(mul, range(n, n - r, -1)) // reduce(mul, range(r, 0, -1))


def nhr(n, r, mod=None):
    """
    重複組み合わせの総数 nHr
    :param int n:
    :param int r:
    :param int mod:
    """
    return ncr(n + r - 1, r, mod)


def cumsum(it):
    """
    累積和
    :param collections.Iterable it:
    """
    cs = 0
    ret = []
    for v in it:
        cs += v
        ret.append(cs)
    return ret


# a = nhr(10, 10)
N, M, Q = list(map(int, sys.stdin.buffer.readline().split()))
ABCD = [list(map(int, sys.stdin.buffer.readline().split())) for _ in range(Q)]

ans = 0
for r in range(M):
    for idx in itertools.combinations_with_replacement(range(1, N + 1), r=r):
        a = [0] * (N + 10)
        a[1] = 1
        for i in idx:
            a[i] += 1
        cum = cumsum(a)
        # print(idx, cum[1: N + 1])
        pt = 0
        for a, b, c, d in ABCD:
            if cum[b] - cum[a] == c:
                pt += d
        ans = max(ans, pt)
print(ans)


Measured memory_bytes: 69216
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
    WRITER:kakitamasziru/OxOmisosiru
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
//#include <unordered_map> // unordered_map
//#include <unordered_set> // unordered_set
#include <bitset> // bitset
//#include <cctype> // isupper, islower, isdigit, toupper, tolower
//It is so troublesome that I 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; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100100;
const int MOD = 1000000007;
typedef pair<int,int> P;
//NのM乗を求める(繰り返し二乗法)
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

int parent[55];
int tall[55];
P E[2000];

int searchRoot(int v){
    if(parent[v] == v) return v;
    return parent[v] = searchRoot(parent[v]);
}

void unite(int x,int y){
    int rootX = searchRoot(x);
    int rootY = searchRoot(y);
    if(rootX == rootY) return;
    if(tall[x] > tall[y]){
        parent[rootY] = rootX;
    }
    else if(tall[x] < tall[y]){
        parent[rootX] = rootY;
    }
    else {
        tall[y]++;
        parent[rootY] = rootX;
    }
}

bool same(int x,int y){
    if(searchRoot(x) == searchRoot(y)) return true;
    else return false;
}

int main() {
    int N,M;cin >> N >> M;
    for(int i = 0;i<M;i++){
        cin >> E[i].first >> E[i].second;
    }
    int ans = 0;

    //i本目の辺をなくす = 飛ばす
    for(int i = 0;i<M;i++){
        //一回ごとに辺情報を初期化
        for(int i = 1;i<=N;i++){
            parent[i] = i;
            tall[i] = 0;
        }
        //i本目を除くすべての辺をつなげる
        for(int j = 0;j<M;j++){
            if(i == j) continue;
            unite(E[j].first,E[j].second);
        }
        if(!(same(E[i].first,E[i].second))) ans++;
    }

    cout << ans << endl;

    // PLEASE GIVE ME THE "ACCEPTED" !
}

Measured memory_bytes: 256
def carriable_baggage(baggage, baggage_num, truck_capacity, truck_num):
    """Return the number of baggae which trucks can carry."""
    laden_baggage = 0
    for i in range(truck_num):
        laden_weight = 0
        while laden_weight + baggage[laden_baggage] <= truck_capacity:
            laden_weight += baggage[laden_baggage]
            laden_baggage += 1
            if laden_baggage == baggage_num:
                return baggage_num
    return laden_baggage

def min_capacity(baggage, baggage_num, truck_num):
    """Return the minimum value of maximum load capacity of trucks."""
    left = 0
    right = max(baggage) * baggage_num
    while right - left > 1:
        mid = (left + right) // 2
        v = carriable_baggage(baggage, baggage_num, mid, truck_num)
        if v >= baggage_num:
            right = mid;
        else:
            left = mid
    return right


import sys

n, k = map(int, sys.stdin.readline().split())

T = list(map(int, sys.stdin))

P = min_capacity(T, n, k)

print(P)

Measured memory_bytes: 11548
#include"bits/stdc++.h"
#define rep(i,n) for(ll i=0;i<n;++i)
#define ALL(x) x.begin(),x.end()

using namespace std;
typedef long long ll;

template<typename T>
T gcd(T a, T b) {
	if (a % b == 0) {
		return(b);
	}
	else {
		return(gcd(b, a % b));
	}
}

template<typename T>
T lcm(T a, T b) {
	return a / gcd(a, b) * b;
}




int main(void) {
	string s;
	vector<char>c;
	cin >> s;
	rep(i, s.length()) {
		if (s[i] != '?') {
			cout << s[i];
		}
		else {
			cout << 'D';
		}
	}

}

/*

*/


Measured memory_bytes: 3756
fun main() {
    fun gcd(c:Long, d:Long):Long{
        if (d>c){return gcd(d,c)}
        if (c%d==0L){return d}
        return gcd(d, c%d)
    }
    val n= readLine()!!.toInt()
    val t= LongArray(n){ readLine()!!.toLong()}
    var ans=1L
    for (i in 0 until n){
        ans=ans/gcd(ans,t[i])*t[i]
//        println(ans)
    }
    println(ans)
}

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

#define      pb    push_back
#define      ff    first
#define      ss    second
#define      ll    long long int
#define      endl  "\n"
#define      FASTIO        ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);


#define      TEST    int t ; cin >> t ; while( t -- )

const ll big = 10e10 + 11 ;

int  main (  ) {

    FASTIO ;

    int  n ;
    cin >> n ;

    int flag = 0 ;

    for( int i = 0 ; i < n ; i++ ){
        int  x ;
        cin >> x ;

        if( x % 2 == 0 ){
            if( x % 3 ==0 || x % 5 ==0 ) ;
            else  flag = 1 ;
        }
    }

    if( flag )  cout << "DENIED" ;
    else  cout << "APPROVED" ;



    return  0 ;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,f=1,t,x,y;
double  a[101],b[101],maxa=0.0,p;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>t>>x>>y;
		if(t<x+y)f=0;
		else if((t-x-y)%2==1)f=0;
	}
	if(f)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
			
}

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

int main() {
	string Alp="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	string Al="ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ";
	int N;
	string T;
	cin>>N>>T;
	
	
	for(int k=0;k<T.size();k++){
		for(int i=0;i<26;i++){
		if(T.at(k)==Alp.at(i)){
			T.at(k)=Al.at(i+N);
		  break;
		}
	}
	}
	cout<<T<<endl;
	return 0;
}

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

using namespace std;

std::vector <int> g[MAXN + 1];
int x[MAXN + 1], y[MAXN + 1];
int grad[MAXN + 1];
int dist[MAXN + 1][MAXN + 1];

void dfs(int nod, int root, int father) {
    for(int i = 0; i < g[nod].size(); i++)
      if(g[nod][i] != father) {
          dist[root][g[nod][i]] = dist[root][nod] + 1;
          dfs(g[nod][i], root, nod);
      }
}


int main(){
   // std::ifstream cin("A.in");
  //  std::ofstream cout("A.out");
    int i, n, k, j;
    cin >> n >> k;
    for(i = 1; i <= n - 1; i++) {
        cin >> x[i] >> y[i];
        g[x[i]].push_back(y[i]);
        g[y[i]].push_back(x[i]);
        grad[x[i]]++;
        grad[y[i]]++;
    }
    for(i = 1; i <= n; i++)
        dfs(i, i, 0);
    int ans = n + 1;
    if(k % 2 == 0) {
        for(i = 1; i <= n; i++) {
            int cnt = 0;
            for(j = 1; j <= n; j++)
               if(dist[i][j] > k / 2)
                  cnt++;
            ans = std::min(ans, cnt);
        }
    }
    else {
        for(i = 1; i <= n - 1; i++) {
            int cnt = 0;
            for(j = 1; j <= n; j++)
               if(std::min(dist[x[i]][j], dist[y[i]][j]) > k / 2)
                  cnt++;
            ans = std::min(ans, cnt);
        }
    }
    cout << ans << std::endl;
   // cin.close();
   // cout.close();
    return 0;
}


Measured memory_bytes: 16128
#define rep(i, m, n) for(int i = m; i < n; i++)
#define repM(i, m, n) for(int i = n-1; i>=m; i--)
#define all(x) (x).begin(),(x).end()
typedef long long ll; using namespace std;
//typedef pair<int,int> pii; using namespace std;

// d = distance(lower_bound(all(x)), upper_bound(all(x)));

#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

const int maxN = 2e5;
int p[maxN], c[maxN];
vector<int> l[maxN];

void cal(int f, int pp){
  for(int k: l[f]) {
    cal(k, pp + p[k]);
    //cout << k << " ";
  }
  c[f] = pp;
}

int main(){
  int N, Q; cin >> N >> Q; int a, b;
  rep(i, 0, N-1) {
    p[i]=0; c[i]=0; cin >> a >> b; a--; b--;
    l[a].push_back(b);
    //cout << b << "*";
  }
  rep(i, 0, Q) {
    cin >> a >> b; p[a-1] += b;
  }
  cal(0, p[0]);
  rep(i, 0, N) {
    cout << c[i] << " ";
  }
}

Measured memory_bytes: 24320
#include <iostream>
#include <algorithm>
using namespace std;
#define INF 1e8

int main(){
    int V,E;
    cin>>V>>E;
    int G[V][V];
    fill(G[0],G[V],INF);
    int ans=0;
    int deg[V];
    fill(deg,deg+V,0);//?¬???°
    for(int i=0;i<E;i++){
        int s,t,d;
        cin>>s>>t>>d;
        G[s][t]=G[t][s]=min(G[s][t],d);
        ans+=d;
        deg[s]++;deg[t]++;
    }
    unsigned int M=0;
    for(int i=0;i<V;i++){
        if(deg[i]%2) M|=(1<<i); 
    }
    for(int i=0;i<V;i++)G[i][i]=0;
    for(int k=0;k<V;k++){
        for(int i=0;i<V;i++){
            for(int j=0;j<V;j++){
                G[i][j]=min(G[i][j],G[i][k]+G[k][j]);
            }
        }
    }
    int dp[1<<V];
    fill(dp,dp+(1<<V),INF);
    dp[0]=0;
    for(unsigned int S=0;S<(1<<V);S++){
        if(__builtin_popcount(S)%2)continue;
        for(int i=0;i<V;i++){
                if(!((1<<i)&S))continue;
            for(int j=i+1;j<V;j++){
                if(!((1<<j)&S))continue;
                unsigned int s = ((1<<i)|(1<<j))^S;
                dp[S]=min(dp[S],dp[s]+G[i][j]);
            }
        }
    }
    ans+=dp[M];
    cout<<ans<<endl;
}

Measured memory_bytes: 3212
#include<stdio.h>
#define MAX_LEN 10000
#define MAX_QUE 500

int main(){
    int num, que_num, i, j, numList[MAX_LEN], queList[MAX_QUE], ans=0;
    scanf("%d", &num);
    for(i=0; i<num; i++){
        scanf("%d", &numList[i]);
    }
    scanf("%d", &que_num);
    for(i=0; i<que_num; i++){
        scanf("%d", &queList[i]);
    }
    for(i=0; i<que_num; i++){
        for(j=0; j<num; j++){
            if(queList[i] == numList[j]){
                ans++;
                break;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

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

//container util
//------------------------------------------
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())

#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).begin(),(c).end(),greater<int>())

#define PB(a) push_back(a)

#define FS first
#define SE second

#define ALL(x) (x).begin(),(x).end()
#define MAX_EL(c) *max_element((c).begin(),(c).end())
#define MIN_EL(c) *min_element((c).begin(),(c).end())
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef string str;
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;


int main(){
// magic spell------------------------------
  cin.tie(0);
  ios::sync_with_stdio(false);
//------------------------------------------

  int X,Y,Z,K;
  VL ans;
  cin >> X >> Y >> Z >> K;
  VL A(X),B(Y),C(Z);
  REP(i,X){
    cin >> A[i];
  }
  REP(i,Y){
    cin >> B[i];
  }
  REP(i,Z){
    cin >> C[i];
  }
  sort(ALL(A),greater<>());
  sort(ALL(B),greater<>());
  sort(ALL(C),greater<>());
  priority_queue <VL> QUE;
  set <VL> iset;
  VL cur{A[0]+B[0]+C[0],0,0,0};
  QUE.push(cur);
  iset.insert(cur);
  REP(i,K){
    cur=QUE.top();
    ans=cur;
    cout << ans[0] << endl;
    QUE.pop();
    if (ans[1]<X-1){
      cur[0]+=A[cur[1]+1]-A[cur[1]];
      cur[1]++;
      if(iset.count(cur)==0){
        QUE.push(cur);
        iset.insert(cur);
      } 
      cur = ans;
    }
    if (ans[2]<Y-1){
      cur[0]+=B[cur[2]+1]-B[cur[2]];
      cur[2]++;
      if(iset.count(cur)==0){
        QUE.push(cur);
        iset.insert(cur);
      } 
      cur = ans;
    }
    if (ans[3]<Z-1){
      cur[0]+=C[cur[3]+1]-C[cur[3]];
      cur[3]++;
      if(iset.count(cur)==0){
        QUE.push(cur);
        iset.insert(cur);
      } 
      cur = ans;
    }
  }
  //cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define LOOP(val, times)   for(val = 0; val < (times); val++)
using namespace std;

int main(){
    int a,b;
    cin >> a>>b;
    cout<<a/b<<" "<<a%b<<" "<<fixed<< setprecision(10)<<(double)a/b<<endl;
}


Measured memory_bytes: 3240
#include<iostream>
#include<stdio.h>
using namespace std;
int main() {
  int a, b, d, r;
  double f;
  cin >> a >> b;
  d = a / b;
  r = a % b;
  f = (double) a / b;
  printf("%d %d %.5f\n", d, r, f);
  return 0;
}

Measured memory_bytes: 1192
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 200005;
int T,n,m;
int main() {
	string s;
	cin>>s;
	int flag = 0;
	ll cnt = 0;
	ll cnta = 0;
  	ll cntbc = 0;
	int pos=0;
	if(s.length()<=2){
		cout<<0<<endl;
		return 0;
	}
	for(int i=0;i<s.length()-2;i++){
		//cout<<cnta<<endl;
		if(s[i]!='A')
			cnta = 0;
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C'){
		//	cout<<"11111"<<endl;
			//cout<<cnta<<"     1234"<<endl;
			for(int j=i;j>=0;j--){
				if(s[j]=='A'){
					cnta++;
				}	
              	else {
                	break;
                }
            }
            //cout<<"                "<<i<<endl;
            for(int j =i+1;j<=s.length();j+=2){
            	if(s[j]=='B'&&s[j+1]=='C'&&j<s.length()){
                	cntbc++;
                	pos = j;
                }
              	else{
              		//cout<<22222<<endl;
              		//cout<<cnta<<" "<<cntbc<<endl;
                  	cnt+=(cnta*cntbc);
                  //	cout<<s[j]<<"  "<<s[j+1]<<"  "<<s[j+2]<<endl;
                    cntbc = 0;
                    pos = j-1;
                 	break;
                }
            }
			i = pos;
		}
	}
	cout<<cnt<<endl;
    return 0;
}

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

class Cube{
	public:
  	int f[6];
  	Cube(){}
  	void roll_z(){roll(1,2,4,3);}//横にまわす。
  	void roll_y(){roll(0,2,5,3);}
  	void roll_x(){roll(0,1,5,4);}
  	void roll(int i,int j,int k,int l){
    int t=f[i];f[i]=f[j];f[j]=f[k];f[k]=f[l];f[l]=t;
    }
};

bool eq(Cube c1,Cube c2){
	for(int i=0;i<6;i++){
    	if(c1.f[i]!=c2.f[i]){
        	return false;
        }
      }
  	return true;
}



bool equal(Cube c1,Cube c2){
  	for(int i=0;i<6;i++){
    	for(int j=0;j<4;j++){
          if(eq(c1,c2)){
          	return true;
          }else{
          	c1.roll_z();
          }
        }
          if(i%2==0){
          	c1.roll_y();
          }else{
          	c1.roll_x();
          }
  }
       return false;
  }

int main(){
  Cube c1,c2;
  for (int i=0;i<6;i++) cin>>c1.f[i];
  for (int i=0;i<6;i++) cin>>c2.f[i];
  
  if(equal(c1,c2)){
  	cout<<"Yes"<<endl;
  }else{
  	cout<<"No"<<endl;
  }
  
  return 0;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
using namespace std;
int main(){
int a;
cin>>a;
set<int> s;
s.insert(a);
for(int i=1;;i++){
  if(s.size()!=i){
    cout<<i;
    return 0;
  }
  a=(a%2==0?a/2:a*3+1);
  s.insert(a);
}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main(){
    int N;
    cin >> N;

    int a=0;
    int un=0;
    int ans=1;
    for(int i=0; i<N; i++){
        string s;
        cin >> s;
        if(s=="A"){
            a++;
        }else{
            un++;
        }

        if(a<un){
            ans=0;
        }
    }

    if(ans==0 || a!=un){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    string s;
    cin >> s;
    int num_one = 0, num_zero = 0, a;
    for (int i = 0; i < (int)s.size(); ++i) {
        if(s[i] == '0') num_zero++;
        else num_one++;
    }
    if (num_zero >= num_one) a = num_zero - num_one;
    else a = num_one - num_zero;

    cout << (int)s.size() - a << endl;
    return 0;
}


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

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

  string S; cin >> S;
  reverse(S.begin(), S.end());
  S += '0';

  ll N = S.size();
  ll INF = (ll) 1e9;
  vector<vector<ll>> dp(N + 1, vector<ll>(2, INF));

  dp[0][0] = 0;
  for (ll i = 0; i < N; i++) {
    for (ll j = 0; j < 2; j++) {
      int d = S[i] - '0';
      d += j;
      dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + d);
      dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + (10 - d));
    }
  }
  ll ans = min(dp[N][0], dp[N][1]);
  cout << ans << '\n';
  return 0;
  
}

Measured memory_bytes: 55964
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL<<60;
constexpr auto mod = 1000000007;

int main() {
	int h, w, n;
	cin >> h >> w >> n;
	queue<int> a;
	FOR(i, n) {
		int A;
		cin >> A;
		FOR(j, A)a.push(i + 1);
	}
	int ans[100][100];
	FOR(i, h) {
		if (i % 2 == 0) {
			FOR(j, w) {
				ans[i][j] = a.front();
				a.pop();
			}
		}
		else {
			eFOR1(j, w) {
				ans[i][w - j] = a.front();
				a.pop();
			}
		}
	}

	FOR(i, h) {
		cout << ans[i][0];
		FOR1(j, w)cout << " " << ans[i][j];
		cout << endl;
	}
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-

""" ビット全検索をちゃんと使ってみる版2 """

D, G = map(int, input().split())

# 各点数問題毎の、全問解いた場合の回答数と得点を保持
class ScoreSet:
    def __init__(self, times, score):
        self.times = times
        self.score = score

# 各パターン毎の、合計回答数と合計得点と、どの点数問題を全問解いたのかを保持
class ScoreSetSum:
    def __init__(self, times, score, bool_list):
        self.times = times
        self.score = score
        self.bool_list = bool_list

# 入力内容から、ScoreSetのリストを作成
scoreSetList = []
for i in range(D):
    p, c = map(int, input().split())
    scoreSetList.append(ScoreSet(p, p*100*(i+1) + c))

# ビット全検索のループとScoreSetのリストから、ScoreSetSumのリストを作成
scoreSetSumList = []
for i in range(1<<D):
    times_tmp = 0
    score_tmp = 0
    bool_list = []
    for j in range(D):
        if 1 & i>>j == 1:
            times_tmp += scoreSetList[j].times
            score_tmp += scoreSetList[j].score
            bool_list.append(True)
        else:
            bool_list.append(False)
    scoreSetSumList.append(ScoreSetSum(times_tmp, score_tmp, bool_list))

# ScoreSetSumのリストを元に、適切なパターンを探していく
ans = float("inf")
for scoreSetSum in scoreSetSumList:
    tmp = float("inf")
    # 得点が既にG以上であれば、そのままその回答数が候補
    if scoreSetSum.score >= G:
        tmp = scoreSetSum.times
    else:
        # 足りなかったら、全問解いていない点数問題から最も高いもの選ぶ
        for i in range(D-1, -1, -1):
            if scoreSetSum.bool_list[i] == False:
                score = scoreSetSum.score
                times = scoreSetSum.times
                # 選んだ点数問題を1問ずつ解いていく
                for j in range(scoreSetList[i].times):
                    score += 100*(i+1)
                    times += 1
                    # G以上に達した時点で、その時の回答数が候補
                    if score >= G:
                        tmp = times
                        break
                    # 最後まで解いてもG以上にならなければ、このパターンは候補外
                break
    # 今までの最小と今回の候補を比較
    ans = min(ans, tmp)

print(ans)

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

int main() { 
    int N, M;
    cin >> N >> M;
    vector<vector<int>> S(M);
    vector<int> P;
    for (int i=0; i<M; i++) {
        int k; cin >> k;

        for (int j=0; j<k; j++) {
            int s; cin >> s;
            S[i].push_back(s-1);
        }
    }
    for (int i=0; i<M; i++) {
        int p; cin >> p;
        P.push_back(p);
    }

    long long res = 0;
    for (int bit=0; bit<(1<<N); bit++) { // スイッチ全パターン
        bool on = true;
        // cout << bitset<8>(bit) << endl;
        for (int i=0; i<M; i++) { // 各電球が付いているかチェック
            int con = 0;
            for (auto v: S[i]) { // 接続スイッチ数のカウント
                if (bit & (1<<v)) con++;
            }
            if (con % 2 != P[i]) {
                on = false;
                break;
            }
        }
        if (on) res++;
    }

    cout << res << endl;
    
    return 0;
}

Measured memory_bytes: 256
n = int(input())
#i+1からL[i]で出席番号から着いた順の写像(i=0,1,2...)
L=list(map(int, input().split()))
#j+1からA[j]で着いた順から出席番号への写像をリスト化(j=0,1,2...)
A=[0]*n
for i in range(n):
	A[L[i]-1]=i+1

print(' '.join(map(str, A)))

Measured memory_bytes: 17764
// ABC088B - Card Game for two
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	_ = nextLine()
	inputLine := strings.Split(nextLine(), " ")
	var a []int
	for i := 0; i < len(inputLine); i++ {
		num, _ := strconv.Atoi(inputLine[i])
		a = append(a, num)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	sum := 0
	flag := true
	for i := 0; i < len(a); i++ {
		if flag {
			sum += a[i]
		} else {
			sum -= a[i]
		}
		flag = !flag
	}
	fmt.Println(sum)

}


Measured memory_bytes: 640
D = int(input())
C = [int(i) for i in input().split()]
S = [[int(i) for i in input().split()] for j in range(D)]

total = 0
last = [0] * 26
ans = []
for i in range(1, D+1):
    score = [0] * 26
    for t in range(26):
        score[t] += S[i-1][t]
        for j in range(26):
            if j != t:
                score[t] -= C[j] * (i - last[j])
    total += max(score)
    last[score.index(max(score))] = i
    ans.append(score.index(max(score))+1)

for i in range(D):
    print(ans[i])

Measured memory_bytes: 9516
#include <bits/stdc++.h>
#define prt_cs                  printf("Case %lld: ",cs)
#define sqr(x)                  (x)*(x)
#define ms(a,b)                 memset(a, b, sizeof(a))
#define db                      double
#define ll                      long long int
#define MOD                     100000007
#define PI                      2*acos(0.0)
#define pii                     pair< int, int >
#define READ                    freopen("in.txt","r",stdin)
#define WRITE                   freopen("out.txt","w",stdout)
#define gcd(a, b)               __gcd(a, b)
#define lcm(a, b)               (((a)*(b))/gcd(a,b))
#define MAX                     100005

using namespace std;

ll h[MAX],dp[MAX][2];

ll solve(int idx,int n,int ch)
{
    if(idx==n-1)
    {
        return 0;
    }
    if(dp[idx][ch]!=-1)return dp[idx][ch];
    ll ans=0,r1=MOD,r2=MOD;
    if(idx+1<n)
    r1=abs(h[idx]-h[idx+1])+solve(idx+1,n,0);
    if(idx+2<n)
    r2=abs(h[idx]-h[idx+2])+solve(idx+2,n,1);
//    cerr<<idx<<" "<<r1<<" "<<r2<<endl;
    ans=min(r1,r2);
    return dp[idx][ch]=ans;
}

int main()
{
//    READ;
//    WRITE;
    int n;
    scanf("%d",&n);
    ms(dp,-1);
    for(int i=0;i<n;i++)
    {
        scanf("%lld",&h[i]);
    }
    ll ans=solve(0,n,0);
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 7296
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();
		String result;
		if (A == B && A != C || A == C && A != B || B == C && A != B) {
			result = "かわいそう";
		} else {
			result = "";
		}
		if (result == "かわいそう") {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 21460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100003,INF=1<<30;

int main(){
    
    int N;cin>>N;
    vector<int> A(N);
    for(int i=0;i<N;i++){
        cin>>A[i];
    }
    sort(all(A));
    
    ll ans=0;
    
    for(int i=0;i<N;i++){
        for(int j=i+1;j<N;j++){
            int x=A[i]+A[j];
            auto it=lower_bound(all(A),x);
            ans+=ll(distance(A.begin(),it)-j-1);
            //cout<<ans<<endl;
        }
    }
    
    cout<<ans<<endl;
}



Measured memory_bytes: 256
// B.

#include <iostream>
#include <algorithm>

using namespace std;

int main(int argc, char *argv[])
{
	int n, k, ans = 1 << 30;
	cin >> n >> k;
	for (int i = 0; i <= n; ++i) {
		int x = 1;
		for (int j = 0; j < n; ++j) {
			if (j < i) {
				x *= 2;
			} else {
				x += k;
			}
		}
		ans = min(ans, x);
	}
	cout << ans << endl;
	return 0;
}


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

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

    Scanner cin;
    Func cin2;
    void calc()
    {
        cin = new Scanner();
        cin2 = new Func();
        int N=cin.nextInt();
        char[] s=cin.next().ToCharArray();
        bool yesorno=true;
        if(N%2==0)
        {
            for(int i=0;i<N/2;i++)
            {
                if(s[i]!=s[N/2+i]){yesorno=false;break;}
            }
        }
        else yesorno = false;
        if(yesorno)Console.WriteLine("Yes");
        else Console.WriteLine("No");
        

    }
}



class Scanner
{
    string[] s;
    int i;

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

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

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

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

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

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

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


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

class Answer
{
    public void Int2DArrayAns(int[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
    public void Char2DArrayAns(char[,]x,char c)
    {
        for(int i=0;i<x.GetLength(0);i++)
        {
            for(int j=0;j<x.GetLength(1)-1;j++)
            {
                Console.Write(x[i,j]);
                Console.Write(c);
            }
            Console.WriteLine(x[i,x.GetLength(1)-1]);
        }
    }
}

class Func
{
    public long GCDLong(long a, long b)
    {
        while(a!=0)
        {
          long t=a;
          a=b%a;
          b= t;
        }
      
        return b;        
    }
}

Measured memory_bytes: 11092
#pragma GCC target ("avx2")
#pragma GCC optimize ("unroll-loops")
#pragma GCC optimize ("O3")
#include "bits/stdc++.h"
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'000'007LL; /*998'244'353LL;*/
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
const int dx[4]={ 1,0,-1,0 };
const int dy[4]={ 0,1,0,-1 };

int N;
ll K, A[200000];

signed main(){
    cin >> N >> K;
    rep(i, N) cin >> A[i];

    ll ok = 1e9;
    ll ng = 0;
    while(ok-ng > 1){
        ll m = (ok+ng) / 2;
        ll cnt = 0;
        rep(i, N){
            cnt += (A[i]+m-1)/m-1;
        }
        if(cnt <= K) ok = m;
        else ng = m;
    }
    cout << ok << endl;
}

Measured memory_bytes: 5076
while True:
    line = input()
    data = line.split()
    x = int(data[0])
    y = int(data[1])
    if x==0 and y==0:
        break

    if x <= y:
        print(str(x) + " " + str(y))
    elif x > y:
        print(str(y) + " " + str(x))


Measured memory_bytes: 5612
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>
using namespace std;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

#ifdef NEAL_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif


const int M = 2019;

int main() {
    ios::sync_with_stdio(false);
#ifndef NEAL_DEBUG
    cin.tie(nullptr);
#endif

    string S;
    cin >> S;
    vector<int64_t> dp(M, 0);
    int64_t ans = 0;

    for (char ch : S) {
        vector<int64_t> next_dp(M, 0);
        int value = ch - '0';
        next_dp[value]++;

        for (int m = 0; m < M; m++) {
            next_dp[value] += dp[m];
            value += 10;

            if (value >= M)
                value -= M;
        }

        dp = next_dp;
        ans += dp[0];
    }

    cout << ans << endl;
}


Measured memory_bytes: 3716
s = gets.chomp.split("")
count = 0
all = 0
s.each_with_index do |item,j|
        if j % 2 == 1 && item == "0"
            count += 1
        elsif j % 2 == 0 && item == "1"
            count += 1
        end
        if j % 2 == 1 && item == "1"
            all += 1
        elsif j % 2 == 0 && item == "0"
            all += 1
        end
end
puts [count,all].min

Measured memory_bytes: 22656
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<vector<ll> > mat;

int a[500005];

int main()
{ios_base::sync_with_stdio(false);
int n;
cin>>n;
rep(i,0,n-1)cin>>a[i];

a[0]--;
rep(i,1,n-1)
{
	if(a[i]-1>=a[i-1])a[i]--;
}
rep(i,1,n-1)
{
	if(a[i]<a[i-1])
	{
		ol("No");
		return 0;
	}
}
ol("Yes");
return 0;
}



Measured memory_bytes: 640
N = int(input())
a = []
for i in range(N):
  a.append(int(input()))
j = 0
count = 1
flag = False

for i in range(N):
  if a[j] == 2:
    flag = True
    break
  else:
    count += 1
    j = a[j]-1


if flag:
  print(int(count))
else:
  print("-1")



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

int main() {
	char a;
   cin>>a;
  
  if (isupper(a)){
  	cout<<"A"<<endl;
  }
  
  else cout<<"a"<<endl;
  
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    while(cin>>n,n){
        bool flag=0;
        double result[4001]={};
        for(int i=0,str,ans=0;i<n;i++){
            double sale,num;
            cin>>str>>sale>>num;
            sale/=1000;num/=1000;
            result[str]+=sale*num;
            if(result[str]>=1){
                cout<<str<<endl;
                result[str]=-50;
                flag=1;
            }
        }
        if(!flag)cout<<"NA"<<endl;
    }
}

Measured memory_bytes: 1264
#include<iostream>
#include<vector>

using namespace std;

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

  vector<int> rev(n);
  for(int i=0;i<n;i++) rev[a[i]-1]=i+1;
  for(int i=0;i<n;i++) cout<<rev[i]<<endl;
}

Measured memory_bytes: 1664
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines

# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	li=[[0,0,0]]+[list(map(int,input().split())) for _ in range(n)]
	
	ans="Yes"
	
	li2=[]
	for i in range(n):
		li2.append([li[i+1][0]-li[i][0],abs(li[i+1][1]-li[i][1])+abs(li[i+1][2]-li[i][2])])
	
	for t,k in li2:
		if t%2!=k%2 or t<k:
			ans="No"
	
	print(ans)
	
	
if __name__ == "__main__":
	main()


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

using namespace std;

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

  int min1 = min((a+b), (a+c));
  int min2 = min((b+c), (b+a));
  int min3 = min((c+a), (c+b));

  int min4 = min(min1, min2);
  int min5 = min(min4, min3);

  cout << min5 << "\n";

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()
const ll MOD = 1000000007;

int main() {
	ll N, K;
	cin >> N >> K;
	vector<ll> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i];
	}
	ll ng = 0, ok = MOD, mid;
	bool bl;
	ll cnt = 0;
	while (ng + 1 != ok) {
		bl = 0;
		cnt = 0;
		mid = (ok + ng) / 2;
		for (int j = 0;j < N;j++) {
			cnt += (A[j] - 1) / mid;
		}
		if (cnt > K)
			bl = 1;

		if (bl) {
			ng = mid;
		}
		else {
			ok = mid;
		}
	}
	cout << ok << endl;
}

Measured memory_bytes: 4732
#include <vector>
#include <string>
#include <random>

#include <iostream>
#include <set>
#include <utility>

// Could get the hash of a substring.
// Constructor : O(n)
// get : O(1)
template <unsigned kMod>
class RollingHash
{
  using ull = unsigned long long;

private:
  const int _length;
  std::vector<unsigned> _hash, _pow;
  unsigned _kBase;

public:
  RollingHash(const std::string &s)
      : _length(s.size()), _hash(_length + 1), _pow(_length + 1, 1)
  {
    std::random_device seed_gen;
    std::mt19937_64 engine(seed_gen());
    const unsigned base = engine() % (kMod - 2) + 2;
    for (int i = 1; i <= _length; ++i)
    {
      _pow[i] = (unsigned)((ull)_pow[i - 1] * base % kMod);
      _hash[i] = (unsigned)(((ull)_hash[i - 1] * base + s[i - 1]) % kMod);
    }
  }

  // Gets the hash of the string[l, r).
  ull get(int l, int r)
  {
    return (_hash[r] - (ull)_hash[l] * _pow[r - l] % kMod + kMod) % kMod;
  }
};

int main()
{
  int n, m;
  std::cin >> n >> m;
  std::string s;
  std::cin >> s;
  RollingHash<1000000009> hashed_str1(s);
  RollingHash<1000000007> hashed_str2(s);
  int r = 1, l = 1;
  std::set<std::pair<unsigned, unsigned>> sub;
  for (int i = 0; i < m; ++i)
  {
    std::string q;
    std::cin >> q;
    if (q == "L++")
    {
      l++;
    }
    if (q == "L--")
    {
      l--;
    }
    if (q == "R++")
    {
      r++;
    }
    if (q == "R--")
    {
      r--;
    }
    sub.insert({hashed_str1.get(l - 1, r), hashed_str2.get(l - 1, r)});
  }
  std::cout << sub.size() << std::endl;
}
// be checked by AOJ(2444).


Measured memory_bytes: 21780
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
   FAST/**/
   
   ll s,w;
   cin>>s>>w;
   
   if(w>=s)
        cout<<"unsafe";
   else cout<<"safe";        
   
   return 0;        
}  
  
   

Measured memory_bytes: 3652
import sys
mod=10**9+7 ; inf=float("inf")
from math import sqrt, ceil
from collections import deque, Counter, defaultdict #すべてのkeyが用意されてる defaultdict(int)で初期化
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from decimal import ROUND_HALF_UP,Decimal  #変換後の末尾桁を0や0.01で指定
  #Decimal((str(0.5)).quantize(Decimal('0'), rounding=ROUND_HALF_UP))
from functools import lru_cache
from bisect import bisect_left as bileft, bisect_right as biright
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#ソート、"a"+"b"、再帰ならPython3の方がいい
#######ここから天ぷら########
n,m=map(int,input().split()) 
G=[] ; Y=[]
G1=[[] for i in range(n)]
for i in range(m):
    a,b,w=map(int,input().split())
    a-=1;b-=1
    G.append([a,b,-w])

# den=set([])
# for i  in range(m):
#     if uf.same(0,Y[i][0]): 
#         G.append(Y[i])
#         den.add(Y[i][0]);den.add(Y[i][1])
# now=len(den)

if 1:
    ansdist=[inf for i in range(n)]
    ansdist[0]=0
    for i in range(n-1):
        for edge in G:
            a,b,d=edge
            #辺ごとに見ていき、infでない(到達済み)頂点から伸びた辺であり、最小値を更新できるようなら緩和する
            if ansdist[b] > ansdist[a]+d:  #inf>inf はFalse
                ansdist[b]= ansdist[a]+d
                # if i==2*n+2 : print("inf");exit()

    # return ansdist

ans=-ansdist[-1]
neg=[0]*n
for i in range(n):
    for edge in G:
        a,b,d=edge
        if ansdist[b]>ansdist[a]+d:
            ansdist[b] = ansdist[a]+d
            neg[b]=1
        if neg[a]:neg[b]=1
if neg[-1]:
    print("inf")
else:
    print(ans)



Measured memory_bytes: 79532
#pragma GCC optimize("Ofast")
#include <set>
#include <map>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define yzh 2333333
#define bql 2147483647
using namespace std;
long long ans,n;
int main()
{
	cin>>n;
	if (n==1)
    {
		cout<<0<<endl;
		return 0;
	}
	for(long long i=1;i<=sqrt(n);i++)
    {
		if(n%i == 0 && n%((n-i)/i)!=0 && i<(n-i)/i)
        {
			ans+=(n-i)/i;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    ll W,H,x,y;
    cin >> W >> H >> x >> y;
    
    printf("%.9lf %d\n", 0.5 * W * H, W == x*2 && H == y*2);
}

Measured memory_bytes: 256
N = gets.chomp.to_i

alphabets = "abcdefghijklmnopqrstuvwxyz"
ans = ""
q = N

while q > 0 do
    q, r = q.divmod(26)

    q -= 1 if r == 0
    
    # r = 26 if r == 0 ... と思ったけど、[-1] だと最後の桁になるので [26] と等価になるので不要だった。よくできてんな。
    ans += alphabets[r - 1]
    # break if r == 0 ... この発想は誤り。Nが大きくてもいきなり第1ループで終わってしまう。
end

puts ans.reverse


Measured memory_bytes: 14344
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <stdlib.h>
#include <stdio.h>

using namespace std;
using Graph = vector<vector<int>>;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

vector<bool> seen;

void dfs(const Graph& G, int v) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) {
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v); // 再帰的に探索
    }
}

int abs_A(int num) {
    if (num > 0)
        return num;
    else
        return -num;
}

int abs_B(long long num, long long numb) {
    if (num - numb >= 0)
        return num - numb;
    else
        return -1 * (num - numb);
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

bool permutation(vector<int>& vec, vector<int>& P) {
    bool ok = true;
    for (int i = 0; i < vec.size(); i++) {
        if (vec.at(i) != P.at(i)) {
            ok = false;
        }
    }
    return ok;
}

const long long MOD = 1000000007;
const int INF = 1001001001;

int main() {
    long long N, A, B;
    cin >> N >> A >> B;
    long long count = N / (A + B);
    if (N % (A + B) == 0) cout << count * A << endl;
    else {
        cout << count * A + min(A, N % (A + B)) << endl;
    }
}


Measured memory_bytes: 256
#include<iostream> 
#include<string>
using namespace std;
int main()
{
	string s;
	int k=0;
	cin>>s;
	for(char c='a';c<='z';c++)
	{
		for(int i=0;i<s.size();i++)
		{
			if(s[i]!=c)
			    k++;
			else
			    break;	
		}
		if(k==s.size())
		{
			cout<<c;
		    return 0;
		}    
		else
		    k=0;    
	}
	cout<<"None";
	return 0;
}

Measured memory_bytes: 512
n,m=map(int,input().split())
j=[0]*n
c=[0]*n
pe=0
ac=0
for i in range(m):
  p,s=input().split()
  p=int(p)-1
  if s[0]=="A" and j[p]==0:
    j[p]=1
    ac+=1
    pe+=c[p]
  elif s[0]=="W":c[p]+=1
print(ac,pe)

Measured memory_bytes: 4596
#include <iostream>
#include <sstream>
#include <vector>
#include <cassert>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
#include <tuple>
#include <regex>
#include <map>

using namespace std;
using ull = unsigned long long;

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

	if (S.length() == 3) {
		reverse(begin(S), end(S));
	}
	cout << S << endl;

	return 0;
}



Measured memory_bytes: 256