akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define endl '\n'
using namespace std;


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

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;

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

	ll a,b,h;
	cin >> a >> b >> h;

	cout << (a + b)*h/2 << endl;

	return 0;
}


Measured memory_bytes: 3620
import java.util.Arrays;
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();

    int[][] proof = new int[n][n];
    int[][] proofcp = new int[n][n];
    int[] honest = new int[n];
    int res = 0;
    boolean acc;

    for (int i = 0; i < n; i++) {

      int a = sc.nextInt();

      for (int j = 0; j < a; j++) {

        int man = sc.nextInt() - 1;
        int tmp = sc.nextInt();

        switch (tmp) {
        case 1:
          proof[i][man] = 1;
          break;

        case 0:
          proof[i][man] = -1;
          break;
        }

      }
    }

    for (int bit = 0; bit < Math.pow(2, n); bit++) {
      Arrays.fill(honest, 0);
      acc = true;
      int cnt = 0;

      for (int i = 0; i < n; i++) {
        if ((1 & (bit >> i)) == 1) { // i が bit に入るかどうか
          honest[i] = 1;
          cnt++;
        } else {
          honest[i] = -1;
        }
      }

      for (int i = 0; i < n; i++) {
        if (honest[i] == 1) {
          for (int j = 0; j < n; j++) {
            if ((proof[i][j] != 0) && (proof[i][j] != honest[j])) {
              acc = false;
              break;
            }
          }
          if (!acc) {
            break;
          }
        }
      }

      if ((acc) && (res < cnt)) {
        res = cnt;
      }
    }

    System.out.println(res);

  }

}

Measured memory_bytes: 23252
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b,t = LI()
    k = t//a
    print(k*b)
    return

#B
def B():
    n = I()
    v = LI()
    c = LI()
    ans = 0
    for i in range(n):
        if v[i] > c[i]:
            ans += (v[i]-c[i])
    print(ans)
    return

#C
def C():
    n = I()
    return

#D
def D():
    n = I()
    return


#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 39152
N, M = map(int, input().split())
S = [[0 for _ in range(N)] for _ in range(M)]

for i in range(M):
    li = list(map(int, input().split()))
    ki = li[0]
    for sij in li[1:]:
        S[i][sij - 1] = 1
P = list(map(int, input().split()))

# print(S)

states = [0 for _ in range(N)]

def dfs(j, jon, states):
    if j == N:
        return 1 if isok(states) else 0
    states[j] = 1 if jon else 0
    count = 0
    count += dfs(j + 1, True, states)
    count += dfs(j + 1, False, states)
    return count

def isok(states):
    for i in range(M):
        x = 0
        for j in range(N):
            x += states[j] if S[i][j] == 1 else 0
        if x % 2 != P[i]:
            return False
    return True

ans = dfs(0, True, states) + dfs(0, False, states)
print(ans // 2)

Measured memory_bytes: 3064
/*
 * AOJ0505_mizo0203.cpp
 *
 *  Created on: 2011/07/14
 *      Author: satoki
 */
#include <iostream>
#include <algorithm>
using namespace std;

int iN;
int iM;
int iS[1000][100];

int iOut[100];
int iOutD[100];

bool input() {
  int i, j;

  scanf("%d %d", &iN, &iM);
  if (iN == 0 && iM == 0) return false;
  for (i = 0; i < iN; i++) {
    for (j = 0; j < iM; j++) {
      scanf("%d", &iS[i][j]);
    }
  }

  return true;
}

void output() {
  int j;

  printf("%d", iOut[0]);
    for (j = 1; j < iM; j++) {
      printf(" %d", iOut[j]);
    }
    printf("\n");

}

void manage() {
  int i, j, tmp;

  for (j = 0; j < iM; j++) {
    iOut[j] = j + 1;
  }
  fill(iOutD, iOutD + iM, 0);

  for (i = 0; i < iN; i++) {
    for (j = 0; j < iM; j++) {
      if (iS[i][j]) {
        iOutD[j]++;
      }
    }
  }

  for (i = 0; i < iM - 1; i++) {
    for (j = iM - 1; j > i; j--) {
      if (iOutD[j - 1] < iOutD[j]) {
        tmp = iOutD[j - 1];
        iOutD[j - 1] = iOutD[j];
        iOutD[j] = tmp;
        tmp = iOut[j - 1];
        iOut[j - 1] = iOut[j];
        iOut[j] = tmp;
      }
    }
  }

}

int main() {
  while (true) {
    if (!input()) break;
    manage();
    output();
  }

  return 0;
}

Measured memory_bytes: 1272
package main

import "fmt"

func main() {
	var n int
	fmt.Scan(&n)
	a := make([]int, n)
	for i := range a {
		fmt.Scan(&a[i])
	}
	printIntArray(a, " ")

	for i := 1; i < n; i++ {
		for j := i - 1; j >= 0; j-- {
			if a[j] > a[j+1] {
				a[j], a[j+1] = a[j+1], a[j]
			} else {
				break
			}
		}
		printIntArray(a, " ")
	}
}

func printIntArray(n []int, d string) {
	for _, i := range n[:len(n)-1] {
		fmt.Print(i, d)
	}
	fmt.Println(n[len(n)-1])
}

Measured memory_bytes: 1376
#include <iostream>
#include <vector>
#include <bits/stdc++.h> 

using namespace std;
int main(){
 vector<int> a(4, 0); 
 int t;
 cin>>t;
 for(int i=0;i<t;i++){
   string s;
   cin >> s;
   if(s == "AC")
     a[0]++;
   else if(s =="WA")
     a[1]++;
   else if(s == "TLE")
     a[2]++;
   else
     a[3]++;
 }
 cout<<"AC x " << a[0]<<endl;
 cout<<"WA x " << a[1]<<endl;
 cout<<"TLE x " << a[2]<<endl;
 cout<<"RE x " << a[3];
}

Measured memory_bytes: 3628
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

#define LL long long

const int maxn = 1e6 + 7;

int main() {
    string S,T;
    while(cin >> S >> T) {
        cout << T << S << endl;
    }
    return 0;
}


Measured memory_bytes: 256
//code by lynmisakura.wish to be accepted!
/****************************/
#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>
#include<algorithm>
#include<bitset>
#include <climits>
#include<set>
#include<bitset>
using namespace std;
/***************************/
typedef long long ll;
typedef long long ijt;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int, int> pi;
typedef vector<pair<int, int>> vpi;

const long long INF = 1LL << 55;

#define itn int
#define endl '\n'
#define pb push_back
#define mp make_pair
#define ss second
#define ff first
#define dup(x,y) ((x) + (y) - 1)/(y)
#define mins(x,y) x = min(x,y)
#define maxs(x,y) x = max(x,y)
#define all(x) (x).begin(),(x).end()
#define Rep(n) for(int i = 0;i < n;i++)
#define rep(i,n) for(int i = 0;i < n;i++)
#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll qp(ll a, ll b) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a; a = 1ll * a*a; } while (b >>= 1); return ans; }
ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1)ans = 1ll * ans*a%mo; a = 1ll * a*a%mo; } while (b >>= 1); return ans; }

#define _GLIBCXX_DEBUG
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

int main(void) {
	ijt n; cin >> n;
	map<ijt, ijt> m;
	rep(i, n) {
		ijt x; cin >> x;
		m[x]++;
	}
	vector<pair<ijt, ijt>> p;
	for (auto i : m) {
		p.pb(mp(i.ss, i.ff));
	}
	sort(all(p));
	reverse(all(p));
	for (int i = 0; i < p.size(); i++) {
		if (p[i].first >= 3) {
			if (p[i].first % 2 == 0)p[i].first = 2;
			else {
				p[i].first = 1;
			}
		}
		
	}
	sort(all(p));
	reverse(all(p));
	//for(auto i : p) cout << i.ss << " " << i.ff << endl;
	for (int i = 0; i < p.size()-1; i++) {
		if (p[i].ff == 2) {
			p[i].ff--;
			p[i + 1].ff--;
		}
	}
	
	ijt ans = 0;
	for (auto i : p) {
		//cout << i.ss << " " << i.ff << endl;
		ans += i.ff;
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 8696
require 'set'; require 'prime'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i

def dsum(n)
  n.to_s.split(//).map(&:to_i).inject(&:+)
end

ans = INF
1.upto(n/2+1).each do |x|
  y = n - x
  sum = dsum(y) + dsum(x)
  ans = sum if ans > sum
end

puts ans


Measured memory_bytes: 2940
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
    vector<int> vs(3);
    for (auto& v : vs)
    {
        cin >> v;
    }
    sort(vs.begin(), vs.end());

    cout << (vs[0] * vs[1] / 2) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <map>
#include <set>
#include <sstream>
#include <stdio.h>
#include <cstdio>
#include <cstring>
#include <math.h>

using namespace std;

#define Rep(i,a,b) for(int i = a; i < b; i++)
#define rep(i,b) Rep(i,0,b)
#define rrep(i,a) for(int i = a; i >= 0; i--)
#define allof(a) (a).begin(), (a).end()

typedef long long ll;
const int inf = 1e9 + 7;
const ll infll = 1ll << 60ll;
const ll mod = 1e9 + 7;
// 0~3までは右左下上 4~7までは斜め
constexpr int dx[] = { 1, 0, -1, 0, 1, 1, -1, -1 };
constexpr int dy[] = { 0, -1, 0, 1, 1, -1, -1, 1 };

/*
// 最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

// 最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}*/

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

	int a, b, c;
	cin >> a >> b >> c;

	if (a == b && a == c && b == c) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string st, t;
  cin >> st >> t;
  int slen = st.length();
  int tlen = t.length();
  string ans(50, 'z'), ansb(50, 'z');
  for(int i = 0; i <= slen - tlen; i++) {
    string s = st;
    bool fla = true;
    for (int j = 0; j < tlen && fla; j++) {
      if (s[i + j] == t[j]) {
        fla = true;
      }
      else if (s[i + j] != '?' && s[i + j] != t[j]) fla = false;
      else if (s[i + j] == '?') {
        fla = true;
        s[i + j] = t[j];
      }
    }
    if (fla) {
      rep(k, slen) {
        if (s[k] == '?') s[k] = 'a';
      }
      ans = min(ans, s);
    }
  }
  if(ans != ansb) cout << ans << endl;
  else cout << "UNRESTORABLE" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int n;//カードの枚数
    int carda,cardb;//AとBのカード
    int scorea,scoreb;//AとBのスコア
    int i;
    
    scanf("%d",&n);
    while(n!=0){
        scorea=0;
        scoreb=0;
        
        for(i=0;i<n;i++){
            scanf("%d %d",&carda,&cardb);
            
            if(carda>cardb){
                scorea=scorea+carda+cardb;
            }else if(cardb>carda){
                scoreb=scoreb+carda+cardb;
            }else if(carda==cardb){
                scorea=scorea+carda;
                scoreb=scoreb+cardb;
            }
        }
        
        printf("%d %d\n",scorea,scoreb);
        
        scanf("%d",&n);
    }
    
    return 0;
}

Measured memory_bytes: 600
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int[] C = new int[N-1];
    int[] S = new int[N-1];
    int[] F = new int[N-1];
    int[] ans = new int[N];
    for(int i=0;i<N-1;i++){
      C[i] = sc.nextInt();
      S[i] = sc.nextInt();
      F[i] = sc.nextInt();
    }
    for(int i=0;i<N;i++){
      int time=0;
      for(int j=i;j<N-1;j++){
        if(time<S[j]){
          time=S[j]+C[j];
        }else if(time%F[j]==0){
          time+=C[j];
        }else{
          time=time+F[j]-(time%F[j])+C[j];
        }
      }
      System.out.println(time);
    }
  }
}

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

int main(){
  int N;
  cin >> N;
  vector<int> X(N);
  for(int i=0; i<N; i++){
    cin >> X[i];
  }
  sort(X.begin(), X.end());
  int ans=0;
  for(int i=X[0]; i<=X[N-1]; i++){
    int cost=0;
    for(int j=0; j<N; j++){
      cost+=(X[j]-i)*(X[j]-i);
    }
    if (i==X[0]) ans=cost;
    ans=min(ans,cost);
  }
  cout << ans<<endl;
}

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

int main(void) {
    int n;
    char s[300001] = {};
    scanf("%d %s", &n, s);
    size_t l = strlen(s);
    int e[300001] = {};
    int w[300001] = {};
    for (size_t i = 0; i < l; i++) {
        if (s[i] == 'E') {
            e[i + 1] = e[i] + 1;
            w[i + 1] = w[i];
        } else {
            e[i + 1] = e[i];
            w[i + 1] = w[i] + 1;
        }
    }
    for (size_t i = 0; i < l; i++) {
        // printf("%d %d\n", e[i], w[i]);
    }
    int ret = INT_MAX;
    for (size_t i = 0; i < l; i++) {
        int tmp = w[i] - w[0] + e[l] - e[i + 1];
        if (tmp < ret) {
            ret = tmp;
        }
    }
    printf("%d\n", ret);
    return 0;
}

Measured memory_bytes: 2816
N, M = map(int, input().split())
X = list(map(int, input().split()))
if M == 1 or N>=M:
    print(0)
else:
    X.sort()
    X_difs = [X[i+1] - X[i] for i in range(M-1)]
    X_difs.sort()
    for _ in range(N-1):
        X_difs.pop(-1)
    print(sum(X_difs))

Measured memory_bytes: 13960
#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int H, A;
  cin >> H >> A;
  int cnt = 0;
  while (H > 0) {
    H -= A;
    ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 256
// atcoder/abc148/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

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

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  lli a, b;
  while (cin >> a >> b) {
    lli x = __gcd(a, b);
    cout << a / x * b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import sys, math

def main():
    N = int( sys.stdin.readline())
    *A, = map(int, sys.stdin.readline().split())
    *B, = map(int, sys.stdin.readline().split())
    *C, = map(int, sys.stdin.readline().split())

    ans = 0
    last = -100
    for a in A:
        ans += B[a-1]
        if a == last + 1:
            ans += C[last -1]
        last = a

    print(ans)

if __name__=='__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int count = 0;
  int ans = 0;
  for ( int i = 0; i < S.size(); i++) {
    if ( S.at(i) == 'A' || S.at(i) == 'C' || S.at(i) == 'G' || S.at(i) == 'T' ) {
      count++;
    }
     else count = 0;
    if ( count >= ans ) ans = count;
  }
  cout << ans << endl;
}

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

using namespace std;

int n, k, q, a[(int)1e5];

int correct[(int)1e5];

int main(){
	cin >> n >> k >> q;
	for(int i = 0; i < q; ++i){
		cin >> a[i];
		correct[a[i]-1]++;
	}
	
	for(int i = 0; i < n; ++i){
		if(k - (q - correct[i]) > 0){
			cout << "Yes" << endl;
		}else{
			cout << "No" << endl;
		}
	}
	
}

Measured memory_bytes: 1408
a = int(input())
b = int(input())
c = int(input())
x = int(input())
ans = 0
for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      if 500 * i + 100 * j + 50 * k == x:
        ans += 1
print(ans)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import copy
import queue

def main():
    mod=10**9+7
    N=I()
    q=queue.Queue()
    q.put("a")
    ans=[]
    
    
    while True:
        s=q.get()
        if len(s)==N:
            q.put(s)
            break
        s2=list(copy.deepcopy(s))
        s2.sort()
        big=ord(s2[-1])-97
        for i in range(big+2):
            q.put(s+chr(i+97))
            
    while not q.empty():
        s=q.get()
        ans.append(s)  
    
    ans.sort()
    
    for i in range(len(ans)):
        print(ans[i])

main()



Measured memory_bytes: 76884
#include <bits/stdc++.h>
#define ll long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define deb(x) cout<<#x<<"="<<x<<endl;
#define endl '\n'
#define M 1000000007
#define int long long
#define max_n 1000000

using namespace std;

void solve()
{
	ll n;
	cin>>n;
	ll a[n];
	map<ll,ll> m2;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
		m2[i+1-a[i]]++;
	}
	ll ans=0;
	for (int i = 0; i < n; ++i)
	{
		m2[i+1-a[i]]--;
		ans+=m2[a[i]+i+1];
	}
	cout<<ans<<endl;
}

int32_t main() 
{
	IOS	
	ll T=1;
	// cin>>T;
	for(ll i=1;i<=T;++i)
	{		
		// cout<<"Case #"<<i<<": ";
    	solve();
	}
	return 0;
}

Measured memory_bytes: 27928
#include <iostream>
#include <queue>
#include <functional>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int main() {
	int n, m;
	priority_queue< P, vector<P>, greater<P> >pq;
	cin >> n >> m;
	P p;
	for (int i = 0; i < m; i++) {
		cin >> p.first >> p.second;
		pq.push(p);
	}
	int start = 0;
	int counter = 0;
	int end;
	bool hantei = false;
	while (!pq.empty()) {
		P pp = pq.top();
		pq.pop();
		while (!pq.empty() && pp.first == (pq.top()).first) {
			pp = pq.top();
			pq.pop();
		}
		if (pp.first > start+1) {
			hantei = true;
			break;
		} else if (pp.first == start+1) {
			start = pp.second;
			counter++;
		} else {
			end = pp.second;
			while (!pq.empty() && (pq.top()).first <= start+1) {
				pp = pq.top();
				pq.pop();
				while (!pq.empty() && (pq.top()).first == pp.first) {
					pp = pq.top();
					pq.pop();
				}
				if (pp.second > end) {
					end = pp.second;
				}
			}
			start = end;
			counter++;
		}
		if (start == n) {
			break;
		}
	}
	if (start < n) {
		hantei = true;
	}
	if (hantei) {
		cout << "Impossible" << endl;
	} else {
		cout << counter << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
#include<stdio.h>
int main(){
  int i,j,k,N,count=0,flag,v;
  int data[100];
  scanf("%d",&N);
  
  for(i=0;i<N;i++){
    scanf("%d",&data[i]);
  }
  flag=1;
  while(flag){
    flag=0;
    for(j=N-1;j>=1;j--){
      if(data[j]<data[j-1]){
	v=data[j];
	data[j]=data[j-1];
	data[j-1]=v;
	flag=1;
	count++;
      }
    }
  }
  for(k=0;k<N;k++){
    printf("%d",data[k]);
    if(k!=N-1)printf(" ");
  }
  printf("\n");
  
  printf("%d\n",count);
  return 0;
}



Measured memory_bytes: 2144
from collections import deque
S = input()
Q = int(input())
S = deque(S)
rev = False
for i in range(Q):
    T, *FC = input().split()
    if T == "1":
        rev = not rev
    else:
        if FC[0] == "1":
            if rev:
                S.append(FC[1])
            else:
                S.appendleft(FC[1])
        else:
            if rev:
                S.appendleft(FC[1])
            else:
                S.append(FC[1])

if rev:
    S.reverse()
print("".join(S))

Measured memory_bytes: 8564
import sys
MAX_INT = int(10e2)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,K = IL()
a = IL()

dp = [[0]*(K+1) for i in range(N+1)] # dp[i人までの子どもが][j個のアメを配る]
Cs = [[0]*(K+1) for i in range(N+1)] # 累積和

aa = a[0]
num = 0
for i in range(K+1):
  if i <= aa:
    dp[1][i] = 1
    num += 1
  Cs[1][i] = num
for i in range(2,N+1):
  num = 0
  for j in range(K+1):
    if j-a[i-1]-1 < 0:
      dp[i][j] = Cs[i-1][j] %mod
    else:
      dp[i][j] = (Cs[i-1][j] - Cs[i-1][j-a[i-1]-1]) %mod
    num += dp[i][j]
    Cs[i][j] = num

print(dp[N][K] %mod)

Measured memory_bytes: 192792
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner cin = new Scanner(System.in);
        
        int n = 0;
        ArrayList<Integer> l = new ArrayList<Integer>();
        
        for(int i = 0; cin.hasNext(); i++){
	        String line = cin.nextLine();
	        
	        if(i == 0) {
	            n = Integer.parseInt(line);
	            
	        } else if(i == 1) {
	            String[] _l = line.split(" ", 0);
	            
	            for(int j = 0; j < _l.length; j++) {
	                l.add(Integer.parseInt(_l[j]));
	                
	            }
	            
	        } else {
	            
	        }
	        
        }
        
        l.sort(Comparator.reverseOrder());
        
        int max = l.get(0);
        int sum = 0;
        
        for(int i = 1; i < l.size(); i++) {
            sum += l.get(i);
            
        }
        
        String res = "No";
        
        if(max < sum) {
            res = "Yes";
            
        } else {
            
        }
        
        System.out.println(res);
        
    }
    
}


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

int main() {
  long long N;
  cin>>N;
  
  map<long long, long long> kaz;
  for(int i=0;i<N;i++){
    long long a;
    cin>>a;
    kaz[a]+=1;
  }
  long long sum=0;
  for(auto x : kaz) {
    sum+=x.first*x.second;
  }
  long long Q;
  cin>>Q;
  for(int i=0;i<Q;i++){
    long long B,C;
    cin>>B>>C;
    long long b=kaz[B];
    kaz[B]=0;
    kaz[C]+=b;
    sum=sum+(C-B)*b;
    cout<<sum<<endl;
    
  }
}


Measured memory_bytes: 9364
#include <iostream>
#include <bits/c++io.h>
#include <vector>
#include <tuple>
#include <queue>
#define N 100
#define INF 1e9 + 5
using namespace std;

int solve(int k, vector<int> &c,vector<int> &dp){
    
    if(k==1){
        return 0;
    }
    if(k<1){
        return INF;
    }
    if(dp[k]) return dp[k];
    return dp[k] = min( solve(k-1,c,dp)+abs(c[k]-c[k-1]), solve(k-2,c,dp)+abs(c[k]-c[k-2]));
}


int main()
{
    int n;
    scanf("%d", &n);
    vector<int> v(n+1);
    vector<int> dp(100001,INF);
    for (int i =0;i<n;i++)
    {
        scanf("%d", &v[i]);
    }
    //재귀로 풀어봅시다. 
    //solve 는 n일 때 최소가 되는 값을 반환하는 함수라고 합시다. 
    
    // printf("%d",solve(n, v, dp));

    //선형으로 풀어봅시다.
    dp[0]=0; 
    for(int i =0;i<n;i++){
        for(auto j:{i+1,i+2}){
            dp[j] = min( dp[j], dp[i]+abs(v[j]-v[i]) );
        }
    }
    cout<<dp[n-1];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T> vector<T> make_vec(size_t a) { return vector<T>(a); }
template <class T, class... Ts> auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

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

    int N, M, C;
    cin >> N >> M >> C;

    auto B = make_vec<int>(M);
    auto A = make_vec<int>(N, M);
    REP(i, M) { cin >> B.at(i); }
    REP(i, N) {
        REP(j, M) { cin >> A.at(i).at(j); }
    }

    int ans = 0;
    REP(i, N) {
        int sum = C;
        REP(j, M) { sum += A[i][j] * B[j]; }
        if (sum > 0) {
            ans++;
        }
    }

    cout << ans << "\n";

    return 0;
}


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

int N, K;
int X1[110], Y1[110], D1[110];
int X2[110], Y2[110], D2[110];
int field[110][110][110];

map<int, int> zip_x, zip_y, zip_z;
int unzip_x[110], unzip_y[110], unzip_z[110];

void compress(vector<int> &x, map<int, int> &zip, int unzip[]) {
  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());
  for (int i=0; i<x.size(); i++) {
    zip[x[i]] = i;
    unzip[i] = x[i];
  }
}

int main() {
  cin >> N >> K;
  vector<int> xs, ys, zs;
  for (int i=0; i<N; i++) {
    cin >> X1[i] >> Y1[i] >> D1[i];
    cin >> X2[i] >> Y2[i] >> D2[i];
    xs.push_back(X1[i]); xs.push_back(X2[i]);
    ys.push_back(Y1[i]); ys.push_back(Y2[i]);
    zs.push_back(D1[i]); zs.push_back(D2[i]);
  }

  compress(xs, zip_x, unzip_x);
  compress(ys, zip_y, unzip_y);
  compress(zs, zip_z, unzip_z);

  for (int i=0; i<N; i++) {
    for (int x=zip_x[X1[i]]; x<zip_x[X2[i]]; x++) {
      for (int y=zip_y[Y1[i]]; y<zip_y[Y2[i]]; y++) {
        for (int z=zip_z[D1[i]]; z<zip_z[D2[i]]; z++) {
          field[x][y][z]++;
        }
      }
    }
  }

  long long ans = 0;
  for (int x=0; x<110; x++) {
    for (int y=0; y<110; y++) {
      for (int z=0; z<110; z++) {
        if (field[x][y][z] >= K) {
          ans += (long)(unzip_x[x+1]-unzip_x[x])
                *(long)(unzip_y[y+1]-unzip_y[y])
                *(long)(unzip_z[z+1]-unzip_z[z]);
        }
      }
    }
  }
  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 7128
#include "bits/stdc++.h"

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> figures(n);
    for(int i = 0; i < n; i++) cin >> figures.at(i);
    int count = 0;
    for(int i = 1; i < n - 1; i++){
        if((figures.at(i) != max(figures.at(i), max(figures.at(i - 1), figures.at(i + 1))))
        and figures.at(i) != min(figures.at(i), min(figures.at(i - 1), figures.at(i + 1)))){
            count++;
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

string s;


int main(){

	cin >> s;
	long count = 0;
	for(int i=0; i<s.size(); i++){
		if(s[i]=='p'){
			count ++;
		}
	}
	
	cout << s.size()/2-count << endl;
}


Measured memory_bytes: 512
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(a, b) for(int unsafe_cnt=a; unsafe_cnt < b;unsafe_cnt++)
#define fn auto
#include <iostream>
#include <stdio.h>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
using namespace std;

void newline() {cout << endl;}
template <typename T> void display(T input){cout << input;}
template <typename T> void put(T input){display(input); newline();}
void iput(int input) {put(input);}

fn main() -> int {
  int w, a, b;
  cin >> w >>  a >> b;
  int move = abs(a >= b ?  a - b : b - a) - w;
  put(move <= 0 ? 0 : move );
}

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


int main(){
	int n,m;    
	cin>>n>>m;
	
	ll temp , sum = 0;
	
	for(int i=0;i<m;i++){
		cin>>temp;
		sum += temp;
	}
	
	if(sum > n)
		cout<<-1<<endl;
	else
		cout<<n - sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
#include <vector>
#include <array>
#include <iostream>

using namespace std;

int main() {
	vector <array <int, 2>> sets;
	vector <char> ops;
	array <int, 2> pusher;
	int a = 0;
	int b = 0;
	int size = 0;
	int counter = 0;
	char op = ' ';

	while (true) {
		cin>> a >> op >> b;
		if (op == '?') {
			break;
		}
		pusher[0] = a;
		pusher[1] = b;
		sets.push_back(pusher);
		ops.push_back(op);
	}
	size = ops.size();
	for (int i = 0; i < size; i++) {
		switch (ops[counter]) {
			case '+': cout << sets[counter][0] + sets[counter][1] << endl;
						break;
			case '-': cout << sets[counter][0] - sets[counter][1] << endl;
						break;
			case '*': cout << sets[counter][0] * sets[counter][1] << endl;
						break;
			case '/': cout << sets[counter][0] / sets[counter][1] << endl;
						break;
		}
		counter++;
	}
}



Measured memory_bytes: 3136
// https://ynucpc.github.io/blog/2018/04/15/cp_vscode/
// http://www.atmarkit.co.jp/ait/articles/1509/08/news019.html

#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i,n) for(ll i=1;i<=(ll)(n);i++)
#define rep3(i,n,m) for(ll i=(n);i<(ll)(m);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
// #define max(a, b) ((a) > (b) ? (a) : (b))
// #define min(a, b) ((a) < (b) ? (a) : (b)) 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
using ll = long long;
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
int stoi (string s, int tmp=10){
	istringstream stm(s);
	int res;
	stm >> res;
	return res;
}
double stod(string s, int tmp=10){
	istringstream stm(s);
	double res;
	stm >> res;
	return res;
}


// 配列の総和
// greater


ll dp[101][101010]={};

int main(){	
	// ll A;
    // cin >> A;
	// cout << "hello" << endl;
	// cout << stoi("14") << endl;
	// cout << max({1,3}) << endl;

	double t, x;
	cin >> t >> x;
	cout << t/x << endl;

}








Measured memory_bytes: 256
import numpy as np
import itertools

N,M,X = list(map(int, input().split()))
book_matrix = [list(map(int, input().split())) for _ in range(N)]

bit_matrix = itertools.product(range(2), repeat = N)

arr_book_matrix = np.array(book_matrix)
arr_bit_matrix = np.array(list(bit_matrix))

arr_ans_matrix = np.dot(arr_bit_matrix, arr_book_matrix)

ans_matrix = arr_ans_matrix.tolist()

ans = 100000 * 20
for ans_vector in ans_matrix:
    if(min(ans_vector[1:]) >= X):
        ans = min(ans, ans_vector[0])

if(ans == 100000 * 20):
    print(-1)

else:
    print(ans)

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


int main() {
  int k , a , b ;
  cin >> k >> a >> b;
  bool ans=false;
  for(int i=a;i<=b;i++){
    
  
  
  if(i%k==0){
    cout << "OK" << endl;
    ans=true;
    break;
  }
  }
  if(ans ==false){
    cout << "NG" <<endl;
  }
    
}

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

using ll = long long;
using P = pair<int, int>;

const int INF = 1e9;
const int MOD = 1e9 + 7;

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  cout << max(c - (a - b), 0) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <queue>
#include <tuple>
#include <functional>
#include <cstring>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)

typedef long long ll;
typedef std::vector<int> v_int;
typedef std::vector<std::vector<int> > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<std::vector<ll> > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<std::vector<std::string> > v2_string;
typedef std::pair<ll, ll> pll;

using namespace std;

#if 0
  // 挿入
  m.insert(MCI::value_type('c', 30));
  m.insert(MCI::value_type('a', 10));
  m.insert(MCI::value_type('b', 20));
  m.insert(MCI::value_type('a', 40)); // キー'a'に対応する値が2つ

  // 同じキーを持つ値の数を取得する
  MCI::size_type count = m.count('a'); // count == 2
  std::cout << "count = " << count << std::endl;

  // キー`a`を持つ値を列挙する
  std::pair<MCI::iterator, MCI::iterator> p = m.equal_range('a');
  for (MCI::iterator it = p.first; it != p.second; ++it) {
    std::cout << it->second << std::endl;
  }
}

#endif

typedef multimap<int, int> Bridge;
Bridge bridge;
int ans = 200000;

void func(int i, int n, int count) 
{
    if(i == n) {
        ans = min(ans, count);
        return ;
    }

    std::pair<Bridge::iterator, Bridge::iterator> p = bridge.equal_range(i);

    for (Bridge::iterator i = p.first; i != p.second; ++i) {
        func(i->second, n, count+1);
    }
}

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

    irep(i, m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        bridge.insert(Bridge::value_type(a,b));
    }

    func(0, n, 0);

    if(ans < 3) {
        cout << "POSSIBLE" << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    
    return 0;
    
}


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;
  
typedef long long LL;
typedef long double LD;
typedef pair<int,int> P;
typedef pair<int,P> P1;
  
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define min_3(a,b,c) min(a,min(b,c))
#define max_3(a,b,c) max(a,max(b,c))
#define mp1(a,b,c) P1(a,P(b,c))
#define pque(a) priority_queue<a>
#define rpque(a) priority_queue<a,vector<a>,greater<a>>
  
const int INF=100000000;
const int dre_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dre_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
const int kaijou[10]={1,1,2,6,24,120,720,5040,40320,362880};
  
int main(){
    while(1){
        int n,m;
        static int ld[202][202]; rep(i,202)rep(j,202){ if(i==j)ld[i][j]=0; else ld[i][j]=INF; }
        static int sd[202][202]; rep(i,202)rep(j,202){ if(i==j)sd[i][j]=0; else sd[i][j]=INF; }
          
        scanf("%d%d",&n,&m); if(n==0&&m==0)return 0;
        rep(i,m){
            int x,y,t; char sl;
            scanf("%d%d%d %c",&x,&y,&t,&sl);
            if(sl=='L'){
                ld[x][y]=t;
                ld[y][x]=t;
            }
            else {
                sd[x][y]=t;
                sd[y][x]=t;
            }
        }
          
        rep1(k,n)rep1(i,n)rep1(j,n)ld[i][j]=min(ld[i][j],ld[i][k]+ld[k][j]);
        rep1(k,n)rep1(i,n)rep1(j,n)sd[i][j]=min(sd[i][j],sd[i][k]+sd[k][j]);
          
        /*rep1(i,n){
            rep1(j,n){
                cout<<sd[i][j]<<" ";
            }
            cout<<endl;
        }*/
          
        int r,z[1002];
        static int dp[1002][202]; rep(i,1002)rep(j,202)dp[i][j]=INF;
          
        scanf("%d",&r);
    	rep(i,r)scanf("%d",&z[i]);
        dp[0][z[0]]=0;
          
        rep1(i,r-1){
            rep1(j,n){
            	dp[i][j]=min(dp[i][j],dp[i-1][j]+ld[z[i-1]][z[i]]);
                if(ld[j][z[i]]!=INF){
                    rep1(k,n){
                        dp[i][j]=min(dp[i][j],dp[i-1][k]+ld[z[i-1]][k]+sd[k][j]+ld[j][z[i]]);
                    }
                }
            }
        }
    	
    	int ret=1000000000;
    	rep1(i,n){
    		ret=min(ret,dp[r-1][i]);
    	}
          
        printf("%d\n",ret);
    }
}

Measured memory_bytes: 2284
#include<stdio.h>
 
int mata[100][100],matb[100];
 
int main(void){
    int i,j,n,m,k;
 
    scanf("%d %d",&n,&m);
    for(i = 0;i < n;i++)
        for(j = 0;j < m;j++)
            scanf("%d",&mata[i][j]);
    for(i = 0;i < m;i++)
        scanf("%d",&matb[i]);
 
    for(i = 0;i < n;i++){
        k = 0;
        for(j = 0;j < m;j++)
            k += mata[i][j] * matb[j];
        printf("%d\n",k);
    }
    return 0;
}


Measured memory_bytes: 2108
n=int(input())
a=[int(input()) for i in range(n)]
a2=[]
for i in range(n):
  if i%2==0:
    a2.append(a[i])
a2=set(a2)
A=sorted(a)
A2=[]
ct=0
for i in range(n):
  if i%2==0:
    if A[i] not in a2:
      ct+=1
print(ct)

Measured memory_bytes: 56664
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<string> vs;
typedef vector<char> vc;
typedef queue<ll> ql;
typedef deque<ll> dql;
typedef priority_queue<ll, vl/*, greater<ll>*/> pql; //降順(/*昇順*/)
typedef set<ll> sl;
typedef pair<ll, ll> pl;
typedef vector<vl> vvl;
typedef vector<pl> vpl;
#define rep(i, n) for(ll i = 0; i < ll(n); ++i)
#define rep2(i, n) for(ll i = 1; i <= ll(n); ++i)
//#define rep(i, k, n) for(ll i = k-1; i < ll(n); ++i)
//#define rep2(i, k, n) for(ll i = k; i <= ll(n); ++i)
#define all(v) (v).begin(), (v).end()
bool chmin(ll &a, ll b) {if(b < a) {a = b; return 1;} return 0;}
bool chmax(ll &a, ll b) {if(b > a) {a = b; return 1;} return 0;}
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
//const ll MOD = 998244353;
const ll MAX = 1e9;
const char newl = '\n';

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

  ll n, ans=1;
  cin >> n;
  rep2(i, n) (ans*=i)%=MOD;
  cout << ans << newl;
}


Measured memory_bytes: 256
count = int(input())
nlist = []
for i in range(count):
    a = int(input())
    nlist.append(a)
mlist = tuple(nlist)
biggest = max(mlist)
nlist.remove(biggest)
c = max(nlist)

for i in range(count):
    if mlist[i] == biggest:
        print(c)
    else:
        print(biggest)


Measured memory_bytes: 14076
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = n;
		int sum = 0;
		while(x > 2) {
			x=x-3;
			sum++;
		}
		System.out.println(sum);
		sc.close();
	}
}

Measured memory_bytes: 23636
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
int main(){
	long long a=1,b;
	cin>>b;
	for(long long i=1;i<=b;i++){
		a*=i;
		a%=1000000007;
	}
	cout<<a<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <string>
#include <queue>
#include <cmath>
#include <iterator>
#include <math.h>
#include <cstdio>
#include <map>

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;

#define sheets_total kind[10]+kind[5]+kind[1]

int main(void){
    int sheets,money;
    cin >> sheets >> money;
    money/=1000;
    array<int,10> kind;
    kind[1] = money%5;
    money -= kind[1];
    kind[10] = money/10;
    money -= kind[10]*10;
    kind[5] = money/5;
    money -= kind[5]*5;
    
    if(sheets_total > sheets){
        cout << "-1 -1 -1" << endl;
        return 0;
    }
    
    while(sheets_total != sheets){
        if(kind[5] != 0 && sheets_total + 4 <= sheets){
            kind[5]--;
            kind[1]+=5;
        }else if(kind[10] != 0){
            kind[10]--;
            kind[5]+=2;
        }else{
            cout << "-1 -1 -1" << endl;
            return 0;
        }
    }
    
    cout << kind[10] << " " << kind[5] << " " << kind[1] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <string.h>
#include <map>
#include <set>
#include <vector>
#include <stdio.h>
#include <math.h>
#include <algorithm>
#include <queue>
#include <cmath>
#include <cstdio>
using namespace std;
pair<int,int> a[100010];
int n,m,cnt;
bool cmp(pair<int,int> x,pair<int,int> y){
	if(x.second==y.second) return x.first<y.first;
	return x.second<y.second;
}
int main() {
	cin>>n>>m;
	for(int i=0;i<m;i++){
		cin>>a[i].first>>a[i].second;
	}
	sort(a,a+m,cmp);
	int last=a[0].second,i=1;
	if(m==1){
		cout<<1<<endl;
		return 0;
	}
	while(i<m){
		while(a[i].first<last && i<m) i++;
		cnt++;
		if(i<m)last=a[i].second;
	}
	cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using ll = long long;
const ll INF = 1000000000000;
#define fir first
#define sec second


int main()
{
    int h,w,d;
    std::cin >> h >> w >> d;
    std::vector<std::vector<int>> a(h,std::vector<int>(w)), sum(d,std::vector<int>(h * w / d + 10));
    std::vector<std::pair<int,int>> map(h * w);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            std::cin >> a[i][j]; a[i][j]--;
            map[a[i][j]] = {i,j};
        }
    }
    int q; std::cin >> q;
    std::vector<int> r(q), l(q);
    for(int i = 0; i < q; i++){std::cin >> r[i] >> l[i];r[i]--;l[i]--;}
    for(int i = 0; i < h * w; i++){
        if(i / d == 0)continue;
        sum[i % d][i / d] = sum[i % d][i / d - 1] +  std::abs(map[i].fir - map[i - d].fir) + std::abs(map[i].sec - map[i - d].sec);
    }


    for(int i = 0; i < q; i++){
        std::cout << sum[r[i] % d][l[i] / d] - sum[r[i] % d][r[i] / d] << std::endl;;
    }

}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
int main()
{
long int sum,n,m,i;
  sum=0;
  cin >> n;
int t[n];
  
  for(i=0;i<n;++i)
  {
  cin >> t[i];
  sum=sum+t[i];
  }
  cin >> m;
int p[m],x[m];
  
  for(i=0;i<m;++i)
  {
  cin >> p[i] >> x[i];
  cout << sum-t[p[i]-1]+x[i] << endl;
  }

return 0;}

Measured memory_bytes: 3580
#include<bits/stdc++.h>
using namespace std;
#define ll long long
char elia[1000][1001];
ll jwa[1001][1001],owa[1001][1001],iwa[1001][1001];
int main(void){
	ll i,j,m,n,k,js,os,is,jsum,osum,isum,a,b,c,d;
	cin>>m>>n>>k;
	for(i=0;i<m;i++) cin>>elia[i];
	for(i=0;i<=m;i++) jwa[i][0]=0,owa[i][0]=0,iwa[i][0]=0;
	for(i=0;i<=n;i++) jwa[0][i]=0,owa[0][i]=0,iwa[0][i]=0;
//	cout<<111111111<<endl;
	for(i=1;i<=n;i++){
		if(elia[0][i-1]=='J') js++;
		if(elia[0][i-1]=='O') os++;
		if(elia[0][i-1]=='I') is++;
		jwa[1][i]=js; owa[1][i]=os; iwa[1][i]=is;
	}
	for(i=1;i<=m;i++){
		js=0,os=0,is=0;
		for(j=1;j<=n;j++){
			if(elia[i-1][j-1]=='J') js++;
			jwa[i][j]=jwa[i-1][j]+js;
			if(elia[i-1][j-1]=='O') os++;
			owa[i][j]=owa[i-1][j]+os;
			if(elia[i-1][j-1]=='I') is++;
			iwa[i][j]=iwa[i-1][j]+is;
		}
	}
	for(i=0;i<k;i++){
		cin>>a>>b>>c>>d;
		a--; b--;
		jsum=jwa[c][d]-jwa[a][d]-jwa[c][b]+jwa[a][b];
		osum=owa[c][d]-owa[a][d]-owa[c][b]+owa[a][b];
		isum=iwa[c][d]-iwa[a][d]-iwa[c][b]+iwa[a][b];
		cout<<jsum<<' '<<osum<<' '<<isum<<endl;
	}
	return 0;
}

Measured memory_bytes: 27284
// written by newbiechd
#include <algorithm>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <vector>

// DELETE the debugging information!
#define debug(x) std::cerr << #x << " = " << (x) << std::endl

int read() {
  int f = 0;
  char ch;
  while (!isdigit(ch = getchar()));
  do f = 10 * f + (ch ^ '0');
  while (isdigit(ch = getchar()));
  return f;
}

const int N_MAX = 100003;
std::vector<int> g[N_MAX];
int dep[N_MAX];
bool deg[N_MAX];
void dfs(int x, int f) {
  dep[x] = dep[f] + 1;
  for (int y : g[x])
    if (y != f) {
      if (dep[y]) {
        if (dep[x] > dep[y])
          printf("%d %d\n", x, y), deg[x] ^= 1;
      }
      else
        dfs(y, x);
    }
  if (x > 1) {
    if (deg[x])
      printf("%d %d\n", x, f), deg[x] = 0;
    else
      printf("%d %d\n", f, x), deg[f] ^= 1;
  }
}

int main() {
  int n = read(), m = read();
  for (int i = 1; i <= m; ++i) {
    int x = read(), y = read();
    g[x].push_back(y), g[y].push_back(x);
  }
  if (m & 1)
    printf("-1\n");
  else
    dfs(1, 0);
  return 0;
}


Measured memory_bytes: 13568
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	for scanner.Scan() {
		n, _ := strconv.Atoi(scanner.Text())
		if n == 0 {
			break
		}
		k := 0
		for n > 1 {
			if n&1 != 0 {
				n = n+((n+1)>>1)
				k+=2
			} else {
				n >>= 1
				k++
			}
		}
		fmt.Println(k)
	}
}


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

struct edge{
    int to,dist;
};

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

    vector<vector<edge>> G(n);
    vector<int> dig(n,-1);
    for(int i=0;i<m;i++){
        int a,b,c;
        cin >> a >> b >> c;
        a--; b--; c %= 2;
        G[a].push_back({b,c});
        G[b].push_back({a,c});
    }

    int count = 0;
    for(int i=0;i<n;i++){
        if(dig[i]!=-1) continue;

        count++;
        queue<int> q;
        q.push(i);
        dig[i] = 0;
        while(!q.empty()){
            int cur = q.front(); q.pop();
            for(int j=0;j<G[cur].size();j++){
                int np = G[cur][j].to;
                int dif = G[cur][j].dist;

                if(dig[np]!=-1) continue;

                dig[np] = (dig[cur]+dif)%2;
                q.push(np);
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 7284
<?php
while (fscanf(STDIN, "%d %d", $w, $h) && ($w | $h)) {
  unset($c);
  for ($i = 0; $i < $h; $i++) {
    $c[] = explode(' ', trim(fgets(STDIN)));
  }
  for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
      $visited[$i][$j] = 0;
    }
  }
  $ans = 0;
  for ($i = 0; $i < $h; $i++) {
    for ($j = 0; $j < $w; $j++) {
      if ($c[$i][$j] && !$visited[$i][$j]) {
        $ans++;
        dfs($i, $j);
      }
    }
  }
  print $ans . "\n";
}

function dfs($y, $x) {
  global $visited, $c, $w, $h;
  
  $visited[$y][$x] = 1;
  
  for ($i = -1; $i <= 1; $i++) {
    for ($j = -1; $j <= 1; $j++) {
      $ny = $y + $i;
      $nx = $x + $j;
      if (0 > $ny || $ny >= $h) continue;
      if (0 > $nx || $nx >= $w) continue;
      if ($visited[$ny][$nx]) continue;
      if (!$c[$ny][$nx]) continue;
      dfs($ny, $nx);
    }
  }
}

Measured memory_bytes: 11136
/*
　　こんにちは。あたしはｶｳｶﾞｰﾙ。
　　redcoderになるためAtCoderを巡る旅をしてます。

　　　 　 ＿_
　　　 ヽ|＿_|ノ　　　　ﾓｫ
　　　　||‘‐‘||ﾚ　　_)_, ―‐ 、
　　　　/(Ｙ (ヽ＿ /・ ヽ　　 ￣ヽ
　　　　∠ ＿ ゝ　 ｀^ヽ ﾉ.::::_(ノヽ
　　　　 _/ヽ　 　　  /ヽ￣￣/ヽ
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define COUT(x) cout << (x) << endl

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; }

int ans;
int n;

// 現在値を保持、bit管理で7,5,3が1つ以上使われているか管理をする。
void dfs(ll now, int mask) {
    if(now > n) return;
    if(mask == 7) ans++;
    dfs(now * 10 + 7, mask | 4); // 3ビット目を立たせてる 0100
    dfs(now * 10 + 5, mask | 2); // 2          "        0010
    dfs(now * 10 + 3, mask | 1); // 1          "        0001
}

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

    cin >> n;
    dfs(0, 0);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a[3];
    for(int i=0;i<3;i++){
        cin >> a[i];
    }
    sort(a,a+3);
    int sum=0;
    for(int i=1;i<3;i++){
        sum+=(a[i]-a[i-1]);
    }
    cout << sum << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#define MIN 1<<31-1
#define HMAX 1000000000000000000
#define MOD 1000000007
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RSET(s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
typedef long long int ll;
using namespace std;
int main()
{
	string s;
	cin>>s;
	int m=700;
	for(int i=0;i<3;i++)
		if(s[i]=='o')
			m+=100;
	cout<<m; 
	return 0;
}

Measured memory_bytes: 256