akhauriyash/Code-Regression huggingface dataset:
n=int(input())
s=input()

rlis=[]
glis=[]
blis=[]
for i in range(len(s)):
    if s[i]=="R":
        rlis.append(i)
    if s[i]=="G":
        glis.append(i)
    if s[i]=="B":
        blis.append(i)
import bisect
ans=0

lis1=rlis
lis2=glis
lis3=blis

for j in lis1:
    maxi = bisect.bisect_left(lis2,j)
    mink = bisect.bisect_right(lis3,j)

    tmp=maxi*(len(lis3)-mink)
    for i in lis2:
        if i>=j:
            break
        tj=j+1
        ti=i+1
        badk=tj+tj-ti
        badk-=1

        ind1=bisect.bisect_left(lis3,badk)
        ind2=bisect.bisect_right(lis3,badk)
        if ind1!=ind2:
            tmp-=1
    ans+=tmp

    lis2,lis3=lis3,lis2
    maxi = bisect.bisect_left(lis2,j)
    mink = bisect.bisect_right(lis3,j)
    tmp=maxi*(len(lis3)-mink)
    for i in lis2:
        if i>=j:
            break
        tj=j+1
        ti=i+1
        badk=tj+tj-ti
        badk-=1

        ind1=bisect.bisect_left(lis3,badk)
        ind2=bisect.bisect_right(lis3,badk)
        if ind1!=ind2:
            tmp-=1
    ans+=tmp


lis1=glis
lis2=blis
lis3=rlis
for j in lis1:
    maxi = bisect.bisect_left(lis2,j)
    mink = bisect.bisect_right(lis3,j)

    tmp=maxi*(len(lis3)-mink)
    for i in lis2:
        if i>=j:
            break
        tj=j+1
        ti=i+1
        badk=tj+tj-ti
        badk-=1

        ind1=bisect.bisect_left(lis3,badk)
        ind2=bisect.bisect_right(lis3,badk)
        if ind1!=ind2:
            tmp-=1
    ans+=tmp

    lis2,lis3=lis3,lis2
    maxi = bisect.bisect_left(lis2,j)
    mink = bisect.bisect_right(lis3,j)
    tmp=maxi*(len(lis3)-mink)
    for i in lis2:
        if i>=j:
            break
        tj=j+1
        ti=i+1
        badk=tj+tj-ti
        badk-=1

        ind1=bisect.bisect_left(lis3,badk)
        ind2=bisect.bisect_right(lis3,badk)
        if ind1!=ind2:
            tmp-=1
    ans+=tmp

lis1=blis
lis2=rlis
lis3=glis
for j in lis1:
    maxi = bisect.bisect_left(lis2,j)
    mink = bisect.bisect_right(lis3,j)

    tmp=maxi*(len(lis3)-mink)
    for i in lis2:
        if i>=j:
            break
        tj=j+1
        ti=i+1
        badk=tj+tj-ti
        badk-=1

        ind1=bisect.bisect_left(lis3,badk)
        ind2=bisect.bisect_right(lis3,badk)
        if ind1!=ind2:
            tmp-=1
    ans+=tmp

    lis2,lis3=lis3,lis2
    maxi = bisect.bisect_left(lis2,j)
    mink = bisect.bisect_right(lis3,j)
    tmp=maxi*(len(lis3)-mink)
    for i in lis2:
        if i>=j:
            break
        tj=j+1
        ti=i+1
        badk=tj+tj-ti
        badk-=1

        ind1=bisect.bisect_left(lis3,badk)
        ind2=bisect.bisect_right(lis3,badk)
        if ind1!=ind2:
            tmp-=1
    ans+=tmp

print(ans)



Measured memory_bytes: 71260
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>
#include <cassert>
#include <cstdint>

using namespace std;

using VI = vector<int>;
using VVI = vector<VI>;

const int inf = 1e9;

int D;
VI c;
VVI s;

uint32_t xor64(void) {
	static uint64_t x = 88172645463325252ULL;
	x = x ^ (x << 13); x = x ^ (x >> 7);
	return x = x ^ (x << 17);
}

int calc_score(const VI &t) {
	// VI scores(D, 0);
	VI lastday(26, 0);

	int score = 0;
	for (int i = 0; i < D; i++) {
		int day = i + 1;
		int contest = t[i] - 1;
		lastday[contest] = day;
		score += s[i][contest];

		for (int j = 0; j < 26; j++) {
			score -= c[j] * (day - lastday[j]);
		}
		// scores[i] = score;
	}

	// return scores;
	return score;
}

VI solve_simple() {
	VI t(D, 1);

	return t;

}

VI solve2() {
	VI t(D, 0);
	for (int i = 0; i < D; i++) {
		t[i] = i % 26 + 1;
	}
	// return t;

	int score1 = calc_score(t);
	// cout << score1 << endl;
	for (int i = 0; i < 400000; i++) {
		int x = xor64() % D;
		int y = xor64() % D;

		if (t[x] == t[y]) {
			continue;
		}

		swap(t[x], t[y]);

		int score2 = calc_score(t);
		if (score2 > score1) {
			score1 = score2;
		} else {
			// 戻す
			swap(t[x], t[y]);
		}
	}

	assert(t.size() == D);
	for (auto x: t) {
		assert(1 <= x && x <= 26);
	}

	// cout << score1 << endl;
	return t;
}

int main() {
	cin >> D;

	c.assign(26, 0);
	for (int i = 0; i < c.size(); i++) {
		cin >> c[i];
	}
	s.assign(D, VI(26, 0));
	for (int i = 0; i < D; i++) {
		for (int j = 0; j < s[i].size(); j++) {
			cin >> s[i][j];
		}
	}

	VI t = solve2();

	for (auto x: t) {
		cout << x << endl;
	}

	return 0;
}


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

int N;
int A[210];        

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

    int res = 0;

    
    while (true) {
        bool exist_odd = false; 
        for (int i = 0; i < N; ++i) {
            if (A[i] % 2 != 0) exist_odd = true;  
        }

        if (exist_odd) break;  

        
        for (int i = 0; i < N; ++i) {
            A[i] /= 2;
        }
        ++res; 
    }

    cout << res << endl;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define pii pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< pii >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define in(x, a, b) ((a) <= (x) && (x) < (b))
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

using Weight = int;
using Flow = int;
struct Edge {
    int s, d; Weight w; Flow c;
    Edge() {};
    Edge(int s, int d, Weight w = 1) : s(s), d(d), w(w), c(w) {};
};
bool operator<(const Edge &e1, const Edge &e2) { return e1.w < e2.w; }
bool operator>(const Edge &e1, const Edge &e2) { return e2 < e1; }
inline ostream &operator<<(ostream &os, const Edge &e) { return (os << '(' << e.s << ", " << e.d << ", " << e.w << ')'); }

using Edges = vector<Edge>;
using Graph = vector<Edges>;
using Array = vector<Weight>;
using Matrix = vector<Array>;

void addArc(Graph &g, int s, int d, Weight w = 1) {
    g[s].emplace_back(s, d, w);
}
void addEdge(Graph &g, int a, int b, Weight w = 1) {
    addArc(g, a, b, w);
    addArc(g, b, a, w);
}

void solve(Graph &g, vi &ans, int p)
{
    for (auto i : g[p]) {
        if (!ans[i.d]) {
            ans[i.d] = (i.w % 2 ? -ans[p] : ans[p]);
            solve(g, ans, i.d);
        }
    }
}

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

    Int(n);
    Graph g(n);
    for (int i = 1; i < n; i++) {
        int3(tmpx, tmpy, tmp);
        tmpx--; tmpy--;
        addEdge(g, tmpx, tmpy, tmp);
    }

    vi ans(n, 0);
    ans[0] = 1;
    solve(g, ans, 0);
    rep(i, ans.size()) {
        std::cout << (ans[i] == -1 ? 0 : 1) << std::endl;
    }

    return 0;
}


Measured memory_bytes: 12928
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 12 + 5, mod = 1e9 + 7;

int a[N];
vector< pair<int, int> > v[N];
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int n;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        for(int j = 0; j < a[i]; j++){
            int x, y;
            cin >> x >> y;
            x--;
            v[i].push_back({x, y});
        }
    }
    int ans = 0;
    for(int i = 0; i < (1 << n); i++){
        bool found = 0;
        for(int j = 0; j < n; j++){
            if((i >> j & 1) == 0) continue;
            for(auto k: v[j]){
                if(k.second != (i >> k.first & 1)) found = 1;
            }
            if(found) break;
        }
        if(!found)  ans = max(ans, __builtin_popcount(i));
    }
    cout << ans;


    return 0;
}


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

int main(){
    ll N; 
    string S;
    ll ans = 0;
    cin >> N >> S;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                char d1 = i+48, d2 = j+48, d3 = k+48;
                auto pos1 = S.find(d1);
                if(pos1 != string::npos){
                    auto pos2 = S.find(d2, pos1+1);
                    if(pos2 != string::npos){
                        auto pos3 = S.find(d3, pos2+1);
                        if(pos3 != string::npos) {
                            ans++;
                        }
                    }

                }
            }
        }
    }
    cout << ans << endl;
}

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

int main() {
    int n, k, q;
    cin >> n >> k >> q;
    int a[110000];
    for(int i = 0; i < q; ++i) cin >> a[i];
    
    int score[110000];
    int num[110000] = {0};
    for(int i = 0; i < q; ++i) {
        ++num[a[i]-1];
    }
    for(int i = 0; i < n; ++i){
        score[i] = (k - q) + num[i];
        if(score[i] > 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}


Measured memory_bytes: 1408
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  long long N;
  scanf("%lld", &N);
  std::vector<long long> a(N);
  for (int i = 0; i < N; i++)
  {
    scanf("%lld", &a[i]);
  }
  ll cnt = 0;
  ll num = 1;
  for (int i = 0; i < N; ++i)
  {
    if (num == a[i])
      num++;
    else
      cnt++;
  }
  if (num == 1)
    cout << -1 << endl;
  else
    cout << cnt << endl;

  return 0;
}


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

n=int(input())
dic=[]
for i in range(n):
    dic.append(sorted(list(input().rstrip())))
dic=sorted(dic)

from math import factorial

ans=0
temp=1
for i in range(1,n):
    if dic[i]==dic[i-1]:
        temp+=1
    else:
        if temp>=2:
            ans+=(factorial(temp)//(2*factorial(temp-2)))
        temp=1

if temp>=2:
    ans+=(factorial(temp)//(2*factorial(temp-2)))

print(ans)

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

using namespace std;

bool isfilled(int mas[20][20], int n)
{
  for(int i = 0; i < n; i++){
    for(int j = 0; j < n; j++){
      if(mas[i][j] == 0) return false;
    }
  }
  return true;
}

void magic(int mas[20][20], int n, int y, int x, int m)
{
  if(isfilled(mas, n)) return;
  if(x < 0 || n <= x || y < 0 || n <= y){
    if(x < 0) x = n-1;
    if(n <= x) x = 0;
    if(y < 0) y = n-1;
    if(n <= y) y = 0;
    magic(mas, n, y, x, m);
  } else if(mas[y][x] != 0){
    magic(mas, n, y+1, x-1, m);
  } else {
    mas[y][x] = m;
    magic(mas, n, y+1, x+1, m+1);
  }
  return;
}

int main()
{
  int n;
  while(cin >> n, n){
    int mas[20][20] = {{0}};
    magic(mas, n, (n-1)/2+1, (n-1)/2, 1);
    for(int i = 0; i < n; i++){
      for(int j = 0; j < n; j++) printf("%4d", mas[i][j]);
      puts("");
    }
  }
  
  return 0;
}

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

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

	int K;
	cin >> K;

	for (int i = 0; i < s.size(); i++) {
		if (s[i] > 'a' && 'z' + 1 - s[i] <= K) {
			while (s[i] <= 'z' && K > 0) {
				s[i]++;
				K--;
				if (s[i] == 'z' + 1) {
					s[i] = 'a';
					break;
				}
			}
		}
	}

	K %= 26;
	while (K > 0) {
		s.back()++;
		if (s.back() == 'z' + 1) s.back() = 'a';
		K--;
	}

	cout << s << endl;
}

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

int main()
{
  long x,i,sum,h,c;
  sum=0;
  h=0;
  cin >> x;  
  
  char s[x];
  for(i=0;i<x;i++)
  {
    cin >>s[i];
  }
  x=x-2;
  for(i=0;i<x;i++)
  {
    if(s[i]=='A')
      if(s[i+1]=='B')
        if(s[i+2]=='C')
        {
          sum=sum+1;
        }
    
  }
  cout << sum <<endl;
  
  return 0;
  
}


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int a,b,k; cin>>a>>b>>k;
	int ans=min(a,b);
	while(k){
		if(a%ans==0&&b%ans==0)--k;
		--ans;
	}
	cout<<++ans<<"\n"s;
}

Measured memory_bytes: 256
using System;
class AOJ
{

    public static void Main()
    {
        int a = int.Parse(Console.ReadLine());
        for (int i = 3; i <= a; i++)
        {
            int f = 0;
            if (i % 3 == 0)
                f = 1;
            int b = i;
            while (true)
            {
                int c = b % 10;
                if (c == 3)
                    f = 1;
                b /= 10;
                if (b == 0)
                    break;
            }
            if (f == 1)
                Console.Write(" {0}", i);
        }
        Console.WriteLine();
    }
}

Measured memory_bytes: 9168
#include"bits/stdc++.h"
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10); } } ___;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
    cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
    const char* comma = strchr(names + 1, ',');
    cerr.write(names, comma - names) << " : " << arg1 << "  ";
    __f(comma + 1, args...);
}

#define ll long long
#define pii pair<int,int>
#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ff first
#define ss second
#define endll '\n'
#define rep(i,n) for(int i=0;i++<n;)
#define scl(i) scanf("%lld",&i)
#define int long long int
#define all(n) n.begin(),n.end()
#define mem(n,i) memset(n,i,sizeof n)
#define em(a) emplace_back(a)
#define pb(a) push_back(a)
#define srep(vv,it) for(auto &it : vv)
#define prep(vv,it) for(auto it : vv)
//vector<vector<int>>arr(n + 5, vector<int>(m + 5,0));

typedef vector<int> vii;
typedef vector<string> vss;
/*

*/

int call(int n)
{
    vector<int>dd(n + 50, 0);
    dd[1] = 1;
    for (int i = 2; i * i <= n + 5; i++)
    {
        if (dd[i]) continue;
        for (int j = i + i; j <= n + 5; j += i)
        {
            if (!dd[j]) dd[j] = i;
        }
    }
    rep(i, n + 5) if (!dd[i]) dd[i] = i;
    int sum = 0;
    for (int i = 1; i <= n; i++)
    {
        int xx = i;
        int d = 1;
        while (xx > 1)
        {
            int yy = dd[xx];
            int ff = 0;
            while (xx % yy == 0) xx /= yy, ff++;
            d *= (ff + 1);
        }
        //cout << d << endll;
        sum += i * d;
    }
    return sum;
}

signed main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int a; cin >> a;
    cout << call(a) << endll;
}


Measured memory_bytes: 81308
N = int(input())
count = 0
Flag = False

for i in range(N):
    D1, D2 = map(int, input().split())
    if D1 == D2:
        count += 1
    else:
        count = 0
    if count == 3:
        Flag = True
        break

if Flag:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
import collections
n = int(input())
list_a = list(map(int, input().split(" ")))
count = collections.Counter(list_a)

count_even = 0
for key, value in sorted(count.items()):
  if value % 2 == 0:
    count_even += 1

if count_even % 2 == 1:
  print(len(count) - 1)
else:
  print(len(count))


Measured memory_bytes: 21460
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N, X = map(int, input().split())
x = [int(_) for _ in input().split(' ')]

dist = [abs(i - X) for i in x]

ans = dist[0]

for i in range(N-1):
    ans = gcd(ans, dist[i+1])

print(ans)

Measured memory_bytes: 14252
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair <int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ld, ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const char nl = '\n';

void solve() {
    int ara[5];
    for(int i = 0; i < 5; ++i){
        cin >> ara[i];
    }
    for(int i = 0; i < 5; ++i){
        if(ara[i] == 0){
            cout << i + 1 << nl;
            return;
        }
    }
}

int main() {
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 3608
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define mx 200
ll ar[mx+10];
ll br[mx+10];
ll mem[mx+10][100009];
ll n,w;

ll dp(ll ind,ll w){
    if(ind>n) return 0;
    else if(mem[ind][w]!=-1) return mem[ind][w];

    ll x=0,y=0;
    if(w-ar[ind]>=0)
        x=br[ind]+dp(ind+1,w-ar[ind]);
    y=dp(ind+1,w);
    mem[ind][w]=max(x,y);
    return mem[ind][w];
}

int main()
{
    memset(mem,-1,sizeof(mem));
    cin>>n>>w;
    for(ll i=1;i<=n;i++){
        cin>>ar[i]>>br[i];
    }
    cout<<dp(1,w)<<endl;
    return 0;
}


Measured memory_bytes: 167628
module Main where
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.List
import qualified Text.Printf
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BC

import qualified Data.Map as Map
import           Data.Map (Map)

------------------------------------------

main :: IO ()
main = do
    n <- readInt
    xs <- replicateM n readInt
    print $ length . filter odd . map length . group . sort $ xs

------------------------------------------

{- Int input -}

parseInt :: BC.ByteString -> Int
parseInt = fst . fromJust . BC.readInt

parseInts :: BC.ByteString -> [Int]
parseInts = map parseInt <$> BC.words

readInt :: IO Int
readInt = parseInt <$> BC.getLine

readInts :: IO [Int]
readInts = parseInts <$> BC.getLine

{- Double Formatting -}

doubleFmt :: Double -> String
doubleFmt = Text.Printf.printf "%.12f"


Measured memory_bytes: 30972
#include<bits/stdc++.h>
#define MAX_N 100001
#define INF_INT 2147483647
#define INF_LL 9223372036854775807
#define REP(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
void init(int n);
int find(int n);
void unite(int x,int y);
bool same(int x, int y);
ll bpow(ll,ll,ll);
typedef vector<int> vec;
typedef vector<vec> mat;
mat mul(mat &A,mat &B);
mat pow(mat A,ll n);
int dx[3] = {1,0,-1};
int dy[3] = {1,0,-1};
const int MOD = 1000000007;

bool cmp_P(const P &a,const P &b){
  return a.second < b.second;
}
int main()
{
  string A,B;
  cin >> A >> B;
  for(int i=0;i<A.size();i++){
    cout << A[i];
    if(i < B.size())
      cout << B[i];
  }
  cout << endl;
  
  return 0;
}

int par[MAX_N];
int ranks[MAX_N];

//n要素で初期化
void init(int n){
  REP(i,n){
    par[i] = i;
    ranks[i] = 0;
  }

}

//木の根を求める
int find(int x){
  if(par[x] == x){
    return x;
  }else{
    return par[x] = find(par[x]);
  }
}

void unite(int x,int y){
  x = find(x);
  y = find(y);
  if(x == y) return ;
  if(ranks[x] < ranks[y]){
    par[x] = y;
  }else{
    par[y] = x;
    if(ranks[x] == ranks[y]) ranks[x]++;
  }
}

bool same(int x, int y){
  return find(x) == find(y);
}

ll bpow(ll a, ll n,ll mod){
  int i = 0;
  ll res=1;
  while(n){
    if(n & 1)
      res = (res*a) % mod;
    a = (a*a) % mod;
    n >>= 1;
  }
  return res;
}
mat mul(mat &A, mat &B){
  mat C(A.size(),vec(B[0].size()));
    REP(i,A.size())REP(k,B.size())REP(j,B[0].size()){
    C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % MOD;
  }
  return C;
}

mat pow(mat A,ll n)
{
  mat B(A.size(),vec(A.size()));
  REP(i,A.size()){
    B[i][i] = 1;
  }
  while(n > 0){
    if ( n & 1) B = mul(B,A);
    A = mul(A,A);
    n >>= 1;
  }
  return B;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int a, b, ans;
    cin>>a>>b;
    ans = a*b - ( a + b) + 1;
    cout<<ans<<endl;
    return 0;

}



Measured memory_bytes: 256
import java.util.*;

class Main
{
    public static void main(String[] args) {
        
        Scanner sc = new Scanner(System.in);
        
        long a = sc.nextInt();
        long b = sc.nextInt();
        long c = sc.nextInt();
        long d = sc.nextInt();
        
        long[] array = new long[4];
        
        array[0] = a * d;
        array[1] = b * c;
        array[2] = a * c;
        array[3] = b * d;
        
        long max = array[0];
        for (int i = 0; i < array.length ; i++) {
            if (max < array[i]) {
                max = array[i];
            }
        }
        
        System.out.println(max);
                
    }
}

Measured memory_bytes: 35780
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
#include <bitset>
#include <unordered_map>
#include <queue>
#include <cstring>
#include <cmath>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, s, n) for (int i = (int)(s); i < (int)(n); i++)
#define MOD 1000000007

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

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

ll combination(int parent, int choice){
    if( choice == 0 ){
        return 1;
    }

    ll ans = 1;

    repn(i,1,choice+1){
        ans *= parent + 1 - i;
        ans /= i;
    }

    return ans;
} 

bool check(string target, int num){
    rep(i,target.length()){
        if( num == 0 ) return true;
        if( target.at(i) - '0' > 0 ){
            num--;
        }
    }
    return (num == 0);
}

long long solve(string target, int depth){
    ll ans = ( check(target, depth + 1) )? 1 : 0;

    int length = target.length();
    rep(i,length){
        if( depth < 0 ) break;
        int target_decimal = target.at(i) - '0';
        if( target_decimal > 0 ){
            target_decimal--;
            ans += target_decimal * combination(length - i - 1, depth) * pow(9, depth);
            repn(j,i+1,length){
                ans += 9 * combination(length - j - 1, depth) * pow(9, depth);
            }
            depth--;
        }
    }

    return ans;
}

int main(){
    string s;
    int k;
    cin >> s >> k;
    cout << solve(s, k-1) << endl;

}

Measured memory_bytes: 256
K = int(input())

if K%7 == 0:
  L = 9*K/7
else:
  L = 9*K
s = 1

for i in range(1, 9*(10**6)+1):
  s = s*10%L
  if s == 1:
    print(i)
    exit()

print("-1")

Measured memory_bytes: 9100
def gcm(a,b):
    if a < b:
        a,b = b,a
    while True:
        if a % b == 0:
            return b
        else:
            a,b = b,a % b

def lcm(a,b):
    g = gcm(a,b)
    return a*b//g;

A,B = map(int,input().split())
print(lcm(A,B))

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#define int long long
#define pb emplace_back
#define mp make_pair
#define tci(v,i) for(auto i=v.begin();i!=v.end();i++)
#define all(v) v.begin(),v.end()
#define rep(i,start,lim) for(long long (i)=(start);i<(lim);i++)
#define boost ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define osit ostream_iterator<int> output (cout," ")
#define pv(x) copy(all(x),output)
#define pa(a) rep(i,0,sizeof(a)/sizeof(a[0]))cout<<a[i]<<" "
#define endl '\n'
#define f first
#define s second
#define PI 3.141592653589793
#define set0(x) memset(x,0,sizeof(x))
#define sort_uniq(c) (sort(c.begin(), c.end()), c.resize(distance(c.begin(), unique(c.begin(), c.end()))))
#define uniq(a) a.resize(distance(a.begin(), unique(a.begin(), a.end())))
#define dg(x) cout<<#x<<':'<<x<<endl;
#define dg2(x,y) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<endl;
#define dg3(x,y,z) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<endl;
#define dg4(x,y,z,zz) cout<<#x<<':'<<x<<' '<<#y<<':'<<y<<' '<<#z<<':'<<z<<' '<<#zz<<':'<<zz<<endl;
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
template<typename T> T gcd(T a,T b){if(a==0) return b; return gcd(b%a,a);}
int isPowerof2(int x) { return (x && !(x & x-1)); }

int32_t main(){
    boost;
    int r;
    cin>>r;
    double ans=2*PI*r;
    cout<<fixed<<setprecision(10)<<ans; 
    return 0;
}


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

typedef long long lint;
typedef long double ldouble;
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())

const int IINF = 1e9 + 10;
const lint LLINF = 1e18;
const lint MOD = 1e9 + 7;
const lint inv = MOD - 2;

int main(){
    int n;
    cin >> n;
    vector<int> a(n), b(n), c(n);
    rep(i, n){
        cin >> a[i];
    }
    rep(i, n){
        cin >> b[i];
    }
    rep(i, n){
        cin >> c[i];
    }
    SORT(a);
    SORT(b);
    SORT(c);
    b.push_back(IINF);
    c.push_back(IINF);
    vector<lint> v(n);
    rep(i, n){
        v[i] = c.end() - upper_bound(c.begin(), c.end(), b[i]) - 1;
    }
    repr(i, n-1){
        v[i] += v[i+1];
    }
    lint ans = 0;
    rep(i, n){
        ans += v[upper_bound(b.begin(), b.end(), a[i]) - b.begin()];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2160
#include "bits/stdc++.h"
using namespace std;

#define pb push_back
#define mp make_pair
#define fst first
#define snd second

#define fr(i,n) 	for(int i=0;i<n;i++)
#define frr(i,n)	for(int i=1;i<=n;i++)

#define ms(x,i)	memset(x,i,sizeof(x))
#define dbg(x)	cout << #x << " = " << x << endl
#define all(x)	x.begin(),x.end()

#define gnl cout << endl
#define olar cout << "olar" << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef pair<ll,ll> pll;

const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f;
const int MOD = 1e9+7;

int main(){

	fastio;
	ll n,k;

	cin >> n >> k;
	vector<pll> v;

	ll sum = 0ll;
	ll ans;
	fr(i,n){
		ll a;
		ll b;
		cin >> a >> b;

		v.pb(mp(a,b));
	}

	sort(all(v));

	fr(i,n){
		sum += v[i].snd;

		if(sum >= k){
			ans = v[i].fst;
			break;
		}
	}

	cout << ans << endl;

}


Measured memory_bytes: 2420
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		boolean flag = S.equals(T.substring(0,T.length() - 1)) && S.length() == T.length() - 1;
		System.out.println(flag?"Yes":"No");
		sc.close();
	}
}

Measured memory_bytes: 35680
#include<bits/stdc++.h>
using ll  = long long;
#define int ll
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define erep(e,v) for(auto && e :v)
#define all(in) in.begin(), in.end()
#define MP make_pair
#define INF (sizeof(int) == 4 ? (int)1e9:(int)1e18)
#define EPS 0.0000000001
using namespace std;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<typename Head, typename Value> auto vectors(const Head &head, const Value &v) { return vector<Value>(head, v); }
template<typename Head, typename... Tail> auto vectors(Head x, Tail... tail) { auto inner = vectors(tail...); return vector<decltype(inner)>(x, inner); }
template<class T> void join(T a){for(auto itr :a){if(itr != *a.begin())cout << " "; cout << itr;} }
using ld  = long double;
using pii = pair<int,int>;
using piii = pair<int,pii>;
int W,H;
int dx[]={0,0,1,-1}, dy[]={1,-1,0,0};
bool valid(int x,int y){return (0<=x&&x<W)&&(0<=y&&y<H);}
template<class T, class Func = function<T(T, T)>>
class segtree {
    vector<T> obj;
    int offset;
    Func updater;
    T e;
    int bufsize(int num) {
        int i = 1;
        for (; num + 1 >i; i <<= 1);
        offset = i - 1;
        return (i << 1) - 1;
    }
    T query(int a, int b, int k, int l, int r) {
        if (r <= a || b <= l)return e;
        if (a <= l && r <= b)return obj[k];
        else return updater(query(a, b, k * 2 + 1, l, (l + r) / 2), query(a, b, k * 2 + 2, (l + r) / 2, r));
    }
public:
    T query(int a, int b) {//[a,b)
        return query(a, b, 0, 0, offset + 1);
    }
    void updateall(int l = 0, int r = -1) {
        if (r < 0)r = offset + 1;
        l += offset, r += offset;
        do {
            l = (l - 1) >> 1, r = (r - 1) >> 1;
            for (int i = l; i < r; i++)obj[i] = updater(obj[i * 2 + 1], obj[i * 2 + 2]);
        } while (l);
    }
    void update(int k, T &a) {
        k += offset;
        obj[k] = a;
        while (k) {
            k = (k - 1) >> 1;
            obj[k] = updater(obj[k * 2 + 1], obj[k * 2 + 2]);
        }
    }
    segtree(int n, T e, const Func &updater = Func()) :obj(bufsize(n), e), e(e), updater(updater) {}
    segtree(vector<T> &vec, T e, const Func &updater = Func()) :obj(bufsize(vec.size()), e), e(e), updater(updater) {
        copy(vec.begin(), vec.end(), obj.begin() + offset);
        updateall();
    }
    typename vector<T>::reference operator[](int n) {
        return obj[n + offset];
    }
};

signed main(){
    int n,k; cin >> n >> k;
    vector<int>v(n);
    erep(e,v) cin >> e;
    vector<int>dif(n);
    rep(i,n - 1)dif[i] = abs(v[i+1] - v[i]);
    segtree<int>sgt(dif,0LL,[](auto a,auto b){
        return a + b;
    });
    int ans = INF;
    rep(i,n - k + 1){
        int mini = min(abs(v[i]),abs(v[i + k - 1]));
        mini += sgt.query(i,i+k-1);
        cmin(ans, mini);
    }
    cout << (ans) << endl;
}




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

using namespace std;
#define mod 1000000007
#define int long long
#define mxn 500005
int fact[mxn];
int inv[mxn];
int mul(int a, int b)
{
    return a*b%mod;
}
int mypower(int a, int b)
{
    int ans = 1;
    while(b)
    {
        if(b%2)
            ans = mul(ans, a);
        b=b/2;
        a=mul(a,a);
    }
    return ans;
}
void pre()
{
    fact[0] = 1;
    int i;
    for(i=1;i<mxn;i++)
        fact[i] = mul(fact[i-1], i);
    inv[mxn-1] = mypower(fact[mxn-1], mod-2);    
    for(i=mxn-2;i>=0;i--)
        inv[i] = mul(inv[i+1], i+1);
}
int nCr(int n, int r)
{
    if(n < 0 || r < 0 || n < r)
        return 0;
    return mul(fact[n], mul(inv[r], inv[n-r]));    
}
signed main() {
    pre();
    int n, m;
    cin >> n >> m;
    int i;
    int ans = 0;
    for(i=0;i<=n;i++)
    {
        int val = mul(nCr(m-i, n-i), fact[n-i]);
        val = mul(val, val);
        val = mul(val, fact[i]);
        val = mul(val, nCr(n, i));
        val = mul(val, nCr(m, i));
        ans = (ans + val*(i%2 == 0 ? 1 : -1))%mod;
    }
    cout << (ans+mod)%mod;
}

Measured memory_bytes: 11408
//----------------------------おまじない
#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")
//----------------------------
#define FOR(i,j,n) for (int i=(j);i<(n);i++)
#define REP(i,n) for (int i=0;i<(n);i++)
#define REPN(i,n) for (int i=(n);i>=0;i--)
#define I(n) scanf("%d", &(n))
#define LL(n) scanf("%lld", &(n))
#define pb(n) push_back((n))
#define mp(i,j) make_pair((i),(j))
#include <bits/stdc++.h>
using namespace std;

//------------------------------typedef集
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef vector<vvi> vvvi;
typedef long long ll;

#define MAX 300
struct node {
    int v, d;
    node(int v, int d):v(v),d(d){}
    bool operator<(const node &n) const { return d > n.d; }
};
struct edge { int to, d; edge(int ti, int di){to = ti; d = di;} };
int V;
vector<edge> G[MAX];
int dist[MAX];
int a,b,c,n,m,r,towndist[10][MAX];
vi town;

void dijkstra(int s) {
    REP(i,MAX) dist[i] = -1;
    priority_queue<node> que;
    que.push(node(s, 0));
    while(!que.empty()){
        int v = que.top().v, d = que.top().d;
        que.pop();
        if(dist[v] >= 0 and dist[v] <= d) continue;
        dist[v] = d;
        for(auto j : G[v])
            que.push(node(j.to, d+j.d));
    }
}

int main(){
    I(n); I(m); I(r);
    town.resize(r);
    REP(i,r) I(town[i]);

    REP(i,m){
        I(a); I(b); I(c);
        G[a].pb(edge(b,c));
        G[b].pb(edge(a,c));
    }
    REP(i,r){
        dijkstra(town[i]);
        memcpy(towndist[i],dist,sizeof(dist));
    }
    int ret = INT_MAX;
    vi perm(r);
    iota(perm.begin(), perm.end(), 0);
    do {
        int tmp = 0;
        REP(i,r-1){
            tmp += towndist[perm[i]][town[perm[i+1]]];
        }
        ret = min(ret,tmp);
    } while (next_permutation(perm.begin(), perm.end()));
    cout << ret << endl;
}


Measured memory_bytes: 1572
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

bool prime(int n) {
    if (n < 2) return false;
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) return false;
    }
    return true;
}

int main() {
    int X; cin >> X;
    while (1) {
        if (prime(X)) break;
        X++;
    }
    cout << X << endl;
    return 0;
}

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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecbool vector<bool>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll nw=0, count=0, guard;
  string s;
  cin >> s;
  forll(i, 0, s.size()){
	if (s[i] == 'W')
	  nw++;
  }
  guard = nw;
  forll(i, 0, nw){
	if(s[i] == 'B'){
	  forll(j, guard, s.size()){
		if (s[j] == 'W'){
		  guard = j + 1;
		  count += j - i;
		  break;
		}
	  }
	}  
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define ARR(array) for(int i=0;i<array.size();i++)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

ll input(){
  ll a;
  cin >> a;
  return a;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll ans=0;
    REP(i,s.size())if(s[i]=='x')ans++;
    cout << (ans<8?"YES":"NO") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long d[100005];
int n,m;
bool vis[100005],use[100005];

vector<int>v[100005];
vector<int>e[100005];

void read(int& x)
{
    char c=getchar();
    x=0;
    while(c<'0'||c>'9')c=getchar();
    while(c>='0'&&c<='9')
    {
        x=x*10+c-'0';
        c=getchar();
    }
}

bool dfs(int fa)
{
    vis[fa]=1;
    use[fa]=1;
    
    for(int i=0;i<v[fa].size();i++)
    {
        int y=v[fa][i];
        int z=e[fa][i];
        if(d[y]>d[fa]+z)
        {
            if(vis[y])return 1;
            d[y]=d[fa]+z;
            if(dfs(y))return 1;
        }
    }
    vis[fa]=0;
    return 0;
}

int main()
{
    read(n);
    read(m);
    
    for(int i=1;i<=n;i++)
    {
        d[i]=200000000000ll;
    }
    
    for(int i=1;i<=m;i++)
    {
        int x,y,z;
        read(x);
        read(y);
        read(z);
        v[x].push_back(y);
        e[x].push_back(z);
        v[y].push_back(x);
        e[y].push_back(-z);
    }
    
    bool ok=0;
    
    for(int i=1;i<=n;i++)
    {
        if(!use[i])
        {
            d[i]=0;
            if(dfs(i))
            {
                ok=1;
            }
        }
    }
    
    if(ok)printf("No\n");
    else printf("Yes\n");
    return 0;
}

Measured memory_bytes: 17024
#include<bits/stdc++.h>
#define rep(i, x, n) for(int i = x; i < n; i++)
#define repr(i, x, n) for(int i = x; i > n; i--)
#define pii pair<int,int>
#define ll long long
const long long iinf = 1e18;
const int inf = 1e9;
const int MOD = (1e6+3);
int dir4[4][2] = {{1,0},{-1,0},{0,1},{0,-1}};
int knight[8][2] = {{2,1},{2,-1},{-2,1},{-2,-1},{1,2},{-1,2},{1,-2},{-1,-2}};

using namespace std;

void solve()
{
    int n; cin >> n;
    if(n%1000 == 0) cout << 0 ;
    else cout << 1000 - n%1000;
    
}
//new line is printed in main()

int main()
{
    int t = 1;
        // cin >> t; // comment out if no test case is required
    int i = 1;
    while(t--){
        //cout << "Case " << i++ << ": ";
        solve();
        // printf("\n");
    }
    return 0;
}


Measured memory_bytes: 3592
r,c=map(int,input().split())
s=[]
t=[]
for i in range(r):
    s.append(list(map(int,input().split())))
    s[i].append(sum(s[i]))
for j in range(c+1):
    u = 0
    for k in range(r):
        u += s[k][j]
    t.append(u)
    s.append(t)
for i in range(r+1):
    w = str(s[i][0])
    for j in range(1,c+1):
        w += " "+str(s[i][j])
    print(w)



Measured memory_bytes: 5692
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=(1e6)+10;
const ll mod=(1e9)+7;
int n;
ll jc[maxn],ivjc[maxn],iv[maxn],ans;
ll c(ll a,ll b) {
	if (a<b) return 0;
	ll res=jc[a]*ivjc[b]%mod*ivjc[a-b]%mod;
	return res;
}
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%d",&n);
	jc[0]=ivjc[0]=1;
	for (int i=1;i<=n;i++) {
		jc[i]=jc[i-1]*i%mod;
		iv[i]=(mod-iv[mod%i]*(mod/i)%mod)%mod;
		if (i==1) iv[1]=1;
		ivjc[i]=ivjc[i-1]*iv[i]%mod;
	}
	ll lst=0;
	for (int s=max(1,n/2-1);s<n;s++) {
		ll tmp=jc[s]*jc[n-s-1]%mod*c(s-1,n-s-1)%mod;
		ans+=((tmp-lst+mod)%mod)*s%mod;
		lst=tmp;
		ans%=mod;
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 23680
module vector_int32_mod
    use,intrinsic :: iso_fortran_env
    type vector
        integer(int64),pointer:: array(:) =>null()
        integer(int64):: l
    contains
        procedure :: push_back => vector_regist
    end type

    interface vector
        module procedure vector_init
    end interface
    private
    public:: vector
contains
    function vector_init() result(vec)
        type(vector):: vec
        allocate(vec%array(1))
        vec%l = 0
    end function

    subroutine vector_regist(vec, v)
        class(vector):: vec
        integer(int64):: v

        if (vec%l+1 > size(vec%array)) call add_(vec)
        vec%l=vec%l+1
        vec%array(vec%l) = v
    end subroutine


    subroutine add_(vec)
        type(vector):: vec
        integer(int64),pointer:: tmp(:) => null()
        integer(int64):: l

        tmp => vec%array
        l = size(vec%array)
        vec%array => null()
        allocate(vec%array(l*2))
        vec%array(1:l) = tmp(:)
        deallocate(tmp)
    end subroutine
end module

program main
    use,intrinsic :: iso_fortran_env
    use vector_int32_mod
    implicit none
    integer(int64):: n,q,k,i
    integer(int64), allocatable:: a(:), b(:), c(:), x(:), y(:)
    integer(int64), allocatable:: k_dist(:)
    type(vector), allocatable:: to(:), d(:)
    
    read*, n
    allocate(a(n-1), b(n-1), c(n-1))
    allocate(to(n), d(n))
    allocate(k_dist(0:n))

    do i=1,n
        to(i) = vector()
        d(i) = vector()
    end do
    
    do i=1,n-1
        read*, a(i), b(i), c(i)
        call to(a(i))%push_back(b(i))
        call to(b(i))%push_back(a(i))
        call d(a(i))%push_back(c(i))
        call d(b(i))%push_back(c(i))
    end do

    read*, q,k
    allocate(x(q), y(q))
    k_dist(0)=0_8
    call dfs(k,0_8,0_8)

    do i=1,q
        read*, x(i), y(i)
    end do

    do i=1,q
        print'(i0)', k_dist(x(i)) + k_dist(y(i))
    end do
contains
    recursive subroutine dfs(self, from, distance)
        integer(int64), intent(in):: self, from, distance
        integer(int64):: i, next, next_d

        k_dist(self) = k_dist(from)+distance

        do i=1,to(self)%l
            next = to(self)%array(i)
            next_d = d(self)%array(i)
            if (next == from) cycle
            call dfs(next, self,next_d)
        end do
    end subroutine
end program main

Measured memory_bytes: 37124
using System;
using System.Linq;

namespace Nikkei2019_C
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());

            var AB = new Model[N];
            for (long i = 0; i < N; i++)
            {
                var ab = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
                AB[i] = (new Model() { i = i, A = ab[0], B = ab[1], AB = ab[0] + ab[1] });
            }

            AB = AB.OrderByDescending(x => x.AB).ToArray();

            long taksum = 0;
            long aoksum = 0;
            for (long i = 0; i < N; i++)
            {
                if (i % 2 == 0)
                {
                    taksum += AB[i].A;
                }
                else
                {
                    aoksum += AB[i].B;
                }
            }
            Console.WriteLine(taksum - aoksum);
        }
        public class Model
        {
            public long i { get; set; }
            public long A { get; set; }
            public long B { get; set; }
            public long AB { get; set; }
        }
    }
}


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

int main(){

    string s;
    cin>>s;
    int y=stoi(s.substr(0,4)),m=stoi(s.substr(5,2));
    if(y*12+m>24232) cout<<"TBD"<<endl;
    else cout<<"Heisei"<<endl;

    return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 2e6 + 5;

ll fac[maxn], ifac[maxn], inv[maxn];

ll nck(ll n, ll k) {
    if (n<k) return 0;
    return fac[n]*ifac[k]%mod*ifac[n-k]%mod;
}

void gen_inv() {
    fac[0]=inv[0]=ifac[0]=1;
    fac[1]=inv[1]=ifac[1]=1;

    for (int i=2; i<maxn; i++) {
	fac[i]=fac[i-1]*i%mod;
	inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	ifac[i]=ifac[i-1]*inv[i]%mod;
    }

    assert(nck(4,2)==6);
}

ll pw(ll x, ll y) {
    ll res=1;
    while (y) {
	if (y%2) res=res*x%mod;
	x=x*x%mod;y=y/2;
    }
    return ((res%mod)+mod)%mod;
}



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

    char c; cin>>c;
  if (c>='A' && c<='Z') out("A");
  out("a");
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

ll table[ll(2*1e5)+10];

struct Point {
    int s,t,c;
    Point(int s_=0, int t_=0, int c_=0) :
        s(s_), t(t_), c(c_){}
    // より小さいcが前へ，cが同じならsでソート
    bool operator<(const Point &p) const{
      return (c<p.c)?1:c==p.c&&s<p.s;
    }
    bool operator==(const Point &p) const{
      return s==p.s&&t==p.t&&c==p.c;
    }
};

int main(){
  ll n,c;cin>>n>>c;
  vector<Point> v(n);
    
  ll S,T,C;
  ll max_t=0;
  rep(i,n){
    cin>>S>>T>>C;
    max_t=max(T,max_t);
    v[i]=Point(S,T,C);
  }
  sort(all(v));
  // 前後をつなぐ
  ll k=v.size();
  rep(i,k-1){
    if(v[i].c==v[i+1].c){
      if(v[i+1].s>=v[i].s&&v[i+1].s<=v[i].t){
        v[i+1].s=v[i].s;
        if(v[i+1].t>=v[i].t){
          v[i].t=v[i+1].t;
        }
      }
      if(v[i]==v[i+1]){
        v[i].s=0;
        v[i].t=0;
        v[i].c=0;
      }
    }
  }

  rep(i,v.size()){
    if(v[i].c!=0){
      table[2*v[i].s-1]++;
      table[2*v[i].t]--;
    }
  }

  rep(i,2*max_t+5){
    table[i+1]=table[i+1]+table[i];
  }

  ll ans=0;
  rep(i,2*max_t+5){
    ans=max(ans,table[i]);
  }
  cout<<ans<<endl;
  return 0;
}

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

int main() {
    map<int, int> m;
    m[1] = m[3] = m[5] = m[7] = m[8] = m[10] = m[12] = 0;
    m[4] = m[6] = m[9] = m[11] = 1;
    m[2] = 2;
    int x, y;
    cin >> x >> y;
    if(m[x] == m[y]) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}
  
int main() {
  int X;
  cin  >> X;
  int i = 0;
  while(X > 0) {
    i++;
    X -= i;
  }
  cout << i << endl;
  return 0;
}

Measured memory_bytes: 256