akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define fastIO() {ios::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);}
#define rep(i, n) for (int i = 0; i < (n); i++)
#define vrep(x, v) for (auto x : v)

using namespace std;

typedef vector<int> vi;
typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;


//int findCost(int memo[], int n, int heights[]){
//    if(n<1)return numeric_limits<int>::max();
//    if(n==1)return heights[1];
//    if(memo[n]>-1)return memo[n];
////    return (min(abs(arr[n]-findCost(arr, n-2)), abs(arr[n]-findCost(arr, n-1))))
//    memo[n] = min(abs(heights[n]-findCost(memo,n-1,heights)), abs(heights[n] -findCost(memo, n-2,heights)));
//    cout<<n<<" "<<memo[n]<<endl;
//    return memo[n];
//}
//
//int helper(int n, int heights[]){
//    int costs[n+1];
//    memset(costs, -1, sizeof(costs));
//    return findCost(costs, n, heights);
//
//}

int findCost2(int n, int heights[]){
    if(n<=1)return 0;
    int memo[n+1];
    memo[1]=0;
    memo[2]=abs(heights[2]-heights[1]);
    for(int i=3;i<n+1;i++) {
        memo[i] = min(abs(heights[i] - heights[i - 1]) + memo[i - 1], abs(heights[i] - heights[i - 2]) + memo[i - 2]);
//        cout<<abs(heights[i] - heights[i - 1]) + memo[i - 1]<<endl;
//        cout<< abs(heights[i] - heights[i - 2]) + memo[i - 2]<<endl;
    }
    return memo[n];
}


int main() {
    fastIO();
    int n, heights[100000];
    cin>>n;
    for(int i=1;i<n+1;i++)
        cin>>heights[i];
    cout<<findCost2(n,heights)<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
ll ans = 0;

void dfs(ll x, int a, int b, int c)
{
	if (x > n)
	{
		return;
	}
	if(a&&b&&c) ans++;

	dfs(x * 10 + 7, 1, b, c);
	dfs(x * 10 + 5, a, 1, c);
	dfs(x * 10 + 3, a, b, 1);
}

int main(){
    cin >> n;
    dfs(0,0,0,0);
    cout << ans << endl;
}


Measured memory_bytes: 256
x=int(input())
a=list(map(int,input().split()))
d=[0]*100001
d0=[0]*100001
p=0
q=0
m0=0
n0=0
m=n=0
for i in range(x):
    if i%2==0:
        d[a[i]]+=1
        if d[a[i]]>=p:
            p=max(p,d[a[i]])
            if a[i]!=m:
                m0=m
                m=a[i]
    else:
        d0[a[i]]+=1
        if d0[a[i]]>=q:
            q=max(q,d0[a[i]])
            if a[i]!=n:
                n0=n
                n=a[i]
if m==n:
    if d[m0]>d0[n0]:
        p=d[m0]
    else:
        q=d0[n0]
print(x-p-q)        

#print(m0,n0,d[m0],d0[n0])

Measured memory_bytes: 53604
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  if (N == 1 || N == 2 || N == 3 || N == 4 || N == 5 || N == 6 || N == 7 || N == 8 || N == 9 || N == 10 || N == 12 || N == 14 || N == 15 || N == 16 || N == 18 || N == 20 || N == 21 || N == 24 || N == 25 || N == 27 || N == 28 || N == 30 || N == 32 || N == 35 || N == 36 || N == 40 || N == 42 || N == 45 || N == 48 || N == 49 || N == 54 || N == 56 || N == 63 || N == 64 || N == 72 || N == 81) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void)
{
    int ct, i, judge = 1, ans = 0;
    scanf("%d", &ct);
    int num[ct];
    for (i = 0; i < ct; i++)
    {
        scanf("%d", &num[i]);
        if (num[i] % 2 != 0)
        {
            judge = 0;
        }
    }
    while (judge)
    {
        ans++;
        for (i = 0; i < ct; i++)
        {
            num[i] /= 2;
            if (num[i] % 2 != 0)
            {
                judge = 0;
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    int sum=0;
    for(int i=0;i<3;i++){
        if(S[i]=='o') sum++;
    }
    cout << 700+sum*100 << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#include<stdlib.h>
int main() {

	int a[100002]={0};
	int b[100002]={0};
	int N;
	int i,k;
	int answer=0;
	int p;

	scanf("%d",&N);
	for(i=1;i<=N;i++)
		scanf("%d %d",&a[i],&b[i]);

	for(k=N+1;k>=1;k--) {
		p=0;
		for(i=1;i<=N;i++) {
			if(a[i]<=k&&k<=b[i])
				p++;

			if(p==k) {
				answer=p-1;
				break;
			}
			else if(p==k-1) {
				answer=p;
				break;
			}
		}
		if(answer>0)
			break;
	}

	printf("%d\n",answer);
	return 0;
}

Measured memory_bytes: 2636
#include<iostream>
#include<cstring>
#include<cstdio>
#include<string>
#include<algorithm>
#include<cmath>
#include<set> 
using namespace std;
long long a[200010];
int main()
{
	int n;
	cin>>n;
	long long sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i]-=(i+1);
	}
	sort(a,a+n);
	long long b=a[n/2];
	long long ans=0;
	for(int i=0;i<n;i++)
	ans+=abs(b-a[i]);
	cout<<ans;
	return 0;
 } 


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner (System.in);
		int min,temp, top = 0,index = 0;

		int a[] = new int[3];
		
		for (int i = 0; i < a.length; i++) // ??°??????????´?
			a[i] = scan.nextInt();

		for (int i = 0; i < a.length; i++) {
			min = a[i];
			index = i;
			for(int j = top; j < a.length; j++) {
				if (a[j] < min) {
					min = a[j];
					index = j;
				}
			}
			top++;
			temp = a[i];
			a[i] = a[index];
			a[index] = temp;
		}

		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}
}

Measured memory_bytes: 26340
MOD = 10 ** 9 + 7

Ss = input()

lenS = len(Ss)

# numAs[i]: あり得るSs[:i]に含まれる'A'の個数
numAs = [0] * lenS
num = 0
pow3_Q = 1
for i, S in enumerate(Ss):
    numAs[i] = num
    if S == 'B' or S == 'C': continue
    if S == '?':
        num *= 3 # 今回'A','B','C'の3通り→これまでの文字列の数が3倍になる（'A'の数も3倍）
        num += pow3_Q # 現時点であり得る全ての文字列に'A'を付加→その数だけ新たに'A'が増える
        pow3_Q = (pow3_Q * 3) % MOD
    else:
        num += pow3_Q # 現時点であり得る全ての文字列に'A'を付加→その数だけ新たに'A'が増える
    num %= MOD

# numCs[i]: あり得るSs[i+1:]に含まれる'C'の個数
numCs = [0] * lenS
num = 0
pow3_Q = 1
for i, S in enumerate(Ss[::-1], 1):
    numCs[lenS - i] = num
    if S == 'A' or S == 'B': continue
    if S == '?':
        num *= 3 # 今回'A','B','C'の3通り→これまでの文字列の数が3倍になる（'C'の数も3倍）
        num += pow3_Q # 現時点であり得る全ての文字列に'C'を付加→その数だけ新たに'C'が増える
        pow3_Q = (pow3_Q * 3) % MOD
    else:
        num += pow3_Q # 現時点であり得る全ての文字列に'C'を付加→その数だけ新たに'C'が増える
    num %= MOD

ans = 0
for i, S in enumerate(Ss):
    if S == 'B' or S == '?':
        ans += (numAs[i] * numCs[i]) % MOD
        ans %= MOD

print(ans)


Measured memory_bytes: 11072
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    string a;
    cin>>a;
    int ans=0;
    int maxn=0;
    for(int i=0;i<n;i++){
    	if(a[i]=='I'){
    		ans++;
    		if(ans>maxn){
    			maxn=ans;
			}
		}else{
			ans--;
		}
	}
	cout<<maxn<<endl;
    return 0;
}


Measured memory_bytes: 256
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <queue>
using namespace std;

int main(){
  int N, M, ans = 0, primer = 0, maker = 0, setG = 0 ;
  cin >> N ;
  
  cout << 1 - N << endl ;
  return 0 ;
}  

Measured memory_bytes: 3628
#include <stdio.h>

int main() {
	int i, j, k, n, res, flg;
	int score[200][3] = { 0 };
	// 入力
	scanf("%d", &n);
	for ( i = 0; i < n; i++){
		for ( j = 0; j < 3; j++) {
			scanf("%d", &score[i][j]);
		}
	}
	// 計算
	for ( i = 0; i < n; i++) {
		res = 0;
		for ( j = 0; j < 3; j++) {
			flg = 0;
			for ( k = 0; k < n; k++) {
				if(i != k) {
					if(score[i][j] == score[k][j]) flg = 1;
				}
			}
			if(flg == 0) res += score[i][j];
		}
		printf("%d\n", res);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#define va first
#define vb second
#define lb lower_bound
#define pb push_back
#define all(v) v.begin(),v.end()
#define fio ios_base::sync_with_stdio(0);cin.tie(0);
using namespace std;
using ll = long long;
using lf = long double;
using pii = pair<int,int>;
using pll = pair<ll,ll>;


int main(){
    fio;
    int n, h, w;
    cin >> n >> h >> w;
    cout << (n-w+1) *(n-h+1) << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;

int main() {
    double x1,x2,y1,y2;
    double distance;
    cin >> x1 >> y1 >> x2 >> y2;
    distance = sqrt( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) );
    printf("%lf\n", distance);
    
    return 0;
}



Measured memory_bytes: 3204
n = int(input())
hs = list(map(int, input().split()))

max_hs = [0]
for h in hs:
  max_hs.append(max(max_hs[-1], h))

count = 0
for h, max_h in zip(hs, max_hs[1:]):
  if h >= max_h:
    count += 1
  
print(count)

Measured memory_bytes: 3060
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

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

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

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

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[400][400], x[N];
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> a[i][j];
		}
	}
	int res = n;
	for (int t = 0; t < m; t++){
		vector <int> b(m + 1, 0);
		for (int i = 0; i < n; i++){
			int id = 0;
			for (int j = 0; j < m; j++){
				if (x[a[i][j]] != 1) {
					id = a[i][j];
					break;
				}
			}
			b[id]++;
		}
		int mx = -1, id = 0;
		for (int i = 1; i <= m; i++){
			if (b[i] > mx){
				mx = b[i];
				id = i;
			}
		}
//		cout << endl << endl;
		res = min(res, mx);
		x[id] = 1;
		
	//	break;
		/*
		for (int i = 0; i < n; i++){
			for (int j = 0; j < m; j++){
				cout << a[i][j] << " ";
			}
			cout << endl;
		}
		cout << endl;*/
	}
	cout << res;
	return 0;
}












Measured memory_bytes: 1152
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

void findDivisor(int n, vector<int>& divisor)
{
    divisor.clear();
    stack<int> stk;
    for(int i=1; i*i<=n; ++i){
        if(n % i == 0){
            divisor.push_back(i);
            if(i * i < n)
                stk.push(n / i);
        }
    }
    while(!stk.empty()){
        divisor.push_back(stk.top());
        stk.pop();
    }
}

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

    vector<int> div;
    findDivisor(sum, div);
    reverse(div.begin(), div.end());
    for(int x : div){
        vector<int> v(n);
        for(int i=0; i<n; ++i)
            v[i] = a[i] % x;
        sort(v.rbegin(), v.rend());

        long long cnt1 = accumulate(v.begin(), v.end(), 0LL);
        long long cnt2 = 0;
        bool ok = (cnt1 <= k);
        for(int i=0; i<n; ++i){
            cnt1 -= v[i];
            cnt2 += (x - v[i]) % x;
            ok |= (cnt1 <= k && cnt2 <= k);
        }
        if(ok){
            cout << x << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}

int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(10);
    int a,b;
    cin>>a>>b;
    if(a>=10||b>=10){a=1;b=-1;}
    cout<<a*b<<endl;
}


Measured memory_bytes: 892
n,m = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(m)]
s = [0] * (10 ** 5+1)
for a,b in ab:
  s[a] += 1
  s[b] += 1
if any([i % 2 for i in s]):
  print("NO")
else:
  print("YES")

Measured memory_bytes: 29072
n,m = map(int, input().split())
a = [input() for i in range(n)]
b = [input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        count = 0
        for k in range(i, i+m):
            if a[k][j:m+j] == b[k-i]:
                count += 1
        if count == m:
            print('Yes')
            exit()
print('No')


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

from collections import defaultdict
from heapq import heappush, heappop
import sys

sys.setrecursionlimit(10**6)
input = sys.stdin.buffer.readline
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")


def debug(*x):
    print(*x)


def solve(N, W, WV):
    MAX_VALUE = N * 10 ** 3
    weights = [INF] * (MAX_VALUE + 1)
    weights[0] = 0
    for i in range(N):
        next_weights = weights[:]
        weight, value = WV[i]
        for j in range(MAX_VALUE - value + 1):
            next_weights[j + value] = min(
                weights[j + value],
                weights[j] + weight)
        weights = next_weights
    for i in range(MAX_VALUE, -1, -1):
        if weights[i] <= W:
            return i


T1 = """
3 8
3 30
4 50
5 60
"""


def main():
    N, W = map(int, input().split())
    WV = [
        list(map(int, input().split()))
        for i in range(N)
    ]
    print(solve(N, W, WV))


def _test():
    """
    >>> as_input(T1)
    >>> main()
    90
    """
    import doctest
    doctest.testmod()


def as_input(s):
    "use in test, use given string as input file"
    import io
    global read, input
    f = io.StringIO(s.strip())
    input = f.readline
    read = f.read


USE_NUMBA = False
if (USE_NUMBA and sys.argv[-1] == 'ONLINE_JUDGE') or sys.argv[-1] == '-c':
    print("compiling")
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', solve.__doc__.strip().split()[0])(solve)
    cc.compile()
    exit()
else:
    input = sys.stdin.buffer.readline
    read = sys.stdin.buffer.read

    if (USE_NUMBA and sys.argv[-1] != '-p') or sys.argv[-1] == "--numba":
        # -p: pure python mode
        # if not -p, import compiled module
        from my_module import solve  # pylint: disable=all
    elif sys.argv[-1] == "-t":
        _test()
        sys.exit()
    elif sys.argv[-1] != '-p' and len(sys.argv) == 2:
        # input given as file
        input_as_file = open(sys.argv[1])
        input = input_as_file.buffer.readline
        read = input_as_file.buffer.read

    main()


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

using namespace std;

typedef long long ll;

ll D[333][333], K[333][333][333];
ll dp[333][333];
ll n, t, m;

int main()
{
	ll i, j, k;
	
	scanf("%lld%lld%lld", &n, &t, &m);
	
	D[0][0] = K[0][0][0] = 1;
	for(i=1;i<=n;i++){
		for(j=0;j<=i;j++){
			for(k=0;k<=j;k++){
				if(j < i){
					K[i][j][k] = (K[i][j][k] + K[i-1][j][k]) % m;
				}
				if(j){
					K[i][j][k] = (K[i][j][k] + K[i-1][j-1][k] * k) % m;
					if(i-j >= k-1) K[i][j][k] = (K[i][j][k] + K[i-1][j-1][k-1] * (i-j-k+2)) % m;
				}
				D[i][j] = (D[i][j] + K[i][j][k]) % m;
			}
		}
	}
	
	for(i=0;i<=n;i++) dp[1][i] = 1;
	
	for(i=2;i<=t;i++){
		for(j=0;j<=n;j++){
			for(k=0;k<=j;k++){
				dp[i][j] = (dp[i][j] + dp[i-1][j-k] * D[j][k]) % m;
			}
		}
	}
	
	printf("%lld\n", dp[t][n]);
	
	return 0;
}

Measured memory_bytes: 261888
main(){double a,b,c,d,e,f,a2,b2,c2,d2,e2,f2,x,y,t,u;while(scanf("%lf %lf %lf %lf %lf %lf",&a,&b,&c,&d,&e,&f)!=-1){d2=a2=a*d;e2=e*a;b2=d*b;c2=c*d;f2=f*a;t=b2-e2;u=c2-f2;y=u/t;b2=e2=b*e;a2=e*a;c2=c*e;d2=d*b;f2=f*b;t=a2-d2;u=c2-f2;x=u/t;if(x==-0)x=0;if(y==-0)y=0;printf("%.3lf %.3lf\n",x,y);}return 0;}

Measured memory_bytes: 0
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 998244353
#define INIT -1

class UF
{
private:
   int n;
   vector<int> root;
   vector<int> size;

public:
   UF(int k)
   {
      n = k;
      root = vector<int>(n, -1);
      size = vector<int>(n, 1);
   }
   int getRoot(int x)
   {
      if (root[x] == -1)
         return x;
      else
         return root[x] = getRoot(root[x]);
   }
   void connect(int x, int y)
   {
      x = getRoot(x);
      y = getRoot(y);
      if (x == y)
         return;
      if (y < x)
         swap(x, y);
      root[y] = x;
      size[x] += size[y];
   }
   int getSize(int x)
   {
      return size[getRoot(x)];
   }
};

int main()
{
   long long int n, m;
   cin >> n >> m;
   vector<pair<int, int>> v;
   for (int i = 0; i < m; i++)
   {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      v.push_back(make_pair(a, b));
   }
   vector<long long int> ans;
   long long int nowans = n * (n - 1) / 2;
   ans.push_back(nowans);
   UF uf(n);
   for (int i = m - 1; i > 0; i--)
   {
      int a = v[i].first;
      int b = v[i].second;
      a = uf.getRoot(a);
      b = uf.getRoot(b);
      if (a != b)
      {
         long long int asize = uf.getSize(a);
         long long int bsize = uf.getSize(b);
         nowans -= asize * bsize;
         uf.connect(a, b);
      }
      ans.push_back(nowans);
   }
   for (auto itr = ans.rbegin(); itr != ans.rend(); itr++)
   {
      cout << *itr << endl;
   }
}

Measured memory_bytes: 6420
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// GCD : greatest common divisor (GCD) via Euclidean algorithm
func GCD(a, b int) int {
	for b != 0 {
		t := b
		b = a % b
		a = t
	}
	return a
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func main() {
	sc.Split(bufio.ScanWords)

	N, K := getInt(), getInt()
	a := make([]int, N)
	m := 0
	for i := 0; i < N; i++ {
		a[i] = getInt()
		m = max(m, a[i])
	}

	g := a[0]
	for i := 1; i < N; i++ {
		g = GCD(g, a[i])
	}

	if K <= m && K%g == 0 {
		out("POSSIBLE")
	} else {
		out("IMPOSSIBLE")
	}

}


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

using namespace std;

int main() {
    stack<int> s;
    string str;
    while(cin >> str) {
        if ('+' == str[0]) {
            int a = s.top(); s.pop();
            int b = s.top(); s.pop();
            s.push(a + b);
        }
        else if ('-' == str[0]) {
            int a = s.top(); s.pop();
            int b = s.top(); s.pop();
            s.push(b - a);
        }
        else if ('*' == str[0]) {
            int a = s.top(); s.pop();
            int b = s.top(); s.pop();
            s.push(a * b);
        }
        else if ('/' == str[0]) {
            int a = s.top(); s.pop();
            int b = s.top(); s.pop();
            s.push(b / a);
        }
        else {
            s.push(atoi(str.c_str()));
        }
    }
    cout << s.top() << endl;
}


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

#define ll long long
#define mod 1000000007

using namespace std;

ll power(ll x, ll N){
	ll res = 1;
	for(ll i=1; i<=N; i++){
		res*=x;
		res%=mod;
	}
	return res;
}


int main(){
	ll N;
	cin>>N;

	ll total = power(10, N);
	ll noZero = power(9, N);
	ll noNine = power(9, N);
	ll neitherZeroNorNine = power(8, N);

	ll ans = total - noNine - noZero + neitherZeroNorNine;
	ans%=mod;
	ans = (ans+mod)%mod;
	cout<<ans;

	return 0;
}

Measured memory_bytes: 3608
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1'000'000'007;
template <class T>
bool chmax(T &a, const T &b) { return (a < b) ? (a = b, 1) : 0; }
template <class T>
bool chmin(T &a, const T &b) { return (b < a) ? (a = b, 1) : 0; }

int maxdiff(int s1, int s2, int s3) {
    int smax = max(s1, max(s2, s3));
    int smin = min(s1, min(s2, s3));
    return smax - smin;
}

int main() {
    int h, w;
    cin >> h >> w;
    int h13 = int(h / 3.0 + 0.5);
    int h23 = h - h13;
    int h33 = h23 - h13;
    int w13 = int(w / 3.0 + 0.5);
    int w23 = w - w13;
    int w33 = w23 - w13;
    int h12 = int(h / 2.0 + 0.5);
    int h22 = h - h12;
    int w12 = int(w / 2.0 + 0.5);
    int w22 = w - w12;
    int ret = INF;
    chmin(ret, maxdiff(h13 * w, h13 * w, h33 * w));
    chmin(ret, maxdiff(h13 * w, h23 * w12, h23 * w22));
    chmin(ret, maxdiff(h * w13, h * w13, h * w33));
    chmin(ret, maxdiff(h * w13, h12 * w23, h22 * w23));
    cout << ret << endl;
    return 0;
}

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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

int main() {
	li min_not_10 = INF;
	li n;
	cin>>n;
	li sum=0;
	rin{
		li s;
		cin>>s;
		sum+=s;
		if(s%10>0){
			min_not_10 = min(min_not_10, s);
		}
	}
	if (min_not_10==INF){
		cout<<0<<endl;
	}else if(sum%10==0){
		cout<<sum - min_not_10<<endl;
	} else{
		cout<<sum<<endl;
	}

	return 0;
}

Measured memory_bytes: 256
N = int(input())
P = []
for i in range(N):
    x,y = map(int,input().split())
    P.append([x,y])
L,R = [],[]
F = 10**9
for a,b in P:
    L.append(a+b)
    R.append(F-b+a)
print(max(max(L)-min(L),max(R)-min(R)))

Measured memory_bytes: 54960
#define LOCAL
#include "bits/stdc++.h"
using namespace std;
#define FAST ios_base::sync_with_stdio(false); cin.tie(0);
#define LLINF ((long long) 1e18)//1234567890987654321
#define INF 1234567890ll
#define pb push_back
#define eb emplace_back
#define ins insert
#define f first
#define s second	
#define db 0
#define EPS (1e-7)    //0.0000001 the value
#define PI (acos((ld)-1.0))
#define MAXN (100006)
#define ll long long int 
#define ld long double
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());    //can be used by calling rng() or shuffle(A, A+n, rng)
#define FOR(ii, ss, ee) for(ll ii = ss; ii < (ll)ee; ++ii)
#define space " "
#define cbr cerr << "hi\n"
#define mmst(x, v) memset((x), v, sizeof ((x)))
#define siz(x) ((ll)x.size())
#define ph push
#define btinpct(x) __builtin_popcountll((x))
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
typedef pair <ll, ll> pi;
typedef pair <ll, pi> spi;
typedef pair <pi, pi> dpi;
inline ll rand(ll x, ll y) { ++y; return (rng() % (y-x)) + x; } //inclusivesss
string to_string(char c) {string s(1,c);return s;}string to_string(bool b){return (b ? "true" : "false");}template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}template <typename A>string to_string(A v) {bool first = true;string res = "{";for (const auto &x : v) {if (!first) {res += ", ";}first = false;res += to_string(x);}res += "}";return res;}void degug_out() { cerr << endl; }template <typename Head, typename... Tail>void degug_out(Head H, Tail... T) {cerr << " " << to_string(H);degug_out(T...);}inline ll gcd(ll a,ll b){if(a>b)swap(a,b);if(a==0)return b;return gcd(b%a,a);}
#ifdef LOCAL
#define degug(...) cerr << "[" << #__VA_ARGS__ << "]:", degug_out(__VA_ARGS__)
#else
#define degug(...) 42
#define cerr if(0)cout
#endif
ll n,dp[MAXN],k;
vector<int>v[MAXN];
const ll MOD=1e9+7;
void dfs(ll x,ll p){
	dp[x]=1;
	for(auto i:v[x])if(i!=p){dfs(i,x);dp[x]*=dp[i];dp[x]%=MOD;}
	if(x==1) { ll co=0; for(auto i:v[x])if(i^p)dp[x]*=(k-1-co++),dp[x]%=MOD;}
	else { ll co=0; for(auto i:v[x])if(i^p)dp[x]*=(k-2-co++),dp[x]%=MOD; }
}
int main()
{
	FAST
	cin>>n>>k; 
	FOR(i,1,n){ll a,b;cin>>a>>b;v[a].pb(b);v[b].pb(a);}
	dfs(1,1);
	cout<<dp[1]*k%MOD<<'\n';
}


Measured memory_bytes: 12416
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())

#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Dev 1000000007

// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<int> v;
    rep(i, n)
    {
        int temp;
        cin >> temp;
        v.push_back(temp);
    }
    SORT(v);
    vector<int> nim;
    if ((v[0]) % 2 != 0)
        nim.push_back(n);
    REP(i, 1, v.size())
    {
        if ((v[i] - v[i - 1]) % 2 != 0)
            nim.push_back(n - i);
    }
    int ans = 0;
    if (DEBUG)
    {
        rep(i, nim.size())
        {
            cout << nim[i] << endl;
        }
    }
    rep(i, nim.size())
    {
        ans = ans ^ nim[i];
    }
    if (ans == 0)
    {
        cout << "second" << endl;
    }
    else
    {
        cout << "first" << endl;
    }
    return 0;
}


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

const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;

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

  if(S.size() <= K){
    cout << S << endl;
  }else{
    int count = S.size() - K;
    rep(i,K){
      cout << S[i];
    }
    //rep(j,count){
      cout << "...";
    //}
  }
return 0;

}


Measured memory_bytes: 3624
import math
from collections import deque

N, D, A = list(map(int, input().split()))
data = []
for _ in range(N):
    x, h = list(map(int, input().split()))
    data.append((x, math.ceil(h/A)))
data = sorted(data, key=lambda x: x[0])

c = 0
damage_que = deque()
attack = 0 # 有効なダメージ合計
for i in range(N):
    x, h = data[i]

    # 爆破範囲が届いていなければ削除していく
    while damage_que and x > damage_que[0][0]:
        _, a = damage_que.popleft()
        attack -= a
    
    # 有効な過去の爆破攻撃を受ける
    remain = max(h - attack, 0)
    # 0になるまで爆破    
    attack += remain
    c += remain

    # 爆破回数追加    
    damage_que.append([x+2*D, remain])

print(c)

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    vector<int> cnt(n + 1, 0);
    int now = - 1;
    int tmp = 0;
    for (int i = 0; i < n; i++){
        if (a[i] != now){
            now = a[i];
            tmp = 1;
        }
        else tmp++;
        cnt[tmp]++;
    }
    vector<int> acc(n + 1, 0);
    for (int i = 1; i <= n; i++) acc[i] = acc[i - 1] + cnt[i];
    for (int i = 1; i <= n; i++){
        int ok = 0;
        int ng = n / i + 1;
        while (abs(ok - ng) > 1){
            int mid = (ok + ng) / 2;
            if (acc[mid] >= (long long)mid * i) ok = mid;
            else ng = mid;
        }
        cout << ok << endl;
    }
}


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

int n, ans = 100000;

void dfs(int num, int cnt) {
    if (ans < cnt) return;
    if (num < 6) {
        ans = min(ans, cnt + num);
        return;
    }
    for (int i = 5; i > 0; i--) {
        int tmp = num - pow(9, i);
        if (tmp < 0) continue;
        dfs(tmp, cnt+1);
        break;
    }
    for (int i = 6; i > 0; i--) {
        int tmp = num - pow(6, i);
        if (tmp < 0) continue;
        dfs(tmp, cnt+1);
        break;
    }
}

int main() {
    cin >> n;
    dfs(n, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<atcoder/dsu>

using namespace std;
using namespace atcoder;

int main(){

  int n,q;
  cin>>n>>q;
  dsu uni(n);
  while(q--){
    int t,u,v;
    cin>>t>>u>>v;
    if(t==0)uni.merge(u,v);
    if(t==1)cout<<uni.same(u,v)<<endl;
  }
}

Measured memory_bytes: 3908
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class Main {
	final int _intMax = Integer.MAX_VALUE; // =2147483647>10^9
	final int _intMin = Integer.MIN_VALUE;
	final long _longMax = Long.MAX_VALUE; // =9223372036854775807L>10^18
	final long _longMin = Long.MIN_VALUE;
	static boolean bElapsed = false;

	void solve() {
		int n = readNum();
		String[] sa = readFlds();
		for (String s : sa) {
			if ("Y".equals(s)) {
				pln("Four");
				return;
			}
		}
		pln("Three");
	}

	int pint(String s) {
		return Integer.parseInt(s);
	}

	long plong(String s) {
		return Long.parseLong(s);
	}

	String readLine() {
		try {
			return _in.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int readNum() {
		String line = readLine();
		return pint(line);
	}

	String[] readFlds() {
		String line = readLine();
		return line.split(" ");
	}

	int[] readNums() {
		String[] flds = readFlds();
		int[] nums = new int[flds.length];
		for (int i = 0; i < flds.length; i++) {
			nums[i] = pint(flds[i]);
		}
		return nums;
	}

	void p(char c) {
		_out.print(c);
	}

	void pln(char c) {
		_out.println(c);
	}

	void p(double d) {
		_out.print(d);
	}

	void pln(double d) {
		_out.println(d);
	}

	void p(long l) {
		_out.print(l);
	}

	void pln(long l) {
		_out.println(l);
	}

	void p(String s) {
		_out.print(s);
	}

	void pln(String s) {
		_out.println(s);
	}

	static BufferedReader _in;
	static PrintWriter _out;

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		_in = new BufferedReader(new InputStreamReader(System.in));
		_out = new PrintWriter(System.out);
		new Main().solve();
		_out.flush();
		long end = System.currentTimeMillis();
		if (bElapsed) {
			System.err.println((end - start) + "ms");
		}
	}
}


Measured memory_bytes: 21204
L, R = list(map(int, input().split()))  


if R - L >= 672:
    ans = 0
elif R * L < 2019:
    ans = L*(L+1)
else:
    ans = 2018
    for i in range(L, R):
        for j in range(L+1, R+1):
            mod=(i*j)%2019
            if mod < ans:
                ans = mod
print(ans)

Measured memory_bytes: 3064
N, A = map(int, input().split())
x = list(map(int, input().split()))
for i in range(N):
    x[i] -= A
max_x = max(max(x), A)

dp = [[0]*(2*N*max_x + 1) for i in range(N+1)]
dp[0][N*max_x] = 1

for i in range(N):
    for k in range(2*N*max_x + 1):
        dp[i+1][k] = dp[i][k]
        if 0 <= k - x[i] and k - x[i] <= 2*N*max_x:
            dp[i+1][k] += dp[i][k - x[i]]

print(dp[N][N*max_x] - 1)

Measured memory_bytes: 5228
n, m = map(int, input().split())
X = []
Y = {}
ans = -2
for _ in range(m):
    # print(X, Y)
    x, y = map(int, input().split())
    if n > 1 and x == 1 and y ==0:
        ans = -1
    if x in Y:
        if Y[x] != y:
            ans = -1
    X += [(x, y)]
    Y[x] = y

if ans == -1:
    print(ans)
else:
    ans = {}
    if n == 1:
        ans[0] = 0
    elif n == 2:
        ans[0] = 1
        ans[1] = 0
    elif n == 3:
        ans[0] = 1
        ans[1] = 0
        ans[2] = 0
    for (x, y) in X:
        ans[x-1] = y
    if n == 1:
        print(ans[0])
    elif n == 2:
        print(int(ans[0])*10 + int(ans[1]))
    elif n == 3:
        print(int(ans[0])*100 + int(ans[1])*10 + int(ans[2]))


Measured memory_bytes: 38256
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int no_of_cards, no_of_lines;
    cin >> no_of_cards >> no_of_lines;

    const int oo = 1e9 + 9;
    int largest_left = -oo, smallest_right = oo;

    for(int i = 1; i <= no_of_lines; i++)
    {
        int left, right;
        cin >> left >> right;

        largest_left = max(largest_left, left);
        smallest_right = min(smallest_right, right);
    }

    int covered_length = (smallest_right < largest_left ? 0 : smallest_right - (largest_left - 1));

    cout << covered_length;
    return 0;
}


Measured memory_bytes: 256
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

    ($iter:expr, bytes) => {
        read_value!($iter, String).into_bytes()
    };

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"5"# => r#"11"#,
r#"86"# => r#"939587134549734843"#,
}

fn solve(src: &str) -> String {

    input! {
        source = src,
        n: usize,
    }

    let mut a:i64 = 2;
    let mut b:i64 = 1;
    for _ in 2..n+1 {
        let tmp = b;
        b = a + b;
        a = tmp;
    }

    let ans = if n == 0 {
                  a
              }  else {
                  b
              };

    ans.to_string()
}

Measured memory_bytes: 4352
import java.util.Scanner;

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

    int N = scanner.nextInt();
    char[] s1 = scanner.next().toCharArray();
    char[] s2 = scanner.next().toCharArray();

    final int M = 1000000007;
    boolean pVertical = false;
    long res = 1;
    for (int i = 0; i < N; i++) {
      if (i < N - 1 && s1[i] == s1[i + 1]) {
        if (i == 0) {
          res *= 6;
        } else if (pVertical) {
          res *= 2;
        } else {
          res *= 3;
        }
        i++;
        pVertical = false;
      } else {
        if (i == 0) {
          res *= 3;
        } else if (pVertical) {
          res *= 2;
        }
        pVertical = true;
      }
      res %= M;
    }
    System.out.println(res % M);
  }
}


Measured memory_bytes: 23124
import functools
import itertools

import os
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


def debug(fn):
    if not os.getenv('LOCAL'):
        return fn

    @functools.wraps(fn)
    def wrapper(*args, **kwargs):
        ret = fn(*args, **kwargs)
        print('DEBUG: {}({}) -> '.format(
            fn.__name__,
            ', '.join(
                list(map(str, args)) +
                ['{}={}'.format(k, str(v)) for k, v in kwargs.items()]
            )
        ), end='')
        print(ret)
        return ret

    return wrapper


def count_mp(target, sizes):
    return (len(sizes) - 1) * 10 + abs(target - sum(sizes))


N, A, B, C = map(int, input().split())
sizes = []
for _ in range(N):
    sizes.append(int(input()))

ans = INF
for allocs in itertools.product('abc_', repeat=N):
    a = []
    b = []
    c = []
    mp = 0
    for i, al in enumerate(allocs):
        if al == 'a':
            a.append(sizes[i])
        if al == 'b':
            b.append(sizes[i])
        if al == 'c':
            c.append(sizes[i])
    if not a or not b or not c:
        continue
    ans = min(ans, count_mp(A, a) + count_mp(B, b) + count_mp(C, c))
    if ans == 0:
        break
print(ans)


Measured memory_bytes: 50648
N = int(input())
d = len(str(N))
if d == 1:
    print(N)
    exit()
x = int(str(N)[0])
y = int(str(N)[-1])
if d == 2:
    M = 0
else:
    M = int(str(N)[1:-1])
count = 0
for A in range(1, N + 1):
    count0 = 0
    a = int(str(A)[0])
    b = int(str(A)[-1])
    if b == 0:
        continue
    if a == b:
        count0 += 1
    count0 += (10 ** (d - 2) - 1) // 9
    if b < x:
        count0 += (10 ** (d - 2))
    if b == x:
        count0 += M
        if a <= y:
            count0 += 1
    count += count0
print(count)


Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define rep(i,n) for(ll i=0;i<(n);++i)
#define REP(i,a,b) for(ll i=(a);i<(b);++i)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ld EPS=10e-8;
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll C=0;
string S[207];
queue<int> Q;
int N;
int chek[207];
vector<int> DIS(207);
int dismax=0;

void bfs(int t){
    if(Q.empty()==1){
        return;
    }
    int h=0;
    rep(i,t){
        rep(j,N){
            if(S[Q.front()][j]=='1'){
                if(chek[j]==1 && (DIS[Q.front()]+1)%2!=DIS[j]%2){
                    cout << -1 << endl;
                    C=-1;
                    return;
                }               
                if(chek[j]==0){
                    DIS[j]=DIS[Q.front()]+1;
                    chek[j]=1;
                    h++;
                    Q.push(j);
                }
            }
        }
        Q.pop();
    }
    bfs(h);
}

void bfs2(int t,int u){
    if(Q.empty()==1){
        return;
    }
    int h=0;
    if(u>dismax){
        dismax=u;
    }
    rep(i,t){
        rep(j,N){
            if(S[Q.front()][j]=='1' && chek[j]==0){
                Q.push(j);
                chek[j]=1;
                h++;
            }
        }
        Q.pop();
    }
    bfs2(h,u+1);
}

int main(){
    cin >> N;
    rep(i,N){
        cin >> S[i];
    }
    chek[0]=1;
    DIS[0]=0;
    Q.push(0);
    bfs(1);
    if(C==-1){
        return 0;
    }
    rep(i,N){
        rep(j,N){
            chek[j]=0;
        }
        chek[i]=1;
        Q.push(i);
        bfs2(1,0);
    }
    cout << dismax+1 << endl;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main() {
	int n; ll w; cin >> n >> w;
	vector<ll> v[5];
	ll p, t; cin >> p >> t; v[0].push_back(t);
	for (int i = 1; i < n; i++) {
		ll z; cin >> z >> t;
		v[z - p].push_back(t);
	}
	ll ans = 0;
	for (int i = 0; i <= 3; i++)sort(v[i].begin(), v[i].end());
	for (ll i = 0; i <= v[0].size(); i++) 
		for (ll j = 0; j <= v[1].size(); j++)
			for (ll k = 0; k <= v[2].size(); k++)
				for (ll l = 0; l <= v[3].size(); l++)
					if (i*p + j*(p + 1) + k*(p + 2) + l*(p + 3) <= w) {
						ll cnt = 0;
						for (int m = 0; m < i; m++)cnt += v[0][v[0].size() - 1 - m];
						for (int m = 0; m < j; m++)cnt += v[1][v[1].size() - 1 - m];
						for (int m = 0; m < k; m++)cnt += v[2][v[2].size() - 1 - m];
						for (int m = 0; m < l; m++)cnt += v[3][v[3].size() - 1 - m];
						ans = max(ans, cnt);
					}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,ans,nn;
  ans=0;
  cin>>n;
  vector<long> vec(0);
  vector<long> tuika(0);
  for(long i=1; i*i<=n; i++){
    if(n%i==0){
      vec.push_back(i);
      if(n/i!=i){
        vec.push_back(n/i);
      }
    }
  }
  nn=n-1;
  for(long i=1; i*i<=nn; i++){
    if(nn%i==0){
      tuika.push_back(i);
      if(nn/i!=i){
        tuika.push_back(nn/i);
      }
    }
  }
 
  for(long i=0; i<vec.size(); i++){
    nn=n;
    while(true){
      if(vec.at(i)==1){
        break;
      }
      if(nn%vec.at(i)==0){
        nn=nn/vec.at(i);
      }
      else{
        break;
      }
    }
    
    
    
    
    if(nn==1){
      ans=ans+1;
      
    }
    else if(vec.at(i)!=1){
      nn=nn-1;
      if(nn%vec.at(i)==0){
        ans=ans+1;
        
      }
    }
  }
  ans=ans-1+tuika.size();
  cout<<ans;
}

Measured memory_bytes: 384
N = int(input())
A= list(map(int,input().split()))
c = 0
for i in range(N):
    minj = i
    for j in range(i,N):
        if A[j] < A[minj]:
            minj = j
    if A[i] != A[minj]:
        A[minj],A[i] = A[i],A[minj]
        c += 1
print (" ".join(map(str,A)))
print (c)

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

int main(){
  int A, B, hoge_count = 0;
  char *S;
  scanf("%d%d", &A, &B);
  S = (char *)malloc(sizeof(char) * (A + B + 2));
  scanf("%s", S);
  for(int i = 0; i < (A + B + 2); i++) if(S[i] == '-') hoge_count++;
  if(hoge_count == 1){
    if(S[A] == '-') printf("Yes");
    else printf("No");
  }else{
    printf("No");
  }
  free(S);
  return 0;
}

Measured memory_bytes: 128