akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<map>
#include<string>
#include<algorithm>
#include<sstream>
#include<cmath>
#include<typeinfo>
using namespace std;

int main() {
	string s,t;
	cin >> s >> t;
	bool flag = true;
	for (int i = 0; i < s.size(); i++) {
		if (s[i] != t[i]) {
			flag = false;
			break;
		}
	}
	if (flag) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 3628
const main = (input) => {
  var s = input[0];
  var ans = true;
  s.split("").forEach((v,i)=>{
    if(i%2==0){
      if(['R', 'U', 'D'].indexOf(v) == -1) ans = false;
    }else{
      if(['L', 'U', 'D'].indexOf(v) == -1) ans = false;
    }
  })
  console.log(ans?"Yes":"No");
}
main(require('fs').readFileSync('/dev/stdin', 'UTF-8').trim().split("\n"));


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

#define ll long long int
ll const mod = 1e9 + 7;

ll power(ll x, ll y, ll p){ //x^y % p
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or equal to p 
    while (y > 0) {
        if (y & 1) // If y is odd, multiply x with result 
        res = (res*x) % p; 
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n,m;
    cin>>n>>m;
    string a[n];
    for(int i=0;i<n;i++)
            cin>>a[i];
    ll dp[n][m];
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(i+j==0) dp[i][j]=1;
            else if(j==0) dp[i][j]=(a[i][j]=='.')?dp[i-1][j]:0;
            else if(i==0) dp[i][j]=(a[i][j]=='.')?dp[i][j-1]:0;
            else dp[i][j]=(a[i][j]=='.')?(dp[i-1][j]+dp[i][j-1])%mod:0;
        }
    }
    cout<<dp[n-1][m-1];
	// your code goes here
	return 0;
}


Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int H = sc.nextInt();
        int M = sc.nextInt();
        sc.close();

        // 角度を求める
        double kakudoA = (double) (0.5 * (H * 60 + M));
        double kakudoB = (double) (6 * M);
        double kakudoC = Math.abs(kakudoA - kakudoB);

        double c = 0;
        if (kakudoC == 0) {
            c = Math.abs(A - B);
        } else if (kakudoC == 180) {
            c = A + B;
        } else if (kakudoC < 180) {
            c = Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(Math.toRadians(kakudoC)));
        } else {
            kakudoC = 360 - kakudoC;
            c = Math.sqrt(A * A + B * B - 2 * A * B * Math.cos(Math.toRadians(kakudoC)));
        }
        System.out.println(c);
        return;
    }
}

Measured memory_bytes: 35852
// Ballazt
//0a..brute force
//0b..greedy
//1..memorizatton of some sort	remember something cleverly
//2..sort
//3..binary search	keep check a particular solution
//4..dp				repeating strucutre,limited choices
//5..dfs/bfs		matrix with obstacles
//6..correlate to graph in some way		each state is a point
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define endl "\n"


int main()

{
	ios::sync_with_stdio(0);
	cin.tie(0);

	
	string s;
	cin>>s;
	if(s=="ABC") cout<<"ARC";
	if(s=="ARC") cout<<"ABC";

	//cout<<"end of loop";
	return 0;
	
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define write(x) printf("%d\n", x)
using namespace std;
typedef long long ll;
template <typename T>
void read(T &x)
{
	x = 0;
	char c;
	while (!isdigit(c = getchar()));
	do
	{
		x = (x << 1) + (x << 3) + (c ^ 48);
	}while (isdigit(c = getchar()));
}
int main()
{
	int h, a;
	read(h);read(a);
	write((h + a - 1) / a);
	return 0;
}



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

int main(){
    int a, b; cin >> a >> b;
    int ans;
    if(a * b == 2) ans = 3;
    else if(a * b == 3) ans = 2;
    else if(a * b == 6) ans = 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> acs(5);
int main() {
    cin >> n;
    for(int i = 0; i < 5; ++i) cin >> acs.at(i);

    long long cnt = 0;
    sort(acs.begin(), acs.end());
    if(n % acs.at(0) == 0) {
        cnt = n / acs.at(0);
    }else {
        cnt = n / acs.at(0) + 1;
    }

    cout << cnt + 4 << endl;
}

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

int main()
{

    int n;
    deque<int>D;
    cin >> n;
    while(n--){
        int x;
        cin >> x;
        if(n%2)
            D.push_back(x);
        else
            D.push_front(x);
    }
       for(int i=0;i<D.size();i++){
            if(i!=0)
                cout << " ";
            cout << D[i];
        }
        cout << endl;
}


Measured memory_bytes: 2944
fun main(args: Array<String>) {

    val (h, n) = readLine()!!.split(' ').map(String::toInt)
    val abList = mutableListOf<Pair<Int, Int>>()
    (1..n).forEach {
        val (a, b) = readLine()!!.split(' ').map(String::toInt)
        abList.add(Pair(a, b))
    }
    abList.sortBy { it.second.toDouble() / it.first.toDouble() }

    var ans = Long.MAX_VALUE / 2
    val dp = LongArray(10001) { Long.MAX_VALUE / 2 }
    for (ab in abList) {
        val (a, b) = ab
        dp[a] = Math.min(dp[a], b.toLong())
        if (a > h) ans = Math.min(ans, b.toLong())
        for (i in 1 until h) {
            if (dp[i] != 0L) {
                if (i + a >= h) ans = Math.min(ans, dp[i] + b.toLong())
                else dp[i + a] = Math.min(dp[i + a], dp[i] + b.toLong())
            }
        }
    }
    println(ans)
}

Measured memory_bytes: 40624
#include<iostream>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a<b)
    cout << "a < b" << endl;
  else if(a>b)
    cout << "a > b" << endl;
  else
    cout << "a == b" << endl;
  return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

using namespace std;
using namespace chrono;
 
typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

//#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define loop(x,n) for(int x = 0; x < n; ++x)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

string get_str() {
    string temp;
    cin >> temp;
    return temp;
}
int get_int() {
    int temp;
    cin >> temp;
    return temp;
}

bool tmp(int a, int b) {
    return a>b;
}

void solve() {

    int n, a[200000];
    cin >> n;
    loop(i, n) cin >> a[i];
    
    sort(a, a+n, tmp);
    
    ll ans = a[0]; n-=2; ll t;

    for(int i=1; n >= 2; i++) {
        n-=2;
        ans += a[i]*2;
        t=i;
    }

    if(n==1) ans += a[t+1];

    cout << ans << endl;

}

int main() {
    
    solve();

}

Measured memory_bytes: 4384
#include <cstdio>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<fstream>

#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
using namespace std;

int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
       
    ll i,j,k,p=1,q=1;
    ll n,m,tmp;
    string s[200000];
    string str;
    ll sum=0;
    ll strr[200005];
    cin>>n;
    ll cnt=0;
    if(n%2) cnt++;
    if(n==1) cnt=0; 
    for(i=1;i<=n/2-1;i++){
        cnt++;
    }

    
    cout<<cnt<<endl;
    return 0;
}

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

long long c[100001];
long long cost(int arr[],int n)
{
    if(n==2)
        return abs(arr[2]-arr[1]);
    if(n==1)
        return 0;
    if(c[n] != -1)
        return c[n];
    c[n]=min(cost(arr,n-1)+abs(arr[n]-arr[n-1]) , cost(arr,n-2)+abs(arr[n]-arr[n-2]));
    return c[n];
}
int main()
{
    long long n,ans;
    cin>>n;
    memset(c,-1,sizeof(c));
    int arr[n+1];
    for(int i=1;i<=n;++i)
        cin>>arr[i];
    ans=cost(arr,n);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 4480
# 何行あるかわからない入力をまとめて処理する
import sys
line = sys.stdin.readlines()
#print(line)
for i in line:
    # map関数は配列の型を一括変換するのに便利
    b = list(map(int, i.split(" ")))
    c = 1
    d = b[0] + b[1]
    while(d >= 10):
        c += 1
        d = d / 10
    print(c)



Measured memory_bytes: 5608
#include <stdio.h>

int ans[] = {
850,
1100,
1230,
1400,
1610,
1520,
1950,
1870,
2070,
2250,
2244,
2620,
2624,
2794,
3004,
3040,
3344,
3390,
3590,
3740,
3764,
4120,
4114,
4314,
4494,
4488,
4864,
4868,
5038,
5248,
5284,
5588,
5634,
5834,
5984,
6008,
6364,
6358,
6558,
6738,
6732,
7108,
7112,
7282,
7492,
7528
};

int main(void){
	int n;
	while(scanf("%d",&n) && n){
		printf("%d\n",ans[n/100-5]);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <string.h>

int main(void){
    int N,X,T,amari,ans;

    scanf("%d %d %d",&N ,&X, &T);

    amari = N % X;
    if(amari != 0)
    {
        ans = (N / X + 1) * T; 
    }
    else
    {
        ans = (N / X) * T; 
    }
    

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

    return 0;
    
}




Measured memory_bytes: 1724
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s; int mx = 0;
    for(int i=0; i<s.size(); i++)
    {
        for(int j=i; j<s.size(); j++)
        {
             int count =0;
            for(int k=i; k<=j; k++)
            {
                if(s[k]=='A'|| s[k]=='C' || s[k]=='G' || s[k]=='T')
                {
                    count++;
                }
                else
                {
                    break;
                }
            }
            mx = max(mx, count);
        }
    }
    cout<<mx<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<60> Bitset;
const ll INFL = 1LL << 60;
const int INF = INT_MAX;
const int MAX = 300000;
const int MOD = 1000000007;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;cin>>n;
    vector<ll>cnt(n+1,2);
    cnt[1] = 1;
    for(int i = 2; i <= n; i++) {
        for(int j = i*2; j <= n; j+=i) {
            cnt[j]++;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += i*cnt[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 81304
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <string.h>
#define pb push_back
#define INF (int)1e9

using namespace std;
int dp[44][444][444];
struct abc{
  int a,b,c;
  abc(int x,int y,int z){
    a=x;b=y;c=z;
  }
};
int main(void){
  int n;
  double mm;
  int a,b,c,ma,mb;
  int i,j,k,res;
  vector<abc> yaku;
  scanf("%d %d %d",&n,&ma,&mb);
  mm=ma/mb;
  for(i=0;i<n;i++){
    scanf("%d %d %d",&a,&b,&c);
    yaku.pb(abc(a,b,c));
  }
  for(i=0;i<=n;i++) for(j=0;j<=444;j++) for(k=0;k<=444;k++) dp[i][j][k]=INF;
  dp[0][0][0]=0;
  res=INF;
  for(i=0;i<n;i++){
    for(j=0;j<=444;j++){
      for(k=0;k<=444;k++){
        dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
        dp[i+1][j+yaku[i].a][k+yaku[i].b]=min(dp[i+1][j+yaku[i].a][k+yaku[i].b],dp[i][j][k]+yaku[i].c);
      }
    }
  }
  for(j=1;j<=444;j++){
    for(k=1;k<=444;k++){
      if(j*mb==k*ma) res=min(res,dp[n][j][k]);
    }
  }
  if(res==INF) res=-1;
  cout<<res<<endl;
  return 0;
}

Measured memory_bytes: 31872
//Littleboy123 Template 1.7
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

//pragmas

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC target ("avx2")
// #pragma GCC optimization ("O3")
// #pragma GCC optimization ("unroll-loops")


typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef pair<ll, ll> pll;
typedef unsigned long long int ull;
typedef long double ld;
typedef unsigned long long ull;

const long double pi = acos(-1.0);

#define FOR(a,b,c) for(ll (a)=(b);(a)<(c);++(a))
#define FORE(a,b,c) for(ll (a)=(b);(a)<=(c);++(a))
#define FORN(a,b,c) for(ll (a)=(b);(a)>(c);--(a))
#define FORNE(a,b,c) for(ll (a)=(b);(a)>=(c);--(a))
#define TC(n) cout << "Case #" << (n) << ": "
#define DEBUG(x) cout << "DEBUG " << #x << ' ' << x << '\n';
#define MEM(a,b) memset((a), (b), sizeof((a)))
#define MAX(a,b) (a) = max((a), (b))
#define MIN(a,b) (a) = min((a), (b))
#define nl '\n'
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>

void init(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

void infile(){
    freopen("fenwick.in", "r", stdin);
}

void outfile(){
    freopen("fenwick.out", "w", stdout);
}

ll modex(ll a, ll b, ll mod){
    if(b == 0)
        return 1;
    if(b == 1)
        return a;
    ll tmp = modex(a, b/2, mod);
    tmp = (tmp * tmp) % mod;
    if(b & 1)
        tmp = (tmp * a) % mod;
    return tmp;
}

//End of template

int main(){
    init();

    int n;
    cin >> n;
    ll arr[105];
    FOR(i, 0, n){
        cin >> arr[i];
    }
    ll cnt = 0;
    FOR(i, 0, n){
        FOR(j, i+1, n){
            FOR(k, j+1, n){
                if(arr[i] == arr[j] || arr[i] == arr[k] || arr[k] == arr[j])
                    continue;
                if(arr[i] + arr[j] > arr[k] && arr[i] + arr[k] > arr[j] && arr[k] + arr[j] > arr[i]){
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3696
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
using namespace std;
using LL = long long;

LL Q, H, S, D;
LL N;

int main(void)
{
	cin >> Q >> H >> S >> D;
	cin >> N;
	H = min(H, 2 * Q);
	S = min(S, 2 * H);
	D = min(D, 2 * S);
	LL two = N / 2;
	LL one = N % 2;
	cout << two * D + one * S << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = [0 for _ in range(n // 2)] + a[n // 2:]
for i in range(n // 2 - 1, -1, -1):
    b[i] = abs(a[i] - sum(b[i::i + 1]) % 2)
print(sum(b))
print(*([i + 1 for i, bi in enumerate(b) if bi > 0]))


Measured memory_bytes: 13244
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>

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

typedef long long ll;

using namespace std;

int main()
{
    ll N;
    cin >> N;
    ll d;
    for(d = sqrt(N); d > 1; d--)
    {
        if(N % d == 0) break;
    }
    N /= d;
    cout << N + d -2 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string.h> 

using namespace std;



int main(void){

  int x;
  int count = 0;

  do{
   cin >> x;
   count++;
   if(x != 0)
      cout << "Case " << count << ": " << x << endl;
  }while(x != 0);

return 0;
}

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

int main(){
  int N; cin >> N;
  vector<int>p(N+1);
  for(int i=1;i<=N;i++){
    cin >> p.at(i);
  }
  int count = 0;
  for(int i=1;i<=N;i++){
    if(p.at(i) == i) count++;
  }
  if(count == N || count == N-2) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
import java.util.*;


		       public class Main {

		           public static void main(String args[])  {
		        	   Scanner sc =new Scanner(System.in);
		        	   int S = sc.nextInt();
		        	   int W = sc.nextInt();
		        	   
		        	   if(S<=W) {
		        		   System.out.println("unsafe");
		        		   
		        	   }else {
		        		   System.out.println("safe");
		        	   }
		        	   

		           }
		       }




Measured memory_bytes: 35840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> P1;
typedef pair<P, P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i, x) for (long long i = 0; i < x; i++)
#define repn(i, x) for (long long i = 1; i <= x; i++)
#define SORT(x) sort(x.begin(), x.end())
#define ERASE(x) x.erase(unique(x.begin(), x.end()), x.end())
#define POSL(x, v) (lower_bound(x.begin(), x.end(), v) - x.begin())
#define POSU(x, v) (upper_bound(x.begin(), x.end(), v) - x.begin())
vector<pair<string, P> > vec;
// vector<vector<int>> data(3, vector<int>(4));

const string YES = "Yes";
const string NO = "No";

void solve(std::string S, std::string T) {
    ll n = S.length();
    vector<ll> sv(26, -1), tv(26, -1);
    bool flg = true;
    rep(i, n) {
        ll sn = S[i] - 'a', tn = T[i] - 'a';
        if ((sv[sn] != -1 && sv[sn] != tn) || (tv[tn] != -1 && tv[tn] != sn)) flg = false;
        sv[sn] = tn;
        tv[tn] = sn;
        // cout << S[i] - 'a' << " " << v[S[i] - 'a'] << endl;
    }
    if (flg)
        cout << YES << endl;
    else
        cout << NO << endl;
}

int main() {
    std::string S;
    std::cin >> S;
    std::string T;
    std::cin >> T;
    solve(S, T);
    return 0;
}


Measured memory_bytes: 1160
h,w = map(int,input().split())
maze = [input() for _ in range(h)]
from collections import deque
D = [(0,1),(1,0),(-1,0),(0,-1)]
ans = 0
for i in range(h):
  for j in range(w):
    if maze[i][j]=='#':
      continue
    queue  = deque([(i,j,0)])
    checked = [[0 for _ in range(w)] for _ in range(h)]
    checked[i][j] = 1
    while queue:
      j,k,d = queue.popleft()
      for dx,dy in D:
        x,y = j+dx,k+dy
        if not(0<=x<h) or not(0<=y<w):
          continue
        if maze[x][y] == '#':
          continue
        if checked[x][y]:
          continue
        checked[x][y] = d+1
        queue.append((x,y,d+1))
    for j in range(h):
      for k in range(w):
        if checked:
          ans = max(ans,checked[j][k])

print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
double dp[3005][3005];
double p[3005];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
  }
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= i; j++) {
      int x = j, y = i - j;
      if (x)
        dp[x][y] += dp[x - 1][y] * p[i];
      if (y)
        dp[x][y] += dp[x][y - 1] * (1 - p[i]);
    }
  }
  double ans = 0;
  for (int i = n, j = 0; i > j; i--, j++) {
    ans += dp[i][j];
  }
  printf("%.10lf\n", ans);
}


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

typedef long long ll;
#define FAST_IO ios_base::sync_with_stdio(0); cin.tie(0);
//#define cerr if(false)cerr
#define PRINT(x) cerr<<"\n" << (#x) << " is " << (x) << endl;
//Erase duplicates in vector
#define REMOVE_DUP(x) x.erase(unique(x.begin(), x.end()), x.end());
#define UP toupper // lowercase to uppercase;
#define DOWN tolower
#define SZ(a) (int)a.size()
#define EB emplace_back
#define PB push_back
#define REP(i, a, b) for(int i=a; i<b; i++)
#define PER(i, a, b) for(int i=a; i>=b; i--)
ostream_iterator<int> output(cout, " ");
#define MOD 1e9+7
#define INF 10008

void solve(){
	ll x, k;
	cin >> x >> k;
	x %= k;
	cout << min(x, k-x) << endl;
}

int32_t main(){
	FAST_IO;
	int t1 = 1; //cin >> t1;
	while(t1--)
		solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N, K;
  cin >> N >> K;
  vector<int> d(K);
  vector<vector<int>> A(K);
  for(int i = 0; i < K; i++){
    cin >> d[i];
    for(int j = 0; j < d[i]; j++){
      int num;
      cin >> num;
      A[i].push_back(num);
    }
  }
  int ans = 0;
  for(int count = 1; count <= N; count++){
    bool key = false;
    for(int i = 0; i < K; i++){
      for(int j = 0; j < A[i].size(); j++){
        if(count == A[i][j]){
          key = true;
        }
      }
    }
    if(key == false){
      ans++;
    }
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 3580
N, K, S = map(int, input().split())

res = []
for x in range(K):
    res.append(S)

q = N - K

fix = round(1e9) if S != 1e9 else round(1e9 - 1)

for _q in range(q):
    res.append(fix)

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

Measured memory_bytes: 12056
// 2020 05 10
// A
#include <algorithm>
#include <complex>
#include <string>
#include <deque>
#include <iostream>
#include <set>
#include <stack>
#include <string>
#include <queue>
#include <utility>
#include <vector>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main() {
    string S;
    string T;
    cin >> S >> T;
    for(int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) {
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;


    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n],c[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    c[0]=0,c[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++){
        c[i]=min(c[i-1]+abs(a[i]-a[i-1]),c[i-2]+abs(a[i]-a[i-2]));
    }
    cout<<c[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#ifdef DEBUG
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
#else
#define show(...) 42
#endif
using namespace std;
using ll = long long;
using pii = pair<int, int>;
template <typename T, typename S>
ostream& operator<<(ostream& os, pair<T, S> a) {
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (auto x : v) os << x << ' ';
    return os;
}
void debug() {
    cerr << '\n';
}
template <typename H, typename... T>
void debug(H a, T... b) {
    cerr << a;
    if (sizeof...(b)) cerr << ", ";
    debug(b...);
}
int main(){
    int n;
    cin >> n;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        if(x!=i+1)cnt++;
    }
    if(cnt<=2){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;
int main()
{
	boost;
	int n, i;
	cin >> n;
	int arr[n];
	fo(i, 0, n)
	cin >> arr[i];
	
	int res = 0;
	for(int x : arr)
	res ^= x;
	
	for(int x : arr)
	cout << (res ^ x) << ' ';
}


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

const int p = 1e9 + 7;

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

    int *f;
    f = new int[s + 1]();
    for (int i = 3; i <= s; ++i)
    {
        f[i] = 1;
        for (int j = 3; j <= i - 3; ++j)
        {
            f[i] = (f[i] + f[j]) % p;
        }
    }

    std::cout << f[s] << std::endl;
    return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define push_back pb

using namespace std;

typedef long long ll;

void solve(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll xa;
    xa=min(a,k);
    k-=xa;
    ll xb=min(b,k);
    k-=xb;
    ll xc=k;
    cout<<xa-xc<<"\n";
}

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

    //freopen("in.txt", "r", stdin);

    solve();


    return 0;
}


Measured memory_bytes: 3616
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace _gnu_pbds;
#define vb __int128
#define ll long long
#define ld long double
#define full(a) a.begin(),a.end()
#define fr(i,a,b) for(ll i = a ; i < b ; i++)
#define stoink stack<ll>
#define quu queue<ll>
#define quee queue<pair<ll,ll>>
#define vec vector <ll>
#define vecd vector<ld>
#define vg vector<vector<ll> >
#define eg vector<pair<ll,ll>>
#define vgw vector<vector<pair<ll,ll> > >
#define pa pair<ll,ll>
#define pb push_back
#define ff first
#define ss second
#define pre 0.00000000000000000001
#define inf 100000000
#define mod 998244353
#define endl '\n'
vec ft(200005);
ll n;
void add(ll ind,ll val) {
    while(ind <= n){
        ft[ind] =max(val,ft[ind]);
        ind += ind & -ind;
    }
}
ll sum(ll ind) {
    ll maxi = 0;
    while(ind > 0) {
        maxi = max(ft[ind],maxi);
        ind -= ind & -ind;
    }
    return maxi;
}
int main()
{	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
    cin >> n;
    vec height(n);
    vec beauty(n);
    fr(i,0,n) cin >> height[i];
    fr(i,0,n) cin >> beauty[i];
    ll ans = 0;
    fr(i,0,n) {
        ll val = beauty[i] + sum(height[i]);
        ans = max(ans,val);
        add(height[i],val);
    }
    cout << ans << endl;
	return 0;
}	

Measured memory_bytes: 7936
import java.util.*;
import java.math.*;
import java.io.*;

public class Main{
  public static void main(String agrgs[]){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int k=sc.nextInt();
    int arr[]=new int[n];
    for(int i=0;i<n;i++){
      arr[i]=sc.nextInt();
    }
    int dp[]=new int[n];
    Arrays.fill(dp,Integer.MAX_VALUE);
    dp[0]=0;
    for(int i=0;i<n-1;i++){
     	for(int j=i+1;j<=i+k&&j<n;j++){
     	    
     	    dp[j]=Math.min(Math.abs(arr[i]-arr[j])+dp[i],dp[j]);
     	}
    }
    System.out.println(dp[n-1]);
  }
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n);
    for (int i=0; i<n; ++i) {
        cin >> h[i];
    }
    vector<set<int>> g(n);
    vector<int> maxh(n, 0);
    for (int i=0; i<m; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].insert(b);
        g[b].insert(a);
        maxh[a] = max(maxh[a], h[b]);
        maxh[b] = max(maxh[b], h[a]);
    }
    int ans = 0;
    for (int i=0; i<n; ++i) {
        if (h[i] > maxh[i]) ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main(void) {
	int N,M,C;
	cin >> N >> M >> C;;
	vector<int> B(M);
	for (int i = 0; i < M; ++i) {
		cin >> B[i];
	}
	int res = 0;
	for (int i = 0; i < N; ++i) {
		int score = C;
		for (int j = 0; j < M; ++j) {
			int A;
			cin >> A;
			score += A*B[j];
		}
		if (score > 0) {
			++res;
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# coding: utf-8

from collections import Counter

def main():
    n = int(input())
    A = list(map(int, input().split()))
    counts = Counter()
    for a in A:
        counts[a] += 1
    remove_count = 0
    for i, c in counts.items():
        if c < i:
            remove_count += c
        else:
            remove_count += c - i
    print(remove_count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 18672
#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int MAXN = 22;
const LL MOD = (LL)1e9 + 7;
LL dp[MAXN][(1 << MAXN)], a[MAXN][MAXN];
bool visit[MAXN][(1 << MAXN)];

LL dfs(int n, int S, int N) {
   if (n == N) {
      if (S != 0) return 0;
      else return 1;
   }
   if (visit[n][S]) return dp[n][S];
   visit[n][S] = 1;
   LL ans = 0;
   for (int i = 0; i < N; i++) {
       if (((1 << i) & S) && (a[n][i])) {
          ans += dfs(n + 1, S - (1 << i), N);
       }
   }
   return dp[n][S] = (ans % MOD);

}


int main() {
    int N;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++)
            scanf("%lld", &a[i][j]);
    }
    printf("%lld\n", dfs(0, (1 << N) - 1, N));
    return 0;
}


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

int calcFirst(int start, int end, int ar[]) {
    int tempSum = 0;
    for(int i = start; i <= end; i++) {
        tempSum += ar[i];
    }
    return tempSum;
}

int main() {
  int n;
  cin >> n;
  int ar[n];
  int total_sum = 0;
  for(int i = 0; i < n; i++) {
      cin >> ar[i];
      total_sum += ar[i];
  }
  int diff = INT_MAX;
  int first = 0;
  for(int i = 0; i < n - 1; i++) {
      first = calcFirst(0, i, ar);
      
      if(abs(first - abs(total_sum - first)) < diff) {
          diff = abs(first - abs(total_sum - first));
      }
  }
  cout << diff << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();
        long k = sc.nextLong();
        System.out.println(Math.min(n % k, k - n % k));
    }

}

Measured memory_bytes: 21844
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
long long n,ans;
int main()
{
	scanf("%lld",&n);
	if(n%2==0)
	{
		for(long long i=10;i<=n;i*=5)
			ans+=(n/i);
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <cctype>
#include <map>
#include <vector>
#include <queue>
#include <list>
#include <numeric>
#define PI 3.141592653
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int euclidean_gcd(int a, int b) {
	while (1) {
		if (a < b) swap(a, b);
		if (!b) break;
		a %= b;
	}
	return a;
}

int main(void){
	int k;
	cin >> k;
	ll ans = 0;
	rep(i, 1, k + 1) {
		rep(j, 1, k + 1) {
			ll num = euclidean_gcd(i, j);
			rep(z, 1, k + 1) {
				ans += euclidean_gcd(num, z);
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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


int dp[101][10001];
int v[101],w[101],N,W;

void DP(){
    for(int i = 0;i <= W;i++) dp[0][i] = 0;
    for(int i = 1;i <= N;i++){
         for(int j = 0;j <= W;j++){
             if(j - w[i - 1] < 0) dp[i][j] = dp[i - 1][j];
             else dp[i][j] = max(dp[i - 1][j],dp[i - 1][j - w[i - 1]] + v[i - 1]);
         }
    }
}

int main(){

    scanf("%d%d",&N,&W);

    for(int i = 0;i < N;i++){
        scanf("%d%d",&v[i],&w[i]);
    }
    
    DP();
    printf("%d\n",dp[N][W]);
    
}



Measured memory_bytes: 7100
s=list(input())
t=input()
l=len(s)
c=0

if "".join(s)==t:
    c=1
else:
    for i in range(l-1):
        n=s[-1]
        del s[-1]
        s.insert(0,n)
        if "".join(s)==t:
            c=1
            break
    
print("Yes" if c==1 else "No")

Measured memory_bytes: 3064
#include <iostream>

using namespace std;
using ll = long long;

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

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

  auto ok = [](char c) { return c == 'A' || c == 'T' || c == 'G' || c == 'C'; };
  int ans = 0;

  rep(i, S.length()) {
    int cnt = 0;
    for (int j = i; j < S.length(); ++j) {
      if (ok(S[j])) {
        ++cnt;
      } else {
        break;
      }
    }
    ans = max(ans, cnt);
  }

  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 256
#abc080c

n=int(raw_input())
f=[map(int,raw_input().split()) for i in xrange(n)]
p=[map(int,raw_input().split()) for i in xrange(n)]
res=-float('inf')
for i in xrange(1,1024):
 temp=0
 for j in xrange(n):
  cnt=0
  for k in xrange(10):
   cnt+=int(i>>k&1 and f[j][k])
  temp+=p[j][cnt]
 res=max(temp,res)
print res


Measured memory_bytes: 2692
package main

import (
	"fmt"
	"math"
	"strconv"
)

func main(){
	//文字の間に＋を挿入するしないのbit探索問題
	var number_in string
	var digits,ans int
	var bin_grids []string
	fmt.Scan(&number_in)
	digits =len(number_in)
	for i :=0;i<int(math.Pow(2.0,float64(digits-1)));i++{
		bin_grids = append(bin_grids,fmt.Sprintf("%*b",digits-1,i))
	}
	for _,bin_grid := range bin_grids{
		var ind_history int
		for ind,bin := range bin_grid{
			if string(bin) == "1"{
				temp,_ := strconv.Atoi(number_in[ind_history:ind+1])
				ans += temp
				ind_history = ind+1
			}
		}
		temp,_ := strconv.Atoi(number_in[ind_history:])
		ans += temp
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
from collections import deque
import sys
input = sys.stdin.readline
k = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
que = deque([i for i in range(1, 10)])
for _ in range(k - 1):
    x = que.popleft()
    if x % 10 != 0:
        que.append(10 * x + x % 10 - 1)
    que.append(10 * x + x % 10)
    if x % 10 != 9:
        que.append(10 * x + x % 10 + 1)
ans = que.popleft()
print(ans)

Measured memory_bytes: 11908
#include<iostream>
#include<algorithm>
#include <string>
#include <vector>
using namespace std;
int main(){
    int a;
    int b;
    cin >> a >> b;
    if(a > b){
        cout << a + a -1;
    }
    if(a < b){
        cout << b + b -1;
    }
    if(a == b){
        cout << a + a;
    }
}

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

int main()
{
    string s;
    cin >> s;
    if ((s[0] == s[1] && s[1] == s[2]) || (s[1] == s[2] && s[2] == s[3]))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
ans = []

loop do
  num_of_cards, cut_time = gets.split.map(&:to_i)

  if [num_of_cards, cut_time] == [0, 0]
    break

  else
    cards = Array.new(num_of_cards, 0)

    num_of_cards.times do |i|
      cards[i] = num_of_cards - i
    end

    cut_time.times do
      a, b = gets.split.map(&:to_i)
      first = a - 1
      last  = a + b - 2
      cards2 = cards[first .. last]
      if first > 0
        cards2 = cards2 + cards[0 .. first - 1]
      end
      if last < num_of_cards - 1
        cards2 = cards2 + cards[last + 1 .. num_of_cards - 1]
      end
      cards[0 .. num_of_cards] = cards2[0 .. num_of_cards]
      cards2.clear
    end

    ans << cards[0]
  end
end

ans.each do |a|
  puts a
end



Measured memory_bytes: 7348
n, k = gets.chomp.split(' ').map(&:to_i)

def seq_sum(from, count)
  (from + count - 1) * (from + count) / 2\
    - (from - 1) * from / 2
end

sum = 0
for i in k..(n+1)
  sum += seq_sum(n-i+1, i) - seq_sum(0, i) + 1
end

puts sum % (10 ** 9 + 7)

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


def divisor(n):  # 約数全列挙
    ans = [1, n]
    i = 2
    while i ** 2 <= n:
        if n % i == 0:
            ans.append(i)
            if i ** 2 < n:
                ans.append(n // i)
        i += 1
    ans.sort()
    return ans
a = list(map(int,input().split()))
ans = []
for num in range(n-1,-1,-1):
    if a[num] %2== 1:
        ans.append(num+1)
        q = divisor(num+1)
        for j in q:
            a[j-1] += 1

print(len(ans))
for i in ans:
    print(i,end=' ')

print()

Measured memory_bytes: 67420
#include<stdio.h>
int main(){
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if((a+b)<c){
		printf("dangerous\n");
	}
	else{
		if(b>=c){
			printf("delicious\n");
		}
		else{
			printf("safe\n");
		}
	}
	printf("\n");
	
}

Measured memory_bytes: 128
S = list(input())
ans = 1
while True:
    del S[-1]
    L = len(S)
    if L % 2 == 0:
        if S[:int(L / 2)] == S[int(L / 2):]:
            print(L)
            ans = -1
            break
    if ans == -1:
        break


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(10**6)

a,b,c,d = map(int, input().split())

#from math import gcd
from fractions import gcd

f = gcd(c,d)
f2 = c*d//f

rem_ans = b//c - (a-1)//c + b//d - (a-1)//d - (b//f2 - (a-1)//f2)
ans = b-a+1-rem_ans
print(ans)

Measured memory_bytes: 5304
#include<stdio.h>
int main()
  { 
     int N,K,count=0,i;
     scanf("%d %d",&N,&K);
     int arr[N];
     for(i=0;i<N;i++)
       { 
         scanf("%d",&arr[i]);
       }
  for(i=0;i<N;i++)
    { 
      if(arr[i]>=K)
        { 
          count++;
        }
    }
  printf("%d",count);
  return 0;
  }


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int A, B, C, K; cin >> A >> B >> C >> K;
  int cnt = 0;
  for(int i = 0; i < (1 << K); i++) {
    bitset<7> bits(i);
    int a = A, b = B, c = C;
    for(int j = 0; j < K; j++) {
      if(bits.test(j)) b *= 2;
      else c *= 2;
    }
    if(a < b && b < c) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
int n,a[200010],cnt;
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	for(int i=1;i<=n;i++)
	{
		if(a[i]==i) 
		{
			cnt++; swap(a[i+1],a[i]);
		}
	}
	cout << cnt << endl;
	return 0 ;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPP(i, n) for(int i = 1; i <= n; ++i)
#define REPR(i, n) for(int i = n-1; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define ALL(v) v.begin(), v.end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll MOD = 1000000007;
const ll INF = 1000000000;

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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s; cin >> s;
    map<char, int> m; m['a'], m['b'], m['c'];
    int n = s.length();
    REP(i,n) ++ m[s[i]];
    bool ans = ((max({m['a'], m['b'], m['c']}) - min({m['a'], m['b'], m['c']}))<2);
    cout << (ans ? "YES" : "NO") << endl;
    return 0;
}

Measured memory_bytes: 512
N,C=map(int,input().split())
x=[0 for i in range(N)]
v=[0 for i in range(N)]
for i in range(N):
    x[i],v[i]=map(int,input().split())
a=[0 for i in range(N)]
b=[0 for i in range(N)]
a[0]=v[0]
b[N-1]=v[N-1]
for i in range(1,N):
    a[i]=v[i]+a[i-1]
for i in range(N-1)[::-1]:
    b[i]=b[i+1]+v[i]
ans=0
f1=[0 for i in range(N+1)]
f1[0]=0
f1[1]=v[0]-x[0]
for i in range(1,N):
    f1[i+1]=f1[i]+v[i]+x[i-1]-x[i]
g1=[0 for i in range(N+1)]
g1[0]=f1[0]
for i in range(1,N+1):
    g1[i]=max([f1[i],g1[i-1]])
f2=[0 for i in range(N+1)]
f2[0]=0
f2[1]=v[0]-2*x[0]
for i in range(1,N):
    f2[i+1]=f2[i]+v[i]+2*x[i-1]-2*x[i]
g2=[0 for i in range(N+1)]
g2[0]=f2[0]
for i in range(1,N+1):
    g2[i]=max([f2[i],g2[i-1]])
for i in range(N+1):
    if i==0:
        OB=0
        EB=0
    else:
        OB=C-x[N-i]
        EB=b[N-i]
    tmpA=EB-2*OB+g1[N-i]
    tmpB=EB-OB+g2[N-i]
    if ans<tmpA:
        ans=tmpA
    if ans<tmpB:
        ans=tmpB
print(ans)


Measured memory_bytes: 30124
#include <iostream>
#include <string>
#include <vector>

using namespace std;
int MAX = 10001;

void countingSort(const vector<int>& A, vector<int>& B, int K) {
	const size_t n = A.size();
	B.resize(n, 0);
	vector<int> C(K, 0);
	for (auto& i : A) ++( C.at(i) );
	for (size_t i = 1; i != K; ++i) C.at(i) += C.at(i - 1);
	for (int i = n - 1; i != -1; --i) B.at(--C.at(A.at(i))) = A.at(i);
}

int main()
{
	int n;
	cin >> n;
	vector<int> A(n);
	for (auto& i : A) cin >> i;
	vector<int> B;
	countingSort(A, B, MAX);
	cout << B.front();
	for (int i = 1; i != n; ++i) cout << " "<<B.at(i);
	cout << endl;


	return 0;
}


Measured memory_bytes: 18336
#include <bits/stdc++.h>
#define REP(i, a, n) for (int i = (a); i < (int)(n); ++i)
#define REPC(i, a, n) for (int i = (a); i <= (int)(n); ++i)
#define ALL(t) t.begin(), t.end()
#define RALL(t) t.rbegin(), t.rend()
#define MATINIT(type, row, col, init) \
  vector<vector<type>>(row, vector<type>(col, init));
#define Yes(cond) cout << (cond ? "Yes" : "No") << endl;
#define YES(cond) cout << (cond ? "YES" : "NO") << endl;
using namespace std;
using LL = long long;
using ULL = unsigned long long;
template <class T>
using VEC = std::vector<T>;
template <class T>
using MAT = std::vector<std::vector<T>>;
void DUMP() { cerr << endl; }
template <class Head, class... Tail>
void DUMP(Head &&head, Tail &&... tail) {
  cerr << head << ", ";
  DUMP(std::move(tail)...);
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec) {
  os << "{";
  for (auto v : vec) os << v << ",";
  os << "}";
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, set<T> &s) {
  os << "{";
  for (auto p : s) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, map<T1, T2> &m) {
  os << "{";
  for (auto p : m) os << p << ",";
  os << "}";
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
  os << "[" << p.first << " " << p.second << "]";
  return os;
}

int main() {
  string s;
  cin>>s;
  int n = s.length();
  int aka=0,ao=0;
  REP(i,0,n){
    if(s[i]=='0')aka++;
  else ++ao;
  }
  int mi = min(aka,ao);
  cout<<2*mi<<endl;


  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <string.h>

int ball[10001];

int min(int a, int b)
{
    if (a > b){
        return (b);
    }
    return (a);
}

int color(int col, int n, int *top, int *bottom)
{
    int i, j;
    int dx, ddx;
    i = *top - 1;
    dx = 0;
    while (i >= 0 && ball[i] == col){
        *top = i;
        i--;
        dx++;
    }
    
    i = *bottom + 1;
    ddx = 0;
    while (i < n && ball[i] == col){
        *bottom = i;
        i++;
        ddx++;
    }
    return(dx + ddx);
}

int count(int check, int n, int *ball)
{
    int i, j;
    int top, bottom;
    int ans, t;
    
    ans = 100000;
    for (i = 1; i <= 3; i++){
        if (ball[check] != i){
            top = bottom = check;
            t = 0;
            if (color(i, n, &top, &bottom) >= 3){
                while (top - 1 >= 0 && bottom + 1 < n && ball[top - 1] == ball[bottom + 1] && color(ball[top - 1], n, &top, &bottom) >= 4){
                    t = bottom - top + 1;
                }
                ans = min(ans, n - t);
            }
        }
    }
    if (ans == 100000){
        return (n);
    }
    return (ans);
}

int main(void)
{
    
    int n;
    int i;
    int ans;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        memset(ball, -1, sizeof(ball));
        for (i = 0; i < n; i++){
            scanf("%d", &ball[i]);
        }
        
        ans = 100000;
        for (i = 0; i < n; i++){
            if (i == 0 || i == n - 1 || !(ball[i] == ball[i - 1] && ball[i] == ball[i + 1])){
                ans = min(ans, count(i, n, ball));
                if (ans == 0){
                    break;
                }
            }
        }
        
        printf("%d\n", ans);
    }
    
    return (0);
}

Measured memory_bytes: 0
# include <iostream>

using namespace std;

int main() {
    int n; cin >> n;
    while (true) {
        int i = n/100;
        int j = n/10 - 10*i;
        int k = n - 100*i - 10*j;

        if (i == j and j == k) break;
        n++;
    }

    cout << n << endl;
    return 0;
}



Measured memory_bytes: 888
#include<iostream>
#include<algorithm>
using namespace std;
int zcfuckzc(int a){
	if(a==0){
		return 0;
	}
	int i;
	for(i=0;i>-1;i++){
		if(a%2==1){
			return i;
			i=-2;
		}
		else{
			a/=2;
		}
	}
}
int main(){
	int n,a[200],i,z[200];
	cin>>n;
	for(i=0;i<n;i++){
		cin>>a[i];
		z[i]=zcfuckzc(a[i]);
	}
	sort(z,z+n);
	cout<<z[0];
	return 0;
}

Measured memory_bytes: 256