akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define endl '\n'
#define pb push_back

// debug 도구

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

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 += "}\n";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)

// debug 도구 end

using llong = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VPII = vector<pair<int, int>>;
using VLL = vector<long long>;
using PII = pair<int, int>;

int main() {
    int n, k;
    cin >> n >> k;
    int l;
    rep(i, 0, n) cin >> l;
    
    cout << 1 + (n - 2) / (k - 1);
    return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <math.h>
#include <regex>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1000000007;
const int INF = 1001001001;

int main(){
    ll n , k ; cin >> n >> k ;
    ll x = n%k;
    ll y = abs(x - k);
    cout << min(x,y) << endl;       
}


Measured memory_bytes: 256
//F5で実行 Shift+F5で停止
//F9でブレークポイント
#include<cmath>
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
//Ctrl+PageUpで上部の大半を選択できる
// 1e18 = 10の18乗

//atcoder 1秒は O(10^8)以上でTLE

//関数の中で宣言するとスタック領域に確保してしまい、
//スタックオーバーフローの恐れあり

string S;

void _main() {
	cin >> S;

	string ans = "";
	string x = "x";

	int Slen = S.length();

	rep(i, 0, Slen)
		ans += x;

	cout << ans <<  endl;
}

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

int main()
{
	int r, c;
	cin >> r >> c;
	vector<vector<int>>v(r + 1, vector<int>(c + 1, 0));
	for (int i = 0; i < r; i++)
	{
		for (int j = 0; j < c; j++)
		{
			cin >> v[i][j];
		}
	}

	for (int i = 0; i < r; i++)
	{

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

	}

	for (int i = 0; i < c + 1; i++)
	{
		for (int j = 0; j < r; j++)
		{
			v[r][i] += v[j][i];
		}

	}

	for (int i = 0; i < r + 1; i++)
	{
		for (int j = 0; j < c + 1; j++)
		{
			cout << v[i][j] ;
			if (j < c)
			{
				cout << " ";
			}
		}
		cout << endl;
	}


	return 0;
}


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

bool is_prime(int num) {
    if (num == 2) return true;
    if (num % 2 == 0) return false;
    for (int i = 3; i < (int)sqrt(num) + 1; i+=2) {
        if (num % i == 0) return false;
    }
    return true;
}

int main() {
    int x;
    cin >> x;
    int num = x;
    if (is_prime(num)) {
        cout << num << endl;
        return 0;
    }
    if (num % 2 == 0) num++;
    while (!is_prime(num)) num += 2;
    cout << num << endl;
    return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using P   = pair<ll, ll>;
using mat = vector<vector<ll>>;

void IOS() { ios::sync_with_stdio(false), cin.tie(0); }

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-10;

template <typename T> void dump(T x) { cout << x << endl; }
void dumpf(ld x, int t) { cout << setprecision(t) << fixed << x << endl; }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
	fill((T *)array, (T *)(array + N), val);
}

inline ll mod(ll a, ll b) {
	if (a > 0) return a % b;
	if (a % b == 0) return 0;
	ll x = -a / b + 1;
	a += x * b;
	return a % b;
}

// ll dx[4] = {1, 0, -1, 0};
// ll dy[4] = {0, 1, 0, -1};

vector<P> g[114514];
ll d[114514];

int main() {
	IOS();
	ll k;
	cin >> k;
	Fill(d, INF);
	for (int i = 0; i < k; i++) {
		g[i].push_back(P((i + 1) % k, 1));
		g[i].push_back(P((i * 10) % k, 0));
	}
	deque<P> que;
	d[1] = 0;
	que.push_back(P(1, 0));
	while (!que.empty()) {
		int a = que[0].first;
		int b = que[0].second;
		que.pop_front();
		for (int i = 0; i < g[i].size(); i++) {
			if (d[g[a][i].first] > g[a][i].second + b) {
				que.push_back(P(g[a][i].first, g[a][i].second + b));
				d[g[a][i].first] = g[a][i].second + b;
			} else if (d[g[a][i].first] > g[a][i].second + b) {
				que.push_front(P(g[a][i].first, g[a][i].second + b));
				d[g[a][i].first] = g[a][i].second + b;
			}
		}
	}
	dump(d[0] + 1);
}

Measured memory_bytes: 9344
#include<bits/stdc++.h> 
#define fo(i,a,b) for(i=a;i<=b;i++)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define min(a,b) (a<b?a:b)
#define max(a,b) (a>b?a:b)
typedef long long ll;
using namespace std;
const int mo=1e9+7;
inline int read(){
	int n=0,f=1;char c;
	for(c=getchar();(c<'0'||c>'9')&&c!='-';c=getchar());
	if (c=='-') c=getchar(),f=-1;
	for(;c>='0'&&c<='9';c=getchar()) n=n*10+c-48;
	return n*f;
}
int i,j,n,m,last;
struct ar{int a[3][3];}f,a,b,o;
ar operator *(ar a,ar b){
	ar c;memset(c.a,0,sizeof(c.a));
	int i,j,k;
	fo(i,0,2)
	fo(k,0,2){
		int aa=a.a[i][k];
		fo(j,0,2) (c.a[i][j]+=(ll)aa*b.a[k][j]%mo)%=mo;
	}return c;
}	
ar qs(ar x,int y){
	ar s=o;
	for(;y;y>>=1,x=x*x) if (y&1) s=s*x;
	return s;
}
int main(){
	n=read(),m=read();
	o.a[0][0]=o.a[1][1]=o.a[2][2]=1;
	fo(i,0,2) fo(j,i,2) b.a[i][j]=1;
	b.a[0][1]++;
	a=b;
	fo(i,0,2) a.a[i][0]++;
	f.a[0][0]=1;
	for(;m--;){
		int now=read();
		f=f*qs(a,now-1-last)*b;
		last=now;
	}
	f=f*qs(a,n-last);
	printf("%d\n",f.a[0][2]);
}

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

using namespace std;

#define int long long

const int MAX_N = 1e5 + 5;
const int MAX_L = 20; // ~ Log N
const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef unordered_map<int,int> mii;
typedef unordered_map<char,int> mci;
typedef unordered_map<string,int> msi;

#define pb push_back
#define f first
#define s second 
 

void solve() {
    int n;
    cin>>n;
    vi a(n),b(n),c(n);
    vvi dp(n,vi(3));
    for(int i=0;i<n;i++) {
        cin>>a[i]>>b[i]>>c[i];
    }
    dp[0][0] = a[0];
    dp[0][1] = b[0];
    dp[0][2] = c[0];


    for(int i=1;i<n;i++) {
        dp[i][0] = a[i] + max(dp[i-1][1],dp[i-1][2]);
        dp[i][1] = b[i] + max(dp[i-1][0],dp[i-1][2]);
        dp[i][2] = c[i] + max(dp[i-1][0],dp[i-1][1]);
    }
    int ans = INT_MIN;
    for(int i=0;i<3;i++) {
        ans = max(ans,dp[n-1][i]);
    }
    cout<<ans<<endl;

}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //#ifdef ONLINEJUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
    //#endif

    int tc; tc=1;
    for (int t = 1; t <= tc; t++) {
        //cout << "Case #" << t  << ": ";
        solve();
    }
}

Measured memory_bytes: 11128
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <set>
#include <array>
#include <stdio.h>
#include <string.h>
#include <random>
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define int long long
#define CONTAINS_VEC(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define ARY_REVERSE(v,a) (reverse((v), (v)+(a)))
#define REP(i, n) for (int (i)=0; (i) < (n); (i)++)
#define REPE(i, n) for (int (i)=0; (i) <= (n); (i)++)
#define CONTAINS_MAP(m, a) ((m).find((a)) != m.end())
#define CONTAINS_SET(m, a) ((m).find((a)) != m.end())
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void Yes() { cout << "Yes" << endl; }
void No() { cout << "No" << endl; }


signed main()
{
	int N;
	cin >> N;
	int a = sqrt(N);
	cout << a * a << endl;
}



Measured memory_bytes: 3632
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

typedef pair<int, int> pint;
typedef long long ll;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
}

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

    typedef double dd;

    int main(){
         ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int arr[n];

    rep(i,0,n){
        cin>>arr[i];
    }
    ll sum=0; int top =arr[0];
    rep(i,0,n){if(i==n-1) continue;
        if(arr[i+1]>=arr[i]){continue;}
        if(arr[i]>arr[i+1]){
            sum+=(arr[i]-arr[i+1]);
            arr[i+1]=arr[i];
        }
    }
       cout<<sum;

        return 0;
    }


Measured memory_bytes: 4304
x, y = map(int, input().split())

a = {1, 3, 5, 7, 8, 10, 12}
b = {4, 6, 9, 11}
c = {2}

if (x in a and y in a) or (x in b and y in b) or (x in c and y in c):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <string>
#include <utility>
#include <map>
#include <queue>
#include <list>
#include <functional>
#include <numeric>
#include <stack>
#include <tuple>

using namespace std;
int dx[4] = { -1,0,1,0 };
int dy[4] = { 0,1,0,-1 };
const int INF = 100000000;
const long long LINF = 1000000000000000000;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-6;
using pii = std::pair<int, int>;
using pLL = std::pair<long long, long long>;
using ll = long long;
#define SORT(v) std::sort(v.begin(), v.end())

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N,M;
	cin >> N >> M;
	if (N >= M) {
		cout << 0 << endl;
		return 0;
	}
	vector<int> x(M),y;
	for (int i = 0; i < M; ++i) {
		cin >> x[i];
	}
	int sum = 0;
	SORT(x);
	for (int i = 1; i <=M-1 ; ++i) {
		y.push_back(x[i] - x[i - 1]);
		sum += y[i - 1];
	}
	SORT(y);
	int count = 0;
	if (N - 1 == 0) {
		cout << sum << endl;
		return 0;
	}
	for (int i = M-2; i >=0; i--) {

		sum -= y[i];
		count++;
		if (count == N - 1) {
			cout << sum << endl;
			return 0;
		}
		
	}
	
	return 0;
}

Measured memory_bytes: 1276
var
	n,b,i:int64;
    a:Array[1..200000] of int64;
begin
	read(n);
    for i:=1 to n do begin
    	read(a[i]);
        b:=b xor a[i];
    end;
    for i:=1 to n do begin
    	writeln(b xor a[i]);
    end;
end.

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

int main()
{
 long long a;
	cin >> a;
	long long  b, i,j,k;
	b = 0 ;

	for (i = 1; i <= a; i++) {
		j = i % 3;
		if (j == 0) {
			b = b + 0;
		}
		else {
			j = i % 5;
			if (j == 0) {
				b = b + 0;
			}
			else {
				j = i % 15;
				if (j == 0) {
					b = b + 0;
				}
				else {
					k = i;
					b = b + k;
		
				}
			}
		}

	
	}
	cout << b;
}

Measured memory_bytes: 3128
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> ivec;
const ll N = 1e9+7;
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

int main(){
    int h,w; cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];

    int moved[h][w] = {};
    int count = 0;
    rep(i,h)rep(j,w) moved[i][j] = N;
    rep(i,h)rep(j,w) if(s[i][j] == '.')count++;
    queue<P> que;
    que.push(P(0,0));
    moved[0][0] = 0;
    int dis = 0;
    while(que.size()){
        P p = que.front();que.pop();
        int tx = p.first, ty = p.second;
        if(tx == h-1 && ty == w-1){
            dis = moved[tx][ty];
            break;
        }
        rep(i,4){
            int nx = tx + dx[i], ny = ty + dy[i];
            if(nx < h && 0 <= nx && ny < w && 0 <= ny && s[nx][ny] == '.' && moved[nx][ny] == N){
                moved[nx][ny] = moved[tx][ty] + 1;
                que.push(P(nx,ny));
            }
        }
    }
    int ans = 0;
    if(dis){
        ans = count - dis - 1;
    }
    else ans = -1;

    // cout << ans <<  ' ' << count << ' ' << dis << endl;

    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		ArrayList<Integer> all = new ArrayList<>(Arrays.asList(1,2,3));
		all.remove(all.indexOf(sc.nextInt()));
		all.remove(all.indexOf(sc.nextInt()));
		System.out.println(all.get(0));
	}
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> A(n, 0);
    REP(i, m){
        int a, b;
        cin >> a >> b;
        a--; b--;
        A[a]++; A[b]++;
    }
    REP(i, n){
        cout << A[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;

public static class P
{
    public static void Main()
    {
        var a = Console.ReadLine().Split().Select(int.Parse).First();
        var b = Console.ReadLine().Split().Select(int.Parse).First();

        Console.WriteLine(a != b ? 1 : 0);
    }
}

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

template<class T = int>
class UnionFind {
    public :
        vector<T> parent;  // 親のインデックス
        vector<T> height;  // 木の高さ
        vector<T> size;  // 木の頂点数
        T componentCount;  // 木の数

        UnionFind (T size_) {
            this->init(size_);
        }

        void init (T size_) {
            this->parent.resize(size_);
            this->size.assign(size_, 1);
            this->height.assign(size_, 1);
            this->componentCount = size_;
            for (T i = 0; i < size_; i++) {
                this->parent[i] = i;
            }
        }

        T root(T index) {
            if (index == this->parent[index]) {
                return index;
            }
            this->parent[index] = root(this->parent[index]);
            return this->parent[index];
        }

        // Union
        bool merge(T index1, T index2) {
            T root1 = this->root(index1);
            T root2 = this->root(index2);

            if (root1 == root2) {
                return false;
            }

            this->componentCount--;

            if (this->height[root1] < this->height[root2]) {
                this->parent[root1] = root2;
                this->size[root2] += this->size[root1];
            } else {
                this->parent[root2] = this->parent[root1];
                this->size[root1] += this->size[root2];
                if (this->height[root1] == this->height[root2]) {
                    this->height[root1]++;
                }
            }
            return true;
        }

        bool isSameRoot(T index1, T index2) {
            return this->root(index1) == this->root(index2);
        }

        T sizeOfSameRoot(T index) {
            return this->size[root(index)];
        }
};

#define FOR(i, n) for (long i = 0LL; i < (long)(n); i++)

int main(void) {
    int N, M;
    cin >> N >> M;

    vector<int> A(M), B(M);

    FOR(i, M) {
        cin >> A[i] >> B[i];
    }

    UnionFind<> tree(N);

    int ans = 0;
    FOR(i, M) {
        tree.init(N);
        FOR(j, M) {
            if (i == j) continue;
            tree.merge(A[j] - 1, B[j] - 1);
        }
        if (tree.componentCount > 1) ans++;
    }

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

Measured memory_bytes: 256
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        x: u16,
    }

    if x < 600 {
        println!("8");
    } else if x < 800 {
        println!("7");
    } else if x < 1000 {
        println!("6");
    } else if x < 1200 {
        println!("5");
    } else if x < 1400 {
        println!("4");
    } else if x < 1600 {
        println!("3");
    } else if x < 1800 {
        println!("2");
    } else if x < 2000 {
        println!("1");
    }
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define ld long double
#define mkp make_pair
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = (ll)1e9+7;
const ll INF = (ll)1e9+1;

int n;
int t[100001], x[100001], y[100001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
    //freopen("D.txt", "r", stdin);
    #endif
    cin >> n;
    int cx=0, cy=0, ct=0;
    for(int i=0; i<n; i++)
    {
        cin >> t[i] >> x[i] >> y[i];
        if(t[i]-ct<abs(x[i]-cx)+abs(y[i]-cy)||((t[i]-ct)+(abs(x[i]-cx)+abs(y[i]-cy)))%2==1)
        {
            puts("No");
            return 0;
        }
        ct = t[i]; cx = x[i]; cy = y[i];
    }
    puts("Yes");

}



Measured memory_bytes: 1408
/*
[arc102] E - Stop. Otherwise...
*/

#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int MAX_Z = 2000 * 2 + 2;
const ll MOD = 998244353;

int K, N;
int fact[MAX_Z + 1];
int ifac[MAX_Z + 1];
int pow2[MAX_Z + 1];

void prepare() {
    int inv[MAX_Z + 1];
    fact[1] = fact[0] = 1;
    ifac[1] = ifac[0] = 1;
    inv[1] = 1;
    for (int i = 2; i <= MAX_Z; i++) {
        fact[i] = 1LL * i * fact[i - 1] % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        ifac[i] = 1LL * ifac[i - 1] * inv[i] % MOD;
    }

    pow2[0] = 1;
    for (int i = 1; i <= MAX_Z; i++) {
        pow2[i] = (2LL * pow2[i - 1]) % MOD;
    }
}

int comb(int n, int r) {
    if (n < 0 || r < 0 || n < r) {
        return 0;
    }
    return (1LL * fact[n] * ifac[n - r]) % MOD * ifac[r] % MOD;
}
int hcomb(int n, int r) {
    if (n == 0 && r == 0) {
        return 1;
    }
    return comb(n + r - 1, r);
}

ll solve(int t) {
    ll ans = 0;

    int p = 0;
    for (int j = 1; j <= K; j++) {
        if (j < t - j && t - j <= K) p++;
    }

    for (int q = 0; q <= min(N, p); q++) {
        ll c = (1LL * pow2[q] * comb(p, q)) % MOD;
        if (t % 2 == 0) {
            (c *= ((hcomb(K - 2 * p + q - 1, N - q) +
                    hcomb(K - 2 * p + q - 1, N - q - 1)) %
                   MOD)) %= MOD;
        } else {
            (c *= hcomb(K - 2 * p + q, N - q)) %= MOD;
        }
        (ans += c) %= MOD;
    }

    return ans;
}

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

    prepare();

    for (int t = 2; t <= 2 * K; t++) {
        cout << solve(t) << endl;
    }

    return 0;
}


Measured memory_bytes: 384
def main():
    import sys
    input = sys.stdin.readline
    from itertools import accumulate

    def e(dice):
        ans = 0
        for r in range(1, dice+1):
            ans += r /dice
        return ans

    n, k = map(int, input().split())
    p = list(map(int, input().split()))

    p_cum = [0] + list(accumulate(p))

    ma = 0
    ind = 0
    for i in range(k, n+1):
        temp = p_cum[i] - p_cum[i-k]
        if ma < temp:
            ma = temp
            ind = i

    x = p[ind-k:ind]

    print(sum(e(d) for d in x))

if __name__ == '__main__':
    main()

Measured memory_bytes: 75408
import scala.io.StdIn._

object Main extends App {

  def bubbleSort(a: Array[Int], n: Int) {
    var cnt = 0
    for (i <- (1 to n-1)) {
      for (j <- (n-1 to i by -1)) {
        val x = a(j)
        if (a(j-1) > a(j)) {
          a(j) = a(j-1)
          a(j-1) = x
          cnt +=1
        }
      }
    }
    println(a.mkString(" "))
    println(cnt)    
  }
  
  val n = readLine.toInt
  val a: Array[Int] = readLine.split(" ")
                              .map(s => s.toInt)
                              .toArray
  bubbleSort(a, n)
}


Measured memory_bytes: 44100
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define lli long long int
#define vi vector<int>
#define vlli vector<lli>
#define vvi vector<vi >
#define str string
#define vs vector<str>
#define vb vector<bool>
#define slli set<lli>
#define mii map<int, int>
#define mlli map<int, lli>
#define msi map<str, int>
#define mp make_pair
#define pii pair<int, int>
#define pll pair<lli, lli>
#define vpii vector<pii >
#define vpll vector<pll >
#define pb push_back
#define loop(i, s, l, j) for(int i = s; i < l; i += j)
#define rloop(i, s, l, j) for(int i = s; i >= l; i -= j)
#define rep(i, n) loop(i,0,n,1)
#define rrep(i, n) rloop(i,n-1,0,1) 
#define fastio() ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ft first
#define sd second
#define all(a) a.begin(),a.end()
#define rev(a) reverse(all(a))
#define min3(a, b, c) min(a, min(b, c))
#define max3(a, b, c) max(a, max(b, c))
#define mod 1000000007
#define inf 100000000
#define limit 200005
#define minval -100000000000000000
#define maxval 1000000000000000
/**********************************************************************************************************************************************/
int dx4[4] = {0, -1, 0, 1};
int dy4[4] = {1, 0, -1, 0};
int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int Power(int base,int exp){int ans=1;  while(exp > 0){if(exp&1)ans=(1LL*ans*base)%mod; exp=exp>>1; base=(1LL*base*base)%mod;}  return ans;}
/**********************************************************************************************************************************************/ 
void input()
{
    int n;
    cin >> n;
    vi a(n);
    rep(i,n)
        cin >> a[i];
    
    int mx = a[0];
    lli ans = 0;
    rep(i,n)
    {
        if(a[i] < mx)
            ans += (mx-a[i]);
        mx = max(a[i], mx);
    }
    cout << ans << '\n';
}
int main()
{
   /*
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
   */
    fastio();
    int q = 1;
    //cin >> q;
    while(q--)
        input();
}


Measured memory_bytes: 3984
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<string>
#define ll long long
const int N=2e5+10;
using namespace std;
const int f[26] = {2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,0,7,7,8,8,8,9,9,9,0};                         //26个字母对应的数字
ll p[N];
map<ll,ll>m;
//p[i]+p[j]==j-i;(j>=i)
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i];
        m[i-p[i]]++;
    }
    ll sum=0;
    for(int i=1;i<=n;i++)
        sum+=m[i+p[i]];
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 27312
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int calc(vector<string> title, vector<int> time, string end)
{
    int sum;
    
    string ti;
    int tm;
    
    sum = 0;
    
    ti = title.back();
    title.pop_back();
    
    while(ti != end) {
        tm = time.back();
        time.pop_back();
        
        sum += tm;
        
        ti = title.back();
        title.pop_back();
    }
    
    return sum;
}

int main(void)
{
    int n;
    
    vector<string> title;
    vector<int> time;

    string ti;
    int tm;
    string end;

    int sum;

    cin >> n;

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

        title.push_back(ti);
        time.push_back(tm);
    }
    
    cin >> end;

    sum = calc(title, time, end);

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <iostream>
#include <string.h>
#include <algorithm>
#include <vector>
#include <queue>

using namespace std;
typedef long long ll;
const ll INF=100000000000000LL;

int main() {
	int n,m;
	cin>>n>>m;
	cout<<(n-1)*(m-1)<<endl;
		return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key

typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    ll h,w;
    cin>>h>>w;
    ll sa,sb,sc;
    ll ans=h*w;
    for(ll i=1;i<=h-2;i++){ // cut horizontally
        sa=i*w;
        ll k=(h-i)/2;
        sb=k*w;
        sc=(h-i-k)*w;
        ll s=max(max(sa,sb),sc)-min(min(sa,sb),sc);
        if(ans>s){
            ans=s;
        }
    }
    for(ll i=1;i<=h-1;i++){ // cut vertically
        sa=i*w;
        ll k=w/2;
        sb=k*(h-i);
        sc=(h-i)*(w-k);
        ll s=max(max(sa,sb),sc)-min(min(sa,sb),sc);
        if(ans>s){
            ans=s;
        }
    }
    swap(h,w);
    for(ll i=1;i<=h-2;i++){ // cut horizontally
        sa=i*w;
        ll k=(h-i)/2;
        sb=k*w;
        sc=(h-i-k)*w;
        ll s=max(max(sa,sb),sc)-min(min(sa,sb),sc);
        if(ans>s){
            ans=s;
        }
    }
    for(ll i=1;i<=h-1;i++){ // cut vertically
        sa=i*w;
        ll k=w/2;
        sb=k*(h-i);
        sc=(h-i)*(w-k);
        ll s=max(max(sa,sb),sc)-min(min(sa,sb),sc);
        if(ans>s){
            ans=s;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def is_triangle(x,y,z):
  return x+y>z and x!=y and y!=z and x!=z
N=int(input())
L=sorted(list(map(int,input().split())))
from itertools import combinations
print(len([(x,y,z) for (x,y,z) in combinations(L,3) if is_triangle(x,y,z)]))

Measured memory_bytes: 20464
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
typedef long long ll;

int n, x, y, res[2010];
int main(){
        scanf("%d%d%d", &n, &x, &y);
        for(int i=1; i<n; i++)
        for(int j=i+1; j<=n; j++){
              int dst = j-i;
              dst = min(dst, abs(i-x)+abs(j-y)+1);
              dst = min(dst, abs(j-x)+abs(i-y)+1);
              res[dst]++;
        }
        for(int i=1; i<n; i++)
            printf("%d\n", res[i]);

        return 0;

 }


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

I = input().split()
N = int(I[0])
M = int(I[1])

I = input().split()
Ai = [0] * M

sum = 0
for i in range(M):
    sum += int(I[i])

ans = N - sum

if ans < 0:
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9524
from collections import defaultdict
import heapq

N, M = map(int, input().split())
daily_jobs = defaultdict(list)

for _ in range(N):
    A, B = input().split()
    daily_jobs[A].append(-int(B))

ans = 0
now_cand = []
for i in range(1, M+1):
    for job in daily_jobs[str(i)]:
        heapq.heappush(now_cand, job)
    if now_cand:
        ans += heapq.heappop(now_cand)

print(-ans)


Measured memory_bytes: 29776
#include <iostream>
#include <cstdlib>
#include <algorithm>
using namespace std;

int main()
{
  int n=0;
  long long ans=0;
  cin >> n;
  long long int a[n], temp=0, b;
  for(int i=0;i<n;++i){
    cin >> a[i];
    a[i] = a[i] - (i+1);
    temp += a[n];
  }
  sort(a, a+n);
  if(n%2==0){
    b = (a[(n/2)-1]+a[(n/2)])/2;
    long long tmpans=0;
    for(int i=0;i<n;i++){
      tmpans+=abs(a[i]-b);
    }
    if(b<0) b--;
    else b++;
    for(int i=0;i<n;i++){
      ans+=abs(a[i]-b);
    }
    if(ans>tmpans) ans=tmpans;
  }else{
    b = a[int(n/2)];
    for(int i=0;i<n;++i){
      ans += abs(a[i]-b);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main(){
    int n,x,c;
        while(1){
        cin >> n >>x;
        if(n==0&&x==0) break;
        c = 0;
        for(int i=1;i<=n-2;i++){
            for(int j=i+1;j<=n-1;j++){
                for(int k=j+1;k<=n;k++){
                    if(i+j+k==x) c++;
                }
            }
        }
            cout << c <<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=5005;
ll a[N],dp[N][N];
inline void cmn(ll&a,ll b){if(a>b)a=b;}
int main()
{
	ll n,A,B,ans=1ll<<60;scanf("%lld%lld%lld",&n,&A,&B);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
	memset(dp,0x3f,sizeof(dp));dp[0][0]=0;
	for(int i=1;i<=n;i++)for(int j=0;j<=n;j++)if(a[i]>j)cmn(dp[i][j],dp[i-1][j]+A),cmn(dp[i][a[i]],dp[i-1][j]);else cmn(dp[i][j],dp[i-1][j]+B);
	for(int i=0;i<=n;i++)cmn(ans,dp[n][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 195968
#include <iostream>
#include <algorithm>
#define MAX_X 100
#define MAX_Y 100
using namespace std;

struct Point {
    int x, y, h;
};

int calc(Point p[], int n, int x, int y) {
    Point w = p[0];
    int h = w.h + abs(w.x - x) + abs(w.y - y);
    for (int i = 1; i < n; i++) {
        Point w = p[i];
        if (w.h != max(h - abs(w.x - x) - abs(w.y - y), 0))
            return 0;
    }
    return h;
}

int main() {
    int n;
    cin >> n;
    Point p[n];
    for (int left = 0, right = n - 1; left <= right;) {
        int x, y, h;
        cin >> x >> y >> h;
        if (h > 0) {
            p[left++]  = Point {x, y, h};
        } else {
            p[right--] = Point {x, y, h};
        }
    }
    for (int y = 0; y <= MAX_Y; y++) {
        for (int x = 0; x <= MAX_X; x++) {
            int height = calc(p, n, x, y);
            if (height > 0) {
                cout << x << ' ' << y << ' ' << height << endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int[] b = new int[a];
		int c = 0;
		for (int i = 0; i < a; i++) {
			b[i] = sc.nextInt();
		}
		for (int j = 0; j < 100; j++) {
			for (int s = 0; s < b.length; s++) {
				if (b[s] % 2 != 0) {
					c++;
					break;
				} else {
					b[s] = b[s] / 2;
				}
			}
			if (c != 0) {
				System.out.println(j);
				break;
			}
		}
	}
}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector< double > v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    sort(v.begin(), v.end());
    double ans = v[0];
    for (int i = 0; i < n; i++) {
        ans = (ans + v[i]) / 2;
    }
    cout << ans << endl;
    return 0;
}

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


def main():
    N = int(input())
    A = list(map(int, input().split()))

    A_sum = sum(A)
    tmp = 0

    result = []

    for a in A:
        tmp += a
        result.append(abs(A_sum - tmp * 2))
    print(min(result[:-1]))


if __name__ == "__main__":
    main()


Measured memory_bytes: 23800
/* ex 9_1
   yumizmiz */

#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 1000

//スタックの定義
typedef struct stack{
    int size;
    int count;
    char data[SIZE];
    char *top;
} stack;

//スタックの初期化
void initialize_stack(stack *stk){
    stk->count = 0;
    stk->size = SIZE;
    stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
    if(stk->count >= stk->size){
        fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
        exit(1);
    }
    else{
        stk->top--;
        *(stk->top) = elem;
        stk->count++;
    }
}

//データの取り出し
char pop(stack *stk){
    char latest;
    
    if(stk->count <= 0){
        fprintf(stdout, "Error: stack underflow.\n");
        exit(1);
    }
    else{
        latest = *(stk->top);
        stk->top++;
        stk->count--;
        return latest;
    }
}

int main(void){
    //スタック
    stack stk;
    initialize_stack(&stk);

    //入力文字列の配列（最大文字数10）
    char input[11], *ptr1;
    //出力文字列の配列（最大文字数10）
    char output[11], *ptr2;
    scanf("%s", input);

    ptr1 = input;
    while(*ptr1){
        //'B'だったらその前の文字を消す（取り出す）．消せる文字がなければ消さない
        if(*ptr1 == 'B'){
            if(stk.count>0)
                pop(&stk);
        }else{
            push(&stk, *ptr1);
        }
        ++ptr1;
    }
    //スタックを逆順に取り出す
    //文字数はstk.count
    ptr2 = &output[stk.count];
    //ヌル文字を入れて
    *ptr2 = '\0';
    //後ろから文字を入れていく
    while(stk.count>0){
        --ptr2;
        *ptr2 = pop(&stk);
    }
    printf("%s\n", output);
    return 0;
}

Measured memory_bytes: 1648
#include <complex>
#include <vector>
#include <cmath>
using namespace std;

const double EPS = 1e-8;
typedef complex<double> P;

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

struct L : public vector<P> {
  L(){}
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

bool intersectSP(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

bool intersectSS(const L &s, const L &t) {
  return ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
    ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0;
}

P projection(const L &l, const P &p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}

double distanceSP(const L &s, const P &p) {
  const P r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s[0] - p), abs(s[1] - p));
}

double distanceSS(const L &s, const L &t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t[0]), distanceSP(s, t[1])),
             min(distanceSP(t, s[0]), distanceSP(t, s[1])));
}

const double PI = 3.14159265358979323846264;

double deg2rad(double deg) {
  return deg*PI/180;
}

P rotate(P p, P c, double d) {
  return c+(p-c)*P(cos(d),sin(d));
}


#include <cstdio>

const int INF = 1000000000;
L star[100][5];
double d[100][100];

double diststar(int i,int j){
  double ans = 1000000;
  for (int ii=0; ii<5; ii++)
    for (int ji=0; ji<5; ji++)
      ans = min(ans,distanceSS(star[i][ii],star[j][ji]));
  return ans;
}

int main() {
  int n,m,l;
  while(scanf("%d %d %d",&n,&m,&l),n) {
    for(int i=0; i<n; i++) {
      double x,y,a,r;
      scanf("%lf %lf %lf %lf",&x,&y,&a,&r);
      P c(x,y),up(x,y+r);
      for (int j=0; j<5; j++) {
	P f = rotate(up,c,deg2rad(j*144+a));
	P t = rotate(up,c,deg2rad(((j+1)%5)*144+a));
	star[i][j] = L(f,t);
      }
    }

    for (int i=0; i<n; i++)
      for (int j=0; j<n; j++)
	d[i][j] = (i==j?0:diststar(i,j));

    for (int k=0; k<n; k++)
      for (int i=0; i<n; i++)
	for (int j=0; j<n; j++)
	  d[i][j] = min(d[i][j],d[i][k]+d[k][j]);

    printf("%.8f\n",d[m-1][l-1]);
  }
}

Measured memory_bytes: 1224
# coding: utf-8
# Your code here!
N=int(input())

l=[0]*3
ans=0
for i in range(N):
    S=(input())
    ans+=S.count("AB")
    if S[0]=="B" and S[-1]=="A":
        l[0]+=1
    elif S[0]=="B":
        l[1]+=1
    elif S[-1]=="A":
        l[2]+=1
if l[0]>0:
    ans+=(l[0]-1)
    if l[1]>0:
        l[1]-=1
        ans+=1
    if l[2]>0:
        l[2]-=1
        ans+=1
ans+=min(l[1],l[2])
    
#print(l)
print(ans)


Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#include <bits/stdc++.h>

using namespace std;

#define int long long
#define all(a) (a).begin(), (a).end()
#define sz(a) (int) (a).size()
#define x first
#define y second


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    int a, b, n;
    cin >> a >> b >> n;
    int ans = 0;
    if (a >= b) {
        for (int x = 0; x <= min(a * 100, n); x++) {
            ans = max(ans, (a * x) / b - a * (x / b));
        }
    } else {
        for (int x = min(b, n); x >= max(0ll, min(n, b) - 100000000ll); x--) {
            ans = max(ans, (a * x) / b - a * (x / b));
        }
    }
    cout << ans << "\n";


    return 0;
}

Measured memory_bytes: 3648
/*
反省点
modintなどの問題なのではないかということで難しく考えすぎた。
同じになる組みなんて計算量えぐくね？みたいなことだったが、よくよく考えてみれば
最小値と最大値がわかっているので計算するだけだったみたい。

似たような問題が出てきたとしても、先入観にとらわれずにしっかりとした方針を立てることが大切だなと感じた一問だった。
DPなんか使うわけないやんみたいな
*/

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; i++)

int main()
{
    ll n, k;
    cin >> n >> k;
    ll res = 0;

    vector<ll> sum(n + 1);
    rep(i, n + 1)
    {
        if (i == 0)
        {
            sum[i] = 0;
        }
        else
        {
            sum[i] += sum[i - 1] + i; //累積和を作成。
        }
    }
    ll count = 0;
    for (int i = k; i <= n + 1; i++) //k個選ぶとき
    {
        //値としての最小値から最大値まで取りうることができる。
        //sum[n] - sum[n - k];//値の最大値
        if (n - i < 0)
        {
            count += (sum[n] - sum[i - 1] + 1) % 1000000007;
        }
        else
        {
            count += (sum[n] - sum[n - i] - sum[i - 1] + 1) % 1000000007; //値の最小値は
        }
        count %= 1000000007;
    }

    cout << count;
}


Measured memory_bytes: 4744
def sol():
    h,w=map(int,input().split())
    c=[list(map(int,input().split())) for i in range(10)]
    a=[list(map(int,input().split())) for i in range(h)]
    for k in range(10):
        for i in range(10):
            for j in range(10):
                #if (c[i][k]!=0 and c[k][j]!=0): c[i][j]=min(c[i][j],c[i][k]+c[k][j])
                c[i][j]=min(c[i][j],c[i][k]+c[k][j])
    ans=0
    for i in range(h):
        for j in range(w):
            if a[i][j]==-1: pass
            else: ans+=c[a[i][j]][1]
    print(ans)

if __name__=="__main__":
    sol()


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

// long long int gcd(long long int x, long long int y){
// 	if(x%y==0){
// 		return y;
// 	}else{
// 		return gcd(y, x%y);
// 	}
// }
long long int gcd(long long int x, long long int y){
	return y ? gcd(y, x%y) : x;	
}

int main() {
	long long int a, b; cin >> a >> b;
	long long int g = gcd(a, b);
	long long int ans = 1LL;
	for(long long int i=2;i*i<=g;i++){
		if(g%i==0){
			ans++;
			while(g%i==0){
				g = g/i;
			}
		}
	}
	if(g!=1) ans++;
	cout << ans << endl;
	return 0;
}

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

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

    string sts;
    for(int i=0;i<s.length();i++){
        if(s[i] == 'B'){
            if(sts.length() > 0) sts.erase(--sts.end());
        }else{
            sts += s[i];
        }
    }
    cout << sts;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll n,i,j,k,l,a,b,c,d;
    string s1;
    cin>>n;
    c=0;
    for(i=1;i<=n;i++)
    {
        stringstream ss;
        ss<<i;
        ss>>s1;
        k=s1.size();
        if(k%2!=0){c++;}
    }
    cout<<c<<endl;
    return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))

b = []
ord = [-1 for x in range(n+1)]
c = 1
l = 1

v = 1
while(ord[v] == -1):
    ord[v] = len(b)
    b.append(v)
    v = a[v-1]
c = len(b) - ord[v]
l = ord[v]

if (k < l):
    print(b[k])
else:
    k -= l
    k %= c
    print(b[l+k])


Measured memory_bytes: 32400
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define enld '\n'
#define rep(i,n) for(int i=0; i<(n); i++)
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[6] = {1, 0, -1, 0,1,-1};
const int dy[6] = {0, 1, 0, -1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------


int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b;
    cin >> a >> b;
    if(a <= 9 and b <= 9){
        cout << a*b << endl;
    }else{
        cout << -1 << enld;
    }
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
import string
import sys
from itertools import chain, dropwhile, takewhile


def read(
    *shape, f=int, it=chain.from_iterable(sys.stdin), whitespaces=set(string.whitespace)
):
    def read_word():
        w = lambda c: c in whitespaces
        nw = lambda c: c not in whitespaces
        return f("".join(takewhile(nw, dropwhile(w, it))))

    if not shape:
        return read_word()
    elif len(shape) == 1:
        return [read_word() for _ in range(shape[0])]
    elif len(shape) == 2:
        return [[read_word() for _ in range(shape[1])] for _ in range(shape[0])]


def readi(*shape):
    return read(*shape)


def readi1(*shape):
    return [i - 1 for i in read(*shape)]


def readf(*shape):
    return read(*shape, f=float)


def reads(*shape):
    return read(*shape, f=str)


def arr(*shape, fill_value=0):
    if len(shape) == 1:
        return [fill_value] * shape[fill_value]
    elif len(shape) == 2:
        return [[fill_value] * shape[1] for _ in range(shape[0])]


def dbg(**kwargs):
    print(
        ", ".join("{} = {}".format(k, repr(v)) for k, v in kwargs.items()),
        file=sys.stderr,
    )


def main():
    while True:
        n, k = readi(2)
        if n == 0:
            return
        a = readi(n)
        tmp = sum(a[:k])
        ans = tmp
        for i in range(k, len(a)):
            tmp += a[i] - a[i - k]
            ans = max(ans, tmp)
        print(ans)


if __name__ == "__main__":
    main()



Measured memory_bytes: 10892
#include  <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 1000000007
//vector<vector<int>> vec(縦, vector<int>(横));
#define REP(i,N) for(int i=0;i<N;i++)
int gcd(int a, int b) {
    if(a>b){
        swap(a,b);
        }
    while(b%a!=0){
        b%=a;
        swap(a,b);
    }
    return a;
}


//cout << setprecision(123)<<ans;
//a=atoi(S.c_str());
//S=to_string(a);
int main(){
  ll N,co1=0,co2=0,co3,co4,ans;
  cin>>N;
  vector<ll>V(N);
  REP(i,N){
    cin>>V[i];
    co1+=V[i];
  }
  
  for(int i=0;i<N;i++){
    co2+=V[i];
    if(co2>co1/2){
      co3=co2-V[i];
      co4=co1-co2;
      if(co3==co4){
        ans=V[i];
        break;
      }
      
      else if(co3>co4){
        ans=abs((co3-co4)-V[i]);
        break;
      }
      else if(co3<co4){
        ans=abs((co4-co3)-V[i]);
        break;
      }
    }
  }
  
  
  
  cout<<ans<<endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using ll = long long;
#define REP(i,m,n) for(ll i = (ll)(m); i < (ll) (n) ;i++)
#define rep(i,n)  REP(i , 0 , n)
using namespace std;

ll l, r, tmp, s;
ll ans = 2018;


int main(){
	cin >> l >> r;
	s = r - l + 1;

	if (s >= 2019 || l == 0){
		cout << 0 << endl;
	}
	else{
		REP(i, l, r + 1){
			REP(j, l, r + 1){
				if (i != j){
					ans = min((i * j) % 2019, ans);
				}
			}
		}
		cout << ans << endl;
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip> //! for setprecision(10)
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
    
    string s, t;
    cin >> s  >> t;

    cout << (t+s) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    final Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        new Main().run();
    }

    private void run() {
        int a = sc.nextInt();
        int b = sc.nextInt();

        switch (a+b) {
            case 3:
                System.out.println(3);
                break;
            case 4:
                System.out.println(2);
                break;
            case 5:
                System.out.println(1);
                break;
        }
    }
}


Measured memory_bytes: 22604