akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;

ll gcd(ll m, ll n){
    ll tmp;
    while(m%n){
        tmp = n;
        n = m % n;
        m = tmp;
    }
    return n;
}

ll lcm(ll m, ll n){
    return m / gcd(m, n) * n;
}

ll two_d(ll n){
    ll ret = 0;
    while(n){
        if(n%2 == 0){
            ++ret;
            n /= 2;
        }
        else break;
    }
    return ret;
}

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

    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    set<ll> st;
    rep(i, n){
        cin >> a[i];
        st.insert(a[i]);
        if(i!=0){
            if(a[i] / 2 % 2 != a[i-1] / 2 % 2 || two_d(a[i]) != two_d(a[i-1])){
                cout << 0 << endl;
                return 0;
            }
        }
    }

    ll lscm = 1;
    for(auto elem: st){

        lscm = lcm(lscm, elem/2);
        if(lscm > m){
            cout << 0 << endl;
            return 0;
        }
    }

    ll res = (lscm <= m);
    res += (m-lscm) / (lscm*2);

    cout << res << endl;


    return 0;
}

Measured memory_bytes: 3992
/***************************************
    codeforces = topcoder = sahedsohel
    IIT,Jahangirnagar University(42)
****************************************/
#include <bits/stdc++.h>
using namespace std;

#define ll long long int

ll A, B, C, D, E,F;


int main()
{
    ll t,i,j,k,l;
    
    cin>>A>>B>>C>>D>>E>>F;
    
    double rs=-1;
    ll r1,r2;
    r1=r2=0;
    for(i=0;i<=F;i+=100*A)
    {
		for(j=0;i+j<=F;j+=100*B)
		{
			ll mx=min(((i+j)/100)*E,F-i-j);
			
			for(k=0;k<=mx;k+=C)
			{
				for(l=0;k+l<=mx;l+=D)
				{
					ll x=l+k;
					ll y=i+j+k+l;
					//if(x==0||y==0)continue;
					
					double q=(x*100.0)/y;
					
					if(q>rs)
					{
						rs=q;
						r1=y;
						r2=x;
					}
				}
			}
		}
	}
    
    cout<<r1<<" "<<r2<<endl;
    
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    int ans;
    if (A == B) ans = C;
    else if (B == C) ans = A;
    else ans = B;
    cout << ans << endl; 
    return 0;
}

Measured memory_bytes: 256
x , k , d = map(int,input().split())

if abs(x) >= d*k:
    print(abs(x) - d*k)
elif abs(x) < d*k:
    now = k - (abs(x)//d)
    a = abs(x) % d
    b = d - (abs(x) % d)
    if now % 2 == 0:
        print(a)
    elif now % 2 == 1:
        print(b)

Measured memory_bytes: 61840
// ------------------------------------
// Date:2018/ 3/12
// Problem:ABC 073 WriteAndErase c.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

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

typedef long long ll;

// static const int MOD = 1000000007;
// static const int MAX_N = 1010101010;

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

  int N;
  cin >> N;

  set< int > SI;
  REP(i, N) {
    int a;
    cin >> a;
    a--;
    if (SI.erase(a) == 0) SI.insert(a);
  }

  int ans = SI.size();
  cout << ans << endl;
  
  return 0;
}



Measured memory_bytes: 4992
A = []
sweetsInfo = [0]*100
empty = 0

N,K = input().split()

for i in range(int(K)):
    d = int(input())
    A = input().split()
    for o in range(d):
        sweetsInfo[int(A[o]) - 1] = 1

for i in range(int(N)):
    if sweetsInfo[i] == 0:
        empty += 1

print(empty)

Measured memory_bytes: 9176
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll n;
    cin>>n;
    string s;
    cin>>s;
    ll c=0;
    rep(0,i,n){
        if(s[i]=='W')++c;
    }
    ll nc=0;
    rep(0,i,c){
        if(s[n-1-i]=='W')++nc;
    }
    cout<<c-nc;
}


Measured memory_bytes: 3704
// Code by ajcxsu
// Geometry template

#include<bits/stdc++.h>
#define EPS (1e-9)
using namespace std;

struct Point {
    double x,y;
    Point(double x=0,double y=0):x(x), y(y) {}

    Point operator +(Point p) { return Point(x+p.x,y+p.y); }
    Point operator -(Point p) { return Point(x-p.x,y-p.y); } // 加减
    Point operator *(double a) { return Point(x*a,y*a); }
    Point operator /(double a) { return Point(x/a,y/a); } // 数乘

    double norm() { return x*x+y*y; } // 范数
    double abs() { return sqrt(norm()); } // 大小

    bool operator < (const Point &p) { return x!=p.x?x<p.x:y<p.y; }
    bool operator == (const Point &p) { return fabs(p.x-x) < EPS && fabs(p.y-y) < EPS; }
} ;
typedef Point Vector;

double dot(const Point &a, const Point &b) {
    return a.x*b.x+a.y*b.y;
} // 内积
double cross(const Point &a, const Point &b) {
    return a.x*b.y-a.y*b.x;
} // 外积
bool equals(double a, double b) { return fabs(a-b)<EPS; } // 误差相等

struct Line {
    Point p1,p2;
} ;
typedef Line Seg;

/* 1 正交 2 平行 0 其他 */
int PO(Vector a, Vector b) {
    if(equals(dot(a,b), 0)) return 1;
    else if(equals(cross(a,b), 0)) return 2;
    else return 0;
}
int PO(Line a, Line b) { // 正交、平行判定
    return PO(a.p2-a.p1, b.p2-b.p1);
}

istream& operator >>(istream &in, Vector &a) {
    in>>a.x>>a.y;
    return in;
}
istream& operator >>(istream &in, Line &a) {
    in>>a.p1>>a.p2;
    return in;
} // 输入重载

Point project(Point a, Seg b) {
    Vector base=b.p2-b.p1;
    Vector hypo=a-b.p1;
    return b.p1+base*(dot(base, hypo)/ base.norm());
} // 投影

Point ref(Point a, Seg b) {
    Vector base=project(a,b)-a;
    return a+base*2;
} // 映像

int ccw(Vector a, Vector b) {
    if(cross(a,b)>EPS) return 1; // Counter clockwise
    else if(cross(a,b)<-EPS) return -1; // Clockwise
    else if(dot(a,b)<-EPS) return 2; // Online back
    else if(a.norm()<b.norm()) return -2; // Online front
    else return 0; // On segement
} // 判断顺时针逆时针
int ccw(Point p0, Point p1, Point p2) {
    return ccw(p1-p0, p2-p0);
}

bool intersect(Point p1, Point p2, Point p3, Point p4) {
    if( ccw(p1,p2,p3)*ccw(p1,p2,p4) <= 0 &&
        ccw(p3,p4,p1)*ccw(p3,p4,p2) <= 0) return 1;
    return 0;
}
bool intersect(Seg a, Seg b) {
    return intersect(a.p1, a.p2, b.p1, b.p2);
}


ostream& operator <<(ostream &out, Vector a) {
    out<<a.x<<' '<<a.y;
    return out;
} // 输出重载

int main() {
    cout.setf(ios::fixed);
    cout<<setprecision(10); // 设置输出精度

    int q;
    cin>>q;
    while(q--) {
        Seg a,b;
        cin>>a>>b;
        cout<<intersect(a,b)<<endl;
    }
    return 0;
}



Measured memory_bytes: 3200
#include<stdio.h>
int main()
{
	int n;
	scanf("%d",&n);
	int arr[n];
	int i;
	for(i=0;i<n;i++)
	{
		scanf("%d",&arr[i]);
	}
	int c=0;
	for(i=0;i<n;i++)
	{
		if((i+1)%2 != 0 && arr[i]%2 !=0)
			c++;
	}
	
	printf("%d",c);
	return 0;
}

Measured memory_bytes: 1680
// GRL_2_A
#include <bits/stdc++.h>
#define endl "\n"
#define rep(i,n) for(int i=0;i<int(n);i++)
#define e_b emplace_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ipair;
typedef pair<ll,ll> lpair;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v) //vectorの中身を見る
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
void map_p(map<int,int>& d){cout<<"map: ";for(auto a : d){cout<<"{"<<a.first<<":"<<a.second<<"}";}cout<<endl;} //mapの中身を見る
void set_p(set<int>& d){cout<<"set: ";for(int a : d){cout<<a<<" ";}cout<<endl;} //setの中身を見る

struct edge{int u,v,cost;};
bool comp(edge a,edge b){
    return a.cost<b.cost;
}
struct unionfind{
    vector<int> par;
    void init(int n){
        par.assign(n,-1);
    }
    int find(int x){
        if(par[x]<=-1) return x;
        par[x]=find(par[x]);
        return par[x];
    }
    int size(int x){
        return -1*par[find(x)];
    }
    void unite(int x,int y){
        x=find(x),y=find(y);
        if(x==y) return;
        if(size(x)<size(y)) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
    }
    bool same_set(int x,int y){
        return find(x)==find(y);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);

    int v,e;
    cin>>v>>e;
    vector<edge> hen(e);
    rep(i,e){
        int s,t,w;
        cin>>s>>t>>w;
        edge aa;
        aa.u=s,aa.v=t,aa.cost=w;
        hen[i]=aa;
    }
    sort(all(hen),comp); //辺のコストが小さい順にソート
    unionfind uf;
    uf.init(v);
    int total=0;
    rep(i,e){
        edge cur=hen[i];
        if(!uf.same_set(cur.u,cur.v)){
            uf.unite(cur.u,cur.v);
            total+=cur.cost;
        }
    }
    cout<<total<<endl;
    return 0;
}


Measured memory_bytes: 4300
import java.util.*;

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

        boolean b = false;
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= 9; j++) {
                if (N == i * j) {
                    b = true;
                    break;
                } else if (N < i * j) {
                    break;
                }
            }
            if (b) {
                break;
            }
        }
        if (b) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
        sc.close();
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define rep2(i, s, n) for (int i = s; i < (int)n; i++)
#define all(obj) obj.begin(), obj.end()
#define debug(x) cerr << #x << ":" << x << "\n"
#define vdebug(vec) cerr << #vec << ":"; for (auto e : vec) cerr << e << " "; cout << "\n"
#define YN(f) cout << (f ? "YES" : "NO") << endl
#define Yn(f) cout << (f ? "Yes" : "No") << endl
#define yn(f) cout << (f ? "yes" : "no") << endl
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main () {
    int N; cin >> N;
    bool f = true;
    int t;
    rep(i, N) {
        cin >> t;
        if (t % 2 == 0 && t % 3 != 0 && t % 5 != 0) {
            f = false;
            break;
        }
    }
    cout << (f ? "APPROVED" : "DENIED");
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define LINF 9223372036854775807
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
//最大公約数
int gcd(int a,int b){
    
    if(a==0 || b==0)return 0;
    if(a<b){
        int sw;
        sw=a;
        a=b;
        b=sw;
    }
    
    int r;
    while((r=a%b)!=0){
        a=b;
        b=r;
    }
    return b;
}
//最小公倍数
int lcm(int a,int b){


    if(a==0 || b==0)return 0;

    return a/gcd(a,b)*b;

}

signed main(){
    
    int n,a[111111];
    cin>>n;
    rep(i,n){
        cin>>a[i];
    }
    int ans=gcd(a[0],a[1]);
    for(int i=2;i<n;i++){
        ans=gcd(a[i],ans);
    }
    cout<<ans<<endl;
    
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,n) for ((i)=1;(i)<=(n);(i)++)
using namespace std;
long long n,i,s,ss;
char c;
int main()
{
	while (cin>>c)
	{
		if (c=='W') ss+=s;else s++;
	}
	cout<<ss<<endl;
	return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<vector>
#include <cmath>
#include <map>
#include <algorithm>
#include <string>
#include <iomanip>
using namespace std;
typedef long long int ll;

int main(void){
    ll n , k ;
    cin >> n >> k ;

    ll a[k] ;
    ll ama =  n % k ;
    if(ama == 0){
        for(ll i = 0 ; i < k ; i++ ){
            a[i] = (n / k) ;
        }
    }else{
        for(ll i = 0 ; i < k ; i++ ){
            if(i < ama){
                a[i] = (n / k) + 1 ;
            }else{
                a[i] = (n / k) ;
            }
        }
    }

    ll ans = 0 ;
    if(k % 2 == 0){
        cout << a[k-1] * a[k-1] * a[k-1] + a[k/2 -1] * a[k/2 -1] * a[k/2 -1] << endl;
    }else{
        cout << a[k-1] * a[k-1] * a[k-1] << endl;
    }
   
    return 0;
}

Measured memory_bytes: 1792
def say_hon_pon_bon():
    n = input()

    lower = n[-1:]

    if lower == '2' or lower == '4' or lower == '5' or lower == '7' or lower == '9':
        print('hon')
    elif lower == '0' or lower == '1' or lower == '6' or lower == '8':
        print('pon')
    elif lower == '3':
        print('bon')


if __name__ == '__main__':
    say_hon_pon_bon()


Measured memory_bytes: 9112
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAXN 1000
int n;
long long T,A,G,K;
int main()
{
    scanf("%d",&n);
    scanf("%d%d",&T,&A);
    G=T,K=A;
    for(int i=2;i<=n;i++)
    {
        scanf("%lld%lld",&T,&A);
        long long p1=(G-1)/T+1,p2=(K-1)/A+1;
        long long P=max(p1,p2);
        G=P*T;
        K=P*A;
    }
    printf("%lld",G+K);
}


Measured memory_bytes: 256
import sys

def base10to(n, b):
    if (int(n/b)):
        return base10to(int(n/b), b) + str(n%b)
    return str(n%b)

def solve(N, K):
    print(len(str(base10to(N, K))))

if __name__ == '__main__':
    N, K = map(int, sys.stdin.readline().strip().split(" "))
    solve(N, K)

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

using namespace std ;

const int N=2e6+10 ;

int to[N<<2] , nxt[N<<2] , v[N<<2] ;
int lst[N<<1] ;
inline void add ( int u , int v )
{
	static int cnt=1 ;
	++cnt,to[cnt]=v,nxt[cnt]=lst[u],lst[u]=cnt,
	++cnt,to[cnt]=u,nxt[cnt]=lst[v],lst[v]=cnt;
}

int sz[N<<1] ;

int fa[N<<1] , sa , sb ;
int da[N<<1] , db[N<<1] ;
int n ;

int ans[N<<1] ;
inline void Euler ( int x )
{
	for ( int &i=lst[x] ; i ; i=nxt[i] ) 
		if ( !v[i] ) 
		{
			// printf("From %d to %d\n",x,e[i].to);
			if ( to[i]==x+n ) ans[x]=1;
			if ( to[i]==x-n ) ans[x-n]=-1;
			v[i]=v[i^1]=1,Euler(to[i]);
		}
	return ;
}

int main ()
{
	int i ;
	scanf("%d",&n);
	for ( i=1 ; i<=n ; i++ ) 
	{
		scanf("%d",fa+i);
		if ( ~fa[i] ) 
			add(i,fa[i]),
			da[fa[i]]^=1;
		sa=(~fa[i]?sa:i);
	}
	for ( i=1 ; i<=n ; i++ ) 
	{
		scanf("%d",fa+n+i);
		if ( ~fa[i+n] ) 
			add(i+n,fa[i+n]+n),
			db[fa[i+n]]^=1;
		sb=(~fa[i+n]?sb:i+n);
	}
	for ( i=1 ; i<=n ; i++ ) 
		if ( da[i]^db[i] ) 
			return puts("IMPOSSIBLE")*0;
	// for ( i=1 ; i<=n ; i++ ) 
	// 	printf("%d ",v[i]); puts("");
	for ( i=1 ; i<=n ; i++ ) 
		if ( !da[i] ) add(i,i+n);
	int S=2*n+1 ;
	add(S,sa),add(S,sb);
	Euler(S);
	puts("POSSIBLE");
	for ( i=1 ; i<=n ; i++ ) 
		printf("%d ",ans[i]);
	return 0 ;
}

Measured memory_bytes: 28032
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cmath>
#include <complex>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <iomanip>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define put(x) cout << x;
#define putsp(x) cout << x << ' ';
#define putbd cout << "---------------------------------------------" << endl;
#define putln(x) cout << x << endl;
#define debug(x) cerr << #x << "=" << x << endl;
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;
typedef complex<double> comp;
typedef vector <int> vec;
typedef vector <ll> vecll;
typedef vector <double> vecd;
typedef vector <vec> mat;
typedef vector <vecll> matll;
typedef vector <vecd> matd;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

const int MAX = 200020;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<29;
const ll INFL = 1e18;
const ll MOD = 1e9+7;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
//const int dx[]={-1,-1,-1,0,1,1,1,0},dy[]={-1,0,1,1,1,0,-1,-1};

//********************************template END****************************************//

void solve(void){

	string S;
	cin >> S;
	rep(3, i)
	{
		if (S[i] == '1')
		{
			put('9');
		}
		else
		{
			put('1');
		}
	}

	cout << endl;

}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long int ll;
typedef unsigned long long int ull;
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define pb push_back
#define mp make_pair

int n;
bool c[21][21]={};
ll dp[1<<21];

ll dfs(int ind,int mask){
    if(ind==n){
        return 1;
    }
    if(dp[mask]!=-1){
        return dp[mask]%1000000007;
    }
    ll ans=0;
    for(int i=0 ; i<n ; i++){
        if(c[ind][i] && ((1<<i)&mask)==0){
            ans+=dfs(ind+1,mask|(1<<i));
            ans%=1000000007;
        }
    }
    return dp[mask]=ans%1000000007;
}

int main(){
	fast;
	int test=1;
	//cin >> test;
	while(test--){
	    cin >> n;
	    memset(dp,-1,sizeof dp);
	    for(int i=0 ; i<n ; i++){
	        for(int j=0 ; j<n ; j++){
	            cin >> c[i][j];
	        }
	    }
	    dfs(0,0);
	    cout << dp[0] << endl;
	}
	return 0;
}

Measured memory_bytes: 19968
#include "iostream"
#include "string"

int Dice[6];

class DiceMove
{
private:
public:
	DiceMove(){}
	void Move(char dir) {
		int temp;
		if (dir == 'N') {
			temp = Dice[0];
			Dice[0] = Dice[1];
			Dice[1] = Dice[5];
			Dice[5] = Dice[4];
			Dice[4] = temp;
		}
		if (dir == 'S') {
			temp = Dice[0];
			Dice[0] = Dice[4];
			Dice[4] = Dice[5];
			Dice[5] = Dice[1];
			Dice[1] = temp;
		}
		if (dir == 'E') {
			temp = Dice[0];
			Dice[0] = Dice[3];
			Dice[3] = Dice[5];
			Dice[5] = Dice[2];
			Dice[2] = temp;
		}
		if (dir == 'W') {
			temp = Dice[0];
			Dice[0] = Dice[2];
			Dice[2] = Dice[5];
			Dice[5] = Dice[3];
			Dice[3] = temp;
		}
	}
};

int main()
{
	int n = 0, fr, up, count = 0;
	int Dice2[6];
	char dir;
	DiceMove move;
	std::string direction;
	for (int i = 0; i < 6; i++)
		std::cin >> Dice[i];
	for (int i = 0; i < 6; i++)
		std::cin >> Dice2[i];
	while (1) {
		if (Dice[1] == Dice2[0] && Dice[0] == Dice2[1]) {
			move.Move('W');
			move.Move('W');
			move.Move('N');
		}
		if (n > 1000) {
			std::cout << "No" << std::endl;
			break;
		}
		if (Dice[0] == Dice2[0] && Dice[1] == Dice2[1] && Dice[2] == Dice2[2] && Dice[3] == Dice2[3]) {
			std::cout << "Yes" << std::endl;
			break;
		}
		else {
			if (count == 3) {
				move.Move('W');
				count = 0;
			}
			else {
				move.Move('N');
				count++;
			}
		}
		n++;
	}
	return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())

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

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

void solve(long long a, long long b, long long c)
{
    cout << a + b + c - max(c, max(a, b)) << endl;
}

int main()
{
    long long a;
    scanf("%lld", &a);
    long long b;
    scanf("%lld", &b);
    long long c;
    scanf("%lld", &c);
    solve(a, b, c);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(begin, end) for (i=begin;i<end;i++)
#define init(arr, val) for (i=0;i<end;i++) arr[i] = val;
#define printint(i0, i1) printf("%d %d\n", i0, i1)

using namespace std;
const int inf = pow(10,9);
const int nil = -1;
long long a, b, x, ans;

int main() {
    scanf(" %lld %lld %lld", &a, &b, &x);
    ans = b / x - a / x;
    if (a % x == 0) ans++;
    printf("%lld\n", ans);
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
using ll = long long;

typedef struct UnionFind
{
    vector<int> par;
    vector<int> rank;

    UnionFind(int n) : par(n), rank(n, 0) 
    {
        for (int i = 0; i < n;i++)
        {
            par[i] = i;
        }
    }

    int find(int x)
    {
        if(x == par[x])
        {
            return x;
        }
        return par[x] = find(par[x]);
    }

    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if(x == y)
        {
            return;
        }

        if(rank[x] < rank[y])
        {
            par[x] = y;
        }
        else
        {
            par[y] = x;
            if(rank[x] == rank[y])
            {
                rank[x]++;
            }
        }
    }

    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
}UnionFind;

typedef struct Edge
{
    int u, v, cost;
}Edge;

bool comp(const Edge& e1, const Edge& e2)
{
    return e1.cost < e2.cost;
}

vector<Edge> es;

int V, E;

ll kruscul()
{
    sort(es.begin(), es.end(), comp);
    UnionFind ui(V);
    ll res = 0;
    for (int i = 0; i < E;i++)
    {
        Edge e = es[i];
        if(!ui.same(e.u, e.v))
        {
            ui.unite(e.u, e.v);
            res += e.cost;
        }
    }

    return res;
}

int main()
{
    cin >> V;

    vector<pair<ll, ll> > xs(V);
    vector<pair<ll, ll> > ys(V);

    for (int i = 0; i < V;i++)
    {
        ll x, y;
        cin >> x >> y;
        xs[i] = make_pair(x, i);
        ys[i] = make_pair(y, i);
    }

    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());

    for (int i = 0; i < V - 1;i++)
    {
        Edge e;
        e.u = xs[i].second;
        e.v = xs[i + 1].second;
        e.cost = xs[i + 1].first - xs[i].first;

        es.push_back(e);

        e.u = ys[i].second;
        e.v = ys[i + 1].second;
        e.cost = ys[i + 1].first - ys[i].first;

        es.push_back(e);
    }

    E = es.size();

    cout << kruscul() << endl;

    return 0;
}

Measured memory_bytes: 8052
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
  int n;
  int L[100];
  int ans=0;

  scanf("%d",&n);
  for(int i=0;i<n;i++)
  {
    scanf("%d",&L[i]);
  }

  if(n==1 || n==2)
  {
    printf("0\n");
    return 0;
  }

  for(int i=0;i<n-2;i++)
  {
    for(int j=i+1;j<n-1;j++)
    {
      for(int k=j+1;k<n;k++)
      {
        if((L[i]-L[j])*(L[j]-L[k])*(L[k]-L[i])==0) continue;
        if(L[i]<L[j]+L[k] && L[j]<L[k]+L[i] && L[k]<L[i]+L[j]) ans++;
      }
    }
  }

  printf("%d\n",ans);

  return 0;
}

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

// int/long:		-2,147,483,648 - 2,147,483,648 (-2^31 <= int < 2^31)
// long/long long:	-9,223,372,036,854,775,808 - 9,223,372,036,854,775,807 (-2^63 <= long < 2^63)

#define	INF (1<<29)
//536,870,912

// lower_bound(A.begin(), A.end(), N)
// upper_bound(...

// A.erase(unique(A.begin(), A.end()), A.end())

// bit: &/and, |/or, ^/xor, ~/not

// getline(cin, String)

// Graph
// Warshall-Floyd: Distance between each node, N^3
// Dijkstra: Distance from the start node, N^2
// DFS(Depth-First Search)

#define	MOD 1000000007

int	main() {
	int A, B;
	cin >>A >>B;
	int S=(A%3)*(B%3)*((A+B)%3);
	if (0==S)
		cout <<"Possible" <<endl;
	else
		cout <<"Impossible" <<endl;
	return 0;
}



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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main(){
  int n,x;
  cin >> n >> x;
  int m[n];
  for (int i = 0; i < n; i++){
    cin >> m[i];
    x -= m[i];
  }
  sort (m,m+n); 
  cout << n + x / m[0] << '\n';
  return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        int a = Cin.Ni();
        int b = Cin.Ni();
        Console.WriteLine(a + b >= 10 ? "error" : (a + b).ToString());
    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

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

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

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


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

const double EPS=1E-10;

int main(){
  complex<double> a, b, c, d;
  while(cin>>a.real()>>a.imag()>>b.real()>>b.imag()>>c.real()>>c.imag()>>d.real()>>d.imag()){
    complex<double> v1=a-b, v2=c-d;
    if((fabs(v1.real()*v2.real()+v1.imag()*v2.imag()))<EPS)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
  }
  return 0;
}

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

class Cmondai
{
    static void Main()
    {
        var N = Int32.Parse(Console.ReadLine());
        var isOpenArray = new bool[N,10];
        var benefitArray = new long[N, 11];
        for (int i=0;i<N*2;++i)
        {
            var line = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();
            if (i < N) for (int j = 0; j < 10; ++j) isOpenArray[i, j] = line[j] == 1;
            else for (int j = 0; j < 11; ++j) benefitArray[i-N, j] = line[j];
        }
        var count = Math.Pow(2,10);
        var ans = long.MinValue;
        for(int i=0;i<count;++i)
        {
            var isOpenMyShopArray = new bool[10];
            for (int j=0;j<10;++j) isOpenMyShopArray[j] = (1 & i >> j) == 1;
            if (isOpenMyShopArray.Count(x => x == true) == 0) continue;

            var benefit = 0L;
            for (int j=0;j<N;++j)
            {
                var overlapCount = 0;
                for (int k=0;k<10;++k) if (isOpenMyShopArray[k] && isOpenArray[j, k]) overlapCount++;
                benefit += benefitArray[j, overlapCount];
            }
            if (ans < benefit) ans = benefit;
        }
        Console.WriteLine(ans);
    }
}



Measured memory_bytes: 11348
import java.io.*;
import java.util.*;

class Main{
	public static void main(String[] args) throws Exception{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		String[] input = reader.readLine().split(" ");
		TreeSet<Stone> set = new TreeSet<Stone>();
		for(int i = 0; i < input.length; i++) {
			set.add(new Stone(i,Long.parseLong(input[i])));
		}
		//for(Stone _stone : set) System.out.println(_stone.num+","+_stone.index);

		long[] result = new long[n];
		while(!set.isEmpty()) {
			Stone last = set.last();
			set.remove(last);
			if(set.isEmpty()) {
				result[last.index] += last.getNum();
			}else {
				Stone newLast = set.last();
				set.remove(newLast);
				if(last.num!=newLast.num) result[last.index] += (last.num-newLast.num)*last.kind;
				newLast.add(last);
				set.add(newLast);
			}
		}
		for(long _result : result) System.out.println(_result);
	}
}

class Stone implements Comparable{
	long num;
	long kind;
	int index;
	Stone(int _index, long _num) {
		num = _num;
		kind = 1;
		index = _index;
	}
	void add(Stone _stone) {
		this.kind += _stone.kind;
		this.index = Math.min(this.index,_stone.index);
	}
	boolean canAdd(Stone _stone) {
		return num*_stone.kind == _stone.num*kind;
	}
	long getNum() {
		return num*kind;
	}
	@Override
	public int compareTo(Object _obj) {
		Stone _stone = (Stone)_obj;
		if(this.num == _stone.num) {
			if(this.index == _stone.index) return 0;
			return (this.index > _stone.index)?1:-1;
		}
		return (this.num > _stone.num)?1:-1;
	}
}


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

int main(){
    int n, a, b, c, d, count;

    while (cin >> n) {
        count = 0;
        for (a = 0; a <= 9; a++) {
            for (b = 0; b <= 9; b++) {
                for (c = 0; c <= 9; c++) {
                    for (d = 0; d <= 9; d++) {
                        if (a + b + c + d == n) {
                            count++;
                        }
                    }
                }
            }
        }
        cout << count << endl;

    }
    return 0;
}


Measured memory_bytes: 3016
#include<iostream>
using namespace std;
int ans(int n) {
	int sum = 0;
	for (int i = n; i > 0; i--) {
		sum += i;
	}
	return sum;
}

int main() {
	int ame;
	cin >> ame;
	int kazu;
	kazu = ans(ame);
	cout << kazu << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
ll dp[51][51][5001];
int main() {
    int n,a;
    cin>>n>>a;
    vector<int> x(n);
    rep(i,n){
        cin>>x[i];
    }
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
         for(int k=0;k<=5000;k++){
             dp[i+1][j][k]+=dp[i][j][k];
             if(k>=x[i]){
                 dp[i+1][j+1][k]+=dp[i][j][k-x[i]];
             }
         }
        }
    }
    ll ans=0;
    for(int i=1;i<=n;i++){
        ans+=dp[n][i][i*a];
    }
    cout<<ans<<endl;




    return 0;
}


Measured memory_bytes: 99840
#include <iostream>


struct Node {
    int parent = -1;
    int child_num;
    int * children;
};

int main() {
    int n;
    std::cin >> n;

    Node nodes[n];

    for (int i = 0; i < n; i++) {
        int id, k;
        std::cin >> id >> k;
        nodes[id].children = new int[k];
        nodes[id].child_num = k;
        for (int j = 0; j < k; j++) {
            int idx;
            std::cin >> idx;
            nodes[id].children[j] = idx;
            nodes[idx].parent = id;
        }
    }

    for (int i = 0; i < n; i++) {
        int depth = 0;
        Node n = nodes[i];
        while (n.parent != -1) {
            depth++;
            n = nodes[n.parent];
        }

        std::string type = "internal node";
        if (nodes[i].parent == -1) {
            type = "root";
        } else if (nodes[i].child_num == 0) {
            type = "leaf";
        }
        
        std::cout << "node " << i << ": parent = " << nodes[i].parent
                  << ", depth = " << depth
                  << ", " << type << ", [";

        for (int k = 0; k < nodes[i].child_num - 1; k++) {
            std::cout << nodes[i].children[k] << ", ";
        }
        if (nodes[i].child_num > 0) {
            std::cout << nodes[i].children[nodes[i].child_num - 1];
        }
        std::cout << "]" << std::endl;
    }
}



Measured memory_bytes: 8088
/* おまじない　*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
}

template<typename T>
vector<ll> countVector(vector< T >v,T guard=-1){
    ll size=v.size();
    //番兵を追加(初期値は-1)
    v.push_back(guard);
    vector<ll>ret;
    ll count=1;
    for(int i=0;i<size;i++){
        if(v[i]==v[i+1]){
            count++;
        }else{
            ret.push_back(count);
            count=1;
        }
    }
    return ret;
}

int main(){
  init();
  ll N,Q;cin>>N>>Q;
  string s;cin>>s;
  vector<ll>dp(N+1,0);
  for(int i=1;i<N;i++){
    dp[i+1]=dp[i];
    if(s[i-1]=='A'&&s[i]=='C')dp[i+1]++;
  }
  //for(int i=0;i<=N;i++)cout<<dp[i]<<" ";
  cout<<endl;
  while(Q--){
    ll l,r;cin>>l>>r;
    cout<<dp[r]-dp[l]<<endl;
  }
}


Measured memory_bytes: 1872
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef long long int lli;
using namespace std;
// #define int long long int

signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    int K;
    cin >> K;

    char t = S[K - 1];
    for (int i = 0; i < N; i++) {
        if (S[i] != t) S[i] = '*';
    }
    cout << S << endl;
    return 0;
}


Measured memory_bytes: 888
n = int(input())
flag = True
s = []
words = []
w1 = input()
words.append(w1)
e = w1[-1]

for i in range(n-1):
    wi = input()
    if e != wi[0]:
        flag = False
    for w in words:
        if w == wi:
            flag = False
    words.append(wi)
    e = wi[-1]


if flag:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
using namespace std;
double r = 380000.0;
int n;
string u;
double x, ans = 0;

int main(){
	cin >> n;
  	while (n--){
      cin >> x >> u;
      if (u == "BTC") ans += x * r;
      else ans += x;
    }
  	printf("%.8f\n", ans);
  	return 0;
}


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

public class Main{

	int maxDepth;
	String goal, cur;
	HashMap<String, String> dict;
	String[] rule;
	int N;
	Set<String> visited;

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			N = in.nextInt();
			if(N==0) return ;
			dict = new HashMap<String, String>();
			rule = new String[N];
			for(int i=0; i<N; i++){
				rule[i] = in.next();
				dict.put(rule[i], in.next());
			}
			cur = in.next();
			goal = in.next();
			System.out.println(solve());
		}
	}

	int solve(){
		if(cur.equals(goal)) return 0;
		for(maxDepth = 1; maxDepth <= 100; maxDepth++){
			visited = new HashSet<String>();
			if(dfs(0)) return maxDepth;
		}
		return -1;
	}

	boolean dfs(int depth){
		if(depth > maxDepth || cur.length() > goal.length() || visited.contains(cur)) return false;
		if(depth > maxDepth) return false;
		if(cur.equals(goal)) return true;
		visited.add(cur);
		String tmp = cur.toString();
		for(int i=0; i<N; i++){
			cur = tmp.replaceAll(rule[i], dict.get(rule[i]));
			if(dfs(depth+1)) return true;
		}
		cur = tmp.toString();
		return false;
	}

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

Measured memory_bytes: 13000
def main():
  while True:
    n, m = map(int,input().split())
    if not n:
      break
    
    lst = [0] * m
  
    for i in range(n):
      lst = [i + j for i, j in zip(lst, map(int,input().split()))]

    lst = sorted(zip(lst, range(1, m + 1)), key=lambda t:-t[0])
    
    print(" ".join(map(str,[t[1] for t in lst])))
  
main()


Measured memory_bytes: 5624
#include<iostream>
#include<string>
using namespace std;
int main(){
    string a;
    cin>>a;
    int sum=0;
    for(int i=0;i<a.length();i++){
        if(i!=0){
            if(a[i]==a[i-1]){
                if(a[i]=='0'){
                    a[i]='1';
                    sum++;
                }
                else{
                    a[i]='0';
                    sum++;
                }
            }
        }
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = Integer.parseInt(sc.nextLine());
        String S = sc.nextLine();
        String[] sarray = S.split("");
        int[] sumArray = new int[sarray.length + 1];
        sumArray[0] = 0;

        int wCount = 0;
        for (int i = 0; i < sarray.length; i++) {
            if (sarray[i].equals("W")) {
                wCount++;
            }
            sumArray[i + 1] = wCount;
        }

        int min = Integer.MAX_VALUE;
        for (int j = 0; j < N; j++) {
            int eastSideLength = N - j - 1;
            int westCount = sumArray[N] - sumArray[j + 1];
            int eastSideCount = eastSideLength - westCount;
            int val = sumArray[j] + eastSideCount;
            if (val <= min) {
                min = val;
                if (val == 0) {
                    break;
                }
            }
        }

        sc.close();

        System.out.println(min);
    }

}

Measured memory_bytes: 52788
/***"In the name of Allah(swt), the most gracious, most merciful. Allah(swt) blesses with knowledge whom he wants."***/
/*** "ALHAMDULILLAH for Everything..." ***/
#include<bits/stdc++.h>
using namespace std;
#define  fastt       ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define  ll         long long
#define  debug      printf("Come here!")
#define  inf        1000000000000000000
#define  pb         push_back
#define  mp         make_pair
#define  sz(a)      a.size()
#define  mem(a,b)   memset(a,b,sizeof(a))
#define  clr(x)     x.clear()
#define  ff         first
#define  ss         second
#define  case(x)    cout << "Case " << x <<": "

#define  md         1000000007
#define  pi         acos(-1.0)
#define  cos(a)     cos(a*pi/180)
#define  sin(a)     sin(a*pi/180)
#define  tan(a)     tan(a*pi/180)
#define  cosi(a)    acos(a)/(pi/180)
#define  sini(a)    asin(a)/(pi/180)
#define  tani(a)    atan(a)/(pi/180)

#define  vl         vector <ll>
#define  vs         vector <string>
#define  vc         vector <char>
#define  vpll       vector < pair <ll, ll> >
#define  vpsl       vector < pair <string, ll> >
#define  vpls       vector < pair <ll, string> >
#define  pql        priority_queue<ll>
#define  minpql     priority_queue<ll,vector<ll>,greater<ll> >

#define  setbits(x)     __builtin_popcountll(x)
#define  zerobits(x)    __builtin_ctzll(x)

#define toll(a) atoll(a.c_str())
string tostr(ll a) {stringstream rr;rr<<a;return rr.str();}
ll pow(ll c,ll d){return d==0?:c*pow(c,d-1);}
ll gcd(ll a,ll b) {return b==0? a:gcd(b,a%b);}
ll lcm(ll a,ll b) {return ((a*b)/gcd(a,b));}

/* mpp.max_load_factor(0.25); mpp.reserve(1024); */
/* cout << fixed << setprecision(12);*/

int main()
{
    fastt;

    ll n, m, k, i, j, x, y, p=0, s=0, h, f=0;
    cin>>n;
    if(n>=30)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}



Measured memory_bytes: 3652
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]
s.sort()
ans = 0
w = s[0]
c = 0
for i in s:
    if i == w:
        c += 1
    else:
        for j in t:
            if j == w:
                c -= 1
        if ans < c:
            ans = c
        c = 1
        w = i
for i in t:
    if i == w:
        c -= 1
if ans < c:
    ans = c
print(ans)

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

#define int long long

signed main() {
    int N, M;
    cin >> N >> M;
    
    vector<vector<int>> list;
    list.resize(N);
    
    int x, y, z;

    for(int i = 0; i < N; ++i){
        list[i].resize(3);
        cin >> x >> y >> z;
        list[i] = {x, y, z};
    }
    
    int ans = 0;
    
    vector<int> temp;
    
    for(int i = 0; i < N; ++i){
        temp.push_back(list[i][0] + list[i][1] + list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    int num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    ans = num;
    
    temp.clear();
    
    
    for(int i = 0; i < N; ++i){
        temp.push_back(list[i][0] + list[i][1] - list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    if(num > ans){ans = num;}
    
    temp.clear();
    
    for(int i = 0; i < N; ++i){
        temp.push_back(list[i][0] - list[i][1] + list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    if(num > ans){ans = num;}
    
    temp.clear();
    
    for(int i = 0; i < N; ++i){
        temp.push_back( - list[i][0] + list[i][1] + list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    if(num > ans){ans = num;}
    
    temp.clear();
    
    for(int i = 0; i < N; ++i){
        temp.push_back(list[i][0] - list[i][1] - list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    if(num > ans){ans = num;}
    
    temp.clear();
    
    for(int i = 0; i < N; ++i){
        temp.push_back(-list[i][0] + list[i][1] - list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    if(num > ans){ans = num;}
    
    temp.clear();
    
    for(int i = 0; i < N; ++i){
        temp.push_back(-list[i][0] - list[i][1] + list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    if(num > ans){ans = num;}
    
    temp.clear();
    
    for(int i = 0; i < N; ++i){
        temp.push_back(-list[i][0] - list[i][1] - list[i][2]);
    }
    
    sort(temp.begin(), temp.end());
    
    num = 0;
    for(int i = N - 1; i >= N - M; --i){
        num += temp[i];
    }
    
    if(num > ans){ans = num;}
    
    temp.clear();
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: isize,
        y: isize
    }
    let mut ans = None;
    'outer: for i in 0..n+1 {
        for j in 0..n-i+1 {
            let k = n - i - j;
            if 10000 * i + 5000 * j + 1000 * k == y {
                ans = Some((i, j, k));
                break 'outer;
            }
        }
    }
    let (x, y, z) = ans.unwrap_or((-1, -1, -1));
    println!("{} {} {}", x, y, z);
}

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

int main(){
	int a, b, n, ans;
	while(cin >> a >> b >> n){
		ans = 0;
		for (int i = 0; i < n; i++) {
			a %= b;
			ans += (10 * a) / b;
			a *= 10;
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3064
#include <stdio.h>
#include <iostream>
using namespace std;

int main(void){
  int n, m;
  int b[100], a[100][100];
  cin >> n >> m;
  for(int i=0; i<n; i++){
    for(int j=0; j<m; j++){
      cin >> a[i][j];
    }
  }
  for(int i=0; i<m; i++){
    cin >> b[i];
  }
  for(int i=0; i<n; i++){
    int sum = 0;
    for(int j=0; j<m; j++){
      sum += a[i][j]*b[j];
    }
    printf("%d\n", sum);
  }
  return 0;
}



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

int main() {
	long long int N, W;
	cin >> N >> W;
	vector<long long int> w(N, 0), v(N, 0);
	for(int i = 0; i < N; ++i) cin >> w[i] >> v[i];
	vector<long long int >curr(W+1, 0), prev(W+1, 0);
	for(int i = 1; i <= N; ++i){
		for(int j = 1; j <= W; ++j){
			curr[j] = max(prev[j], j-w[i-1] >= 0 ? prev[j - w[i-1]] + v[i-1] : curr[j-1]);
		}
		prev = curr;
	}
	cout << curr[W];
	return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STI(s) atoi(s.c_str())
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const ll MOD = 1000000007;
const double EPS = 1e-9;
const int INF = INT_MAX;
const ll LLINF = 1LL<<60;


int main(void) {
    
    int k,x;
    cin>>k>>x;
    if(500*k>=x)fin("Yes");
    else fin("No");

}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

string s;
int main() {
    cin >> s;
    int n = s.length();
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'p') {
            ++cnt;
        }
    }
    int max_cnt = n / 2;
    cout << max_cnt - cnt << endl;
    return 0;
}


Measured memory_bytes: 3768