akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h> 
using namespace std;
///////////////////////////////////////////
const long long int INF = INT32_MAX;
const long long int Mod = 1000000007;
const long long int mod = 100000;//10^5
using ll = long long int; //long long int は64bit
using ci = const int; using vi = vector<int>; using Vi = vector<long long int>; using pii = pair<int,int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define mt make_tuple
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
#define np nullptr
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define fill(x,num) memset(x,num,sizeof(x));
typedef vector<vector<ll> > matrix;
//       cin.tie(0);ios::sync_with_stdio(false);
void cinit(){cin.tie(0);ios::sync_with_stdio(false);}
//////////////////////////^^ *Emile ^^^//////////////////////////////////////////////////////

ll n;
Vi v;
int main(){
	cinit();cin>>n;
	ll aa;
	rep(i,n){cin>>aa;v.pb(aa);}
	Vi v2(v.size());
	copy(all(v),v2.begin());sort(all(v2));
	Vi v3;v3.pb(0);
	copy(all(v),std::back_inserter(v3));v3.pb(0);
	ll sum=0;     
	for(int i = 1;i<=n+1;i++){		
		sum+=abs(v3[i-1]-v3[i]);
	}
	for(int i=1;i<=n;i++){
		cout<<sum-abs(v3[i]-v3[i-1])-abs(v3[i+1]-v3[i])+abs(v3[i+1]-v3[i-1])<<endl;
	}
	return 0;
}

Measured memory_bytes: 3700
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] L = new int[M];
        int[] R = new int[M];
        int max=N+1;
        int min=0;
        for(int i=0; i<M; i++){
            L[i]=sc.nextInt();
            R[i]=sc.nextInt();
            min = Math.max(min,L[i]);
            max = Math.min(max,R[i]);
        }
        //int K = sc.nextInt();
        //long N = sc.nextLong();
        int res = Math.max(max-min+1,0);
        

        
        System.out.println(res);
        }
    }

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

int main() {
  int X;
  cin >> X;
  int A = 0;
  
  for(int i = 0; i < X; i++) {
    int l, r;
    cin >> l >> r;
    A += 1;
    A += r;
    A -= l;
  }
  cout << A << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm> 
using namespace std;
struct node
{
	long long v,nxt;
};
node edge[200001];
struct reads
{
	long long num,data;
	bool operator < (const reads &a)const
	{
		return data<a.data;
	}
};
reads t[100001];
long long n,m,a[100001],b[100001],head[100001],len,rt[100001],sz[100001],Mx[100001];
int find(int x)
{
	if (rt[x]==x)
		return x;
	return rt[x]=find(rt[x]);
}
void unionn(int x,int y)
{
	sz[find(y)]+=sz[find(x)];
	Mx[find(y)]=min(Mx[find(y)],max(Mx[find(x)],a[find(y)]-b[find(y)]-sz[find(x)]));
	rt[find(x)]=find(y);
	return;
}
void add(int x,int y)
{
	edge[++len].v=y;
	edge[len].nxt=head[x];
	head[x]=len;
	return;
}
int main()
{
	int x,y;
	cin>>n>>m;
	for (int i=1;i<=n;++i)
	{
		cin>>a[i]>>b[i];
		rt[i]=i;
		sz[i]=b[i];
		t[i].num=i;
		Mx[i]=max(a[i]-b[i],0ll);
		t[i].data=Mx[i];
	}
	for (int i=1;i<=m;++i)
	{
		cin>>x>>y;
		add(x,y);
		add(y,x);
	}
	sort(t+1,t+n+1);
	for (int i=1;i<=n;++i)
		for (int j=head[t[i].num];j>0;j=edge[j].nxt)
			if (a[t[i].num]>=a[edge[j].v]&&find(edge[j].v)!=find(t[i].num))
				unionn(edge[j].v,t[i].num);
	cout<<Mx[find(1)]+sz[find(1)]<<endl;
	return 0;
}

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

namespace ARC069
{
    class A
    {
        static void Main(string[] args)
        {
            long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
            long N = input[0];
            long M = input[1];

            long res = 0;
            if (2 * N < M)
            {
                res = N + (M / 2 - N) / 2;
            }
            else
            {
                res = M / 2;
            }
            Console.WriteLine(res);
        }
    }
}


Measured memory_bytes: 13268
import math

def inputlist(): return [int(i) for i in input().split()]

def kumiawase(num):
    r = 2
    if num != 1 and num != 0:
        return math.factorial(num) // (math.factorial(num - r) * math.factorial(r))
    else:
        return 0

def main():
    N, M = inputlist()
    print(kumiawase(N) + kumiawase(M))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define fi first
#define se second
#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 srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const v(T)&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>inline ostream& operator<<(ostream&o,const v(T)&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>inline ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
const int MX = 305;

double dp[MX][MX][MX];

int main() {
  int n;
  scanf("%d",&n);
  vi a(3);
  rep(i,n) {
    int x;
    scanf("%d",&x);
    a[x-1]++;
  }
  double p = 1.0/n;
  rep(k,n+1)rep(j,n+1)rep(i,n+1) {
    int z = n-i-j-k;
    if (z < 0) break;
    if (z == n) continue;
    double x = 1-z*p;
    if (i) dp[i][j][k] += dp[i-1][j][k]*i*p;
    if (j) dp[i][j][k] += dp[i+1][j-1][k]*j*p;
    if (k) dp[i][j][k] += dp[i][j+1][k-1]*k*p;
    dp[i][j][k] += 1;
    dp[i][j][k] /= x;
  }
  printf("%.10f\n",dp[a[0]][a[1]][a[2]]);
  return 0;
}






















Measured memory_bytes: 112576
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;
vi eulerSieve(int n)    // 查找记录2-n的素数
{
    vi p;
    vector<bool> vst(n+1, false);
    for (int i = 2; i <= n; i++)
    {
        if (vst[i] == false)  // 如果未被筛过，则为素数
            p.push_back(i);
        for (int j = 0; j < p.size(); j++)
        {
            if (i * p[j] > n)      // 当要标记的合数超出范围时跳出
                break;
            vst[i * p[j]] = true;     // 将已经记录的素数的倍数进行标记
            if (i % p[j] == 0)      //关键步骤
                break;
        }
    }
    return p;
}

vi primesUntil(int n){
    vi p;
    p.push_back(2);
    for (int i =3; i<=n; ++i){
        for (int j=0; j<p.size(); ++j){
            if (i%p[j] == 0) break;
            if (p[j]* p[j]> i)
            {
                p.push_back(i);
                break;
            }
        }
    }
    return p;
}

vector<pll> defactor(lint v, const vi& p){// prime,   power
    vector<pll> ans;
    int pid = 0;
    while(v>1){
        int cnt = 0;
        while(v%p[pid] == 0) {
            cnt++;
            v= v/p[pid];
        }
        if (cnt) ans.push_back({p[pid], cnt});
        pid++;
        if (v > 1 && (pid >= p.size() || lint(p[pid])*p[pid]>v)){
            ans.push_back({v, 1});
            break;
        }
    }
    return ans;
}


int main()
{
    ios_base::sync_with_stdio(0);    cin.tie(NULL);    cout.tie(NULL);

    int n; cin>>n;
    int s; cin>>s;
    lint mod = 998244353;
    vi a(n);
    for (int &i : a) cin>>i;

    vl p(s+1, 0);
    p[0] = 1;
    for (int i=0; i<n; ++i){
        vl op = p;
        for (int k=0; k<=s; ++k){
            p[k] = 2*op[k]%mod;
        }

        for (int k=0; k<=s; ++k){
            if (k + a[i] <= s){
                p[k + a[i]] = (p[k + a[i]] + op[k])%mod;
            }
        }
//        p = op;
    }
    cout<<p[s];


}


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

#define  int        long long int
 #define    sp(x)                 setprecision(x)
#define    bp(x)           __builtin_popcount(x)
 #define  ld         long double
 #define  f(i,j,n)            for(int i = j; i <= n; i++)
#define  r(i,n,j)       for(int i = n; i >= j; i--)
 #define  all(container)       container.begin() , container.end()
#define  sz(container)   (int)container.size()
 #define  ff             first
#define  ss             second
 #define  pii      pair <int , int>
#define  sp(x)       setprecision(x)
 #define  endl    "\n"
#define  mod  1000000007
 #define  pb    push_back
#define  mp    make_pair
 #define  T     int ttt; cin >> ttt; while(ttt--)
#define fast ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL);

int power(int x, int y, int p)  
{  
    int res = 1;    
    x = x % p; 
    if (x == 0) return 0; 
    while (y > 0)  
    {     
        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res; 
}

int32_t main()
{
    fast
    int x,y,n,f1=0,f2=0;
    cin>>x>>y>>n;
    set<pii>s;
    map<int,int>r,c,rr,cc;
    f(i,1,n)
    {
        cin>>x>>y;
        r[x]++; c[y]++;
        s.insert({x,y});
    }
    x=0;y=0;
    for(auto i: r)
        x=max(x,i.second);
    for(auto i: c)
        y=max(y,i.second);
    for(auto i: r)
        if(i.second==x)
            rr[i.ff]=i.ss;
    for(auto i: c)
        y=max(y,i.second);
    for(auto i: c)
        if(i.second==y)
            cc[i.ff]=i.ss;
    for(auto i : rr)
        for(auto j : cc)
            if(s.find({i.ff,j.ff})==s.end())
            {
                cout<<x+y;
                exit(0);
            }
        
    cout<<x+y-1;
}

Measured memory_bytes: 97348
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  string s;
  cin >> s;
  if ((int) s.length() < 26) {
    int used[26] = {};
    for (char c : s) {
      used[c - 'a']++;
    }
    for (int i = 0; i < 26; i++) {
      if (!used[i]) {
        cout << s + (char) (i + 'a') << endl;
        return 0;
      }
    }
  }
  for (int i = 25; i > 0; i--) {
    if (s[i - 1] < s[i]) {
      for (int j = 0; j < i - 1; j++) {
        cout << s[j];
      }
      char c = 'z';
      for (int j = i; j < 26; j++) {
        if (s[j] > s[i - 1]) c = min(c, s[j]);
      }
      cout << c << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;	
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
class Program
{
    //static List<string> str = new List<string>();
	static void Main(string[] args)
	{
		// 入力フェーズ
		int N = Int32.Parse(Console.ReadLine());
		string[] A = Console.ReadLine().Split(' '); // 街にいるモンスターの数
		string[] B = Console.ReadLine().Split(' ');// 勇者の倒せるモンスターの数

		List<int> city = new List<int>();
		List<int> brave = new List<int>();
		for(int i=0; i<=N; i++){
			city.Add(Int32.Parse(A[i]));
		}
		for(int i=0; i<N; i++)
		{
			brave.Add(Int32.Parse(B[i]));
		}
		// 勇者が全力で倒して行くと最大になるから・・・
		long monster = 0;
		for(int i=0; i<N; i++)
		{
				// i番目の勇者が倒せる数は・・・
				int cityMonster1 = city[i];
				int braveNum = brave[i];

				if(cityMonster1 >= braveNum)
				{
					// 最初の街で力尽きた
					monster += braveNum;
					continue;
				}
				else
				{
					// 余力あり
					monster += cityMonster1;
					braveNum -= cityMonster1;
				}



				// i+1番目の街のモンスターも倒す
				int cityMonster2 = city[i+1];
				if(cityMonster2 >= braveNum)
				{
					// 2番目の街で力つきた
					monster += braveNum;
					//ほうれんそう
					city[i+1] = cityMonster2 - braveNum;
				}
				else
				{
					// 2番目の街も片付けた
					monster += cityMonster2;
					city[i+1] = 0;
				}
		}
    // 最終的に倒せたモンスターは・・・
		Console.WriteLine(monster + "");


    }

}


Measured memory_bytes: 32344
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    string s; cin >> s;
    ll ans = INFLL;

    ll cnt = 0;
    char c = '0';
    REP(i, s.length()) {
        if (s[i] != c)++cnt;
        c = c == '0' ? '1' : '0';
    }
    ans = min(ans, cnt);

    cnt = 0;
    c = '1';
    REP(i, s.length()) {
        if (s[i] != c)++cnt;
        c = c == '0' ? '1' : '0';
    }
    ans = min(ans, cnt);

    cout << ans << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<bits/stdc++.h>
#include<string>
using namespace std;
int main()
{
  int n ;
  cin >>  n ;
  
  string str ;
  str = to_string(n) ;
  
  for(int i=0;i<3;i++){
    if(str[i]=='1'){
      str[i] = '9' ;
    }else if(str[i]=='9'){
      str[i] = '1' ;
    }
  }
  
  n = stoi(str);

    cout << n << endl ;

  return 0 ;
}


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

using namespace std;

const long long mod = 1e9 + 7;

long long dp[201][100001];
long long N, X;
long long S[201];

int main()
{
    cin >> N >> X;
    for (int i = 0;i < N;i++)
    {
        cin >> S[i];
    }
    sort(S, S+N, greater<long long>());
    dp[0][X] = 1;
    for (long long i = 1; i <= N; i++)
    {
        for (long long j = 0; j <= X;j++)
        {
            dp[i][j % S[i - 1]] += dp[i - 1][j];
            dp[i][j % S[i - 1]] %= mod;
            dp[i][j] += dp[i - 1][j] * (N - i);
            dp[i][j] %= mod;
        }
    }
    long long ans = 0;
    for (long long i = 0; i <= X;i++)
    {
        ans += i * dp[N][i];
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 156544
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <sstream>
#include <numeric>
#include <cstdio>
#include <bitset>

#define int ll

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;

#define pb push_back
#define F first
#define S second
#define _sz(x) ((int)x.size())

const int N = 2e5 + 20;
int n;

ld a[N], b[N], c[N];

ld f[N], E[N];

int sz, stk[N];

int L[N], R[N];
bool mark[N];

inline bool is_bigger (pii a, pii b) {
    return (ld)a.F * b.S > (ld)b.F * a.S;
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    cin >> n;

    int mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] > a[mx]) mx = i;
    }
    
    for (int i = 0; i < n; i++) cin >> b[i];

    rotate(a, a + mx, a + n);
    rotate(b, b + mx, b + n);

    a[n] = a[0];

    c[0] = c[1] = 0;
    for (int i = 2; i <= n; i++) {
        c[i] = 2 * c[i - 1] + 2 * b[i - 1] - c[i - 2];
    }


    for (int i = 0; i <= n; i++) a[i] -= c[i];

    stk[sz++] = 0;
    
    for (int i = 1; i <= n; i++) {
        while (sz >= 2 && is_bigger(pii(a[i] - a[stk[sz - 2]], i - stk[sz - 2]), pii(a[stk[sz - 1]] - a[stk[sz - 2]], stk[sz - 1] - stk[sz - 2]))) {
            sz--;
        }
        stk[sz++] = i; 
    }

    for (int i = 0; i < sz; i++) {
        mark[stk[i]] = 1;
        f[stk[i]] = a[stk[i]];
    }

    for (int i = 0; i <= n; i++) {
        if (mark[i]) L[i] = i;
        else L[i] = L[i - 1];
    }

    for (int i = n; i >= 0; i--) {
        if (mark[i]) R[i] = i;
        else R[i] = R[i + 1];
    }

    for (int i = 0; i <= n; i++) {
        if (mark[i]) continue;

        f[i] = (f[L[i]] * (R[i] - i) + f[R[i]] * (i - L[i])) / (R[i] - L[i]);
    }

    for (int i = 0; i <= n; i++) E[i] = f[i] + c[i];
    
    ld sum = 0;
    for (int i = 0; i < n; i++) sum += E[i];



    ld result = sum / n;

    cout << fixed << setprecision(10) << result << '\n';
}


Measured memory_bytes: 24072
import java.util.Arrays;
import java.util.Scanner;

class B2 {
    public static void main(String... args) {
        final Scanner sc = new Scanner(System.in);
        final char[] T = sc.next().toCharArray();
        final int[] dp = new int[T.length + 1];
        final char[] ans = Arrays.copyOf(T, T.length);
        for (int i = 1; i <= T.length; i++)
            if (T[i - 1] == 'P') {
                dp[i] = dp[i - 1];
            } else if (i >= 2 && T[i - 2] == 'P') {
                dp[i] = dp[i - 2] + 2;
                ans[i - 1] = 'D';
            } else if (i >= 2 && T[i - 2] == '?') {
                if (dp[i - 1] + 1 < dp[i - 2] + 2) {
                    dp[i] = dp[i - 2] + 2;
                    ans[i - 1] = 'P';
                    ans[i - 1] = 'D';
                } else {
                    dp[i] = dp[i - 1] + 1;
                    ans[i - 1] = 'D';
                }
            } else {
                dp[i] = dp[i - 1] + 1;
                ans[i - 1] = 'D';
            }
        System.err.println(dp[T.length]);
        System.out.println(ans);
    }
}
public class Main {
    public static void main(String... args) {
        B2.main();
    }
}


Measured memory_bytes: 42368
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main() {
long long n,k;
cin >> n >> k;
COMinit();
long long all=COM(2*n-1,n);
long long empty=0;
for(int i=k+1;i<n;i++){
    empty+=(COM(n,i)*COM(n-1,i))%MOD;
    empty%=MOD;
}
all = (all - empty + MOD)%MOD;
cout << all << endl;
}


Measured memory_bytes: 23680
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define SZ 666666
ll n; int vs[SZ],*h=vs+SZ/3,*t=h,cnt=0;
void md(ll s)
{
	if(s==1) return;
	md(s/2); *(t++)=++cnt;
	if(s&1) *(--h)=++cnt;
}
int main()
{
	cin>>n; ++n; md(n); int sz=t-h;
	printf("%d\n",sz+sz);
	for(int i=0;i<sz;++i) printf("%d ",*(h+i));
	for(int i=0;i<sz;++i) printf("%d ",i+1);puts("");
}

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

using namespace std;

int main(){
	int N, X, Y;
	vector<int> dist;
	cin>>N>>X>>Y;
	dist.assign(N, 0);
	for(int i=1;i<=N;i++){
		for(int j=i+1;j<=N;j++){
			int dis = min(abs(j-i), min(abs(X-i)+1+abs(Y-j), abs(X-j)+1+abs(Y-i)));
			dist[dis]++;
		}
	}
	for(int i=1;i<=N-1;i++){
		cout<<dist[i]<<"\n";
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<queue>
using namespace std;
struct NODE{
	int step,mny;
	NODE(int stepp,int mnyy){
		step=stepp;
		mny=mnyy;
	}
};
queue<NODE>Q;
int Pow(int x,int y){
	int ret=1;
	for(int i=1;i<=y;i++)
		ret*=x;
	return ret;
}
int main(){
	int n;
	scanf("%d",&n);
	Q.push(NODE(0,n));
	while(!Q.empty()){
		NODE now=Q.front();
		Q.pop();
		for(int i=5;i>=1;i--){
			int k=now.mny-Pow(9,i);
			if(k<0)	continue;
			if(k==0){
				printf("%d\n",now.step+1);
				return 0;
			}
			Q.push(NODE(now.step+1,k));
			break;
		}
		for(int i=6;i>=1;i--){
			int k=now.mny-Pow(6,i);
			if(k<0)	continue;
			if(k==0){
				printf("%d\n",now.step+1);
				return 0;
			}
			Q.push(NODE(now.step+1,k));
			break;
		}
		if(now.mny<6){
			printf("%d\n",now.step+now.mny);
			return 0;
		}
	}
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
using namespace std;

const long long MOD = 1000000007;



int main() {
  int N, M;
  cin >> N >> M;


  vector<vector<int>> order(M,vector<int>(2));
  REP(m,M) cin >> order[m][0] >> order[m][1];  
  sort(order.begin(),order.end(),[](const vector<int> &alpha,const vector<int> &beta){return alpha[1] < beta[1];});

  int befor=-100;
  int ans = 0;
  REP(m,M){
    int left  = order[m][0];
    int right = order[m][1];
    if (left <= befor && befor < right){
      // do nothing
    } else{
      befor = right - 1;
      ans += 1;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 5888
import collections

n = int(input())
s = [''] * n
for i in range(n):
    s[i] = input()

cs = collections.Counter(s)
mcs = cs.most_common()
cnt = mcs[0][1]

fcs = [i[0] for i in cs.items() if i[1] == cnt]
ans = sorted(fcs)
for s in ans:
    print(s)


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

int main(){
  string s;
  cin >> s;
  int x=s.size();
  int cnt=0;
  for (int i=0;i<x-1;++i){
    if (s[i]!=s[i+1]) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 512
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def check(sp, s):
    
    for i in range(len(s)):
        if sp[i] != '?' and s[i] is not None and sp[i] != s[i]:
            return False
    return True

def main():
    sp = input()
    n = len(sp)
    t = input()
    s = [None] * n

    for i in range(n):
        if sp[i] != '?':
            s[i] = sp[i]
    anss = list()
    # i~ i+len(t)文字目までをtとした場合
    for i in range(n-len(t)+1):
        p = [None]*n
        for j in range(len(t)):
            p[i+j] = t[j]
        if check(sp, p):
            ans = str()
            for i in range(n):
                if p[i] is None:
                    if sp[i] == '?':
                        ans += 'a'
                    else:
                        ans += sp[i]
                else:
                    ans += p[i]
            anss.append(ans)
    if anss:
        anss.sort()
        print(anss[0])
        return
    print('UNRESTORABLE')
    return
            

    #print(check(sp, 'atcoder'))

if __name__ == '__main__':
    main()

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

int main(){
  string S;
  cin >> S;
  bool f=false;
  bool g=false;
  int  a=((S[0]-'0')*10 + S[1]-'0');
  int  b=((S[2]-'0')*10 + S[3]-'0');
  if(  a<=12 and a>0) f=true;
  if(  b<=12 and b>0) g=true;
  if (f and g) cout << "AMBIGUOUS" << endl;
  if (f==false and g) cout << "YYMM" << endl;
  if (f and g==false) cout << "MMYY" << endl;
  if (f==false and g==false) cout << "NA" << endl;
  return 0;
}

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

int main()
{
	int n;
	cin >> n;
	bool suc = false;
	for (int i = 0; i < 3; i++) {
		if (n % 10 == 7) {
			suc = true;
		}
		n /= 10;
	}
	cout << (suc ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1LL<<60;
#define all(x) (x).begin(),(x).end()
#define REP(i,n) for(int i=0; i<(n);++i)
#define FOR(i,k,n) for(int i=(k);i<(n);++i)

int main(){
    int N;ll K;cin>>N>>K;
    vector<ll> a(N);
    REP(i,N)cin>>a[i];
    vector<ll> b(N+1,0);
    REP(i,N)b[i+1]=b[i]+a[i];
  	vector<pair<ll,ll>> v;
    REP(i,N+1){b[i]+=i*(K-1);b[i]%=K;}
  	REP(i,N+1)v.push_back(make_pair(b[i],i));
    sort(all(v));
    v.push_back(make_pair(INF,INF));
    ll res=0;
  	int l=0,r=0;
    while(l<N+1 && r<N+1){
        while(v[l].first==v[r+1].first && v[r+1].second-v[l].second<K){r++;}
        res+=(ll)(r-l);
        if(r==l){r++;l++;}
        else l++;
    }
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 9584
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const A = parseInt(arg[0].split(" ")[0]);
    const B = parseInt(arg[1].split(" ")[0]);
    const C = parseInt(arg[2].split(" ")[0]);
    const D = parseInt(arg[3].split(" ")[0]);
    const E = parseInt(arg[4].split(" ")[0]);
    
    const list = [A, B, C, D, E];
    let last = Infinity;
    let lastIdx = -1;
    
    for(let i=0; i<5; i++) {
        let temp = list[i] % 10;
        
        if(temp !== 0) {
            if(last > temp) {
                lastIdx = i;
                last = temp;
            }
        }
    }
    
    let answer = 0;
    
    for(let i=0; i<5; i++) {
        let temp = list[i] % 10;
        
        if(i === lastIdx) {
            answer += list[i];
        } else {
            if(temp !== 0) {
                answer += list[i] + (10 - temp);
            } else {
                answer += list[i];
            }
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 21064
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7


int main() {
	char S[1000005];
	scanf("%s", S);


	int odd = 0;// 1010101
	int even = 0; //010101

	int size = 0;
	for (int i = 0; i < 1000005; i++) {
		if (S[i] == '\0') {
			size = i;
			break;
		}

	}

	for (int i = 0; i < size; i++) {
		if (i % 2 == 1) {//奇数番目
			if (S[i] == '1') {
				even++;
			}
			else {
				odd++;
			}
		}
		else {
			if (S[i] == '0') {
				even++;
			}
			else {
				odd++;
			}
		}
	}


	printf("%d\n", min(odd, even));
}






Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int a,b,c,d,e,f;
	double x,y;
	while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=-1){
		y = (double)(c*d-f*a)/(b*d-e*a);
		x = (double)(c*e-f*b)/(a*e-d*b);
		if(y<=0&&y>-0.0005)y=0;
		if(x<=0&&x>-0.0005)x=0;
		printf("%.3f %.3f\n",x,y);
	}
	return 0;
}

Measured memory_bytes: 636
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;

int gcd(int a, int b) {
  return b ? gcd(b, a%b) : a;
} 

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	string s;
	int k;
	cin >> s >> k;

	ll ans = 0;
	int n = (int) s.length();
	for(int i = 0; i< n; i++)
	{
		for(int cif1 = 1; cif1 <= 9; ++cif1)
		{
			if(i == 0 && cif1 > (s[0] - '0'))
				continue;
			bool less1 = i || cif1 < s[0] - '0';
			if(k == 1)
				ans++;
			else
			{
				for(int j = i+1; j< n; ++j)
				{
					for(int cif2 = 1; cif2 <= 9; ++cif2)
					{
						if(!less1 && cif2 > s[j] - '0')
						{
							continue;
						}

						bool less2 = less1 || cif2 < s[j] - '0';

						if(k == 2)
							ans++;
						else
						{
							for(int k = j+1; k < n; ++k)
							{
								for(int cif3 = 1; cif3 <= 9; ++cif3)
								{
									if(!less2 && cif3 > s[k] - '0')
										continue;
									ans++;
								}
								if(s[k] > '0')
									less2 = 1;
							}
						}
					}
					if(s[j] > '0')
						less1 = 1;
				}
			}
		}
	}
	cout << ans;

    return 0;
}

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

int main(){
double r,l,s;
cin >>r;
l=2*r*3.141592653589;
s=r*r*3.141592653589;
cout <<fixed<< setprecision(6)<< s<<" "<<l;
    return 0;
}

Measured memory_bytes: 1284
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>
#include <assert.h>
#include <bitset>
#include <list>

auto& in = std::cin;
auto& out = std::cout;
#define all_range(C) std::begin(C), std::end(C)
const double PI = 3.141592653589793238462643383279502884197169399375105820974944;

int32_t N;

int64_t gcd(int64_t a, int64_t b)
{
	while (b > 0)
	{
		auto c = b;
		b = a % b;
		a = c;
	}
	return a;
}
int a[100000];
int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);
	in.tie(nullptr);
	out.tie(nullptr);
	

	int n,k;
	in >> n>>k;
	for (int i = 0; i < n; i++)
	{
		in >> a[i];
	}
	int64_t g = a[0];
	for (int i = 0; i < n; i++)
	{
		g = gcd(g, a[i]);
	}
	if (k%g || *std::max_element(a,a+n)< k) {
		out << "IM";
	}
	out << "POSSIBLE" << endl;

	return 0;
}
#endif


Measured memory_bytes: 640
read n m x y;
for((;++i<n;))do
	read -d' ' a
	x=$[x<a?a:x]
done
read a
x=$[x<a?a:x]
for((;++j<m;))do
	read -d' ' a
	y=$[y<a?y:a]
done
read -d' ' a
y=$[y<a?y:a]
[ $x -lt $y ]&&echo No War||echo War

Measured memory_bytes: 376
import sys
from heapq import heappop, heappush


adjacent = (
    (1, 4),
    (0, 2, 5),
    (1, 3, 6),
    (2, 7),
    (0, 5, 8),
    (1, 4, 6, 9),
    (2, 5, 7, 10),
    (3, 6, 11),
    (4, 9, 12),
    (5, 8, 10, 13),
    (6, 9, 11, 14),
    (7, 10, 15),
    (8, 13),
    (9, 12, 14),
    (10, 13, 15),
    (11, 14)
)

distance = (
    (),
    (0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5, 3, 4, 5, 6),
    (1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4, 4, 3, 4, 5),
    (2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3, 5, 4, 3, 4),
    (3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2, 6, 5, 4, 3),
    (1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4, 2, 3, 4, 5),
    (2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3, 3, 2, 3, 4),
    (3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2, 4, 3, 2, 3),
    (4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1, 5, 4, 3, 2),
    (2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3, 1, 2, 3, 4),
    (3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2, 2, 1, 2, 3),
    (4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1, 3, 2, 1, 2),
    (5, 4, 3, 2, 4, 3, 2, 1, 3, 2, 1, 0, 4, 3, 2, 1),
    (3, 4, 5, 6, 2, 3, 4, 5, 1, 2, 3, 4, 0, 1, 2, 3),
    (4, 3, 4, 5, 3, 2, 3, 4, 2, 1, 2, 3, 1, 0, 1, 2),
    (5, 4, 3, 4, 4, 3, 2, 3, 3, 2, 1, 2, 2, 1, 0, 1)
)

end = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0]


def get_distance():
    global board
    sum_distance = 0
    for i in range(16):
        if board[i] == 0:
            continue
        sum_distance += distance[board[i]][i]
    return sum_distance


def search(limit, move, space, lower, prev_space):
    global board

    if move == limit:
        if board == end:
            return True

    else:
        for next_space in adjacent[space]:
            if next_space == prev_space:
                continue
            board[space] = board[next_space]
            board[next_space] = 0

            new_lower = lower - distance[board[space]][next_space] + distance[board[space]][space]

            if new_lower + move <= limit:
                if search(limit, move + 1, next_space, new_lower, space):
                    return True
            board[next_space] = board[space]
            board[space] = 0


board = []
for _ in range(4):
    board.extend(list(map(int, sys.stdin.readline().strip().split())))

# 最初のスペースの位置で、解の手順が奇数手か偶数手かが決定される
n = get_distance()  # 暫定的な最小手
first_space = board.index(0)
e_o = (0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 0)
if n % 2 != e_o[first_space]:
    n += 1

for l in range(n, 46, 2):
    if search(l, 0, first_space, n, None):
        print(l)
        break



Measured memory_bytes: 5772
/// Rustで競技プログラミングの入力をスッキリ記述するマクロ
///
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

#[inline]
#[allow(dead_code)]
fn gcd(mut m: u64, mut n: u64) -> u64 {
    if m < n {
        std::mem::swap(&mut m, &mut n);
    }

    loop {
        let k = m % n;
        if k == 0 {
            return n;
        }

        m = n;
        n = k;
    }
}

#[inline]
#[allow(dead_code)]
fn lcm(m: u64, n: u64) -> u64 {
    m / gcd(m, n) * n
}

macro_rules! eprint(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = write!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! eprintln(
    ($($arg:tt)*) => { {
        use std::io::Write;
        let r = writeln!(&mut ::std::io::stderr(), $($arg)*);
        r.expect("failed printing to stderr");
    } }
);

macro_rules! dbg {
    ($val:expr) => {
        // Use of `match` here is intentional because it affects the lifetimes
        // of temporaries - https://stackoverflow.com/a/48732525/1063961
        match $val {
            tmp => {
                eprintln!("[{}:{}] {} = {:#?}",
                          file!(), line!(), stringify!($val), &tmp);
                tmp
            }
        }
    }
}

fn main() {
    input!{
        n: u64,
        m: u64,
    }

    let div = 1000000007;

    let sub_abs = (n as i64 - m as i64).abs() as u64;

    let mut answer = if sub_abs > 1 {
        0
    } else {
        let n_fac = (2..(n+1)).fold(1, |mul, x| (mul % div) * (x % div)) % div;
        let m_fac = (2..(m+1)).fold(1, |mul, x| (mul % div) * (x % div)) % div;
        (n_fac * m_fac) % div
    };

    if sub_abs == 0 {
        answer *= 2;
        answer = answer % div;
    }

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


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second

ll n, d[101];
 
int main(int argc, char **argv) {
	CLEAR(d);
	cin >> n;
	REP(i, n) {
		ll t;
		cin >> t;
		d[t] = 1;
	}
	ll res = 0;
	REP(i, 101) res += d[i];
	cout << res << endl;
	return 0;
}
 

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

vector<string> ans;

int main(){
    string res = "";
    char c;
    while(~(c = getchar())){
	if(c == ',' || c == ' ' || c == '.'){
	    if(res.size() >= 3 && res.size() <= 6)
		ans.push_back(res);	    
	    res = "";
	}
	else{
	    res += c;
	}
    }
    for(int i = 0;i < ans.size();i++){
	cout << ans[i];
	if(i != ans.size()-1)cout << " ";
    }
   cout << endl;
    return 0;
}

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

typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int> > vii;
#define rrep(i, m, n) for(int (i)=(m); (i)<(n);  (i)++)
#define erep(i, m, n) for(int (i)=(m); (i)<=(n); (i)++)
#define  rep(i, n)    for(int (i)=0; (i)<(n);  (i)++)
#define  rev(i, n)    for(int (i)=(n)-1; (i)>=0; (i)--)
#define erev(i, m, n) for(int (i)=(m); (i)>=n; (i)--)
#define vrep(i, c)    for(__typeof((c).begin())i=(c).begin(); i!=(c).end(); i++)
#define  ALL(v)       (v).begin(), (v).end()
#define mp            make_pair
#define pb            push_back
template<class T1, class T2> inline void minup(T1& m, T2 x){ if(m>x) m=static_cast<T2>(x); }
template<class T1, class T2> inline void maxup(T1& m, T2 x){ if(m<x) m=static_cast<T2>(x); }

#define INF 1000000000
#define MOD 1000000009
#define EPS 1E-9

const int MAX_N = 100;
const int MAX_W = 10000;
int N, W;
int v[MAX_N];
int w[MAX_N];
int dp[MAX_W+1];

int main()
{
  cin >> N >> W;
  rep(i, N) cin >> v[i] >> w[i];

  rep(i, N) erep(j, w[i], W) maxup(dp[j], dp[j-w[i]] + v[i]);

  cout << dp[W] << endl;

  return 0;
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
 
using namespace std;
using vecint = vector<int>;
 
int main(){
    int a,b,c,x;
    cin >> a>> b>>c>>x;
    int ans= 0;
    FOR(i,0,a+1){
        FOR(j,0,b+1){
            FOR(k,0,c+1){
                if(i*500+j*100+50*k == x){
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int suuji;
  int i = 1;
  while(true){
    cin >> suuji;
    if(suuji == 0)	break;
    cout << "Case " << i << ": " << suuji << endl;
    i++;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
  ll a[5],b[5],c[5];
  for(ll i=0;i<5;i++) {
    cin >>a[i];
    if(a[i]%10==0) b[i]=0;
    else{
      ll p=((a[i]/10)+1)*10;
      b[i]=p-a[i];
    }
    c[i]=b[i];
  }
  sort(b,b+5);
  ll k;
  for(ll i=0;i<5;i++){
    if(c[i]==b[4]){
      k=i;
      break;
    }
  }
  ll ans=0;
  for(ll i=0;i<5;i++){
    if(i==k) ans+=a[i];
    else if(c[i]==0) ans+=a[i];
    else ans+=(a[i]+c[i]);
  }
  cout <<ans<<endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long N;
int ans=12;
int main(){
    cin>>N;
    for(long long i=1;i*i<=N;i++){
        if(N%i==0){
            ans=min(ans,(int)to_string(N/i).size());
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
///
// File:  1346.cpp
// Author: ymiyamoto
//
// Created on Sun Nov 26 02:53:16 2017
//

#include <cstdint>
#include <iostream>
#include <stack>
#include <string>

using namespace std;

int32_t main()
{
  string str;
  cin >> str;
  uint32_t n;
  cin >> n;

  stack<int32_t> stack;
  for (uint32_t i = 0; i < str.size(); i++) {
    if (i % 2 == 0) {
      uint32_t val = str[i] - '0';
      stack.push(val);
    } else {
      char op = str[i];
      if (op == '*') {
        i++;
        uint32_t val1 = stack.top();
        stack.pop();
        uint32_t val2 = str[i] - '0';
        stack.push(val1 * val2);
      }
    }
  }

  uint32_t result1 = 0;
  while (!stack.empty()) {
    result1 += stack.top();
    stack.pop();
  }

  uint32_t result2 = str[0] - '0';
  for (uint32_t i = 1; i < str.size(); i++) {
    if (str[i] == '+') {
      i++;
      result2 += str[i] - '0';
    } else {
      i++;
      result2 *= str[i] - '0';
    }
  }

  if (result1 == n && result2 == n) {
    cout << "U" << endl;
  } else if (result1 == n) {
    cout << "M" << endl;
  } else if (result2 == n) {
    cout << "L" << endl;
  } else {
    cout << "I" << endl;
  }

  return 0;
}

Measured memory_bytes: 3208
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC128
{
    class E
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();
            int N = a[0], Q = a[1];

            List<int[]> list = new List<int[]>();
            for (int i = 0; i < N; i++)
            {
                int[] b = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();
                int[] x = { b[0] - b[2], 0, b[2], i };
                list.Add(x);
                int[] y = { b[1] - b[2], 1, b[2], i };
                list.Add(y);
            }
            list = list.OrderBy(x => x[0]).ToList();

            bool[] uc = new bool[N];
            List<int> qlist = new List<int>();
            for (int i = 0; i < Q; i++)
            {
                int[] c = Console.ReadLine().Split(' ').Select(cc => int.Parse(cc)).ToArray();
                qlist.Add(c[0]);
            }

            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            int index = 0;
            SortedSet<int> ss = new SortedSet<int>();
            foreach(int q in qlist)
            {
                while (index < list.Count)
                {
                    int[] data = list[index];
                    if (data[0] > q) break;

                    if (data[1] == 0)
                    {
                        ss.Add(data[2]);
                    }
                    else
                    {
                        ss.Remove(data[2]);
                    }
                    index++;
                }

                int min = -1;
                if (ss.Count > 0) min = ss.First();
                Console.WriteLine(min);
            }

            Console.Out.Flush();

        }

    }
}


Measured memory_bytes: 60392
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(long long int i = 0; i < (n); i++)


int Len(int n) {
  int s=0;
  while(n!=0) s++, n/=10;
  return s;
}


int Sint(int n) {
  int m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(int i=s-1;i>=0;i--) m+=n/((int)pow(10,i))-(n/((int)pow(10,i+1)))*10;
  return m;
}


int Svec(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}


int GCD(int a,int b){
  int r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


int LCM(int a,int b){
  int c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


int Factorial(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}




/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  long long int n,ans=0;
  cin>>n;
  vector<string> v(n);
  map<string,long long int> mp;
  rep(i,n){
    cin>>v[i];
    sort(v[i].begin(),v[i].end());
  }
  rep(i,n){
    mp[v[i]]++;
  }
  for(auto c:mp){
    ans+=(c.second-1)*(c.second)/2;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 18176
import sys
from itertools import combinations


fin = sys.stdin.readline
N, A, B, C = [int(elem) for elem in fin().split()]
l_list = sorted([int(fin()) for _ in range(N)], reverse=True)

min_mp = float('inf')
for num_conc_A in range(1, N - 1):
    # mp = 0
    rest_indices = set(range(N))
    for A_indices in combinations(rest_indices, num_conc_A):
        mp_A = 10 * (num_conc_A - 1) + abs(sum(l_list[i] for i in A_indices) - A)
        rest_indices -= set(A_indices)
        for num_conc_B in range(1, N - num_conc_A):
            for B_indices in combinations(rest_indices, num_conc_B):
                mp_B = 10 * (num_conc_B - 1) + abs(sum(l_list[i] for i in B_indices) - B)
                rest_indices -= set(B_indices)
                for num_conc_C in range(1, N - num_conc_A - num_conc_B + 1):
                    for C_indices in combinations(rest_indices, num_conc_C):
                        mp_C = 10 * (num_conc_C - 1) + abs(sum(l_list[i] for i in C_indices) - C)
                        min_mp = min(min_mp, mp_A + mp_B + mp_C)
                rest_indices.update(set(B_indices))
        rest_indices.update(set(A_indices))
print(min_mp)

Measured memory_bytes: 69904
#include <stdio.h>

int  max(int,int);

int  main(){
    int n;
    int a[3][100000];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d%d%d",&a[0][i],&a[1][i],&a[2][i]);
    }
    int dp[3][100000]={};
    dp[0][0]=a[0][0];
    dp[1][0]=a[1][0];
    dp[2][0]=a[2][0];

    for(int i=1;i<n;i++){
        dp[0][i]=max(a[0][i]+dp[1][i-1],a[0][i]+dp[2][i-1]);
        dp[1][i]=max(a[1][i]+dp[0][i-1],a[1][i]+dp[2][i-1]);
        dp[2][i]=max(a[2][i]+dp[1][i-1],a[2][i]+dp[0][i-1]);
    }
    int answer=max(dp[0][n-1],max(dp[1][n-1],dp[2][n-1]));
    printf("%d\n",answer);
}

int max(int a,int b){
    if(a>=b) return a;
    else return b;
}

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

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

int main() {
  int k;
  cin >> k;
  
  int ans = 0;
  for (int a = 1; a <= k; a++)
  {
      for (int b = 1; b <= k; b++)
      {
          for (int c = 1; c <= k; c++)
          {
              ans += gcd(gcd(a,b),c);
          }   
      }   
  }
  cout << ans << endl;
}


Measured memory_bytes: 3636