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

struct proc{
    string name;
    long int time;
};

int main(){
    int n, q;
    cin >> n >> q;
    queue<proc> procs;
    for(int i=0; i<n; i++){
        proc p;
        cin >> p.name >> p.time;
        procs.push(p);
    }
    
    int time = 0;
    while(!procs.empty()){
        if(procs.front().time > q){
            proc p = procs.front();
            procs.pop();
            p.time -= q;
            procs.push(p);
            time += q;
        }else{
            time += procs.front().time;
            cout <<  procs.front().name << " " << time <<  endl;
            procs.pop();
        }
    }
    
    return 0;
}

Measured memory_bytes: 4404
N,T = map(int,input().split())
A = sorted([list(map(int,input().split())) for _ in range(N)],key=lambda x:x[0])
A.insert(0,[-1,-1])
dp = [[0 for _ in range(T+1)] for _ in range(N)]
for i in range(1,N):
    for j in range(1,T+1):
        dp[i][j] = dp[i-1][j]
        if j>A[i][0]:
            dp[i][j] = max(dp[i][j],dp[i-1][j-A[i][0]]+A[i][1])
dmax = 0
for i in range(1,N+1):
    dmax = max(dmax,dp[i-1][T]+A[i][1])
print(dmax)

Measured memory_bytes: 124248
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>

using ll = long long;
const int inf = 99999999;

using namespace std;

void print2(ll a , ll b){cout << a << " : " << b << endl;}
void print3(ll a , ll b , ll c){cout << a << " : " << b << " : " << c << endl;}

const ll mod = 1e9 + 7;

int main(){
	int r,g,b,n;
	cin >> r >> g >> b >> n;
	ll ans = 0;
	for(int i = 0; i <= n/r + 1; i++){
		for(int j = 0; j <= n/g + 1; j++){
			int k = n - (i*r + j*g);
			if(k%b == 0 && k >= 0)ans++;
		}
	}
	cout << ans << endl;
	return 0;
}
 


Measured memory_bytes: 3592
N=int(input())
A= [int(i) for i in input().split()]
A.insert(0,0)
A.insert(N+1,0)
dist=0
for i in range(N+1):
    dist=dist+abs(A[i]-A[i+1])

for i in range(1,N+1):
    s=dist+abs(A[i-1]-A[i+1])-(abs(A[i-1]-A[i])+abs(A[i]-A[i+1]))
    print(s)


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

int main()
{
    int n,i;
    cin >> n;
    vector<int> b(n);
    vector<int> a;
    for(i = 0;i < n;++i){
        cin >> b.at(i);
    }
    while(n){
        for(i = n-1;i >= 0;--i){
            if(b.at(i) == i+1){
                a.push_back(b.at(i));
                b.erase(b.begin()+i);
                break;
            }
        }
        if(i == -1){
            cout << -1 << endl;
            return 0;
        }else{
            --n;
        }
    }
    reverse(a.begin(),a.end());
    for(int x : a){
        cout << x << endl;
    }
    return 0;
}

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

map<string, vector<string> > m;
set<string> visited;

int rec(string s) {
  visited.insert(s);
  if(m.find(s) == m.end()) return 1;
  int res = 0;
  vector<string> &v = m[s];
  for(int i = 0; i < v.size(); ++i) {
    if(visited.find(v[i]) == visited.end()) {
      res += rec(v[i]);
    }
  }
  return res;
}

int main() {
  int n;
  while((cin >> n) && n) {
    cin.ignore();
    m.clear();
    visited.clear();
    string g0;
    for(int i = 0; i < n; ++i) {
      string line, str, group;
      getline(cin, line);
      int p = 0;
      str = "";
      while(p < line.size()) {
	if(line[p] == ':') {
	  group = str;
	  if(i == 0) g0 = str;
	  str = "";
	} else if(line[p] == ',' || line[p] == '.') {
	  m[group].push_back(str);
	  str = "";
	} else {
	  str += line[p];
	}
	++p;
      }
    }
    cout << rec(g0) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (ll i = 0; i < n; i++)
#define IREP(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i < b + 1; i++)
#define all(v) v.begin(), v.end()
#define SENTINEL 2000000000
#define NIL -1
using namespace std;
typedef long long ll;

const ll MAX = 510000;
const ll INF = 1LL << 60;
const ll MOD = 998244353;
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 n;
    cin >> n;
    vector<ll> a(n);
    ll tmp=0;
    REP(i,n){
        cin >> a[i];
        tmp^=a[i];
    }
    REP(i,n){
        a[i]=tmp^a[i];
        cout << a[i] << endl;
    }
}


Measured memory_bytes: 4816
n,m = list(map(int,input().strip().split()))
h = list(map(int,input().split()))
temp = [1] * n
ans = int(0)
for i in range(m):
    a,b = list(map(int,input().strip().split()))
    if h[a-1] > h[b-1]:
        temp[b-1] *= 0
    elif h[a-1] == h[b-1]:
        temp[a-1] *= 0
        temp[b-1] *= 0
    else:
        temp[a-1] *= 0
ans += temp.count(1)
print(ans)

Measured memory_bytes: 20116
#include <bits/stdc++.h>
#define N 1000005
#define ll long long int 
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define fi first
#define se second
#define ii pair<int,int>
#define lli pair<ll,ll>
#define fast cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
#define fast2 freopen ("myfile.in","r",stdin);freopen ("myfile.out","w",stdout);
using namespace std;

ll n,ar[N],a[N],b[N],c[N],dp[N][5];

ll f(int ind,int k)
{
	if(dp[ind][k])
		return dp[ind][k];
	if(ind>n)
		return dp[ind][k]=0;
	ll t1=0;
	ll t2=0;
	ll t3=0;

	if(k!=1)
		t1=f(ind+1,1)+a[ind];
	if(k!=2)
		t2=f(ind+1,2)+b[ind];
	if(k!=3)
		t3=f(ind+1,3)+c[ind];
	ll mn=max(t1,t2);
	// return mn;
	return dp[ind][k]=max(mn,t3);

}

int main()
{
	fast;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i]>>b[i]>>c[i];
	ll a=f(1,0);
	cout<<a;
}


Measured memory_bytes: 19328
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    while(T --> 0)
    {
        cin>>n>>k;
        a = n%k;
        cout<<min(a,abs(a-k));
    }
    return 0;
}

Measured memory_bytes: 256
x1, y1, x2, y2 = map(int, input().split())

ans = ''

dx = x2 - x1
dy = y2 - y1

ans += 'R'*dx + 'U'*dy + 'R' + 'D'*(dy+1) + 'L'*(dx+1) + 'U'*(dy+1) + 'R'*dx + 'U' + 'L'*(dx+1) + 'D'*(dy+1) + 'R'

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}
int main(){
  
  ll N;
  cin>>N;
  vector<vector<ll>>plan(N,vector<ll>(N-1));
  
  rep(i,N){
    rep(j,N-1){
      ll x;
      cin>>x;
      x--;
      plan[i][j]=x;
    }
  }

  queue<ll>que;
  vector<vector<bool>>first_game(N,vector<bool>(N));
  
  rep(i,N){
    que.push(i);
  }
  vector<ll>ptr(N);
  
  ll cnt_game=0;
  ll day=0;
  
  while(!que.empty()){
    ll num=que.size();
    bool can_decide=false;
    
    rep(i,num){//queueのシステム的にqueueが空になったとき全て試したことになる？
      ll a=que.front();//queの先頭を出力し消す
      que.pop();//que全消去
      if(ptr[a]==N-1){//??　N-1人全て相手をしたので飛ばす
        continue;
      }
      
      ll b=plan[a][ptr[a]];//選手aの中の一番最初の対戦するべき相手？
      
      if(first_game[a][b]||first_game[b][a]){
                ptr.at(a)++;//一人こなした
				ptr.at(b)++;//一人こなした
				que.push(a);//ptr[a]がN-1になるまで再生させる
				que.push(b);//上の同じ
				cnt_game++;
        first_game.at(a).at(b) = first_game.at(b).at(a) = false;//対戦終了
                can_decide = true;
      }
      else {
				first_game.at(a).at(b) = first_game.at(b).at(a) = true;
			}
    }
      if(can_decide){
day++;
      }
    }
  

      if(cnt_game==N*(N-1)/2)cout<<day<<endl;
    else cout<<-1<<endl;
    }

    

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

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

int main()
{
	fast;
	int n;
	cin >> n;
	FOR(n)
	{
		int t;
		cin >> t;
		if (t % 2 == 0 && (t % 3 && t % 5))
		{
			cout << "DENIED";
			return 0;
		}
	}
	cout << "APPROVED";
}

Measured memory_bytes: 3652
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

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

    vector<vector<char>> s;
    s.resize(H+2);
    for(int i=0;i<H+2;i++){
        s[i].resize(W+2);
    }

    for(int i=0;i<H+2;i++){
        s[i][0]='.';
        s[i][W+1]='.';        
    }
    for(int i=0;i<W+2;i++){
        s[0][i]='.';
        s[H+1][i]='.';        
    }
    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            scanf(" %c",&s[i][j]);
        }
    }

    for(int i=1;i<=H;i++){
        for(int j=1;j<=W;j++){
            if(s[i][j]=='#'){
                if(s[i-1][j]=='.' && s[i+1][j]=='.' && s[i][j-1]=='.' && s[i][j+1]=='.'){
                    printf("No\n");
                    return 0;                
                }
            }
        }
    }

    printf("Yes\n");
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args){
      // 入力
      Scanner sc = new Scanner(System.in);
      int X = sc.nextInt();
      int Y = sc.nextInt();
      
      // 判定
      String result = "Yes";
      int allCrane = 2 * X;
      int allTurtle = 4 * X;
      if(Y < allCrane || allTurtle < Y){
        result = "No";
      }else{
        int dif = Y - allCrane;
        if(dif % 2 == 1){
          result = "No";
        }
      }
      
      // 出力
      System.out.println(result);
    }
    

}

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

using namespace std;

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

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

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

ll A[3005];
ll dp[3005][3005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, S;
    cin >> N >> S;
    REP(i, N) {
        cin >> A[i];
    }

    memset(dp, 0, sizeof(dp));
    REP(i, N) {
        dp[i][0] = 1;
    }
    REP(i, N) {
        REP(j, S + 1) {
            dp[i + 1][j] += dp[i][j];
            if (j - A[i] >= 0)
                dp[i + 1][j] += dp[i][j - A[i]];
            dp[i + 1][j] %= MOD;
        }
    }

    ll ans = 0;
    REP(i, N) {
        ans = (ans + dp[i + 1][S]) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 70912
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) {

		Scanner keyboard = new Scanner(System.in);

		int N = keyboard.nextInt();
		//キーがStringで中身がintのHashMapを作る
		HashMap<String, Integer> count = new HashMap<String, Integer>();
		
		for (int s=0; s<N; s++) {
			String S = keyboard.next();
			if (count.containsKey(S)) { //HashMapに既にキーがあるとき
				int now = count.get(S); //キーSに紐づく中身のintを取得
				count.replace(S, now + 1);
			}
			else {
				count.put(S, 1); //まだHashMapにキーが登録されていないなら、登録する
			}
		}
		
		int Max = 0;
		for (int val: count.values()) { 
			if (Max <= val) {
				Max = val;
			}
		}
		
		List<String> print = new ArrayList<String>();
		
		for (String s: count.keySet()) { 
			int now = count.get(s);
			if (now == Max) {
				print.add(s);
			}
		}
		Collections.sort(print);
		
		StringBuilder s = new StringBuilder();
	    for (int i = 0 ; i < print.size() ; i++){
	        String ans = print.get(i);
	        s.append(ans + '\n');
	    }
	    System.out.println(s.toString());
		keyboard.close();
	}
	
}


Measured memory_bytes: 83296
use std::fs;
use std::io::{stdin, Read};

macro_rules! parse {
    ($it: ident) => {
        $it.next().unwrap().parse().unwrap()
    };
    ($it: ident,2) => {
        (parse!($it), parse!($it))
    };
    ($it: ident,3) => {
        (parse!($it), parse!($it), parse!($it))
    };
    ($it: ident,4) => {
        (parse!($it), parse!($it), parse!($it), parse!($it))
    };
    ($it: ident, $n: expr) => {
        (&mut $it).take($n).map(|e| e.parse().unwrap()).collect();
    };
}

fn solve(s: &str) {
    let mut it = s.split_whitespace();
    let n: usize = parse!(it);
    let mut g = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let (a, b): (usize, usize) = parse!(it, 2);
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }
    let dfs = |u: usize| {
        let mut stack = vec![u];
        let mut ret = vec![None; n];
        ret[u] = Some(0);
        while let Some(u) = stack.pop() {
            for &v in g[u].iter() {
                if ret[v] == None {
                    ret[v] = Some(ret[u].unwrap() + 1);
                    stack.push(v)
                }
            }
        }
        ret.into_iter().map(|x| x.unwrap()).collect::<Vec<usize>>()
    };
    let da = dfs(0);
    let db = dfs(n - 1);
    let count = da
        .into_iter()
        .zip(db.into_iter())
        .filter(|&(x, y)| x <= y)
        .count();
    println!("{}", if 2 * count > n { "Fennec" } else { "Snuke" });
}

fn main() {
    let mut s = String::new();
    stdin().read_to_string(&mut s).unwrap();
    solve(&s);
}

#[cfg(test)]
mod tests {
    use super::*;
    #[test]
    fn test_input() {
        let s = "
        ";
        solve(s);
    }
}


Measured memory_bytes: 18684
B = int(input())
N = list(map(int,input().split()))
A = 'APPROVED'
for i in range(len(N)):
  if  N[i] %2 ==0 :
    if N[i] % 3 != 0 and N[i] % 5 != 0:
      A = 'DENIED'
      break
    else:
      continue
print(A)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)
#define ALL(a) (a).begin(),(a).end()

using namespace std;
using ll  = long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 62;
const int INF = 1e9 + 7;


ll func(ll n, ll x){
    if(n == 0)return 1;

    ll len = (1LL<<(n+1)) - 3;
    ll p = (1LL<<n) - 1;

    if(x == 1)return 0;
    else if(x <= len + 1)return func(n-1, x-1);
    else if(x == len + 2)return p + 1;
    else if(x <= 2*len + 2)return p + 1 + func(n-1, x - len - 2);
    else return 2*p + 1;
}

int main(){
    ll n, x;
    cin >> n >> x;

    cout << func(n, x) << endl;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007


int main()
{
   int arr[3];
   for(int i=0;i<3;i++)
      cin>>arr[i];
   sort(arr,arr+3);
   cout<<arr[0] + arr[1]<<endl;

   return 0;
}


Measured memory_bytes: 3680
#include <stdio.h>
int main(){
	int n;
	while(scanf("%d", &n) != EOF)
	{
		int a,b;
		scanf("%d%d", &a, &b);
		int sum = n*a;
		if(sum > b)printf("%d\n",b);
		else printf("%d\n",sum);
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << "\n";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split()))

# O(log min(a, b))
# 最大公約数
# ユークリッドの互除法
def gcd(a, b):  # a >= b
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

ans = A[1]
for i in range(2, N+1):
    ans = gcd(ans, A[i])
print(ans)


Measured memory_bytes: 14228
import java.util.Scanner;


public class Main {


	//final int MOD = 1000000007;


	public static void main(String[] args) {

		long ans = 0;
		Scanner sc = new Scanner(System.in);
		boolean f = false;

		int n = sc.nextInt();
		int m = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < m; i++) {
			a[i]= sc.nextInt();
		}

		//-------------------------------------------------------------------------------------

		for(int i = 0; i < m; i++) {
			ans += a[i];
		}

		if(ans <= n) {
			ans = n - ans;
		} else {
			ans = -1;
		}

		//-------------------------------------------------------------------------------------

//		if(f) {
//			System.out.println("Yes");
//		} else {
//			System.out.println("No");
//		}

		System.out.println(ans);

		sc.close();
	}
}

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

int main() {
  string S;
  cin >> S;
  
  int N = S.size();
  
  int s = 0, t = 0;
  
  for (int i = 0; i < N; i++) {
    if (S[i] == 'S') s++;
    if (S[i] == 'T') {
      if (s > 0) {
        s--;
      } else {
        t++;
      }
    }
  }
  
  cout << s + t << endl;
}

Measured memory_bytes: 3720
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>
#include <tuple>

template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr r, l;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int main() {
  std::string S;
  std::cin >> S;
  if (S == "AAA" || S == "BBB") {
    std::cout << "No\n";
  }
  else {
    std::cout << "Yes\n";
  }
  return 0;
}


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

int main(void){
    int n,m,a,c;
    cin>>n>>m;
    int p[n+3];
    int t[m+3];
    for(int i=0;i<=n+3;i++){
        p[i]=0;
    }
    
    for(int i=1;i<=m;i++){
        cin>>t[i];
    }
    for(int i=1;i<=m;i++){
        c=t[i];
        for(int j=1;j<=n;j++){
            cin>>a;
            if(a==c){
                p[j]+=1;
                
            }
            else{
                p[c]+=1;
            
            }
            
        }
        
        
        
        
    }
    for(int i=1;i<=n;i++){
        cout<<p[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 3036
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
const int INF = 1000000;

int main()
{
    int n; cin >> n;
    vector<int> a;
    
  	rep(i,n) {
      int b;
      cin >> b;
      a.push_back(b);
    }
    int sum = 0;
    rep (i, n-1) {
        for (int j = i + 1; j < n; j++) {
            sum += (a[i] * a[j]);
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long
#define mod 100000007
#define rep(i, n) for (int i = 0; i < n; ++i)
using Graph = vector<vector<int>>;
#define grepq priority_queue<double, std::vector<double>, std::greater<double>>

ll lcm(ll a, ll b)
{
    return a * b / __gcd(a, b);
}
ll INF = 10010001010;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
    int X, Y, Z;
    cin >> X >> Y >> Z;
    X -= Z;
    int ans = X / (Y+Z);
    cout << ans << endl;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);

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()
{
  ll N; cin>>N;
  vector<ll> X(N),L(N); rep(i,N) cin>>X[i]>>L[i];
  
  vector<pair<ll,ll>> vec(N); rep(i,N) vec[i]={X[i]+L[i],X[i]-L[i]};
  sort(vec.begin(),vec.end());
  
  vector<ll> left_list(N),right_list(N); rep(i,N) tie(right_list[i],left_list[i])=vec[i];
  
  ll ans=0,right=-INF;
  rep(i,N){
    if(left_list[i]<right) continue;
    ans++; right=right_list[i];
  }
  
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 8076
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; --i)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; --i)
#define INF 1000000000000
#define MOD 1000000007
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0, a1, a2, a3, a4, x, ...) x
#define debug_1(x1) cout << #x1 << ": " << x1 << endl
#define debug_2(x1, x2) \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << endl
#define debug_3(x1, x2, x3)                                                 \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << endl
#define debug_4(x1, x2, x3, x4)                                             \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << endl
#define debug_5(x1, x2, x3, x4, x5)                                         \
    cout << #x1 << ": " << x1 << ", " #x2 << ": " << x2 << ", " #x3 << ": " \
         << x3 << ", " #x4 << ": " << x4 << ", " #x5 << ": " << x5 << endl
#ifdef _DEBUG
#define debug(...)                                                        \
    CHOOSE((__VA_ARGS__, debug_5, debug_4, debug_3, debug_2, debug_1, ~)) \
    (__VA_ARGS__)
#else
#define debug(...)
#endif

using namespace std;
using ll = long long;

int main() {
    string s;
    cin >> s;
    if (s[1] == 'S') {
        if (s[0] == 'R' || s[2] == 'R')
            cout << 1 << endl;
        else
            cout << 0 << endl;
        return 0;
    } else {
        int cnt = 0;
        rep(i, s.size()) {
            if (s[i] == 'R') cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}

Measured memory_bytes: 3172
#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;
using ll = long long;
using p = pair<int,int>;

int main() {
  int N ,M;
  cin >> N >> M;
  
  vector<vector<int>> ab(M, vector<int>(2));
  rep (i, M)
  {
    cin >> ab.at(i).at(0) >> ab.at(i).at(1); 
  }
  
  vector<int> v;
  rep (i, N)
  {
    v.push_back(i+1);
  }
  
  bool total_flag;
  bool flag;
  int count = 0;
  do {
    if (v.at(0) != 1)
      break;
    total_flag = true;
    for (int i = 0; i < N - 1; i++)
    {
      flag = false;
      rep(j ,M)
      {
        if( ab.at(j).at(0) == v.at(i) && ab.at(j).at(1) == v.at(i+1) )
        {
          //cout << v.at(i) << ' ' << v.at(i+1) << endl;
          flag = true;
          continue;
        }
        else if(ab.at(j).at(1) == v.at(i) && ab.at(j).at(0) == v.at(i+1))
        {
          //cout << v.at(i) << ' ' << v.at(i+1) << endl;
          flag = true;
          continue;
        }
      }
      if (flag == false)
      {
        total_flag = false;
      }
    }
    if (total_flag == true)
    {
      count++;
    }
  } while (next_permutation(v.begin(), v.end()));
  cout << count << endl;
  
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  string S;
  cin >> S;
  bool j1 = true, j2 = false, j3 = true, j4 = false;
  int cp = 0;
  for (int i = 0; i < S.length(); ++i) {
    if (i == 0 && S[i] != 'A') j1 = false;
    if (2 <= i && i <= S.length() - 2 && S[i] == 'C') {
      if (j4 == false)
        j2 = true, j4 = true, cp = i;
      else
        j2 = false;
    }
    if (i != 0 && i != cp && 'A' <= S[i] && S[i] <= 'Z') j3 = false;
  }
  if (j1 && j2 && j3)
    printf("%s\n", "AC");
  else
    printf("%s\n", "WA");
}

Measured memory_bytes: 3628
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<string>
#include<stdexcept>
#include<stdio.h>
#include<queue>
#include <cmath>
//for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<n;i++) cin >> x[i];
#define pi pair<int,int> 
using namespace std;

int main(){
    string s; cin >> s;
    int ans=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='o') ans++;
    }
int q=ans+15-s.size();
if(q>=8) cout << "YES";
else cout << "NO";
return 0;
}



Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

plus = []
minus = []
for i in range(N):
    tmp = A[i] - B[i]
    if tmp > 0:
        plus.append(tmp)
    elif tmp < 0:
        minus.append(tmp)
        
plus = sorted(plus, reverse=True)

plus_cum = []
for i in range(len(plus)):
    if i == 0:
        plus_cum.append(plus[0])
    else:
        plus_cum.append(plus_cum[i-1] + plus[i])
        
minus_sum = sum(minus)
ans = -1
for i in range(len(plus_cum)):
    if plus_cum[i] >= -minus_sum:
        ans = i+1
        break

if len(minus) == 0:
    print(0)
elif ans == -1:
    print(ans)
else:
    print(ans + len(minus))

Measured memory_bytes: 24432
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v).begin(), (v).end()
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define DEBUG
#define int long long
#define INF 1e18
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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<"\n";}
typedef long long ll;

signed main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<set<int>>v(26);
    for (int i = 0; i < 26; i++)
    {
        v[i].insert(-INF);
        v[i].insert(INF);
    }
    
    for (int i = 0; i < n; i++)
    {
        int x = s[i]-'a';
        v[x].insert(i);
    }
    int q;
    cin>>q;
    while(q--){
        int a;
        cin>>a;
        if(a==1){
            int x;
            char c;
            cin>>x>>c,x--;
            v[s[x] - 'a'].erase(x);
            v[c-'a'].insert(x);
            s[x]=c;
        }
        else{
            int l,r;
            cin>>l>>r;
            l--,r--;
            int cnt=0;
            for (int i = 0; i < 26; i++)
            {
                int x=*v[i].lower_bound(l);
                //if(i==3)cerr<<x<<endl;
                if(x<=r) {
                    cnt++;
                    //cerr<<(char)('a'+i)<<" ";
                }
                
            }
            cout<<cnt<<endl;
        }
    }
  //  show(v);
    
    
    return 0;
}

Measured memory_bytes: 26244
#include <stdio.h>

int main() {
	int n;
	
	scanf("%d", &n);
	
	long long int in[n], max = 1e18, drop = 1, point = 0, oh = 0;
	
	for(int J = 0; J < n; J++) {
		scanf("%lld", &in[J]);
		point = (in[J] > max) ? 1 : point;
		drop *= in[J];
		(in[J]) ? max /= in[J] : oh = 1;
		
	}
	
	(oh) ? puts("0") : ((point) ? puts("-1") : printf("%lld", drop));
		
	return 0;
}

Measured memory_bytes: 2504
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  if(s=="SUN") cout<<7<<endl;
  else if(s=="MON") cout<<6<<endl;
  else if(s=="TUE") cout<<5<<endl;
  else if(s=="WED") cout<<4<<endl;
  else if(s=="THU") cout<<3<<endl;
  else if(s=="FRI") cout<<2<<endl;
  else if(s=="SAT") cout<<1<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
    int N ,K;
    cin >> N >> K;
    int l;
    vector<int> L(N);
    for(int i=0;i<N;i++){
        cin >> l ;
        L.at(i) = l;
    }
    sort(L.begin(), L.end());
    reverse(L.begin(), L.end());
    int max_lengh=0;
    for(int i=0;i<K;i++){
        max_lengh = max_lengh + L.at(i) ;
    }
    cout << max_lengh << endl;
}

Measured memory_bytes: 3632
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <climits>
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>

#define DIV 1000000007

using namespace std;

long long N;
string S, T;


bool check(int rap){
	return (S.substr(S.size() - rap)  == T.substr(0, rap));
}



int main(){
	cin >> N >> S >> T;
	S = S.substr(0, N);
	T = T.substr(0, N);

	for(int i = N; i >= 0; i--){
		if(check(i)){
			cout << 2 * N - i << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<ll,ll>
#define PP pair<P,P>
using namespace std;

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int ans=0;
 for(;;){
        int times=0;
        bool alzo=true;
        bool ze=false;
        rep(i,n){
            if(h[i]<=0 && ze==true){
                ze=false;
                continue;
            }
            if(ze==false && h[i]>0){
                times++;
                ze=true;
                alzo=false;
            }
            h[i]--;
        }
    if(alzo==true){
        cout << ans << endl;
        return 0;
    }
    ans+=times;
}
}


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

int main()
{
    int n; cin>>n;
    vector<long> a(n); for(auto& e: a) cin>>e;
    vector<long> b(n); for(auto& e: b) cin>>e;

    long sa=0, sb=0, d=0;
    for(int i=0; i<n; ++i) {
        if (a[i]<b[i]) d+=(b[i]-a[i]+1)/2;
        sa+=a[i];
        sb+=b[i];
    }
    cout<<(d<=sb-sa ? "Yes" : "No")<<endl;
}


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

int main() {

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

  int n, k, q;
  cin >> n >> k >> q;

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

  int ans = INT_MAX;
  for (int i = 0; i < n; ++i) {
    int x = a[i];
    multiset<int> s;
    vector<int> sm;

    for(int j = 0; j < n; ++j) {
      if (a[j] < x) {
        while ((int)s.size() >= k) {
          sm.push_back(*s.begin());
          s.erase(s.begin());
        }
        s.clear();
      } else {
        s.insert(a[j]);
      }
    }
    while ((int)s.size() >= k) {
      sm.push_back(*s.begin());
      s.erase(s.begin());
    }
    s.clear();
    sort(sm.begin(), sm.end());

    if ((int)sm.size() >= q) {
      ans = min(ans, sm[q-1] - sm[0]);
    }
  }

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

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 5;
int a[N];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int c, n, maxn = 0;
	cin >> c >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (i > 0) {
			int t = a[i] - a[i - 1];
			maxn = max(maxn, t);
		}
	}
	maxn = max(maxn, c - a[n - 1] + a[0]);
	cout << c - maxn << endl;
	return 0;
}

Measured memory_bytes: 1152
#include<stdio.h>
int main() {
 
	long long int n, k;
	scanf("%lld", &n);
	scanf("%lld", &k);
 
	long long int a[200000];
	for (long long int i = 0;i < n;i++)
	{
		scanf("%lld", &a[i]);
	}
	for (long long int j = 0;j < n - k;j++)
	{
		if (a[k + j] > a[j])
		{
			printf("Yes\n");
		}
		else
			printf("No\n");
	}
 
	return 0;
}

Measured memory_bytes: 3176
/*
 * Since g++10 is released, some characters is not valid inside #if 0 :(
 * So, why not using clang++? :D

 * Date:
  echo -n '  ' && date +%Y.%m.%d # Just Run this (Type !!sh in Vim).

 * Solution:
  To be updated after "Accept".

 * Digression:

 * CopyRight:
          ▁▃▄▄▄▃▃▃▃▄▶
        ▗▇▀▔    ▔▔▔▔
       ▄▛   ▃▅━━■▄▂
      ▟▊   ▐▘     ▀▙
     ▟▜▌   ▐▖   ▋  ▐▍
    ▟▘ ▜   ▝▀▇▆●▘  ▐▌
  ▗▟▘   ▜▃       ▁▅▛
  ▔▀▼▅▄▃▃██▅▄▄▄▅■▀▔
        ▔▔▔▔▔▔
 */

#include <cstdio>
#include <cstring>
#include <algorithm>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

const int maxn = 1000005;
char s[maxn];
int pre[maxn];
int smax[maxn];

int f (int n, int lim) {
	int add = 0, p = 0, res = 0;
	for (int i = 1; i <= n; i ++) {
		p += (s[i] == '1' ? 1 : -1);
		if (s[i] == '?' and add + smax[i] + 2 <= lim)
			add += 2, p += 2;
		res = std::min(res, p);
	}
	return res;
}

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

	int max = 0;
	for (int i = 1; i <= n; i ++) {
		pre[i] = pre[i - 1] + (s[i] == '1' ? 1 : -1);
		max = std::max(max, pre[i]);
	}

	smax[n] = pre[n];
	for (int i = n; i; i --)
		smax[i - 1] = std::max(smax[i], pre[i - 1]);

	printf("%d\n", std::min(max - f(n, max), max + 1 - f(n, max + 1)));
}


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

#define mod 1000000007
#define INF (ll)9999999999999999

#define add emplace
#define pb emplace_back
#define eb emplace_back
#define all(x) begin(x), end(x)
#define len(x) ((int)(x).size())
#define exist(a, x) (a.find(x) != end(a))
#define log(x) cout << (x) << endl
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define rrep(i,a,b) for (int i = (int)a; i >= (int)b; --i)
#define loop(i,a,b) for(int i = (int)(a); i < (int)(b); ++i)

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int,int>;
using vpi = vector<pi>;
using vstr = vector<string>;


const int N = 500000;
int fe[N]={0}, fw[N]={0};

#define rcnt(a,l,r) (a[r] - (l>0 ? a[l-1]:0))

int main() {
	int n;
	string s;
	cin >> n >> s;

	rep (i, n) {
		fw[i] = (s[i]=='W') + (i>0?fw[i-1]:0);
		fe[i] = (s[i]=='E') + (i>0?fe[i-1]:0);
	}

	int mn = min(rcnt(fe,1,n-1), rcnt(fw,0,n-2));

	loop (i, 1, n-1)
		mn = min(mn, rcnt(fw,0,i-1) + rcnt(fe,i+1,n-1));

	log(mn);

	return 0;
}





Measured memory_bytes: 3076
n, m = map(int, input().split())
x = sorted(map(int, input().split()))
if n >= m:
  print(0)
else:
  d = [x[i + 1] - x[i] for i in range(m - 1)]
  s = sorted(d, reverse=True)[:n - 1]
  i = [0] + [d.index(si) + 1 for si in s] + [0]
  ans = 0
  for k in range(n):
    ans += x[i[k + 1] - 1] - x[i[k]]
  print(ans)

Measured memory_bytes: 13968
import numpy as np

def parse():
  H, W = map(int, input().split(" "))
  grid = [list(input()) for y in range(H)]
  return H, W, grid

def print_grid(grid):
  H = len(grid)
  print("grid:")
  for line in grid:
    for c in line:
      print(c, end="")
    print("")

def main():
  H, W, grid = parse()
  # print(H, W)
  # print_grid(grid)

  # visited = [[W * H if grid[y][x] == "." else 0 for x in range(W)] for y in range(H)]
  visited = np.zeros((H, W), int)
  for y in range(H):
    # visited.append([])
    for x in range(W):
      if grid[y][x] == ".":
        visited[y][x] = H * W

  for y in range(1, H):  # ↓
    # 要素ごとの処理
    # print(visited)
    visited[y][:] = np.minimum(visited[y][:], visited[y - 1][:] + 1)
    # print(visited)
    # input()
    # print(visited[y])
    # exit(0)

  for y in range(H - 2, -1, -1):
    visited[y, :] = np.minimum(visited[y, :], visited[y + 1][:] + 1)

  for x in range(1, W):
    visited[:, x] = np.minimum(visited[:, x], visited[:, x - 1] + 1)

  for x in range(W - 2, -1, -1):
    visited[:, x] = np.minimum(visited[:, x], visited[:, x + 1] + 1)

  # print(visited)
  # exit(0)

  # max_len = 0
  # for y in range(H):
  #   max_val = max(visited[y])
  #   max_len = max_len if max_len > max_val else max_val
  # print(max_len)
  print(np.max(visited))

if __name__ == "__main__":
  main()

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

    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var an = Console.ReadLine().Split().Select(long.Parse).ToArray();
            var minusnum = an.Count(e => e < 0);
            var abssum = an.Select(e => Math.Abs(e)).Sum();
            if(minusnum%2!=0)
            {
                var absmin = an.Min(e => Math.Abs(e));
                abssum -= 2 * absmin;
            }
            Console.WriteLine(abssum);

        }
    }


Measured memory_bytes: 29148
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define mod 1000000007
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){
    int c=max(a,b)-min(a,b);
    return c;
}
int gcd(int a,int b){//最大公約数
    int c=a%b;
    while(true){
	if(c==0) break;
	a=b;
	b=c;
	c=a%b;
    }
    return b;
}
bool IsPrime(int num){
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
    double sqrtNum = sqrt(num);
    for(int i=3;i<=sqrtNum;i+=2){
	if(num%i==0){
	    return false;
	}
    }
}
int lcm(int a,int b){//最小公倍数
    return (a*b)/gcd(a,b);
}	
signed main(){
// __builtin_ctz(N); Nを２で何回割り切れるかを返す
//(n+1)*n/2; １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,d,f=2;
    vector<pair<int,pair<int,int> > > id;
    cin>>a>>b;
    for(int i=0;i<b;i++){
	cin>>c>>d;
	id.push_back(make_pair(c,make_pair(d,i)));
    }
    sort(id.begin(),id.end());
    id[0].se.fi=1;
    swap(id[0].fi,id[0].se.se);
    swap(id[0].se.fi,id[0].se.se);
    for(int i=1;i<b;i++){
	if(id[i-1].se.fi!=id[i].fi){
	    f=1;
	}	
	id[i].se.fi=f;
	f++;
	swap(id[i].fi,id[i].se.se);
	swap(id[i].se.fi,id[i].se.se);
    }
    sort(id.begin(),id.end());
    for(int i=0;i<b;i++){
	if(id[i].se.fi<10) cout<<"0";
	if(id[i].se.fi<100) cout<<"0";
	if(id[i].se.fi<1000) cout<<"0";
	if(id[i].se.fi<10000) cout<<"0";
	if(id[i].se.fi<100000) cout<<"0";	
	cout<<id[i].se.fi;
	if(id[i].se.se<10) cout<<"0";
	if(id[i].se.se<100) cout<<"0";
	if(id[i].se.se<1000) cout<<"0";
	if(id[i].se.se<10000) cout<<"0";
	if(id[i].se.se<100000) cout<<"0";
	cout<<id[i].se.se<<"\n";
    }    
}


Measured memory_bytes: 4980
// B - Theater
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int L = 0, R = N;
	rp(i, 0, N){
		int l,r; cin>>l>>r;
		L += l; R += r;
	}
	cout<< R-L <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int mod =1e9+7;
const int N = (int)2e5 + 5;

void solve(){
      int a,b,c,d;
      cin>>a>>b>>c>>d;
      for(int i=0;;i++){
      	if(i%2==0)c-=b;
      	else a-=d;
      	if(a<=0){
      		cout<<"No";
      		return;
      	}
      	if(c<=0){
      		cout<<"Yes";
      		return;
      	}
      }
}

int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 3652
x,y=map(int, input().split())
group_a=[1,3,5,7,8,10,12]
group_b=[4,6,9,11]
group_c=[2]

if x in group_a and y in group_a:
  print("Yes")
elif x in group_b and y in group_b:
  print("Yes")
elif x in group_c and y in group_c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9136
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

prime = 998244353
root = 3
def _fmt(A, inverse = False):
    N = len(A)
    logN = (N - 1).bit_length()
    base = pow(root, (prime - 1) // N * (1 - 2 * inverse) % (prime - 1), prime)
    step = N
    for k in range(logN):
        step >>= 1
        w = pow(base, step, prime)
        wj = 1
        nA = [0] * N
        for j in range(1 << k):
            for i in range(1 << logN - k - 1):
                s, t = i + j * step, i + j * step + (N >> 1)
                ps, pt = i + j * step * 2, i + j * step * 2 + step
                nA[s], nA[t] = (A[ps] + A[pt] * wj) % prime, (A[ps] - A[pt] * wj) % prime
            wj = (wj * w) % prime
        A = nA
    return A

def convolution(f, g):
    N = 1 << (len(f) + len(g) - 2).bit_length()
    Ff, Fg = _fmt(f + [0] * (N - len(f))), _fmt(g + [0] * (N - len(g)))
    N_inv = pow(N, prime - 2, prime)
    fg = _fmt([a * b % prime * N_inv % prime for a, b in zip(Ff, Fg)], inverse = True)
    del fg[len(f) + len(g) - 1:]
    return fg

P = 200_003
logN = (2 * P - 1).bit_length()
N = 1 << logN
r = 2
exp = [1] * (P - 1)
log = [0] * P

e = 1
for i in range(1, P - 1):
    e *= r
    e %= P
    exp[i] = e
    log[e] = i

def resolve():
    n = int(input())
    A = list(map(int, input().split()))
    B = [0] * P
    for a in A:
        if a == 0:
            continue
        B[log[a]] += 1
    C = [0] * P
    Bh = [b >> 9 for b in B]
    Bl = [b & 511 for b in B]
    for i, b in enumerate(convolution(Bh, Bh)):
        C[exp[i % (P - 1)]] += b << 18
    for i, b in enumerate(convolution(Bh, Bl)):
        C[exp[i % (P - 1)]] += b << 10
    for i, b in enumerate(convolution(Bl, Bl)):
        C[exp[i % (P - 1)]] += b
    for a in A:
        C[(a * a) % P] -= 1
    ans = 0
    for i in range(1, P):
        ans += i * C[i] // 2
    print(ans)
resolve()

Measured memory_bytes: 243724
s=input()
n=int(input())
str=[""]*(n*2+1)
str[n]=s
start=n-1
end=n+1
dir=1


for _ in range(n):
    h=input()
    if h[0]=="1":
        if end-start!=2:
            dir*=-1
    else:
        if h[2]=="1":
            if dir==1:
                str[start]=h[4]
                start-=1
            else:
                str[end]=h[4]
                end+=1
        else:
            if dir==1:
                str[end]=h[4]
                end+=1
            else:
                str[start]=h[4]
                start-=1
if dir==-1:
    str.reverse()
    str[n]="".join(list(reversed(str[n])))
print("".join(str))


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    vector<pair<int,int>>t(5);

    int max=0,sum=0;
    rep(i,5){
        int a;cin>>a;
        if(a%10!=0){
            sum+=a+(10-a%10);
            if(10-a%10>max){
                max=10-a%10;
            }
        }
        else {
            sum+=a;
        }
    }
    cout<<sum-max<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define vout(x) rep(i,x.size()) cout << x[i] << " "
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
template<class T> bool chmax(T &a, T b) {if(a<b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const int inf = 1e9;
const ll inf_l = 1e18;
const int MAX = 1e5;

int main() {
    ll x; cin >> x;
    vll fact;
    for (int i = 1; i * i <= x; i++) {
        if (x % i == 0) {
            fact.push_back(i);
            fact.push_back(x/i);
        }
    }
    rep(j,fact.size()) {
        for (int i = 1e5; i > -1e5; i--) {
            if (pow(i+fact[j],5)-pow(i,5) == x) {
                cout << pow(pow(i,5)+x,0.2) << " " << i << endl;
                return 0;
            }
        }
    }
}

Measured memory_bytes: 4392
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>
#include <boost/range/adaptors.hpp>

using namespace std;
using namespace boost;
using namespace boost::adaptors;
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long int;

int main() {
    string a, b;
    cin >> a >> b;
    if (a.size() > b.size())cout << "GREATER"; else if (a.size() < b.size()) cout << "LESS";
    else {
        for (auto &&i: irange(0LL, (ll)a.size())){
            if (a.at(i)>b.at(i)){cout << "GREATER";return 0;} else if (a.at(i) < b.at(i)) {cout << "LESS"; return 0;}
        }
        cout << "EQUAL" << endl;
    }
    return 0;
}


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

#define each(i, c) for (auto& i : c)
#define mkp(a, b) make_pair(a, b)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9+7;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << ": " << p.second << ")"; return os; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ", "; os << ")"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; each (i, m) os << i << ", "; os << "}"; return os; }

int main() {
  ll n;
  cin >> n;

  for (ll a = 1; a <= 3500; ++a) {
    for (ll b = 1; b <= 3500; ++b) {
      if (4*a*b-n*b-n*a == 0) continue;
      ll c = (n*a*b)/(4*a*b-n*b-n*a);
      if (c > 0 && (n*a*b)%(4*a*b-n*b-n*a) == 0) {
        cout << a << " " << b << " " << c << endl;
        return 0;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 3604