akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-6;
const double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
int main(){
	int ret=mod;
	long long a;scanf("%lld",&a);
	for(int i=1;(long long)i*i<=a;i++){
		if(a%i==0){
			long long tmp=a/i;
			int cnt=0;
			while(tmp){
				cnt++;tmp/=10;
			}
			ret=min(ret,cnt);
		}
	}
	printf("%d\n",ret);
}

Measured memory_bytes: 128
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int r,g,b;
inline void solve(){
  IN3(r,g,b);
  OUT((r*100+g*10+b)%4==0?"YES":"NO");
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        h: [usize; n]
    }
    h.sort();
    let hh = h.iter().take(n - k + 1).zip(h.iter().skip(k - 1)).map(|(min, max)| max - min).min().unwrap();
    println!("{}", hh);
}


Measured memory_bytes: 4352
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
// #define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
typedef string::const_iterator State;
Def expr(State &i);
Def term(State &i);
Def factor(State &i);
Def number(State &i);
void consume(State &i,char expected){
	if(*i==expected)i++;
	else{
		exit(0);
	}
}
Def expr(State &i){
	Def out=term(i);
	while(*i=='+'||*i=='-'){
		char op=*i;
		i++;
		Def out1=term(i);
		if(op=='+')out+=out1;
		else out-=out1;
	}
	return out;
}
Def term(State &i){
	Def out=factor(i);
	while(*i=='*'||*i=='/'){
		char op=*i;
		i++;
		Def out1=factor(i);
		if(op=='*')out*=out1;
		else out/=out1;
	}
	return out;
}
Def factor(State &i){
	if(isdigit(*i))return number(i);
	//'('
	i++;
	Def out=expr(i);
	i++;
	return out;
}
Def number(State &i){
	Def out=0;
	while(isdigit(*i))out=out*10+*(i++)-'0';
	return out;
}
int main(){
	int n;
	cin>>n;
	while(n--){
		string s;
		cin>>s;
		State begin=s.begin();
		cout<<expr(begin)<<endl;
	}
}

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

int e1[100+1],result[100+1];
char eFin[100000+1];
int cnt=0;
int a;
int b;

void FirstReload();
void Distinguish();

int main(){
	scanf("%s",eFin);
	FirstReload();
	while(1){
	    a=b=-1;
        Distinguish();
        //printf(">>>%d %d\n", result[a], e1[a]);

		if(b == -1){
			// printf("%d\n",result[a]?:e1[a]);
            if(result[a]){
                printf("%d\n",result[a]?:e1[a]);
            }else{printf("%d\n",result[a]?:e1[a]);}
            //printf(">>>>%d %d\n", result[a], e1[a]);
			goto aaa;
		}
		//e1[a]+=e1[b];
		result[a]+=result[b]+(e1[a]+=e1[b]);
		e1[b]=0;    //初期化
	}
    aaa: return 0;
}

void Distinguish(){
    for(int cnt=0; cnt<26; cnt++){
        if(e1[cnt] != 0){
			if( e1[a] > e1[cnt] || a==-1){
                b=a,a=cnt;
                continue;
            }
			if(b==-1||e1[b] > e1[cnt]){
                b=cnt;
                continue;
            }
	    }
    }
}
void FirstReload(){while(eFin[cnt]){e1[eFin[cnt]-97]++;cnt++;}}


Measured memory_bytes: 2144
#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

class Dice {
private:
    int top;
    int bottom;
    int north;
    int south;
    int west;
    int east;

public:
    Dice() :
        top   (1),
        bottom(6),
        north (5),
        south (2),
        west  (4),
        east  (3) {}

    int getTop() {
        return top;
    }

    void turnNorth() {
        swap(south, top);
        swap(south, bottom);
        swap(north, bottom);
    }

    void turnSouth() {
        swap(south, bottom);
        swap(south, top);
        swap(north, top);
    }

    void turnWest() {
        swap(east, top);
        swap(east, bottom);
        swap(west, bottom);
    }

    void turnEast() {
        swap(east, bottom);
        swap(east, top);
        swap(west, top);
    }

    void turnRight() {
        swap(south, west);
        swap(south, east);
        swap(north, east);
    }

    void turnLeft() {
        swap(south, east);
        swap(south, west);
        swap(north, west);
    }
};

int main() {
    int n, ans;
    string str;

    while(cin >> n) {
        if(n == 0) break;

        Dice dice;
        ans = 1;

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

            if(str == "North")      dice.turnNorth();
            else if(str == "South") dice.turnSouth();
            else if(str == "West")  dice.turnWest();
            else if(str == "East")  dice.turnEast();
            else if(str == "Right") dice.turnRight();
            else if(str == "Left")  dice.turnLeft();

            ans += dice.getTop();
        }

        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3180
#include <iostream>
#include <map>

using namespace std;

int main(void) {
    int64_t N, K;
    cin >> N >> K;
    map<int64_t,int64_t> mp;
    while(N--) {
        int64_t a, b;
        cin >> a >> b;
        mp[a] += b;
    }

    int64_t cnt = 0;
    for(auto itr=mp.begin(); itr!=mp.end(); itr++) {
        cnt += itr->second;
        if(cnt >= K) {
            cout << itr->first << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,e;
	scanf("%d/%1d%1d/%1d%1d",&a,&b,&c,&d,&e);
	printf("2018/%d%d/%d%d",b,c,d,e);
	return 0;
} 

Measured memory_bytes: 256
import java.io.*;
import java.util.*;
import static java.lang.System.*;
import static java.lang.Math.*;

public class Main
{	
	public static void main(String []args)throws IOException
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String []s=br.readLine().split(" ");
		
		long S=Long.parseLong(s[0]);
		long W=Long.parseLong(s[1]);
		
		
		if(W>=S)
			out.println("unsafe");
		else
			out.println("safe");
		
			
			
		
		
	}
	
	
}




Measured memory_bytes: 32412
from heapq import heappush, heappop
n,m=map(int,input().split())
a=list(map(int,input().split()))
h=[]
for x in a:
    heappush(h,-x)
for _ in [0]*m:
    k=-heappop(h)
    heappush(h,-(k//2))
ans=0
for _ in [0]*n:
    ans+=-heappop(h)
print(ans)

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

int main(){
  int N;
  cin >> N;
  int T[N];
  for(int i = 0;i < N;i++)
    cin >> T[i];
  int M;
  cin >> M;
  int P[M],X[M];
  for(int i = 0;i < M;i++)
    cin >> P[i] >> X[i];
  int sum = 0;
  for(int c : T)
    sum += c;
  for(int i = 0;i < M;i++)
    cout << sum - T[P[i] - 1] + X[i] << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())


def FLIST(n):
    res = [1]
    for i in range(1, n+1):
        res.append(res[i-1]*i % DVSR)
    return res


K = II()

res = -1
a = 7
for i in range(K+1000):
    if a % K == 0:
        res = i+1
        break
    a = a*10 + 7
    a %= K

print(res)


Measured memory_bytes: 9272
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int main(){
    double w, h, x, y;
    cin >> w >> h >> x >> y;

    printf("%f ",w*h/2);


    if (x == w/2 && y == h/2) cout << "1\n";
    else if ((x == 0 || x == w) && (y == 0 || y == h)) cout << "0\n";
    else if (x == w/2 && (y == 0 || y == h/2)) cout << "0\n";
    else if (y == h/2 && (x == 0 || x == w/2)) cout << "0\n";
    else if (x == w/2 || y == h/2)  cout << "0\n";
    else cout << "0\n";

    return 0;
}


Measured memory_bytes: 256
<?php
list($A, $B) = explode(" ", trim(fgets(STDIN)));
list($a, $b) = explode(" ", trim(fgets(STDIN)));
list($C) = explode(" ", trim(fgets(STDIN)));
if($A == $C)$a--;
if($B == $C)$b--;

echo implode(" ", [$a, $b]);

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

#ifdef _DEBUG
#define debug(x) cerr << "line: " << __LINE__ << ", func: " << __func__ << " ->  " << #x << " = " << x << endl
#else
#define debug(x)
#endif

#define all(s) begin(s), end(s)
#define rall(s) rbegin(s), rend(s)
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = ((a)-1); i >= (b); i--)
#define pb push_back
#define sz(a) int((a).size())

using namespace std;

using ll = long long;
using ull = unsigned long long;
using i_i = pair<int, int>;
using ll_ll = pair<ll, ll>;
using d_ll = pair<double, ll>;
using ll_d = pair<ll, double>;
using d_d = pair<double, double>;

static constexpr ll LL_INF = 1LL << 60;
static constexpr int I_INF = 1 << 28;
static constexpr double PI = static_cast<double>(3.14159265358979323846264338327950288);
static constexpr double EPS = numeric_limits<double>::epsilon();
static constexpr const char* NO = "IMPOSSIBLE";

static map<type_index, const char* const> scanType = {
    {typeid(int), "%d"}, {typeid(ll), "%lld"}, {typeid(double), "%lf"}, {typeid(char), "%c"}};

template <class T> static void scan(vector<T>& v);
[[maybe_unused]] static void scan(vector<string>& v, bool isWord = true);
template <class T> static inline bool chmax(T& a, T b);
template <class T> static inline bool chmin(T& a, T b);
template <class A, size_t N, class T> static void Fill(A (&arr)[N], const T& val);

int main(int argc, char* argv[]) {
  long long A;
  scanf("%lld", &A);
  long long B;
  scanf("%lld", &B);

  ll diff = abs(A - -B);
  if (diff % 2 == 1) {
    cout << NO << endl;
    return 0;
  }

  cout << diff / 2 << endl;
  return 0;
}

template <class T> static void scan(vector<T>& v) {
  auto tFormat = scanType[typeid(T)];
  for (T& n : v) {
    scanf(tFormat, &n);
  }
}

static void scan(vector<string>& v, bool isWord) {
  if (isWord) {
    for (auto& n : v) {
      cin >> n;
    }
    return;
  }

  int i = 0, size = v.size();
  string s;
  getline(cin, s);

  if (s.size() != 0) {
    i++;
    v[0] = s;
  }

  for (; i < size; ++i) {
    getline(cin, v[i]);
  }
}

template <class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

template <class A, size_t N, class T> void Fill(A (&arr)[N], const T& val) {
  std::fill((T*)arr, (T*)(arr + N), val);
}


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

using namespace std;
typedef long long int ll;

int main(){

    ll N;
    cin >> N;

    vector<pair<ll, ll > > A;

    for(ll i = 0; i < N; i++){
        ll in; cin >> in;
        A.push_back(make_pair(in, i + 1));
    }

    sort(A.begin(), A.end());


    for(ll i = 0; i < N - 1; i++){
        cout << A[i].second << " ";
    }  
    cout << A[N - 1].second << endl;

}

Measured memory_bytes: 2544
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  ll a,b;
  cin >> a >> b;
  cout << ((a%2 && b%2) ? "Odd" : "Even") << endl;
  return 0;
}


Measured memory_bytes: 256
def prob_b():
    N = int(input())
    P = list(map(int, input().split(' ')))

    longest = 0
    total_len = 0

    for p in P:
        longest = max(longest, p)
        total_len += p

    if (longest + longest) < total_len:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    prob_b()

Measured memory_bytes: 3188
#include <iostream>
#include <bitset>
#include <string>
#include <vector>
using namespace std;

int main() {
    int a,i;
    bool f = 1>0;
    vector<int> b;
    scanf("%d\n",&a);
    b.resize(a);
    for(i=0;i<a;i++){
    scanf("%d",&b[i]);
    }
    for(i=0;i<a;i++){
        if (b[i] % 2 == 0) {
            f = f && ((b[i] % 3 == 0) || (b[i] % 5 == 0));
        };
        if (f){
            continue;
        }
        else{
            break;
        };
    };
    if (f){
        printf("APPROVED");
    }
    else{
        printf("DENIED");
    };
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define EPS 1e-10
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
#define first_more_idx(ve, num) upper_bound(all(ve), num)-ve.begin() // idx = first_more_idx(ve,num); if(idx = ve.size()) , then not exist
#define first_lessequal_idx(ve, num) lower_bound(all(ve), num)-ve.begin()
#define pq_pair_tB priority_queue <pair<ll,ll>, vector<pair<ll,ll> > , greater<pair<ll,ll> > >
#define pq_pair_ts priority_queue <pair<ll,ll> > // only sort first param
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}
ll power(ll x, ll n){if(n == 0) return 1;return  (n%2)? x*power(x, n-1)%MOD : power(x*x%MOD, n/2);}
ll dx[]={0, 0, -1, 1};
ll dy[]={1, -1, 0, 0};// up,down,left right


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

    ll K, N;
    cin >> K >> N ;
    
    vector<ll> A;
    rep(i, N){
        ll inp; cin >> inp;
        A.pb(inp);
    }
    
    ll ans = 0;
    rep(i, N){
        if(i == N - 1) ans = max(ans, K + A[0] - A[i]);
        else ans = max(ans, A[i + 1] - A[i]);
    }
    
    cout << K - ans << endl;
    
    //cout << fixed << setprecision(16) << ans << endl;
    return 0;
}


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

int main(){
  int A, B;
  cin >> A >> B;
  if(A >= 13){
    cout << B << endl;
  }
  else if(A >= 6){
    cout << B / 2 << endl;
  }
  else{
    cout << '0' << endl;
  }
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, x int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&c)
	fmt.Scan(&x)

	result := 0

	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if (500*i)+(100*j)+(50*k) == x {
					result++
				}
			}
		}
	}

	fmt.Print(result)
}


Measured memory_bytes: 512
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools
import numpy as np




def main():
    num = int(input())
    data = [int(input()) for i in range(num)]
    sum_num = sum(data)
    mod = 998244353

    dp = np.zeros(sum_num + 1, dtype=np.int64)
    dp[0] = 1
    for i in range(num):
        now_num = data[i]
        prev = dp
        dp = 2 * prev
        dp[now_num:] += prev[:-now_num]
        dp %= mod

    ans = pow(3, num, mod) - dp[(1 + sum_num) // 2:].sum() * 3
    if sum_num % 2 == 0:
        dp2 = np.zeros(sum_num + 1, dtype=np.int64)
        dp2[0] = 1
        for i in range(num):
            now_num = data[i]
            # prev = dp2
            dp2[now_num:] += dp2.copy()[:-now_num]
            dp2 %= mod
        ans += dp2[sum_num // 2] * 3


    ans %= mod
    print(ans)


if __name__ == '__main__':
    main()



Measured memory_bytes: 14852
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int s, num, ans;
  cin >> s;
  vector<int> v;

  v.push_back(s);
  for(int i=1;i<=1000000;i++){
    if(s%2 == 0){
      s = s/2;
    }else{
      s = 3*s + 1;
    }
    v.push_back(s);
    num = count(v.begin(), v.end(), s);
    if(num == 2){
      ans = i+1;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include <random>
#include <algorithm>
#include <unordered_set>
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
#define ld long double
#define Sort(a) sort(a.begin(),a.end())
#define cSort(a,cmp) sort(a.begin(),a.end(),cmp)
#define reSort(a) sort(a.rbegin(), a.rend())
static const ll llMAX = numeric_limits<long long>::max();
static const int intMAX = numeric_limits<int>::max();
static const ll  llMIN = numeric_limits<long long>::min();
static const int intMIN = numeric_limits<int>::min();
static const ll d_5 = 100000;
static const ll d9_7 = 1000000007;
static const ll d_9 = 1000000000;
static const double PI=3.14159265358979323846;
template<class T>
T gcd(T a,T b){
  if(a==0){
    return b;

  }else if(b==0){
    return a;
  }
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
ll digitpower(ll a,ll b){//aのb乗を計算
  if(b==1){
    return a;
  }else if(b==0){
    return 1;
  }
  int mode=1;
  if(mode==0){
    if(b%2==1){
      ll tmp = digitpower(a,(b-1)/2);
      tmp%=d9_7;
      tmp*=tmp;
      tmp%=d9_7;
      tmp*=a;
      return (tmp)%d9_7;
    }else{
      ll tmp = digitpower(a,(b)/2);
      tmp%=d9_7;
      tmp*=tmp;
      tmp%=d9_7;
      return (tmp)%d9_7;
    }
  }else{
    if(b%2==1){
      ll tmp = digitpower(a,(b-1)/2);
      tmp*=tmp;
      tmp*=a;
      return (tmp);
    }else{
      ll tmp = digitpower(a,(b)/2);
      tmp*=tmp;
      return (tmp);
    }
  }
  return 0;
  
}
template<class T>
void Printvector(std::vector<T> &a){
  int size = a.size();
  rep(i,size){
    cout<<a[i]<<" ";
  }
  cout<<endl;
}
template<class T>
void Printvector(std::vector<std::vector<T>> &a){
  int size = a.size();
  rep(i,size){
    int size2=a[i].size();
    rep(j,size2){
      cout<<a[i][j]<<" ";
    }
    cout<<endl;
  }
  cout<<endl;
}
int main(void){
  ll n,k;
  cin>>n>>k;
  while(n>k){
    n-=((n/k))*k;
  }
  set<ll> past;
  while((ll)abs(n-k)<n){
    if(past.find((ll)abs(n-k))!=past.end()){
      break;
    }
    n=(ll)abs(n-k);
    past.insert(n);
  }
  cout<<n<<endl;
  return 0;
}

//<<std::setprecision(30)

//重複削除
 /* std::sort(vec.begin(), vec.end());
 
  vec.erase(std::unique(vec.begin(), vec.end()), vec.end());*/

  //ペアの全探索
  /*do{
		int s=0;
		for(int i=0;i<n/2;i++)s+=v[i]^v[i+n/2];
		r=max(s,r);
		reverse(v.begin()+n/2,v.end());
	}while(next_permutation(v.begin(),v.end()));*/


Measured memory_bytes: 256
#include <iostream>
using namespace std;
template
<
    typename TYPE,
    std::size_t SIZE
>
std::size_t array_length(const TYPE (&)[SIZE])
{
    return SIZE;
}

int main() {
    int N, K;
    cin >> N >> K;
    int h[N+1];
    for(int i = 0; i < N; i++) {
        cin >> h[i];
    }
    int sum = 0;
    for(int i = 0; i < N; i++) {
        if(K <= h[i]) {
            sum++;
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 640
package main

import "fmt"

func main() {
	var h, w int
	for {
		fmt.Scan(&h, &w)
		if h == 0 && w == 0 {
			break
		}
		for i := 0; i < h; i++ {
			if i % 2 == 0 {
				for j := 0; j < w; j++ {
					if j != w - 1 {
						if j % 2 == 0 {
							fmt.Print("#")
						} else {
							fmt.Print(".")
						}
						continue
					}
					if w % 2 == 0 {
						fmt.Print(".\n")
					} else {
						fmt.Print("#\n")
					}
				}
				continue
			} else {
				for j := 0; j < w; j++ {
					if j != w - 1 {
						if j % 2 == 0 {
							fmt.Print(".")
						} else {
							fmt.Print("#")
						}
						continue
					}
					if w % 2 == 0 {
						fmt.Print("#\n")
					} else {
						fmt.Print(".\n")
					}
				}
			}
		}
		fmt.Print("\n")
	}
}


Measured memory_bytes: 1124
def chmin(a, b):
    if a > b:
        return b
    return a

N, K = map(int, input().split())
H = list(map(int, input().split()))

dp = [float('inf')]*N
dp[0] = 0

for i in range(N-1):
    k = min(K, N-(i+1))
    for j in range(1, k+1):
        dp[i+j] = chmin(dp[i+j], dp[i] + abs(H[i+j] - H[i]))

print(dp[-1])

Measured memory_bytes: 55776
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <numeric>

using namespace std;

int main(){
    string a,b,c;
    cin>>a>>b>>c;
    if(a[a.size()-1]==b[0] & b[b.size()-1]==c[0] )cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <math.h>
#include <map>
#include<stack>
#include<fstream>

using namespace std;
const long long INF = 1LL << 60;  // どういう意味だろうか

const string write_file("");

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

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

int main() {
	int N, K;
	cin >> N >> K;


	if((N % 2) == 0){
		if(K <= N /2){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}
	else{
		if(K <= N/2  + 1){
			cout << "YES" << endl;
		}
		else{
			cout << "NO" << endl;
		}
	}



}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;


vector<ll> inv,fact,invfact;
void mod_build(int n=101010){
    fact.resize(n+1);
    inv.resize(n+1);
    invfact.resize(n+1);
    fact[0]=inv[0]=invfact[0]=1;
    inv[1]=1;
    rep(i,n){
        fact[i+1]=fact[i]*(i+1)%mod;
        if(i>0)inv[i+1]=mod-inv[mod%(i+1)]*(mod/(i+1))%mod;
        invfact[i+1]=invfact[i]*inv[i+1]%mod;
    }
}
ll perm(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return fact[n]*invfact[n-k]%mod;
}
ll comb(int n,int k){
    if(n<0||k<0||k>n)return 0;
    return (fact[n]*invfact[n-k]%mod)*invfact[k]%mod;
}
ll powmod(ll n,ll k){
    k%=mod-1;
    if(k<0)k+=mod-1;
    ll ret=1;
    while(k){
        if(k&1)ret=ret*n%mod;
        n=n*n%mod;
        k>>=1;
    }
    return ret;
}
int main(){
    ll n;
    cin>>n;
    mod_build(303030);
    ll a,b,c;cin>>a>>b>>c;
    a=a*inv[100]%mod;
    b=b*inv[100]%mod;
    c=c*inv[100]%mod;
    ll ret=0;
    rep(i,n){
        ll res=comb(n+i-1,i)*powmod(a,n)%mod*powmod(b,i)%mod*powmod(powmod(a+b,n+i),mod-2)%mod;
        ret+=(n+i)*powmod(a+b,mod-2)%mod*res%mod;
        ret%=mod;
    }
    rep(i,n){
        ll res=comb(n+i-1,i)*powmod(b,n)%mod*powmod(a,i)%mod*powmod(powmod(a+b,n+i),mod-2)%mod;
        ret+=(n+i)*powmod(a+b,mod-2)%mod*res%mod;
        ret%=mod;
    }
    cout<<ret<<endl;
    return 0;
}

Measured memory_bytes: 7296
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cctype>
#include <vector>
#include <numeric>
#include<string>
#include <map>

using namespace std;

#define ll long long
#define rep(cnt,a,n) for(ll cnt=a;cnt<n+a;cnt++) //aから始めてn回ループ
#define vector2(type,name,a,b) vector<vector<type>> name(a, vector<type>(b))
#define PI 3.141592653589793



int main() {
    
    ll n;
    cin >> n;
    map <ll, ll> a;
    ll hoge;
    rep(cnt, 0, n) {
        cin >> hoge;
        a[hoge]++;
    }
    ll q;
    cin >> q;
    ll b,c;
    ll souwa = 0;
    for (auto p : a) {
        souwa += p.first * p.second;
    }
    vector<ll> ans(q);
    rep(cnt, 0, q) {
        cin >> b >> c;
        souwa = souwa - a[b] * b + c*a[b];
        a[c] += a[b];
        a.erase(b);
        ans[cnt] = souwa;
    }
    rep(cnt, 0, q) {
        cout << ans[cnt] << endl;
    }



    return 0;
}


Measured memory_bytes: 7940
while True:
    n=int(input())
    if n==0:
        break
    l=[0]*10
    for i in range(n):
        c=int(input())
        l[c]+=1
    for j in range(10):
        if l[j]==0:
            print('-')
        else:
            k=0
            while k<=l[j]-2:
                print('*',sep='',end='')
                k+=1
            print('*')


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

int main() {
  int a, b;
  cin >> a >> b;
  
  if (a > b) {
    rep(i, a) {
      cout << b;
    }
  }
  
  else if (a < b) {
    rep(i, b) {
      cout << a;
    }
  }
  
  else {
    rep(i, a) {
      cout << b;
    }
  }
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}



int main(){
  ll n,w;
  cin >> n >> w;
  ll weight[110],value[110];
  FOR(i,n){
    cin >> weight[i] >> value[i];
  }

  ll dp[110][100010]={0};
  for(int i=1;i<=n;i++){
    for(int j=1;j<=w;j++){
      dp[i][j]=dp[i-1][j];
      if(j>=weight[i-1]){
        chmax(dp[i][j],dp[i-1][j-weight[i-1]]+value[i-1]);
      }
    }
  }

  cout << dp[n][w] << endl;
  
}


Measured memory_bytes: 86144
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 200005
#define inf 1e9
#define eps 1e-10
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

string s;

int main()
{
	int n=read(),ans=0; cin>>s;
	for(int i=0;i<s.length()-2;i++)
	{
		if(s[i]=='A'&&s[i+1]=='B'&&s[i+2]=='C') ans++;
	}
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define tt int tc; cin>>tc; while(tc--)
#define nl cout<<"\n";
#define sp cout<<" ";
#define rep(i, a, b) for(long long i=a; i<b; i++)

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
double PI = 4*atan(1);

int main()
{
    optimize();

    int n, t;
    string s;
    cin>> n;

    vector < std::tuple < string, int, int > > v;

    for(int i=0; i<n; i++)
    {
        cin>> s>> t;
        v.push_back(std::tuple<string,int,int>(s, 100- t, i+1));
    }

    sort (v.begin(), v.end());

    for ( const auto& i : v )
        cout << get<2>(i) << '\n';
    


    return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main(void){
int a,b,c;
int k;
int f=0;
int max=0;
scanf("%d %d %d",&a,&b,&c);
scanf("%d",&k);
if(a>=max){max=a;f=1;}
if(b>=max){max=b;f=2;}
if(c>=max){max=c;f=3;}
if(f==1){
    printf("%d",(int)pow(2,k)*a+b+c);
}
else if(f==2){
    printf("%d",(int)pow(2,k)*b+a+c);
}
else if(f==3){
    printf("%d",(int)pow(2,k)*c+a+b);
}
}


Measured memory_bytes: 128
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<long long> vll;
typedef pair<int,int> pint;
typedef pair<long long, long long> pll;

#define MP make_pair
#define PB push_back
#define ALL(s) (s).begin(),(s).end()
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P) 
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P) 
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P) 
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s; }



const int MAX = 10100;

int n;
int a[MAX];

int check(int i, int ic) {
    int res = 0;
    int c = ic;
    int tmp = 1;
    for (int j = i-1, k = i+1; j >= 0 && k <= n+1; ) {
        if (a[j] == c) { 
            --j;
            ++tmp;
            continue;
        }
        else {
            if (a[k] == c) {
                ++k;
                ++tmp;
                continue;
            }
            else {
                if (tmp >= 4) res += tmp;
                else {
                    //cout << i << ", " << ic << " : " << res << endl;
                    return res;
                }
                
                c = a[j];
                tmp = 0;
            }
        }
    }
    //cout << i << ", " << ic << " : " << res << endl;
    return res;
}

int main() {
    //freopen( "/Users/macuser/Dropbox/Contest/input.in", "r", stdin );
    while (cin >> n) {
        if (n == 0) break;
        
        memset(a, 0, sizeof(a));
        for (int i = 0; i < n; ++i) cin >> a[i+1];
        
        int res = 0;
        for (int i = 1; i <= n; ++i) {
            for (int c = 1; c <= 3; ++c) {
                int tmp = check(i, c);
                chmax(res, tmp);
            }
        }
        
        cout << n-res << endl;
    }
    return 0;
}


Measured memory_bytes: 1208
//ABC099-C(Strange Bank)
#include<iostream>
using namespace std;

const int INF=1<<29;
int N;
int dp[101010];

int main(){
    cin>>N;
    
    dp[0]=0;
    //dp[1,6,9,36,81,...]=1
    //1円玉を使うかどうかで場合分け
    //dp[N]=1+dp[N-1](1円玉を使うとき)
    //dp[N]=1+dp[N-6^m]
    //dp[N]=1+dp[N-9^m]...これらのminを求める
    for(int i=1; i<=N; i++){
        dp[i]=INF;//初期化
        int power=1;//6べきを行う→powを使わなくても実装できる
        while(power<=i){
            dp[i]=min(dp[i],dp[i-power]+1);
            power*=6;
        }
        power=1;//9べきを行う
        while(power<=i){
            dp[i]=min(dp[i],dp[i-power]+1);
            power*=9;
        }
    }
    
    cout<<dp[N]<<endl;
    
    return 0;
}

Measured memory_bytes: 640
import java.util.*;
// warm-up
public class Main {

	static void solve() {
		Scanner sc = new Scanner(System.in);
		Map<Integer, Integer> m = new HashMap<Integer, Integer>();
		int N = sc.nextInt(), t = 0;
		while (N-->0) {
			int a = sc.nextInt();
			m.put(a, m.get(a)==null ? 1 : m.get(a)+1);
		}
		for (int e : m.keySet()) if (e!=m.get(e)) t+=(m.get(e)>e) ? m.get(e)-e : m.get(e);
		System.out.println(t);
		sc.close();		
	}

	public static void main(String args[]) {
		solve();
	}

}

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

#if 0
所要時間は10分程度であった。この程度であればもう少し早く解ききれるようになりたい。
#endif

int main() {
 int n;
 cin >> n;
 vector<int> nums;

 for(int i=0;i<n;i++){
   int buff;
   cin >> buff;
   nums.push_back(buff);
 }

 long long sum=0;
 int min,max;

 min = nums[0];max=nums[0];

 for(auto itr=nums.begin(); itr!=nums.end();itr++){
   sum += *itr;
   if(*itr > max) max = *itr;
   if(*itr < min) min = *itr;
 }

 printf("%d %d %lld\n",min,max,sum);
}



Measured memory_bytes: 3368
#include <bits/stdc++.h>
#define int long long 

using namespace std;
const long double PI = acos(-1);
const int somod = 1e9 + 7;
const int maxn = 2e5 + 7;

int n, m, a[maxn];
vector<int> vt[maxn];
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin);
    cin >> n >> m;
    int limit = n * (n + 1) / 2, ans = 0;
    for(int i = m; i <= n + 1; i++)
    {
        int Min = i * (i - 1) / 2;
        int Max = (n + n - i + 1) * i / 2;
        ans += Max - Min + 1;
        ans %= somod;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 8332
#include<stdio.h>
#include<string.h>
int main(){
  int n,i;
  char str[5];
  while(1){
    int  ue=1,sita=6,hidari=4,migi=3,mae=2,usiro=5,tmp,sum=1;
  scanf("%d",&n);
  if(n==0)break;
  for(i=0;i<n;i++){
    scanf("%s",str);
    if(str[0]=='N'){
      tmp=mae;
      mae=sita;
      sita=usiro;
      usiro=ue;
      ue=tmp;
    }
    if(str[0]=='E'){
      tmp=hidari;
      hidari=sita;
      sita=migi;
      migi=ue;
      ue=tmp;
    }
    if(str[0]=='W'){
      tmp=migi;
      migi=sita;
      sita=hidari;
      hidari=ue;
      ue=tmp;
    }
    if(str[0]=='S'){
      tmp=usiro;
      usiro=sita;
      sita=mae;
      mae=ue;
      ue=tmp;
    }
    if(str[0]=='R'){
      tmp=mae;
      mae=migi;
      migi=usiro;
      usiro=hidari;
      hidari=tmp;
      
    }
    if(str[0]=='L'){
      tmp=mae;
      mae=hidari;
      hidari=usiro;
      usiro=migi;
      migi=tmp;
    }
    sum+=ue;
  }
  printf("%d\n",sum);
  }
  return 0;
}

Measured memory_bytes: 604
MOD = 10**9+7
N, M = map(int,input().split())
dp = [0]*(N+1)
dp[0] = 1
for i in range(M):
    dp[int(input())] = None
dp[1] = 1 if dp[1]==0 else 0
for i in range(2,N+1):
    if dp[i] == None:
        dp[i] = 0
    else:
        dp[i] = dp[i-1]+dp[i-2]
print(dp[-1]%MOD)

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

int main(){
  
  int N,M;
  cin >> N >> M;
  
  int m = min(N, M);
  int s = max(N, M);
  
  for(int i = 0; i < s; i++){
  	cout << m;
  }
  
  cout << endl;
}


Measured memory_bytes: 256
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

#print(a)

x = 0
y = 0
a[x][y] = '.'

while  x < h and y < w:
    #print(x, y)
    if x < h-1:
        if a[x+1][y] == '#':
            x += 1
            a[x][y] = '.'
            continue
    if y < w-1:
        if a[x][y+1] == '#':
            y += 1
            a[x][y] = '.'
            continue
    if x == h - 1 and y == w - 1:
        break
    else:
        print('Impossible')
        exit()

#for x in a: print(x)

for b in a:
    if '#' in b:
        print('Impossible')
        exit()


print('Possible')

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

int main()
{
    int N;
    cin >> N;
    vector<int> L(N);
    for(int i = 0; i < N; i++) {
        cin >> L[i];
    }

    int count = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i+1; j < N; j++) {
            for(int k = j+1; k < N; k++) {
                if(L[i] != L[j] && L[i] != L[k] && L[j] != L[k] &&
                        (L[i]+L[j]) > L[k] && (L[j]+L[k]) > L[i] && (L[k]+L[i]) > L[j]) {
                    count += 1;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3624
n,m,Q=map(int,input().split())

l=[]
r=[]
for i in range(m):
    a,b=map(int,input().split())
    l.append(a)
    r.append(b)

p=[]
q=[]    
for i in range(Q):
    c,d=map(int,input().split())
    p.append(c)
    q.append(d)

grid=[[0]*(n+1) for i in range(n+1)]

for i in range(m):
    grid[l[i]][r[i]]+=1

for i in range(1,n+1):
    for j in range(1,n+1):
        grid[i][j]+=grid[i-1][j]
        grid[i][j]+=grid[i][j-1]
        grid[i][j]-=grid[i-1][j-1]
    
for i in range(Q):
    print(grid[q[i]][q[i]]-grid[q[i]][p[i]-1]-grid[p[i]-1][q[i]]+grid[p[i]-1][p[i]-1])
    

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

using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> b(n - 1);
    for(auto&& i : b){
        cin >> i;
    }
    b.push_back(1e9 + 7);
    int ans = b[0];
    for(int i = 1; i < b.size(); i++){
        ans += min(b[i], b[i - 1]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
const int mod = 1e9+7;
ll dp[102][100001];
ll a[102];
int main(){
  int n,k;
  cin >> n >> k;
  a[0]=0;
  memset(dp,0,sizeof(dp));
  for(int i=1;i<=n;i++){
    cin >> a[i];
  }
  for(int i=0;i<=k;i++){
    dp[0][i] = 1;
  }
  for(int i=0;i<=n;i++){
    dp[i][0]=1;
  }
  for(int i=1;i<=n;i++){
    for(int j=1;j<=k;j++){
      if(j>a[i]){
        dp[i][j]=((dp[i-1][j]%mod-dp[i-1][j-a[i]-1]%mod+mod)%mod+dp[i][j-1]%mod)%mod;
      }
      else{
        dp[i][j]=(dp[i-1][j]%mod+dp[i][j-1]%mod)%mod;
      }
    }
  }
  cout<<((dp[n][k]%mod-dp[n][k-1]%mod+mod)%mod)<<endl;
}


Measured memory_bytes: 79872
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define sc(a,b,c) scanf("%lld %lld %lld",&a,&b,&c) 

int main()
{
	ll a,b,c;
	sc(a,b,c);

    ll n =a+b+c;
    if(n<22)
    {
    	printf("win\n");
	}
	else
	{
		printf("bust\n");
	}
}

Measured memory_bytes: 256
import heapq
N, M = map(int, input().split())

edges = [set() for _ in range(N)]

for _ in range(M):
    u, v = map(int, input().split())
    edges[u-1].add(v-1)

S, T = map(int, input().split())
S -= 1
T -= 1

cost = [-1 for _ in range(N)]
q = []
heapq.heappush(q, (0, S))

step1memo = set()
step2memo = set()
step3memo = set()

while len(q) != 0:
    c, u = heapq.heappop(q)
    if cost[u] != -1:
        continue
    cost[u] = c
    for u1 in edges[u]:
        if u1 in step1memo:
            continue
        step1memo.add(u1)
        for u2 in edges[u1]:
            if u2 in step2memo:
                continue
            step2memo.add(u2)
            for u3 in edges[u2]:
                heapq.heappush(q, (c+1, u3))

print(cost[T])


Measured memory_bytes: 116896
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int a[3],n;
	cin>>n;
	for(int k=0;k<n;k++){
		for(int i=0;i<3;i++){
			cin>>a[i];
       }
	   sort(a,a+3);
	   if((a[0]*a[0])+(a[1]*a[1])==a[2]*a[2])cout<<"YES"<<endl;
	   else cout<<"NO"<<endl;
	   }
	return 0;
	}


Measured memory_bytes: 3112
#include <iostream>
#include <string>

using namespace std;

string s;
string v[]={"0","SAT","FRI","THU","WED","TUE","MON","SUN"};
int i;
int main()
{
    cin>>s;
    for(i=1;i<=7;i++){
        if(s==v[i])
            cout<<i;
    }
    return 0;
}


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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

N = int(input())
As = list(map(int, input().split()))
print(max(As) - min(As))


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

struct edge{int to,cap,rev;};
const int INF = 1000000000;

vector <edge> G[100];
bool used[100];

void add_edge(int from,int to,int cap){
	G[from].push_back((edge){to,cap,G[to].size()});
	G[to].push_back((edge){from,0,G[from].size()-1});
}

int dfs(int v,int t,int f){
	if(v==t) return f;
	used[v] = true;
	for(int i=0;i<G[v].size();i++){
		edge &e = G[v][i];
		if(!used[e.to]&&e.cap>0){
			int d = dfs(e.to,t,min(e.cap,f));
			if(d>0){
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int max_flow(int s,int t,int V){
	int flow = 0;
	while(true){
		fill(used,used+V,false);
		int f = dfs(0,t,INF);
		if(f==0) return flow;
		else flow += f;
	}
}

int main(){
	int V,E;
	scanf("%d %d",&V,&E);
	for(int i=0;i<E;i++){
		int u,v,c;
		scanf("%d %d %d",&u,&v,&c);
		add_edge(u,v,c);
	}
	printf("%d\n",max_flow(0,V-1,V));
	return 0;
}

Measured memory_bytes: 2808
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define CALL(c) (c).cbegin(), (c).cend()
#define RALL(c) (c).rbegin(), (c).rend()
#define CRALL(c) (c).crbegin(), (c).crend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a, x, b) (a<=x && x<b)
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}
#define OUT(dist) std::cout<<(dist);
#define WS std::cout<<" ";
#define NL std::cout<<"\n"

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;
template<class T, int W=255> using A = array<T, W>;
template<class T, int W=255, int H=255> using A2 = array<array<T, W>, W>;

int n, m;
V<V<int>> e;
V<bool> vis;

int dfs(int ni) {
    bool ok = true;
    REP(i,n) if(!vis[i]) ok = false;
    if(ok) return 1;

    int ans = 0;
    REP(i, e[ni].size()) {
        if(vis[e[ni][i]]) continue;
        vis[e[ni][i]] = true;
        ans += dfs(e[ni][i]);
        vis[e[ni][i]] = false;
    }

    return ans;
}

int main(){
    INIT;
    cin >> n >> m;
    e.resize(n);
    REP(i,m) {
        int x, y; cin >> x >> y;
        x--; y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }

    vis.resize(n,false);
    vis[0] = true;
    cout << dfs(0) << "\n";
}

Measured memory_bytes: 256