akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)n;i++)
using Graph = vector<vector<int> >;
using GraphC = vector<vector<char> >;
const int INF = 1000000000;
typedef pair<int, int> P;
const int MAX_N = 1000000;
typedef int64_t ll;
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll mod = 1e9 + 7;

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

	vector<int> oks(N + 1, true);
	for (int i = 0; i < M; i++)
	{
		int a; cin >> a;
		oks[a] = false;
	}

	vector<ll> dp(N + 1);
	dp[0] = 1;
	for (int now = 0; now < N; ++now) {
		for (int next = now+1;  next <= min(N,now+2);  next++)
		{
			if (oks[next])
			{
				dp[next] += dp[now];
				dp[next] %= mod;
			}
		}
	}
	cout << dp[N] << endl;
	return 0;
}


Measured memory_bytes: 4556
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int main(void){
    int N;cin>>N;
    vector<long long>V(N);
    for(int i=0;i<N;i++)cin>>V[i];
    if(N==1)cout<<V[0]<<endl;
    else{
        long long ans=V[0]/gcd(V[0],V[1])*V[1];
        for(int i=2;i<N;i++){
            ans=ans/gcd(ans,V[i])*V[i];
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 256
#include<cstdio>
int main()
{
    int a,b,c,ans=0;
    scanf("%d%d%d",&a,&b,&c);
    int s[a];
    for(int i=0;i<a;i++)
    {
        scanf("%d",&s[i]);
        if(s[i]<b||s[i]>=c)
            ans++;
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
import sys, math
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
S = rs()

import itertools

G = list(itertools.groupby(S))
print(len(G))


Measured memory_bytes: 56412
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <math.h>
using namespace std;

#define INF (1<<31-1)
#define ll long long

int main(){

	int N, M;
	int A[100002];
	ll S[100002];
	map<int, int> amari;
	ll result = 0;

	cin >> N >> M;
	S[0] = 0;
	for (int i = 1; i <= N; i++){
		cin >> A[i];
		S[i] = S[i - 1] + A[i];

		int mod = S[i] % M;
		if (amari.find(mod) == amari.end())
			amari[mod] = 1;
		else
			amari[mod] ++;
	}

	if (amari.find(0) != amari.end()) result = amari[0];
	for (map<int, int>::iterator i = amari.begin(); i != amari.end(); i++){
		int v = i->second;
		result += (ll)v*(v - 1)/2;
	}

	cout << result << endl;


	return 0;
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<stdlib.h>



int N=100;

int main(){
  int i, j, k, n, c, p[N+1], m[N+1][N+1];
  scanf("%d",&n);
  for(i=1 ; i<=n ; i++)scanf("%d%d",&p[i-1],&p[i]);
  for(i=1 ; i<=n ; i++)m[i][i]=0;
  for(j=2 ; j<=n ; j++){
    for(i=1 ; i<=n-j+1 ; i++){
      c=i+j-1;
      m[i][c]=(1<<21);
      for(k=i ; k<=c-1 ; k++){
        if(m[i][c]>m[i][k]+m[k+1][c]+p[i-1]*p[k]*p[c])m[i][c]=m[i][k]+m[k+1][c]+p[i-1]*p[k]*p[c];
      }
    }
  }
  printf("%d\n",m[1][n]);
  return 0;
}


Measured memory_bytes: 2116
import java.util.*;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		String S = in.readLine();
		in.close();
		long resultA = getCount(S, true);
		long resultB = getCount(S, false);
		System.out.println(Math.min(resultA, resultB));
	}

	static long getCount(String s, boolean firstIsZero) {
		long result = 0;
		char c = firstIsZero ? '0' : '1';
		for (int i = 0; i < s.length(); ++i) {
			if (s.charAt(i) != c) {
				++result;
			}
			c = (c == '0') ? '1' : '0';
		}
		return result;
	}

}


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

int main(){
  int n, k; cin >> n >> k;
  vector<unsigned long long> N;
  unsigned long long tmp = 0;
  N.push_back(0);
  for (int i = 0; i <= n; i++)
  {
    N.push_back(i + tmp);
    tmp += i;
    tmp %= (1000000007);
  }

/*
  cout << "N: ";
  for (auto &&i : N)
  cout << i << " ";
  cout << endl;
*/

long long ans = 0;
  for (int i = k; i <= n + 1; i++)
  {
    long long int min = N.at(i);
    long long int max = N.at(n+1)-N.at(n+1-i);
    //cout << "if k = " << i << " is ("<< N.at(n+1) << " - " << N.at(n+1-i) << ") - " << min << " = " << max - min << "\n";
    ans += max - min + 1;
    ans %= 1000000007;
    if (ans < 0)
    {
      ans += 1000000007;
    }
    
  }
  
  ans %= 1000000007;
  cout << ans << endl;
}

Measured memory_bytes: 5344
import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        Scanner myObj = new Scanner(System.in);
        String inputStr = myObj.nextLine();
        char[] inputChar = inputStr.toCharArray();

        if (inputChar[2] == inputChar[3] && inputChar[4] == inputChar[5])
        {
            System.out.print("Yes");
        }
        else {
            System.out.print("No");
        }
    }
}


Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main()
{
	string str;
	getline(cin, str);
	for (int i = 0; i < str.length(); i++)
		if (isupper(str[i]))
			str[i] = tolower(str[i]);
		else if (islower(str[i]))
			str[i] = toupper(str[i]);
	cout << str << endl;
}


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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    Int(n);
    vector<int> data(n);
    for (int i = 0; i < n; i++) {
        cin >> data[i];
    }
    
    vi dp(n, INF);
    dp[0] = 0;

    rep(i, n-1) {
        dp[i+1] = min(dp[i+1], dp[i] + abs(data[i] - data[i+1]));
        //cout << abs(data[i] - data[i+1]) << endl;
        if (i != n-2)
        dp[i+2] = min(dp[i+2], dp[i] + abs(data[i] - data[i+2]));
    }

    std::cout << dp[n-1] << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    char a[3];
    cin >> a[0] >> a[1] >> a[2];
    intl cnt = 0;
    rep(i,3){
        if(a[i] == '1')cnt++;
    }
    cout << cnt;
    return 0;
}

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

import static java.lang.Integer.parseInt;

/**
 * Frog Going Straight
 */
public class Main {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String[] words;

		line = br.readLine();

		int D, L;
		D = parseInt(line.substring(0, line.indexOf(' ')));
		L = parseInt(line.substring(line.indexOf(' ') + 1));

		int[] dp = new int[D + 1];

		for (int i = 0; i <= D; i++) {
			dp[i] = i;
			if (i >= L) {
				dp[i] = Math.min(dp[i], dp[i - L] + 1);
			}
		}

		System.out.println(dp[D]);
	}
}

Measured memory_bytes: 24444
import java.util.Scanner;

class Main{
    public static void main(String args[]){
        Scanner scan=new Scanner(System.in);
        int a,b;
        a=scan.nextInt();
        b=scan.nextInt();
        System.out.printf("%d %d %f\n",a/b,a%b,(double)a/(double)b);
   }
}


Measured memory_bytes: 26396
using namespace std;
#define _CRT_SECURE_NO_WARNINGS
#pragma target("avx")
#pragma optimize("O3")
#pragma optimize("unroll-loops")
#include<iostream>
#include<algorithm>
#include<ctime>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<iomanip>
#include<numeric>
#include<queue>
#include<deque>
#include<cfloat>
#include<functional>
#include<tuple>
#include<math.h>
#include<bitset>
#include<stack>
#include<set>
#include<random>
#include<stdlib.h>
#define rip(i,n) for(ll i=0;i<n;i++)
#define Rip(i,n) for(ll i=1;i<n;i++)
#define all(V) V.begin(),V.end()
#define ll long long
#define ld long double
#define MOD 998244353
#define mod MOD
#define sec setprecision
constexpr double eps = 1e-9;
constexpr double PI = 3.141592653589793238462643383279;
ll gcd(ll a, ll b) {
	if (a % b == 0)	return(b);
	else return(gcd(b, a % b));
}
ll lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void cominit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (ll i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}
vector<ll> soinnsuubunnkai(ll n) {
	vector<ll>a;
	while (n % 2 == 0) {
		a.push_back(2);
		n /= 2;
	}
	ll f = 3;
	while (f * f <= n) {
		if (n % f == 0) {
			a.push_back(f);
			n /= f;
		}
		else f += 2;
	}
	if (n != 1)
		a.push_back(n);
	return(a);
}
// 二項係数計算
long long com(ll n, ll k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}
ll pow(ll a, ll b) {
	a = a % mod;
	if (b == 0)return(1);
	else if (b % 2 == 0)return(pow((a * a) % mod, b / 2));
	else return(a * (pow(a, b - 1)));
}
void solve() {
	string s, t;
	cin >> s >> t;
	int a, b;
	cin >> a >> b;
	string u; cin >> u;
	if (s == u)cout << a - 1 << " " << b << endl;
	else cout << a << " " << b - 1 << endl;
}
int main() {
	solve();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int a, b, c;
  
  cin >> a >> b >> c;
  
  if((a!=b&&a==c)||(a==b&&a!=c)||(a!=b&&b==c)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <iomanip>
using namespace std;
 
int main() {
	int A,B,H,M;
	cin>>A>>B>>H>>M;
	long double time=H*60+M;
	long double angleH,angleM;
	angleH=time*2*M_PI/12.0/60;
	angleM=M*6*M_PI/180.0;
	//cout<<angleH*180/M_PI;
	
	long double ans=pow(A,2)+pow(B,2)-2*A*B*cos(angleH-angleM);
	ans=sqrt(ans);
	cout<<setprecision(20)<<ans;
	return 0;
}

Measured memory_bytes: 4156
#include<stdio.h>
#include <math.h>

double ceil2(double dIn, int nLen) {
	double dOut,unit;

	unit = pow(10.0, nLen-1);
	dOut = (round(dIn * unit)) / unit;

	return dOut;
}

int main(void) {

	double x1[20], x2[20], x3[20], y1[20], y2[20], y3[20];
	double distance_12[20],distance_23[20],distance_31[20];
	int n = 0,i=0;
	double cosA,sinA,r,p,q;

	do {
		scanf("%d",&n);
	} while (n > 20);


	while (i < n) {
		scanf("%lf%lf%lf%lf%lf%lf", &x1[i], &y1[i], &x2[i], &y2[i], &x3[i], &y3[i]);
		if ((-100 <= x1[i]) && (-100 <= x2[i]) && (-100 <= x3[i]) && (-100 <= y1[i]) &&
			(-100 <= y2[i]) && (-100 <= y3[i]) && (100 >= x1[i]) && (100 >= x2[i]) &&
			(100 >= x3[i]) && (100 >= y1[i]) && (100 >= y2[i]) && (100 >= y3[i])) {
			i++;
		}
	}


	for (i = 0; i < n; i++) {
		distance_12[i] = sqrt(pow(x1[i] - x2[i], 2) + pow(y1[i] - y2[i], 2));
		distance_23[i] = sqrt(pow(x2[i] - x3[i], 2) + pow(y2[i] - y3[i], 2));
		distance_31[i] = sqrt(pow(x3[i] - x1[i], 2) + pow(y3[i] - y1[i], 2));
		}

	for (i = 0; i < n; i++) {
		p = ((y1[i] - y3[i])*(pow(y1[i],2) - pow(y2[i],2) + pow(x1[i],2) - pow(x2[i],2)) - (y1[i] - y2[i])*(pow(y1[i],2) - pow(y3[i],2) + pow(x1[i],2) - pow(x3[i],2))) / (2*(y1[i] - y3[i])*(x1[i] - x2[i]) - 2*(y1[i] - y2[i])*(x1[i] - x3[i]));
		q = ((x1[i] - x3[i])*(pow(x1[i],2) - pow(x2[i],2) + pow(y1[i],2) - pow(y2[i],2)) - (x1[i] - x2[i])*(pow(x1[i], 2) - pow(x3[i], 2) + pow(y1[i], 2) - pow(y3[i], 2))) / (2 * (x1[i] - x3[i])*(y1[i] - y2[i]) - 2 * (x1[i] - x2[i])*(y1[i] - y3[i]));
		cosA = (pow(distance_23[i], 2) + pow(distance_31[i], 2) - pow(distance_12[i], 2))/(2*distance_23[i]*distance_31[i]);
		sinA = sqrt(1 - pow(cosA, 2));
		r = distance_12[i] / (sinA * 2);
		printf("%.3lf %.3lf %.3lf\n",ceil2(p,4),ceil2(q,4),ceil2(r,4));
	}
	return 0;
}

Measured memory_bytes: 708
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <functional>
#include <fstream>
#include <array>
#include <map>
#include <queue>
#include <time.h>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <assert.h>
#include <unordered_set>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) (min(a,b) <= (x) && (x) <= max(a,b)) //hei
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MODU 998244353LL 
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#define PI 3.141592653589
 
 
#define izryt bool
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T & val) {
	std::fill((T*)array, (T*)(array + N), val);
}
 
//[a, b)
#define Getsum(ar, a,b) (ar[b] - ar[a])
#define INF 10000000000000000LL
#define chmax(a,b) a = max(a,b)
#define chmin(a,b) a = min(a,b)
 
struct Edge {
	int from, to;
	ll w;
	bool operator<(const Edge& rhs) const {
		return MP(w, MP(from, to)) < MP(rhs.w, MP(rhs.from, rhs.to));
	}
 
};
typedef vector<vector<Edge>> Graph;
typedef unsigned long long ull;
 
 
inline ll ksum(ll n, ll k){
  return k * (2*n - k - 1);
}

pii updtp2(pii p, int nw){
  if(p.first == -1) p.first = nw;
  else if(p.second == -1) p.second = nw;
  else if(p.first >= nw) {
    p.second = p.first;
    p.first = nw;
  }
  else if(p.second >= nw) p.second = nw;
  return p;
}
 
#define isValid(y,x) (y >=0 && y < n && x >= 0 && x < m)

int main(){
  int n;
  long long sum = 0;
  cin >> n;
  vector<int> a(n + 1);
  REP(i,n + 1) {
    cin >> a[i];
    sum += a[i];
  }

  long long ans = 0, cur = 1;

  REP(i,n + 1){
    if(cur < a[i]) {
      cout << -1 << endl;
      return 0;
    }
    ans+=cur;
    cur -= a[i];
    sum -= a[i];
    cur = min(cur * 2, sum);
  }
  cout << ans << endl;
	return 0;
} 

Measured memory_bytes: 3788
#include <iostream>
#include <algorithm>
#define llint long long

using namespace std;

llint N, x;
llint a[105];

int main(void)
{
	cin >> N >> x;
	for(int i = 1; i <= N; i++) cin >> a[i];
	sort(a+1, a+N+1);
	
	llint sum = 0, ans = N;
	for(llint i = 1; i <= N; i++){
		sum += a[i];
		if(sum > x){
			ans = i-1;
			break;
		}
	}
	
	if(ans == N && sum < x) ans--;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
/*
数据不清空，爆零两行泪。
多测不读完，爆零两行泪。
边界不特判，爆零两行泪。
贪心不证明，爆零两行泪。
动规顺序错，爆零两行泪。
大于少等号，爆零两行泪。
变量不统一，爆零两行泪。
越界不判断，爆零两行泪。
调试不注释，爆零两行泪。
溢出不 l l，爆零两行泪。
*/
#include<bits/stdc++.h>
using namespace std;
const int N=100000;
int n;
int a[N+1];
int ans[N+1];
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=n-1;i;i--)if(a[i+1]<=a[i])ans[i]=ans[i+1]+1;
	cout<<*max_element(ans+1,ans+n+1);
	return 0;
}

Measured memory_bytes: 1024
S = input()
dp = [0]*(len(S)+1)
cur = int(S[len(S)-1])
mod_10 = 1
count_num = [0]*2019
count_num[0] += 1
for i in range(len(S)):
    dp[len(S)-i-1] = cur
    count_num[cur] += 1
    mod_10 = (mod_10*10)%2019
    if i <= len(S)-2:
        cur = (cur+int(S[len(S)-i-2])*(mod_10))%2019
ans = 0
for i in range(2019):
    ans += (count_num[i]*(count_num[i]-1))//2
print(ans)


Measured memory_bytes: 16468
from collections import deque
import itertools

H, W = map(int, input().split())

s = []
for _ in range(H):
    s.append(input())

sx, sy = 0, 0
gx, gy = W - 1, H - 1

score = [[-1 for _ in range(W)] for _ in range(H)]

d = deque()
score[sy][sx] = 0
d.append([sy, sx])

diff = [[-1, 0], [1, 0], [0, -1], [0, 1]]

while len(d) != 0:
    y, x = d.popleft()

    for dy, dx in diff:
        ny, nx = y + dy, x + dx
        if nx >= 0 and ny >= 0 and nx < W and ny < H and s[ny][nx] != '#' and score[ny][nx] == -1:
            score[ny][nx] = score[y][x] + 1
            d.append([ny, nx])

min_cell = score[gy][gx]
if min_cell != -1:
    whites = list(itertools.chain.from_iterable(s)).count('.')

    repaintings = whites - min_cell - 1
    print(repaintings)
else:
    print(-1)

Measured memory_bytes: 3316
// id: ALDS1_3_B
// CPU: 00:01sec  Memory: 5880KB
#include <cstdio>
#include <queue>
#include <string>

using std::queue;
using std::string;

static const int NAME_LEN = 10;

struct Process {
	string pid;
	int rest;

	Process(const string &s, int t): pid(s), rest(t) { }
	Process(const Process &p): pid(p.pid), rest(p.rest) { }
};

int main()
{
	int n, slice;
	int time = 0;
	queue<Process> processes;

	scanf("%d%d", &n, &slice);

	for ( int i = 0; i < n; ++i ) {
		char pid[NAME_LEN + 1];
		int rest;

		scanf("%s%d", pid, &rest);

		processes.emplace(string(pid), rest); //新标准的函数，oj的编译器似乎不支持
		//processes.push(Process(string(pid), rest));
	}

	while ( !processes.empty() ) {
		Process p(processes.front());
		processes.pop();

		if ( p.rest > slice ) {
			p.rest -= slice;
			time += slice;
			processes.push(p);
		}
		else {
			time += p.rest;
			printf("%s %d\n", p.pid.c_str(), time);
		}
	}

	return 0;
}


Measured memory_bytes: 5812
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
//#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)




int main(){
    int n, d, x;
    cin >> n >> d >> x;
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    int tabeta = 0;

    rep(i, n){
        for(int j = 0; j*A[i]+1 <= d; j++){
            tabeta++;
        }
    }
    int ans = x + tabeta;
    cout << ans << endl;
}

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

int main()
{

    int a,b,c,p,q,r,A,B;

    cin>>a;

    p=a/100;
    q=a%100;



    if ((q>0&&q<13)&&(p>0&&p<13))
        cout<<"AMBIGUOUS"<<endl;


    /* else if(p>=13&&q>=13)
         cout<<"AMBIGUOUS"<<endl;*/

    else if (p>0&&p<13)
        cout<<"MMYY"<<endl;


    else if(q>0&&q<13)
        cout<<"YYMM"<<endl;


    else
        cout<<"NA"<<endl;

//Afridi

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
typedef long long ll;

int main(void) {
  ll i, j, k, n, ans = 0;
  scanf("%lld", &n);
  ll a[3 * n];
  for(i = 0; i < 3 * n; ++i) scanf("%lld", &a[i]);
  std::sort(a, a + 3 * n);
  for(i = 3 * n - 2; i >= n; i -= 2) ans += a[i];
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 2560
import collections
#データの入力
a=input().split()

number=int(a[0])
quantum=int(a[1])

#保持データの作成
time=0

#キューの作成
name=[]
name=collections.deque()
q=[]
q=collections.deque()

#結果の保持
result=[[0 for i in range(2)]for j in range(number)]
endednumber=0

totaltime=0

for i in range(number):
    b=input().split()
    name.append(b[0])
    q.append(int(b[1]))
    totaltime+=int(b[1])

#キューの処理
while totaltime>time:
    cn=name.popleft()
    cq=q.popleft()

    if cq<=quantum:
        time+=cq

        result[endednumber][0]=cn
        result[endednumber][1]=time
        endednumber+=1
    else :
        time+=quantum
        newq=cq-quantum
        name.append(cn)
        q.append(newq)

#結果の表示
for i in range(number):
    print(result[i][0],result[i][1])







Measured memory_bytes: 16168
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  int len = s.length();

  char stone = s[0];
  llong ans = 0;
  REP(i,len){
    if(s[i] != stone){
      ans++;
      stone = s[i];
    }
  }

  printf("%lld\n", ans);
  return 0;
}



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

using namespace std;

int main()
{
	int n,min,cnt=0;
	string t,s1,s2;
	vector<string> arr1, arr2;

	cin >>n;
	for (int i = 0; i != n; ++i)
	{
		cin >> t;
		arr1.push_back(t);
		arr2.push_back(t);
	}
	
	for (int i = 0; i != n - 1; ++i)
	{
		for (int j = n-1; j != 0; --j)
		{
			if (arr1[j][1] < arr1[j-1][1])
			{
				arr1[j].swap(arr1[j - 1]);
			}
		}
	}

	for (int i = 0; i != n; ++i)
	{
		s1 += arr1[i];
		cout << arr1[i];
		if (i == n - 1)
		{
			cout << endl<< "Stable" << endl;
			break;
		}
		cout << " ";
	}


	for (int i = 0; i != n - 1; ++i)
	{
		min = i;
		for (int j = i+1; j != n; ++j)
		{
			if (arr2[j][1] < arr2[min][1])
			{
				min = j;
			}
		}
		if (i != min)
		{
			arr2[i].swap(arr2[min]);
		}
		
	}

	for (int i = 0; i != n; ++i)
	{
		s2 += arr2[i];
		cout << arr2[i];
		if (i == n - 1)
		{
			cout << endl;
			break;
		}
		cout << " ";
	}

	if (s1 == s2)
	{
		cout << "Stable" << endl;
	}
	else
	{
		cout << "Not stable"<< endl;
	}
	

	return 0;

}


Measured memory_bytes: 3192
#include<stdio.h>
#include<iostream>
#include<algorithm>

using namespace std;

int main(void) {

	int n, a[100], k, ali, bob;
	ali = 0;
	bob = 0;

	cin >> n;
	for (k = 0; k < n; k++)cin >> a[k];
	sort(a, a + n);

	for (k = n - 1; k >= 0; k--) {
		if ((n - 1 - k) % 2 == 0) ali += a[k];
		else bob += a[k];
	}

	cout << ali - bob << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)

int N;
vector<int> h;

int solve(int k){
  vector<int> a;
  rep(i,0,N){
    if(i == k) continue;
    a.push_back(h[i]);
  }

  int diff = a[1] - a[0];


  rep(i,0,N - 2){
    if(diff != a[i + 1] - a[i]) return false;
  }
  return true;
}

int main(){
  while(cin >> N,N){
    h.resize(N + 1);
    rep(i,0,N) cin >> h[i];

    rep(i,0,N){
      if(solve(i)){
        cout << h[i];
        break;
      }
    }

    cout << endl;
  }
}



Measured memory_bytes: 3096
def main():
    """
    input:
        1 <= H <= 100
        1 <= W <= 8
        1 <= K <= W

    output:
        数列の項の最大公約数の最大値
    """
    H, W, K = map(int, input().split())

    # ans = f(H, W, K)
    ans = editorial(H, W, K)
    print(ans)


def editorial(H, W, K):
    mod = 10 ** 9 + 7
    dp = [[0] * W for _ in range(H+1)]
    dp[0][0] = 1

    for i in range(H):
        for j in range(W):
            k_max = 1 << (W - 1)
            for k in range(k_max):
                # 2つの横線がつながっていないか
                ok = True
                for l in range(W - 2):
                    if k >> l & 1 and k >> (l + 1) & 1:
                        ok = False

                if not ok:
                    continue

                if j >= 1 and k >> (j - 1) & 1:  # left
                    a = j - 1
                elif j <= W - 2 and (k >> j) & 1:  # right
                    a = j + 1
                else:  # straight
                    a = j

                dp[i + 1][a] += dp[i][j]
                dp[i + 1][a] %= mod

    return dp[H][K - 1]


if __name__ == '__main__':
    main()


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

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

using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<bool>> g(N, vector<bool>(N, false));
    REP(_, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        g[a][b] = true;
        g[b][a] = true;
    }

    int result = 0;
    vector<int> p(N);
    REP(i, N) p[i] = i;
    do {
        bool flag = true;
        REP(i, N - 1) {
            if (!g[p[i]][p[i + 1]]) {
                flag = false;
                break;
            }
        }
        result += flag;
    } while (next_permutation(p.begin() + 1, p.end()));
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
<?php

$n = trim(fgets(STDIN));
$d = explode(" ", (trim(fgets(STDIN))));

$ans = 0;
$memo = [];
for ($i = 0; $i < $n; $i++) {
     for ($j = 0; $j < $n; $j++) {
          if($i == $j) continue;
          if(isset($memo[$i][$j])) continue;
          
          $memo[$i][$j] = true;
          $memo[$j][$i] = true;
          $ans += $d[$i] * $d[$j];
     }
}

echo $ans;

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

using namespace std;

using ll = long long;
using ld = long double;

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vs = vector<string>;

typedef pair<ll, ll> P;

#define bit(n) (1LL << (n))

//#define int long long

#define all(v) v.begin(), v.end()

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

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

template <class T>
inline void chmax(T& a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T& a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
const long long INF = 1LL << 60;

vll c, d;

// Dijkstra
// O(Elog(V))
struct Dijkstra {
  struct Edge {
    int to;
    ll cost;
    long long time;
  };

  vector<vector<Edge>> G;
  int num_v;
  vector<priority_queue<P, vector<P>, greater<P>>> vinfo;

 public:
  Dijkstra(int max_v) : G(max_v), num_v(max_v), vinfo(max_v) {
  }

  void add_edge(int from, int to, long long cost, long long time) {
    G[from].push_back((Edge){to, cost, time});
  }

  void solve(int s, ll initial_silver) {
    // P.first : time
    // P.second: index
    // P.third: money
    using T = tuple<ll, ll, ll>;
    priority_queue<T, vector<T>, greater<T>> que;

#define MAX_SILVER ((ll)2500)

    chmin(initial_silver, MAX_SILVER);

    // memo[v][num_silver]: vにいて銀貨をnum_silver枚持っている状態の最小時間
    vvll memo(num_v + 1, vll(MAX_SILVER + 1, INF));

    que.emplace(0, s, initial_silver);

    while (!que.empty()) {
      T p = que.top();
      que.pop();

      ll t = get<0>(p);
      int v = get<1>(p);
      ll sil = get<2>(p);
      chmin(sil, (ll)MAX_SILVER);

      // より少ないコストでの経路が見つかっている場合
      if (memo[v][sil] <= t) {
        continue;
      }
      chmin(memo[v][sil], t);

      // vの各辺に対しよりコストの低い経路があるかを確認
      for (auto& e : G[v]) {
        ll silver = sil - e.cost;
        if (silver >= 0) {
          if (memo[e.to][silver] > t) {
            que.emplace(t + e.time, e.to, silver);
          }
        }
      }

      // 換金
      ll new_c = min(sil + c[v], MAX_SILVER);
      if (memo[v][new_c] > t) {
        que.emplace(t + d[v], v, new_c);
      }
    }

    FOR(i, 2, num_v) {
      cout << *min_element(all(memo[i])) << endl;
    }
  }

  vector<int> get_path(const vector<int>& prev, int t) {
    vector<int> path;

    for (int v = t; v != -1; v = prev[v]) {
      path.push_back(v);
    }

    reverse(path.begin(), path.end());
    return path;
  }
};

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);

  ll n, m, s;
  cin >> n >> m >> s;

  Dijkstra graph(n + 1);

  rep(i, m) {
    int u, v;
    ll a, b;
    cin >> u >> v >> a >> b;
    graph.add_edge(u, v, a, b);
    graph.add_edge(v, u, a, b);
  }

  c = vll(n + 1);
  d = vll(n + 1);

  REP(i, n + 1) {
    cin >> c[i] >> d[i];
  }

  graph.solve(1, s);

  return 0;
}


Measured memory_bytes: 10564
#include <bits/stdc++.h>
#define INF LLONG_MAX
#define ll  long long
#define ull unsigned long long
#define rep(i,n) for(int i=0; i<n; ++i)
#define MOD 1000000007
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if(a>b) {a=b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if(a<b) {a=b; return true;} return false;}

int main() {
  int W,H,N; cin >> W >> H >> N;
  vector<int> x(N), y(N), a(N);
  rep(i,N) cin >> x[i] >> y[i] >> a[i];
  int x0=0, x1=W, y0=0, y1=H;
  rep(i,N) {
    switch(a[i]) {
      case 1:
        if(x0 <= x[i]) x0 = x[i];
        break;
      case 2:
        if(x1 >= x[i]) x1 = x[i];
        break;
      case 3:
        if(y0 <= y[i]) y0 = y[i];
        break;
      case 4:
        if(y1 >= y[i]) y1 = y[i];
        break;
    }
  }
  if(x1<x0 || y1<y0) cout << 0 << endl;
  else cout << (x1-x0)*(y1-y0) << endl;
}


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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            var time = int.Parse(line[0]);
            var rate = int.Parse(line[1]);
            if(time < 10)
            {
                rate += 100 * (10 - time);
            }
            Console.WriteLine(rate);
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,k,cnt=0;
    cin >> n;
    
    int num[n];
    num[n]=0;
    
    for (int i=0; i<n; i++){
        cin >> k;
        num[i]=k;
    }
    
    
    for(int m=n-1; 0<m; m--){
        cout << num[m] << " ";
    }

    cout << num[0] << endl;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

ll INF=LLONG_MAX;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int h,w; cin >> h >> w;
	string s[h]; ll dp[h][w];
	for(int i=0; i<h; i++)for(int j=0; j<w; j++)dp[i][j]=0;
	dp[0][0] = 1;
	for(int i=0; i<h; i++)cin >> s[i];
	for(int i=0; i<h; i++){
		for(int j=0; j<w; j++){
			if(i==0&&j==0)continue;
			if(s[i][j]=='.'){
				dp[i][j] = (i-1>=0?dp[i-1][j]:0)+(j-1>=0?dp[i][j-1]:0);
				dp[i][j] %= MOD;
			}
		}
	}
	cout << dp[h-1][w-1] << endl;
}	
/* Benq's
	stuff you should look for
	* ll, int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/


Measured memory_bytes: 9088
#include <iostream>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <algorithm>

typedef long long ll;

using namespace std;

int t = 0;
vector<vector<int> > a;
vector<int> d, f;
vector<bool> v;

void dfs(int i) {
  v[i] = true;
  d[i] = ++t;
  for (int j : a[i]) {
    if (!v[j]) {
      dfs(j);
    }
  }
  f[i] = ++t;
}

int main() {
    int n; cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        int u; cin >> u; u--;
        int k; cin >> k;
        for (int j = 0; j < k; j++) {
            int v; cin >> v; v--;
            a[i].push_back(v);
        }

    }
    v.resize(n, false);
    d.resize(n);
    f.resize(n);

    for (int i = 0; i < n; i++) {
        if (!v[i]) {
            dfs(i);
        }
    }

    for (int i = 0; i < n; i++) {
        cout << (i + 1) << " " << d[i] << " " << f[i] << endl;
    }
    return 0;
}




Measured memory_bytes: 3164
#include <cstdio>

using i64 = long long;

constexpr int maxn = 200000;

inline int io() {
	static int v;
	return scanf("%d\n", &v), v;
}

inline void chkMin(int &x, const int &y) {
	(x > y) and (x = y);
}

int main() {
	static char s[maxn + 1];
	static int w[maxn + 2], b[maxn + 2];

	const int n = io();
	fread(s + 1, 1, n, stdin);

	for (int i = n; i; --i)
		b[i] = b[i + 1] + (s[i] == '#');
	for (int i = 1; i <= n; ++i)
		w[i] = w[i - 1] + (s[i] == '.');

	int ans = n;
	for (int i = 0; i <= n; ++i)
		chkMin(ans, (n - i - b[i + 1]) + (i - w[i]));
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 1920
package main

import (
	"fmt"
	"math"
)

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

func main() {
	var N int
	fmt.Scan(&N)
	A := make([]int, N)
	for i := range A {
		fmt.Scan(&A[i])
	}
	ans := math.MaxInt32
	for i := 0; i < N; i++ {
		t := A[i]
		c := 0
		for t%2 == 0 {
			t /= 2
			c++
		}
		ans = min(ans, c)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
K = int(input())
X = 50

A = [X - 1] * X
A = [a + K // X for a in A]
for i in range(K % X):
    A[i] += 1
for i in range(X - (K % X)):
    A[-i - 1] -= K % X

print(X)
print(*A, sep=' ')


Measured memory_bytes: 9116
N,M=map(int, input().split())
from collections import defaultdict
G=defaultdict(lambda: [])
for _ in range(M):
    a,b=map(int, input().split())
    G[a].append(b)
    G[b].append(a)
for nx in G[1]:
    if N in G[nx]:
        print("POSSIBLE")
        exit()
print("IMPOSSIBLE")

Measured memory_bytes: 135464
using System;

public class Program{
    public static void Main(){
        string[] input1=Console.ReadLine().Split(' ');
        int N=int.Parse(input1[0]);
        int D=int.Parse(input1[1]);
        int[][] X=new int[N][];
        int num=0;
        for(int i=0;i<N;i++){
            string[] input2=Console.ReadLine().Split(' ');
            X[i]=new int[D];
            for(int j=0;j<D;j++){
                X[i][j]=int.Parse(input2[j]);
            }
        }
        for(int i=0;i<N;i++){
            for(int j=i+1;j<N;j++){
                int sum=0;
                for(int k=0;k<D;k++){
                    int d=X[i][k]-X[j][k];
                    sum+=d*d;
                }
                for(int k=1;k*k<=sum;k++){
                    if(k*k==sum){
                        num+=1;
                        break;
                    }
                }
            }
        }
        Console.WriteLine(num);
    }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,n) for(int i = 0;i < (n);i++)
using namespace std;
const ll INF = 1e10;

int a,b,k;
int main(){
  cin>>a>>b>>k;
  for(int i=a;i<=b;i++){
    if(i<a+k || i>b-k)cout<<i<<endl;
  }
  return 0;
}



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

using namespace std;

int main(void)
{
  int a,ans;
  cin >> a;
  if(a == 0) ans = 1;
  else ans = 0;
  cout << ans <<endl;
  return 0;
}


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

class Main {
    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static void main(String[] args) throws IOException {
        int s = Integer.parseInt(br.readLine());
        System.out.println(s/3600+":"+s/60%60+":"+s%60);
    }
}

Measured memory_bytes: 24364
#include<iostream>
#include<algorithm>
using namespace std;
int n,m,x[1<<17];
int s[1<<17];
main()
{
	cin>>n>>m;
	for(int i=0;i<m;i++)cin>>x[i];
	sort(x,x+m);
	long ans=x[m-1]-x[0];
	for(int i=0;i<m-1;i++)s[i]=x[i+1]-x[i];
	sort(s,s+m-1);
	for(int i=m-2;i>=0&&m-2-i<n-1;i--)ans-=s[i];
	cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, a, n) for(ll i = (ll)a; i < (ll)n; i++)
#define FORR(i, n) for(ll i = (ll)n - 1LL; i >= 0LL; i--)
#define rep(i, n) FOR(i, 0, n)
#define ALL(x) ((x).begin(), (x).end())
using namespace std;
using ll = long long;
template <typename T> using V = vector<T>;

constexpr int Mod = 998244353;
constexpr int mod = 1e9 + 7;
constexpr ll inf = 1LL << 60;

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

/*-------------------------------------------*/

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

    int n, k;
    double ans = 0;
    cin >> n >> k;
    FOR(d, 1, n + 1) {
        int x = 1;
        while(d * x < k)
            x <<= 1;
        ans += 1.0 / (n * x);
    }
    cout << fixed << setprecision(10) << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> ke(n, -1), c(m), s(m);
  int flag = 1;

  if(n == 1 && m == 0){
    cout << 0 << endl;
    return 0;
  }

  if(n == 1){
    for(int i = 0; i < m; i++){
      cin >> s[i] >> c[i];
    }
    for(int i = 0; i < m - 1; i++){
      if(c[i] == c[i+1]){
        continue;
      }else{
        cout << -1 << endl;
        return 0;
      }
    }
    cout << c[0] << "\n";
    return 0;
  }

  for(int i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
    if(s[0] == 1 && c[0] == 0){
      flag = 0;
    }

    if(ke[s[i]-1] == -1 || ke[s[i]-1] == c[i]){
      ke[s[i] - 1] = c[i];
    }else{
      flag = 0;
    }
  }
  if(ke[0] == -1){
    ke[0] = 1;
  }

  if(flag == 1){
    for(int i = 0; i < n; i++){
      if(ke[i] == -1){
        cout << 0;
      }else{
        cout << ke[i];
      }
    }
  }else{
    cout << -1;
  }
  cout << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;
void parse(int& x, int& y) {
    string s;
    cin >> s;
    y = s[0] - 'a';
    x = stoi(s.substr(2));
    x--;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

typedef tuple<int, int, int, int> T; // dist, x, y, r

bool valid(int x, int w) {
    return 0 <= x && x < w;
}

int main(){
    int H, W;
    while(cin >> H >> W && H > 0) {
        int D;
        cin >> D;
        int ns;
        cin >> ns;

        int K[21][21] = {};
        REP(i, ns) {
            int x, y;
            parse(x, y);
            cin >> K[y][x];
        }

        int nc;
        cin >> nc;
        bool forbid[21][21][4] = {};
        REP(i, nc) {
            int x1, y1, x2, y2;
            parse(x1, y1);
            parse(x2, y2);
            if(x1 == x2) {
                if(y1 > y2) swap(y1, y2);
                forbid[y1][x1][1] = true;
                forbid[y2][x1][3] = true;
            } else {
                if(x1 > x2) swap(x1, x2);
                forbid[y1][x1][0] = true;
                forbid[y1][x2][2] = true;
            }
        }

        int cost[21][21][4] = {};
        int nj;
        cin >> nj;
        REP(i, nj) {
            int x1, y1, x2, y2;
            parse(x1, y1);
            parse(x2, y2);
            int d;
            cin >> d;
            if(x1 == x2) {
                if(y1 > y2) swap(y1, y2);
                cost[y1][x1][1] = d;
                cost[y2][x1][3] = d;
            } else {
                if(x1 > x2) swap(x1, x2);
                cost[y1][x1][0] = d;
                cost[y1][x2][2] = d;
            }
        }

        int sx, sy, gx, gy;
        parse(sx, sy);
        parse(gx, gy);

        priority_queue<T, vector<T>, greater<T>> que;
        bool memo[20][20][4][101] = {};
        REP(r, 4) {
            memo[sy][sx][r][0] = true;
            que.push(T(0, sx, sy, r));
        }

        int ans = INT_MAX;
        while(!que.empty()) {
            T _t = que.top(); que.pop();
            int d, x, y, pr;
            tie(d, x, y, pr) = _t;
            //printf("d = %d x = %d y = %d pr = %d\n", d, x, y, pr);

            if(K[y][x] != 0) {
                int t = (d / K[y][x]);
                if((pr + 1) % 2 != t % 2) continue;
            }

            if(x == gx && y == gy) {
                ans = d;
                break;
            }

            REP(r, 4) if((r + 2) % 4 != pr) {
                int nx = x + dx[r];
                int ny = y + dy[r];
                if(!valid(nx, W)) continue;
                if(!valid(ny, H)) continue;
                if(forbid[y][x][r]) continue;

                // ??
                //if(K[y][x] != 0 && (d / K[y][x]) % 2 != (r + 1) % 2) continue;

                int nd = d + D + cost[y][x][r];
                if(nd > 100) continue;
                if(memo[ny][nx][r][nd]) continue;

                memo[ny][nx][r][nd] = true;
                que.push(T(nd, nx, ny, r));
            }
        }

        assert(ans != INT_MAX);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1428
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<map>

using namespace std;
#define mod 1000000007
#define ll long long 


int n, a[100009], b[100009], c[100009];
int dp[100009][4];
 
int solve(int idx, int prev) {
    if(idx == n)
        return 0;
    
    if(dp[idx][prev] != -1)
        return dp[idx][prev];
 
    int ans = INT_MIN;
 
    if(prev == 0) {
        ans = max(ans, b[idx] + solve(idx + 1, 1));
        ans = max(ans, c[idx] + solve(idx + 1, 2));
    } else if (prev == 1) {
        ans = max(ans, c[idx] + solve(idx + 1, 2));
        ans = max(ans, a[idx] + solve(idx + 1, 0));
    } else if (prev == 2){
        ans = max(ans, a[idx] + solve(idx + 1, 0));
        ans = max(ans, b[idx] + solve(idx + 1, 1));
    } else {
        ans = max(ans, a[idx] + solve(idx + 1, 0));
        ans = max(ans, b[idx] + solve(idx + 1, 1));
        ans = max(ans, c[idx] + solve(idx + 1, 2));
    }
 
    return dp[idx][prev] = ans;
}
 
int main() {
 
    // int t;
    // cin>>t;
    // while(t--) {
        cin>>n;
        memset(dp, -1, sizeof(dp));
        for(int i = 0; i < n; i++) {
            cin>>a[i]>>b[i]>>c[i];
        }
 
        cout<<solve(0, 3)<<endl;
    // }
}

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

int main()
{
	string s;
	cin >> s;
	bool flag=false;
	if (s[0]=='A'&&!(s[1]<='Z'&&s[1]>='A')&&!(s[s.size()-1]>='A'&&s[s.size()-1]<='Z'))
	{
		for (int i=1; i<s.size()-1; i++)
		{
			if (s[i]=='C')
			{
				if (!flag)
					flag=true;
				else
				{
					cout << "WA" << endl;
					return 0;
				}
			}
		}
	}
	if (flag)
	{
		cout << "AC" << endl;
	}
	else
	{
		cout << "WA" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int n, count = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; i++) {
        int j = i, keta = 0;
        while (j != 0) {
            j /= 10;
            keta++;
        }
        if(keta % 2 == 1) {
            count++;
        }
    }
    printf("%d\n", count);
    return 0;
}

Measured memory_bytes: 128
n,k=map(int,input().split())
r,s,p=map(int,input().split())
t=input()
ans=0
janken={"r":p,"s":r,"p":s}
aiko=[]
for i in range(n):
    if i<k:
        ans+=janken[t[i]]
        aiko.append(False)
    else:
        if t[i-k]!=t[i] or (t[i-k]==t[i] and aiko[i-k]):
            ans+=janken[t[i]]
            aiko.append(False)
        else: aiko.append(True)
print(ans)

Measured memory_bytes: 4212
n = int(input())
array = [int(v) for v in input().split(" ")]

count = 0

max_count = 0
v0 = array[0]

for i in range(1, len(array)):
    v = array[i]
    if v0 >= v:
        count += 1
      
        if count > max_count:
            max_count = count
    else:
        count = 0

    v0 = v

print(max_count)

Measured memory_bytes: 14252
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<numeric>
#include<algorithm>
#include<complex>
#include<queue>
#include<stdlib.h>
#include<map>
#include<cmath>
#include<stdio.h>
#include<stdlib.h>
#include<set>
#include<iomanip>

#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define mp make_pair
#define MOD 1000000007

using namespace std;
using ll=long long int;

int H,W;
vector<string> S;

int main(){
    string N;
    cin >> N;
    for(int i=0;i<N.size();i++){
        if(i+1<N.size()&&N[i]==N[i+1]){
            cout << "Bad" << endl;
            return 0;
        }
    }
    cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,x,n) for(int i=x;i<n;i++)
#define mod 1000000007 //10^9+7
#define INF 1000000000000 //10^12
#define F first
#define S second
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()
//library begin
int gcd(int a,int b){
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a*b/gcd(a,b);
}
int log(int a){
    int b=a;
    int cnt=0;
    while(b%2==0){
        b/=2;
        cnt++;
    }
    return cnt;
}
int mypow(int a,int b){
    if(b==0)return 1;
    if(b==1)return a;
    int t=mypow(a,b/2);
    if(b%2==0)return t*t;
    return t*t*a;
}
//library end
int n,k;
int sum=0;
int a[200000];
signed main(){
    cin>>n>>k;
    rep(i,n)cin>>a[i];
    sort(a,a+n);
    if(k>=n)cout<<0<<endl;
    else{
        int ans=0;
        rep(i,n-k){
            ans+=a[i];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 1792