akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;


void enqueue(P x){
  Q[tail] = x;
  tail = (tail + 1) % LEN;
}

P dequeue(){
  P x = Q[head];
  head = (head + 1) % LEN;
  return x;
}

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

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }

  head = 1;
  tail = n + 1;

  while(head != tail)
    {
      u = dequeue();
      c = min(q,u.t);
      u.t -= c;
      elaps += c;
      if(u.t > 0) enqueue(u);
      else
	{
	  printf("%s %d\n",u.name,elaps);
	}
    }
  return 0;
}

  



Measured memory_bytes: 11924
/* {{{ Shinobu kawaii */
/*
  ______   __        _                  __                 
.' ____ \ [  |      (_)                [  |                
| (___ \_| | |--.   __   _ .--.   .--.  | |.--.   __   _   
 _.____`.  | .-. | [  | [ `.-. |/ .'`\ \| '/'`\ \[  | | |  
| \____) | | | | |  | |  | | | || \__. ||  \__/ | | \_/ |, 
 \______.'[___]|__][___][___||__]'.__.'[__;.__.'  '.__.'_/ 

*/
/* }}} */

#include <bits/stdc++.h>
using namespace std;

// #define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (int i = (a); i >= n; --i)
#define DEP(i, n) DEPS(i, n, 0)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; std::cin >> x; return x;}
template <typename T> void print(T x) {std::cout << x << '\n';}
template <typename T>
void print(std::vector<T>& v, std::string s = " ") {
  REP(i, v.size()) {
    if (i != 0) std::cout << s;
    std::cout << v[i];
  }
  std::cout << '\n';
}

/* }}} */

signed main()
{
  vi shinobu(2001, 0);

  REP(i, 1001) REP(j, 1001) ++shinobu[i + j];
  int n;
  while (cin >> n) {
    int chie = 0;
    REP(i, min(2001, n + 1)) {
      if (n - i > 2000) continue;
      chie += shinobu[i] * shinobu[n - i];
    }
    print(chie);
  }

  return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a[1000000];
	long long sum=0,temp=0;
	scanf("%s",a);
	for(int i=0;i<strlen(a);i++){
		if(a[i]=='B') temp++;
		else sum+=temp;
	}
	printf("%lld",sum);
	return 0;
}

Measured memory_bytes: 512
from itertools import combinations
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

for (i,j) in combinations([a,b,c,d,e], 2):
    if(abs(i-j)>k):
        print(":(")
        exit()

print("Yay!")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,ans,sum=0,i;
    cin>>a>>b;
    bool f=false;
    for(i=1; i<=10000; i++)
    {

        if(i*8/100==a&&i*10/100==b)
        {
            cout<<i<<endl;
            f=true;
            break;
        }
    }
    if(f==false)
        cout<<-1<<endl;
    return 0;
}


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


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


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
const long long MOD = 1000000007;

ll N, C, x[100010], v[100010];
ll max_L[100010], max_2L[100010], max_R[100010], max_2R[100010];

signed main(){
    cin >> N >> C;
    REP(i, N) cin >> x[i] >> v[i];
    ll sum = 0;
    REP(i, N){
        sum += v[N - 1 - i];
        if(i == 0){
            max_L[N - 1 - i] = max(0LL, sum - (C - x[N - 1 - i]));
            max_2L[N - 1 - i] = max(0LL, sum - 2 * (C - x[N - 1 - i]));
        }else{
            max_L[N - 1 - i] = max(max_L[N - i], sum - (C - x[N - 1 - i]));
            max_2L[N - 1 - i] = max(max_2L[N - i], sum - 2 * (C - x[N - 1 - i]));
        }
    }
    sum = 0;
    REP(i, N){
        sum += v[i];
        if(i == 0){
            max_R[i] = max(0LL, sum - x[i]);
            max_2R[i] = max(0LL, sum - 2 * x[i]);
        }else{
            max_R[i] = max(max_R[i - 1], sum - x[i]);
            max_2R[i] = max(max_2R[i - 1], sum - 2 * x[i]);
        }
    }
    ll ans = 0;
    REP(i, N){
        if(i == 0) ans = max(ans, max_L[0]);
        ans = max(ans, max_2R[i - 1] + max_L[i]);
    }
    REP(i, N){
        if(i == N - 1) ans = max(ans, max_R[N - 1]);
        ans = max(ans, max_2L[i + 1] + max_R[i]);
    } 
    PRINT(ans);
    return 0;
}

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

class edge{
	public:
		int to,cost;
		edge();
		edge(int _to,int _cost){
			to = _to;
			cost = _cost;
		}
};
class state{
	public:
		int id,cost,ticket;
		state();
		state(int _id,int _cost,int _ticket){
			id = _id;
			cost = _cost;
			ticket = _ticket;
		}
		bool operator<(const state st)const{
			return cost > st.cost;
		}
};
const int INF = 1000000000;

int main()
{
	int c,n,m,s,g;
	while(cin >> c >> n >> m >> s >> g){
		if(!c&&!n&&!m&&!s&&!g)
			break;
		vector<edge> t[101];
		int d[101][11];
		for(int i=0;i<m;i++){
			int a,b,cost;
			cin >> a >> b >> cost;
			a--;b--;
			t[a].push_back(edge(b,cost));
			t[b].push_back(edge(a,cost));
		}
		s--;g--;

		int ans = INF;
		for(int j=0;j<101;j++){
			for(int i=0;i<11;i++){
				d[j][i] = INF;
			}
		}
		d[s][c] = 0;
		priority_queue<state> que;
		que.push(state(s,0,c));
		while(!que.empty()){
			state st = que.top();
			que.pop();
			int v = st.id;
			if(st.id == g)
				ans = min(ans,st.cost);
			for(unsigned i=0;i<t[v].size();i++){
				edge e = t[v][i];	
				if( d[e.to][st.ticket] > d[v][st.ticket] + e.cost){
					d[e.to][st.ticket] = d[v][st.ticket] + e.cost;
					que.push(state(e.to,d[e.to][st.ticket],st.ticket));
				}
				if(st.ticket>0){
					if( d[e.to][st.ticket-1] > d[v][st.ticket] + (e.cost)/2){
						d[e.to][st.ticket-1] = d[v][st.ticket] + (e.cost)/2;
						que.push(state(e.to,d[e.to][st.ticket-1],st.ticket-1));
					}
				}
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 1240
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int m1 = Integer.parseInt(sc.next());
	int d1 = Integer.parseInt(sc.next());
    int m2 = Integer.parseInt(sc.next());
    int d2 = Integer.parseInt(sc.next());

	if(m1 != m2 && d2 == 1) {
      System.out.println("1");
    } else {
      System.out.println("0");
    }
    
  }
}


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

string colors[] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};

int dis(int id, vector<int> a){
  int res = 0;
  for(int i=0;i<3;i++){
    int comp = 0;
    if(id&1) comp = 255;
    res += (a[i]-comp)*(a[i]-comp);
    id/=2;
  }
  return res;
}

int toDec(char a){
  if(isdigit(a))return a-'0';
  return a-'a'+10;
}

int main(){
  string s;
  while(cin >> s, s != "0"){
    vector<int> a(3);
    for(int i=0;i<3;i++){
      a[i] = toDec(s[2*i+1])*16 + toDec(s[2*i+2]);
    }
    reverse(a.begin(), a.end());
    int ans = 0, dmin = dis(0,a);
    for(int i=1;i<8;i++){
      if(dis(i,a) < dmin){
        ans = i; dmin = dis(i,a);
      }
    }
    cout << colors[ans] << endl;
  }
}

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

int main() {
	
	int n, h;
	cin >> n >> h;
	vector<int> a(n), b(n);
	int a_max = 0;
	rep(i, n){
		cin >> a[i] >> b[i];
		if(a_max < a[i]) a_max = a[i];
	}
	sort(all(b));
	int p = upper_bound(all(b), a_max) - b.begin();
	int b_sum = 0;
	int cnt = 0;
	for(int i = n - 1; i >= p; i--){
		if(b_sum >= h){
			break;
		}
		b_sum += b[i];
		cnt++;
	}
	int ans = 0;
	ans += max(0, (h - b_sum + a_max - 1)) / a_max;
	ans += cnt;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/abc134/tasks/abc134_d

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define EPS (1e-9)
#define INF (1e9)
#define INFL (1e18)
#define MOD (1000000007)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define LEN(x) (sizeof(x) / sizeof(*(x)))
// ll gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// ll lcm(long a, long b) { return a * b / gcd(a, b); }

inline int read() {
    int out = 0, fh = 1;
    char jp = getchar();
    while ((jp > '9' || jp < '0') && jp != '-')
        jp = getchar();
    if (jp == '-')
        fh = -1, jp = getchar();
    while (jp >= '0' && jp <= '9')
        out = out * 10 + jp - '0', jp = getchar();
    return out * fh;
}

int a[200001];
bool b[200001];
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = n; i >= 1; i--) {
        int x = a[i];
        for (int j = i << 1; j <= n; j += i) {
            x ^= b[j];
        }
        b[i] = x;
        if (x)
            ans++;
    }
    cout << ans << '\n';
    for (int i = 1; i <= n; i++) {
        if (b[i])
            cout << i << " ";
    }

    return 0;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
#define max(x, y) ((x) > (y) ? (x) : (y))
#define min(x, y) ((x) < (y) ? (x) : (y))
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define rall(x) x.end(),x.begin()
#define sz(x) ((int)x.size())
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pi;
int a, b, c, i, j, k;
long long ans = 0LL;
int main ()
{
	int t,T;
	scanf("%d%d",&t,&T);
    if (t%T == 0) {
        cout << t/T << endl;
    } else {
        cout << t/T + 1 << endl;
    }
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
static const int N = 100;
static const int INFTY = (1<<21);

int n, m[N][N];
int d[N];

void bfs(int s) {
    queue<int> q;
    q.push(s);
    for (int i = 0; i < n; i++) d[i] = INFTY;
    d[s] = 0;
    int u;
    while (!q.empty()) {
        u = q.front(); q.pop();
        for (int v = 0; v < n; v++) {
            if (m[u][v] == 0) continue;
            if (d[v] != INFTY) continue;
            d[v] = d[u] + 1;
            q.push(v);
        }
    }
    for (int i = 0; i < n; i++) {
        cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
    }
}

int main() {
    int u, k, v;

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

    for (int i = 0; i < n; i++) {
        cin >> u >> k;
        u--;
        for (int j = 0; j < k; j++) {
            cin >> v;
            v--;
            m[u][v] = 1;
        }
    }

    bfs(0);
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl '\n'
#define ll long long
int main(){
    Hello
    string s, a = "", b = "";
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        if(i % 2) a += '1';
        else a += '0';
    }
    for(int i = 0; i < s.size(); i++){
        if(i % 2) b += '0';
        else b += '1';
    }
    int ans1 = 0, ans2 = 0;
    for(int i = 0; i < s.size(); i++)
        if(s[i] != a[i]) ans1 ++;
    for(int i = 0; i < s.size(); i++)
        if(s[i] != b[i]) ans2 ++;
    cout << min(ans1, ans2);
    return 0;
}


Measured memory_bytes: 3900
#include<stdio.h>
#define STABLE 1
#define NOT_STABLE 0
int BubbleSort( char Suit[], char Number[], int Order[], int n ){

  int i,j,k;
  char c;

  for ( i = 0 ; i < n ; i++ ){
    for ( j = n - 1 ; j > i ; j-- ){
      if ( Number[j] < Number[ j - 1 ] ) {
	c = Suit[j];
	Suit[j] = Suit[ j - 1 ];
	Suit[ j - 1 ] = c;
	c = Number[j];
	Number[j] = Number[ j - 1 ];
	Number[ j - 1 ] = c;
	k = Order[j];
	Order[j] = Order[ j - 1 ];
	Order[ j - 1 ] = k;
      }
    }
  }

  return 0;

}
int SelectionSort( char Suit[], char Number[], int Order[], int n ){

  int i,j,k,minj;
  char c;

  for ( i = 0 ; i < n ; i++ ){
    minj = i;
    for( j = i ; j < n ; j++ ){
      if ( Number[j] < Number[minj] ){
	minj = j;
      }
    }
    c = Suit[i];
    Suit[i] = Suit[minj];
    Suit[minj] = c;
    c = Number[i];
    Number[i] = Number[minj];
    Number[minj] = c;
    k = Order[i];
    Order[i] = Order[minj];
    Order[minj] = k;
  }

  return 0;
  
}
int is_stable( char Suit[], char Number[], int Order[], int n ){

  int i;

  for ( i = 0 ; i < n - 1 ; i++ ){
    if ( Number[i] == Number[ i + 1 ] && Order[i] > Order[ i + 1 ] ) {
      return NOT_STABLE;
    }
  }

  return STABLE;
  
}



int main(){

  int i,n;

  scanf("%d", &n );

  char Suit[37],Number[37],c;
  int Order[37];

  for ( i = 0 ; i < n ; i++ ){
    scanf("%c", &c );
    scanf("%c", &Suit[i] );
    scanf("%c", &Number[i] );
    Order[i] = i;
  }

  char Suit1[37],Number1[37];
  int Order1[37];

  for ( i = 0 ; i < n ; i++ ){
    Suit1[i] = Suit[i];
    Number1[i] = Number[i];
    Order1[i] = Order[i];
  }
  
  BubbleSort( Suit1, Number1, Order1, n );

  for ( i = 0 ; i < n ; i++ ){
    if ( i < n - 1 ) {
      printf("%c%c ", Suit1[i], Number1[i] );
    } else {
      printf("%c%c\n", Suit1[i], Number1[i] );
    }
  }

  if ( is_stable( Suit1, Number1, Order1, n ) == STABLE ){
    printf("Stable\n");
  } else if ( is_stable( Suit1, Number1, Order1, n ) == NOT_STABLE ){
    printf("Not stable\n");
  } else {
    printf("ERROR\n");
  }

  SelectionSort( Suit, Number, Order, n );

  for ( i = 0 ; i < n ; i++ ){
    if ( i < n - 1 ) {
      printf("%c%c ", Suit[i], Number[i] );
    } else {
      printf("%c%c\n", Suit[i], Number[i] );
    }
  }

  if ( is_stable( Suit, Number, Order, n ) == STABLE ){
    printf("Stable\n");
  } else if ( is_stable( Suit, Number, Order, n ) == NOT_STABLE ){
    printf("Not stable\n");
  } else {
    printf("ERROR\n");
  }


  return 0;

}

Measured memory_bytes: 608
#include <stdio.h>
int H,W;
char L[120][120];
int mvX[4]={0,0,1,-1};
int mvY[4]={1,-1,0,0};

void dfs(int y, int x){
  int i;
  char c=L[y][x];
  L[y][x]='.';
  for (i=0;i<4;i++){
    int mx=x+mvX[i];
    int my=y+mvY[i];
    if (0<=mx && mx<W && 0<=my && my<H && L[my][mx]==c)
      dfs(my,mx);
  }
}

int main(){
  int i,j;
  while (1){
    int cnt=0;
    scanf("%d %d",&H,&W);
    if (H==0 && W==0) break;
    for (i=0;i<H;i++)
        scanf("%s",L[i]);
    for (i=0;i<H;i++)
      for (j=0;j<W;j++)
        if (L[i][j]!='.'){
            dfs(i,j);
            cnt++;
          }
    printf("%d\n",cnt);
  }
  return 0;
}

Measured memory_bytes: 1080
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define mp make_pair
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;

using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
    {
        return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
    }
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
    {
        x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
        x*=f;
    }

    template<typename T>inline void write(T x,char ch='\n')
    {
        if(!x)*nowps++='0';
        if(x<0)*nowps++='-',x=-x;
        static uint32 sta[111],tp;
        for(tp=0;x;x/=10)sta[++tp]=x%10;
        for(;tp;*nowps++=sta[tp--]^48);
        *nowps++=ch;
    }
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
    FILE*DSA=freopen("water.in","r",stdin);
    FILE*SDU=freopen("water.out","w",stdout);
#endif
}

const int MAXN=1e3+17;

static int n;

static struct node
{
	int x,y,r;
}p[MAXN];

void init()
{
	read(p[1].x),read(p[1].y),read(p[2].x),read(p[2].y);
	read(n);n+=2;
	Rep(i,3,n)read(p[i].x),read(p[i].y),read(p[i].r);
}

static double ps[MAXN][MAXN],dis[MAXN];

inline double sq(double x){return x*x;}

static int vis[MAXN];

inline void solve()
{
	Rep(i,2,n)dis[i]=DBL_MAX;
	Rep(i,1,n)Rep(j,i+1,n)ps[i][j]=ps[j][i]=
		max(sqrt(sq(p[i].x-p[j].x)+sq(p[i].y-p[j].y))-p[i].r-p[j].r,0.0);
	Rep(i,1,n-1)
	{
		int hd=0;
		double ds=DBL_MAX;
		Rep(j,1,n)if(!vis[j]&&ds>dis[j])ds=dis[j],hd=j;
		vis[hd]=1;
		Rep(j,1,n)Chkmin(dis[j],ds+ps[hd][j]);
	}
	printf("%.13lf\n",dis[2]);
}

int main()
{
    init();
    solve();
    return 0;
}


Measured memory_bytes: 8320
#include "bits/stdc++.h"
using namespace std;

#define rep(i, n) for(auto i=0; i != n; ++i)
#define REP(i, k, n) for(auto i=k; i != n; ++i)
#define rrep(i, n) for(auto i=n; i != 0; --i)
#define RREP(i, n, k) for(auto i=n; i != k; --i)


int main() {
    cin.tie(nullptr);

    while(1){
        int m, nmin, nmax; cin >> m >> nmin >> nmax;

        if(m+nmin+nmax == 0)    break;
        vector<int> p(m);
        rep(i, m)   cin >> p[i];
        int max_gap = 0, ans = 0;
        REP(i, nmin, nmax+1){
            if(max_gap <= p[i-1] - p[i]) {
                max_gap = p[i - 1] - p[i];
                ans = i;
            }
        }

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 3052
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

string s;
int n;
signed main() {
    cin >> s >> n;
    rep(i,0,s.length()) {
        if(i != s.length() - 1 && s[i] == 'a') continue;
        int nd = 'z' - s[i] + 1;
        if(nd <= n) {
            n -= nd;
            s[i] = 'a';
        }
        if(i == s.length() - 1) {
            int cur = s[i] - 'a';
            s[i] = 'a' + ((cur + n) % 26);
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 512
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <stdio.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second
#define mp make_pair
 
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll GCD(ll a, ll b){
  if (a < b) swap(a, b);
  while (a % b != 0){
    a %= b; swap(a, b);
  }
  return b;
}
ll LCM(ll a, ll b){
  ll G = GCD(a, b);
  return a / G * b;
}
ll Count(ll a, ll c, ll d){
  return a / c + a / d - a / LCM(c, d);
}

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

  cout << B - A + 1 - (Count(B, C, D) - Count(A - 1, C, D)) << endl;

  return 0;
}


Measured memory_bytes: 256
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//211
	ll n;
	cin>>n;
	vector<bool> prime(n+1,1);
	REP(i,2,n) {
		if(prime[i])for(int j=i+i;j<=n;j+=i)prime[j]=0;
	}
	ll ans = 1;
	for(ll i=2;i<=n;i++) {
		if(prime[i]) {
			ll now = i,cnt=0;
			while(now<=n){cnt=cnt+(n/now);now*=i;}
			ans = (ans*(cnt+1))%1000000007;
		}
	}
	//if(n!=1)ans = (ans*2)%1000000007;
	cout<<ans;
}//1, 2, 4, 8, 12, 30, 60, 96

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
typedef int64_t ll;
struct Solution {
    void solve(std::istream& in, std::ostream& out) {
        ll N,ans=1;
        in >> N;
        for (int i = 1; i < 11145114; i <<= 1) {
            if (N >= i) {
                ans = i;
            }
        }
        out << ans << endl;
    }
};
void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}
#include <fstream>
#include <iostream>
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    istream& in = cin;
    ostream& out = cout;
    solve(in, out);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e15;
// __uint128_t

int main(){
    ll H, M, h, m, K; cin >> H >> M >> h >> m >> K;
    ll mins;
    if(M <= m) mins = (h-H)*60 + m-M;
    else mins = (h-H-1)*60 + 60-M+m;
    cout << mins-K << endl;


}

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

int main(){
    int n;
    char s[33333];
    scanf("%d%s",&n,s);
    vector<vector<bool> > a(n,vector<bool>(10,false)), b(n,vector<bool>(10,false));
    for(int i=0;i<n;i++){
        a[i][s[i]-48] = true;
        b[n-1-i][s[n-1-i]-48] = true;
        if(i){
            for(int j=0;j<10;j++){
                a[i][j] = a[i][j]|a[i-1][j];
                b[n-1-i][j] = b[n-1-i][j]|b[n-i][j];
            }
        }
    }
    vector<bool> c(1000,false);
    for(int i=1;i<n-1;i++){
        for(int j=0;j<10;j++){
            for(int k=0;k<10;k++){
                if(a[i-1][j] && b[i+1][k]){
                    c[j*100 + (s[i]-48)*10 + k] = true;
                }
            }
        }
    }
    int cnt=0;
    for(int i=0;i<1000;i++){
        if(c[i]){
            cnt++;
            //cout<<i<<endl;
        }
    }
    cout << cnt << endl;
    //for(int i=0;i<10;i++)cout<<a[n-1][i];
    return 0;
}

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

int main() {
  ll n,ans=1;
  cin>>n;
  for(int i=1; i<=n; i++){
    ans*=i;
    ans%=1000000007;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  string s;
  cin >> s;

  ll n = s.size();
  bool ok = false;
  if (s == "keyence") {
    ok = true;
    goto ANS;
  }
  repLRE(i, 0, n - 1) repLRE(j, i, n - 1) {
    string test = "";
    if (i > 0) test += s.substr(0, i);
    if (j < n - 1) test += s.substr(j + 1, n - 1 - j);
    if (test == "keyence") {
      //cout << i << " " << j << endl;
      ok = true;
      goto ANS;
    }
  }

ANS:
  string ans = ok ? "YES" : "NO";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N;
    cin >> N;
    vector<int>vec(N);
    vector<int>vec2(N);
    for(int i=0;i<N;i++){
        cin >> vec.at(i);
    }
    for(int i=0;i<N;i++){
        cin >> vec2.at(i);
    }
    int counta =0;
    int countb =0;
    do{
    for(int i=0; i<N; i++){
        }
        counta++;
     } while(next_permutation(vec.begin(),vec.end()));
     do{
    for(int i=0;i<N;i++){
    }
    countb++;}
    while(next_permutation(vec2.begin(),vec2.end()));
    int souryou=1;
    for(int i=N;0<i;i--){
      souryou*=i;
    } 
    int A=abs((souryou+1-counta)-(souryou+1-countb));
    cout << A <<endl;

}

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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int N = 1e5+5;
vector<int> g[N];
bool vis[N];
int dp[N];

void dfs(int u){
    for(int v: g[u]){
        if(!vis[v]){
            vis[v] = 1;
            dfs(v);
        }
        dp[u] = max(dp[u], dp[v]+1);
    }
}

void solve(){
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; ++i) g[i].clear();
    memset(dp, 0, sizeof dp);
    memset(vis, 0, sizeof vis);

    for(int i = 0; i < m; ++i){
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
    }

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

    cout << *max_element(dp+1, dp+n+1) << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


Measured memory_bytes: 12348
#include <stdio.h>
#define M 100000
#define N 50000

int binarySearch(int, int *, int);

int main(){
  int n,q,A[M],B[N],i,j,count=0;

  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(j=0; j<q; j++){
    scanf("%d",&B[j]);
    if(binarySearch(i,A,B[j])==0) count++;
  }
  printf("%d\n",count);
  return 0;
}

int binarySearch(int n, int *A, int key){
  int left, right, mid;
  left=0;
  right=n;
  while(left<right){
    mid = (left+right)/2;
    if(key == A[mid])return 0;
    if(A[mid] < key)left=mid+1;
    else if(key < A[mid])right=mid;
  }
  return 1;
}



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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
const ll MOD = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1);

int main(void)
{
    ll n; cin>>n;
    ll t[n+1],x[n+1],y[n+1];
    t[0]=x[0]=y[0]=0;
    for(int i=1;i<=n;i++){
        cin>>t[i]>>x[i]>>y[i];
    }
    bool can=true;
    rep(i,n){
        ll dist=abs(x[i+1]-x[i])+abs(y[i+1]-y[i]);
        ll dt=abs(t[i+1]-t[i]);
        if(dist%2!=dt%2||dt<dist) can=false;
    }
    if(can) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 5948
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
struct edge{int to,cost;};
vector<int> es[114];
signed main(){
    int n,p;cin>>n>>p;
    int odd=0;
    rep(i,0,n){
        int a;cin>>a;
        if(a%2)odd++;
    }
    if(odd==0&&p==1){
      cout<<0<<endl;
        return 0;
    }
    int sum=1;
    rep(i,0,n){
        sum*=2;
    }
    if(odd==0&&p==0){
        cout<<sum<<endl;
        return 0;
    }
    cout<<sum/2<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <climits> // FOO_MAX, FOO_MIN
#include <cmath> 
#include <cstdlib> // abs(int)
#include <iomanip>

using namespace std;

#define roundup(n,d) ( ((n) + ((d)-1)) / (d) )
#define assign_max(into, compared) (into = max((into), (compared)))
#define assign_min(into, compared) (into = min((into), (compared)))
#define rep(i,n) for(long long i = 0;i < n;i++)
#define fix(n) fixed << setprecision(n)
using ll = long long;
using ull = unsigned long long;
using llv = vector<long long>;


int main(void){
    enum {
        AC=0,
        WA,
        TLE,
        RE,
    };
    ll n;
    cin >> n;
    ll c[4] = {};
    rep(i,n){
        string s;
        cin >> s;
        if(s == "AC"){
            c[AC]++;
        } else if(s == "WA"){
            c[WA]++;
        } else if(s == "TLE"){
            c[TLE]++;
        } else if(s == "RE"){
            c[RE]++;
        }
    }

    cout << "AC x " << c[AC] << endl;
    cout << "WA x " << c[WA] << endl;
    cout << "TLE x " << c[TLE] << endl;
    cout << "RE x " << c[RE] << endl;

    return 0;
}

Measured memory_bytes: 3196
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;

const long long N = 1e3 + 17;
ll a[N], b[N], cnt, ans, lnt, n, m, r1, r0, l1, l0, sum, mx, h, c[N], t[N], mn = N, x, y, k;
pair<ll,ll>pr[N];
vector<ll>v,v2;
map<ll,ll>mp;
bool used[N];
char ch[1005][1005];
ll prime[N] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    string s;
    cin >> s;
    s[3] = '8';
    cout << s;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ljh ioi_aker
#define yxy tourist
#define wlj ugly_and_slow
#define pmh legendary_grandmaster
using namespace std;
#define cs const 
#define int long long
#define low(i) (i&(-i))
#define mid ((l+r)>>1)
#define ls (now<<1)
#define rs (now<<1|1)
#define par pair<int,int>
#define mp make_pair
#define pb push_back
#define fr first 
#define se second
#define cn(x) memset(x, 0, sizeof(x))
#define rep(i, x, y) for(int i=x; i<=y; ++i)
#define drep(i, x, y) for(int i=x; i>=y; --i)
#define fore(i, x) for(int i=fir[x]; i; i=nex[i])
#define dbg cout << "---------------------------------\n"
cs int base = 233;
cs int ff = 2e6+1;
cs int mod = 998244353;
cs int inf = 1e17+1;
int fir[ff], nex[ff], to[ff], tot;
void add(int x, int y)
{
	if( x == y ) return;
	nex[++tot] = fir[x];
	fir[x] = tot;
	to[tot] = y;
}
int n, b[ff], s1, ans;
int cxk(int now, int N = n)
{
	while( N >= now )
	{
	//	cout << N << " " << now << " " << ans << endl;
		if( N % now == 0 ) N /= now;
		else { return N % now == 1 ? 1 : 0; }
	}
	return N % now == 1 ? 1 : 0;
}
void init()
{
	cin >> n;
	rep(i, 2, sqrt(n))
		if( n % i == 0 )
			if( i * i == n ) b[++s1] = i;
			else b[++s1] = i, b[++s1] = n / i;
	b[++s1] = n;
	sort(b+1, b+1+s1);
	rep(i, 1, s1)
		if( cxk(b[i]) ) ans++;
	s1 = 0; n--;
	rep(i, 1, sqrt(n))
		if( n % i == 0 )
			if( i * i == n ) b[++s1] = i;
			else b[++s1] = i, b[++s1] = n / i;
	cout << ans + s1 - 1;
}
signed main()
{
	int T = 1;
//	cin >> T;
	while(T--) 
		init();
} 

Measured memory_bytes: 2432
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    h,w=map(int,input().split())
    if h%3==0 or w%3==0:
        print(0)
        return
    ans=INF
    # hをtrisect, wをbisect
    a=(h//3)*w
    b=(h-h//3)*(w//2)
    c=h*w-a-b
    ans=min(ans,max(a,b,c)-min(a,b,c))
    a=(h//3+1)*w
    b=(h-h//3-1)*(w//2)
    c=h*w-a-b
    ans=min(ans,max(a,b,c)-min(a,b,c))
    # hをbisect, wをtrisect
    a=(w//3)*h
    b=(w-w//3)*(h//2)
    c=h*w-a-b
    ans=min(ans,max(a,b,c)-min(a,b,c))
    a=(w//3+1)*h
    b=(w-w//3-1)*(h//2)
    c=h*w-a-b
    ans=min(ans,max(a,b,c)-min(a,b,c))
    # hをtrisect
    print(min(ans,h,w))
resolve()

Measured memory_bytes: 38384
n = int(input())
info = [list(map(int, input().split())) for i in range(n)]
dp = [[0] * (n+1) for i in range(3)]

for i in range(n):
    dp[0][i+1] = max(dp[1][i], dp[2][i]) + info[i][0]
    dp[1][i+1] = max(dp[2][i], dp[0][i]) + info[i][1]
    dp[2][i+1] = max(dp[0][i], dp[1][i]) + info[i][2]

print(max(dp[0][n], dp[1][n], dp[2][n]))

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

int main(void){

  int m, f, r;

  while(1){
    scanf("%d %d %d", &m, &f, &r);
    if(m+f+r == -3){
      break;
    }
    if(m == -1 || f == -1){
      printf("F\n");
    }else if(m+f > 79){
      printf("A\n");
    }else if(m+f > 64){
      printf("B\n");
    }else if(m+f > 49){
      printf("C\n");
    }else if(m+f > 29){
      if(r > 49){
        printf("C\n");
      }else{
        printf("D\n");
      }
    }else{
      printf("F\n");
    }
  }

  return 0;

}



Measured memory_bytes: 2044
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    h = list(map(int, input().split()))
    for i in range(1, n):
        if h[i] - h[i-1] >= 1:
            h[i] -= 1
        if h[i-1] > h[i]:
            print('No')
            return
    print('Yes')

if __name__ == '__main__':
    main()

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

using namespace std;

#define MAX_SIZE 1000005

int nums[MAX_SIZE];
vector<bool> check(MAX_SIZE, false);

int main() {
  int n;
  scanf("%d", &n);

  memset(nums, 0, sizeof(nums));
  int max_a = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    nums[x]++;
    if (x > max_a) {
      max_a = x;
    }
  }

  // 0 for pair-wise, 1 for set-wise, 2 for not
  int ans = 0;

  for (int pointer = 2; pointer <= max_a;) {
    int count = 0;
    for (int i = pointer; i <= max_a; i += pointer) {
      count += nums[i];
      check[i] = true;
    }
    
    if (count == n) {
      ans = 2;
      break;
    } else if (count > 1){
      ans = 1;
    }

    while(pointer <= max_a && check[pointer]) {
      pointer++;
    }
    
  }

  const char *ans_str[] = {"pairwise coprime", "setwise coprime", "not coprime"};
  printf("%s\n", ans_str[ans]);
  return 0;
}

Measured memory_bytes: 7700
using namespace std;
#include<bits/stdc++.h>
#define int long long
#define pb push_back 
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define repa(i,a,b) for (int i=a; i<=b; i++)
#define repd(i,b,a) for (int i=b; i>=a; i--)
#define endl "\n"
//debugging
#define debug1(a) cout<<#a<<" = "<<(a)<<endl;
#define debug2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<", "<<#d<<" = "<<(d)<<endl;

const int N = 1e+6+5;
int big = 1e+18+3;
int mod = 1e+9+7;

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

    int ans = ((m)*(m-1))/2;

    ans+=((n)*(n-1))/2;

    cout<< ans <<endl;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

#define ff first
#define ss second
#define pb push_back
#define sz size()
#define mp make_pair
#ifndef ONLINE_JUDGE 
#include "/home/asif/Codes/Library/debug.h"
#endif
/*--------------------------------------------------------------------*/

const int N = 1e5 + 5;
const int MOD = 1e9 + 7;

int main() {

  ll n, k;
  cin >> n >> k;
  std::vector<int> v(n), vis(n);

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

  int cycle_len = 0, cycle_st = -1;

  int now = 0;
  while(1){
    vis[now]++;
    if(vis[now] == 2){
      if(cycle_st == -1){
        cycle_st = now;
        if(now == v[now]){
          cout << now + 1 << endl; return 0;
        }
        now = v[now];
        cycle_len++;
      }
      else {
        now = v[now];
        cycle_len++;
      }
      continue;
    }
    if(vis[now] == 3) break;
    k--;
    now = v[now];
    if(k == 0){
      cout << now + 1<< endl; return 0;
    }
  }
  // cout << cycle_st << ' ' << cycle_len << endl;
  k %= cycle_len;
  now = cycle_st;
  while(k--){
    now = v[now];
  }
  cout << now + 1 << endl;

  return 0;
}

Measured memory_bytes: 4760
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>

#define INF 1000000000000000

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pl;

struct rail {
    ll to, a, b;
};

int main() {
    ll n, m, s, t;
    cin >> n >> m >> s >> t;
    vector< vector<rail> > e(n + 1);
    for (ll i = 0; i < m; ++i) {
        ll u, v, a, b;
        cin >> u >> v >> a >> b;
        rail r1 = {v, a, b}, r2 = {u, a, b};
        e.at(u).push_back(r1);
        e.at(v).push_back(r2);
    }

    vector<ll> minA(n + 1, INF);
    minA.at(s) = 0;
    priority_queue< pl, vector<pl>, greater<pl> > qA;
    qA.push(pl(0, s));
    while (!qA.empty()) {
        pl now = qA.top();
        qA.pop();
        ll c = now.first, v = now.second;
        if (minA.at(v) < c) continue;
        for (ll i = 0; i < e.at(v).size(); ++i) {
            rail r = e.at(v).at(i);
            if (minA.at(r.to) > minA.at(v) + r.a) {
                minA.at(r.to) = minA.at(v) + r.a;
                qA.push(pl(minA.at(r.to), r.to));
            }
        }
    }

    vector<ll> minB(n + 1, INF);
    minB.at(t) = 0;
    priority_queue< pl, vector<pl>, greater<pl> > qB;
    qB.push(pl(0, t));
    while (!qB.empty()) {
        pl now = qB.top();
        qB.pop();
        ll c = now.first, v = now.second;
        if (minB.at(v) < c) continue;
        for (ll i = 0; i < e.at(v).size(); ++i) {
            rail r = e.at(v).at(i);
            if (minB.at(r.to) > minB.at(v) + r.b) {
                minB.at(r.to) = minB.at(v) + r.b;
                qB.push(pl(minB.at(r.to), r.to));
            }
        }
    }

    vector<ll> ans(n + 1);
    ans.at(n) = minA.at(n) + minB.at(n);
    for (ll i = n - 1; i > 0; --i) {
        ans.at(i) = min(ans.at(i + 1), minA.at(i) + minB.at(i));
    }
    for (ll i = 1; i <= n; ++i) {
        cout << INF - ans.at(i) << endl;
    }
    return 0;
}


Measured memory_bytes: 14200
N,M = map(int,raw_input().split())
node_list = [0 for l in range(N)]
for i in range(M):
    items = map(int,raw_input().split())
    node_list[items[0]-1]+=1
    node_list[items[1]-1]+=1
flag=True
for i in range(N):
    if node_list[i]%2==1:
        flag=False


if flag:
    print 'YES'
else:
    print 'NO'

Measured memory_bytes: 8572
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>

using namespace std;

int main() {
  double L;
  cin >> L;
//double V,x,y,z;//体積V，横ｘ，縦ｙ，高さｚ
//x = L/3;y = L/3;z = L/3;
//V = x*y*z;//(L/3)^3
double x = L/3;
double ans = pow(x,3);//べき乗計算;
printf("%.10f\n",ans);
 return 0;

}//a*a*a の値が増減し， (a-ε)*(a+ε) のとき a^2-ε^2

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

using namespace std;

int main() {
  int n, t;
  cin >> n >> t;
  int small = 1010;

  while(n--) {
    int c, m;
    cin >> c >> m;
    if(m > t) continue;
    else small = min(small, c);
  }

  if(small != 1010) cout << small << endl;
  else cout << "TLE\n";

  return 0;
}

Measured memory_bytes: 256
main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  if 1 < (abs $ n - m) then print 0
                       else print $ solve n m

modN = 10^9+7

fact :: Int -> Int
fact 0 = 1
fact n = (flip mod modN) . (*n) $ fact (n-1)

solve :: Int -> Int -> Int
solve n m
  | n == m    = (flip mod modN) . (*2) . (flip mod modN) . (*(fact n)) $ fact m
  | otherwise = (flip mod modN) . (*(fact n)) $ fact m


Measured memory_bytes: 3964
#C問題になると、正攻法ではTLEになる気がするが、ダメもとで出してみるか…
#更新してから足しちゃうと、答え変わるから注意。(書きかけの時）
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
beat = []
remain = []
 
for i in range(n+1):
  if i==0:
    if a[i]<=b[i]:
      beat.append(a[i])
      remain.append(0)
      b[i]-=a[i]
    else:
      beat.append(b[i])
      remain.append(a[i]-b[i])
      b[i] = 0
  elif i==n:
    if a[i]<=b[i-1]:
      beat.append(a[i])
      remain.append(0)
      b[i-1]-=a[i]
    else:
      beat.append(b[i-1])
      remain.append(a[i]-b[i-1])
      b[i-1] = 0
  elif a[i]<=b[i-1]:
    b[i-1] -= a[i]
    beat.append(a[i])
    remain.append(0)
  elif a[i] > b[i-1] and a[i]<=b[i]+b[i-1]:
    b[i] -= a[i]-b[i-1]
    b[i-1] = 0
    beat.append(a[i])
    remain.append(0)
  else:
    beat.append(b[i-1]+b[i])
    remain.append(a[i]-b[i-1]-b[i]) 
    b[i]=0
    b[i-1]=0
print(sum(beat))

Measured memory_bytes: 18624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int n, m; cin >> n >> m;
    vector<P> box;
    rep(i,n){
        int a, b; cin >> a >> b;
        box.push_back(P(a,b));
    }
    sort(ALL(box));
    ll ans = 0;
    for(auto elem : box){
        ll money = elem.first;
        int drink = elem.second;
        if(drink <= m){
            ans += money * drink;
            m -= drink;
        }else{
            ans += money * m;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4332
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}

signed main()
{
  string S;
  cin >> S;
  int N = S.size();
  
  if (N == 1)
  {
    cout << "YES" << endl;
    return 0;
  }
  if (N == 2)
  {
    string ans = "NO";
    if (S.at(0) != S.at(1)) ans = "YES";
    cout << ans << endl;
    return 0;
  }

  map<char, int> mp;
  for (int i = 0; i < N; i++)
  {
    mp[S.at(i)]++;
  }
  
  auto itr = mp.begin();
  int a = itr->second;
  itr++;
  int b = itr->second;
  itr++;
  int c = itr->second;
  
  string ans = "NO";
  if (max({a, b, c}) - min({a, b, c}) <= 1) ans = "YES";

  cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,t;
  cin >> n >> t;

  ll ans=inf;
  for(ll i=0;i<n;i++){
    ll a,b;
    cin >> a >> b;
    if(b<=t)ans=min(ans,a);
  }

  if(ans!=inf)cout << ans << endl;
  else cout << "TLE" << endl;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(int i=(a),i##Len_=(b);i<i##Len_;i++)
const char* LF = "\n";
namespace{struct _{_(){
    cin.tie(0);
    ios::sync_with_stdio(false);
}}a;}

signed main() {
    ll N, A,B,C,D,E;
    cin >> N;
    REP(i, 5) cin >> A>>B>>C>>D>>E;
    ll x = min(min(min(min(A,B),C),D),E);
    ll ans = N / x;
    if (N%x>0) ans++;
    ans+=4;
    cout << ans << LF;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(int argc, char *argv[]) {
  int n, a, b;
  std::cin >> n >> a >> b;

  int abcount = 0,fcount = 0;
  for (int i = 1; i <= n; ++i) {
    char c;
    std::cin >> c;
    if (c == 'a')
      if (a + b > abcount) {
        ++abcount;
        std::cout << "Yes" << std::endl;
        continue;
      }
    if (c == 'b') {
      ++fcount;
      if (a + b > abcount && fcount <= b) {
        ++abcount;
        std::cout << "Yes" << std::endl;
        continue;
      }
    }
    std::cout << "No" << std::endl;
  }
}


Measured memory_bytes: 640