akhauriyash/Code-Regression huggingface dataset:
//author rhythmicankur
                                                                  //god_is_almighty
#pragma GCC optimize("O3")
#pragma GCC target ("sse4")
#include<bits/stdc++.h>
#define f 		first
#define s 		second
#define int     long long
#define ll      int
#define ld 		long double
#define pb 		push_back
#define eb 		emplace_back
#define mk 		make_pair
#define vi 		vector<int>
#define pii 		pair<int,int>
#define pip             pair<int,pii>
#define vpi 		vector<pii>
#define sbcount(x) __builtin_popcountll(x)
#define REP(i,n) for (int i = 1; i <= n; i++)
#define trav(a, x)      for(auto& a : x)
#define all(x)          x.begin(), x.end()
#define fill(a,val)	memset(a,val,sizeof(a))
#define 	PI acos(-1)
#define coud(a,b) cout<<fixed << setprecision((b)) << (a)
#define M1 	998244353
#define M2 	1000000007
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;

template<typename T> T gcd(T a,T b) { if(a==0) return b; return gcd(b%a,a); } 
#define test4(x,y,z,a) 		    cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<"  |  "<<#a<<": "<<a<<endl;
#define test1(x)                cerr<<#x<<": "<<x<<endl
#define test2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define test3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
ll power(ll a,ll b,ll m=M2){ll answer=1;while(b){if(b&1)answer=(answer*a)%m;b/=2;a=(a*a)%m;}return answer;}
using namespace std;
void ctrl(){cout<<"Control"<<endl;}
int make_num(string p){stringstream geek(p); int x = 0; geek >> x;return x;}
string make_str(int x){ostringstream str1; str1 << x; string geek = str1.str(); return geek;}

signed main()
{	ios::sync_with_stdio(0);
	cin.tie(0); 
	cin.exceptions(cin.failbit);
	int k,x;
    cin>>k>>x;
    if(k*500>=x)
    cout<<"Yes";
    else
    {
        cout<<"No";
    }
    

return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

#define CHMIN(a, b) a=min((a), (b))
#define CHMAX(a, b) a=max((a), (b))

const ll MOD=1000000007ll;
// const ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, p[114514];
	cin>>n;
	REP(i, n){
		cin>>p[i];
	}
	int ans=0;
	REP(i, n){
		if(i+1==p[i]){
			swap(p[i], p[i+1]);
			++ans;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main()
{
    ll N;
    cin >> N;
    ull Ti, Ai;
    ull nT=1, nA=1;
    for(int i=0;i<N;i++){
        cin >> Ti >> Ai;
        auto n1 = (nT + Ti-1)/Ti;
        auto n2 = (nA + Ai-1)/Ai;
        auto n = max(n1, n2);
        nT = Ti * n;
        nA = Ai * n;
    }
    cout<<(nT+nA)<<endl;

    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void) {
    int a,b,c;
    scanf("%d %d %d", &a,&b,&c);
    if (a < b && b < c)printf("Yes\n");
    else printf("No\n");
    return 0;
}


Measured memory_bytes: 2120
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rrep(i, n) for (int i = (n); i >= 0; --i)

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

  vector<int> A(N);
  map<int, int> m;
  rep(i, N) {
    cin >> A[i];
    ++m[A[i]];
  }
  sort(A.begin(), A.end());

  int ans = 0;
  rrep(i, N - 1) {
    if (m[A[i]] == 0) continue;
    --m[A[i]];
    int pow = 1;
    while (2 * pow <= A[i]) pow *= 2;
    if (m[2 * pow - A[i]] > 0) {
      ++ans;
      --m[2 * pow - A[i]];
    }
  }
  cout << ans << endl;

  return 0;
}


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

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

int dp[101][100100];

int main(void) {
	int N,K;
	cin >> N >> K;
	dp[0][0] = 1;
	REP(i,N) {
		int x;
		cin >> x;
		int sum=0;
		for(int j=0; j<=K; j++) {
			sum = (sum+dp[i][j]) % 1000000007;
			if(j > x)
				sum = (sum+1000000007-dp[i][j-x-1]) % 1000000007;
			dp[i+1][j] = sum;
		}
	}
	cout << dp[N][K] << endl;
	return 0;
}


Measured memory_bytes: 39296
n = input()
L = []
s = 0
for i in range(len(n)):
  L.append(int(n[i]))

for i in range(len(n)):
  s += (sum(L[0:i])*(2**(i-1))+(L[i]*(2**i)))*(10**(len(n)-i-1))
print(int(s))

Measured memory_bytes: 3060
using System;
using static System.Console;
using static System.Math;
using System.Numerics;
using System.Collections.Generic;
using System.Linq;


public class Program
{
    public static void Main(string[] args)
    {
        var s = int.Parse(ReadLine());
        var ans = "";
        for (int i = 0; i < s;i++)
            ans += "ACL";
        WriteLine(ans);
        Out.Flush();
    }
}
public static class myRead
{
    public static int readInt() { return int.Parse(ReadLine()); }
    public static long readLong() { return long.Parse(ReadLine()); }
    public static string reatStr() { return ReadLine(); }
    public static int[] readIntArray() { return ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] readLongArray() { return ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] readStrArray() { return ReadLine().Split(' '); }
}


public static class MyMath
{
    public static long Factorical(long n)
    { return n <= 1 ? 1L : n * Factorical(n - 1); }
    public static long Permutation(long n, long m)
    { return m == 0 ? 1L : (m == n) ? Permutation(n, m - 1) : n * Permutation(n - 1, m - 1); }
    public static long Combination(long n, long m)
    { return n - m > m ? Permutation(n, m) / Factorical(m) : Permutation(n, n - m) / Factorical(n - m); }
    public static long Gcd(long n, long m)
    { return n % m == 0 ? m : Gcd(m, n % m); }
    public static long Lcm(long n, long m)
    { return n * m / Gcd(n, m); }
    public static long Pow(long n, long m)
    { return m == 0 ? 1L : m == 1 ? n : n * Pow(n, m - 1); }
}




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

int main() 
{
	int a,b,c;
	cin>>a>>b>>c;
	unordered_map<int,int> found;
	int mul=a;
	while(true)
	{
		int md=mul%b;
		if(found.find(md)!=found.end())
		{
			cout<<"NO";
			return 0;
		}
		if(md==c)
		{
			cout<<"YES";
			return 0;
		}
		mul+=a;
		found[md]=1;
	}
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
using namespace std;
int main(){
    int n,cnt,ans; cin >> n;
    if (n<105) ans=0;
    else if (n<135) ans=1;
    else if (n<165) ans=2;
    else if (n<189) ans=3;
    else if (n<195) ans=4;
    else ans = 5;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <stack>
#include <cstring>
#include <cmath>
#include <vector>
using namespace std;
typedef long long ll;
int main()
{
#ifdef LOCAL
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif // LOCAL

    char ch;
    ch=getchar();
    if(ch=='a'||ch=='i'||ch=='e'||ch=='o'||ch=='u')
        printf("vowel");
    else
        printf("consonant");
    return 0;
}


Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <stack>
#include <queue>
#include <string>
#include <map>
#define mp make_pair
#define pb push_back
#define p push
#define FOR(a,c) for(int a = 0;a<c;a++)
#define ll long long
#define abs(x) (x<0 ? (-x) : x)
#define getI(a) scanf("%d",&a)
#define getII(a,b) scanf("%d %d",&a,&b)
#define getIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define getL(a) scanf("%lld",&a)
#define getLL(a,b) scanf("%lld %lld",&a,&b)
#define getLLL(a,b,c) scanf("%lld%lld%lld",&a,&b,&c)
#define BEND(c) (c).begin(),(c).end()
#define fi first
#define se second
#define pi 3.1415926535897932384626
#define getS(a) scanf("%s",a)
#define pfi(a) printf("%d\n",a);
#define pfii(a,b) printf("%d %d\n",a,b);
#define pfl(a) printf("%lld\n",a);
#define pfll(a,b) printf("%lld %lld\n",a,b);
#define  SIZE 1000000007

using namespace std;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vl;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<long long,long long>> vpl;
typedef pair<int,int> pii;
typedef pair <ll,ll> pll;


int gcd(int a, int b) {
    while (a > 0 && b > 0)
        if (a > b) a %= b;
        else b %= a;
    return a + b;
}

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

int grid [1003][1003];


long long fast_exp(long long n,long long k){
    if(k == 0)
        return 1;
    if(k==1)
        return n;

    long long temp = fast_exp(n,k>>1);

    if((k&1)==1)
        return (n*temp*temp)%SIZE;
    return (temp*temp)%SIZE;

}
ll isprime(ll i){
    if (i==2 || i == 3){
        return 0;
    }
    bool ctr =0;
    for(ll k = 2;k*k <i;k++){
        if(i%k==0)ctr=1;
    }
    if(ctr)return 1;
    else return 0;

}

int main()
{
    string s;
    cin >> s;
    if(s == "Sunny")cout << "Cloudy";
    else if (s == "Cloudy") cout <<"Rainy";
    else if ( s == "Rainy") cout << "Sunny";



  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main()
{
    int n; cin >> n;
    ll ans = 0;
    FOR(i, 1, n+1){
        ll k = floor(n/i);
        ans += k*(k+1)*i/2;
    }
    pr(ans);
    return 0;}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
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);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B; cin >> A >> B;
    if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }

    return res;
}

//template<class Type>
//Type solve(Type res = Type()){
//    ll N; cin >> N;
//    vector<ll> a(N); for(auto&in:a) cin >> in;
//    ll suma = accumulate(a.begin(),a.end(),0LL);
//    if(suma%N != 0){
//        cout << -1 << endl;
//        return res;
//    }
//
//    ll eacha = suma/N;
//    ll now = a[0] - eacha;
//    for(int i = 1; i < N;i++){
//        if(now != 0){
//            res++;
//        }
//
//        now += a[i] - eacha;
//    }
//
//    cout << res << endl;
//    return res;
//}



//template<class Type>
//Type solve(Type res = Type()){
//    ll N; cin >> N;
//    vector<ll> A(N); for(auto& in:A) cin >> in;
//    sort(A.begin(),A.end());
//    A.erase(unique(A.begin(),A.end()),A.end());
//    cout << A.size() << endl;
//    return res;
//}


int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    solve(0);
    // cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	}
}

Measured memory_bytes: 42432
#include <iostream>
#include <vector>
#include <unordered_set>

using namespace std;

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

	if ((n < 7 && n != 4) || n == 9 || n == 10 || n == 13 || n == 17)
	{
		cout << "No" << endl;
	}
	else
	{
		cout << "Yes" << endl;
	}
}

Measured memory_bytes: 256
exception Error of string
let err s = raise (Error s)

let _ =
    let swap a b
        = if a > b then (b, a)
          else (a, b) in
    let a, b, c = Scanf.scanf "%d %d %d" (fun a b c -> a, b, c) in
    let a, b = swap a b in
    let b, c = swap b c in
    let a, b = swap a b in
    Printf.printf "%d %d %d\n" a b c


Measured memory_bytes: 2428
# util functions

# debug
$debugFlag = ( ARGV[0] != nil )
p "==== DEBUG MODE ====" if $debugFlag

def pd(str)
  p str if $debugFlag
end

def printd(str)
  print str if $debugFlag
end

# input
inputs = []
lc = 0
while l = $stdin.gets do
  if false
    inputs << l.chomp.split(" ").map(&:to_s)
  else
    inputs << l.chomp.split(" ").map(&:to_i)
  end
  lc += 1
end

aa = inputs[0][0]

# input check
if $debugFlag
  p "--- INPUT (begin) ---"
  inputs.each do |l_i|
    p l_i
  end
  p "--- INPUT (end) ---"
  print "\n"
end

# body
if $debugFlag
end

puts 3*aa*aa


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;
  cin>>S;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='0') count++;
  }
  int X=(int)S.size();
  cout<<min(count,X-count)*2<<endl;
}



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

using namespace std;
 
const int inf = 1e8;
#define ll long long
#define fr(i,a,n) for (int i=a;i<n;i++)
#define rfr(i,n,a) for (int i=n;i>=a;i--)
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define endl "\n"
typedef vector<int> VI;
typedef vector<ll> VL;

ll n,m,k;

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	k = n * (n-1);
	k += m * (m- 1);
	cout << k/2 << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
N,M=map(int,input().split())
to=[[] for _ in range(N)]
for _ in range(M):
  a,b=map(int,input().split())
  to[a-1].append(b-1)
  to[b-1].append(a-1)
q=deque([0])
r=[None]*N
while q:
  x=q.popleft()
  for i in to[x]:
    if r[i] is None:
      q.append(i)
      r[i]=x+1
print('Yes')
print('\n'.join(map(str,r[1:])))

Measured memory_bytes: 44552
# -*- coding: utf-8 -*-
import unittest


def func(s,t):
    n = len(s)
    for c in set(s):
        d = None
        for i in range(n):
            if s[i]==c:
                if d is None:
                    d = t[i]
                elif d!=t[i]:
                    return "No"
    for c in set(t):
        d = None
        for i in range(n):
            if t[i]==c:
                if d is None:
                    d = s[i]
                elif d!=s[i]:
                    return "No"
    return "Yes"

class Test(unittest.TestCase):
    def test(self):
        self.assertEqual(func("azzel", "apple"), "Yes")
        self.assertEqual(func("chokudai", "redcoder"), "No")
        self.assertEqual(func("abcdefghijklmnopqrstuvwxyz", "ibyhqfrekavclxjstdwgpzmonu"), "Yes")
        self.assertEqual(func("abc", "abc"), "Yes")

if __name__ == '__main__':
    s = input()
    t = input()
    # unittest.main()
    print(func(s,t))


Measured memory_bytes: 6224
n = int(input())
k = int(input())
x = int(input())
y = int(input())

# print(n)
# print(k)
# print(x)
# print(y)

result = 0
for i in range(n):
    # print(i)
    if i < k:
        result = result + x
    else:
        result = result + y
        
print(result)

Measured memory_bytes: 2940
a, b, c, x = [int(input()) for i in range(4)]
res = 0
for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      if 500 * i + 100 * j + 50 * k == x:
        res += 1
print(res)

Measured memory_bytes: 2940
// M - Candies  https://atcoder.jp/contests/dp/tasks/dp_m
/* 入力例
3 4
1 2 3
// →出力 5 longlongintにしたらあと1個1-08以外は通った。unsilonglongintだとint同様９番目以下全滅なぜだ？
// longlongintでも ３５行目のif(dp[i][j]<0){dp[i][j]=0;}//最後の変更点処理を加えると9番目以下が全滅。longlongintで通ったテストでDPが負になっているということ？
*/
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int N, K;
    cin >> N >> K;
    long long int a[N], dp[K + 1][N];
    for(int i = 0; i < N; i++) {
        cin >> a[i];
    }
    for(int j = 0; j < N; j++) {
        dp[0][j] = 1;
    }
    for(int i = 1; i <= K; i++) {
        if(i <= a[0]) {
            dp[i][0] = 1;
        } else {
            dp[i][0] = 0;
        }
        for(int j = 1; j < N; j++) {
            if(a[j] == 0) {
                dp[i][j] = dp[i][j - 1];
            } else {
                if(i <= a[j]) {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] + 1000000007) % (1000000007);
                } else {
                    dp[i][j] = (dp[i][j - 1] + dp[i - 1][j] - dp[i - 1 - a[j]][j - 1] + 1000000007) % (1000000007);
                }
            }
        }
    }
    cout << dp[K][N - 1] << endl;
    return 0;
}


Measured memory_bytes: 78336
use std::cmp::max;
use std::io::stdin;
use std::io::Read;
use std::io::StdinLock;
use std::str::FromStr;

fn read<T: FromStr>(s: &mut StdinLock) -> Option<T> {
  let s = s
    .by_ref()
    .bytes()
    .map(|c| c.unwrap() as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect::<String>();
  s.parse::<T>().ok()
}

#[derive(Clone, Debug)]
struct Calculator {
  q: usize,
  a: Vec<usize>,
  b: Vec<usize>,
  c: Vec<i32>,
  d: Vec<i32>,
}

impl Calculator {
  fn new(q: usize, a: Vec<usize>, b: Vec<usize>, c: Vec<i32>, d: Vec<i32>) -> Self {
    Self {
      q: q,
      a: a,
      b: b,
      c: c,
      d: d,
    }
  }

  fn exec(self, array: &[i32]) -> i32 {
    let mut ans: i32 = 0;
    for i in 0..self.q {
      if array[self.b[i as usize] - 1] - array[self.a[i as usize] - 1] == self.c[i as usize] {
        ans += self.d[i as usize];
        // println!(
        //   "exec add[{:?}] d[{:?}] ans[{:?}]",
        //   i, self.d[i as usize], ans
        // );
      }
    }
    ans
  }
}

fn main() {
  let s = stdin();
  let mut s = s.lock();
  let s = &mut s;
  let n = read::<i32>(s).unwrap();
  let m = read::<usize>(s).unwrap();
  let q = read::<usize>(s).unwrap();

  let mut a: Vec<usize> = Vec::with_capacity(q);
  let mut b: Vec<usize> = Vec::with_capacity(q);
  let mut c: Vec<i32> = Vec::with_capacity(q);
  let mut d: Vec<i32> = Vec::with_capacity(q);

  for _ in 0..q {
    a.push(read::<usize>(s).unwrap());
    b.push(read::<usize>(s).unwrap());
    c.push(read::<i32>(s).unwrap());
    d.push(read::<i32>(s).unwrap());
  }
  let calculator = Calculator::new(q, a, b, c, d);

  // println!("calculator={:?}", calculator);

  fn dfs(rest: i32, start: i32, end: i32, calculator: Calculator, vec: &mut Vec<i32>) -> i32 {
    // println!("rest={:?} start={:?} end={:?}", rest, start, end);
    if rest >= 1 {
      let mut ans = 0;
      for i in start..=end {
        vec.push(i);
        ans = max(ans, dfs(rest - 1, i, end, calculator.clone(), vec));
        vec.pop();
      }
      ans
    } else {
      // println!("array={:?}", vec);
      calculator.exec(&vec)
    }
  }

  println!(
    "{:?}",
    dfs(
      n,
      1,
      m as i32,
      calculator,
      &mut Vec::with_capacity(n as usize)
    )
  );
}


Measured memory_bytes: 2152
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.StringTokenizer;

public class Main {

    public static void main(String[] args) throws InterruptedException {
        FastScanner fs=new FastScanner();
        int T=fs.nextInt();
        /*
        for (int tt=0; tt<T; tt++) {

        }
         */
        if (T % 1000 == 0) {
            System.out.println("0");
        } else {
            int round = (1 + (T / 1000)) * 1000;
            System.out.println(round - T);
        }
    }

    void sort(int[] a) {
        ArrayList<Integer> list=new ArrayList<>();
        for (int i:a) list.add(i);
        Collections.sort(list);
        for (int i=0; i<a.length; i++) a[i]=list.get(i);
    }

    static class FastScanner {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer("");

        public String next() {
            while (!st.hasMoreTokens())
                try {
                    st=new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            return st.nextToken();

        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public int[] readArray(int n) {
            int[] a=new int[n];
            for (int i=0; i<n; i++) a[i]=nextInt();
            return a;
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

        public long[] readLongArray(int n) {
            long[] a=new long[n];
            for (int i=0; i<n; i++) a[i]=nextLong();
            return a;
        }
    }
}

Measured memory_bytes: 32628
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>
#include<queue>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   int A, B, C;
   cin >> A >> B >> C;
   if (A <= C && C <= B) cout << "Yes" << endl;
   else cout << "No" << endl;
   return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
using namespace std;
int ans,n;
int a,b;
int main()
{
	system("color 0a");
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a>>b;
		ans+=abs(a-b)+1;
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int s;
  cin >> s;
  
  int s1, s2, s3;
  s3 = s % 10;
  s1 = s / 100;
  s2 = (s - s3) / 10 % 10;
  
  cout << s1 + s2 + s3 << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; cin>>n;
	vll p(n);
	rep(i, n) cin>>p[i];

	ll ans=0;
	rep(i, n-2){
		vll cp(3);
		rep(j, 3) cp[j] = p[i+j];
		sort(all(cp));
		if (cp[1] == p[i+1]){
			ans++;
		}
	}

	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,L,R;
string S, T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
typedef pair<ll,ll> P;

int main() {
    cin>>N;
    S = "No";
    rep(i,9) rep(j,9) if((i+1) * (j+1) == N) S = "Yes";
    cout<<S<<endl;
}

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

int main() {
    int d; cin >> d;
    if(d==25){
        cout << "Christmas" << endl;
    }
    else if(d==24){
        cout << "Christmas Eve" << endl;
    }
    else if(d==23){
        cout << "Christmas Eve Eve" << endl;
    }
    else if(d==22){
        cout << "Christmas Eve Eve Eve" << endl;
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mp mak_pair
#define pb push_back
int n;
ll x[200000];
ll mod=int(1e9+7);
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	ll s=0,res=0;
	for(int i=0;i<n;i++)cin>>x[i],s+=x[i];
	s%=mod;
	for(int i=0;i<n;i++){
		s-=x[i];
		s=(s+mod)%mod;
		res+=(x[i]*s+mod)%mod;
		res=(res+mod)%mod;
	}
	cout<<(res+mod)%mod;
	return 0;
}

Measured memory_bytes: 5172
# -*- coding:utf-8 -*-
import datetime


def main(a, b):
    dt = datetime.datetime(2004, a, b)
    week_num = dt.weekday()

    if week_num == 0:
        print('Monday')
    elif week_num == 1:
        print('Tuesday')
    elif week_num == 2:
        print('Wednesday')
    elif week_num == 3:
        print('Thursday')
    elif week_num == 4:
        print('Friday')
    elif week_num == 5:
        print('Saturday')
    elif week_num == 6:
        print('Sunday')


while True:
    a, b = [int(e) for e in input().split()]
    if a == 0 and b == 0:
        break

    main(a, b)

Measured memory_bytes: 8116
#include <cstdio>
using namespace std;
int n, ans;
int main() {
	scanf("%d", &n);
	for ( int i = 1, a; i <= n; i ++) {
		scanf("%d", &a);
		while ( !(a & 1)) ans ++, a >>= 1;
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 128
use std::io::*;
use std::str::FromStr;

fn main() {
    let n: usize = read();
    let p: Vec<i64> = (0..n).map(|_| read()).collect();

    let mut sum = 0;
    let mut max = 0;
    for i in &p {
        sum += *i;
        max = std::cmp::max(max, *i);
    }
    println!("{}", sum - max / 2);
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}


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

ll cara(ll n){
  if(n==1)return 1;
  else return(cara(n/2)*2+1);
}

int main(){
  ll n;
  cin >> n;
  cout<<cara(n)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,m,lsg,x,sum,ans;
int read(){
	char c=getchar();while (c!='-'&&(c<'0'||c>'9'))c=getchar();
	int k=1,kk=0;if (c=='-')k=-1,c=getchar();
	while (c>='0'&&c<='9')kk=kk*10+c-'0',c=getchar();return k*kk;
}
signed main(){
	n=read();ans=1e15;for (int i=1;i<=n;i++){
		x=read();sum+=x;if (x%10!=0)ans=min(ans,x);
	}if (sum%10==0)sum-=ans;sum=max(sum,0ll);cout<<sum<<endl;
}


Measured memory_bytes: 256
import Control.Monad
import Control.Applicative

main = do
  contents <- (fmap (read :: String -> Int) . lines) <$> getContents
  solve contents []

solve :: [Int] -> [Int] -> IO ()
solve [] _ = return ()
solve (x:xs) [] = solve xs (x:[])
solve (x:xs) (y:ys) = if x == 0
  then do
    putStrLn $ show y
    solve xs ys
  else solve xs (x:y:ys)

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

int main()
{
	int c[3][3];

	for (int i = 0; i < 3; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			cin >> c[i][j];
		}
	}

	bool isYes = true;
	for (int j = 1; j < 3; ++j)
	{
		if (!(c[0][0] - c[j][0] == c[0][1] - c[j][1]
			  && c[0][0] - c[j][0] == c[0][2] - c[j][2]
			  && c[0][0] - c[0][j] == c[1][0] - c[1][j]
			  && c[0][0] - c[0][j] == c[2][0] - c[2][j]))
		{
			isYes = false;
			break;
		}
	}

	if (isYes)
	{
		cout << "Yes" << endl;
	}
	else
	{
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int R = int.Parse(Console.ReadLine());
            string ans = "";
            if (R < 1200)
            {
                ans = "ABC";
            }
            else if (R < 2800)
            {
                ans = "ARC";
            }
            else
            {
                ans = "AGC";
            }
            Console.WriteLine(ans);
        }
    }
}

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

int	sum_digits(int num)
{
	int	sum = 0;
	while (num > 0) {
		sum += num % 10;
		num /= 10;
	}
	return sum;
}

int	main()
{
	int	N;
	cin >> N;
	int	min_sum = 100;
	int	cur_sum;
	for (int a = 1; a < N; ++a) {
		cur_sum = sum_digits(a) + sum_digits(N - a);
		if (cur_sum < min_sum) min_sum = cur_sum;
	}
	cout << min_sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define exrep(i, a, b) for(long long i = a; i <= b; i++)
#define rep(i,n)for(long long i=0;i<(long long)(n);i++)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
const ll MOD=1e9+7;
const ll INF=1e18;
const int MAX=510000;
const double pi=acos(-1);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
ll modpow(ll a, ll n){
  if(n==0)return 1;
  if(n%2==0){
    ll t=modpow(a,n/2);
    return t*t%MOD;
  }
  return a*modpow(a,n-1)%MOD;
}
ll modinv(ll a){
  return modpow(a,MOD-2);
}
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;
}
struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
 
    UnionFind(int n = 1) {
        init(n);
    }
 
    void init(int n = 1) {
        par.resize(n); rank.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0;
    }
 
    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }
 
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
 
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        return true;
    }
};
vvl G;
ll dfs(int v){
  ll res=1;
  for(auto nv:G[v]){
    res+=dfs(nv);
  }
  return res;
}
    
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
  COMinit();
  
  ll n;
  cin >> n;
  
  ll m=-1;
  exrep(i,1,n){
    if(i*(i+1)/2==n){
      m=i;
    }
  }
  if(m==-1){
    cout << "No" << endl;
    return 0;
  }
  
  vvl ans(m+1);
  ll j=1,idx1=0,idx2=1;
  for(ll i=m;i>=1;i--){
    for(ll k=0;k<i;j++,k++){
      ans[idx1].push_back(j);
      ans[idx2].push_back(j);
      idx2++;
    }
    idx1++;
    idx2=idx1+1;
  }
  
  cout << "Yes" << endl;
  cout << m+1 << endl;
  rep(i,m+1){
    cout << ans[i].size();
    for(auto j:ans[i])cout << " "<<j;
    cout << endl;
  }
  return 0;
    
  
    
  
}


Measured memory_bytes: 15232
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static String Y = "Yes";
	public static String N = "No";
	public static long MOD = (long) (Math.pow(10, 9) + 7);
	public static Scanner sc = new Scanner(System.in);

	public static void main(String[] args) {

		int num = 1;
		for (int i = 1; i <= 365; i++) {

			out(26);
			//			if (num == 27) {
			//				num = 1;
			//			}
		}

	}

	/*
	 * 以下メソッド集
	 */
	static int[] sort(int[] n) {
		Arrays.sort(n);
		return n;
	}

	static void debug() {
		out("---");
	}

	static void debug(long a) {
		out("-------");
		out(a);
		out("-------");
	}

	static void debug(String a) {
		out("-------");
		out(a);
		out("-------");
	}

	static long[] sort(long[] n) {
		Arrays.sort(n);
		return n;
	}

	static int ketasuu(int n) {
		String str = "" + n;
		return str.length();
	}

	static int account(String str) {
		String target = "AC";
		int count = 0;
		int len = str.length();
		for (int i = 0; i < len - 1; i++) {
			if (target.equals(str.substring(i, i + target.length()))) {
				count++;
			}
		}
		return count;
	}

	static int ni() {
		return sc.nextInt();
	}

	static long nl() {
		return sc.nextLong();
	}

	static double nd() {
		return sc.nextDouble();
	}

	static String n() {
		return sc.next();
	}

	static char[] nc() {
		return sc.next().toCharArray();
	}

	static int kaijo(int n) {
		if (n == 0 || n == 1) {
			return 1;
		} else {
			return n * kaijo(n - 1);
		}
	}

	static int fib(int n) {
		return (n == 1 || n == 0) ? n : fib(n - 2) + fib(n - 1);
	}

	static long lcm(long m, long n) {

		return m * n / gcd(m, n);
	}

	static int lcm(int m, int n) {

		return m * n / gcd(m, n);
	}

	static long gcd(long a, long b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static int gcd(int a, int b) {
		return (b == 0) ? a : gcd(b, a % b);
	}

	static void out(String info) {
		System.out.println(info);
	}

	static void out(int info) {
		System.out.println(info);
	}

	static void out(double info) {
		System.out.println(info);
	}

	static void out(long info) {
		System.out.println(info);
	}

	static void out(char info) {
		System.out.println(info);
	}

	static void out(Object obj) {
		System.out.println(obj.toString());
	}

	static void outn(String info) {
		System.out.print(info);
	}

	static void outn(int info) {
		System.out.print(info);
	}

	static void outn(double info) {
		System.out.print(info);
	}

	static void outn(long info) {
		System.out.print(info);
	}

	static void outn(char info) {
		System.out.print(info);
	}

	static double max(double d, double e) {
		return Math.max(d, e);
	}

	static long max(long a, long b) {
		return Math.max(a, b);
	}

	static long min(long d, long e) {
		return Math.min(d, e);
	}

	static int min(int a, int b) {
		return (int) Math.min(a, b);
	}
}

class XY {
	int h;
	int c;

	XY(int h, int c) {
		this.h = h;
		this.c = c;
	}
}


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

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

  if(S=="000"){
    cout << 0 << endl;
  }
  else if(S=="111"){
    cout << 3 << endl;
  }
  else if(S=="011" || S=="101" ||S=="110"){
    cout << 2 << endl;
  }
  else{
    cout << 1 << endl;
  }

return 0;  
}

Measured memory_bytes: 256
//      https://www.youtube.com/watch?v=RBtlPT23PTM

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

typedef long long ll;
typedef long double ld;
typedef long long unsigned llu;
typedef pair<long long, long long> pll;
const long long inf = 2000000000000000000LL;    // 2e18
#define pi                  acos(-1.0)
#define fast                ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define nl                  "\n"
#define ff                  first
#define ss                  second
#define pb                  push_back
#define pf                  push_front
#define all(x)              x.begin(),x.end()
#define debug(x)            cout<<"debug "<<x<<"\n"

int main()
{
    fast;
    ll t,i,j,k,l,m,n,o,p,q,temp,ans=0,flag=0,mod=1000000007;
    cin>>n;
    ll a[n];
    for(temp=0,i=0;i<n;i++){
        cin>>a[i];
        temp^=a[i];
    }
    for(i=0;i<n;i++){
        cout<<(temp^a[i])<<" ";
    }
}


Measured memory_bytes: 5184
program ABC172C
    implicit none
    integer(8)::i,j
    integer(8)::N,M,K,best0,ans=0
    integer(8),allocatable,dimension(:)::A,B,As,Bs
    read*,N,M,K
    allocate(A(N))
    allocate(As(N+1))
    allocate(B(M))
    allocate(Bs(M+1))
    read*,A,B
    As(1)=0
    Bs(1)=0
    do i=2,N+1
        As(i)=As(i-1)+A(i-1)
    end do

    do i=2,M+1
        Bs(i)=Bs(i-1)+B(i-1)
    end do

    best0=M+1

    do i=1,N+1
        if(As(i)>K)exit
        do j=best0,1,-1
            if(Bs(j)<=K-As(i))then
                best0=j
                ans=max(ans,i+j-2)
                exit
            end if
        end do
    end do
    print'(i0)',ans
end program ABC172C

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

using namespace std;

vector<double>v;

bool visited[3009][3009];
double DP[3009][3009];

double Coins(int i,int coroa){
	if(i==v.size()){
		return 1;
	}
	
	double valor = 0;
	
	if(visited[i][coroa] == true){
		return DP[i][coroa];
	}
	
	visited[i][coroa] = true;
	
	valor += Coins(i+1,coroa) * v[i];
	
	if(coroa < (v.size()/2)){
		valor += Coins(i+1,coroa+1) * (1-v[i]);
	}

	return DP[i][coroa] = valor;
}

int main(){
	int N;
	double x;
	
	cin >> N;
	
	for(int i=0;i<N;i++){
		cin >> x;
		v.push_back(x);
	} 
	
	x = Coins(0,0);
	
	cout << fixed << setprecision(10) << x << endl;

	return 0;
}

Measured memory_bytes: 78464
#include <bits/stdc++.h>
#define dbgi(x) cout << #x << " = " << (x) << "\n";
#define dbgvi(x) cout << #x << " = "; for(int i = 0; i < (x.size()); ++i) cout << x[i] << " ";
#define mrk() cout << "HERE\n"
#define int long long
#define vi vector < int >
#define vs vector < string >
#define vii vector < vi >
#define viii vector < vii >
#define viiii vector < viii >
#define pii pair < int, int >
#define vpii vector < pii >
#define foru(i, a, b) for(int i = a; i < b; ++i)
#define ford(i, b, a) for(int i = b; i > a; --i)
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ld long double
using namespace std;

vi add1, add2;

const int inf = (int)1e15;


void addc(int c, int l, int r){
    if(l > r)return;
    add1[l] += c;
    add1[r + 1] -= c;
}

void addp(int s, int d, int l, int r){
    if(l > r)return;
    if(l == r){
        addc(s, l, r);
        return;
    }
    add1[l] += s;
    add2[l + 1] += d;
    add2[r + 1] -= d;
    add1[r + 1] += -(s + d * (r - l));
}





signed main(){
    int n, m;
    cin >> n >> m;
    vi a(n);
    foru(i, 0, n){
        cin >> a[i];
        a[i]--;
    }
    vpii e(n - 1);
    foru(i, 0, n - 1){
        e[i] = {a[i], a[i + 1]};
    }
    add1.resize(m + 1); // add constant
    add2.resize(m + 1); // add progression
    foru(i, 0, n - 1){
        int f = e[i].first;
        int s = e[i].second;
        if(f < s){
            int d = s - f;
            addc(d, 0, f);
            addc(d, s + 1, m - 1);
            addp(d, -1, f + 1, s);
        } else {
            int d = m - f + s;
            addp(d, -1, f + 1, m - 1);
            addc(d, s + 1, f);
            addp(s + 1, -1, 0, s);
        }
    }
    int cur = 0;
    foru(i, 0, m){
        cur += add2[i];
        add1[i] += cur;
    }
    vi ans(m);
    cur = 0;
    int res = inf;
    foru(i, 0, m){
        cur += add1[i];
        ans[i] = cur;
        res = min(res, ans[i]);
    }
    cout << res;
}


Measured memory_bytes: 4992
#include <iostream>
#include <assert.h>
#include <vector>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    //对岛屿1-n都打上false的标记
    //对vis的前n+1个元素都初始化为false
    vector <bool> vis(n+1,false);
    bool ans = false;
    for(int i = 0;i<m;i++){
        int a,b;
        cin>>a>>b;
        //assert(1<=a && a<b &&b<=n);
        if(a == 1){
            if(vis[b]){
                ans = true;
                break;
            }
            vis[b] = true;
        }
        if(b == n){
            if(vis[a]){
                ans = true;
                break;
            }
            vis[a] = true;
        }
    }
    if(ans) cout <<"POSSIBLE"<<endl;
    else cout<<"IMPOSSIBLE"<<endl;
    return 0;
}

Measured memory_bytes: 256
######################################################
############Created by Devesh Kumar###################
#############devesh1102@gmail.com####################
##########For CodeForces(Devesh1102)#################
#####################2020#############################
######################################################
import sys
input = sys.stdin.readline

# import sys
import heapq 
import copy
import math
import decimal
# import sys.stdout.flush as flush
# from decimal import *
#heapq.heapify(li) 
#
#heapq.heappush(li,4) 
#
#heapq.heappop(li)
#
# &	Bitwise AND Operator	10 & 7 = 2
# |	Bitwise OR Operator	10 | 7 = 15
# ^	Bitwise XOR Operator	10 ^ 7 = 13

# <<	Bitwise Left Shift operator	10<<2 = 40
# >>	Bitwise Right Shift Operator
# '''############ ---- Input Functions ---- #######Start#####'''


def inp():
	return(int(input()))
def inlt(): 
	return(list(map(int,input().split())))
def insr():
	s = input()
	return(list(s[:len(s) - 1]))
def insr2():
	s = input()
	return((s[:len(s) - 1]))
def invr():
	return(map(int,input().split()))
############ ---- Input Functions ---- #######End
# #####   

def pr_list(a):
	print(*a, sep=" ")
def main():
	# tests =  inp()
	tests = 1
	mod = 1000000007
	limit = 10**18
	ans = 0
	start = {}
	def pre_sum(arr):
		ans = [arr[0]]
		for i in range(1,len(arr)):
			ans.append(ans[-1]+ arr[i])
		return ans
	for test in range(tests):
		n = inp()
		branch = {}

		# parent = [0 for i in range(n+1)]
		for i in range(n-1):
			[p,r] =  inlt()
			if p in branch:
				branch[p].append(r)
			else:
				branch[p] = [r]
			if r in branch:
				branch[r].append(p)
			else:
				branch[r] = [p]
		parent = [-1 for i in range(n+1)]
		# print(branch)
		# print(parent)
		# print(branch)

		dp = [[0 for j in range(n+1)] for i in range(2)]
		leaf = {}
		ans = 2
		stack = [1]
		parent[1] = 0
		if n == 1:
			print(2)
			continue
		while(stack!=[]):
			# print(stack)
			curr = stack[-1]
			flag = 0
			for i in branch[curr]:
				if parent[i] == -1:
					parent[i] = curr
					stack.append(i)
					flag = 1
			if flag == 0:
				curr= stack.pop()
				white = 1
				black = 1
				for i in branch[curr]:
					if i !=parent[curr]:
						white = (white*(dp[0][i] + dp[1][i]))%mod
						black = (black*(dp[0][i]))%mod
				dp[0][curr] = white
				dp[1][curr] = black

		print((dp[0][1] + dp[1][1])%mod) 


		# for i in range(1,n+1):
		# 	if i not in branch:
		# 		leaf[i] = 1
		# 		dp[0][i] =1
		# 		dp[1][i] =1
		# # print(leaf)
		# while(leaf!={}):
		# 	nexts = {}
		# 	for i in leaf:
		# 		nexts[parent[i]] = 1
		# 	# print(nexts)
		# 	if 0 in nexts:
		# 		del nexts[0]
		# 	for i in nexts:
		# 		white = 1
		# 		black = 1
				
		# 		for j in branch[i]:
		# 			white = white*(dp[0][j] + dp[1][j])
		# 			black = black * dp[1][j]##1 is white
		# 		dp[0][i] = black
		# 		dp[1][i] = white
		# 		ans= max(ans, dp[0][i]+dp[1][i])
		# 	leaf = nexts
		# print(ans)




		


if __name__== "__main__":
	main()

Measured memory_bytes: 41752
import java.util.Scanner;

public class Main{
    public static void main(String[]arg){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        for(int i=1;i<=x;i++){
            int n=i;
            if(n%3==0){
                System.out.printf(" %d",i);
            }else 
                while(n!=0){
                    if(n%10==3){
                        System.out.printf(" %d",i);
                        break;
                     }
                    n/=10;
                 } 
            }
        System.out.print("\n");
    }
}


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

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

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

using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  int a, b, c;
  cin >> a >> b >> c;

  int abc_max = max(a, max(b, c));
  int diffs = 0;
  diffs += abc_max - a;
  diffs += abc_max - b;
  diffs += abc_max - c;

  if (diffs % 2 == 0) {
    cout << (diffs / 2) << "\n";
  } else {
    cout << (diffs / 2 + 2) << "\n";
  }
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(){
  int x[5];
 
  for(int i = 0; i<5; i++)
    scanf("%d", &x[i]);
  
  for(int i = 0; i<5; i++){
    if(x[i]==0){
      printf("%d\n", i+1);
    }
  }
  return 0;
}

Measured memory_bytes: 1724
import sys, math
import collections
input = sys.stdin.readline

N, = list(map(int, input().split()))
X = list(map(int, input().split()))

p = sum(X) / N

def f(p):
	s = 0
	for x in X:
		s += (x - p)**2
	return s

s = min(f(math.floor(p)), f(math.ceil(p)))
print(s)


Measured memory_bytes: 3316
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader in = new BufferedReader(isr);
		Main me = new Main();
		System.out.println(me.fact(Integer.parseInt(in.readLine())));
	}
	private long fact(long n){
		if(n==1)
			return 1;
		else
			return n*fact(n-1);
	}
}

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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF (long long)(1e18)
#define MOD (int)(1e9+7)

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

signed main(){
	cout<<fixed<<setprecision(7);
	
	string s;
	int a,b;
	
	cin>>s;
	
	for(int i = 0; i < s.size(); i++){//cout<<i<<" "<<s[i]<<endl;
		if(s[i] == 'A'){
			a = i;
			break;
		}
	}
	for(int i = 0; i < s.size(); i++){
		if(s[s.size()-i-1] == 'Z'){
			b = s.size()-i-1;
			break;
		}
	}
	// cout<<b<<" "<<a<<endl;
	cout<<b-a+1<<endl;
	
	return 0;
}

Measured memory_bytes: 640