akhauriyash/Code-Regression huggingface dataset:
X, Y = map(int,input().split())
MOD = 10 ** 9 + 7
if (X + Y) % 3 != 0 or 2 * X < Y or 2 * Y < X:
    print(0)
elif 2 * X == Y or 2 * Y == X:
    print(1)
else:
    turn = (X + Y) // 3
    turn2 = X - turn
    turn1 = turn - turn2
    ans = turn
    inv = [0, 1]
    for i in range(2, min(turn1, turn2) + 1):
        ans = ans * (turn - i + 1) % MOD
        ans = ans * (-inv[MOD % i] * (MOD // i)) % MOD
        inv.append((-inv[MOD % i] * (MOD // i)) % MOD)
    print(ans % MOD)

Measured memory_bytes: 58156
#include<iostream>
using namespace std;
const int M = 105;
int p[M];

int main(){
	int n,sum; cin >> n;
	sum = 0;
	for(int i = 0; i < n; i++){
		cin >> p[i];
		sum = sum + p[i];
	}
	
	int x,y,t; cin >> t;
	for(int i = 0; i < t; i++){
		cin >> y >> x;
		int ans = sum - p[y-1] + x;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static int times(int x, int n) {
		int num = 1;
		for(int i = 0; i < n; i++) {
			num = num*x;
		}
		return num;
	}
	public static void digits(int x, int r, int[] d) {
		int digits = 1;
		//String dchar = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";

		do {
				d[digits++] = (x % r);
				x /= r;

		}while(x != 0);
	}

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sca = new Scanner(System.in);
		int n = sca.nextInt();
		int x[][] = new int[n+1][n+1];
		int y[][] = new int[n+1][n];
		int ai[] = new int[n+1];
		for(int i = 1; i < n+1; i++) {
			ai[i] = sca.nextInt();
			for(int j = 1; j < ai[i] + 1; j++) {
				x[i][j] = sca.nextInt();
				y[i][j] = sca.nextInt();
			}
		}
		int big = 0;
		int digi[] = new int[n+1];
		for(int i = 1; i < n+1; i++) {
			digi[i] = 0;
		}
		int count;
		for(count = 0; count < times(2, n); count++) {
			digits(count, 2, digi);
			boolean flag = true;
			for(int i = 1; i < n+1; i++) {
				if(flag == false) {
					break;
				}
				for(int j = 1; j < ai[i] + 1; j++) {
					if (digi[x[i][j]] == y[i][j] && digi[i] == 1) {
						// ループを続ける
					}
					//else if(digi[x[i][j]] != y[i][j] && digi[i] == 1 || digi[x[i][j]] == y[i][j] && digi[i] == 0){
					else if(digi[x[i][j]] != y[i][j] && digi[i] == 1){
						flag = false;
						break;
					}
				}
			}
			if(flag == true) {
				int big_t = 0;
				for(int i = 1; i < n+1; i++) {
					if(digi[i] == 1) {
						big_t++;
					}
				}
				if(big < big_t) {
					big = big_t;
				}
			}
		}
		System.out.println(big);
		sca.close();
	}
}

Measured memory_bytes: 23624
/* ex6_2
    riverstone*/

#include <stdio.h>
#include <string.h>

//入力される式の文字数の上限をSIZEとして定義
#define SIZE 101
 
int main(void){
    int length; //lengthは単語の長さを表す変数
    char word[SIZE]; //wordは単語を入力する文字列
    
    //単語を入力
    scanf("%s",word); 

    //文字列の長さをlengthに代入
    length = strlen(word); 
    
    //単語の最初の文字+その間の数+最後の文字を出力
    printf("%c%d%c\n",word[0],length-2,word[length-1]); 
 
    return 0; 
}

Measured memory_bytes: 128
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<iomanip>
#include<complex>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef stack<int> SI;
typedef queue<int> QI;
typedef list<int> LI;
typedef pair<int,int> PII;
typedef long long LL;

#define d(x)  cout<<#x<<" = "<<(x)<<endl;
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define EP empty()
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define REACH(i,c) for(typeof((c).rbegin()) i=(c).rbegin(); i!=(c).rend(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c,n) sort(c,c+n)
#define VSORT(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 DFOR(i,b,a) for(int i=(b)-1;i>=(a);--i)
#define DREP(i,n) DFOR(i,n,0)
#define INF 1000000000
#define PI  acos(-1.0)
////////////////////////////////////////////////
int main()
{
	string s,ss;
	cin>>s>>ss;
	REP(i,SZ(s)-SZ(ss)+1)
	{
		int f=0;
		REP(j,SZ(ss))
		{
			if(s[i+j]!=ss[j])
			{
				f=1;
				break;
			}
		}
		if(f==0)
		{
			cout<<i<<endl;
		}
	}
	return 0;
}

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

int main(){ 
    int w,a,b;
    cin >> w >> a >> b;
    if(b > a+w) cout << b-(a+w) << endl;
    else if(a > b+w) cout << a-(b+w) << endl;
    else cout << 0 << endl;
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
    for(auto &e:t) fill_v(e,v);
}

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

  int a = numeric_limits<int>::max(), z = 0;
  REP(i, (int)s.length()){
    if(s[i] == 'A') a = min(a, i);
    if(s[i] == 'Z') z = max(z, i);
  }

  cout << z - a + 1 << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long a, b, ava[200100], bva[200100], m, c[100100], i, ans=1000000000, x[100100], y[100100];
    cin >> a >> b >> m;
    for(i=0;i<a;i++){
        cin >> ava[i];
    }
    for(i=0;i<b;i++){
        cin >> bva[i];
    }
    for(i=0;i<m;i++){
        cin >> x[i] >> y[i] >> c[i];
        x[i]--;y[i]--;
    }
    for(i=0;i<m;i++){
        ans=min(ans, ava[x[i]]+bva[y[i]]-c[i]);
    }
    sort(ava, ava+a);
    sort(bva, bva+b);
    ans=min(ans, ava[0]+bva[0]);
    cout << ans <<endl;
    return 0;
}

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

using namespace std;

int main() {
    int N;
    int ans = 0;

    cin >> N;

    int A[N];
    int B[N];
    int C[N - 1];

    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
        ans += B[i];
    }
    for (int i = 0; i < N - 1; i++) {
        cin >> C[i];
    }

    int index;
    for (int i = 0; i < N - 1; i++) {
        if ((A[i + 1] - A[i]) == 1) {
            index = A[i];
            ans += C[index - 1];
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll n,m,k;
ll a[200005],b[200005];
ll t;
ll j;
ll J;
ll T;
ll ans;
bool x;
int main(void){
    cin>>n>>m>>k;
    for(int i=0;i<n;i++){
        cin>>a[i];
        t+=a[i];
        if(t<=k){
            j=i+1;
            T=t;
        }
    }
    t=T;
    for(int i=0;i<m;i++){
        cin>>b[i];
        t+=b[i];
        if(t<=k){
            J=i+1;
            T=t;
        }
    }
    ans=j+J;
    //cout<<T<<" "<<j<<" "<<J<<" "<<ans<<endl;
    x=true;
    for(int i=j-1;i>=0;i--){
        T-=a[i];
        x=true;
        while(T<=k&&J<m){
            T+=b[J];
            J++;
            if(T>k) x=false;
        }
        if(x==false){
            J--;
            T-=b[J];
        }
        ans=max(ans,i+J);
        if(J==m){
            cout<<ans<<endl;
            return 0;
        }
        //cout<<T<<" "<<i<<" "<<J<<" "<<ans<<endl;
    }
    cout<<ans<<endl;
    

}



Measured memory_bytes: 6728
#include<bits/stdc++.h>
using namespace std;
using ld =long double;
const long double PI = acos(-1);

int main(){
    int a,b,h,m;
    cin >> a >> b >> h >> m ;

    ld rad = PI * 2 * (
        (ld)h / 12.0 + ((ld)m / 60.0) / 12.0 - (ld)m / 60.0    );
    
    ld rsq = (ld)(a * a + b * b) - (ld)(2 * a * b) * cosl(rad);

    printf("%20.20Lf\n", sqrtl(rsq));
} 

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define int ll

const ll MOD = 1000000007;
const ll INF_LL = (ll)1000000007 * 1000000007;
const int INF_INT = (int)1000000007;
const double PI = 3.14159265358979323846;

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define irep(itr, st) for (auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for (auto itr = (st).rbegin(); itr != (st).rend(); ++itr)

#define m0(x) memset((x), 0, sizeof((x)))
#define m1(x) memset((x), -1, sizeof((x)))

// xにはvectorなどのコンテナ
#define ALL(x) (x).begin(), (x).end()  // sortなどの引数を省略したい
#define RALL(x) (x).rbegin(), (x).rend()  // sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())     // sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))  //最大値を求める
#define MIN(x) *min_element(ALL(x))  //最小値を求める
#define all(x) (x).begin(), (x).end()

//略記
#define pb emplace_back  // vectorヘの挿入
#define mp make_pair     // pairのコンストラクタ
#define F first          // pairの一つ目の要素
#define S second         // pairの二つ目の要素

#define BITCOUNT __builtin_popcount
#define BITCOUNT_LL(x) __builtin_popcountll(x)

#define perm(c)             \
  sort(all(c));             \
  for (bool c##p = 1; c##p; \
       c##p = next_permutation(all(c)))  //順列 123 132 213 231 312 321

#define BIT(n) (1LL << (n))

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ": " << (A) << std::endl;
#else
#define PRINT(A)
#endif

//入力高速化
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

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

signed main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W, 0));
  vector<vector<int>> B(H, vector<int>(W, 0));
  rep(i, H) {
    rep(j, W) {
      cin >> A[i][j];
      B[i][j] = A[i][j];
    }
  }
  int count = 0;
  rep(i, H) {
    rep(j, W - 1) {
      if (B[i][j] % 2 == 1) {
        B[i][j]--;
        B[i][j + 1]++;
        count++;
      }
    }
  }
  rep(i, H - 1) {
    if (B[i][W - 1] % 2 == 1) {
      B[i][W - 1]--;
      B[i + 1][W - 1]++;
      count++;
    }
  }
  cout << count << endl;
  rep(i, H) {
    rep(j, W - 1) {
      if (A[i][j] % 2 == 1) {
        A[i][j]--;
        A[i][j + 1]++;
        cout << i + 1 << " " << j + 1 << " " << i + 1 << " " << j + 2 << endl;
      }
    }
  }
  rep(i, H - 1) {
    if (A[i][W - 1] % 2 == 1) {
      A[i][W - 1]--;
      A[i + 1][W - 1]++;
      cout << i + 1 << " " << W << " " << i + 2 << " " << W << endl;
    }
  }
}

Measured memory_bytes: 6144
import java.util.Scanner;

public class Main {
	private static Scanner sc=new Scanner(System.in);
	private static int pointT=0;
	private static int pointH=0;
	private static int size=sc.nextInt();
	public static void main(String[] args){
		for(int i=0;i<size;i++){
			String wordT=sc.next();
			String wordH=sc.next();
			battle(wordT,wordH);
		}
		System.out.println(pointT+" "+pointH);
	}
	private static void battle(String t,String h){
		if(t.compareTo(h)>0) pointT+=3;
		if(t.compareTo(h)<0) pointH+=3;
		if(t.compareTo(h)==0){
			pointH++;
			pointT++;
		}
	}
}

Measured memory_bytes: 29544
H,N=map(int,input().split())
A=[0]*N
B=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())

INF=10**9
dp=[INF]*(H+1)
# dp[x]:xダメージを与えるための最小魔力
dp[0]=0
for i in range(N):
  for j in range(len(dp)):
    if dp[j]!=INF:
      if j+A[i]<len(dp):
        if dp[j+A[i]]>dp[j]+B[i]:
          dp[j+A[i]]=dp[j]+B[i]
      else:
        if dp[len(dp)-1]>dp[j]+B[i]:
          dp[len(dp)-1]=dp[j]+B[i]
print(dp[-1])

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

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

long d[kMax5][13];

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

  const int kRem = 13;
  const long kKM = 1000000007;
  const int res[] = { 1, 10, 9, 12, 3, 4 };

  string s;
  cin >> s;
  int n = s.size();
  reverse(s.begin(), s.end());

  mmst(d);
  if (s[0] == '?') {
    rep(i, 0, 9) d[0][i] = 1;
  } else {
    d[0][s[0] - '0'] = 1;
  }

  rep(i, 1, n - 1) {
    if (isdigit(s[i])) {
      int dig = s[i] - '0';
      rep(j, 0, kRem - 1) {
        int ba = dig * res[i % 6] % kRem;
        d[i][j] = d[i - 1][(j + kRem - ba) % kRem];
      }
    } else {
      rep(dig, 0, 9) {
        rep(j, 0, kRem - 1) {
          int ba = dig * res[i % 6] % kRem;
          d[i][j] = (d[i][j] + d[i - 1][(j + kRem - ba) % kRem]) % kKM;
        }
      }
    }
  }

  cout << d[n - 1][5] << endl;

  return 0;
}


Measured memory_bytes: 10752
#include<stdio.h>

int main(){

  int n,s,u,t,sum;

  while(1){ 
    scanf("%d",&n);
    if(n==0){break;}
    s=n/4;
    sum=0;
    for(t=0;t<s;t++){
      scanf("%d",&u);
      sum= sum + u;
 }
    printf("%d\n",sum);

  }

 return 0;
}

Measured memory_bytes: 600
struct Read<R: std::io::BufRead> {
    stdin: R,
    v: Vec<String>,
    i: usize,
}
impl<R:std::io::BufRead> Read<R> {
    pub fn new(stdin: R) -> Self {
        Read{
            stdin,
            v: Vec::new(),
            i: 0,
        }
    }
    pub fn read_until<T: std::str::FromStr>(&mut self) -> T {
        if self.i == self.v.len() {
            self.read_line();
        }
        let elem = &self.v[self.i];
        self.i += 1;
        elem.parse().unwrap_or_else(|_| panic!())
    }
    #[allow(dead_code)]
    pub fn read_i32(&mut self) -> i32 {
        if self.i == self.v.len() {
            self.read_line();
        }
        let elem = self.v[self.i].parse().unwrap();
        self.i += 1;
        elem
    }

    pub fn read_string(&mut self) -> String {
        if self.i == self.v.len() {
            self.read_line();
        }
        let elem = &self.v[self.i];
        self.i += 1;
        elem.to_owned()
    }
    pub fn read_line(&mut self) {
        self.i = 0; self.v.clear();
        let mut buf = String::new();
        self.stdin.read_line(&mut buf).unwrap();
        let buf = buf.trim().to_owned();
        let mut ws = buf.split_whitespace();
        loop {
            let x = ws.next();
            if x.is_none() {
                break;
            }
            let x = x.unwrap().to_owned();
            self.v.push(x);
        }
    }
}
fn main() {
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let mut read = Read::new(stdin);

    let mut n:usize = read.read_until();
    let mut s:Vec<String> = Vec::new();
    for _i in 0..n {
        s.push(read.read_string());
    }
    s.sort();
    let mut ans = 1;
    for i in 0..n-1 {
        if s[i] != s[i+1] {
            ans+=1;
        }
    }
    println!("{}",ans);
}

Measured memory_bytes: 14900
n,k= map(int,input().split())
h=list(map(int,input().split()))

x=[0]*n
for i in range(k):
    a,b = map(int, input().split())
    if h[a-1]>=h[b-1]:
      x[b-1] +=1
    if h[b-1]>=h[a-1]:
      x[a-1] +=1
print(x.count(0))

Measured memory_bytes: 20020
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    times = list(map(int, input().split()))

    alice_start = times[0]
    alice_end = times[1]
    bob_start = times[2]
    bob_end = times[3]

    if (bob_end < alice_start) or (alice_end < bob_start):
        print(0)
    else:
        sorted_times = sorted(times)
        print(sorted_times[2] - sorted_times[1])


Measured memory_bytes: 3060
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

from itertools import product

H,W,K = LI()
S = [list(map(str, input())) for _ in range(H)]

A = product([0,1],repeat=H-1)
ans = float('inf')
for a in A:
    count = 0
    for a0 in a:
        if a0 == 1:
            count += 1
    List = []
    now = []
    for i in range(H):
        now.append(i)
        if i != H-1:
            if a[i] == 1:
                List.append(now)
                now = []
    List.append(now)
    n = len(List)
    nums = [0]*n
    now_nums = [0]*n
    for j in range(W):
        flag = False
        # L = [0,1]
        for k,L in enumerate(List):
            for l in L:
                if S[l][j] == '1':
                    now_nums[k] += 1
        #print(a,j,now_nums)         
        for k in range(n):
            if now_nums[k] > K:
                flag = True
                break
        
        c_flag = False
        for k in range(n):
            if nums[k]+now_nums[k] > K:
                count += 1
                c_flag = True
                break
        
        if c_flag:
            nums = now_nums[:]
            now_nums = [0]*n
        else:
            for k in range(n):
                nums[k] += now_nums[k]
            now_nums = [0]*n

        if flag:
            break
    if flag:
        continue

    if count < ans:
        ans = count

print(ans)

Measured memory_bytes: 49496
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(int i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N, K;
    cin >> N >> K;
    vector<int> h(N);
    REP(i, N) cin >> h[i];

    vector<int> dp(N, 1<<30);
    dp[0] = 0;

    for(int i=0; i<N; i++){
        for(int j=1; j<=K; j++){
            int to = i + j;
            if(to >= N) continue;
            dp[to] = min(dp[to], dp[i] + abs(h[i] - h[to]));
        }
    }
    cout << dp[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if "." in n:
		l = n.find(".")
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == "0":
			head_zeros += 1
		else:
			break

	return n[head_zeros:]

# compare a, b
# a, b: int or string
def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	else:
		if a > b:
			return 1
		elif a < b:
			return -1
		else:
			return 0

# calculate a + b
# a, b: int or string
def bigint_plus(a, b):
	a = str(a)
	b = str(b)

	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b

	ans = ""
	carry = 0
	for i in range(d):
		s = int(a[-i-1]) + int(b[-i-1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans

	return ans

# calculate a - b
# a, b: int or string
def bigint_minus(a, b): 
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ""

	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = "-"
	m = '0' * (len(M) - len(m)) + m

	ans = ""
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i-1]) - int(m[-i-1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans

	return sign + delete_head_zeros(ans)

# calculate a * b
# a, b: int or string
def bigint_multiply(a, b):
	a = str(a)
	b = str(b)

	md = []
	for j in range(len(b)):
		carry = 0
		mj = ""
		for i in range(len(a)):
			m = int(a[-i-1]) * int(b[-j-1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)

	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + "0" * k, ans)

	return ans


# calculate a / b to d digits after decimal point
# a, b, d: int or string
def bigint_divide(a, b, d = 0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0

	ans = ""
	r = ""
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += "."
			r += "0"
		else:
			r += "0"

		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)

	return delete_head_zeros(ans)

def main():
	A, B, N = [int(x) for x in input().split(" ")]
	r = min([N, B - 1])
	print(bigint_divide(bigint_multiply(A, r), B))

main()

Measured memory_bytes: 9260
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>
#include<queue>
#include <map>

using namespace std;

int main(){

	int a,b;
	cin>>a>>b;
	int ans=-1;
	int x,y;
	for(int i=1;i<10000+10;i++){
		x=(int)i*0.08;
		y=(int)i*0.1;
		if(x!=a)continue;
		if(y!=b)continue;
		ans=i;
		break;
	}


	cout<<ans;
	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main()
{
	int W,H,x,y,r;
	scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);
	if(x>0 && y>0 && x <= (W-r) && y <= (H-r)){
		printf("Yes\n");
	}
	else
	printf("No\n");

	return 0;
}


Measured memory_bytes: 2112
// Create your own template by modifying this file!
#include <string>
#include <vector>
#include <climits>
#include <cstring>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cassert>
#include <deque>
#include <stack>
#include <functional>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x;  }
void _R(int &x) { scanf("%d", &x);  }
void _R(int64_t &x) { scanf("%lld", &x);  }
void _R(double &x) { scanf("%lf", &x);  }
void _R(char &x) { scanf(" %c", &x);  }
void _R(char *x) { scanf("%s", x);  }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...);  }
template<class T> void _W(const T &x) { cout << x;  }
void _W(const int &x) { printf("%d", x);  }
void _W(const int64_t &x) { printf("%lld", x);  }
void _W(const double &x) { printf("%.16f", x);  }
void _W(const char &x) { putchar(x);  }
void _W(const char *x) { printf("%s", x);  }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' ');  }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...);  }
#ifdef DEBUG
 #define debug(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define debug(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
template<class T> void MIN(T& a, const T& b) { a = min(a, b); }
template<class T> void MAX(T& a, const T& b) { a = max(a, b); }

#include <atcoder/all>
using namespace atcoder;

void solve() {
    int N, Q;
    R(N, Q);
    dsu d(N);
    while (Q--) {
        int t, u, v;
        R(t, u, v);
        if (t) {
            W(d.same(u, v));
        } else {
            d.merge(u, v);
        }
    }
}

int main() {
#define MULTITEST 0
#if MULTITEST    
    CASET{
        solve();
    }
#else
    solve();
#endif
    return 0;
}



Measured memory_bytes: 3552
#include<iostream>
#include<vector>
#include<set>
#include<queue>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<stack>
#include<unordered_map>
#include<bitset>
#include<limits>
#include<complex>
#include<array>
#include<numeric>
#include<functional>

using namespace std;
#define ll long long
#define ull unsigned long long
#define rrep(i,m,n) for(ll (i)=(ll)(m);(i)>=(ll)(n);(i)--)
#define rep(i,m,n) for(ll (i)=(ll)(m);i<(ll)(n);i++)
#define REP(i,n) rep(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
constexpr long double m_pi = 3.1415926535897932L;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 62;
constexpr long double EPS = 1e-10;
template<typename T> using vector2 = vector<vector<T>>;
template<typename T> using vector3 = vector<vector2<T>>;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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() {
	ios::sync_with_stdio(false);
	std::cin.tie(0);
	std::cout.tie(0);

	ll h, w, k;
	cin >> h >> w >> k;	
	ll sx, sy, gx, gy;
	cin >> sx >> sy >> gx >> gy;
	sx--; sy--; gx--; gy--;
	vector<string> s(h);
	REP(i, h)cin >> s[i];
	queue<P> que;
	Matrix d(h, Array(w, INF));
	d[sx][sy] = 0;
	que.push({ sx,sy });
	Array dx = { 1,0,-1,0 };
	Array dy = { 0,1,0,-1 };
	while (que.size()) {
		auto [x, y] = que.front();
		que.pop();
		auto update = [&](ll dx,ll dy,ll x,ll y) {
			rep(i, 1, k + 1) {
				ll nx = clamp(x + i * dx, 0LL, h - 1), ny = clamp(y + i * dy, 0LL, w - 1);
				if (s[nx][ny] == '@' || d[nx][ny] < d[x][y] + 1)break;
				if (chmin(d[nx][ny], d[x][y] + 1))que.push({ nx,ny });
			}
		};
		REP(i, 4)update(dx[i], dy[i], x, y);
	}
	if (d[gx][gy] != INF)cout << d[gx][gy] << "\n";
	else cout << -1 << "\n";

	return 0;
}

Measured memory_bytes: 19812
#!python3

def LI():
    return list(map(int, input().split()))

# input
N, K = LI()


def p(x):
    ret = 1
    while x < K:
        ret /= 2
        x *= 2
    return ret


def main():
    ans = 0
    for i in range(1, N + 1):
        ans += p(i)

    ans /= N
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/

	coding: utf-8
	lang: C++ (GCC 5.4.1)
*/

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

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[])
{
	int n;
	cin >> n;
	OUT(n * n * n) BR;
	RET;
}


Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B - Algae
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int N = 10;

/* typedef */

/* global variables */

/* subroutines */

/* main */

int main() {
  int r, d, x;
  scanf("%d%d%d", &r, &d, &x);

  for (int i = 0; i < N; i++) {
    x = r * x - d;
    printf("%d\n", x);
  }
  return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>
#include <locale>
#include <random>
#include <type_traits>
#include <chrono>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define REP(i, n) FOR(i, 0, (n))
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)

#define FOREACH(x, arr) for (auto &(x) : (arr))
#define FORITER(x, arr) for (auto(x) = (arr).begin(); (x) != (arr).end(); ++(x))

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}

using LL = long long;

//------------------------------------------
//------------------------------------------

const double PI = acos(-1);

double toDegree(double rad) {
    return (180.0 * rad) / PI;
}

double toRadian(double degree) {
    return PI * (degree / 180.0);
}

int main() {

    double a, b, x;
    cin >> a >> b >> x;

    double degree = 0;
    if (x * 2 >= a * a * b) {
        double h = 2 * (a * b - (x / a)) / a;
        double rad = atan2(h, a);
        degree = toDegree(rad);
    } else {
        double h = (2 * x / a) / b;
        double rad = atan2(b, h);
        degree = toDegree(rad);
    }

    cout << fixed << setprecision(20) << degree << endl;

}



































Measured memory_bytes: 256
#include<cstdio>
main(){int a,b,c,d;scanf("%d%d%d", &a, &b, &c);c-=60;d=a+b;
while((c+=60)<3600)
if(0<=c%d&&c%d<=a)
break;
printf("%d\n",c>3599?-1:c);}

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

const int MAX = 200000;

int main() {
	long long N;
	int A[MAX];

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

	long long ans = 0;
	long long begin = 0;
	long long end = 0;
	int sum = 0;

	while (true) {
		while ((sum + A[end]) == (sum ^ A[end]) && end < N) {
			sum ^= A[end];
			ans += end - begin;
			end++;
		}
		if (end == N)break;

		while ((sum + A[end]) != (sum ^ A[end])) {
			sum ^= A[begin];
			begin++;
		}
	}

	cout << ans + N << endl;

	return 0;
}

Measured memory_bytes: 1024
//yukicoder@cpp14
//author:luckYrat(twitter:@luckYrat_)
//競技プログラミングから逃げるな
//https://www.youtube.com/watch?v=z_B9iJ8r4ic

//せんげん！
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

#include <cctype>
#include <utility>
#include <climits>


//なまえくーかん！
using namespace std;
using ll = long long;
using P = pair<ll,ll>;

//てーすう！
const int mod = 1000000007;
const int inf = (1<<30)-1;
const ll linf = (1LL<<62LL)-1;
const double EPS = (1e-10);

//でふぁいん！
#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)

//みじかく！
#define pb push_back
#define fir first
#define scn second
#define ednl endl

//いぇすのー！
#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")

//きんぼーnほーこー！！
P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる

計算量は変わらないが楽できるシリーズ
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる
*/
int dp[200001][2020];
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}
int main(){
  string s;cin>>s;
  int ans = 0;
  for(int i = 0; s.size() > i; i++){
    dp[0][0] += 1;
    for(int j = 0; 2020 > j; j++){
      dp[1][(j*10+s[i]-'0')%2019] += dp[0][j];
    }
    ans += dp[0][0];
    for(int j = 0; 2020 > j; j++){
      dp[0][j] = dp[1][j];
      dp[1][j] = 0;
    }
  }
  ans += dp[0][0];
  cout << ans-s.size() << endl;

}

Measured memory_bytes: 3792
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define bg begin()
#define en end()

using namespace std;

typedef long long ll;

int N;
ll A[100005];
ll e[3];

int main() {
  scanf("%d", &N);
  rep(i, 0, N) scanf("%lld", &A[i]);
  sort(A, A+N, greater<int>());
  
  int cnt = 0;
  rep (i, 0, N) {
    if (A[i] == A[i+1]) {
      e[cnt++] = A[i];
      i++;
    }
    if (i == N || cnt == 2) break;
  }
 
  printf("%lld\n", e[0]*e[1]);

}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mod 1000000007
#define pi (3.141592653589)
#define deb(n) cerr << #n << " = " << (n) << " ";
using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout << fixed;
	cout.precision(10);
	
	long long n;
	cin >> n;
	string sol = "";
	while(n)
	{
		int rem = n % 26;
		char ch;
		if(rem == 0)
		{
			ch = 'z';
			n /= 26;
			n--;
		}
		else
		{
			ch = 'a' + rem - 1;
			n  /= 26;
		}
		sol = ch + sol;
	}
	cout << sol;

	return 0;
}


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

int main()
{
  int N;
  cin >> N;
  vector<int> b(300, -1);
  for (int i = 1; i <= N; i++) cin >> b.at(i);
  
  vector<int> ans(300, -1);
  int k = N;
  for (int i = 1; i <= N; i++)
  {
    for (int j = N; j >= 1; j--)
    {
      if (b.at(j) == j) 
      {
        b.erase(b.begin() + j);
        ans.at(k) = j;
        k--;
        break;
      }
    }
  }
  
  if (k == 0)
  {
    for (int i = 1; i <= N; i++)
    {
      cout << ans.at(i) << endl;
    }
  }
  else cout << -1 << endl;
}

Measured memory_bytes: 256
N = int(input())
S = input()

left_num = 0
right_num = 0

for i in range(N):
    if S[i] == '(':
        right_num += 1
    else:
        if right_num > 0:
            right_num -= 1
        else:
            left_num += 1

ans = '('*left_num + S + ')'*right_num
print(ans)


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

using namespace std;
typedef long long int ll;

#define INF (1e9)

int A, B;

int main() {
    cin >> A >> B;

    int ans;

    if (B % A == 0)
        ans = A + B;
    else
        ans = B - A;

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


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <string>
#include <time.h>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;

int main(void) {

	int N = 0, L = 0;
	cin >> N;
	L = N / 15;
	int res = N * 800 - L * 200;

		cout << res << endl;

	return 0;




}


Measured memory_bytes: 256
// #pragma GCC optimize("Ofast,unroll-all-loops")

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define all(v) v.begin(), v.end()
#define len(v) ((int)(v).size())
#define pb push_back
#define kek pop_back
#define pii pair<int, int>
#define mp make_pair
#define int ll

#define debug(x) cout << #x << " = " << x << endl;

const int INF = (is_same<int, ll>::value ? 1e18 + 666 : 1e9 + 666);
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

// const int MEM_SIZE = 1e8;
// char mem[MEM_SIZE];
// int cur_mem_ptr = 0;

// void* operator new(size_t n) {
//     cur_mem_ptr += n;
//     return mem + cur_mem_ptr - n;
// }

// void operator delete(void*) noexcept {}
// void operator delete(void*, size_t) noexcept {}

template<class t1, class t2>
bool cmin(t1 &a, const t2 &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<class t1, class t2>
bool cmax(t1 &a, const t2 &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

#ifndef LOCAL
void UseFiles(const string &s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
#else
void UseFiles(const string&) {}
#endif

void run();

signed main() {
    // UseFiles("squads");
    iostream::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    run();
}

pii norm(int a, int b) {
    if (a == 0 && b == 0) return {0, 0};
    if (a < 0) {
        a *= -1;
        b *= -1;
    }
    if (a == 0 && b < 0) {
        a *= -1;
        b *= -1;
    }
    int g = gcd(a, b);
    a /= g;
    b /= g;
    return {a, b};
}

const int mod = 1e9 + 7;

bool check(const vector<pii> &v, int msk) {
    for (int i = 0; i < len(v); ++i) {
        for (int j = 0; j < len(v); ++j) {
            if ((msk & (1 << i)) && (msk & (1 << j)) && (v[i].first * v[j].first + v[i].second * v[j].second == 0))
                return false;
        }
    }
    return true;
}

int bpow(int a, int b) {
    int res = 1;
    for (; b; b >>= 1) {
        if (b & 1) {
            res *= a;
            res %= mod;
        }
        a *= a;
        a %= mod;
    }
    return res;
}

void run() {
    int n;
    cin >> n;
    vector<pii> v(n);
    for (auto &[a, b] : v) {
        cin >> a >> b;
        tie(a, b) = norm(a, b);
    }
    map<pii, int> m;
    for (auto &[a, b] : v) {
        ++m[norm(a, b)];
    }
    int ans = m[mp(0, 0)];
    m.erase(mp(0, 0));
    int ans2 = 1;
    for (auto &[x, y] : m) {
        if (x.second <= 0 && m.count(mp(-x.second, x.first))) continue;
        int a = y;
        int b = m[mp(x.second, -x.first)];
        ans2 *= bpow(2, a) + bpow(2, b) - 1;
        ans2 %= mod;
    }
    cout << (ans + ans2 - 1 + mod) % mod << endl;

    // int cnt = 0;
    // for (int i = 1; i < (1 << n); ++i) {
    //     cnt += check(v, i);
    // }
    // cerr << cnt << endl;
}

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

int main()
{
    int N, L;

    cin >> N >> L;
    int diff;
    if (L < 0)
    {
        diff = min(0, L + N - 1);
    }
    else
    {
        diff = L;
    }
    cout << N * (L - 1) + (N * (N + 1)) / 2 - diff << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = n-1; i >= 0; i--)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VP = vector<P>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

const int mod = 998244353;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
    mint operator+(const mint a) const { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= a;}
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime mod
    mint inv() const { return pow(mod-2);}
    mint& operator/=(const mint a) { return *this *= a.inv();}
    mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    int n, k;
    cin >> n >> k;
    VP sec(k);
    rep(i,k) cin >> sec[i].first >> sec[i].second;
    vector<mint> dp(n+2);
    dp[1] = 1;
    for(int i = 1; i < n; i++){
        rep(j, k){
            int l = min(sec[j].first + i, n+1);
            int r = min(sec[j].second + i + 1, n+1);
            dp[l] += dp[i];
            dp[r] -= dp[i];
        }
        if (i > 1) dp[i+1] += dp[i];
    }   
    cout << dp[n] << endl;
    return 0;
}

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

using namespace std;

string s, t;

void init() {
  cin >> s >> t;
}
void solve() {
  int ans = 0;
  for(int i = 0 ; i < 3 ; ++i) if(s[i] == t[i]) ans++;
  cout << ans << '\n';
}

int main() {
  init();
  solve();
}


Measured memory_bytes: 256
N,K = map(int, input().split())
A = [*map(lambda x:int(x)-1, input().split())]

pre = 0
index = [-1]*N
path_cnt = 0
for i in range(N):
    if index[pre] >= 0:
        break
    else:
        index[pre] = i
        path_cnt += 1
    pre = A[pre]

loops = path_cnt - index[pre]
one = path_cnt - loops
k = max(0, K-one) % loops + min(K, one)

pre = 0
for _ in range(k): pre = A[pre]
print(pre + 1)


Measured memory_bytes: 32372
num_s, *D,  = [s.split() for s in open(0)]
flag = 0
D  = [d[0] for d in D]
pw = D[0]
if len(D) != len(set(D)):
    flag += 1
else:
    for i in range(1, len(D)):
        w = D[i]
        if pw[-1] != w[0]:
            flag += 1
            break 
        pw = w 
        
if flag:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 3064
const stdin = require('fs').readFileSync('/dev/stdin', 'utf8').trim()

const [n, k] = stdin
  .split('\n')[0]
  .split(' ')
  .map(Number)

const ans = () => {
  if (k === 1 || n === k) {
    return 0
  }

  return n - k
}

console.log(ans())


Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define optimize ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long
#define ld long double
#define vi vector<int>
#define si set<int>
#define pb push_back
#define lp(i,a,b) for(int i = a ; i <= b ; i ++)
#define rlp(i,a,b) for(int i = b ; i >= a ; i --)
#define a_sort(v) sort(v.begin(), v.end())
#define d_sort(v) sort(v.rbegin(), v.rend())
#define pii pair<int,int>
#define pi 3.14159265358979323846264338327950
using namespace std ;
// #define debug

const int MOD = 1E9 + 7 ;
const int N = 1E5 ;

int main() {
    #ifdef debug
    freopen("input.txt", "r", stdin) ;
    freopen("output.txt", "w", stdout) ;
    #endif // debug
    optimize

    int x , y ; cin >> x >> y ;
    puts(y % 2 == 0 && (y <= x * 4 && y >= x * 2) ? "Yes" : "No") ;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(c<a)
  {
   	cout<<0<<endl; 
  }
  else
  {
   	int d = c;
    d = d/a;
    d = d*b;
    cout<<d<<endl;
  }
  
}

Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
int i,j,k,n,m,l,A[105][105],B[105][105];
long  int C[105][105];
 
   scanf("%d %d %d",&n,&m,&l);
   for(i=0;i<n;i++){
       scanf("%d",&A[i][0]);
       for(j=1;j<m;j++){
           scanf(" %d",&A[i][j]);
       }
   }
   for(i=0;i<m;i++){
       scanf("%d",&B[i][0]);
       for(j=1;j<l;j++){
           scanf(" %d",&B[i][j]);
       }
   }
 
   for(i=0;i<n;i++){
       for(j=0;j<l;j++){
           for(k=0;k<m;k++){
               C[i][j]=C[i][j]+A[i][k]*B[k][j];
           }
       }
   }
   for(i=0;i<n;i++){
       printf("%ld",C[i][0]);
       for(j=1;j<l;j++){
           printf(" %ld",C[i][j]);
       }printf("\n");
   }
 
   return 0;
}

Measured memory_bytes: 776
#!/usr/bin/env python3

from collections import deque

n, m = list(map(int, input().split()))

road_map = [[] for _ in range(n)]

for i in range(m):
    a, b = list(map(int, input().split()))
    road_map[a-1].append(b-1)
    road_map[b-1].append(a-1)
# print(road_map)

check_list = [0 for _ in range(n)]
d = deque([(0, -1)])
ans = [0 for _ in range(n)]
while(len(d) >= 1):
    # print(d)
    index, origin = d.popleft()
    if check_list[index] == 1:
        continue
    else:
        check_list[index] = 1
        ans[index] = origin
    road_list = road_map[index]

    for i in road_list:
        if check_list[i] == 0:
            # check_list[i] = 1
            d.append((i, index))


for i in range(1, len(ans)):
    if ans[i] == -1:
        print("No")
        exit()

print("Yes")
for i in range(1, len(ans)):
    print(ans[i]+1)


Measured memory_bytes: 40536
#include <iostream>

int main(){
  int r,c;
  std::cin >> r >> c;
  int num[101][101];
  int rsum[101], csum[101], sum=0;


  /*imput*/
  for(int i=0; i<r; i++){
    for(int j=0; j<c; j++){
      std::cin >> num[i][j];
      rsum[i] += num[i][j];
    }
  }

  /*output*/
  for(int i=0; i<r; i++){
    for(int j=0; j<c; j++){
      std::cout  << num[i][j] << " ";
    }
    std::cout << rsum[i] << std::endl;
  }

  /*output*/
  for(int i=0; i<c; i++){
    for(int j=0; j<r; j++){
    csum[i] += num[j][i];
    }
    sum += csum[i];
    std::cout << csum[i] << " ";
  }
  std::cout << sum << std::endl;

  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)




int main(){
    ll n,x,m; cin>>n>>x>>m;
    vector<int> che(1e5+5,0);
    ll now=x%m;
    int cnt=0;
    while(che[now]==0){
        che[now]=1;
        now*=now;
        now%=m;
        cnt++;
    }
    vector<ll> candi;
    candi.push_back(now);
    now*=now;
    now%=m;
    while(candi[0]!=now){
        candi.push_back(now);
        now*=now;
        now%=m;
    }
    cnt-=candi.size();
    if(n<=cnt){
        ll ans=0;
        now=x%m;
        rep(i,n){
            ans+=now;
            now*=now;
            now%=m;
        }
        cout<< ans <<endl;
        return 0;
    }
    ll ans=0;
    now=x%m;
    rep(i,cnt){
        ans+=now;
        now*=now;
        now%=m;
    }
    ll kari=0;
    for(auto &v: candi){
        kari+=v;
    }
    n-=cnt;
    ans+=kari*(n/candi.size());
    n%=candi.size();
    rep(i,n){
        ans+=candi[i];
    }
    cout<< ans <<endl;
    return 0;
}

Measured memory_bytes: 4316