akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cstring>
#include <map>
#include <set>
#include <cmath>
#define FOR(i, a, b) for (ll i = (a); i < (b); ++i)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define INF 1e9
typedef long long int ll;
using namespace std;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
    for (T &x : vec)
        is >> x;
    return is;
}

ll gcd(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    while (m != n)
    {
        if (m > n)
            m = m - n;
        else
            n = n - m;
    }
    return m;
}

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

vector<ll> decom;

void decompositPrime(ll n)
{
    ll a = 2;
    while (n >= a * a)
    {
        if (n % a == 0)
        {
            decom.push_back(a);
            n /= a;
        }
        else
        {
            a++;
        }
    }
    decom.push_back(n);
}

int main(){
    string S;
    cin >> S;

    int ans=0;

    REP(i,S.size()-1){
        if(S[i+1]!=S[i]){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

#define ll long long
const long long llINF = 1LL << 60;
const int iINF = 0x20000000;
template<class T> inline bool chmin(T& a, T b) { if (b < a) { 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; }

void execute();
int main() 
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);// cin と scanfの併用禁止
    cout << fixed << setprecision(15);
    execute();
    return 0;
}


void execute()
{
    string s;
    cin >> s;

    cout << s.substr(0, 3) << endl; 
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
//正なら元の値、負なら０を返す関数
long long ramp(long long x){
    if(x>=0) return x;
    else return 0;
}
int main(){
	long long n; 
    cin >> n;
    vector<long long> a(n+1);
    for(int i=0; i<n+1; i++) cin >> a[i];
    //元のモンスターの数
    long long s=accumulate(a.begin(),a.end(),0ll);
    
    long long tmp;
    for(int i=0; i<n; i++){
        cin >> tmp;
        //i番目の勇者が倒した後のモンスターの数
        //ramp(tmp-a[i])が余力
        a[i+1] = ramp(a[i+1]-ramp(tmp-a[i]));
        //a[i]>tmpならa[i]-tmp,それ以外は0
        a[i] = ramp(a[i]-tmp);
    }
    //生き残ったモンスターの数
    long long e=accumulate(a.begin(),a.end(),0ll);
    //元－生き残り＝倒した数
    s -= e;
    cout << s << endl;
}


Measured memory_bytes: 1024
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  n, k = map(int, input().split())
  s = input().strip()
  sz, ez = [], []
  i = 0
  while i < n:
    if s[i] == '0':
      sz.append(i)
      while i < n and s[i] == '0': i += 1
      ez.append(i)
    else:
      i += 1
  
  if k >= len(sz):
    print(len(s))
    return 
  max = -1
  for i in range(len(sz)-k+1):
    if i==0:
      score = sz[i+k] - 0
    elif i==len(sz)-k:
      score = n - ez[i-1]
    else:
      score = sz[i+k] - ez[i-1]
    if max < score:
      max = score
  print(max)
      

if __name__=='__main__':
  main()


  


Measured memory_bytes: 7168
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>

using namespace std;

int main() {
   string n;
    
   
   cin >> n;
  
  int num;
 
    num = stoi(n);
  
 //  cout << n[0]-'0' << endl;
 // cout << n[1]-'0' << endl;
  
  int ans=0;
for(int i = 0;i<n.size();i++){
     

    int nn = n[i]-'0';
  
  ans = ans + nn;
  
}
  
//   int num1 = n[0]-'0';
 //  int num2 = n[1]-'0';
  
 // char c = '1';
//int i = c - '0';
  
 // int ans = num1+num2;
  
 //   cout << ans << endl;
 //   cout << num << endl;
  
  if(num%ans==0){
     cout << "Yes" << endl;
  }else{
     cout << "No" << endl;
  }
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
template<class T> bool max(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class T> int maxReturn(T a, T b) {
    if (a > b) {
        return a;
    }
    return b;
}

template<class T> bool min(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

int main(void){
    string s, t;
    cin >> s;
    cin >> t;
    int slength = s.length();
    int tlength = t.length();
    int dp[3100][3100] = {0};
    
    for (int i = 1; i <= slength; i++) {
        for (int a = 1; a <= tlength; a++) {
            if (s[i-1] == t[a-1]) {
                dp[i][a] = dp[i-1][a-1] + 1;
            } else {
                dp[i][a] = maxReturn(dp[i-1][a], dp[i][a-1]);
            }
        }
    }
    
    int i = slength;
    int j = tlength;
    string res = "";
    
    while (i > 0 && j > 0) {
        if (dp[i][j] == dp[i][j-1]) {
            j--;
        } else if (dp[i][j] == dp[i-1][j]) {
            i--;
        } else {
            res = s[i-1] + res;
            i--;
            j--;
        }
    }
    
    cout << res << endl;
}

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

short dp[3003][3003];
int main() {
  string s, t;
  cin >> s >> t;
  int ss, ts;
  ss = s.size();
  ts = t.size();
//  int dp[ss+1][ts+1];
  rep(i, ts+1) dp[0][i] = 0;
  rep(i, ss+1) dp[i][0] = 0;
  rep(i, ss) {
    rep(j, ts) {
      if ((s[i] == t[j]) && (dp[i][j] == dp[i][j+1]) && (dp[i][j] == dp[i+1][j])) {
        dp[i+1][j+1] = dp[i][j] + 1;
      } else {
        dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
      }
    }
  }
//  rep(i, ss+1) {rep(j, ts+1) cout << dp[i][j]; cout << endl;}
  if (dp[ss][ts] == 0) cout << "" << endl;
  else {
    string ans = "";
    for (int i = ss, j = ts; (i > 0) && (j > 0);) {
//      cout << ss-si << "," << ts-ti << endl;
      if (dp[i][j] == dp[i-1][j]) i--;
      else if (dp[i][j] == dp[i][j-1]) j--;
      else {ans = t[j-1] + ans; j--; if (dp[i][j] <= 0) break;}
    }
    cout << ans << endl;
  }
}


Measured memory_bytes: 17920
#include <iostream>
#include <math.h>
#include <stdio.h>
#define PI 3.141592653589
using namespace std;
int main(void){
    double r;
    cin >> r;
    double ference;
    ference = (r*2)*PI;
    double area;
    area = pow(r,2)*PI;
    printf("%.8lf %.8lf\n",area,ference);
}


Measured memory_bytes: 3188
sd = input()
t = input()

n = len(sd)
m = len(t)
s = []

for i in range(n-m, -1, -1):
    t_p = sd[i:i+m]
    for j in range(m+1):
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        else:
            if t_p[j] == "?":
                continue
            elif t_p[j] != t[j]:
                break

print("UNRESTORABLE")

Measured memory_bytes: 9012
import numpy as np

def dp(v, d, c):
    if memo[v-1][d]:
        return

    memo[v-1][d] = True
    if d == 0:
        res[v-1] = str(c)
        return

    dp(v, d-1, c)
    for e in dic[v-1]:
        dp(e, d-1, c)


N, M = [int(e) for e in input().split(' ')]

dic = [[] for _ in range(N)]
memo = [[False]*11 for _ in range(N)]

for m in range(M):
    a, b = [int(e) for e in input().split(' ')]
    dic[a-1].append(b)
    dic[b-1].append(a)

Q = int(input())


vdc = [[int(e) for e in input().split(' ')] for _ in range(Q)]

res = ['0']*N

[dp(v, d, c) for v, d, c in vdc[::-1]]


print('\n'.join(res))


Measured memory_bytes: 72292
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

int main() {
    int r;
    scanf("%d", &r);
    printf("%d", 3 * r * r);
    return 0;
}

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

int main() {
   char s;
   cin >> s;

   if (isupper(s))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }
}

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

using namespace std;

constexpr int INF = 1000000202;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int h, n;
  cin >> h >> n;
  vector<int> a(n), b(n);
  int a_max = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i] >> b[i];
    a_max = max(a_max, a[i]);
  }
  vector<int> dp(20010, INF);
  dp[0] = 0;
  for (int i = 1; i <= h + a_max; i++) {
    for (int j = 0; j < n; j++) {
      if (a[j] <= i) {
        dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
      } else {
        dp[i] = min(dp[i], b[j]);
      }
    }
  }
  int ans = INF;
  for (int i = h; i <= h + a_max; i++) {
    ans = min(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3748
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<(int)(n);i++)
#define N 300000
vector<int>e[N];

int dfs(int k){
	vector<int>b;
	int m = 0;
	if (e[k].size() == 0)return 0;
	f(i, e[k].size()){
		b.push_back(dfs(e[k][i]));
	}
	sort(b.begin(), b.end(),greater<int>());
	f(i, b.size()){
		m = max(m, b[i] + i + 1);
	}
	return m;
}


int main(){
	int n;
	int x, ans;
	scanf("%d", &n);
	for (int i = 1; i < n; i++){
		scanf("%d", &x);
		x--;
		e[x].push_back(i);
	}
	ans=dfs(0);
	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 19712
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <complex>

#define pb push_back
#define mp make_pair
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define tr(c, i) for (typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define rtr(c, i) for (typeof((c).rbegin()) i = (c).rbegin(); i != (c).rend(); --i)
#define contains(c, x) ((c).find(x) != (c).end())
#define Contains(c, x) (find(all(c), x) != (c).end())
#define REP(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) REP(i, 0, (n))
#define To_String to_string< char,std::char_traits<char>,std::allocator<char> >

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main()
{
	ios_base::sync_with_stdio(0);
	int n, a[21];
	while (cin >> n, n) {
		int sum = 0;
		rep(i, n) {
			cin >> a[i];
			sum += a[i];
		}
		int res = 1000000000;
		rep(i, (1<<n)) {
			int A = 0;
			rep(j, n) if (i & (1 << j)) A += a[j];
			res = min(res, abs(A - (sum - A)));
		}
		cout << res << endl;
	}
	return 0;
}

Measured memory_bytes: 0
n = int(input())
a = list()
for i in range(n):
    x,y = input().split()
    y = int(y)
    if x == "S" :
        a.append(y + 0)
    if x == "H" :
        a.append(y + 13)
    if x == "C" :
        a.append(y + 26)
    if x == "D" :
        a.append(y + 39)
for i in range(1,53) :
    if not(i in a):
        if i <= 13 :
            print("S {}".format(i - 0))
        elif i <= 26 :
            print("H {}".format(i-13))
        elif i <= 39:
            print("C {}".format(i-26))
        else :
            print("D {}".format(i -39))


Measured memory_bytes: 5592
//状态:	UC
//题号:atcoder 084 c
#include <iostream>
#include <stdio.h>
#include <algorithm>
using namespace std;
int a[100005];
int b[100005];
int c[100005];
int n;
void sor(){
	sort(a,a+n);
	sort(b,b+n);
	sort(c,c+n);
}

void ini(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d",&a[i]);
	for(int i=0;i<n;i++)scanf("%d",&b[i]);
	for(int i=0;i<n;i++)scanf("%d",&c[i]);
}

void sol(){
	long long ans=0;
	int i,j,k;
	for(j=0;j<n;j++){
		i=lower_bound(a,a+n,b[j])-a;
		k=upper_bound(c,c+n,b[j])-c;
		k=n-k;
		ans+=(long long)(i)*k;
	}
	printf("%lld\n",ans);
}

int main(){
	ini();
	sor();
	sol();
	return 0;
}

Measured memory_bytes: 1536
#include <stdio.h>

int main(void){
	int a, b;

	scanf("%d%d", &a, &b);

	if(a == b) {
		printf("Draw");
	}else if(a == 1 || (b != 1 && a > b)) {
		printf("Alice");
	}else{
		printf("Bob");
	}

	return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
    
    int HEIGHT = 4;
    int WIDTH = 4;
    int[][] relationXY;

    void run(){
        Scanner sc = new Scanner(System.in);        
        while(true){
            int[][] temp = new int[4][2];
            int x = sc.nextInt();
            if(x > 4){
                break;
            }
            int y = sc.nextInt();
            temp[0][0] = x;
            temp[0][1] = y;
            for(int i = 1;i < 4;i++){
                temp[i][0] = sc.nextInt();
                temp[i][1] = sc.nextInt();
            }
            relationXY = temp;
            boolean[][] visited = new boolean[HEIGHT][WIDTH];
            System.out.println(dfs(visited,HEIGHT*WIDTH,0));
        }
    }
    int dfs(boolean[][] visited,int remain,int next){
        if(remain == 0){
            return 1;
        }
        if(next >= HEIGHT*WIDTH){
            return 0;
        }

        int count = 0;

        int y = next / HEIGHT;
        int x = next % WIDTH;
        if( visited[y][x]){
            count+=dfs(visited,remain,next+1);
        }
        else{
            for(int i = 0;i < relationXY.length;i++){
                int rx = x + relationXY[i][0];
                int ry = y + relationXY[i][1];
                if(rx < 0 || WIDTH <= rx || ry < 0 || HEIGHT <= ry){
                    continue;
                }
                if(!visited[ry][rx]){
                    visited[y][x] = true;
                    visited[ry][rx] = true;
                    count += dfs(visited,remain-2,next+1);
                    visited[y][x] = false;
                    visited[ry][rx] = false;
                }
            }
        }

        return count;
    }
    public static void main(String[] args) {
        new Main().run();
    }
}
    

Measured memory_bytes: 17216
if __name__ == '__main__':
    length, question_count = map(int, input().split())

    string = input()
    ac_sums = [0]
    for i in range(1, len(string) + 1):
        if i > 1 and string[i - 2] == 'A' and string[i - 1] == 'C':
            ac_sums.append(ac_sums[i - 1] + 1)
        else:
            ac_sums.append(ac_sums[i - 1])

    for i in range(question_count):
        l, r = map(int, input().split())
        ans = ac_sums[r] - ac_sums[l - 1]
        if l > 1 and string[l - 1] == 'C' and string[l - 2] == 'A':
            ans -= 1
        print(ans)


Measured memory_bytes: 6180
import sys
sys.setrecursionlimit(1000000)

def solve(N, M , A):
    s = sum(A)
    if N - s < 0:
        return -1
    return N - s

if __name__ == "__main__":
    N, M = tuple(map(int, input().split(" ")))
    A = list(map(int, input().split(" ")))

    print(solve(N, M, A))


Measured memory_bytes: 10048
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <bits/stdc++.h>
#define ll long long
#define pi 3.14
using namespace std;
void put(int x){
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x==0) {
		putchar('0');
	}
	int num=0;
	char c[15];
	while(x) {
		c[++num]=(x%10)+48;
		x/=10;
	}
	while(num) {
		putchar(c[num--]);
	}
	putchar('\n');
}
inline void in(int &x){
	char ch=getchar();
	int flag=1;
	while(!(ch>='0'&&ch<='9')) {
		if(ch=='-')
			flag*=-1;
		ch=getchar();
	}
	x=ch-'0';
	ch=getchar();
	while(ch>='0'&&ch<='9') {
		x=((x<<3)+(x<<1))+ch-'0';
		ch=getchar();
	}
	x*=flag;
}
int x,y;
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	in(x);in(y);
	if((y-2*x)>=0&&(y-2*x)%2==0){
		int a=(y-2*x)/2,b=x-a;
		if(a>=0&&b>=0)
		printf("Yes\n");
		else printf("No\n");
	}
	else printf("No\n");
	return 0;
}

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

#define fi first
#define se second
#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define pb push_back
#define int long long

const int MOD = 1e9 + 7;
const int oo = 1e9;
const int N = 105;

int n, k;
int f[N][N * N], pw[N * N], cnt[N][N * N];

void upd(int &x, int y) {
    if(x == -1) x = 0ll;
    x = (x + y) % MOD;
}

signed main()
{
    //freopen("test.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n >> k;
    memset(f, -1, sizeof f);
    pw[0] = 1ll; FOR(i, 1, n * n) pw[i] = pw[i - 1] * (k + 1) % MOD;
    f[n + 1][0] = 0;
    cnt[n + 1][0] = 1ll;
    for(int i = n + 1; i > 1; --i) {
        // calc the tmp

        FOR(j, 0, n * n)    if(f[i][j] >= 0)    {
            if(k >= i) upd(cnt[i - 1][j], cnt[i][j] * (k - i + 1)); // case take t > i - 1
            FOR(t, 0, min(i - 1, k)) {
                int rem = (t + j) % (i - 1);
                int tim = (t + j) / (i - 1);
                upd(cnt[i - 1][tim + j], cnt[i][j]);
            }
            // calc the f[i - 1][j]
            if(k >= i) upd(f[i - 1][j], (f[i][j] * (k - i + 1) + (j * (k - i + 1) + (k - i + 1) * (k + i) / 2) * cnt[i][j]));
            FOR(t, 0, min(i - 1, k))    {
                int rem = (t + j) % (i - 1);
                int tim = (t + j) / (i - 1);
                upd(f[i - 1][tim + j], (f[i][j] + rem * cnt[i][j]) % MOD);
            }
        }
    }
    //cout << f[2][0] << ' ' << cnt[2][0] << '\n';
    int ans = 0ll;
    FOR(i, 0, n * n) if(f[1][i] >= 0) upd(ans, f[1][i]);
    cout << ans;
}


Measured memory_bytes: 16640
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

long long lcm(long long a, long long b){ return a/__gcd(a, b)*b; }

int main(){
    Init();
    ll n, m; cin >> n >> m;
    string s, t; cin >> s >> t;
    ll num = lcm(n, m);
    bool chk = true;
    ll gcdn = __gcd(n, m);
    ll step_n = n/gcdn;
    ll step_m = m/gcdn;
    for(ll i=0; i<gcdn; i++){
        if(s[step_n*i] != t[step_m*i]) chk = false;
    }
    cout << (chk ? num : -1) << endl; 
}

Measured memory_bytes: 3852
#include<cstring>
#include<cstdio>
using namespace std;

int main() {
    char s[201], p[101];
    char ch[101];
    
    scanf("%s", s);
    scanf("%s\n", p);
    strcpy(ch, s);
    strcat(s,ch);
    if (strstr(s, p) == NULL) printf("No\n");
    else printf("Yes\n");
    
    return 0;
    
    
}



Measured memory_bytes: 2744
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int T, card[9];

bool is_same_number(int a, int b, int c) {
  if (a == b && a == c) return true;
  else return false;
}

bool is_sequence(int a, int b, int c) {
  if (a+2 == c && b+1 == c) return true;
  else return false;
}

bool is_good_set(int a, int b, int c) {
  if (is_same_number(a, b, c) || is_sequence(a, b, c)) return true;
  else return false;
}

bool is_all_good_set() {
  if (is_good_set(card[0], card[1], card[2]) && is_good_set(card[3], card[4], card[5]) && is_good_set(card[6], card[7], card[8])) return true;
  else return false;
}

int win() {
  sort(card, card+9);
  do {
    if (is_all_good_set()) return 1;
  } while (next_permutation(card, card+9));
  return 0;
}

int main() {
  cin >> T;
  for (int t = 0; t < T; t++) {
    for (int i = 0; i < 9; i++) {
      cin >> card[i];
    }
    string color;
    for (int i = 0; i < 9; i++) {
      cin >> color;
      if (color == "G") card[i] += 10;
      else if (color == "B") card[i] += 20;
    }
    cout << win() << endl;
  }
}

Measured memory_bytes: 3076
from functools import reduce
from math import ceil

def solve(N, fortune):
  value = reduce(lambda a, b: a - b[1], fortune, 0)
  fortune.sort(key=lambda f: f[0] + f[1], reverse=True)
  for i in range(0, N, 2):
    value = value + fortune[i][0] + fortune[i][1]
  return value

N = int(input())
fortune = [tuple(map(int, input().split())) for _ in range(N)]

print(solve(N, fortune))


Measured memory_bytes: 21880
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll int64_t

using namespace std;

int main() {
	int n;
	int ans[4] = {0,0,0,0};

	cin >> n;
	rep(i,n){
		string s;
		cin >> s;

		if (s == "AC")
		{
			ans[0]++;
		}
		if (s == "WA")
		{
			ans[1]++;
		}
		if (s == "TLE")
		{
			ans[2]++;
		}
		if (s == "RE")
		{
			ans[3]++;
		}
	}

	cout << "AC x " << ans[0]<<endl;
	cout << "WA x " << ans[1]<<endl;
	cout << "TLE x " << ans[2]<<endl;
	cout << "RE x " << ans[3]<<endl;


	return 0;
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
int main(){
    string S;
    cin >> S;
    int N = S.size();
	int MOD = 1000000007;

    long long dp[100010][4] = {};
    for(int i = N; i >= 0; --i){
        for(int j = 3; j >= 0; --j){
            if(i == N){
                dp[i][j] = (j == 3 ? 1LL : 0LL);
            }else{
                dp[i][j] = dp[i+1][j] * (S[i] == '?' ? 3LL : 1LL);
                if(j < 3 && (S[i] == '?' || S[i] == "ABC"[j])){
                    dp[i][j] += dp[i+1][j+1];
                }
                dp[i][j] %= MOD;
            }
        }
    }
    cout << dp[0][0] << endl;
}


Measured memory_bytes: 3584
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<ll,ll>;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

////////// 二項係数(N<=10^7) //////////

ll fac[MAX],finv[MAX],inv[MAX];
// fac[i] i!
// finv[i] i!の逆元
// inv[i] iの逆元

// テーブルを作る前処理
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(ll i=2; i<MAX; ++i){
    fac[i]=fac[i-1]*i%MOD;
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    finv[i]=finv[i-1]*inv[i]%MOD;
  }
}

// 二項係数計算
ll COM(ll n,ll k){
  if(n<k) return 0;
  if(n<0 || k<0) return 0;
  return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;
}

//////////////////////////////////////////////////

int main(){
  COMinit();
  ll N,K,ans=0;
  cin>>N>>K;
  vector<ll> A;
  REP(i,N){
    ll a;
    cin>>a;
    A.PB(a);
  }
  SORT(A);
  
  if(K==1){
    co(0);
    return 0;
  }
  
  ll SUM[N];
  SUM[K-2]=1;
  for(int i=K-1; i<N; ++i){
    SUM[i]=(SUM[i-1]+COM(i,K-2))%MOD;
  }
  
  REP(i,N){
    if(i<=N-K) ans-=A[i]*SUM[N-i-2];
    if(K-1<=i) ans+=A[i]*SUM[i-1];
    ans%=MOD;
    if(ans<0) ans+=MOD;
  }
  
  co(ans);
  return 0;
}

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

#define max(a, b) ((a) > (b) ? (a) : (b))


int main(void) {
    int n;
    scanf("%d", &n);
    
    int *arr[3] = {
        malloc(sizeof(int) * n),
        malloc(sizeof(int) * n),
        malloc(sizeof(int) * n),
    };

    for(int i = 0; i < n; i++)
        scanf("%d %d %d", &arr[0][i], &arr[1][i], &arr[2][i]);
    
    int dp_last[3] = {0, 0, 0};
    int dp_curr[3] = {0, 0, 0};
    for(int i = 0; i < n; i++) {
        for(int x = 0; x < 3; x++) {
            for(int y = 0; y < 3; y++) {
                if(x == y)
                    continue;

                dp_curr[x] = max(dp_curr[x], dp_last[y] + arr[x][i]);
            }
        }

        dp_last[0] = dp_curr[0];
        dp_last[1] = dp_curr[1];
        dp_last[2] = dp_curr[2];
    }

    printf("%d\n", max(max(dp_last[0], dp_last[1]), dp_last[2]));

    return 0;
}





Measured memory_bytes: 1280
def dis(j,i):
    return abs(c[j]-a[i])+abs(d[j]-b[i])

n, m = map(int, input().split())
a, b = [0]*n, [0]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())
c, d = [0]*m, [0]*m
for i in range(m):
    c[i], d[i] = map(int, input().split())

close = 0
for i in range(n):
    for j in range(m-1):
        if dis(j+1,i) < dis(close, i):
            close = j+1
    print(close+1)
    close = 0


Measured memory_bytes: 3064
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    auto a = readints;
    a.sort!((a, b) => a > b);
    writeln(a.map!(e => e.to!string).join(" "));
}



Measured memory_bytes: 2500
while True:
    H,W = map(int,input().split())
    if H==W==0:
        break
    cnt = 0
    for y in range(H):
        str = ""
        for x in range(W):
            if ((~x)^y)&1:
                str+="#"
            else:
                str+="."
        print(str)
    print()

Measured memory_bytes: 5612
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(x) (x).begin(),(x).end()

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "Yes"; }
  string_type do_falsename() const { return "No"; }
};

void solve(ll N, vector<ll> x) {
  vector<int> res(N * N);
  vector<pair<int,int>> vec;
  REP(i,N) vec.emplace_back(x[i] - 1, i + 1);
  sort(ALL(vec));
  set<int> s;
  REP(i,N*N) s.insert(i);

  for (auto p: vec) {
    res[p.first] = p.second;
    s.erase(p.first);
  }
  for (auto p: vec) {
    REP(i,p.second - 1) {
      int num = *s.begin();
      s.erase(s.begin());
      if (num > p.first) { cout << false << endl; return; }
      res[num] = p.second;
    }
  }
  reverse(ALL(vec));
  for (auto p: vec) {
    REP(i,N-p.second) {
      int num = *prev(s.end());
      s.erase(prev(s.end()));
      if (num < p.first) { cout << false << endl; return; }
      res[num] = p.second;
    }
  }
  cout << true << endl;
  REP(i,N*N) cout << res[i] << " \n"[i == N * N - 1];
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll N;
	scanf("%lld", &N);
	vector<ll> x(N-1+1);
	for (int i = 0 ; i <= N-1 ; i++) {
	  scanf("%lld", &x[i]);
	}
	solve(N, x);
	return 0;
}


Measured memory_bytes: 13824
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from functools import reduce




INF = float('inf')
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 1000000007


n, m = LI()
graph = [[] for _ in range(n)]
for a, b in LIR(m):
    graph[a-1] += [b-1]
    graph[b- 1] += [a - 1]



cnt = 0

for l in list(permutations(range(n), n)):
    if l[0]:
        continue
    for i in range(n-1):
        if not l[i+1] in graph[l[i]]:
            break
    else:
        cnt += 1



print(cnt)

Measured memory_bytes: 47216
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cassert>
#include<vector>
#include<map>
#include<complex>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
template<class T> void vp(T &a,int size){rep(i,size)cout << a[i]<<" ";cout << endl;}

string solve(string &in){
  vector<char> tmp;;
  vector<vector<char> > a;
  rep(i,in.size()){
    if (in[i] == 'h')tmp.push_back(in[i]);
    else if (in[i] == 'g')tmp.push_back(in[i]),i++;//skip eg(g)
  }
  char last = 'a';
  vector<char> b;
  rep(i,tmp.size()){
    if (tmp[i] == last)a.push_back(b),b.clear();
    last = tmp[i];
    b.push_back(last);
  }
  a.push_back(b);

  /*
  rep(i,a.size()){
    rep(j,a[i].size())cout << a[i][j] <<" " ;
    cout << endl;
  }
  cout <<"---" << endl;
  */

  char ret;
  int len=-1;
  rep(i,a.size()){
    //rep(j,a[i].size())cout << a[i][j] <<" " ;cout << endl;
    //cout << a[i].size() <<" " << len << endl;
    if ((int)a[i].size() > len){
      //cout << a[i].size() <<" " << len << endl;
      //cout <<"true "<< endl;
      ret = a[i].back();
      len = a[i].size();
    }
  }
  return ret == 'g'?"egg":"chicken";
}


main(){
  string in;
  while(cin>>in){
    cout << solve(in) << endl;
  }
}

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

typedef long long int ll;
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a;
    cin >> n >> a;
    int rem = n%500;
    //cout << rem << endl;
    if(rem <= a){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    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 k = sc.nextInt();
		// System.out.println("k: " + k);
		int ans = -1;
		int cur = 0;
		for (int i = 1; i <= 1e7; i++) {
			cur = (cur * 10 + 7) % k;
			if (cur == 0) {
				ans = i;
				break;
			}
		}
		System.out.println(ans);
	}
}








Measured memory_bytes: 35500
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        String a = sc.next();

        if (a.toUpperCase().equals(a))
            System.out.println("A");
        else
            System.out.println("a");
    }
}


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

using namespace std;
#define pb push_back
int b[200005];

int main()
{
    int n;
    cin>>n;
    unordered_map<int,int>mp;
    unordered_map<int,int>::iterator it;
    for(int i=1; i<n; i++){
        int x;
        cin>>x;
        mp[x]++;
    }
    for(it=mp.begin(); it!=mp.end(); it++){
        b[(it->first)-1]=it->second;
    }
    for(int i=0; i<n; i++)cout<<b[i]<<endl;

    return 0;
}


Measured memory_bytes: 12264
#include<stdio.h>
#include<iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include<bits/stdc++.h>
using namespace std;
#define ll          long long
#define pb          push_back
#define pii         pair<long,long>
#define vi          vector<long>
#define vii         vector<pii>
#define mi          map<long,long>
#define mii         map<pii,long>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define fIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

ll sub(ll a, ll b){return (a-b+hell)%hell;}
ll add(ll a, ll b){return (a+b)%hell;}
ll mul(ll a, ll b){return (a*b)%hell;}



int main()
{
fIO;


/*#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif*/


long long n,t=1,m=0;
//cin >> t;
while(t--){
    ll k;
  cin>>n>>m;
vi a(n+1,0),b(n+1,0); 
ll co=0,wr=0,x;
rep(i,0,m){
    string s;
    cin>>x>>s;
    if(a[x]!=-1&&s=="WA")b[x]++;
    else if(a[x]!=-1&&s=="AC"){co++;a[x]=-1;}
}
ll cor=0;
rep(i,1,n+1){
    if(a[i]==-1)cor++;
}
rep(i,1,n+1){
    if(a[i]==-1)wr+=b[i];
}
cout<<cor<<" "<<wr;
}
	
}

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

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

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vector<string> S(N);
    REP(i,0,N) cin >> S[i];

    ll ab = 0, bxa = 0, xa = 0, bx = 0;
    REP(i,0,N) {
        ll M = SZ(S[i]);
        REP(j,0,M-1) {
            if(S[i][j] == 'A' && S[i][j+1] == 'B') ++ab;
        }
        if(S[i][0] == 'B' && S[i][M-1] == 'A') ++bxa;
        else if(S[i][0] == 'B' && S[i][M-1] != 'A') ++bx;
        else if(S[i][0] != 'B' && S[i][M-1] == 'A') ++xa;
    }

    if(xa > 0) {
        ab += bxa;
        --xa;
        ab += MIN(bx,xa+1);
    }
    else {
        if(bxa > 0) {
            ab += bxa-1;
            ab += MIN(bx,xa+1);
        }
        else {
            ab += MIN(xa,bx);
        }
    }

    PR(ab);


    return 0;
}

/*



*/

Measured memory_bytes: 3704
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n==0 || n==1){
    return dp[n]=1;
  }
  if(dp[n]!=-1){
    return dp[n];
  }
  return dp[n]=fib(n-1)+fib(n-2);
}

int main(){
  int n,i;
  for(i=0;i<50;i++){
    dp[i]=-1;
  }
  scanf("%d",&n);
  printf("%d\n",fib(n));

  return 0;
}



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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<pii, int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;
const int N = 1e6 + 5;


int32_t main() {
    fast;
    vi spf(N,-1);
    for(int i=2 ; i*i*1LL<N ; i++) if(spf[i] == -1){
       for(int j=2*i ; j<N ; j+=i) spf[j] = i;
    }

    int n;
    cin >> n;

    int a[n];
    f(i,0,n)    cin >> a[i];

    int cnt = 0;

    vi v(N,0);

    rf(i,n-1,0){
        set<int> s;
        int x = a[i];

        while(spf[x] != -1){
            s.insert(spf[x]);
            x /= spf[x];
        }
        if(x > 1) s.insert(x);

        int ok = 1;
        for(int x : s){
            if(v[x] > 0) ok = 0;
            v[x] = 1;
        }
        if(ok) cnt++;
        else{
            break;
        }
    }

    int gc = 0;
    f(i,0,n)    gc = __gcd(gc, a[i]);

    if(cnt == n){
        cout << "pairwise coprime";
    }
    else if(gc == 1){
        cout << "setwise coprime";
    }
    else{
        cout << "not coprime";
    }
}


Measured memory_bytes: 26676
import numpy as np
def DFS(answer,matrix,color,N,i):
    if not 0 in color:
        answer[0]+=1
    for j in range(N):
        if color[j]==0 and matrix[i][j]==1:
            color[j] = 1
            DFS(answer,matrix,color,N,j)
            color[j] = 0
    
def main():
    N,M = map(int,input().split())
    S = [list(map(int,input().split())) for _ in range(M)]
    matrix = np.zeros([N,N],dtype=np.int32)
    for s in S:
        matrix[s[0]-1][s[1]-1]=1
        matrix[s[1]-1][s[0]-1]=1
    color = [0]*N
    color[0] = 1
    answer = [0]
    DFS(answer,matrix,color,N,0)
    print(answer[0])
    

if __name__=='__main__':
    main()


Measured memory_bytes: 12516
#include <stdio.h>
typedef struct Dice{
	int	f[6];
}Dice;

int main(void)
{
	int n, upper, front, right, a, b, i, j;
	Dice D0 = {0};
	Dice Dw = {0};
	for(i=0; i<6; i++){
		scanf("%d", D0.f+i);
	}
	scanf("%d", &n);
	for(j=0; j<n; j++){
		scanf("%d%d", &upper, &front);
		a=0;
		while(*(D0.f+0) != upper){
			for(i=0; i<6; i++){
				*(Dw.f+i) = *(D0.f+i);
			}
			b = a % 2;
			switch(b){
				case 0:
					*(D0.f+0) = *(Dw.f+3);
					*(D0.f+2) = *(Dw.f+0);
					*(D0.f+3) = *(Dw.f+5);
					*(D0.f+5) = *(Dw.f+2);
					break;
				case 1:
					*(D0.f+0) = *(Dw.f+1);
					*(D0.f+1) = *(Dw.f+5);
					*(D0.f+4) = *(Dw.f+0);
					*(D0.f+5) = *(Dw.f+4);
					break;
				default:
					break;
			}
			a++;
		}
		if(front == *(D0.f+1)){
			right = *(D0.f+2);
		}else if(front == *(D0.f+2)){
			right = *(D0.f+4);
		}else if(front == *(D0.f+4)){
			right = *(D0.f+3);
		}else if(front == *(D0.f+3)){
			right = *(D0.f+1);
		}
		printf("%d\n", right);
	}
	return 0;
}

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

int main(){
	int N;
	long long Z,W,p,q;
	cin>>N>>Z>>W;
	cin>>q;
	for(int i=0;i<N-1;i++){
		p=q;
		cin>>q;
	}
	if(N>1){
		cout<<max(abs(p-q),abs(q-W))<<endl;
	}else{
		cout<<abs(q-W)<<endl;
	}
	return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define FOR(i,a,b) for(ll i = a ; i < b ; i++) // for i in range(a,b)
#define REP(i,n) for(ll i = 0 ; i < n ; i++) // for i in range(b)
#define FORD(i,a,b) for(ll i = a ; i > b ; i--) // for i in range(a,b,-1)
#define ALL(x) x.begin(),x.end()

#define DEBUG(x) cerr << #x << ": " << x << '\n'
#define DEBUGL(xl) dbgl_f(#xl,xl)
#define DEBUGLL(xll) dbgll_f(#xll,xll)
template<class T> void dbgl_f(string name, vector<T> xl){cerr<<name<<": "; for(T x: xl) cerr<<x<<" "; cerr << '\n';}
template<class T> void dbgll_f(string name, vector<vector<T>> xll){
    cerr<< name << ": " << '\n'; 
    for(vector<T> xl: xll){
        for(T x : xl) cerr << x << " ";
        cerr << '\n';
    }
}

const int IINF = 1'001'001'001;
const ll INF = 1'001'001'001'001'001'001ll;
const int MOD = 1'000'000'007;


void solve(){
    int n,m; cin >> n >> m;
    vector<P> abl;
    REP(i,m){
        int a,b; cin >> a >> b;
        abl.push_back(P(a,b));
    }
    sort(abl.begin(), abl.end());
    int curr_l = 0;
    int curr_r = 0;
    int ans = 0;
    for( P ab : abl ){
        int a = ab.first;
        int b = ab.second;
        if(a < curr_r && curr_r <= b){
        }
        else if( b < curr_r ){
            curr_r = b;
        }
        else if( a >= curr_r ){
            ans += 1;
            curr_r = b;
        }
    }
    cout << ans << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}

Measured memory_bytes: 5308
#include<stdio.h>

int main(void){
	int a,b,c,d,n;
	int count=0;
	
	while(scanf("%d", &n) != EOF){
		count=0;
	for(a=0;a<10;a++){
		for(b=0;b<10;b++){
			for(c=0;c<10;c++){
				for(d=0;d<10;d++)
					if((a+b+c+d) == n) count++;
			};};};
			printf("%d\n", count);
	};
	return (0);
}

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

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;


//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}


int main(){
  int N;
  cin >> N;
  int rate;
  set<int> rating;
  int cnt = 0;
  rep(i,N){
    cin >> rate;
    if(rate >= 3200) cnt++;
    else rating.insert(rate/400);
  }
  int minAns = max(1,(int)rating.size());
  cout << minAns << " " << rating.size()+cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=250000+50;
ll  num[maxn];
ll sum[maxn];
ll he(ll n){
        if(n==1)
                return 0;
        if(n==0)
                return 0;
        return (n*(n-1))/2;
}
map<ll,int>mp;
int main()
{
    //std::ios::sync_with_stdio(false);
    int n;
    scanf("%d",&n);
    long long summ=0;
    memset(sum,0,sizeof(sum));
    for(int i=1;i<=n;i++){
        scanf("%lld",&num[i]);
        sum[i]=sum[i-1]+num[i];
    }
    for(int i=1;i<=n;i++){
        if(mp[sum[i]]==0)mp[sum[i]]++;
        else{
                mp[sum[i]]++;
        }

    }
    map<ll,int>::iterator it;
    for(it=mp.begin();it!=mp.end();it++){
        //cout<<it->first<<" "<<it->second<<endl;
        if(it->first==0)
        summ+=(he(it->second)+(it->second));
        else if(it->second>1){
                if(it->first!=0)
                        summ+=he(it->second);

        }

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


Measured memory_bytes: 16256
# coding: utf-8
num_N = int(input())
l_num = list(map(int, input().split()))
l_num.sort()

num_div = num_N // 2

if num_N % 2 == 1:
    l_cor = [0]
    for i in range(1, num_div + 1):
        l_cor.append(i * 2)
        l_cor.append(i * 2)

else:
    l_cor = []
    for i in range(1, num_div + 1):
        l_cor.append(2 * i - 1)
        l_cor.append(2 * i - 1)

if l_num == l_cor:
    print((2 ** num_div) % (10 ** 9 + 7))

else:
    print(0)

Measured memory_bytes: 13812
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

ans = 0
for i in range(n-1):
  num = i // 2
  num += 1
  if i == 0:
    ans += a[i]
  else:
    ans += a[i-num+1]
print(ans)

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

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

	int cnt = 0;
	for (int i = 0; i < s.size(); i++) {
		if (((i + 1) % 2) == 1) {
			if (s.at(i) == 'L') cnt++;
		}
		else {
			if (s.at(i) == 'R') cnt++;
		}
	}

	if (cnt == 0) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
require 'set'

def main
  loop do
    n,h = gets.chomp.split(' ').map(&:to_i)
    break if (n|h) == 0
    get_non_hole_cubes_num(n, h)
  end
end

def get_non_hole_cubes_num n, h
  hole_cubes = Set.new

  h.times do
    c,a,b = gets.chomp.split(' ')
    case c
    when 'xy'
      x = a.to_i
      y = b.to_i
      1.upto(n) do |idx|
        hole_cubes << "#{x} #{y} #{idx}"
      end
    when 'xz'
      x = a.to_i
      z = b.to_i
      1.upto(n) do |idx|
        hole_cubes << "#{x} #{idx} #{z}"
      end
    when 'yz'
      y = a.to_i
      z = b.to_i
      1.upto(n) do |idx|
        hole_cubes << "#{idx} #{y} #{z}"
      end
    end
  end

  puts n * n * n - hole_cubes.size
end

main

Measured memory_bytes: 12836
from math import factorial

inputnum = input().split()
N = int(inputnum[0])
M = int(inputnum[1])
ans = 0
if N >= 2:
  ans+= factorial(N) / factorial(2) / factorial(N - 2)
  
if M >= 2:
  ans += factorial(M) / factorial(2) / factorial(M - 2)
  
print(int(ans))


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

int main() {

	string s; cin >> s;

	int n = s.size();

	int ans1 = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (s[i] == '0') {
				ans1++;
			}
		}
		else {
			if (s[i] == '1') {
				ans1++;
			}
		}
	}

	int ans2 = 0;
	for (int i = 0; i < n; i++) {
		if (i % 2 == 0) {
			if (s[i] == '1') {
				ans2++;
			}
		}
		else {
			if (s[i] == '0') {
				ans2++;
			}
		}
	}

	cout << min(ans1, ans2) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
using namespace std;
using ll = long long;

int main()
{
    // 整数の入力
    ll N;
    cin >> N;
    vector<pair<ll, ll>> dots;
    map<pair<ll, ll>, ll> counter;
    for (int i = 0; i < N; i++)
    {
        ll x, y;
        cin >> x >> y;
        dots.push_back(make_pair(x, y));
    }

    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            if (i == j){
                continue;
            }
            ll diff_x = dots[i].first - dots[j].first;
            ll diff_y = dots[i].second - dots[j].second;
            counter[make_pair(diff_x, diff_y)]++;
        }
    }

    ll max_count = 0;
    pair<ll, ll> ma_p;
    for (auto a : counter)
    {
        if (max_count < a.second)
        {
            max_count = a.second;
            ma_p = a.first;
        }
        // cout << a.first.first << a.first.second << a.second << endl;
    }
    // cout << counter[ma_p] << endl;
    cout << N - counter[ma_p] << endl;

    return 0;
}

Measured memory_bytes: 384
n, k = map(int, input().split())
s = str(input())

t =  ''
for i in range(n):
    if i == k - 1:
        if s[i] == 'A':
            t = t + 'a'
        elif s[i] == 'B':
            t = t + 'b'
        else:
            t = t + 'c'
    else:
        t = t + s[i]

print(t)

Measured memory_bytes: 3060