akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int gcd(int m, int n) {
  int t;
  if ((!m) || (!n)) return 0;
  while (m%n) {
    m = m%n;
    t = n;
    n = m;
    m = t;
  }
  return n;
}

int main() {
  int a, b, c, t, d;
  cin >> a >> b >> c;
  d = gcd(60,a+b);
  if (a >= c%d) {
    t = c;
    while (t%(a+b) > a) t += 60;
    cout << t << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}

Measured memory_bytes: 3080
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
vector<ll>v(1e7+1,1);
void sieve(){
    for(ll i=2;i<1e7+1;i++){
        v[i]++;
        for(ll j=i*2;j<1e7+1;j+=i){
            v[j]++;
        }
    }
    return;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    sieve();
    ll n;
    cin>>n;
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=i*v[i];
    }
    cout<<ans;
    return 0;
}



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

int main(){
    int N, K;
    long long *H;

    cin >> N >> K;
    H = new long long[N];
    int i;
    long long sum=0;
    for (i=0;i<N;i++){
        cin >> H[i];
        sum += H[i];
    }

    // 大きい順にソート
    sort(H, H+N, greater<int>());

    long long out; // 全てのモンスターを倒すのに必要な攻撃の回数(答え)
    // Kがモンスターの数より大きければ、全て必殺技で倒せる
    if (K >= N){
        out = 0;
    }
    else if (K == 0)
    {
        out = sum; 
    }
    else{
        for (i=0;i<K;i++){
            sum -= H[i];
        }
        out = sum;
    }

    cout << out << endl;
    return 0;
}

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

#define MAX_V 1000
int V;
int n;
vector<int> G[MAX_V];
int match[MAX_V];
int Match[MAX_V];
int used[MAX_V];
int L[MAX_V],R[MAX_V];
int C=0;

void add_edge(int u,int v){
  G[u].push_back(v);
  G[v].push_back(u);
}
 
bool dfs(int v){
  used[v]=C;
  for(int i=0;i<(int)G[v].size();i++){
    int u=G[v][i],w=match[u];
    int a=min(u,v),b=max(u,v)%n;
    if(b<L[a] || R[a]<b)continue;
    if( w<0 || (used[w]!=C && dfs(w)) ){ 
      match[v]=u;
      match[u]=v;
      return true;
    }
  }
  return false;
}
 
int bipartite_matching(){
  C++;
  int res=0;
  memset(match,-1,sizeof(match));
  for(int v=0;v<n;v++){
    C++;
    
    if(match[v]<0){
      if(dfs(v))res++;
      else return 0;
    }
  }
  return res;
}


int t[500][500];
int main(){
  cin>>n;
  n--;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      scanf("%d",&t[i][j]);
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)
      if(t[j][i]==1)add_edge(i,n+j);

  V=n+n;
  for(int i=0;i<n;i++){
    L[i]=0;
    R[i]=n-1;    
  }
  int F = bipartite_matching();
  //  for(int i=0;i<V;i++)Match[i]=match[i];
  
  if( F == n ){
    cout<<"yes"<<endl;
    for(int i=0;i<n;i++){
      //cout<<i<<endl;
      int l=0,r=match[i]-n,m;      
      while(l<r){
        m=(l+r)/2;
        R[i]=m;
        if(bipartite_matching() == n){
          r=m;
        }else{
          l=m+1;
        }
      }
      L[i]=R[i]=l;
      bipartite_matching();
    }

    //cout<<bipartite_matching()<<endl;
    for(int i=0;i<n;i++){
      cout<<match[i]+1-n<<endl;
    }

  }else{
    cout<<"no"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
const int N = 200;
const int LIM = 100;

bool placed[N][N];
int a, b, x, y;

inline void get_next()
{
	y += 2; 
	if( y < 50 )
		return;
		
	x = x + 2; y = 2;
}

int main()
{
	scanf( "%d%d", &a, &b ); a --; b --;
	
	memset( placed, false, sizeof( placed ) );
	for( int i = 1; i <= 100; i ++ )
		for( int j = 51; j <= 100; j ++ )
			placed[i][j] = true;
	
	x = 2, y = 2;
	for( int i = 1; i <= a; i ++ )
	{
		placed[x][y] = true;
		get_next();
	}
	
	x = 2; y = 2;
	for( int i = 1; i <= b; i ++ )
	{
		placed[x][y+50] = false;
		get_next();
	}
	
	printf( "100 100\n" );
	for( int i = 1; i <= 100; i ++ )
	{
		for( int j = 1; j <= 100; j ++ )
		{
			if( placed[i][j] )
				printf( "." ); 
			else printf( "#" );
		}
		printf( "\n" );
	}
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i,n) for(int i=0;i<(n);++i)
#define ll long long
const long long INF = 1LL<<60;
const long long mod = 1e9 + 7;
using Graph = vector<vector<int>>;

int main(){
    int N,K;
    cin >> N >> K;
    int digits = 1;
    while(N>=pow(K,digits)){
        digits++;
    }
    cout << digits << endl;
}

Measured memory_bytes: 3960
S = [int(x) for x in list(input())]
bw = [0, 1]
wb = [1, 0]
ans1 = 0
ans2 = 0
for i in range(len(S)):
  if(S[i]!=bw[i%2]):
    ans1 += 1
  if(S[i]!=wb[i%2]):
    ans2 += 1
print(min(ans1,ans2))

Measured memory_bytes: 10500
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int n,k;
  cin>>n>>k;
  vector<int> v(n);
  for(int i=0;i<n;i++){
    v[i]=0;
  }
  for(int i=0;i<k;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int a;
      cin>>a;
      v[a-1]++;
    }
  }
  int sum=0;
  for(int i=0;i<n;i++){
    if(v[i]==0){
      sum++;
    }
  }
  cout<<sum<<endl;
}

Measured memory_bytes: 3628
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

    private static Scanner scan = new Scanner(System.in);
    private static int W;
    private static int H;

    public static void main(String[] args) {
	H = Integer.parseInt(scan.next());
	W = Integer.parseInt(scan.next());
	int N = Integer.parseInt(scan.next());
	Grid[] black = new Grid[N];
	for (int i = 0; i < N; i++) {
	    int a = Integer.parseInt(scan.next()) - 1;
	    int b = Integer.parseInt(scan.next()) - 1;
	    black[i] = new Grid(a, b);
	}

	Arrays.sort(black, new Comparator<Grid>() {
		@Override
		public int compare(Grid o1, Grid o2) {
		    return o1.dist() - o2.dist();
		}
	    });

	long[] ans = new long[10];

	List<Grid> m0 = new ArrayList<Grid>();
	List<Grid> m1 = new ArrayList<Grid>();
	List<Grid> m2 = new ArrayList<Grid>();
	int current = 0;
	for (int i = 0; i < N; i++) {
	    if(black[i].dist() != current) {
		current = black[i].dist();
		for(Grid s: m2) {
		    ans[s.count]++;
		}
		m2 = m1;
		m1 = m0;
		m0 = new ArrayList<Grid>();
	    }
	    List<Grid> square = getSquare(black[i]);
	    for(Grid s: square) {
		int index;
		if((index = m2.indexOf(s)) >= 0) {
		    m2.get(index).count++;
		} else if ((index = m1.indexOf(s)) >= 0) {
		    m1.get(index).count++;
		} else if ((index = m0.indexOf(s)) >= 0) {
		    m0.get(index).count++;
		} else {
		    s.count = 1;
		    m0.add(s);
		}
	    }
	}
	for(Grid s: m2) ans[s.count]++;
	for(Grid s: m1) ans[s.count]++;
	for(Grid s: m0) ans[s.count]++;

	ans[0] = (long)(H-2)*(W-2);
	for (int i = 1; i < 10; i++) {
	    ans[0] = ans[0] - ans[i];
	}
	
	for (int i = 0; i < 10; i++) {
	    System.out.println(ans[i]);
	}	
	scan.close();
    }

    private static class Grid {
	int a;
	int b;
	int count = 0;

	public Grid(int a, int b) {
	    this.a = a;
	    this.b = b;
	}

	public int dist() {
	    return Integer.max(a, b);
	}

	@Override
	public boolean equals(Object o) {
	    if(o instanceof Grid) {
		Grid g = (Grid) o;
		if(g.a == this.a && g.b == this.b) return true;
		else return false;
	    } else {
		return false;
	    }
	}
    }

    private static boolean isValid(int a, int b) {
	if(a > 0 && a < H-1 && b > 0 && b < W-1) return true;
	else return false;
    }

    private static List<Grid> getSquare(Grid grid) {
	int a = grid.a;
	int b = grid.b;
	List<Grid> result = new ArrayList<Grid>();
	for (int i = -1; i < 2; i++) {
	    for (int j = -1; j < 2; j++) {
		if(isValid(a+i, b+j)) result.add(new Grid(a+i, b+j));
	    }
	}
	return result;
    }
}


Measured memory_bytes: 74972
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

int fac(int x)
{
    int y = 1;
    for (int i = 2; i <= x; i++) y *= i;
    return y;
}

int main()
{
    int N; cin >> N;
    int P[10], Q[10];
    for (int i = 1; i <= N; i++) cin >> P[i];
    for (int i = 1; i <= N; i++) cin >> Q[i];

    int a = 1;
    for (int i = 1; i <= N; i++)
    {
        a += fac(N - i) * (P[i] - 1);
        for (int j = i + 1; j <= N; j++)
        {
            if (P[i] < P[j]) P[j]--;
        }
    }

    int b = 1;
    for (int i = 1; i <= N; i++)
    {
        b += fac(N - i) * (Q[i] - 1);
        for (int j = i + 1; j <= N; j++)
        {
            if (Q[i] < Q[j]) Q[j]--;
        }
    }

    cout << abs(a - b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=100000+10;
long long x[N],a,b,n,f[N]={0},ans=0;
int main(){
    scanf("%ld%ld%ld",&n,&a,&b);
    for(int i=1;i<=n;i++)
        scanf("%ld",&x[i]);
    for(int i=1;i<=n-1;i++)
        f[i]+=min((x[i+1]-x[i])*a,b);
    for(int i=1;i<=n-1;i++)
     ans+=f[i]; 
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <climits>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <list>
#include <set>
#include <bitset>
#include <iterator>
#include <functional>
#define loop(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) for(long long i = 0; i < (long long)(n); i++)
#define debug(x)  cout << #x << " = " << (x) << endl;

using namespace std;
using LL = long long int;
using ULL = unsigned long long;

using Graph = vector<vector<int>>;
Graph graph;
vector<LL> counter;
void dfs(int v, int p, LL add) {
    counter[v] += add;
    for (auto x : graph[v]) {
        if (x == p) continue;
        else dfs(x, v, counter[v]);
    }
}
int main() {
    int n, q;
    cin >> n >> q;
    graph = Graph(n);
    rep(i, n - 1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    vector<pair<int, int>> query(q);
    rep(i, q) {
        int p, x;
        cin >> p >> x;
        p--;
        query[i] = make_pair(p, x);
    }
    counter = vector<LL>(n, 0);
    for (auto px : query) {
        counter[px.first] += px.second;
    }

    dfs(0, 0, 0);
    for (auto v : counter) {
        cout << v << " ";
    }
    cout << endl;
}


Measured memory_bytes: 25984
#include<bits/stdc++.h>
//K:Stones

using namespace::std;

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

	int N,K;
	cin >> N >> K;

	vector<int> V(N);
	for(int i = 0;i < N;i++)
		cin >> V[i];

	stable_sort(V.begin(),V.end());

	vector<bool> DP(K + 1,0);
	for(int i = 1;i <= K;i++){
		for(int j : V){
			if(j <= i && DP[i - j] == 0)
				DP[i] = 1;
		}
	}

	if(DP[K])
		cout << "First\n";
	else
		cout << "Second\n";
	
	return 0;
}


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

    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var input = Console.ReadLine().Split(' ').Select(s=>int.Parse(s));

            var count = 0;
            foreach(var item in input)
            {
                var tmpItem = item;
                while(tmpItem % 2==0)
                {
                    tmpItem /= 2;
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }

Measured memory_bytes: 13920
# エラトステネスの篩, 累積和
from math import sqrt
p = [True] * (10 ** 5 + 1)
p[0] = False
p[1] = False
n = int(sqrt(10 ** 5)) + 1
for j in range(4, 10 ** 5 + 1, 2):
  p[j] = False
for i in range(3, n + 1, 2):
  if p[i]:
    for j in range(i + i, 10 ** 5 + 1, i):
      p[j] = False
c = [0] * (10 ** 5 + 2)
for i in range(2, 10 ** 5 + 2):
  c[i] = c[i - 1]
  if p[i - 2] and p[(i - 1) // 2]:
    c[i] += 1
q = int(input())
for _ in range(q):
  l, r = map(int, input().split())
  print(c[r + 2] - c[l + 1])


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

int main() {
  int K;
  cin >> K;
  string S;
  cin >> S;
  
  int i;
  if(S.size() <= K){
    cout << S << endl;
  } else {
    for(i = 0;i < K; i++){
      cout << S.at(i);
    }
    cout << "..." << endl;
  }
}


Measured memory_bytes: 3628
// 1_3_C

#include <iostream>
using namespace std;

int main(){
  int x, y;
  while(1){
    cin >> x; cin >> y;
    if(x == 0 && y == 0) return 0;
    if(x < y) cout << x << " " << y << endl;
    else cout << y << " " << x << endl;
  }
}

Measured memory_bytes: 3072
# coding: utf-8
# Your code here!
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    
    if op=='+':
        print(a+b)
    elif op=='-':
        print(a-b)
    elif op=='*':
        print(int(a*b))
    elif op=='/':
        print(int(a/b))
    elif op=='?':
        break
    else:
        break


Measured memory_bytes: 5600
#include <stdio.h>
#include <string.h>
int main(void)
{
	int a,n,len1,len2;
	char s[100];
	char t[100];
	scanf("%d",&n);
	
	if(!(1<=n&&n<=100)){return -1;}
	
	scanf("%s",s);
	scanf("%s",t);
	len1=strlen(s);
	len2=strlen(t);
	
	if(n==len1&&n==len2){
		for(a=0;a<n;a++){
			printf("%c%c",s[a],t[a]);
		}
	}
	else {return -1;}
	return 0;
}

Measured memory_bytes: 128
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

// #include <iomanip>
//  cout << fixed << setprecision(15) << y << endl;

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll A;
ll B;
ll C;
ll N;
ll M;
ll K;

ll ltmp;
string stmp;
double dtmp;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> A;
    cin >> B;
    cin >> C;
    
    ll cnt=0;
    for( ll ni = A ; ni <=B ; ni++ ){
        if(ni%C==0)cnt++;
    }
    cout << cnt << endl;
    

}

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define MOD 1000000007
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())

signed main(){

	lli n,m;
	cin>>n>>m;

	const lli size = 1<<13;

	lli dp[size];
	REP(i,0,size)dp[i]=INF;
	dp[0]=0;

	REP(i,0,m){
		lli a,b;
		lli bit = 0;
		cin>>a>>b;

		REP(j,0,b){
			lli c;
			cin>>c;
			c--;
			bit |= (1<<c);

			for(lli i=size-1;i>=0;i--){
				if(dp[i]==INF)continue;

				lli nextBit = i | bit;
				if(DEBUG)cout<<"nextBit="<<nextBit<<endl;
				dp[nextBit] = min(dp[nextBit],dp[i]+a);
			}
		}
	}

	lli ansBit = 0;
	REP(i,0,n)ansBit |= (1<<i);

	if(dp[ansBit]==INF)cout<<-1<<endl;
	else cout<<dp[ansBit]<<endl;

	return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
A = [int(_) for _ in input().split()]

counter = Counter(A)

values = []
for value in counter.values():
    if value >= 2 and value % 2 == 0:
        values.append(2)
    elif value >= 2 and value % 2 == 1:
        values.append(1)
    else:
        values.append(1)

sec_count = Counter(values)
if sec_count[2] % 2 == 0:
    print(len(values))
else:
    print(len(values) - 1)

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

bool judge_yes_or_no(int *h, int n){
	int tmp_min = 0;
	/*
	 * 交換場所の決定
	 * */

	for (int i = 0; i < n-1; i++){
		for(int next_i = i+1; next_i < n; next_i++){
			if(h[i] > h[next_i] && tmp_min<next_i){
				tmp_min = next_i;
			}
		}
		//何かしら交換してたらループぬける
		if(tmp_min != 0){
			int tmp_i = h[i];
			h[i] = h[tmp_min];
			h[tmp_min] = tmp_i;
			break;
		}
	}

	/* 失敗条件
	 * 一度交換しても昇順にならない
	 * ex)2 3 5 4 1など
	 *
	 * それ以外なら成功
	 * */
	for (int i = 0; i < n-1; i++){
		for(int next_i = i+1; next_i < n; next_i++){
			if(h[i] > h[next_i]){
				return false;
			}
		}
	}
	return true;
}

int main(void){
	/*input*/
	int n;
	cin >> n;

	int p[n];
	for(int i = 0; i < n;i++){
		cin >> p[i];
	}

	/*calc*/
	bool judge;
	judge = judge_yes_or_no(p,n);

	/*output*/
	if(judge == true){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e5+5;
ll inf=1e15;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    while(t--)
    {
        ll n;
        cin>>n;
        ll sum=0;
        ll ar[n];
        for(int i=0;i<n;i++){
            cin>>ar[i];
            sum+=ar[i];
            sum%=mod;
        }
        ll res=0;
        for(int i=0;i<n;i++){
            sum=(sum%mod-(ar[i]%mod)+mod)%mod;
            res=(res%mod+(sum*ar[i])%mod)%mod;
        }
        cout<<res;
    }

    return 0;
}

Measured memory_bytes: 5204
#include<iostream>
#include <vector>
#include <algorithm>
#include<set>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000;
#include <map>

using ll = long long;
using namespace std;


int main(){
    int n;
    cin >> n;
    int f1, f2, f3;
    f1=0;
    f2=0;
    f3=0;
    if(n%10==7){
        f1=1;
    }
    n/=10;
    if(n%10==7){
        f2=1;
    }
    n/=10;
        if(n%10==7){
        f3=1;
    }
    if(f1==1||f2==1||f3==1) cout << "Yes"<< endl;
    else cout << "No" << endl;
    
}

Measured memory_bytes: 3636
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D - Gathering Children
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;

/* typedef */

/* global variables */

char s[MAX_N + 4];
int cs[MAX_N];

/* subroutines */

/* main */

int main() {
  scanf("%s", s);
  int n = strlen(s);

  for (int i = 0; i < n;) {
    // 'R'
    int j = i;
    while (j < n && s[j] == 'R') j++;
    for (int k = i; k < j; k++)
      cs[((j - k) & 1) ? j - 1 : j]++;
    i = j;
    
    // 'L'
    while (j < n && s[j] == 'L') j++;
    for (int k = i; k < j; k++)
      cs[((k - i) & 1) ? i - 1 : i]++;
    i = j;
  }

  for (int i = 0; i < n; i++) {
    if (i) putchar(' ');
    printf("%d", cs[i]);
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 896
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <iterator>      //集合演算(積集合,和集合,差集合など)
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;

//マクロ
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define MAXR 100000 //10^5:最大のrange(素数列挙などで使用)

const ll maxs = 5;
ll N, M;
ll s[maxs];
ll c[maxs];

ll solve()
{
  ll st = 0;
  if (N > 1)
  {
    st = pow(10, N - 1);
  }
  ll en = pow(10, N);
  FOR(i, st, en - 1)
  {

    bool ok = true;
    REP(j, M)
    {
      ll keta = pow(10, N - s[j]);
      // cout << i << "," << keta << ", " << s[j] << ", " << (i / keta) % 10 << ", " << c[j] << endl;
      if ((i / keta) % 10 != c[j])
      {
        ok = false;
      }
    }
    if (ok)
    {
      return i;
    }
  }
  return -1;
}

signed main()
{
  cin >> N >> M;
  REP(i, M)
  {
    ll si, ci;
    cin >> si >> ci;
    s[i] = si;
    c[i] = ci;
  }
  cout << solve() << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
typedef long double ld;
//////////////////////////////////////////////////////////////////////

const int N = 221;
struct Line{
  ll a,b,c;
  Line(const pair<ll,ll>&p1,const pair<ll,ll>&p2){
    a = p2.ss - p1.ss;
    b = p1.ff - p2.ff;
    c = -p2.ss * b - p2.ff * a;
    ll g = __gcd(a,b);g = __gcd(g,c);
    //cerr << "!" << a << ',' << b << ',' << c << endl;
    a /= g;b /= g;c /= g;
  }
};
bool operator<(const Line&l1,const Line&l2){
  return l1.a != l2.a ? l1.a < l2.a : (l2.b!=l1.b ? l1.b<l2.b : l1.c < l2.c);
}
map<Line,int > mp;

ll n,rev[N*N];
pair<ll,ll> p[N];

const ll mod = 998244353;
ll exMod(ll x,ll pow){
  ll y = 1;
  for(;pow>0;pow>>=1,x=(x*x)%mod)
    if(pow&1)y = (y*x)%mod;
  return y;
}

int main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  
  cin>>n;
  for(int i=1;i<=n;i++){
    cin>>p[i].ff>>p[i].ss;
    rev[(i*i-i)/2] = i;
  }

  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++){
      Line Lij = Line(p[i],p[j]);
      mp[Lij]++;
    }

  ll ans = exMod(2,n);
  for(auto&it:mp){
    Line line = it.ff;int cnt = it.ss;
    ll vertices = rev[cnt];
    //cerr << "#" << vertices << endl;
    ans = (ans + 1 + vertices + mod - exMod(2,vertices))%mod;
  }
  ans = (ans + mod - 1 - n)%mod;
  cout << ans << endl;
  
  return 0;
};


Measured memory_bytes: 1920
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C (GCC 5.4.1)
*/

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

#define _CRT_SECURE_NO_WARNINGS
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	char s[10003];

	scanf("%d %s",&n, s);
	for (int i = 0; i < strlen(s); ++i)
	{
		printf("%c", (s[i] - 'A' + n) % 26 + 'A');
	}
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

int main() {
	
    // 頂点数と辺数
    int n, m; cin >> n >> m;

    // グラフ入力受取 (ここでは無向グラフを想定)
    Graph G(n);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // BFS のためのデータ構造
    vector<int> prevNode(n, -1); // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    prevNode[0] = 0;
    que.push(0); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        int v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int new_v : G[v]) {
            if (prevNode[new_v] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 new_v について距離情報を更新してキューに追加する
            prevNode[new_v] = v;
            que.push(new_v);
        }
    }
    cout << "Yes" << endl;
    for (int i = 1; i < n; i++) {
        cout << prevNode[i] + 1 << endl;
    }

	return 0;
}

Measured memory_bytes: 10168
#include <iostream>

using namespace std;

int main()
{
    int num;
    cin >> num;
    int temp = num;

    int n = 0;
    while(temp)
    {
        n += temp % 10;
        temp /= 10;
    }

    if(0 == num % n)
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import Data.List (sort, group)
import qualified Data.IntMap as M

solve :: [Int] -> [Int] -> Bool
solve ts ds =
    let f (t,l) = maybe False (l <=) (M.lookup t m)
     in all f tl
  where
    tpl g = (head g, length g)
    tl = map tpl . group . sort $ ts
    dl = map tpl . group . sort $ ds
    m  = M.fromList dl

main :: IO ()
main = do
    n <- readLn :: IO Int
    d <- map (fst . fromJust . BS.readInt)
        . BS.words <$> BS.getLine :: IO [Int]
    m <- readLn :: IO Int
    t <- map (fst . fromJust . BS.readInt)
        . BS.words <$> BS.getLine :: IO [Int]
    putStrLn $ if solve t d then "YES" else "NO"

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

#define PI acos(-1)
#define int long long int
#define pb push_back
#define pi pair<int, int>
#define fir first
#define sec second
#define MAXN 2001
#define mod 1000000007

int n, nn;
int dp[MAXN * 9];

int solve(int j)
{
  if (j == n)
    return dp[j] = 1;
  if (j > n)
    return dp[j] = 0;
  if (dp[j] != -1)
    return dp[j];
  int ret = 0;
  for (int f = 3; f <= n - j; f++)
    ret = (ret + solve(j + f)) % mod;
  return dp[j] = ret;
}
signed main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  int ans = 0;
  memset(dp, -1, sizeof(dp));
  cout << solve(0) << endl;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define rep2(i,a,n) for(int i=(a); i<(n); i++)
#define all(vec) vec.begin(),vec.end()
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

int main(){
  ll A, B, C, K; cin >> A >>B >>C >>K;
  ll ans;
  if(K%2 == 0) ans = A-B;
  else ans = B-A;
  if(ans > 1e18) cout << "Unfair" << endl;
  else cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
import sys
# import math
# import decimal
# import queue
# import bisect
# import heapq
# import time
# import itertools
# from fractions import Fraction

mod = int(1e9+7)
INF = 1<<29

def main():
    h,w = map(int,input().split())
    c = []
    for i in range(h):
        x = list(input().split())
        c.append(x)
    for i in range(h):
        print(''.join(c[i]))
        print(''.join(c[i]))
    return

if __name__=='__main__':
    main()


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[100005];

int main()
{
    ll N, x;
    cin >> N >> x;
    REP(i, N)
    {
        cin >> A[i];
    }

    ll sum = 0;
    FOR(i, N, 1)
    {
        if (A[i] + A[i - 1] <= x)
            continue;
        ll t = std::min(A[i], A[i] + A[i - 1] - x);
        sum += t;
        A[i] -= t;
        if (A[i - 1] > x)
        {
            sum += A[i - 1] - x;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline

N, A, B = map(int, input().split())
ans = 0
if (A + B) % 2 == 0:
    ans = (A + B)//2 - A
    print(ans)
else:
    ans = min(A, N-B+1)
    ans += (A + B)//2 - A
    print(ans)


Measured memory_bytes: 9180
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second

template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e15;
const int INF=1e9;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int q;
	cin>>q;
	ll cons=0,suml=0,sumr=0,cnt=0;
	priority_queue<ll> quel;
	priority_queue<ll,vector<ll>,greater<ll>> quer;
	while(q--){
		int c;
		cin>>c;
		if(c==1){
			ll a,b;
			cin>>a>>b;
			cons+=b;
			cnt++;
			if(cnt==1){
				quel.push(a);
				suml+=a;
			}else if(cnt%2==1){
				if(quer.top()<=a){
					quer.push(a);
					sumr+=a;
					quel.push(quer.top());
					suml+=quer.top();
					sumr-=quel.top();
					quer.pop();
				}else{
					quel.push(a);
					suml+=a;
				}
			}else{
				if(a<=quel.top()){
					quel.push(a);
					suml+=a;
					quer.push(quel.top());
					sumr+=quel.top();
					suml-=quel.top();
					quel.pop();
				}else{
					quer.push(a);
					sumr+=a;
				}
			}
		}else{
			ll ave=quel.top();
			ll ans=cons-suml+ave*(ll)quel.size()-ave*(ll)quer.size()+sumr;
			cout<<ave<<' '<<ans<<endl;
		}
	}
}

Measured memory_bytes: 3828
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) {

		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in));) {
			String input = br.readLine();
			int num = Integer.parseInt(input);
			
			System.out.println(num * num * num);
			
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}

}


Measured memory_bytes: 24408
#include<bits/stdc++.h>
#define mod int(1e9+7)
using namespace std;
int f[100010] = { 1 }, b[100010], a[100010], n;
int main() {
	scanf("%d", &n);
	b[n + 1] = 1;
	for (int i = 1; i <= n; i++) f[i] = (f[i - 1] * 1LL * i) % mod;
	for (int i = n; i >= 1; i--) b[i] = (b[i + 1] * 1LL * i) % mod;
	for (int i = 1; i <= n; i++) a[i] = (a[i - 1] + 1LL * f[i - 1] * b[i + 1]) % mod;
	int res = 0;
	for (int i = 1, x; i <= n; i++) {
		scanf("%d", &x);
		res = (res + ((long long)a[i] + a[n - i + 1])*x) % mod;
		res = (res + 1LL * (mod - f[n])*x) % mod;
	}
	printf("%d", res);
	return 0;
}

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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(long long i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

  
int main() {
int A, B, C, D;
cin >> A >> B >> C >> D;

if(A + B > C + D) print("Left");
if(A + B == C + D) print("Balanced");
if(A + B < C + D) print("Right");

}


Measured memory_bytes: 256
N, M = map(int, input().split())
if N % 2 == 1:
    for i in range(M):
        print(1+i, 2*M-i)
elif (N // 2) % 2 == 1:
    amari = N-(M*2)
    n = amari+1
    for i in range(M):
        if n * 2 == N:
            break
        n += 2
    else:
        for i in range(M):
            print(1+i, 2*M-i)
        exit()
    for k in range(M):
        if k <= i:
            print(1+k, 2*M-k+1)
        else:
            print(1+k, 2*M-k)
else:
    amari = N-(M*2)
    n = amari + 2
    for i in range(1, M):
        if n * 2 == N:
            break
        n += 2
    else:
        for i in range(M):
            print(1+i, 2*M-i)
        exit()
    for k in range(M):
        if k < i:
            print(1+k, 2*M-k+1)
        else:
            print(1+k, 2*M-k)


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

#define int long long

const int INF = 0x3f3f3f3f;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, W;
  cin >> n >> W;
  vector<int> w(n);
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> w[i] >> v[i];
  }
  vector< vector<int> > dp(n + 1, vector<int>(W + 1, -INF));
  for (int i = 0; i <= n; i++) {
    for (int j = 0; j <= W; j++) {
      if (i == 0 || j == 0) {
        dp[i][j] = 0;
      } else if (w[i - 1] <= j) {
        dp[i][j] = max(v[i - 1] + dp[i - 1][j - w[i - 1]], dp[i - 1][j]);
      } else {
        dp[i][j] = dp[i - 1][j];
      }
    }
  }
  cout << dp[n][W];
  return 0;
}

Measured memory_bytes: 80256
S = input()
if len(S) == 1:
  print(int(S))
else:
  def count(n):
    a = 0
    if len(n) == 1:
      return 0
    else:
      for i in range(1, len(n)):
        a += int(n[:i]) * 2 ** (len(n) - 1 - i) + int(n[i:]) + count(n[i:])
      return a
  print(int(S) + count(S))

Measured memory_bytes: 38384
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int main(int argh,char **argv)
{
int N; 
int i, ma, ans;
int x, y;
scanf ("%d", &N);
int p[N];
for(i=0;i<N;i++) {
scanf("%d",&p[i]);
}
ma = p[0];
for(i=0;i<N;i++) {
if (ma<p[i]) {
ma=p[i];
}
ans+=p[i];
}
x=ans  -ma /2;
printf ("%d", x);
return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <iostream>
#include <queue>
#include <stdio.h>
#include <string>
#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>;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

const int INF = 10011001001;
vector<int> to[100005];

int main()
{
	int n, m;
	cin >> n >> m;

	int a, b;
	rep(i, m)
	{
		cin >> a >> b;
		--a; --b;			// 頂点を0から
		to[a].push_back(b);
		to[b].push_back(a);
	}

	queue<int> q;
	vector<int> dist(n, INF);
	vector<int> pre(n, -1);

	dist[0] = 0;
	q.push(0);
	while (!q.empty())
	{
		int v = q.front(); q.pop();
		for (int u : to[v]) {
			if (dist[u] != INF) continue;	// 距離がわかっているときは何もしない
			dist[u] = dist[v] + 1;
			pre[u] = v;
			q.push(u);
		}
	}

	cout << "Yes" << endl;
	rep(i, n) {
		if (i == 0) continue;
		int ans = pre[i];
		++ans;
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 10600
H, W = map(int, input().split())

N = 0
s = [] #squares
for i in range(H):
  s.append(list(map(int, input().split())))
  
ans = []
for i in range(H):
  for j in range(W):
    if s[i][j] % 2 == 1:
      if j != W-1: #端でなければ右のマスに一枚移動させる
        s[i][j] -= 1
        s[i][j+1] += 1
        ans.append(str(i+1) + " " + str(j+1) + " " + str(i+1) + " " + str(j+2)) #右に一枚移した
        N += 1
      else:
        #右端の場合、一番下でなければ下に一枚移動させる
        if i != H-1:
          s[i][j] -= 1
          s[i+1][j] += 1
          ans.append(str(i+1) + " " + str(j+1) + " " + str(i+2) + " " + str(j+1)) #右に一枚移した
          N += 1

print(N)
for i in ans:
  print(i)

Measured memory_bytes: 16472
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
//#define DEBUG true
#define DEBUG false
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

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

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

  int p[n + 1], b[n + 1];
  p[1] = a[0];
  for(int i = 2; i <= n; i++){
    p[i] = gcd(p[i - 1], a[i - 1]);
  }
  b[n - 1] = a[n - 1];
  for(int i = n - 2; i >= 0; i--){
    b[i] = gcd(b[i + 1], a[i]);
  }

  int ans = 1;
  for(int i = 0; i < n; i++){
    if(i == 0) ans = max(ans, b[1]);
    else if(i == n - 1) ans = max(ans, p[n - 1]);
    else ans = max(ans, gcd(p[i], b[i + 1]));
  }

  cout << ans << endl;

  return 0;
}


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

int main(void) {
	using namespace std;
	string S;
	cin >> S;
	char p = S[0];
	int num_swap = 0;
	for(int i = 1; i < S.length(); ++i) {
		if(p != S[i]) {
			++num_swap;
		}
		p = S[i];
	}
	cout << num_swap << '\n';
	return 0;
}



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

int main() {
    int n;cin>>n;
    int a[4];
    for(int i=0; i<4; i++) {
        a[3-i] = n%10;
        n/=10;
    }
    if((a[0]==a[1]&&a[1]==a[2]) || (a[2]==a[1]&&a[3]==a[2])) {
        cout<<"Yes"<<endl;
    }
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func rScan() []rune {
	return []rune(Scan())
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bPrint(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func iSSPrint(x []int) {
	fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
}

var lp int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp)
	sc.Split(bufio.ScanWords)
	n, c := iScan(), iScan()
	x, v := make([]int, n+2), make([]int, n+2)
	for i := 1; i <= n; i++ {
		x[i], v[i] = iScan(), iScan()
	}
	p, q, r, s := make([]int, n+2), make([]int, n+2), make([]int, n+2), make([]int, n+2)
	copy(p, v)
	copy(q, v)
	copy(r, v)
	copy(s, v)
	for i := 1; i <= n; i++ {
		p[i] += p[i-1]
		q[i] += q[i-1]
	}
	for i := n; i >= 0; i-- {
		r[i] += r[i+1]
		s[i] += s[i+1]
	}
	for i := 1; i <= n; i++ {
		p[i] -= x[i]
		q[i] -= x[i] * 2
		r[i] -= c - x[i]
		s[i] -= (c - x[i]) * 2
	}
	for i := 1; i <= n+1; i++ {
		p[i], q[i] = larger(p[i], p[i-1]), larger(q[i], q[i-1])
	}
	for i := n; i >= 0; i-- {
		r[i], s[i] = larger(r[i], r[i+1]), larger(s[i], s[i+1])
	}
	ans := 0
	for i := 0; i <= n; i++ {
		ans = max([]int{ans, p[i] + s[i+1], q[i] + r[i+1]})
	}
	fmt.Println(ans)
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i, a, b) for(int i=(a);i<(b);i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define RREP(i, n) RFOR(i, n, 0)
#define MFOR(i, m) for(auto i=(m).begin();i!=(m).end();i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())

typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1 << 30;

template<typename T>
void printv(vector<T> const& s) {
  REP(i, SZ(s)) {
    cout << s[i] << " ";
  }
  cout << endl;
}

int main () {
  cin.tie(0);
  cout << setprecision(10);

  ll n, k; cin >> n >> k;

  vector<pair<ll, ll>> v;
  REP(i, n) {
    ll t, d; cin >> t >> d;
    t--;
    v.pb(pair<ll, ll>(d, t));
  }

  sort(ALL(v));
  reverse(ALL(v));
  /* REP(i, n) {
    cout << v[i].fi << ":" << v[i].se << endl;
   */

  priority_queue<ll> pq;
  priority_queue<ll, vector<ll>, greater<ll>> miel;
  vector<bool> sel(n, false);

  ll cnt = 0;
  ll nans = 0;
  REP(i, n) {
    pair<ll, ll> now = v[i];
    if(i < k) {
      nans += now.fi;
      if(!sel[now.se]) {
        sel[now.se] = true;
        cnt++;
      } else {
        miel.push(now.fi);
      }
    } else if(!sel[now.se]) {
      //cout << now.se << ":" << now.fi << endl;
      pq.push(now.fi);
      sel[now.se] = true;
    }
  }
  nans += cnt * cnt;


  //cout << nans << endl;
  //cout << SZ(miel) << endl;
  ll ma = nans;
  while(!miel.empty() && !pq.empty()) {
    cnt++;
    //cout << pq.top() << ":" << miel.top() << endl;
    nans += pq.top() - miel.top(); pq.pop(); miel.pop();
    nans += 2 * cnt - 1;
    ma = max(ma, nans);
    //cout << nans << endl;
  }
  cout << ma << endl;

}


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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(v)     for(bool p=1;p;p=next_permutation(ALL(v)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll INF = 1e15;
const ll MOD = 1e9+7;
const double EPS = 1e-10;

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

int main() {
    ll N, x; cin >> N >> x;
    
    if (x == 1 or x == 2 * N - 1) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
        
        vector<ll> ans(2 * N, -1);
        vector<bool> used(2 * N, false);
        queue<ll> que;
        if (N != 2) {
            if (x + 2 <= 2 * N - 1) {
                ans[N-1] = x + 1; used[x + 1] = true;
                ans[N]   = x    ; used[x]     = true;
                ans[N+1] = x - 1; used[x - 1] = true;
                ans[N+2] = x + 2; used[x + 2] = true;
            } else {
                ans[N-1] = x - 1; used[x - 1] = true;
                ans[N]   = x    ; used[x]     = true;
                ans[N+1] = x + 1; used[x + 1] = true;
                ans[N+2] = x - 2; used[x - 2] = true;
            }
        }
        
        FOR(i, 1, 2 * N) if (!used[i]) que.push(i);
        FOR(i, 1, 2 * N) if (ans[i] == -1) {
            ll x = que.front(); que.pop();
            ans[i] = x;
        }
        FOR(i, 1, 2*N) cout << ans[i] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
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;}

//INSERT ABOVE HERE
const Int MAX = 1010;
Int dp[MAX][MAX];
signed main(){
  Int n;
  while(cin>>n,n){
    vector<string> st(n);
    for(Int i=0;i<n;i++) cin>>st[i];
    memset(dp,0,sizeof(dp));
    for(Int i=n-1;i>=0;i--)
      for(Int j=n-1;j>=0;j--)
        if(st[i][j]!='*')
          dp[i][j]=min({dp[i+1][j],dp[i][j+1],dp[i+1][j+1]})+1;

    Int ans=0;
    for(Int i=0;i<n;i++)
      for(Int j=0;j<n;j++)
        chmax(ans,dp[i][j]);
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 11824
#include<bits/stdc++.h> 
#define int long long 
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
using namespace std; 
void fastio()
{
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
signed main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    if(n%2)
    cout<<"No";
    else
    {
        for(int i=0;i<n/2;i++)
        {
            if(s[i]!=s[i+n/2])
            {
                cout<<"No";
                return 0;
            }
        }
        cout<<"Yes";
    }
    
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

string s;
int data[200010];
int opt[200010];
int dp[1 << 26];

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

    cin >> s;

    for(size_t i = 1; i <= s.size(); ++i){
        data[i] = data[i - 1] ^ (1 << int(s[i - 1] - 'a'));
    }
    
    for(int i = 0; i < (1 << 26); ++i){
        dp[i] = 1 << 29;
    }

    opt[0] = 1 << 29;
    dp[0] = 0;
    for(size_t i = 1; i <= s.size(); ++i){
        opt[i] = dp[data[i]] + 1;
        for(int j = 0; j < 26; ++j){
            opt[i] = min(opt[i], dp[data[i] ^ (1 << j)] + 1);
        }
        dp[data[i]] = min(dp[data[i]], opt[i]);
    }

    cout << opt[s.size()] << endl;

    return 0;
}

Measured memory_bytes: 264340
#include <cstdio>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
 
using namespace std;
#define PB push_back
#define MP make_pair
#define REP(i,n) for(int i=0;i<(n);i++)
#define ll long long
map<int,ll>cnt;
const ll mod = 1000000007;
ll Pow(ll x, ll y){
	ll ans=1;
	for(; y; y>>=1, x=x*x%mod) if(y&1) ans=ans*x%mod;
	return ans;
}
int main(){
    int a[10010];
    int n;
    cin>>n;
    long long ans=0,p=1;
    REP(i,n){
        cin>>a[i];
        int num=a[i];
        for(int j=2;j*j<=num;j++)
        {
            int c=0;
            while(num%j==0)
            {
                num/=j;
                c++;
            }

            if(cnt[j]<c)
                cnt[j]=c;
        }
        if(num!=1&&cnt[num]==0)
            cnt[num]=1;
    }
    ll s = 1;
    for(int i=1;i<=1000000;i++)
    {
        s = (s * Pow(i,cnt[i])) % mod;
    }
    REP(i,n)
    {
        ans = (ans + (ll)s * Pow(a[i],mod-2)) % mod;
    }
    cout<<ans<<endl;
}

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

#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 10007
#define left lleft
#define right rright
#define INF 2000000000
#define LINF 1000000000000000000LL
#define next nnext

using namespace std;

lld N,M,ans;

int main(){
	scanf("%lld %lld",&N,&M);
	ans += min(N,M/2);
	N -= ans; M -= ans*2;
	ans += (M/4);
	printf("%lld\n",ans);

	return 0;
}


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

int main () {
    int N;
    cin >> N;
    vector<int> A(N,0);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    int count = 0;
    bool even = true;
    while(even == true){
        for (int i = 0; i < N; i++) {
            if (A.at(i) % 2 != 0) even = false;
        }
        for (int j = 0; j < N; j++) {
            A.at(j) /= 2;
        }
        count++;
    }
    cout << count - 1 << endl;

}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
#ABC064C
import math

n = int(input())
tmp = input().split()
hoge = list(map(lambda a: int(a), tmp))

area=[0,0,0,0,0,0,0,0,0]
#print(area)

for i in range(0,n):
	fuga = (hoge[i]//400)
	if(fuga>8):fuga=8
	area[fuga]+=1

#print("---")
#print(hoge)
#print(area)

ans=0
for i in range(0,8):
	if(area[i]>0):
		ans += 1
#print(ans)
if(ans==0):
	min=1
else:
	min=ans
max=ans+area[8]

print("{} {}".format(min,max))

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

int main()
{
	int n, k = 0;
	cin >> n >> k;
	vector<string> list(n);
	for (int i = 0; i < n; i++)
	{
		cin >> list[i];
	}
	sort(list.begin(), list.end());
	string ans = "";
	for (int i = 0; i < list.size(); i++)
	{
		ans += list[i];
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256