akhauriyash/Code-Regression huggingface dataset:
sel=3
# ABC070-D
if sel==1:
    from collections import deque
    N=int(input())
    ver=[[] for i in range(N)] # (vertex,cost) in each vertex
    for _ in range(N-1):
        a,b,c=map(int,input().split())
    ver[a-1].append((b-1,c))
    ver[b-1].append((a-1,c))

    Q,K=map(int,input().split())

    par=[-2 for i in range(N)]
    par[K-1]=-1
    q=deque([K-1])
    while q:
        i=q.popleft()
        for j,c in ver[i]:
            if par[j]==-2:
                par[j]=i
                q.append(j)

    cost=[-1 for i in range(N)]
    cost[K-1]=0
    stack=[[K-1,0]]
    while stack:
        i,c=stack.pop()
        for j,d in ver[i]:
            if par[i]!=j:
                cost[j]=c+d
                stack.append([j,cost[j]])
    # print(cost)
    for _ in range(Q):
        x,y=map(int,input().split())
    print(cost[x-1]+cost[y-1])

  

# ABC079-D
if sel==2:
    H,W=map(int,input().split())
    C=[[int(i) for i in input().split()] for j in range(10)]
    for i in range(10):
        C[i][i]=0
    for k in range(10):
        for i in range(10):
            for j in range(10):
                C[i][j]=min(C[i][j],C[i][k]+C[k][j])
    ans=0
    for _ in range(H):
        for a in input().split():
            a=int(a)
            if a!=-1:
                ans+=C[a][1]
    print(ans)

#AGC016-A
if sel==3:
    s=input()
    ans=10**3
    for k in set(list(s)):
        t=s
        cnt=0
        while len(set(t))!=1:
            tmp=''
            for i in range(len(t)-1):
                if t[i]==k or t[i+1]==k:
                    tmp+=k
                else:
                    tmp+=t[i]
            t=tmp
            cnt+=1
        ans=min(ans,cnt)
    print(ans)
            
                

Measured memory_bytes: 3192
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

map <int, int> ss;
int a[nax];
int b[nax];
int ca[nax];
int cb[nax];
int n;

int top;

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

    for (int i = 1 ; i <= n ; ++ i) {
        scanf("%d %d", a + i, b + i);
        ca[i] = a[i];
        cb[i] = b[i];
    }
  //  cb[0] = INT_MAX;

    sort(ca + 1, ca + 1 + n);
    sort(cb + 1, cb + 1 + n);

    if (n % 2) {
        int a = ca[n / 2 + 1];
        int b = cb[n / 2 + 1];

        cout << b - a + 1;
    } else {
        int a = ca[n / 2] + ca[n / 2 + 1];
        int b = cb[n / 2] + cb[n / 2 + 1];

        cout << b - a + 1;
    }
  
  /**
  Stupid me. 
  First number that can be median is ca[n / 2 + 1]. 
  last number is cb[n / 2 + 1].
  
  This number has real existence and you already know that number will be able to be median in continuous range.
  
  Same for even case
  
  */

 /*   sort(c + 1, c + 1 + n);


    int cR = c[1].second;
    int cL = c[1].first;
    for (int i = 2 ; i <= n ; ++ i) {

        if (c[i].first > cR) {
            d[++ top] = make_pair(cL, cR);
            cR = c[i].second;
            cL = c[i].second;
        } else {
            cR = max(cR, c[i].second);
        }
    }

    d[++ top] = make_pair(cL, cR);


    long long ans = 0;
    if (n % 2) {
        for (int i = 1 ; i <= top ; ++ i) {
            int l = d[i].first, r = d[i].second;

            int min_bound = ca[(n + 1) / 2];
            int max_bound = cb[(n + 1) / 2];

            l = max(l, min_bound);
            r = min(r, max_bound);

            if (l > r) continue;

            ans += r - l + 1;
        }

        cout << ans;
    } else {

       /// throw;
        #define int long long

        int l_min = INT_MAX, l_max = INT_MIN;

        for (int i = 1 ; i <= top ; ++ i) {
            int l = d[i].first, r = d[i].second;

            int min_bound = ca[n / 2];
            int max_bound = cb[n - n /2];

            l = max(l, min_bound);
            r = min(r, max_bound);

            if (l > r) continue;

            l_min = min(l_min, l);
            l_max = max(l_max, r);

        }


        int r_min = INT_MAX, r_max = INT_MIN;


        for (int i = 1 ; i <= top ; ++ i) {
            int l = d[i].first, r = d[i].second;
            int min_bound = ca[n / 2 + 1];
            int max_bound = cb[n / 2 - 1];

            l = max(l, min_bound);
            r = min(r, max_bound);

            if (l > r) continue;

            r_min = min(r_min, l);
            r_max = max(r_max, r);

        }


        int all = r_max + l_max - r_min - l_min;

        cout << all + 1;
    }
*/

}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 6904
// Ala be zekrellah tatmaenolgholoob ...
// :)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define F first
#define S second
#define MP make_pair
using namespace std;
using namespace __gnu_pbds;
template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> using ordered_multiset =  tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64,int64> pii64;
const int maxn = 1e5+9;
const int64 M = 1e9+7;
const int64 I = 1e9;

int a[maxn];
int n, x;

int main () {
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> x;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	int64 ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] + a[i + 1] > x) {
			int cur = min(a[i + 1], a[i] + a[i + 1] - x);
			ans += cur;
			a[i + 1] -= cur;
		}
		if (a[i] + a[i + 1] > x) {
			int cur = min(a[i], a[i] + a[i + 1] - x);
			ans += cur;
		}
	}
	cout << ans << "\n";
}



Measured memory_bytes: 640
data = input()
stack = []
lakes = []
for i, X in enumerate(data):
    if X == "\\":
        stack.append(i)
    elif X == "/":
        try:
            j = stack.pop()
        except IndexError:
            continue
        s = 0
        while True:
            if (not lakes) or lakes[-1][1][0] < j:
                break
            s += lakes[-1][0]
            lakes.pop()
        lakes.append([i - j + s, (j, i)])

text = [len(lakes)] + [L[0] for L in lakes]
print(sum(text[1:]))
print(" ".join(list(map(str, text))))

Measured memory_bytes: 8260
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cmath>
#include<deque>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<tuple>
#include<utility>
#include<vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef vector<vector<int>> vvi;

#define rep(i, a, n)  for(int i=a; i<n; i++)
#define REP(i, n)  for(int i=0; i<(int)(n); i++)
#define REPS(i, n)  for(int i=1; i<=(int)(n); i++)
#define PER(i, n) for(int i=(int)(n)-1; i>= 0; i--)
#define PERS(i, n)  for(int i=(int)(n); i>0; i--)
#define FOR(i, c) for(__typeof((c).begin()) i = (c).begin(); i!=(c).end(); i++)
#define RFOR(i, c)  for(__typeof((c).rbegin()) i=(c).rbegin(); i!=(c).end(); i++)
#define ALL(container)  (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) (container).size()
#define FILL0(n)  setfill('0') << right << setw(n)
#define mp(a, b)  make_pair(a, b)
#define toLower(c)  c+0x20
#define toUpper(c)  c-0x20
#define pb  push_back
#define eb  emplace_back

const int INF = 1e9;
const long long LLINF = 1e18;
const int MOD = 1000000007;
const double Pi = 3.14159265358979323146;

int main(){
  int n;  cin>>n;
  vector<int> v(n, 0);
  REP(i, n-1){
    int a;  cin >> a;
    a--;
    v[a]++;
  }
  REP(i, n){
    cout << v[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
int top;
string b;
int a[1005];
void push1(int x)
{
		top++;
	a[top]=x;
}
int pop1()
{
	top--;
	return a[top+1];
}

int main()
{
	int x,y;
top=0;
getline(cin,b);
for(int i=0;i<b.length();i++)
{
	if(b[i]=='+')
	{
		x=pop1();
		y=pop1();
		push1(x+y);
	}
	else if(b[i]=='-')
	{
		x=pop1();
		y=pop1();
		push1(y-x);
	}
	else if(b[i]=='*')
	{
			x=pop1();
		y=pop1();
		push1(x*y);
	}
	else if(b[i]==' ')
	{
		int j=i-1,sum=0,k=1;
	while(b[j]!=' '&&j>=0)
	{
		if(b[j]=='+'||b[j]=='-'||b[j]=='*')
		break;
		
		else if(b[j]>='0'&&b[j]<='9')
		{
			sum=sum+(b[j]-48)*k;
			
		}
		k=k*10;
		j--;
	}
	 if(sum>0)
		push1(sum);
	}
}
cout<<pop1()<<endl;
	return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int number;
    cin >> number;
    A[number - 1] = i + 1;
  }
  for (int i = 0; i < N; i++) {
  	cout << A[i];
    if (i == N - 1) {
      cout << endl;
    } else {
      cout << " ";
    }
  }
}


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

class Cube{
    public:
    int f[6];
    Cube(){}
    void roll_z(){roll(1,2,4,3);}
    void roll_y(){roll(0,2,5,3);}
    void roll_x(){roll(0,1,5,4);}
    void roll(int i, int j, int k,int l){
        int t =f[i] ; f[i]= f[j] ;f[j]=f[k]; f[k]=f[l]; f[l]=t;
    }
};

bool eq( Cube c1,Cube c2){
    for (int i=0; i<6; i++)
        if (c1.f[i] != c2.f[i]) return false;
    return true ;
}

bool equal(Cube c1, Cube c2){
    for(int i=0; i<6; i++){
        for(int j =0;j<4;j++){
            if(eq(c1,c2)) return true;
            c1.roll_z();
        }
        if (i%2 ==0) c1.roll_y();
        else c1.roll_x();
    }
    return false;
}

int main(){
    Cube c1,c2;
    
    for (int i=0 ; i<6 ; i++) cin >> c1.f[i];
    for (int i =0 ;i<6; i++) cin >> c2.f[i];
    
    if (equal (c1,c2)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 3100
#include <stdio.h>
#include <string.h>

int main() {
	char A[4] = {}, w[101];
	int i, c[200] = {};
	scanf("%s", w);
	for (i = 0; i < strlen(w); i++) {
		c[w[i]]++;
	}
	for (i = 0; i <= 199; i++) {
		if (c[i] % 2 == 1) {
			strcpy(A,"No");
			break;
		}
	}
	if (A[0] != 'N') {
		strcpy(A,"Yes");
	}
	printf("%s\n", A);
	return 0;
}

Measured memory_bytes: 128
#define _CRT_SECURE_NO_WARNINGS
//#pragma GCC optimize("O3")
#include <vector>
#include <algorithm>
#include <vector>
//#include <random>
#include <fstream>
#include <map>
#include <string>
#include <deque>
#include <set>
#include <ctime>
#include <exception>
#include <iostream>
#include <queue>
using namespace std;

//const int size2 = 6e5;
const int size1 = 1e6 + 500;
const long long INF = 1e9 + 10;
const long long mod = 1e9 + 9;
const long double eps = 1e-7;
const long double pi = 3.1415926535;
const int erat = 1e6 + 500;


int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	static long long mas[size1];
	long long ans = 0;
	map<long long, long long> map1;
	long long pred = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> mas[i];
		pred += mas[i];
		if (pred == 0)
		{
			ans++;
		}
		if (map1.count(pred))
		{
			ans += map1[pred];
		}
		if (map1.count(pred))
		{
			map1[pred]++;
		}
		else
		{
			map1[pred] = 1;
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 14336
H, W, K = map(int, input().split())
c = []
for _ in range(H):
    ver = list(map(str,input()))
    c.append(ver)


ans = 0
n = H + W
for i in range(1<<H):
    for j in range(1<<W):
        cnt = 0
        for I in range(H):
            for J in range(W):
                if((i >> I) & 1):
                    continue
                if((j >> J) & 1):
                    continue
                if(c[I][J] == '#'):
                    cnt += 1
        if cnt == K:
            ans += 1
print(ans)


Measured memory_bytes: 9196
#include <iostream>
#include <cstring>
#include <string>
struct aaa
{
    std::string s;
    int x=0,y=0;
}aa[1000];
int main()
{
    int n,m,t=0;
    std::cin>>n;
    for(int i=1;i<=n;i++)
    {
        std::string s;std::cin>>s;
        int j;
        for(j=1;j<=t;j++)if(s==aa[j].s)break;
        if(j==t+1)aa[++t].s=s,aa[t].x=1;
        else aa[j].x++;
    }
    std::cin>>m;
    for(int i=1;i<=m;i++)
    {
        std::string s;
        std::cin>>s;
        int j;
        for(j=1;j<=t;j++)if(s==aa[j].s)break;
        aa[j].y++;
    }
    int gg=0;
    for(int j=1;j<=t;j++)gg=std::max(gg,aa[j].x-aa[j].y);
    std::cout<<gg<<std::endl;
}

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


#define base 1000000007LL
#define ll long long
// unsigned long long int t = 10000000000000000003ULL;
#define ulint unsigned long long int
#define ld long double
#define X first
#define Y second
#define pb push_back
#define EPS 1e-15
#define all(a) (a).begin(), (a).end()
#define sz(a) int((a).size())

#define ms(s, n) memset(s, n, sizeof(s))

#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define sqr(a) (a)*(a)

#define foru(i,a,b) for (ll i = (a); i <= (b); i++)
#define ford(i,a,b) for (ll i = (a); i >= (b); i--)
#define cbit(a) __builtin_popcount(a)
#define uni(a) (a).resize(unique(all(a)) - (a).begin())
#define cprint(n) printf("%.6lf + %.6lfi\n", (n).real(), (n).imag())

#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it !=(a).end(); it++)


using namespace std;
typedef pair<ll, ll> II;
typedef pair<int, int> ii;



struct Edge{
    ll u,v,w;
    Edge(ll u=0, ll v=0, ll w=0): u(u),v(v),w(w) {}
    bool operator < (Edge a){return w<a.w;}
};

const int M=1e5+7;
const int MM=4*M;
const ll MOD=base;
const int MAX=1e9;


inline ll gcd(ll a, ll b) {ll r; while (b) {r = a % b; a = b; b = r;} return a;}
inline ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
inline ll power(ll n, ll k, ll p = MOD) {ll r = 1; for (; k; k >>= 1LL) {if (k & 1LL) r = r * n % p; n = n * n % p;} return r;}
inline ll inverse(ll n, ll p=MOD){return power(n,p-2);}
ll search(ll a[], ll N, ll x){ ll l = 0, r = N - 1; while (l <= r){ ll mid = (l + r) / 2; if (x == a[mid]){ return 1; } else if (x < a[mid]){ r = mid - 1; } else if (x > a[mid]){ l = mid + 1; } } return -1; }
ll find_greater_equal(ll a[], ll N, ll x){ int q = lower_bound(a, a + N, x) - a; if(q == N){ return -1; } return q; }
ll find_greater(ll a[], ll N, ll x){ int q = upper_bound(a, a + N, x) - a; if(q == N){ return -1; } return q; }

ll a, b, c;
int main(){
    ios::sync_with_stdio(0);
    cin >> a >> b >> c;
    ll t = max (a * 10 + b + c, a + b * 10 + c);
    cout << max(t, a + b + c * 10);
    return 0;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; 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(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#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 show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
typedef vector<pii> vp;
typedef vector<tiii> vt;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
const ll INFLL = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main () {
  int n, d, x;
  cin >> n >> d >> x;

  int ans = x;
  rep(i,n) {
    int a;
    cin >> a;
    ans += (d-1)/a + 1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;
 
 
int main(){
	ll a, b, c, k, sum=0;
	cin >> a >>  b >> c >> k;
	if(k <= a) { cout << k << endl; return 0; }
	else sum+= a;
	k -= a;
	if(k <= b) { cout << sum << endl; return 0; }
	else k-= b;
	cout << sum - k << endl;
}

Measured memory_bytes: 3584
using System;

namespace arc081_b
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();
            long ret = s1[0] == s2[0] ? 3 : 6;
            bool tate = s1[0] == s2[0];
            for (int i = tate ? 1 : 2; i < n; i++)
            {
                if (s1[i] != s2[i])
                {
                    ret *= tate ? 2 : 3; ret %= 1000000007;
                    i++;
                    tate = false;
                }
                else
                {
                    if (tate)
                    {
                        ret *= 2; ret %= 1000000007;
                    }
                    tate = true;
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 11092
N = int(input())
L = []
for _ in range(3):
    l = list(map(int,input().split()))
    L.append(sorted(l))
import bisect
ans = 0
for x in L[1]:
    n = bisect.bisect_left(L[0],x)
    m = bisect.bisect_right(L[2],x)
    m = N - m
    ans += n*m
print(ans)

Measured memory_bytes: 107108
#include<bits/stdc++.h>
using namespace std;
int main(void){
	vector<int> a(3);
	for(int i = 0;i < 3;i++){
		cin >> a.at(i);
	}
	sort(a.begin(),a.end());
	
	int A = a.at(0),B = a.at(1), C = a.at(2);
	int a1 = C - A,b1 = C - B;
	int aa = 1 + 5*(a1 %2), bb = 1 + 3*(b1 %2);
	
	switch(aa*bb){
		case 1: cout << (a1 + b1)/2; break;
		case 4: cout << 1 + (a1 + b1 + 1)/2; break;
		case 6: cout << 1 + (a1 + b1 + 1)/2; break;
		case 24: cout << 1 + (a1 + b1 - 2)/2; break;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N;
	long long ans = 0, p = 1;
	cin >> N;
	vector<long long>H(N),sum(N+1);
	for (size_t i = 0; i < N; i++)
	{
		cin >> H.at(i);
		sum.at(i+1) = H.at(i)+sum.at(i);
		//cout << sum.at(i)<<endl;
	}
	sort(sum.begin(),sum.end());
	for (size_t i = 0; i < N+1; i++)
	{
		//cout << sum.at(i) << endl;
	}
	for (size_t i = 0; i < sum.size()-1; i++)
	{
		if (sum.at(i) == sum.at(i + 1)) { 
			p++;
			//cout << "hoge";
		}
		else {
			ans += p * (p-1) / 2;
			p = 1;
		}
	}
	ans += p * (p - 1) / 2;
	cout << ans;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define REP(i, a, n) for (ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll MOD = 1000000007;

mat mul(mat &A, mat &B) {
  mat C(A.size(), vector<ll>(B[0].size()));
  REP(i, 0, A.size())
    REP(j, 0, B[0].size())
      REP(k, 0, B.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, 0, A.size()) B[i][i] = 1;
  while(n > 0) {
    if(n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}

int main(void) {
  ll N, K;
  cin >> N >> K;
  mat A(N, vec(N));
  REP(i, 0, N) REP(j, 0, N) cin >> A[i][j];

  mat M = pow(A, K);

  ll ans = 0;
  REP(i, 0, N) REP(j, 0, N) {
    ans += M[i][j];
    ans %= MOD;
  }
  cout << ans << endl;
}

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

int main(){
    while(1){
        int x,y,s;
        cin >> x >> y >> s;
        if(x==0) break;

        int ans=0;
        for(int i=1; i<s; i++){
            int xa = (double)i*(100+x)/100;
            if(s-xa<=0) break;
            int mb = (double)(s-xa)*100/(100+x);//lower bound of no tax
            while(1){
                int xb = (double)mb*(100+x)/100;
                if(xa+xb>s) break;
                if(xa+xb==s){
                    int tmp = (int)((double)i*(100+y)/100)
                        + (int)((double)mb*(100+y)/100);
                    ans = max(ans, tmp);
                }
                mb++;
            }
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 3080
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  string s; cin >> s;
  ll n = s.size()/2 - 1;
  while(true){
    bool flg = false;
    REP(i, n){
      if(s[i] != s[n+i]) break;
      if(i == n-1) flg = true;
    }
    if(flg) break;
    n--;
  }
  cout << 2*n << endl;
}

Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

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

fn main() {
    input! {
        mut v: [usize; 3],
    }
    v.sort();
    let ans = v[0] + v[1];
    println!("{}", ans);
}


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

int int_compare(const int* a, const int* b)
{
    if (*a > *b) {
        return -1;
    } else if (*a < *b) {
        return 1;
    } else {
        return 0;
    }
}

int main(void)
{
    int n;
    scanf("%d", &n);
    int* arr = calloc(n, sizeof(int));
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
    }

    int* sorted = calloc(n, sizeof(int));
    for (int i = 0; i < n; i++) {
        sorted[i] = arr[i];
    }

    qsort(sorted, n, sizeof(int), (int (*)(const void*, const void*))(*int_compare));

    int max = sorted[0];
    int second_max = sorted[1];

    for (int i = 0; i < n; i++) {
        if (arr[i] == max) {
            printf("%d\n", second_max);
        } else {
            printf("%d\n", max);
        }
    }
    return 0;
}


Measured memory_bytes: 3120
#include <stdio.h>
int search(int A[], int n, int key) {
  int i = 0;  A[n] = key;
  while(A[i] != key) i++;
  return i != n;
}
int main(void) {
  int i, n, A[10000+1], q, key, sum = 0;
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) {
    scanf("%d", &key);
    if(search(A, n, key)) sum++;
  }
  printf("%d\n", sum);
  return 0;
}


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

const array<int, 8> dh = {1, 1, 0, -1, -1, -1, 0, 1},
  dw = {0, 1, 1, 1, 0, -1, -1, -1};

int main(){
  int H, W;
  cin >> H >> W;

  vector<string> S(H);
  for(int h = 0; h < H; h++){
    cin >> S[h];
  }

  vector<string> ans(S);
  for(int h = 0; h < H; h++){
    for(int w = 0; w < W; w++){
      if(S[h][w] == '.'){
        int bomb_cnt = 0;
        for(int i = 0; i < 8; i++){
          int h_ = h + dh[i], w_ = w + dw[i];
          if(h_ >= 0 && h_ < H && w_ >= 0 && w_ < W && S[h_][w_] == '#'){
            bomb_cnt++;
          }
        }
        ans[h][w] = '0' + bomb_cnt;
      }
    }
  }

  for(int h = 0; h < H; h++){
    cout << ans[h] << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i = (a);i <= (b);i++)
#define pii pair<int,int>
#define pll pair<long long, long long>
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int maxn = 2e5 + 5;
const int maxm = 1e6 + 5;
const double eps = 1e-8;
const double pi = acos(-1.0);
ll gcd(ll a,ll b){return !b?a:gcd(b,a%b);}
ll lcm(ll a,ll b){return a * b / gcd(a,b);}
ll poww(ll x,ll y,ll p){ll ans = 1;while(y){if(y & 1) ans = ans * x % p;x = x * x % p;y >>= 1;}return ans % p;}
bool isp(ll x){if(x < 2) return 0; for(ll i = 2;i * i <= x;i++){if(x % i == 0) return 0;}return 1;}
int n,m;
int a[1005];
int main(){
 	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	int sum = 0;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		sum += a[i];
	}
	int k = 4 * m;
	sort(a,a+n,greater<int>());
	int ans = 0;
	for(int i = 0;i < m;i++){
		int x = a[i];
		if(x * k >= sum) ans++;
	}
	if(ans == m) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}
//do smt instead of nothing! never give up!
//take care of long long!
//take care of upper or lower case e.g "yes" or "YES"?
//boundary condition! e.g. n = 0?
//brute force is always the first choice!
// print the ans to look for patterns in the data!

Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
char s[SIZE];
LL three[SIZE],two[SIZE];
int main(){
    three[0]=two[0]=1;
    REPP(i,1,SIZE){
        two[i]=two[i-1]*2%MOD;
        three[i]=three[i-1]*3%MOD;
    }
    RS(s);
    int n=LEN(s);
    LL an=0;
    int now=0;
    REP(i,n){
        if(s[i]=='1'){
            ADD(an,two[now]*three[n-i-1]);
            now++;
        }
    }
    ADD(an,two[now]);
    W(an);
    return 0;
}


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

int main(){
  int H,M,h,m,K; //Hで起きてhで寝る
  cin >> H >> M >> h >> m >> K;
  //まずは寝る時間から、最後に始められるギリギリの時間を出す
  int x = (h * 60 + m) - (H * 60 + M); //起きてる時間(分)
  if(x - K <= 0 ){
    cout << 0 << endl;
  }
  else cout << x - K << endl;
  
}

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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
//#define int long long

signed main()
{
  int n;cin>>n;
  int dan = 0;
  vi v1(n);
  REP(i,n)
    cin>>v1[i];
  
  sort(ALL(v1));reverse(ALL(v1));
  
  REP(i,n){
  if(v1[i] > v1[i+1])
  ++dan;
  }
  
  cout << dan;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>

int main()
{
  char w[100]={};
  int i,j;
  char x;
  int count[100]={};
  
  scanf("%s",w);
  
  int l=strlen(w);
  int tmp=1;
  
 for(x='a';x<='z';x++)
 {
   for(j=0;j<l;j++)
   {
     if(w[j]==x)
     {
       count[(int)x-(int)'a']++;//[0]~[25]
     }
   }
 }
    for(i=0;i<=25;i++)
    {
      if(count[i]%2!=0)
      {
        tmp=0;
      }
    }
  
  /*for(i=0;i<=25;i++)
   {
     printf("count[%d]=%d\n",i,count[(int)i]);
   }*/
  if(tmp==0)
  {
    printf("No\n");
  }
  else
  {
    printf("Yes\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
	long long int a,b;

	scanf("%lld %lld",&a,&b);
	if(a > 0){
		printf("Positive\n");
	}
	if(a <= 0 && b >= 0){
		printf("Zero\n");
	}
	if(b < 0){
		if((b - a) % 2){
			printf("Positive\n");
		}else{
			printf("Negative\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define repr(i,n) for(ll i=(n-1);i>=0;i--)
#define all(x) x.begin(),x.end()
#define br cout << "\n";
using namespace std;
const long long INF = 1e10;
const long long MOD = 1e9+7;
using Graph = vector<vector<ll>>;
using pll = pair<ll, ll>;
template<class T> inline bool chmin(T &a, T b) { if(a > b){ a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b) { if(a < b){ a = b; return true;} return false;}

// 0 false, 1 true 
// string to int : -48
// a to A : -32
// ceil(a)  1.2->2.0
// c++17	g++ -std=c++17 a.cpp

int main() {
    std::cout << std::fixed << std::setprecision(15);
    ll x, y; cin >> x >> y;
    string ans = "No";
    for(ll i = 0; i <= x; i++){
        if(i * 2 + (x-i) * 4 == y){
            ans = "Yes";
        }
    }
    cout << ans << endl;


}

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

import sys
import os
import math

def f(x, q):
    return x - (x ** 3 - q) / (3 * (x ** 2))

for s in sys.stdin:
    q = int(s)
    if q == -1:
        break

    x = q / 2
    while abs(x ** 3 - q) >= 0.00001 * q:
        x = f(x, q)

    print(x)

Measured memory_bytes: 7644
//Head File
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<map>
#include<ctime>
#include<set>
#include<cstdlib>
#include<vector>
#include<cassert>
#include<cmath>
#include<iostream>
using namespace std;

#define il inline

//Variable
#define ll long long
#define ull unsigned long long
#define db double
#define lb long double
#define ui unsigned int

//Debug
#define B cerr<<"Break Point"<<endl;
#define P(x) cerr<<#x<<' '<<"="<<' '<<(x)<<endl;
#define p(x) cerr<<#x<<' '<<"="<<' '<<(x)<<' ';
#define ml(x) cerr<<"Size of array is "<<x*4/1024/1024<<" MB"<<endl;

//Vector
#define vc vector
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define vbe(x) x.begin(),x.end()

//Memset
#define ms(x) memset(x,0,sizeof(x))
#define MS(x) memset(x,0x3f3f3f3f,sizeof(x))

//Pair
#define fi first
#define se second

//File

#define fin(x) freopen(x,"r",stdin)
#define fou(x) freopen(x,"w",stdout)
void fio()
{
    #ifndef ONLINE_JUDGE
    freopen("sample.in","r",stdin);
    freopen("sample.out","w",stdout);
    #endif
}
void pti()
{
    double timeuse = clock()*1000.0/CLOCKS_PER_SEC;
    cerr<<"Timeuse "<<timeuse<<"ms"<<endl;
}
void end()
{
    #ifndef ONLINE_JUDGE
    pti();
    #endif
    exit(0);
}

//Inf
#define INF 0x3f3f3f3f
#define LINF ((long long)(0x3f3f3f3f3f3f3f3f))

//IO
#define pc(s) putchar(s)
#define say(s) cout<<s<<endl
namespace io
{
    const int SIZ=55;int que[SIZ],op,qr;char ch;
    template<class I>
    il void gi(I &w)
    {
        ch=getchar(),op=1,w=0;
	    while(!isdigit(ch)){if(ch=='-') op=-1;ch=getchar();}
        while(isdigit(ch)){w=w*10+ch-'0';ch=getchar();}w*=op;
    }
    template<typename T,typename... Args>
    il void gi(T& t,Args&... args){gi(t);gi(args...);}
    template<class I>
    il void print(I w)
    {
        qr=0;if(!w) putchar('0');if(w<0) putchar('-'),w=-w;
	    while(w) que[++qr]=w%10+'0',w/=10;
        while(qr) putchar(que[qr--]);
    }
}
using io::gi;
using io::print;

const int N=2e7+5;
const int base=131;
const ll mod=192608179;

string a,b;
int tag[N];
ll ha[N],hb[N],fac[N];

ll gethash(int x)
{
    if(x+b.size()>a.size()) return -1;
    return (ha[x+b.size()-1]-ha[x-1]*fac[b.size()]%mod+mod)%mod;
}
int main()
{
    cin>>a>>b;
    while(a.size()<b.size()*2) a=a+a;
    a=a+a,a=a+a,a=a+a;
    fac[0]=1,ha[0]=a[0]-'a',hb[0]=b[0]-'a';
    for(int i=1;i<a.size();++i) fac[i]=fac[i-1]*base%mod;
    for(int i=1;i<a.size();++i) ha[i]=(ha[i-1]*base%mod+a[i]-'a')%mod;
    for(int i=1;i<b.size();++i) hb[i]=(hb[i-1]*base%mod+b[i]-'a')%mod;
    for(int i=0;i<a.size();++i) tag[i]=hb[b.size()-1]==gethash(i);
    int ans=0;
    for(int i=a.size()-b.size();i>=0;--i) if(tag[i]) tag[i]+=tag[i+b.size()],ans=max(ans,tag[i]);
    if(ans+1>=a.size()/b.size()) print(-1);
    else print(ans);
    end();
}


Measured memory_bytes: 342716
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<int> d(n);
    for (int i = 0; i < n; ++i)
        cin >> d[i];

    sort(d.begin(), d.end());

    int count = 1;
    int previous = d[0];
    for (int i = 1; i < n; ++i) {
        if (d[i] > previous)
            ++count;
        previous = d[i];
    }
    cout << count << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<cmath>
#include<map>
#include<queue>
#include<stack>
#include<algorithm>
#include<functional>

typedef unsigned long long LL;

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	int ch = A - B;
	if (ch > C) {
		cout << 0 << endl;
	}
	else {
		cout << C - ch << endl;
	}
}

Measured memory_bytes: 256
import sys
N = int(input())
A = list(map(int, input().split()))
for i in range(N):
  if A[i] == 0:
    print(0)
    sys.exit()
R = 1
for i in range(N):
  R *= A[i]
  if R > 10**18:
    print(-1)
    sys.exit()
print(R)

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

int main()
{
    int a,b,num;
    while(~scanf("%d%d",&a,&b))
    {
        if ((a<0&&b>=0)||(a==0)) printf("Zero\n");
        else if (a>0) printf("Positive\n");
        else if (a<0)
        {
            num=b-a+1;
            if (num%2==0) printf("Positive\n");
            else printf("Negative\n");
        }

    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
typedef long long ll;

int N,C,A[410],B[410];
ll dp[410][410] = {{0}},value[410][410] = {{0}},beki[410][410] = {{0}},inf = 1e9+7;

ll mult(ll n, ll m){
	if(m==0) return 1;
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}


int main(){
	cin >> N >> C;
	for(ll x=1;x<=400;x++){
		for(ll c=0;c<=400;c++){
			if(c==0) beki[x][c] = 1;
			else{
				beki[x][c] = beki[x][c-1]*x;
				beki[x][c] %= inf;
			}
		}
	}
	for(int i=1;i<=N;i++) cin >> A[i];
	for(int i=1;i<=N;i++) cin >> B[i];
	for(int i=1;i<=N;i++){
		for(ll c=0;c<=C;c++){
			for(ll x=A[i];x<=B[i];x++){
				value[i][c] += beki[x][c];
				value[i][c] %= inf;
			}
			if(i==1) dp[i][c] = value[i][c];
		}
	}
	for(int i=2;i<=N;i++){
		for(int c=0;c<=C;c++){
			for(int k=0;k<=c;k++){
				dp[i][c] += dp[i-1][c-k]*value[i][k];
				dp[i][c] %= inf;
			}
		}
	}
	cout << dp[N][C] << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  } //N個の数字を配列vecとして取得
  
  sort(vec.begin(), vec.end()); // vecを小さい順に並べる
  reverse(vec.begin(), vec.end()); // vecを大きい順に並べる
     
  int A, B;
  A = 0;
  B = 0;
  
  for (int i = 0; i < N; i++) {
    if (i%2 == 0) {
      A = A + vec.at(i);
    } //添字0,2,4,...の値を取得してAliceの合計値とする
    else {
      B = B + vec.at(i);
    } //添字1,3,5,...の値を取得してBobの合計値とする
  }
  
  int S;
  S = A - B;
    
  cout << S << endl;
}


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

using namespace std;

int getg(int n) {
	if(n/100==0){
		if(n/10==0)
			return n;
		return n%10;
	}
	return (n%100)%10;
}

int main(int argc,char ** argv) {
	int n;
	cin >> n;
	switch(getg(n)) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			cout <<"hon";
			break;
		case 0:
		case 1:
		case 6:
		case 8:
			cout <<"pon";
			break;
		case 3:
			cout <<"bon";
			break;
	}
	
	return 0; 
}

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

#define pp push_back
#define pf push_front
#define mp make_pair
#define fs first
#define sc second
#define sf scanf

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

const int N = (int) 1e5;
const int INF = (int) 1e9 + 7;

int main(int argc, char *argv[])
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll x;
	cin >> x;

	ll ans = 0;
	ll n = 100;
	while (n < x) {
		++ans;
		n += n / 100;
	}

	cout << ans;

	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
using namespace std;
int main(){
	string s;
	char com;
	int a[4],b;
	for(int i=0;i<4;i++){
		a[i]=0;
	}
	while(cin>>b>>com>>s){
		if(s=="A")a[0]++;
		else if(s=="B")a[1]++;
		else if(s=="AB")a[2]++;
		else a[3]++;
	}
	for(int i=0;i<4;i++){
		cout<<a[i]<<endl;
	}
}

Measured memory_bytes: 1204
import copy
n=int(input())
in_L=list(map(int,input().split()))
cnt=0
tmp_L=copy.copy(in_L)
sort_L=sorted(in_L)

for i in range(n):
    for j in range(n-i):
        tmp_L[i],tmp_L[i+j]=tmp_L[i+j],tmp_L[i]
        if tmp_L==sort_L:
            cnt=True
            break
        else:
            tmp_L=copy.copy(in_L)
            
            
        
if cnt:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3444
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

bool findIndex(vector<int> a, int a_i) {
    auto itr = std::find(a.begin(), a.end(), a_i);
    if (itr != a.end()) {
        return true;
    } else {
        return false;
    }
}

int main()
{
    // 整数の入力
    int s;
    int result = 0;
    cin >> s;
    vector<int> a;
    bool flg = false;
    int i = 1;
    
    a.push_back(s);
    while( !flg ) {
        i++;
        int a_i = a.back();
        if (a_i % 2 == 0) {
            a_i = a_i / 2;
        } else {
            a_i = 3 * a_i + 1;
        }
        flg = findIndex(a, a_i);
        a.push_back(a_i);

    } 
    cout << i << endl;
    return 0;
}

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

int main() {
  int h, w, d;
  cin >> h >> w >> d;
  vector<pair<int, int>> a(h * w + 1);
  for (int i = 0; i < h; i ++) {
    for (int j = 0; j < w; j ++) {
      int t; cin >> t;
      a[t] = make_pair(i, j);
    }
  }

  vector<int> b(h * w + 1, 0);
  for (int i = d + 1; i <= h * w; i ++) {
    b[i] = b[i - d] + abs(a[i].first - a[i - d].first) + abs(a[i].second - a[i - d].second);
  }

  int q, l, r;
  cin >> q;
  for (int i = 0; i < q; i ++) {
    cin >> l >> r;
    cout << b[r] - b[l] << endl;
  }
}


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

int main() {
	int n; cin >> n;
	vector<int>a(n+5);
	for (int i = 0; i < n; i++) {
		int tmp; cin >> tmp;
		a[i] = tmp;
	}
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (a[i] == i + 1)ans++,swap(a[i], a[i + 1]);
	}
	cout << ans << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7


ll N, M;
vector<vector<ll>> G;
vector<ll> color;

bool dfs(ll v, ll c) {
	color[v] = c;
	for (auto p : G[v]) {
		if (color[p] == c)return false;
		if (color[p] == 0 && !dfs(p, -c))return false;
	}
	return true;
}

int main()
{
	cin >> N >> M;
	G.resize(N);
	color.resize(N, 0);
	REP(i, M) {
		ll a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	if (dfs(0, 1)) {
		ll res = 0;
		for (auto c : color)if (c == 1)res++;
		cout << res * (N - res) - M << endl;
		//cerr << "2th" << endl;
	}
	else {
		cout << N * (N - 1)/2 - M << endl;
		//cerr << "all" << endl;
	}

	return 0;
}


Measured memory_bytes: 7424
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int Inf = (1 << 30);
ll inf = (1LL << 60);
const int MOD = 1e9 + 7;
int main(){
	int k, n;
	cin >> k >> n;
	V a(n + 2);
	rep1(i, n) {
		cin >> a[i];
	}
	a[n + 1] = a[1];
	a[0] = a[n];
	int ans = Inf;
	for (int i = 1; i <= n; i++) {
		int tmp = abs(a[i] - a[i - 1]);
		if (a[i] > a[i - 1]) tmp += k;
		int tmp2 = a[i] - a[i + 1] + k;
		chmin(tmp, tmp2);
		chmin(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}

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

int main (){
	int a,b,ans=2018;
	cin>>a>>b;
	if(b-a>=2019)puts("0");
	else{
		for(int i=a;i<=b;i++){
			for(int j=i+1;j<=b;j++){
				ans=min(ans,((i%2019)*(j%2019))%2019);
			}
		}
	cout<<ans<<endl;
	}
	return 0;
} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const long double PI = (acos(-1));
#define rep(i, x, n) for (int i = x; i < (int)(n); i++)
#define sc(x) scanf("%d",&x)
#define scll(x) scanf("%lld",&x)
int main(){
    int n, x, y, tmp = 0;
    sc(n), sc(x), sc(y);
    x--, y--;
    vector<int> ans(n,0);
    rep(i, 0, n-1){
        rep(j, i+1, n){
            if (j <= x) tmp = j-i;
            else if (i >= y) tmp = j-i;
            else if (i <= x){
                if (j < y) tmp = min(j-i, x+y-i-j+1);
                else tmp = x-y+j-i+1;
            }else{
                if (j < y) tmp = min(j-i, i-x+y-j+1);
                else tmp = min(j-i, i+j-x-y+1);
            }
            ans[tmp] += 1;
        }
    }
    rep(i, 1, n){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int a,b;
    cin>>a>>b;
    int sum=a+b;
    int mult=a*b;
    int sub=a-b;
    if(sum>mult&&sum>sub)
        cout<<sum;
    else if(mult>sum&&mult>sub)
        cout<<mult;
    else
        cout<<sub;
    return 0;
}


Measured memory_bytes: 256