akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <queue>
#include <algorithm>
using namespace std;

const int maxn = 20 + 3;

int h, w;
char maze[maxn][maxn];
bool already[maxn][maxn];

inline bool out(int x, int y) {
  if (x < 0 || x >= h || y < 0 || y >= w) return true;
  else return false;
}

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

struct Node {
  int x, y, cnt;
  Node(int a, int b, int c): x(a), y(b), cnt(c) {}
};

int solve(int stx, int sty) {
  memset(already, 0, sizeof(already));
  queue<Node> q;
  while (!q.empty()) q.pop();
  q.push(Node(stx, sty, 0));
  already[stx][sty] = true;
  int ans = 0;
  while (!q.empty()) {
    Node buf = q.front(); q.pop();
    ans = max(ans, buf.cnt);
    for (int i = 0; i < 4; i++) {
      int nx = buf.x + dx[i];
      int ny = buf.y + dy[i];
      if (!out(nx, ny) && maze[nx][ny] != '#' && !already[nx][ny]) {
        already[nx][ny] = true;
        q.push(Node(nx, ny, buf.cnt + 1));
      }
    }
  }
  return ans;
}

int real_solve() {
  int ans = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++)
      if (maze[i][j] == '.') ans = max(ans, solve(i, j));
  return ans;
}

int main() {
  //freopen("input.txt", "r", stdin);
  while (~scanf("%d%d", &h, &w)) {
    memset(maze, 0, sizeof(maze));
    for (int i = 0; i < h; i++) scanf("%s", maze[i]);
    printf("%d\n", real_solve());
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int a[5];
    int i,swap,j;
    
    while(scanf("%d,%d,%d,%d,%d",&a[0],&a[1],&a[2],&a[3],&a[4])!=EOF){
        for(j=0;j<5;j++){
            for(i=4;i>=j;i--){
                if(a[i]<a[i-1]){
                    swap=a[i];
                    a[i]=a[i-1];
                    a[i-1]=swap;
                }
            }
        }
        //printf("%d,%d,%d,%d,%d\n",a[0],a[1],a[2],a[3],a[4]);
        if((a[0]==a[1]&&a[0]==a[2]&&a[0]==a[3])||(a[1]==a[2]&&a[1]==a[2]&&a[1]==a[3]&&a[1]==a[4])){
            printf("four card\n");
        }
        else if((a[0]==a[1]&&a[0]==a[2]&&a[3]==a[4])||(a[0]==a[1]&&a[2]==a[3]&&a[2]==a[4])){
            printf("full house\n");
        }
        else if((a[0]+1==a[1]&&a[1]+1==a[2]&&a[2]+1==a[3]&&a[3]+1==a[4])||(a[0]==1&&a[1]==10&&a[2]==11&&a[3]==12&&a[4]==13)){
            printf("straight\n");
        }
        else if((a[0]==a[1]&&a[0]==a[2])||(a[1]==a[2]&&a[1]==a[3])||(a[2]==a[3]&&a[2]==a[4])){
            printf("three card\n");
        }
        else if((a[0]==a[1]&&a[2]==a[3])||(a[0]==a[1]&&a[3]==a[4])||(a[1]==a[2]&&a[3]==a[4])){
            printf("two pair\n");
        }
        else if((a[0]==a[1])||(a[1]==a[2])||(a[2]==a[3])||(a[3]==a[4])){
            printf("one pair\n");
        }
        else
            printf("null\n");
        
    }
    return 0;
}

Measured memory_bytes: 576
import math
X = int(input())
beki = []
beki.append(1)
Xruto = math.sqrt(X)
Xruto = math.floor(Xruto)
for i in range(2, Xruto+1):
    for j in range(10):
        a = pow(i, j)
        if a <= X:
            beki.append(a)
        else:
            break
print(max(beki))


Measured memory_bytes: 9124
#include <iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
bool l[26]={1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,1,1,1,0,1,1,1,0,1};
int main(){
	while(true){
		string s;
		cin >> s;
		if(s[0]=='#') break;
		bool now=l[s[0]-'a'];
		int cnt=0;
		rep(i,s.size()){
			if(l[s[i]-'a']!=now) cnt++;
			now=l[s[i]-'a'];
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1184
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		String ans = ""+ (int) (N + Math.pow(N, 2) + Math.pow(N, 3));
		System.out.println(ans);
	}
}


Measured memory_bytes: 38740
#include <stdio.h>

int main(void){

  int a,b,c,x;

  x=0;

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

  if(a>b){

    x=a;

    a=b;

    b=x;

}

   if(b>c){

    x=b;

    b=c;

    c=x;

}


      if(a>b){

        x=a;

       a=b;

      b=x;

}

  printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <map>
#include <stack>
#include <string>
#include <list>
#include <set>
#include <queue>
#include <deque>
#include <math.h>
using namespace std;

typedef pair<int, int> P;
#define ll long long
#define int ll
#define INF (1LL<<60)
#define mod 1000000007
int dx[4] = { 0, 1, 0, -1 };
int dy[4] = { 1, 0, -1, 0 };


signed main(){

	string s;
	cin >> s;

	for (int n = 0; n < 8; n++){
		int sum = s[0] - '0';
		for (int m = 0; m < 3; m++){
			if ( (n>>m) %2 == 1){
				sum += s[m + 1] - '0';
			}
			else{
				sum -= s[m + 1] - '0';
			}
		}
		if (sum == 7){
			cout << s[0];
			for (int m = 0; m < 3; m++){
				if ((n >> m) % 2 == 1){
					cout << "+" << s[m + 1];
				}
				else{
					cout << "-" << s[m + 1];
				}
			}
			cout << "=7" << endl;
			return 0;
		}
	}

	return 0;
}


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

int main(){
  char ch;
  int cnt[26] = {};
  while(cin >> ch){
    if('a' <= ch && ch <= 'z'){
      cnt[ch - 'a']++;
    }
    else if('A' <= ch && ch <= 'Z'){
      cnt[ch - 'A']++;
    }
  }
  for(int i = 0; i < 26; i++){
    printf("%c : %d\n", 'a' + i, cnt[i]);
  }
}



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

//---------------------------------------------------------------
// ------ graph ------ //
using Weight = int;
using Flow = int;
struct Edge {
    int src, dst;
    Weight weight;
    Flow cap;
    Edge() : src(0), dst(0), weight(0) { }
    Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) { }
};
bool operator < (const Edge &e, const Edge &f) {
    return e.weight != f.weight ? e.weight > f.weight : // pqが降順のため
        e.src != f.src ? e.src < f.src : e.dst < f.dst;
}
using Edges = vector<Edge>;
struct Graph {
    vector<Edges> adj;
    Graph(int n) : adj(n) { }
    int size() { return adj.size(); }
    Edges operator [] (int v) { return adj[v]; }
    void add_edge(int a, int b, Weight w = 1) { // graph
        adj[a].emplace_back(a, b, w);
        adj[b].emplace_back(b, a, w);
    }
    void add_arc(int a, int b, Weight w = 1) {  // digraph
        adj[a].emplace_back(a, b, w);
    }
};
using Array = vector<Weight>;
using Matrix = vector<Array>;
//---------------------------------------------------------------

int is_bipartite(Graph &G) {
    int n = G.size();
    vector<int> color(n, -1);
    int cntW = 0;
    function<bool(int, int)> dfs = [&](int u, int c) {
        if ((color[u] = c) > 0) cntW++;
        for (Edge &e : G[u]) {
            int v = e.dst;
            if (color[v] == c) return false;
            if (color[v] < 0 && !dfs(v, 1 - c)) return false;
        }
        return true;
    };
    if (!dfs(0, 0)) return -1;
    return cntW;
}

int main() {
    int V, E; cin >> V >> E;
    Graph G(V);
    for (int i = 0; i < E; i++) {
        int a, b; cin >> a >> b;
        G.add_edge(a - 1, b - 1);
    }
    int cntW = is_bipartite(G);
    if (cntW < 0) {
        cout << ((long long)V * (V - 1) / 2 - E) << endl;
    } else {
        int cntB = V - cntW;
        cout << ((long long)cntB * cntW - E) << endl;
    }
    return 0;
}

Measured memory_bytes: 9984
// Author: getharshkumar

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

int main()
{
    ll n, s = 0, c = 0, ans = 1e18;
    cin >> n;
    vector<ll> a(n);
    for (ll &e : a)
        cin >> e, s += e;
    for (ll e : a)
        c += e, ans = min(ans, abs(2 * c - s));
    cout << ans;
    return 0;
}

Measured memory_bytes: 1920
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            decimal iR = decimal.Parse(sS[0]);

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            decimal iOut = 2M * iR * (decimal)Math.PI;

            // 出力
            System.Console.WriteLine("{0}", iOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 27500
def f_pure():
    # 参考: http://drken1215.hatenablog.com/entry/2019/09/29/012000
    from collections import deque
    N, M = [int(i) for i in input().split()]

    graph = [[] for _ in range(N)]
    for _ in range(M):
        a, b = [int(i) for i in input().split()]
        graph[a - 1].append(b - 1)

    shortest = N + 1
    ans = []
    for s in range(N):
        # 頂点sから他の辺へ行くには何個の頂点を辿る必要があるか計算する
        dist = [-1] * N
        previous = [-1] * N  # [n]: 頂点nへはどこから来たか
        queue = deque([s])
        dist[s] = 0
        while queue:
            v = queue.pop()
            for next_node in graph[v]:
                if dist[next_node] == -1:
                    dist[next_node] = dist[v] + 1
                    previous[next_node] = v
                    queue.appendleft(next_node)

        for t in range(N):
            if t == s or dist[t] == -1:
                continue  # 頂点tは始点と同じ、または、始点から到達不可能
            for next_node in graph[t]:
                if next_node == s:  # ループ完成
                    ans_tmp = [s]  # 解になりうる頂点集合
                    current_node = t
                    # 頂点tからsまで巻き戻していく
                    while current_node != s:
                        ans_tmp.append(current_node)
                        current_node = previous[current_node]
                    # 頂点集合の濃度が減少した
                    if shortest > len(ans_tmp):
                        shortest = len(ans_tmp)
                        ans = ans_tmp

    if shortest == N + 1:
        return -1  # 閉路がなかった。条件を満たす頂点集合はない
    return ' '.join(map(str, [len(ans)] + sorted(v + 1 for v in ans)))

print(f_pure())

Measured memory_bytes: 3572
#![allow(unused_imports)]
#![allow(unused_variables)]
use proconio::input;
use proconio::marker::*;
use std::cmp::{min, max};
use std::collections::{HashSet, HashMap, BinaryHeap};

fn main() {
    input! {
        d: usize,
        t: usize,
        s: usize,
    }
    let ans = if t * s >= d {"Yes"} else {"No"};
    println!("{}", ans);
}


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

using namespace std;
int main() {
  
 	size_t n, k;
  	cin >> n >> k;
  vector<int> p(n);
  for(size_t i = 0; i < n; i++) 
    cin >> p[i];
  sort(p.begin(), p.end());
  for(size_t i = 1; i < n; i++) {
    p[i] = p[i] + p[i - 1];
  }
  cout << p[k - 1];
  return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
//*******************
// Mahmoud Magdy    *
//*******************
#define ll long long
#define endl "\n"

void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m ;
    cin>>m;
    return m ;
}
int fr[100006];
int main()
{
int n=D();
int c=0;
for(int i=0;i<n;++i){
    int a=D();
    if(a>n)
        c++;
    else
        fr[a]++;
}
for(int i=1;i<=n;++i)
{
    if(fr[i]!=i){
        if(i>fr[i])
            c+=fr[i];
        else
            c+=fr[i]-i;
    }
}
cout<<c<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int nmax=1e5+3;
typedef long long ll;
char s1[nmax],s2[nmax];
ll t,p1,p2,r1,r2,n,m;
int main()
{
    cin>>n>>m;
    cin>>s1;
    cin>>s2;
    t=(n*m)/__gcd(n,m);
    p1=0;
    p2=0;
    r1=t/n;
    r2=t/m;
    while(p1<n&&p2<m)
    {
        if(p1*r1+1==p2*r2+1)
        {
            if(s1[p1]!=s2[p2])
            {
                cout<<-1;
                return 0;
            }
            ++p1;
            ++p2;
            continue;
        }
        if(p1*r1>p2*r2)
        {
            ++p2;
            continue;
        }
        ++p1;
    }
    cout<<t;
    return 0;
}


Measured memory_bytes: 384
//
//  main.cpp
//  CppTest
//
//  Created by Ryu on 2017/02/08.
//  Copyright ?? 2017??´ Ryu. All rights reserved.
//

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
using namespace std;

long gcd(long x, long y){
    if (x > y) {
        if(x % y == 0){
            return y;
        }else{
            return gcd(y, x % y);
        }
    }else{
        if (y % x == 0) {
            return x;
        }else{
            return gcd(x, y % x);
        }
    }
}

int main(int argc, const char * argv[]) {
    // insert code here...
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long a[50], b[50], g[50], l[50];
    int n = 0;
    while (cin >> a[n] >> b[n]){
        g[n] = gcd(a[n], b[n]);
        l[n] = a[n] * b[n] / g[n];
        //printf("d: %f, x: %.4f, y: %.4f\n", d, x[n], y[n]);
        n++;
    }
    
    
    for(int i = 0; i < n; i++){
        printf("%ld %ld\n", g[i], l[i]);
    }
    
    
    return 0;
}

Measured memory_bytes: 3120
import java.util.*;


public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        int count = 0;
        while(a <= b){
            count++;
            a*=2;
        }

        System.out.println(count);
    }
}


Measured memory_bytes: 21844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl;
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   " << endl;
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}
 



const int D = 365;
vector<int> c(26, 0);
vector<vector<int>> s(D, vector<int>(26, 0));

ll calc_score(vector<int> &t){
  vector<int> last(26, -1);
  ll score = 0;
  for(int d=0; d<D; d++){
    int type = t[d];
    score += s[d][type];
    last[type] = d;
  
    for(int i=0; i<26; i++){
      score = score - c[i] * (d - last[i]);
    }
  }
  return score;
}

vector<int> best_oneday(vector<int> &t){
    int type = 0;
    vector<int> last(26, -1);
    for(int d=0; d<D; d++){
    
        ll score = 0;// d日目のみで得られるスコア
        for(int j=0; j<26; j++){
            vector<int>  saigo = last;
            ll get = s[d][j];
            saigo[j] = d;
            for(int k=0; k<26; k++){
              get -= c[k] * (d-saigo[k]);
            }
            if(get > score){
              type = j;
              score = get;
            }      
        }
    last[type] = d; 
    t[d] = type;  
    //cout << " (d, type): (" << d << ", " << type << ")  s[d][type]: " << s[d][type] << endl;
    //cout << type + 1 << endl;
  }
  return t;
}

int main(){
  // int D;
  // cin >> D;
  int tmp;
  cin >> tmp;
  //vector<int> c(26, 0);
  for(int i=0; i<26; i++) cin >> c[i];
  //vector<vector<int>> s(D, vector<int>(26, 0));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }


  
  vector<int> t(D);
  t = best_oneday(t);  

  const int LOOP = 100;
  for(int i=0; i<LOOP; i++){
    
    
  }
  for(int i=0; i<D; i++){
    cout << t[i] + 1 << endl;
  }
 
    
}


Measured memory_bytes: 3656
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

//#include<boost/circular_buffer.hpp>
using namespace std;

//cout << fixed << setprecision(10);
typedef long long ll;
#define PI 3.141592653589793
#define Yes(a) a ? "Yes" : "No";
#define YES(a) a ? "YES" : "NO";
#define rep(i,n) for(int i=0;i<n;i++)

int gcd(int a, int b) {
	if (a < b) {
		int tmp = a;
		a = b;
		b = tmp;
	}
	int r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}
	return b;
}

int lcm(int a, int b) {
	long long int L;
	L = (a * b) / gcd(a, b);
	return L;
}

vector<long long  int> Prime;
void Eratosthenes(long long int n) {
	vector<bool> is_prime(n, true);
	for (int i = 2; i * i <= n; i++) {
		;
		if (is_prime.at(i)) {
			for (int j = i * i; j <= n; j += i) {
				is_prime.at(j) = false;
			}
		}
		Prime.emplace_back(i);
	}
}

/*
map<int, int> prime;
void Prime_number(long long int n) {
	for (int i = 2; i <= n; i++) {
		int count = 0;
		while (n % i == 0) {
			count++;
			n /= i;
		}
		if (count != 0) {
			prime.insert(make_pair(i, count));
		}
	}
}
*/
//std::cout.fill('0');

int main() {
	int n;
	string s;
	string str[7] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
	int k = 0;

	cin >> s;
	rep(i, 7) if (s == str[i]) { k = i; }
	cout << 7-k << endl;
}

Measured memory_bytes: 256
import sys
from collections import *
import heapq
import math
import bisect
from itertools import permutations,accumulate,combinations,product
from fractions import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]

def serch(dp,i,j,k,now):
    if i<0:
        return ""
    # print(i,j,k,now)
    # print(dp[i])
    for l in range(3):
        if j+l-1==-1:
            continue
        if now+dp[i][j+l-1]<k:
            now+=dp[i][j+l-1]
        else:
            return str(j+l-1)+serch(dp,i-1,j+l-1,k,now)

k=int(input())
dp=[[0]*10 for i in range(10)]
for i in range(10):
    dp[0][i]=1
# print(dp)

for i in range(1,10):
    for j in range(10):
        if j==0:
            dp[i][j]+=dp[i-1][j]
            dp[i][j+1]+=dp[i-1][j]
        elif j==9:
            dp[i][j-1]+=dp[i-1][j]
            dp[i][j]+=dp[i-1][j]
        else:
            dp[i][j-1]+=dp[i-1][j]
            dp[i][j]+=dp[i-1][j]
            dp[i][j+1]+=dp[i-1][j]
# for i in range(10):
#     dp[i][0]=0
# print(dp)

now=0
for i in range(10):
    for j in range(1,10):
        if now+dp[i][j]<k:
            now+=dp[i][j]
            continue
        else:
            # print(k,now,j)
            ans=str(j)
            ans+=serch(dp,i-1,j,k,now)
            print(ans)
            quit()



Measured memory_bytes: 65388
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n;
    cin >> n;
    for(int i=0; i<100000; i++){
        if(n<i*i){
            cout << (i-1)*(i-1) << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
  long n,a,b;
  long blue=0;
  
  scanf("%ld %ld %ld",&n,&a,&b);
  
  blue+=(n/(a+b)*a);
  if(n%(a+b)<a){
    blue+=(n%(a+b));
  } else {
    blue+=a;
  }
  printf("%ld",blue);
}

Measured memory_bytes: 128
fn main() {
	let mut s = String::new();
	use std::io::Read;
	std::io::stdin().read_to_string(&mut s).unwrap();
	let mut s = s.split_whitespace();
	let n: usize = s.next().unwrap().parse().unwrap();
	let m: usize = s.next().unwrap().parse().unwrap();
	let mut bit = BIT::new(m + 1);
	let mut q = vec![vec![]; m];
	for _ in 0..n {
		let l: usize = s.next().unwrap().parse().unwrap();
		let r: usize = s.next().unwrap().parse().unwrap();
		q[r - l].push((l, r));
	}

	use std::io::Write;
	let out = std::io::stdout();
	let mut out = std::io::BufWriter::new(out.lock());
	let mut f = n as i32;
	for d in 1..=m {
		writeln!(
			out,
			"{}",
			f + (d..=m).step_by(d).fold(0, |r, i| r + bit.sum(i + 1))
		)
		.unwrap();
		f -= q[d - 1].len() as i32;
		for &(l, r) in q[d - 1].iter() {
			bit.add(l, 1);
			bit.add(r + 1, -1);
		}
	}
}

pub struct BIT<T> {
	data: Vec<T>,
}

impl<T> BIT<T>
where
	T: Clone + Default + std::ops::Add<Output = T>,
{
	pub fn new(n: usize) -> Self {
		Self {
			data: vec![T::default(); n],
		}
	}

	pub fn sum(&self, i: usize) -> T {
		let mut r = T::default();
		let mut i = i;
		while i > 0 {
			r = r + self.data[i - 1].clone();
			i &= i - 1;
		}
		r
	}

	pub fn add(&mut self, i: usize, value: T) {
		let mut i = i;
		while i < self.data.len() {
			self.data[i] = self.data[i].clone() + value.clone();
			i |= i + 1;
		}
	}
}


Measured memory_bytes: 14420
#include <bits/stdc++.h>
using namespace std;
struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20);} } fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c){
    return b / c - (a - 1) / c;
}

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}



int main() {
    int x, a, b;
    cin >> x;
    a = x / 100;
    b = x % 100;
    if (b == 0){
        cout << 1 << endl;
        return 0;
    }
    if (b <= a * 5){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
}

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

vector<vector<ll>> adj, radj;
vector<ll> grundy;


int main() {
  int N; cin >> N;
  adj.resize(N); radj.resize(N);
  rep(i,N) { ll p; cin >> p; p--; adj[p].push_back(i); radj[i].push_back(p); }

  grundy.resize(N,-1); 
  ll tos[N] = {}; rep(i,N) tos[i] = adj[i].size();
  queue<ll> leaf; rep(i,N) if (tos[i]==0) leaf.push(i);
  while (leaf.size()) {
    ll now = leaf.front(); leaf.pop();
    for (auto x: radj[now]) { tos[x]--; if (tos[x]==0) leaf.push(x); }
    set<ll> used; for (auto x: adj[now]) used.insert(grundy[x]); 
    grundy[now] = 0; while (used.count(grundy[now])) grundy[now]++;
  }

  vector<ll> f(N), s(N);
  rep(i,N) {
    if (grundy[i]==-1) {
      set<ll> used; for (auto x: adj[i]) used.insert(grundy[x]);
      f[i] = 0;      while (used.count(f[i])) f[i]++;
      s[i] = f[i]+1; while (used.count(s[i])) s[i]++;
    }
  } 

  // debug(all(grundy));
  // debug(all(f)); debug(all(s));

  ll st = 0; while (grundy[st]!=-1) st++;
  vector<ll> gf = grundy, gs = grundy;
  ll nf = st; gf[nf] = f[nf]; 
  ll ns = st; gs[ns] = s[ns]; 

  bool okf = false, allf = false;
  while (!allf) {
    for (auto x: radj[nf]) {
      if (grundy[x]==-1) {
        if (gf[x]==-1) {
          gf[x] = gf[nf]==f[x] ? s[x] : f[x];
          nf = x;
          break;
        }
        else {
          if (gf[nf]!=f[x]) okf = true;
          allf = true;
          break;
        }
      }
    }
  }
  bool oks = false, alls = false;
  while (!alls) {
    for (auto x: radj[ns]) {
      if (grundy[x]==-1) {
        if (gs[x]==-1) {
          gs[x] = gs[ns]==f[x] ? s[x] : f[x];
          ns = x;
          break;
        }
        else {
          if (gs[ns]==f[x]) oks = true;
          alls = true;
          break;
        }
      }
    }
  }
  // cout << okf << endl; debug(all(gf));
  // cout << oks << endl; debug(all(gs));

  string result = okf||oks ? "POSSIBLE" : "IMPOSSIBLE";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 33184
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,L=MI()
    A=LI()
    pos = False
    idx = 0
    for i in range(N-1):
        if A[i]+A[i+1] >= L:
            pos = True
            idx = i
    if pos:
        print("Possible")
        for i in range(N-1):
            if i!=idx:
                print(i+1)
            else:
                break
        for i in range(N-1)[::-1]:
            if i!=idx:
                print(i+1)
            else:
                break
        print(idx+1)
    else:
        print("Impossible")

if __name__ == '__main__':
    main()

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

// 私は一瞬ライブラリ貼りました，ごめんなさい [luma]
// ごめんなさい

constexpr int mod = 998244353;

ll modpow(ll a, ll b) {
  a = a % mod;
  ll r = 1;
  while(b) {
    if(b & 1) r = r * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return r;
}

ll inv(ll x) {
  return modpow(x, mod - 2);
}

using tree = vector<vector<int>>;
int n;

ll sol1(tree & a, tree & b) {
  vector<ll> A(n), B(n);
  for(int i = 0; i < n; i++) A[i] = a[i].size() - 1, B[i] = b[i].size() - 1;
  ll Asum = 0, Bsum = 0;
  for(int i = 0; i < n; i++) Asum += A[i], Bsum += B[i];
  Bsum %= mod;
  ll res = 0;
  for(int i = 0; i < n; i++) res += ll(A[i]) * (Bsum - B[i]) % mod;
  res %= mod;
  res = res * inv(4) % mod;
  return res;
}

ll sol2(tree & a, tree & b) {
  vector<ll> A(n), B(n);
  for(int i = 0; i < n; i++) A[i] = a[i].size() - 1, B[i] = b[i].size() - 1;
  ll res = 0;
  for(int i = 0; i < n; i++) res += A[i] * ll(n - 1 - b[i].size()) % mod;
  res %= mod;
  res = res * inv(8) % mod;
  return res;
}

ll sol3(tree & a, tree & b) {
  vector<set<int>> bs(n);
  for(int i = 0; i < n; i++) for(auto e : b[i]) bs[i].insert(e);
  ll res = 0;
  for(int i = 0; i < n; i++) {
    for(int j : a[i]) if(i < j) {
      res += ll(n) - 1 - ll(b[i].size()) - ll(b[j].size());
      int f = bs[i].count(j);
      res += f;
    }
  }
  res %= mod;
  res = res * inv(16) % mod;
  return res;
}

ll sol4(tree & a) {
  vector<ll> A(n);
  for(int i = 0; i < n; i++) A[i] = a[i].size() - 1;
  ll res1 = 0;

  for(int i = 0; i < n; i++) res1 += A[i];

  res1 %= mod;
  res1 = res1 * inv(2) % mod;

  ll res2 = 0;

  res2 += n - 1;

  res2 = res2 * inv(4) % mod;

  ll res = (res1 - res2 + mod) % mod;
  return res;
}

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n;
  tree T(n), U(n);
  for(int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    T[a].push_back(b);
    T[b].push_back(a);
  }
  for(int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    U[a].push_back(b);
    U[b].push_back(a);
  }

  ll ans = 0;

  ans += sol1(T, U);

  ans -= sol2(U, T);
  ans -= sol2(T, U);

  ans += sol3(T, U);

  ans += sol4(T);
  ans += sol4(U);

  ans += 1;

  ans = (ans % mod + mod) % mod;

  cout << ans << endl;
  return 0;
}



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

int node[100100];

main()
{
	int n,m;
	scanf("%d %d",&n,&m);
	for(int i=0;i<m;i++)
	{
		int a,b;
		scanf("%d %d",&a,&b);
		node[a]++;
		node[b]++;
	}
	for(int i=1;i<=n;i++)
	{
		if(node[i]%2!=0)
		{
			printf("NO\n");
			return 0;
		}
	}
	printf("YES\n");
}

Measured memory_bytes: 768
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <stdio.h>

using namespace std;

#define fo(i,n) for(int i=0; i<(int)n; i++)
#define rep(it,s) for(__typeof((s).begin()) it=(s).begin();it!=(s).end();it++)
#define mp(a,b) make_pair(a,b)
#define pb(x) push_back(x)
#define pii pair<int,int>

int p[50];
int t[50];
int n;
int dp[50][5];
bool vis[50][5];
int bad[50];

int solve(int i, int cur) {
	if (i==n+1) return p[i-1];
	if (vis[i][cur]) return dp[i][cur];
	
	int tmp = -1;
	
	if (cur==3) {
		if ((p[i]+p[i-1]*4) > t[i]-t[i-1]) {
			dp[i][cur] = -1;
			vis[i][cur] = 1;
			return -1;
		}
		bad[i] = 0;
		int d = (p[i]+p[i-1]);
		if (solve(i+1,1)!=-1)
			d += solve(i+1,1);
		else d = -1;
		bad[i] = 0;
		dp[i][cur] = d;
		vis[i][cur] = 1;
		return d;
	}
	else {
		int d = -1;
		if ((p[i]+p[i-1]*(cur+1)) <= t[i]-t[i-1]) {
			d = p[i]+p[i-1];
			if (solve(i+1,1)!=-1) 
				d += solve(i+1,1);
			else d = -1;
			bad[i] = 0;
		}
		if (abs(p[i]-p[i-1])*(cur+1) <= t[i]-t[i-1]) {
			int tmp;
			tmp = abs(p[i]-p[i-1]);
			if (solve(i+1,cur+1)!=-1)
				tmp += solve(i+1,cur+1);
			else tmp = -1;
			if (d==-1) d = tmp;
			else if (tmp!=-1 && d!=-1) d = min(tmp,d);
			bad[i] = 0;
		}
		dp[i][cur] = d;
		vis[i][cur] = 1;
		return d;
	}
	return 0;
}

int main() {

    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);

	while (scanf("%d",&n) && n!=0) {
		for (int i=1; i<=n; i++) scanf("%d%d",p+i,t+i);
		
		t[0] = 0;
		p[0] = 0;
		
		for (int i=0; i<=n; i++) for (int k=0; k<5; k++) vis[i][k] = 0;
		
		for (int i=0; i<=n; i++) bad[i] = 1;
		
		int ans = solve(1,0);
		
		if (ans==-1) {
			int a;
			for (int i=1; i<=n; i++) if (bad[i]) {
				a = i;
				break;
			}
			cout<<"NG "<<a<<endl;
		}
		else cout<<"OK "<<ans<<endl;
	}

    return 0;

}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int lim = 1e5+5;
const int mod = 1e9+7;
int n,k,nways[lim];
vector<int> adj[lim];

int dfs(int p,int v,int s) {
	nways[v] = max(0,k-s);
	int l = (v!=1);
	for(int i=0;i<adj[v].size();i++) {
		if(adj[v][i]==p)
			continue;
		dfs(v,adj[v][i],l+1);
		l++;
	}
}

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

	cin>>n>>k;
	for(int i=1;i<n;i++) {
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
	dfs(-1,1,0);

	ll ans = 1;
	for(int i=1;i<=n;i++)
		ans = (ans*nways[i])%mod;
	cout<<ans;
	return 0;
}

Measured memory_bytes: 10752
//自称高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF 1999999999
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

int main() {
    int ans = 0;
    int tmp;
    string s;
    cin >> s;
    cout << "2018/01/" << s.substr(8, 2) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

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

const ll mod=1000000007;

ll countBits(ll in){
  int res=0;
  for(;in>0;in>>=1){
    if((in&0x01)!=0){
      res++;
    }
  }
  return res;
}

template<typename T>
void show2dVector(vector<vector<T>>& v){
  for(int i=0;i<v.size();i++){
    int m=v[i].size();
    cout<<i<<" : ";
    for(int j=0;i<m;i++){
      cout<<v[i][j]<<" ";
    }
    cout<<endl;
  }
}

void bfs(const vector<vector<int>>&g, int v, vector<bool>& seen){
  seen[v]=true;
  cout<<v<<" ";
  for(auto next: g[v]){
    if(seen[next]){
      continue;
    }
    bfs(g,next,seen);
  }
}

bool dfs(vector<vector<int>> &g,int start,int goal,vector<bool>&seen){
  bool res=false;
  seen[start]=true;
  if(start==goal){
    return true;
  }
  for(auto next: g[start]){
    if(seen[next]){
      continue;
    }
    res=dfs(g,next,goal,seen);
    if(res){
      break;
    }
  }
  return res;
}

ll gcd(ll a,ll b) {
  return b? gcd(b,a%b): a;  
}
ll lcm(ll a,ll b) {
  return a*b/gcd(a,b);
}
bool isLowerCase(char c){
  return (c>='a'&&c<='z');
}

ll powm(ll a,ll n, ll m){
  ll ret=1;
  while(n>0){
    if(n%2==1){
      ret=(ret*a)%m;
    }
    n>>=1;
    a=(a*a)%m;
  }
  return ret;
}

const string yesno(bool ans){
  return (ans?"Yes":"No");
}
int main() {
  string s;cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char* argv[])
{
    int X; cin >> X;

    string res;
    if (X == 3 || X == 5 || X == 7) {
        res = "YES";
    } else {
        res = "NO";
    }

    cout << res << 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;
using ll = long long;
int INF = 1000000009;
bool isOkmx(ll a,vector<int> v){
    
    rep(i,v.size()){
        a /= v[i];
        a *= v[i];
    }
    return a >= 2;
}
bool isOkmin(ll a,vector<int> v){
    rep(i,v.size()){
        a /= v[i];
        a *= v[i];
    }
    return a <= 2;
}
int main()
{
    int k;
    cin >> k;
    vector<int> a(k);
    rep(i,k){
        cin >> a[i];
    }
    ll ok = 1e+18;
    ll ng = 1;
    ll lx = 0, rx = 0;
    while (abs(ok - ng)>1)
    {
        ll mid = (ng+ok)/2;
        if(isOkmx(mid,a)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    lx = ok;
    ok = 1;
    ng = 1e+18;
    while (abs(ok - ng)>1)
    {
        ll mid = (ng + ok) / 2;
        if (isOkmin(mid, a))
        {
            ok = mid;
        }
        else
        {
            ng = mid;
        }
    }
    rx = ok;
    if(lx > rx){
        cout << -1 << endl;
    }else{
        cout << lx << " " << rx << endl;
    }
}

Measured memory_bytes: 1024
#include <iostream>
#include <stdio.h>
#include <fstream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define IFOR(i,a) for(int i=(a);;i++)
#define REP(i,n)  FOR(i,0,n)
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define INPUT \
FILE *fp; \
fp=fopen("input.text","r");



int main() {
    int N,cnt=0,high=0;
    cin >> N;
    int takasa[N];
    
    FOR(i, 0, N) cin >> takasa[i];
    FOR(i, 0, N){
        if (takasa[i]>=high) {
            high=takasa[i];
            cnt+=1;
            
        }
        
    }

    
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
 
using namespace std;
 
class DisjointSet {
public:
    vector<int> rank, p;

    DisjointSet(int size) {
        rank.resize(size, 0);
        p.resize(size, 0);
        for (int i = 0; i < size; i++)makeSet(i);
    }
 
    void makeSet(int x) {
        p[x] = x;
        rank[x] = 0;
    }
 
    bool same(int x, int y) {
        return findSet(x) == findSet(y);
    }
 
    void unnite(int x, int y) {
        link(findSet(x), findSet(y));
    }
 
    void link(int x, int y) {
        if (rank[x] > rank[y]) {
            p[y] = x;
        }
        else {
            p[x] = y;
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
    }
 
    int findSet(int x) {
        if (x != p[x]) {
            p[x] = findSet(p[x]);
        }
        return p[x];
    }
};
 
int main() {
    int n, a, b, q;
    int t;
 
    cin >> n >> q;
    DisjointSet ds = DisjointSet(n);
 
    for (int i = 0; i < q; i++) {
        cin >> t >> a >> b;
        if (t == 0)ds.unnite(a, b);
        else if (t == 1) {
            if (ds.same(a, b))cout << 1 << endl;
            else cout << 0 << endl;
        }
    }
 
    return 0;
}


Measured memory_bytes: 3164
//Zory-2019
#include<bits/stdc++.h>
using namespace std;
namespace mine
{
    typedef long long ll;
    #define pr pair<int,int>
    #define FR first
    #define SE second
    #define MP make_pair
    #define PB push_back
    #define vc vector
    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())
    #define bin(x) (1ll<<(x))
    #define GG(x) if(x) {puts("error");exit(666);}
    #define fo(i,l,r) for(int i=(l),I=(r);i<=I;i++)
    #define fd(i,r,l) for(int i=(r),I=(l);i>=I;i--)
    ll qread()
    {
        ll ans=0,f=1;char c=getchar();
        while(c<'0' or c>'9') {if(c=='-')f=-1;c=getchar();}
        while('0'<=c and c<='9') ans=ans*10+c-'0',c=getchar();
        return ans*f;
    }
    void write(ll num)
    {
        if(num<0) putchar('-'),num=-num;
        if(num>=10) write(num/10);
        putchar('0'+num%10);
    }
    void write1(ll num){write(num);putchar(' ');}
    void write2(ll num){write(num);putchar('\n');}
    template<typename T> void chmax(T &x,const T y) {x=(x>y?x:y);}
    template<typename T> void chmin(T &x,const T y) {x=(x<y?x:y);}
    ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

    const int INF=0x3f3f3f3f;
    const int MOD=1e9+7;
    int mm(const int x){return x>=MOD?x-MOD:x;}
    template<typename T> void add(T &x,const int &y){x=(x+y>=MOD?x+y-MOD:x+y);}
    ll qpower(ll x,ll e,int mod=MOD){ll ans=1;GG(e<0)while(e){if(e&1)ans=ans*x%mod;x=x*x%mod;e>>=1;}return ans;}
    ll invm(ll x){return qpower(x,MOD-2);}
    const int N=1e6+10;

    int a[N];
	void main()
	{
        int n=qread(),x=qread(),m=n+n-1;
        if(x==1 or x==m) {puts("No");return;}puts("Yes");
        a[n-1]=x-1,a[n]=x,a[n+1]=x+1;
        int now=1;
        fo(i,1,x-2) {a[now]=i;now++;if(now==n-1)now=n+2;}
        fo(i,x+2,m) {a[now]=i;now++;if(now==n-1)now=n+2;}
        fo(i,1,m) write1(a[i]);
	}
};//(ans+MOD)%MOD
signed main()
{
    srand(time(0));
    mine::main();
}


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

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int p;
	int A = 0, B = 0, C = 0;
	for ( int i = 0; i < n; i++ ) {
		cin >> p;
		if ( p <= a ) A++;
		else if ( p <= b ) B++;
		else C++;
	}

	cout << min(A, min(B, C)) << endl;

}


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

using namespace std;
typedef long long ll;


const int mod = 998244353;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%mod+mod)%mod) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const {
        return pow(mod-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};


int main(){


int N,K;
cin >>N >>K;

vector<int> L(K);

vector<int> R(K);


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

    cin >>L[i] >> R[i];
}


vector<mint> A(N,0);


vector<mint> Ri(N,0);


Ri[0]=1;

A[0] =1;


for(int i=1;i<N;i++){


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


        int mi = i -R[j]-1;

        int ma = i -L[j];


        

        if(ma>=0){

            if(mi<0){


                A[i]+=Ri[ma];
            }
            else{


                A[i] =A[i] +Ri[ma] -Ri[mi];

            }

        }



    }


    Ri[i] =Ri[i-1] + A[i];
    

}


cout << A[N-1] << endl;


return 0;
}


Measured memory_bytes: 6332
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a+b<24){
        cout << a+b << endl;
    }else if(a+b>=24){
        cout << a+b-24 << endl;
    }
}

Measured memory_bytes: 256
n, m, x = map(int, input().split())
l = [list(map(int, input().split())) for _ in range(n)]
mn = 1e9
k = 2 ** n
for i in range(k):
    c = 0
    subset = [0] * m
    for y in range(n):
        if i & 1 << y:
            c += l[y][0]
            for z in range(1, m + 1):
                subset[z - 1] += l[y][z]
    if all(h >= x for h in subset):
        mn = min(c, mn)
if mn == 1e9:
    print(-1)
else:
    print(mn)




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

using namespace std;

int main(){
  int n,k;
  cin>>n>>k;
  vector<int> l(n);
  for(int i=0;i<n;i++){
    cin>>l[i];
  }

  sort(l.begin(),l.end());
  reverse(l.begin(),l.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans+=l[i];
  }
  cout << ans <<endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int64_t n, m;
	cin >> n >> m;
	int64_t x[n], y[n], z[n];
	for (int i = 0; i < n; i++)
	{
		cin >> x[i] >> y[i] >> z[i];
	}
	int64_t ans = 0;
	for (int i = 0; i < (1 << 3); i++)
	{
		int64_t val[n];
		for (int j = 0; j < n; j++)
		{
			val[j] = x[j] * ((i & 1) ? -1 : 1) + y[j] * ((i & 2) ? -1 : 1) + z[j] * ((i & 4) ? -1 : 1);
		}
		sort(val, val + n);
		reverse(val, val + n);
		ans = max(ans, accumulate(val, val + m, int64_t(0)));
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define invrepr(i,a,b) for(int i=b-1;i>=a;i--)
#define invrep(i,n) invrepr(i,0,n)
#define repitr(itr,a) for(auto itr=a.begin();itr!=a.end();++itr)
const int MOD=1e9+7;


int main() {
    int n;
    cin >> n;
    if (n%2==0) cout << n << endl;
    else cout << n*2 << endl; 
    
}

Measured memory_bytes: 256
#include <stdio.h>
#define M 100
#define I (1<<21)
#define W 0
#define G 1
#define B 2

int n,A[M][M];

void ds(){
  int v,i,j,t;
  int d[M],clr[M];

  for(i=0;i<n;i++){
    d[i]=I;
    clr[i]=W;
  }

  d[0]=0;
  clr[0]=G;
  while(1){
    v=I;
    j=-1;
    for(i=0;i<n;i++){
      if(v>d[i] && clr[i] != B){
	j=i;
	v=d[i];
      }
    }
    if(j == -1)break;
    clr[j]=B;
    for(t=0;t<n;t++){
      if(clr[t] != B && A[j][t] != I){
	if(d[t] > d[j] + A[j][t]){
	  d[t]=d[j]+A[j][t];
	  clr[t]=G;
	}
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d %d\n",i,d[i]);
  }
}
    
  

int main(){
  int i,j,k,s,t,u;

    scanf("%d",&n);

    for(i=0;i<n;i++){
      for(j=0;j<n;j++){
	A[i][j]=I;
      }
    }

    for(i=0;i<n;i++){
      scanf("%d %d",&k,&s);
      for(j=0;j<s;j++){
	scanf("%d %d",&t,&u);
	A[k][t]=u;
      }
    }
    ds();

    return 0;
}



Measured memory_bytes: 2112
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
signed main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int n;
	cin >> n;
	vector<int> a(n + 1, 0);
	int df = 0;
	for(int i = 1 ; i <= n ; i ++){
		cin >> a[i];
		df += (a[i] != i);
	}
	if(df > 2) cout << "NO";
	else cout << "YES";
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n, 0);
  REP(i, n) { cin >> a[i]; }
  REP(j, k) {
    vector<int> imos(n, 0);
    REP(i, n) {
      imos[max(i - a[i], 0ll)] += 1;
      if (i + a[i] + 1 < n) imos[i + a[i] + 1] -= 1;
    }
    REP(i, n) {
      if (i == 0)
        a[i] = imos[i];
      else
        a[i] = a[i - 1] + imos[i];
    }
    bool f = true;
    REP(i, n) {
      if (a[i] != n) {
        f = false;
        break;
      }
    }
    if (f) {
      REP(i, n) {cout << n << " ";}
      cout << "\n";
      return 0;
    }
  }
  REP(i, n) { cout << a[i] << " "; }
  cout << "\n";
  return 0;
}


Measured memory_bytes: 4756
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>

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

using namespace std;

typedef long long ll;


ll n;
ll x;
ll l[101];


int main() {

//    ifstream in("/Users/koichihasegawa/src/repository/cpp/AtCoder/ABC/abc130/input.txt");
//    cin.rdbuf(in.rdbuf());

    cin >> n >> x;

    ll d[n + 1];

    ll ans = 1;

    REP(i, n) {
        cin >> l[i];

        if (i > 0) {
            d[i] = l[i] + d[i - 1];
        } else {
            d[i] = l[i];
        }
        if (d[i] <= x) {
            ans++;
        }
    }

    cout << ans;


    return 0;
}


Measured memory_bytes: 888
n,m,l = map(int, input().split())
a = []
b = []
for _ in range(n):
	a.append(list(map(int, input().split())))
for _ in range(m):
	b.append(list(map(int, input().split())))
for i in range(n):
	ans = []
	for j in range(l):
		result = 0
		for k in range(m):
			result += a[i][k]*b[k][j]
		ans.append(result)
	print(" ".join(list(map(str,ans))))


Measured memory_bytes: 6248
#include <stdio.h>

/* -------- main code -------- */
int    main(void)
{
    int flag;
    int x, y, z, n;
    double sum;

    flag = 0;
    scanf("%d %lf", &n, &sum);
    for(x = 0; x <= n; x++){
        for(y = 0; y <= (n - x); y++){
            z = n - (x + y);
            if(sum == (10000 * x + 5000 * y + 1000 * z)){
                flag = 1;
                break;
            }
        }
        if(flag == 1){
            break;
        }
    }

    if(flag == 1){
        printf("%d %d %d\n", x, y, z);
    }
    else{
        printf("-1 -1 -1\n");
    }
    return (0);
}

Measured memory_bytes: 128
def main():
    n, k, *a = map(int, open(0).read().split())
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print(root[index])
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()


Measured memory_bytes: 109516