akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <vector>
using namespace std;
typedef long long LL;
const int MAX=2e5+5;
const LL mod=1e9+7;
int n,c[MAX];
vector<int> st[MAX];
LL dp[MAX];
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;++i){
        scanf("%d",c+i);
    }
    n=unique(c+1,c+n+1)-c-1;
    static int prv[MAX];
    for(int i=1;i<=n;++i){
        if(prv[c[i]]!=0){
            st[i-1].push_back(prv[c[i]]);
        }
        prv[c[i]]=i;
    }
    dp[0]=1;
    for(int i=1;i<=n;++i){
        dp[i]=dp[i-1];
        for(int j=0;j<(int)st[i].size();++j){
            dp[i]=(dp[i]+dp[st[i][j]-1])%mod;
        }
    }
    printf("%lld\n",dp[n]);
    return 0;
}

Measured memory_bytes: 13440
while True:
    try:
        a,o,b = map(str, input().split())
    
        if o == "?":
            break
    
        ans = 0
        if o == "+":
            ans = int(a) + int(b)
        elif o == "-":
            ans = int(a) - int(b)
        elif o == "/":
            ans = int(a) // int(b)
        elif o == "*":
            ans = int(a) * int(b)
        print(ans)
        
    except EOFError:
        break


Measured memory_bytes: 5600
#include <bits/stdc++.h>
using namespace std;
long long mod=1e9+7;
int main() {
    int n;
    cin>>n;
    long long a[n];
    int b[n][62];
    int c[62];
    long long ans[62];
    memset(c,0,sizeof(c));
    memset(ans,0,sizeof(ans));
    memset(b,0,sizeof(b));
    for(int i=0;i<n;i++){
        cin>>a[i];
        long long k=a[i];
        int j=0;
        while(k){
            b[i][j]=k%2;
            c[j]+=b[i][j];
            k/=2;
            j++;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<62;j++){
            c[j]-=b[i][j];
            if(b[i][j]==1){
                ans[j]+=n-i-1-c[j];
            }
            else{
                ans[j]+=c[j];
            }
            ans[j]%=mod;
        }
    }
    long long z=0,yo;
    for(int i=0;i<62;i++){
        yo=1;
        for(int j=0;j<i;j++){
        yo*=2;
            yo%=mod;
        }
        yo*=ans[i];
        yo%=mod;
        z+=yo;
        z%=mod;
    }
    cout<<z%mod;
    return 0;
}


Measured memory_bytes: 75264
import java.util.*;

public class Main {

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


        String input = in.nextLine();
        input=input.replaceAll(" ","");
        if (input.matches("557")||input.matches("755")||input.matches("575")) System.out.println("YES");
        else System.out.println("NO");

    }
}


Measured memory_bytes: 19924
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int n, m, k;
int cnt[N];
string s;
int a[N];
vector < int > g[N];
int u[N];
int ans, res;
int cur;


int main () {
	SpeedForce;
	
	ll a, b, n;
	cin >> a >> b >> n;
	auto f = [&] (ll x) {
		ll res = ((ll)((a * x) / b)) - a * ((ll)(x/b));
		return res;
	};

	ll l = 1, r = n;
	while (r - l > 20) {
		ll m1 = (l + (r-l)/ 3);
		ll m2 = (r - (r-l) / 3);
		if (f(m1) > f(m2))
			r = m2;
		else
			l = m1;
	}
	ll res = f(n);
	for (int it = 0; it < n && it < 20; ++it)
		res = max(res, f(n-it-1));

	while(l <= r) res = max(res, f(l++));
	cout << res << '\n';

	return Accepted;
}

// B...a

Measured memory_bytes: 17668
def biscuit():
    cost,A,B=map(int,input().split())
    maisu=1
    if B-A<=2:
        return cost+1
    else:
        cost-=A-1#最初にA枚集まるまで殴り続ける
        maisu=A
        pocket=cost%2
        yen=cost//2
        return maisu+pocket+yen*(B-A)
print(biscuit())

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


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

#import numpy as np

from math import gcd
from collections import defaultdict

def main():
	n=II()
	mod=10**9+7

	ans=1
	cnt=0
	d=defaultdict(int)

	for _ in range(n):
		a,b=MI()
		if a==b==0:
			cnt+=1
		elif a==0:
			d[(1,0)]+=1
		elif b==0:
			d[(0,-1)]+=1
		else:
			g=gcd(abs(a),abs(b))
			if a*b>0:
				d[(abs(a//g),abs(b//g))]+=1
			else:
				d[(abs(a//g),-abs(b//g))]+=1


	s=set()

	for a,b in list(d):
		#print(a,b,s)
		if (a,b) in s:
			continue
		if b>=0:
			x=d[(a,b)]
			y=d[(b,-a)]
			s.add((a,b))
			s.add((b,-a))
		else:
			x=d[(a,b)]
			y=d[(-b,a)]
			s.add((a,b))
			s.add((-b,a))
		ans*=2**x+2**y-1
		ans%=mod
	ans+=cnt-1
	print(ans%mod)

if __name__ == "__main__":
	main()


Measured memory_bytes: 130704
import java.util.*;
import java.io.*;
import java.lang.Math;
public class Main{
    public static void main(String[] args){
        Scanner sn = new Scanner(System.in);


        //入力読み込み
        int i =0;
        int N =0;
		ArrayList<Integer> list = new ArrayList<Integer>();
        while (sn.hasNextLine()) {
        		String str = sn.nextLine();
            try{
                if(i ==0){
                    N = Integer.parseInt(str);
                    if(N<2 || N>200000){
                        System.out.println("error");
                        return;
                    }
                }else{
                    int x = Integer.parseInt(str);
                    if(x<1 || x > 200000){
                        System.out.println("error2");
                        return;
                    }
					list.add(x);
                }
            }catch(Exception e){
                System.out.println("error3");
                //do nothing
                return;
            }
            i++;
            if(i>N){
                break;
            }
        }     
        sn.close();  

        //logic1
		int y = 0;
		try{
		Integer m = Collections.max(list);
		int maxarray = list.indexOf(m);
		list.remove(maxarray);
		Integer n = Collections.max(list);
		
		for (int j = 0; j < N; j++){
			if(j == maxarray){
				System.out.println(n);
			}else{
				System.out.println(m);
			}
		}
		}catch(Exception e){
			System.out.println(e);
		}
	}
  }

Measured memory_bytes: 156752
#include<stdio.h>

int main(void)
{  
	int a,b,c,d=0,i;
	
	scanf("%d %d %d",&a,&b,&c);
	for(i=a;i<=b;i++){
	if(c%i==0)d++; 
	}
	printf("%d\n",d);

	return 0;
}

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

int main() {
  int a,b,c,d,L,R;
  
  cin >> a >> b >> c >> d;
  L = a + b;
  R = c + d;
  if (L > R){
    cout << "Left" << endl;
  }
  else if(R > L){
    cout << "Right" << endl;
  }
  else {
    cout << "Balanced" << endl;
  }
}
  

Measured memory_bytes: 256
#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
fileoperation=0
if(fileoperation):
    orig_stdout = sys.stdout
    orig_stdin = sys.stdin
    inputfile = open('W:/Competitive Programming/input.txt', 'r')
    outputfile = open('W:/Competitive Programming/output.txt', 'w')
    sys.stdin = inputfile
    sys.stdout = outputfile

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    t,a= map(int, sys.stdin.readline().split(' '))
    b=list(map(int,sys.stdin.readline().split(' ')))
    v=(t-a)//(0.006)

    diff=mod
    ans=0

    for i in range(n):
        te=v-b[i]
        if(abs(te)<diff):
            diff=abs(te)
            ans=i

    print(ans+1)

    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

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

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//cout << fixed << setprecision(6);
	string s;
	cin >> s;
	if(s[2] == s[3] && s[4] == s[5]){
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    #define rep(i, n) for (int i = 0; i < (int)(n); i++)
     
    int main() {
      char n;
      cin  >> n;
      
      if (n == 'a' || n == 'i' || n == 'u' || n == 'e' || n == 'o') {
        cout << "vowel" << endl;
      }
      else {
        cout << "consonant" << endl;
      }

      
    }

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,m; cin>>n>>m;
	vector<vector<int>>v(m);
	for(int i=0;i<m;++i){
		int k; cin>>k;
		for(int j=0;j<k;++j){
			int s; cin>>s; --s;
			v.at(i).emplace_back(s);
		}
	}
	vector<int>p(m); for(auto&&i:p)cin>>i;
	int ans=0;
	for(int i=0;i<(1<<n);++i){
		vector<bool>sw(n,false);
		for(int j=0;j<n;++j){
			if(i&(1<<j))sw.at(j)=true;
		}
		int tans=0;
		for(int j=0;j<v.size();++j){
			int cnt=0;
			for(int k=0;k<v.at(j).size();++k){
				if(sw.at(v.at(j).at(k)))++cnt;
			}
			if(cnt%2==p.at(j))++tans;
		}
		if(tans==m)++ans;
	}
	cout<<ans<<"\n"s;
}

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

typedef long long ll;

using vi = vector<int>;

using vii = vector<vector<int>>;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
       const int INF=1e9+7;
    int n,k,temp=INF;
 
    cin>>n>>k;
    vi arr(n+1);
    vi dp(n+1);  //dp[i]: minimum cost to reach stone i.
    dp[1]=0;
    for(int i=1;i<=n;i++)cin>>arr[i];
for(int i=2;i<=min(n,k);i++)
{
    temp=INF;
    for(int j=1;j<i;j++)temp=min(temp,dp[j]+abs(arr[i]-arr[j]));
        dp[i]=temp;
}

for(int i=k+1;i<=n;i++)
{
    temp=INF;
    for(int j=1;j<=k;j++)temp=min(dp[i-j]+abs(arr[i]-arr[i-j]),temp);
    dp[i]=temp;
}

cout<<dp[n]<<"\n";




return 0;

}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];

    vector<ll> b, c;

    rep(i, n) {
        if (i % 2 == 0) b.push_back(a[i]);
        else c.push_back(a[i]);
    }

    if (n % 2 == 0) {
        reverse(c.begin(), c.end());
        rep(i, c.size()) cout << c[i] << " ";
        rep(i, b.size()) {
            cout << b[i];
            if (i < (int)b.size() - 1) cout << " ";
        }
        cout << endl;
    }
    else {
        reverse(b.begin(), b.end());
        rep(i, b.size()) cout << b[i] << " ";
        rep(i, c.size()) {
            cout << c[i];
            if (i < (int)c.size() - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 5484
import java.util.*;

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

        int a = sc.nextInt();
        int b = sc.nextInt();

        int count = 0;
        int sockets = 1;
        for (int i = 1; i < b; i+=a) {
            i--;
            count++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 23252
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

int main()
{	
	double posX=0;
	double posY=0;
	double angle=90;
	string str;
	while(getline(cin,str,',')){
		string str2;
		getline(cin,str2);

		int a,b;
		sscanf(str.c_str(),"%d",&a);
		sscanf(str2.c_str(),"%d",&b);

		if(a==0 && b==0) break;

		posX -= a * sin(M_PI/2.0 -angle/180.0*M_PI);
		posY += a * cos(M_PI/2.0 -angle/180.0*M_PI);

		angle += b;	
	}
	printf("%.0f\n%.0f\n",floor(posX),ceil(posY));
}

Measured memory_bytes: 0
#include <stdio.h>
int main(){
  int a,b;
  int c=0;
  int i;
  scanf("%d %d",&a,&b);
  for(i=0;i<2;i++){
  	if(a>b){
   	 c+=a;
   	 a--;
 	 }else{
   	 c+=b;
   	 b--;
	 }
  }
  printf("%d\n",c);
  return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main(){
    int x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int dx, dy;
    dx = x2-x1;
    dy = y2-y1;
    cout << x2-dy << ' ' << y2+dx << ' ' << x1-dy << ' ' << y1+dx << endl;
    return 0;
}

Measured memory_bytes: 256
// Contest.cpp : コンソール アプリケーションのエントリ ポイントを定義します。
//

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <list>
#include <set>
#include <numeric>
#include <ios>
#include <iomanip>

using namespace std;

int main()
{
	int n, a, b;
	cin >> n >> a >> b;
	if ((b - a) % 2 == 0)puts("Alice");
	else puts("Borys");
	return 0;
}



Measured memory_bytes: 256
use std::io;
use std::cmp;

fn main() {
    let (a, b, c, x, y) = {
        let i = read::<usize>();
        (i[0], i[1], i[2], i[3], i[4])
    };

    let or = x * a + y * b;
    let ab_max = cmp::max(x, y) * 2 * c;
    let ab_min = cmp::min(x, y) * 2 * c + if x < y { (y - x) * b } else { (x - y) * a };
    println!("{}", cmp::min(or, cmp::min(ab_min, ab_max)));
}

#[allow(unused)]
fn read<T>() -> Vec<T>
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}


#[allow(unused)]
fn read_one<T>() -> T
where
    T: std::str::FromStr,
    T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 2144
#include<stdio.h>
#include<string.h>

int main(){
  int k;
  char str[100], copy[100]={0};
  scanf("%d",&k);
  scanf("%s",str);
  if(strlen(str)>k){
    printf("%s...\n",memcpy(copy,str,k));
  }else {
    printf("%s\n",str);
  }
  return 0;
}

Measured memory_bytes: 1704
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<queue>
#include<cmath>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<stack>
#include<cstdio>
#include<bitset>
#include<unordered_map>
#include<climits>
#include<fstream>
using namespace std;
///////////////////library zone!!!!!!!!!!!!!!!!!!!!!!!!!!!!
typedef long long ll;
typedef long double ld;
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll mod = 998244353;
struct H {
	ll x, y;
	bool operator<(const H &b) const {
		if (x != b.x) return x < b.x;
		return y < b.y;
	}
	bool operator>(const H &b) const {
		if (x != b.x) return x > b.x;
		return y > b.y;
	}
	bool operator==(const H &b) const { return x == b.x&&y == b.y; }
	bool operator!=(const H &b) const { return (*this) != b; }
};
struct P {
	ll pos, cost;
	bool operator<(const P &b) const { return cost < b.cost; }
	bool operator>(const P &b) const { return cost > b.cost; }
};
struct B {
	ll to, cost;
};
struct E {
	ll from, to, cost;
	bool operator<(const E &b) const { return cost < b.cost; }
	bool operator>(const E &b) const { return cost > b.cost; }
};
template<typename T, typename U>
void chmin(T &a, U b) {
	if (a > b) a = b;
}
template<typename T, typename U>
void chmax(T &a, U b) {
	if (a < b) a = b;
}
template<typename T>
T max_0(T a) {
	if (a < 0) return 0;
	return a;
}
template<typename T>
T min_0(T a) {
	if (a > 0) return 0;
	return a;
}
ll read() {
	ll u;
	ll k = scanf("%lld", &u);
	return u;
}
ll gcd(ll i, ll j) {
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcd(j%i, i);
}
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * x % p;
		x = x * x % p;
		n >>= 1;
	}
	return res;
}//x^n%p
const ll Inf = 3023372036854775807;
const int inf = 1500000000;
#define int long long
//----------------------------------------------------
string s, p;
signed main() {
	cin >> s;
	int ans = 0;
	while (cin >> p && p != "END_OF_TEXT") {
		for (int i = 0; i < s.size(); i++) {
			if ('A' <= s[i] && s[i] <= 'Z') {
				s[i] += ('a' - 'A');
			}
			if (i >= p.size()) break;
			if ('A' <= p[i] && p[i] <= 'Z') {
				p[i] += ('a' - 'A');
			}
		}
		if (s == p) ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    string S;
    int Q;
    cin >> S >> Q;
    int T, F;
    char C;
    bool rev = false;
    while (Q--)
    {
        cin >> T;
        if (T == 1) rev = !rev;
        else
        {
            cin >> F >> C;
            if (F == 1 ^ rev) S.insert(S.begin(), C);
            else S.push_back(C);
        }
    }
    if (rev) reverse(all(S));
    cout << S << endl;
    return 0;
}

Measured memory_bytes: 900
#include <iostream>
using namespace std;
int g(int a, int b){
    if(a%b==0)return b;
    return g(b, a%b);
}
int main(void){
    int n, a[100000], l[100000], r[100000], x=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    l[0]=a[0];
    for(int i=1;i<n;i++){
        l[i]=g(l[i-1], a[i]);
    }
    r[n-1]=a[n-1];
    for(int i=n-2;i>=0;i--){
        r[i]=g(r[i+1], a[i]);
    }
    x=max(l[n-2], r[1]);
    for(int i=1;i<n-1;i++){
        x=max(x, g(l[i-1], r[i+1]));
    }
    cout<<x<<endl;
}


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

int tab[10][10];
int to(char c){
  return c-'0';
}

int f(string& s){
  int l = 0;
  for(int i=0;i<4;++i)
	l = tab[l][to(s[i])];
  return l;
}

bool check(string& s){
  int x = f(s);
  x = tab[x][to(s[4])];
  return x == 0;
}

bool checkalter(string s){
  for(int i=0;i<5;++i){
	for(char c='0';c<='9';++c){
	  string tmp = s;
	  tmp[i] = c;
	  if(tmp == s) continue;
	  if(check(tmp)) return false;
	}
  }

  return true;
}

bool checktrans(string s){
  for(int i=0;i<4;++i){
	string tmp = s;
	swap(tmp[i], tmp[i+1]);
	if(s == tmp) continue;
	if(check(tmp)) return false;
  }
  return true;
}

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

  REP(i,10) REP(j,10) cin >> tab[i][j];

  int ans = 0;
  for(int i=0;i<10000;++i){
	string s = to_string(i);
	s = string(4-SZ(s), '0') + s;
	string enc = s + string(1, '0'+f(s));
	if(!checkalter(enc) || !checktrans(enc))
	  ++ans;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3288
n=int(input())
data=[list(map(int,input().split(' '))) for _ in range(n)]

cnt=0
flag = False
for i in range(n):
    if data[i][0] == data[i][1]:
        cnt += 1
    else:
        cnt = 0
    if cnt >= 3:
        flag = True
        break

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9192
import numpy as np
input()
x = list(map(int, input().split()))
x.sort()
x=np.array(x)
ans=0
for i in x[:-2]:
    y = x[x>i]
    for j in y:
        z = y[y>j]
        for k in z:
            if i+j>k:
                ans+=1
print(ans)

Measured memory_bytes: 27268
from bisect import bisect_left
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
b,c = [a[0]],[False for i in range(n)]
for i in range(1,n): b.append(b[-1]+a[i])
for i in range(n-1,-1,-1):
	x = bisect_left(a,b[i]*2+0.5)
	if x==n: c[i] = True
	elif c[x-1]: c[i] = True
print(sum(c))

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

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
	int n; cin >> n;
	string s[n];
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	for (int i = 0; i < n-1; i++) {
		if (s[i][s[i].size()-1] != s[i+1][0]) {
			cout << "No\n";
			return 0;
		}
	}   
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (i != j && s[i] == s[j]) {
				cout << "No\n";
				return 0;
			}
		}
	}
	cout << "Yes\n";
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
static const ll maxLL = (ll) 1 << 62;
const ll MOD = 1000000007, INF = 1e18;

template<typename T1, typename T2>
bool pairCompare(const pair<T1, T2> &firstElof, const pair<T1, T2> &secondElof) {
    return firstElof.second > secondElof.second;
}

int mapMaxValue(std::map<ll, int> m) {
    int max = 0;
    for (std::map<ll, int>::iterator it = m.begin(); it != m.end(); it++) {
        if (max < it->second) max = it->second;
    }
    return max;
}

int main(void) {
    int n;
    cin >> n;
    vector<string> s(n);
    vll anagram_count;
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    sort(s.begin(), s.end());

    ll cnt = 1;
    string prev_str = "";
    for (int i = 0; i < n; ++i) {
        if (s[i] != prev_str) {
            if (cnt > 1) {
                anagram_count.pb(cnt);
                cnt = 1;
            }
        } else {
            cnt++;
            if (i == n - 1 && cnt > 1) anagram_count.pb(cnt);
        }
        prev_str = s[i];
    }

    ll ans = 0;
    for (auto ana_count : anagram_count) {
        ans += (ll) (ana_count == 1 ? 1 : ana_count * (ana_count - 1) / 2);
    }
    cout << ans << endl;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 6e3 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, m, k, dp[maxn][maxn];

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

	cin >> n >> m >> k;

	if (!n || !m)
	{
		cout << 1 << endl;
		return 0;
	}

	dp[1][k - 1] += 1;
	dp[k][0] -= 1;
	for (int i = k; i <= n + m; i++)
	{
		for (int j = 1; j <= i; j++)
			dp[j][i - j] = (dp[j][i - j] + dp[j - 1][i - j + 1]) % mod;
		
		for (int j = 0; j <= i; j++)
			if (dp[j][i - j])
			{
				dp[j][i - j + k - 1] = (dp[j][i - j + k - 1] + dp[j][i - j]) % mod;
				if (i - j - 1 >= 0)
					dp[j + k - 1 + 1][i - j - 1] = (dp[j + k - 1 + 1][i - j - 1] - dp[j][i - j] + mod) % mod;
			}
	}

	ll ans = 0;
	for (int i = n; i >= 0 + (n > 0); i -= (k - 1))
		for (int j = m; j >= 0 + (m > 0); j -= (k - 1))
			ans = (ans + dp[i][j]) % mod;
	cout << ans << endl;
}



Measured memory_bytes: 142976
def ans(N):
  if N < 13:
    return N
  high = N
  low = 0
  while 1 < high - low:
    med = (high + low) // 2
    p = int(med * 1.08)
    if p == N:
      return med
    if p < N:
      low = med
    if N < p:
      high = med
  return ':('
N = int(input())
print(ans(N))

Measured memory_bytes: 3064
import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline

# mod=10**9+7
# rstrip().decode('utf-8')
# map(int,input().split())
# import numpy as np


def main():
	n=int(input())
	li=[[0,0,0]]+[list(map(int,input().split())) for _ in range(n)]
	td=[]
	for i in range(n):
		td.append((li[i+1][0]-li[i][0],abs(li[i+1][1]-li[i][1])+abs(li[i+1][2]-li[i][2])))

	ans="Yes"

	for t,d in td:
		if t<d or t%2!=d%2:
			ans="No"

	print(ans)
















if __name__ == "__main__":
	main()


Measured memory_bytes: 36396
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    vector<unordered_map<int, int>> vm(m, unordered_map<int, int>());
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        vm[x % m][x]++;
    }
    vector<pair<int, int>> vp(m, make_pair(0, 0));
    for (int i = 0; i < m; i++) {
        for (auto p : vm[i]) {
            vp[i].first += p.second % 2;
            vp[i].second += p.second / 2 * 2;
        }
    }
    int res = 0;
    res += (vp[0].first + vp[0].second) / 2;
    for (int i = 1; i <= m - i; i++) {
        if (i == m - i) {
            res += (vp[i].first + vp[i].second) / 2;
        } else {
            auto p1 = vp[i], p2 = vp[m - i];
            int r = min(p1.first, p2.first);
            p1.first -= r;
            p2.first -= r;
            res += r;
            if (p1.first > 0) {
                r = min(p1.first, p2.second);
                res += r;
                p2.second -= r;
                res += p1.second / 2;
                res += p2.second / 2;
            } else {
                r = min(p2.first, p1.second);
                res += r;
                p1.second -= r;
                res += p1.second / 2;
                res += p2.second / 2;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 15552
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 100005

int main(){

	int N;
	scanf("%d",&N);

	char A[2],B[2],current[2];

	scanf("%s %s",A,B);

	bool is_T = (B[0] == 'T') || (A[0] == 'F');

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

		scanf("%s",current);

		if(current[0] == 'T'){

			is_T = true;

		}else{

			if(is_T){

				is_T = false;
			}else{

				is_T = true;
			}
		}
	}

	if(is_T){

		printf("T\n");

	}else{

		printf("F\n");
	}

	return 0;
}



Measured memory_bytes: 3160
H1, M1, H2, M2, K = map(int, input().split())

import datetime
dt1 = datetime.datetime(year=2020, month=5, day=29, hour=H1, minute=M1)
dt2 = datetime.datetime(year=2020, month=5, day=29, hour=H2, minute=M2)

tmp = dt2 - datetime.timedelta(minutes=K)
tmp2 = dt2 - dt1
ans = (tmp - dt1).total_seconds() / 60

if (tmp2.total_seconds()) <= 0:
        print(0)
        exit()
else:
        print(int(ans))



Measured memory_bytes: 9440
#include <stdio.h>
char s[55][55]={};
int bomb(int i,int j){
  return (s[i][j] == '#')? 1:0;
}

int main(){
  int h,w;
  int a[55][55]={};
  scanf("%d%d",&h,&w);
  for(int i=0;i<h;i++){
    scanf("%s",s[i]);
  }
  if(s[0][0]!='#'){ s[0][0]='0';
                       s[0][0]+=bomb(0,1);
    s[0][0]+=bomb(1,0);s[0][0]+=bomb(1,1);
  }
  for(int j=1;j<w-1;j++){
    if(s[0][j]!='#'){ s[0][j]='0';
      s[0][j]+=bomb(0,j-1);                   s[0][j]+=bomb(0,j+1);
      s[0][j]+=bomb(1,j-1);s[0][j]+=bomb(1,j);s[0][j]+=bomb(1,j+1);
    }
  }
  if(s[0][w-1]!='#'){ s[0][w-1]='0';
    s[0][w-1]+=bomb(0,w-2);
    s[0][w-1]+=bomb(1,w-2); s[0][w-1]+=bomb(1,w-1);
  }
  for(int i=1;i<h-1;i++){
    if(s[i][0]!='#'){ s[i][0]='0';
      s[i][0]+=bomb(i-1,0);s[i][0]+=bomb(i-1,1);
                           s[i][0]+=bomb(i,1);
      s[i][0]+=bomb(i+1,0);s[i][0]+=bomb(i+1,1);
    }
    for(int j=1;j<w-1;j++){
      if(s[i][j]!='#'){ s[i][j]='0';
        s[i][j]+=bomb(i-1,j-1);s[i][j]+=bomb(i-1,j);s[i][j]+=bomb(i-1,j+1);
        s[i][j]+=bomb(i,j-1);                       s[i][j]+=bomb(i,j+1);
        s[i][j]+=bomb(i+1,j-1);s[i][j]+=bomb(i+1,j);s[i][j]+=bomb(i+1,j+1);
      }
    }
    if(s[i][w-1]!='#'){ s[i][w-1]='0';
    s[i][w-1]+=bomb(i-1,w-2);s[i][w-1]+=bomb(i-1,w-1);
    s[i][w-1]+=bomb(i,w-2);
    s[i][w-1]+=bomb(i+1,w-2);s[i][w-1]+=bomb(i+1,w-1);
    }
  }
  if(s[h-1][0]!='#'){ s[h-1][0]='0';
    s[h-1][0]+=bomb(h-2,0);s[h-1][0]+=bomb(h-2,1);
                           s[h-1][0]+=bomb(h-1,1);
  }
  for(int j=1;j<w-1;j++){
    if(s[h-1][j]!='#'){ s[h-1][j]='0';
      s[h-1][j]+=bomb(h-2,j-1);s[h-1][j]+=bomb(h-2,j);s[h-1][j]+=bomb(h-2,j+1);
      s[h-1][j]+=bomb(h-1,j-1);                       s[h-1][j]+=bomb(h-1,j+1);
    }
  }
  if(s[h-1][w-1]!='#'){ s[h-1][w-1]='0';
    s[h-1][w-1]+=bomb(h-2,w-2);s[h-1][w-1]+=bomb(h-2,w-1);
    s[h-1][w-1]+=bomb(h-1,w-2);
  }
  for(int i=0;i<h;i++){
    printf("%s\n",s[i]);
  }
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
 
const double pi = 3.141592653589793238462643383279;
using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
 
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
 
//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007
 
 
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)

const long double EPS = 1e-6, PI = acos((long double)-1);

//ここから編集


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(4);

  int x; cin >> x;
  cout << (x^1) << endl;
}

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

int main() {
	int n;
	bool a[4][13];
	for (int i = 0; i < 4; i++)
		for (int j = 0; j < 13; j++)
			a[i][j] = true;
	cin >> n;
	for (int i = 0; i < n; i++) {
		char c;
		int r;
		cin >> c >> r;
		switch (c) {
		case 'S':
			a[0][r - 1] = false;
			break;
		case 'H':
			a[1][r - 1] = false;
			break;
		case 'C':
			a[2][r - 1] = false;
			break;
		case 'D':
			a[3][r - 1] = false;
			break;
		}
	}
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 13; j++) {
			if (a[i][j]) {
				switch (i) {
				case 0:
					cout << "S " << j + 1 << endl;
					break;
				case 1:
					cout << "H " << j + 1 << endl;
					break;
				case 2:
					cout << "C " << j + 1 << endl;
					break;
				case 3:
					cout << "D " << j + 1 << endl;
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 3088
package main

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

// 文字列変換
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	str := sc.Text()
	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())
	for i := 0; i < q; i++ {
		sc.Scan()
		ary := strings.Split(sc.Text(), " ")
		a, _ := strconv.Atoi(ary[1])
		b, _ := strconv.Atoi(ary[2])
		switch ary[0] {
		case "replace":
			str = str[:a] + ary[3] + str[b+1:]
		case "reverse":
			str = str[:a] + reverse(str[a:b+1]) + str[b+1:]
		case "print":
			fmt.Printf("%v\n", str[a:b+1])
		}
	}
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}



Measured memory_bytes: 1308
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<int> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1000000000;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

vector<vector<pair<int,int>>> edge(100001, vector<pair<int, int>>(0));
vector<bool> color(100001, false);

void dfs(int v, int p, ll dis) {
	color[v] = dis % 2;
	REP(i, edge[v].size()) {
		if (edge[v][i].first != p)
			dfs(edge[v][i].first, v, dis + edge[v][i].second);
	}
	return;
}

int main() {
	int n;
	cin >> n;
	int u, v, w;
	REP(i, n - 1) {
		cin >> u >> v >> w;
		edge[u].push_back({ v,w });
		edge[v].push_back({ u,w });
	}
	dfs(1, -1, 0);
	REP(i, n)
		cout << color[i + 1] << '\n';
}

Measured memory_bytes: 8064
#include <iostream>
#include <cstdlib>
#include <vector>
#include <string>
#include <climits>
#include <algorithm>
#include <functional>
#include <string.h>

#define LOP(N) for(int i=0; i<N; i++)
#define LOOP(i, N) for(int i=0; i<N; i++)
#define LOOP_s(i, start, end) for(int i=start; i<end; i++)

using namespace std;


int main() {
    int as, ae, bs, be;
    cin >> as >> ae >> bs >> be;
    int len = min(ae, be) - max(as, bs);
    if (len < 0) len = 0;
    cout << len;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void) 
{
	char s[3];
	cin>>s[0]>>s[1]>>s[2];
	if(s[0]=='R' && s[1]=='R' && s[2]=='R')
	cout<<"3\n";
	else if((s[0]=='R' && s[1]=='R')||(s[2]=='R' && s[1]=='R'))
	cout<<"2\n";
	else if(s[0]=='S' && s[1]=='S' && s[2]=='S')
	cout<<"0\n";
	else
	cout<<"1\n";
}

Measured memory_bytes: 3588
# coding: utf-8
def get_ln_inputs():
    return input().split()


def map_list(fn, xs):
    return list(map(fn, xs))


def get_ln_int_inputs():
    return map_list(int, get_ln_inputs())


def possible_to_insert(S, T, index):
    if index + len(T) > len(S):
        return False
    for i in range(len(T)):
        if S[index + i] != "?" and S[index + i] != T[i]:
            return False
    return True


def main():
    S = get_ln_inputs()[0]
    T = get_ln_inputs()[0]

    ins_idx = -1
    for i in range(len(S)):
        if possible_to_insert(S, T, i):
            ins_idx = i

    if ins_idx == -1:
        print("UNRESTORABLE")
        return

    S = S[:ins_idx] + T + S[ins_idx + len(T):]
    print(S.replace("?", "a"))

    return


main()

Measured memory_bytes: 3064
#!/usr/bin/env ruby
require 'set'

Node = Struct.new('Node', :index, :next)

Nodes = [nil]

def find_cycle()
  visited = []
  visited_set = Set.new
  last_visited_count = 0
  current = Nodes[1]
  loop do
    visited_set << current.index
    if visited_set.size == last_visited_count
      start_point = visited.index(current.index)
      return visited[start_point..-1]
    end
    visited << current.index
    last_visited_count = visited_set.size
    current = Nodes[current.next]
  end
end

n, k = gets.split.map(&:to_i)

teles = gets.split.map(&:to_i)
teles.each_with_index do |next_node, idx|
  Nodes << Node.new(idx + 1, next_node)
end

rest_step = k - 1
pos = Nodes[teles[0]].index
cycle_nodes = find_cycle
# p cycle_nodes
cycle_start = cycle_nodes[0]

while pos != cycle_start && rest_step > 0
  rest_step -= 1
  current = Nodes[pos]
  pos = Nodes[current.next].index
end

res = pos

if rest_step > 0
  res = cycle_nodes[rest_step % cycle_nodes.size]
end

puts res


Measured memory_bytes: 47656
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner (System.in)){
			boolean flag = false;
			//arrayを配置
			int n = sc.nextInt();
			int[] array1 = new int[n];
			for (int i=0; i<n; i++) array1[i] = sc.nextInt();
			int m = sc.nextInt();
			int[] array2 = new int[m];
			for (int i=0; i<m; i++) array2[i] = sc.nextInt();
			//-------------------------------------------------------
			for (int i=0; i<Math.min(n,m);i++) {
				if (array1[i] != array2[i]) {
					System.out.println(array1[i] >= array2[i]? '0':'1');
					flag = true;
					break;
				}
			}
			if (!flag) {
				System.out.println( n>=m ? '0':'1');
			}
		}
	}
}


Measured memory_bytes: 31728
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc;
		String str="";
		float syori=0;
		float max=0;
		float min=0;
		int counter=0;

	sc=new Scanner(System.in);
		while(sc.hasNext()) {
			str=sc.next();
			syori=Float.parseFloat(str);
			if(counter==0) {
				min=syori;
				max=syori;
			}
			else {
				if(min>syori) {
					min=syori;
				}
				else if(max<syori) {
					max=syori;
				}
			}
			counter++;
		}
		System.out.println(max-min);
	}
}


Measured memory_bytes: 25952
import java.util.*;
import java.io.*;
import java.math.*;
public class Main {
    public static void main(String[]args){
		Scanner sc = new Scanner(System.in);
		PrintWriter ou = new PrintWriter(System.out);
		int n = Integer.parseInt(sc.next());
		int[] l = new int[n];
		for(int i = 0 ; i < n ; i++) l[i] = Integer.parseInt(sc.next());
		Arrays.sort(l);
		int yono = 0;
		for(int i = 0 ; i < n - 1 ; i++) yono += l[i];
		if(yono > l[n - 1]) ou.println("Yes");
		else ou.println("No");
		ou.flush();
	}
}

Measured memory_bytes: 35700
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
const int INF = 100000000;
const int MOD = 1000000007;
bool IsPrime(int num)//素数判定
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
int main(){
  std::ios::sync_with_stdio(false);
    std::cin.tie(0);
  std::vector<int> a(100001,0);
  for (int i =3; i <= 100000; i++) {
    /* code */
    if(i%2!=0){
      if(IsPrime(i)&&IsPrime((i+1)/2))a[i]=a[i-1]+1;
      else a[i]=a[i-1];
    }
    else a[i]=a[i-1];
  }
  int q;
  std::cin >> q;
  rep(i,q){
    int l,r;
    std::cin >> l>>r;
    std::cout <<a[r]-a[l-1] << std::endl;
  }
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a) (a).begin(),(a).end()
typedef long long ll;
typedef vector<int> VI;
typedef vector< vector<int> > VII;
typedef pair<int,int> PII;

int main(){
  int A,B;
  cin>>A>>B;
  int ans=1,sum=A;
  if(B==1) cout<<0<<endl;
  else{
    while(sum<B){
      sum+=A-1;
      ans++;
    }
    cout<<ans<<endl;
  }
}




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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat (i, a, b) for (int i = (a); i < (b); i++)
#define rep (i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int n;
    cin >> n;
    int res = 0;
    if (n <= 9) {
        res += n;
    } else if (10 <= n && n <= 99) {
        res += 9;
    } else if (100 <= n && n <= 999) {
        res += 9;
        res += n - 99;
    } else if (1000 <= n && n <= 9999) {
        res += 9;
        res += 900;
    } else if (10000 <= n && n <= 99999) {
        res += 9;
        res += 900;
        res += n - 9999;
    } else {
        res = 90909;
    }
    out(res);
}


Measured memory_bytes: 256
#include<bits/stdc++.h> 
#define range(i,a,b) for(int i = (a); i < (b); i++){
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x) cerr << #x << " = " << (x) << endl;
using namespace std;

struct Data{
	int m, d, s, v;
	int start, end;
};

int dayCount(int start, int end){
	int res = 0;
	while(start != end){
		res++;
		start++;
		if(start == 360) start = 0;
	}
	return res;
}

bool isHoliday(int x, Data d){
	for(int i = d.start; i != d.end + 1 ; i++){
		if(i == 360) i = 0;
		if(i == x) return true;
	}
	return false;
}

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


	Data d[205];
	rep(i,n){
		cin >> d[i].m >> d[i].d >> d[i].v >> d[i].s;
		d[i].start = (d[i].m - 1) * 30 + (d[i].d - 1);
		d[i].end = d[i].start + d[i].v - 1;
		if(d[i].end >= 360) d[i].end -= 360;
	}

	vector<int> v(360,0);
	rep(i,360){
		rep(j,n){
			if(isHoliday(i, d[j])) v[i] = max(v[i], d[j].s);
			else{
				v[i] = max(v[i], max(0, d[j].s - min(dayCount(i, d[j].start), dayCount(d[j].end, i))));
			}
				//cout << i << ' ' << d[j].start << endl;
		}
	}
	
	cout << *min_element(all(v)) << endl;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n;
    cin >> n;
    vector<lint> a(n), b(n);
    vector<lint> amb, bma;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }
    lint k = 0;
    for (int i = 0; i < n; ++i) {
        if (a[i] < b[i]) {
            lint cnt = (b[i] - a[i] + 1) / 2;
            a[i] += 2 * cnt;
            k += cnt;
        }
    }
    for (int i = 0; i < n; ++i) {
        k -= max(0LL, a[i] - b[i]);
    }
    if (k < 0)
        cout << "No"
             << "\n";
    else
        cout << "Yes"
             << "\n";
    return 0;
}

Measured memory_bytes: 384
n = int(input())
f = [0]*n
for i in range(n):
  f[i] = [int(x) for x in input().split()]

p = [0]*n
for i in range(n):
  p[i] = [int(x) for x in input().split()]

ans = -10**9-7

for i in range(2**10):
  o = [0]*10
  for j in range(10):
    if (i >> j) & 1:
      o[j] = 1
  if not any(o):
    continue
  sub = 0
  for k in range(n):
    key = 0
    for j in range(10):
      if o[j] and f[k][j]:
        key += 1
    sub += p[k][key]
  if sub > ans:
    ans = sub

print(ans)

Measured memory_bytes: 3064
class dice:
    def __init__(self, lable):
        self.top, self.front, self.right, self.left, self.rear, self.bottom = label
    
    def roll(self, odr):
        if odr == 'N': self.top, self.front, self.bottom, self.rear = \
            self.front, self.bottom, self.rear, self.top
        elif odr == 'E': self.top, self.left, self.bottom, self.right = \
            self.left, self.bottom, self.right, self.top
        elif odr == 'W': self.top, self.right, self.bottom, self.left = \
            self.right, self.bottom, self.left, self.top
        elif odr == 'S': self.top, self.rear, self.bottom, self.front = \
            self.rear, self.bottom, self.front, self.top
    def print_top(self): print(self.top)
label = list(map(int, input().split()))
odr_list = list(input())
d = dice(label)
for odr in odr_list:
    d.roll(odr)
d.print_top()
        




Measured memory_bytes: 5600
/**
*    created: 12.05.2020 09:35:34
**/
#include <bits/stdc++.h>
#define int long long
const int INF = 1e18L + 5;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int n; cin >> n;
    vector<int> w(n);
    rep(i,n) cin >> w[i];
    int sum = 0; rep(i,n) sum += w[i];
    int sum2 = 0;
    int ans = 1000000000;
    for (int i = 1; i < n; i++) {
        sum2 += w[i-1];
        ans = min(ans,abs((sum-sum2)-sum2));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

void test(){
	ll d,t,s;
	cin>>d>>t>>s;
	ll tm = d/s;
	if(d%s!=0)tm++;
	if(tm<=t)cout<<"Yes\n";
	else cout<<"No\n";
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


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

typedef long long LL;

template<typename T>
void printmatrix(vector<vector<T> > ar){
    for (int i = 0; i < (int)ar.size(); i++) {
        for (int j = 0; j < (int)ar.size(); j++) {
            cout << ar[i][j];
        }
        cout << endl;
    }
}

template<typename T>
void printvector(vector<T> vec){
    for (int i = 0; i < (int)vec.size(); i++) {
        cout << vec[i] << endl;
    }
}

template<typename T>
void unique(vector<T>& vec){
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
}

template<typename T>
vector<T> cumsum(vector<T> vec){
    vector<T> newvec((T)vec.size());
    int tmp = 0;
    for (int i = 0; i < (int)vec.size(); i++) {
        tmp += vec[i];
        newvec[i] = tmp;
    }

    return newvec;
}

int main(int argc, char const* argv[])
{

    int n;
    cin >> n;

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

    int m=0;
    for (int i = 0; i < 100000-1; i++) {
        if (i == 0) m = max(m, v[i] + v[i+1] );
        m = max(m, v[i-1] + v[i] + v[i+1]);
    }

    cout << m << endl;

    return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

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

  int64 x;
  cin >> x;
  int64 d = gcd(x, 360LL);
  int64 lcm = x * 360LL / d;
  cout << lcm / x << endl;
}

Measured memory_bytes: 3628