akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {

        const long Mod = 1000000007;
        public static void Main (string[] args)
        {
            new Program ().Solve (new ConsoleInput (Console.In, ' '));
        }

        public void Solve (ConsoleInput cin)
        {
            int S = cin.ReadInt;

            long ans = 0;
            int k = 1;
            while (S - 3 * k + (k - 1) >= 0)
            {
                ans = (ans + CombinationMod(S - 3 * k + (k - 1), k - 1)) % Mod;
                k += 1;
            }

            Console.WriteLine (ans);
        }

        public static long  CombinationMod(long m, long n)
        {
            var a = 1L;
            var b = 1L;
            for (long i = 1; i <= n; i++)
            {
                a = (a * (m - i + 1)) % Mod;
                b = (b * i) % Mod;
            }

            return ModDiv (a, b) % Mod;
        }
        static long ModDiv (long x1, long x2)
        {
            long bb = ModPow (x2, Mod - 2);
            return (x1 * bb) % Mod;
        }

        static long ModPow (long x1, long x2)
        {
            long ans = 1;
            while (x2 > 0)
            {
                if (x2 % 2 == 1)
                {
                    ans = (ans * x1) % Mod;
                }
                x2 /= 2;
                if (x2 == 0) break;
                x1 = (x1 * x1) % Mod;
            }
            return ans % Mod;
        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput (System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string> ();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue ();
                string[] tmp = _stream.ReadLine ().Split (_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue (tmp[i]);
                return inputStream.Dequeue ();
            }
        }
        public string ReadLine { get { return _stream.ReadLine (); } }
        public int ReadInt { get { return int.Parse (Read); } }
        public long ReadLong { get { return long.Parse (Read); } }
        public double ReadDouble { get { return double.Parse (Read); } }
        public string[] ReadStrArray (long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray (long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray (long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 27756
import math
def main():
    n = int(input())
    mn = math.floor(n/1.08)
    mx = math.floor((n+1)/1.08)+1
    for i in range(mn, mx):
        if math.floor(1.08*i) == n:
            print(i)
            return 0
    print(':(')

main()

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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[500005];

int main()
{
    string S;
    cin >> S;
    ll N = S.length();
    memset(A, 0, sizeof(A));
    queue<pll> q;
    REP(i, N + 1)
    {
        if (i == 0 && S[i] == '<')
            q.push(pll(i, 0));
        else if (i == N && S[i - 1] == '>')
            q.push(pll(i, 0));
        else if (i < N && S[i - 1] == '>' && S[i] == '<')
            q.push(pll(i, 0));
    }
    while (!q.empty())
    {
        pll t = q.front();
        q.pop();
        A[t.first] = t.second;
        {
            ll n = t.first - 1;
            if (n >= 0 && S[n] == '>')
                q.push(pll(n, t.second + 1));
        }
        {
            ll n = t.first;
            if (n < N && S[n] == '<')
                q.push(pll(n + 1, t.second + 1));
        }
    }
    ll ans = 0;
    REP(i, N + 1)
    {
        ans += A[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 8708
I=input;s,t=I()[::-1],I()[::-1]
l=len(t)
for i in range(len(s)-l+1):
	f=1;j=-1
	for k in s[i:i+l]:
		j+=1
		if "?"!=k!=t[j]:
			f=0
	if f:
		s=s[:i]+t+s[i+l:]
		print(s.replace("?","a")[::-1])
		exit()
print("UNRESTORABLE")

Measured memory_bytes: 3064
(defun solve (n l)
  (if (< (car l) n)
      (solve n (remove-if (lambda (x) (zerop (mod x (car l)))) l))
      (car l)))

(defun initialize ()
  (loop :as i
        :below 100002
        :collect (+ i 2)))

(princ (solve (read) (initialize)))

Measured memory_bytes: 61864
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>

using namespace std;

int main(void){
	while(1){
		int n;
		string str;
		scanf("%d",&n);
		if(n==-1)break;
		if(n==0)cout << "0" << endl;
		else{
			while(n>0){
				str+=n%4+'0';
				n=n/4;
			}
			reverse(str.begin(),str.end());
			cout << str << endl;
		}
	}
    return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main()
{
    int a,b,c,rem;
    double d;
    scanf("%d%d",&a,&b);
   c=a/b;
   rem=a%b;
   d=(double)a/(double)b;
   printf("%d %d %.5lf\n",c,rem,d);
}





Measured memory_bytes: 2120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <iomanip>
using namespace std;



int main() {
	int N;
	cin >> N;
	
	vector<int> D(N);
	for (int i = 0; i < N; i++) {
		cin >> D.at(i);
	}
	
	int count = 0;
	sort(D.begin(), D.end());

	count = D[N / 2] - D[N / 2 - 1];

	cout << count << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(){
    const double PI = acos(-1);
    long double a,b,h,m;
    cin >> a >> b >> h >> m;
    long double hrad = h/12*2*PI + m/12/60*2*PI;
    long double mrad = m/60*2*PI;
    long double hx = cos(hrad)*a;
    long double hy = sin(hrad)*a;
    long double mx = cos(mrad)*b;
    long double my = sin(mrad)*b;
    cout << setprecision(20) << sqrt(static_cast<long double>(hx-mx)*(hx-mx) + (hy-my)*(hy-my));
}


Measured memory_bytes: 4188
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF = 1<<30;

int main(){
  int a, b, k, i;cin>>a>>b>>k;
  for(i=min(a, b);i>=1&&k>0;i--)if(a%i+b%i==0)k--;
  cout<<++i<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    string s;
    cin >> s;
    int n = s.size();
    ll cnt = 0;
    string pre, cur;
    for (int i = 0; i < n; i++) {
        cur += s[i];
        if (pre != cur) {
            pre = cur;
            cur = "";
            cnt++;
        }
    }
    cout << cnt << endl;
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

int main() {
	int time, total = 0;
	rep(i, 4) {
		scanf("%d", &time);
		total += time;
	}
	printf("%d\n%d\n", total / 60, total % 60);
	return 0;
}

Measured memory_bytes: 3200
n = int(input())
g = [[] for i in range(n)]
for i in range(n-1):
  a,b,c = map(int,input().split())
  a-=1;b-=1
  g[a].append([b,c])
  g[b].append([a,c])
q,k = map(int,input().split())
k -= 1
con = [-1] * n
con[k] = 0
stack = [k]
while stack:
  cur = stack.pop()
  for i,j in g[cur]:
    if con[i] == -1:
      con[i] = con[cur] + j
      stack.append(i)
for i in range(q):
  x,y = map(int,input().split())
  x-=1;y-=1
  print(con[x]+con[y])

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

int main(){
    ll a,b,c,n,ans;
    cin >> n;
    n = n % 10;
    if(n==0||n==1||n==6||n==8){
        cout << "pon";
    }else if(n==3){
        cout << "bon";
    }else{
        cout << "hon";
    }
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  char a;
  cin >> a;
  char ax = toupper(a);
  if(a==ax){
    cout << "A" << endl;
  }else{
    cout << "a" << endl;
  }
  
}

Measured memory_bytes: 3560
N = int(input())
L = list(range(1, N + 1))
T, A = map(int, input().split())
H = list(map(int, input().split()))
tmp = 10 ** 9 + 7
ind = -1
for i, j in zip(H, L):
    if abs(A - T + i * 0.006) < tmp:
        tmp = abs(A - T + i * 0.006)
        ind = j
print(ind)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
int main()
{
    int count;
    string s,t;
    cin >> s;
    cin >> t;
    for(int i = 0;i < 3;i++)
    {
        if(s[i] == t[i])
        {
            count++;
        }
    }
    cout << count;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        int a=sc.nextInt();
        int b=sc.nextInt();
        int area=a*b;
        int length=a*2+b*2;
        System.out.println(area + " " + length);
        sc.close();

    }
}


Measured memory_bytes: 26088
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long li;

const int maxn = 1e5;
int n, x[maxn], y[maxn];
vector<li> ans;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
const char *str = "LURD";

void Solve(li x, li y, int id) {
  // printf("solve %lld %lld\n", x, y);
  if (id == ans.size()) {
    if (x != 0 || y != 0) throw;
    return;
  }

  int best = -1;
  li min_d = 1e18, d = ans[id];

  for (int i = 0; i < 4; ++i) {
    li new_d = abs(x - d * dx[i]) + abs(y - d * dy[i]);
    if (new_d < min_d) min_d = new_d, best = i;
  }

  putchar(str[best]);
  x -= d * dx[best];
  y -= d * dy[best];

  Solve(x, y, id + 1);
}

int main(void) {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d%d", x + i, y + i);
  }
  for (int i = 1; i < n; ++i) {
    if ((x[i] + y[i] & 1) != (x[0] + y[0] & 1)) {
      puts("-1");
      return 0;
    }
  }

  ans.push_back(1);
  while (ans.back() < 1e9) {
    ans.push_back(ans.back() * 2);
  }
  if (!(x[0] + y[0] & 1)) {
    ans.push_back(1);
  }
  reverse(ans.begin(), ans.end());
  printf("%d\n", (int)ans.size());
  for (int i = 0; i < ans.size(); ++i) {
    printf("%lld ", ans[i]);
  }
  puts("");

  for (int i = 0; i < n; ++i) {
    Solve(x[i], y[i], 0);
    puts("");
  }
}


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

int main()
{
  int64_t N, M;
  vector<pair<int, int>> ans;
  cin >> N >> M;
  if (N % 2)
  {
    for (int l = 0, r = N - 1; l < r; l++, r--)
    {
      ans.emplace_back(l, r);
    }
  }
  else
  {
    bool flag = true;
    for (int l = 0, r = N - 1; l < r; l++, r--)
    {
      if (flag && r - l <= N / 2)
      {
        r--;
        flag = false;
      }
      ans.emplace_back(l, r);
    }
  }
  for (int i = 0; i < M; i++)
  {
    cout << ans[i].first + 1 << ' ' << ans[i].second + 1 << endl;
  }
}

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

#define rep(i, n)     for(int i = 0;      i < int(n); ++i)
#define rep3(i, a, b) for(int i = int(a); i < int(b); ++i)
#define all(x)        (x).begin(),(x).end()
#define sz(x)         int(x.size())
#define mp            make_pair
#define pb            push_back


typedef long long ll;

using namespace std;

int main(){
  int a, b;
  cin >> a >> b;
  cout << a*b-a-b+1 << endl;

  return 0;
}


Measured memory_bytes: 256
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #n = int(stdin.readline()[:-1])   
    r = stdin.readline()[:-1]
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]
    #n = int(r)
    #a = r.split()
    #a,b,c = r.split()
    #a = list(map(int, r.split()))
    #a,b,c,d = map(int, r.split())
    #a = [int(s[i]) for i in range(1, n+1)]
    #a = [list(map(int, r.split())) for i in range(1,n+1)]
    #res = 0

    boin = ['a','e','i','o','u']
    if r in boin:
        print('vowel')
    else:
        print('consonant')

if __name__ == '__main__':
    main()


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

int main(){
	int a;
	for(int i = 1 ; i <= 9 ; i++){
		for(int b = 1 ; b <= 9 ; b++){
		a = i * b;
		cout<<i<<"x"<<b<<"="<<a<<endl;
		}
	}

	return 0;
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
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; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

bool check(int N, int mid, vector<ll> &a){
    if(mid == 0) return false;
    if(mid == N+1) return true;

    ll size = a[mid];
    for(int i=1; i<=N; ++i){
        if(i == mid) continue;

        if(a[i] <= 2*size){
            size += a[i];
        }
        else{
            return false;
        }
    }

    return true;
}

void solve(int N, vector<ll> &a){
    int left = 0, right = N+1; 
    int mid;

    while(left+1 < right){
        mid = (left+right)/2;
        if(check(N, mid, a)) right = mid;
        else left = mid;
        //cout << mid << endl;
    }

    cout << N+1 - right << endl;
}

int main(){
    int N; cin >> N;
    vector<ll> a(N+1, -1);
    for(int i=1; i<=N; ++i) cin >> a[i];
    sort(a.begin(), a.end());

    solve(N, a);
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
#define nl '\n'
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define flood(x) memset(x, 0x3f3f3f3f, sizeof x)
#define drain(x) memset(x, 0, sizeof x)
#define dcit cin.sync_with_stdio(0);cin.tie(0)
#define frp(x, y) freopen(x, "r", stdin);freopen(y, "w", stdout);
#define endl '\n'
typedef pair<int, int> pii;
typedef long long ll;

#ifdef LOCAL_PROJECT
#define gc getchar()
#define pc(x) putchar(x)
#else
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
#endif

template<typename T> void scani(T &x) {x = 0;register bool _=0;register T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printi(T n) {register bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);pc(10);}
string nextstring() { string r; register char c=gc;while(c==32||c==10) c = gc;while(!(c==32||c==10)) { r += c;c = gc; }return r; }
char nextgetchar(){ register char c = gc; while(c==32 || c==10) c = gc; return c;}

void prints(string k){ for (int i = 0; i < k.length(); i++)pc(k[i]); }
void scani() {}

template<typename First, typename ... Ints>
void scani(First &arg, Ints&... rest) { scani(arg);scani(rest...); }

const ll MOD = 1e9+7;
int H, W; ll dp[1002][1002];
char grid[1002][1002];
int main(){
    scani(H, W);
    dp[1][1] = 1;
    for (int i = 1; i <= H; i++) {
        for (int j = 1; j <= W; j++) {
            char c = nextgetchar();
            if(c!='#' &&!( i==1 && j==1)) {
                dp[i][j] = (dp[i-1][j]+dp[i][j-1])%MOD;
            }
        }
    }
    printi(dp[H][W]);
    return 0;
}

Measured memory_bytes: 8064
#include<iostream>

int main(){
	int i,N,B[100];
  scanf("%d",&N);
  for(i=0;i<=N-2;i++){
  	scanf("%d",&B[i]);
  }
  if(N==2){
    printf("%d",B[0]*2);
    return 0;
  }
  int sum=B[0];
  for(i=0;i<=N-3;i++){
  	if(B[i]>=B[i+1]){
    	sum=sum+B[i+1];
    }
    else{
    	sum=sum+B[i];
    }
  }
  	sum=sum+B[N-2];
  printf("%d",sum);
}

Measured memory_bytes: 256
n,a,b=map(int,input().split())
ans=0

def find(x):
        rtn=0
        while x>0:
                rtn+=int(x%10)
                x/=10
        return rtn

for i in range(n+1):
        sum=int(find(i))
        if sum>=a and sum<=b:
                ans+=int(i)

print(ans)

Measured memory_bytes: 3064
//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int i,j,k,n;
            cin>>n;
            int ans[n+1];
            for(i=1;i<=n;++i)
                ans[i]=0;
            for(i=1;i*i<=n;++i)
            {
                for(j=1;j*j<=n;++j)
                {
                    for(k=1;k*k<=n;++k)
                    {
                        if(i*i+j*j+k*k+i*j+i*k+j*k>n)
                            break;
                        ++ans[i*i+j*j+k*k+i*j+i*k+j*k];
                    }
                }
            }
            for(i=1;i<=n;++i)
                cout<<ans[i]<<endl;
        }
        return 0;
    }


Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)

const int mod=2;
typedef valarray<int> vec;
typedef valarray<vec> mat;

mat mul(mat a,mat b){
	int m=a.size();
	mat c(vec(0,m),m);
	rep(i,m)rep(j,m) rep(k,m){
		c[i][j]+=a[i][k]*b[k][j];
		c[i][j]%=mod;
	}
	return c;
}
mat power(mat a,int n){
	int m=a.size();
	mat b(vec(0,m),m);
	rep(i,m) b[i][i]=1;
	while(n){
		if(n&1) b=mul(b,a);
		a=mul(a,a);
		n>>=1;
	}
	return b;
}
inline int pivoting(mat &a,int k,int &c){
	int n=a.size(),m=a[0].size(),p=k,ret=0;
	for(;c<m;++c){
		int cmax=abs(a[k][c]);
		range(i,k+1,n){
			if(abs(a[i][c])>cmax){
				p=i,ret=1;
				cmax=abs(a[i][c]);
			}
		}
		if(cmax) break;
	}
	if(k!=p) swap(a[k],a[p]);
	return ret;
}
int forward(mat &a){
	int n=a.size(),m=a[0].size(),ret=0,c=0;
	rep(i,n-1){
		ret+=pivoting(a,i,c);
		if(abs(a[i][c])==0) break;
		range(j,i+1,n){
			int coef=a[j][c]/a[i][c];
			range(k,c,m) a[j][k]=(mod+a[j][k]-coef*a[i][k])%mod;
		}
	}
	return ret;
}
vec back(mat &a){
	int n=a.size(),m=a[0].size();
	vec x(0,n);
	for(int i=n-1;i>=0;i--){
		int sum=0;
		if(i+1<n) range(j,i+1,n) sum+=a[i][j]*x[j];
		sum%=mod;
		x[i]=a[i][i]*(mod+a[i][m-1]-sum)%mod;
	}
	rep(i,n) cout << (i?" ":"") << x[i];
	cout << endl;
	return x;
}
int answer(mat &a){
	int n=a.size(),m=a[0].size();
	int arank=0,brank=0;
	rep(i,n)rep(j,m-1) if(a[i][j]) arank=i+1;
	rep(i,n)rep(j,m) if(a[i][j]) brank=i+1;
	if(arank!=brank) return 0;
	if(arank<n) return 2;
	return 1;
}

int main(void){
	int n,t;
	cin >> n;
	mat a(vec(0,n),n),b(vec(0,n+1),n);
	rep(i,n)rep(j,n) cin >> a[i][j];
	rep(i,n) cin >> b[i][n];
	cin >> t;

	a=power(a,t);
	rep(i,n)rep(j,n) b[i][j]=a[i][j];

	forward(b);
	int ans=answer(b);
	if(ans==0)
		puts("none");
	else if(ans==1)
		vec x=back(b);
	else
		puts("ambiguous");
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

const int INF = 1 << 30;

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

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

    int cl[N][N];
    for (int x = 0; x < N; ++x) {
        for (int y = 0; y < N; ++y) {
            cin >> cl[x][y];
            --cl[x][y];
        }
    }

    int diff[3][C];
    fill(diff[0], diff[3], 0);
    // ゾーンiをcに変えるときの違和感

    for (int x = 0; x < N; ++x) {
        for (int y = 0; y < N; ++y) {
            for (int c = 0; c < C; ++c) {
                if (cl[x][y] == c) continue;
                diff[(x + y) % 3][c] += D[cl[x][y]][c];
            }
        }
    }

    int ans = INF;
    int a[3];
    // ゾーンiをa[i]で塗る

    for (a[0] = 0; a[0] < C; ++a[0]) {
        for (a[1] = 0; a[1] < C; ++a[1]) {
            for (a[2] = 0; a[2] < C; ++a[2]) {
                // a[i]間に重複がないか判定
                bool dup = false;
                for (int i = 0; i < 3; ++i) {
                    if (a[i] == a[(i + 1) % 3]) dup = true;
                }
                if (dup) continue;

                int cost = 0;
                for (int i = 0; i < 3; ++i) {
                    cost += diff[i][a[i]];
                }

                ans = min(ans, cost);
            }
        }
    }

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


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  bool J=true;
  if(A!=5 && A!=7)
    J=false;
  if(B!=5 && B!=7)
    J=false;
  if(C!=5 && C!=7)
    J=false;
  if(A+B+C!=17)
    J=false;
  if(J)
    cout << "YES";
  else
    cout << "NO";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;


int main()	
{
	ll n,a,sum=0;
	string s;
	stringstream ss;
	cin>>s;
	n=s.length()-1;
	for(ll bit=0;bit<(1<<n);bit++)
	{	
		ll p=0;
		for(ll i=0;i<n;i++)
		{
			if(bit&(1<<i))
			{
				string t=s.substr(p,i+1-p);
				ss<<t;
				ss>>a;
				ss.clear();
				sum+=a;
				p=i+1;
			}
		}
		ss<<s.substr(p,n+1-p);
		ss>>a;
		ss.clear();
		sum+=a;
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
def solve():
  a,b,x = (int(i) for i in input().split())
  L  = a*a*b
  if L <= x:
    print(0)
  else:
    mi = 0
    ma = 89.999999999
    while ma-mi >= 10**(-9):
      next = (mi+ma)/2
      bairitu = math.tan(math.radians(next))
      if x >= L/2 :
        lim = L-(a**3/2)*round(bairitu, 10)
      else:
        lim = (0.5)*a*b*b*math.tan(math.radians(90-next))
      if x > lim:
        ma  = next
      else:
        mi = next
    print(ma)
solve()


Measured memory_bytes: 3064
#include <iostream>

int main(int argc, char *argv[])
{
  using namespace std;
  int a, b;
  cin >> a >> b;
  if (a < b) {
    cout << "a < b" << endl;
  } else if (a > b) {
    cout << "a > b" << endl;
  } else {
    cout << "a == b" << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    int n;
    cin>>n;
    vector<int>h(n);
    for(int i=0;i<n;i++){
        cin>>h.at(i);
    }
    vector<int>dp(n);
    dp[0]=0;
    dp[1]=abs(h.at(1)-h.at(0));
    for(int i=2;i<n;i++){
        dp[i]=min(dp[i-2]+abs(h.at(i)-h.at(i-2)),dp[i-1]+abs(h.at(i)-h.at(i-1)));
    }
    cout<<dp[n-1]<<endl;
    // for(int i=0;i<n;i++){
    //     cout<<dp.at(i)<<endl;
    // }





    return 0;
}


Measured memory_bytes: 1024
N = int(input())
A = list(map(int, input().split()))

x = 0
tmp = 0
for i in range(N):
    tmp += A[i]
    if i & 1 == 0:
        if tmp < 1:
            x += 1-tmp
            tmp = 1
    else:
        if tmp > -1:
            x += 1+tmp
            tmp = -1
y = 0
tmp = 0
for i in range(N):
    tmp += A[i]
    if i & 1:
        if tmp < 1:
            y += 1-tmp
            tmp = 1
    else:
        if tmp > -1:
            y += 1+tmp
            tmp = -1
print(min(x,y))

Measured memory_bytes: 14468
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

/* ?\????1??´1???1??\?????????????????\??°?¨???? */
int Fairfield(int y,int m,int d){
  if(m<=2){
    y--;
    m+=12;
  }
  
  int dy = 365*(y - 1);
  int dl = y / 4 - y / 100 + y / 400;
  int dm = (306*m - 324) / 10;
  return dy + dl + dm + d - 1;
}

/* ?????\?¨???? (0??\?????\ - 6????????\)???*/
int Zeller(int y,int m,int d){
  if(m<=2){
    y--;
    m+=12;
  }
  return (y + y/4 - y/100 + y/400 + (13*m + 8)/5 + d)%7;
}

/* ???????????´ */
bool is_uruu(int y) {
  return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
}



bool calc(){
  int ya,ma,da,yb,mb,db;

  cin >> ya >> ma >> da >> yb >> mb >> db;

  if(ya == -1) return false;


  cout << Fairfield(yb,mb,db) - Fairfield(ya,ma,da) << endl;

  return true;
}

int main(){

  while(calc());
  
  return 0;
}

Measured memory_bytes: 3004
import collections

s = ""
t = ""
res = []


def solve():
    global s,t
    s = input()
    t = input()
    i = 0
    while i+len(t) <= len(s):
        for a,b in zip(t,s[i:]):
            if b != '?' and a != b:
                break
        else:
            x = s[0:i].replace('?','a')+t+s[i+len(t):].replace('?','a')
            res.append(x)
        i+=1
    if len(res):
        print(min(res))
    else:
        print("UNRESTORABLE")



if __name__ == "__main__":
    solve()


Measured memory_bytes: 3316
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    int N,M; cin>>N>>M;
    vector<vector<int>>vec(M);
    rep(i,M){
        int k; cin>>k;
        vec[i].resize(k);
        rep(j,k){
            cin>>vec[i][j];
        }
    }
    vector<int>p(M);
    rep(i,M)cin>>p[i];

    int ans=0;
    for(int i=0;i<(1<<N);i++){
        bool ok =true;
        for(int j=0;j<M;j++){
            int c=0;
            for(auto nv:vec[j]){
                if(i>>(nv-1)&1){
                    c++;
                }
            }
            if(c%2!=p[j])ok=false;
        }
        if(ok)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define INF int(1e9)
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define REPONE(i, n) for(int i = 1; i <= (int)(n); i++)
#define EACH(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(int i = m;i < n;i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

ll N, M;
const int MAX_M = (int) 1e5 * 2;
vector<ll> G[MAX_M];

void solve() {
    REP(i, G[0].size()) {
        REP(j, G[G[0][i]].size()) {
            if (G[G[0][i]][j] == N - 1) {
                cout << "POSSIBLE" << endl;
                return;
            }
        }
    }
    cout << "IMPOSSIBLE" << endl;
}

int main() {
    cin >> N >> M;
    REP(i, M) {
        int a, b;
        cin >> a >> b;
        G[a - 1].emplace_back(b - 1);
    }
    solve();
    return 0;
}

Measured memory_bytes: 8832
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define nl '\n'
typedef long long ll;
//////////////////////////////////////////////////////////////////////



int main(){
  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  
  ll q,h,s,d,n;
  cin>>q>>h>>s>>d>>n;

  ll c1 = min(s , min(2*h,4*q) );
  ll c2 = min(s+s , d);
  
  ll ans = c1*n;

  ans = min(ans,c1*(n%2)+c2*(n/2));
  
  cout << ans << nl;
  
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
using namespace std;
double n,d,x,ans;
int main()
{
	scanf("%lf%lf%lf",&n,&d,&x);
	for(d+=(n-0.5)*x;n;--n) ans+=d,d+=d/n;
	return printf("%.10f",ans),0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramB
    {
        static void Main()
        {
            int n = NextInt;
            var list = IntList;

            System.Console.WriteLine(Enumerable.Range(1, n - 2).Count(i => {
                int max = Math.Max(Math.Max(list[i], list[i - 1]), list[i + 1]);
                int min = Math.Min(Math.Min(list[i], list[i - 1]), list[i + 1]);

                return list[i] != max && list[i] != min;
            }));
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> b,v;
    for(int i = 0;i < n;i++)
    {
        int x;
        cin >> x;
        b.push_back(x);
    }
    while(!b.empty())
    {
        int Max = -1;
        for(int i = 0;i < b.size();i++)
        {
            if(i + 1 == b.at(i))
            {
                Max = i;
            }
        }
        if(Max != -1)
        {
            v.push_back(Max + 1);
            b.erase(b.begin() + Max);
        }
        else
        {
            cout << "-1";
            return 0;
        }
        n--;
    }
    for(int i = v.size() - 1;i >= 0;i--)
    {
        cout << v.at(i) << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
/*
    ASEEN AAN 
            PINDAN AALE JATT!!!
                                */
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
//#include <boost/functional/hash.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int lli;
lli M=1000000007;   
lli INF=1e17;
#define sqr(x) (x) * (x)
#define bip(n) __builtin_popcount(n)//no of ones bit in binary!!
#define bictz(n) __builtin_ctz(n)//no of trailing zeroes in binary!!
#define biclz(n) __builtin_clz(n)//no of leading zeroes in binary!!
#define bffs(n) __builtin_ffs(n)//index of first one bit!!
typedef pair<lli,lli> ll;
#define mem1(a,x) fill(&a[0], &a[0] + sizeof(a) / sizeof(a[0]), x)
#define mem2(a,x) fill(&a[0][0], &a[0][0] +sizeof(a)/sizeof(a[0][0]),x)
#define mem3(a,x) fill(&a[0][0][0], &a[0][0][0] +sizeof(a)/sizeof(a[0][0][0]),x)
#define fi1 ifstream fin("input.txt")
#define of1 ofstream fout("output.txt")
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ost;
lli n,q,z,x,y,k,m;
const double pi1=3.14159265358979323846;
//unordered_map<pair<ll,lli>,lli> mp;
lli me(lli a,lli b,lli M)
{
    if(b==0)
    return 1;
    else if(b%2==0)
    return me((a*a)%M,b/2,M);
    else
    return (a%M*me((a*a)%M,(b-1)/2,M)%M)%M;
}
lli mI(lli a,lli m)
{
    return me(a,m-2,m);
}
//lli tot=0;
vector<lli> pf(string s) {
    int n = (int)s.length();
    vector<lli> pi(n);
    for (int i = 1; i < n; i++) {
        int j = pi[i-1];
        while (j > 0 && s[i] != s[j])
            j = pi[j-1];
        if (s[i] == s[j])
            j++;
        pi[i] = j;
    }
    return pi;
}
//map<ll,lli> dp;
//set<lli> s[100005];
int main()
{
    ios_base::sync_with_stdio(0);
    cin>>n;
    ll p[n+1];
    map<ll,lli> ml,mk;
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].first>>p[i].second;
        mk[{p[i].first,p[i].second}]=1;
    }
    sort(p+1,p+n+1);
    lli cnt=0;
    for(int i=1;i<=n;i++)
    {
        //cin>>p[i].first>>p[i].second;
        for(int j=1;j<i;j++)
        {
            lli x=p[i].first-p[j].first;
            lli y=p[i].second-p[j].second;
            ml[{x,y}]=1;
            //cout<<x<<" "<<y<<" "<<i<<" "<<j<<endl;
        }
    }
    lli mx=0;
    map<ll,set<ll>> jk;
    for(int i=1;i<=n;i++)
    {
        lli xx=p[i].first;
        lli yy=p[i].second;
        lli xx1=xx;
        lli yy1=yy;
        for(auto &j: ml)
        {
            lli p1=j.first.first;
            lli q1=j.first.second;
            lli cnt=1;
            while(1)
            {
                xx-=p1;
                yy-=q1;
                if(mk[{xx,yy}])
                cnt++;
                else
                break;
                jk[{p1,q1}].insert({xx,yy});
            }
            xx=xx1;
            yy=yy1;
        }
    }
    for(auto &i: jk)
    {
        set<ll> s1=i.second;
        lli d=s1.size();
        mx=max(mx,d);
    }
    mx=n-mx;
    cout<<mx;
}

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main() {
    int n;
    cin >> n;
    
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    //ボールの番号を配列のインデックスにする
    rep(i, n) a[i]--;
    //ある番号が何個あるかを把握する配列，初期値はゼロになっている
    vector<int> cnt(n);

    rep(i, n) cnt[a[i]]++;

    //その番号を選ばないときの総和を考える
    ll tot = 0;
    rep(i, n) tot += choose2(cnt[i]);

    rep(i,n){
        //トータルからその番号を選んだ時の増減を考える
        ll ans = tot;
        ans -= choose2(cnt[a[i]]);
        ans += choose2(cnt[a[i]]-1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	ll n,tmp=0;
	cin >> n;
	vector<ll>a(n);
	rep(i, n)cin >> a[i];
	vector<ll>aa(a);
	sort(all(aa));
	ll ma = aa[aa.size()-1];
	ll ma2 = aa[aa.size() - 2];
	for (ll i = 0; i < n; i++) {
		if (a[i] == ma)cout << ma2 << endl;
		else cout << ma << endl;
	}
}



Measured memory_bytes: 4864
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**6)
INF = 10 ** 9 + 1  # sys.maxsize # float("inf")
MOD = 10 ** 9 + 7


def debug(*x):
    print(*x, file=sys.stderr)


# Fenwick Tree
def init(n):
    global N, bit
    N = n
    bit = [0] * (N + 1)  # 1-origin


def bit_add(pos, val):
    assert pos > 0
    x = pos
    while x <= N:
        bit[x] += val
        x += x & -x  # (x & -x) = rightmost 1 = block width


def bit_sum(pos):
    ret = 0
    x = pos
    while x > 0:
        ret += bit[x]
        x -= x & -x
    return ret


def bit_bisect(lower):
    "find a s.t. v1 + v2 + ... + va >= lower"
    x = 0
    k = 1 << (N.bit_length() - 1)  # largest 2^m <= N
    while k > 0:
        if (x + k <= N and bit[x + k] < lower):
            lower -= bit[x + k]
            x += k
        k //= 2
    return x + 1


def main():
    # parse input
    N, Q = map(int, input().split())
    init(N)
    AS = list(map(int, input().split()))
    for i, a in enumerate(AS):
        bit_add(i + 1, a)

    for _q in range(Q):
        a, b, c = map(int, input().split())
        if a == 0:
            bit_add(b + 1, c)
        else:
            print(bit_sum(c) - bit_sum(b))


# tests
T1 = """
5 5
1 2 3 4 5
1 0 5
1 2 4
0 3 10
1 0 5
1 0 3
"""
TEST_T1 = """
>>> as_input(T1)
>>> main()
15
7
25
6
"""


def _test():
    import doctest
    doctest.testmod()
    g = globals()
    for k in sorted(g):
        if k.startswith("TEST_"):
            doctest.run_docstring_examples(g[k], g, name=k)


def as_input(s):
    "use in test, use given string as input file"
    import io
    f = io.StringIO(s.strip())
    g = globals()
    g["input"] = lambda: bytes(f.readline(), "ascii")
    g["read"] = lambda: bytes(f.read(), "ascii")


input = sys.stdin.buffer.readline
read = sys.stdin.buffer.read

if sys.argv[-1] == "-t":
    print("testing")
    _test()
    sys.exit()

main()


Measured memory_bytes: 127184
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
typedef complex<D> P;
#define F first
#define S second
const ll MOD=1000000007;
//const ll MOD=998244353;

template<typename T,typename U>istream & operator >> (istream &i,pair<T,U> &A){i>>A.F>>A.S; return i;}
template<typename T>istream & operator >> (istream &i,vector<T> &A){for(auto &I:A){i>>I;} return i;}
template<typename T,typename U>ostream & operator << (ostream &o,const pair<T,U> &A){o<<A.F<<" "<<A.S; return o;}
template<typename T>ostream & operator << (ostream &o,const vector<T> &A){ll i=A.size(); for(auto &I:A){o<<I<<(--i?" ":"");} return o;}


bool solve(){
  ll N;
  cin>>N;
  if(N==0){return false;}
  vector<int> A(10);
  for(int i=0;i<10;i++){A[i]=i;}
  map<char,int> M;
  vector<string> Str(N);
  for(auto &I:Str){
    cin>>I;
    for(auto &J:I){M[J]=-1;}
  }
  //cout<<N<<endl;
  //for(auto &I:Str){cout<<I<<endl;}
  int cnt=0;
  for(auto &I:M){I.S=cnt++;}
  for(auto &I:Str){
    for(auto &J:I){J=M[J];}
  }
  //cout<<N<<endl;
  //for(auto &I:Str){for(auto &J:I){cout<<(int)J;}cout<<endl;}
  ll ans=0;
  do{
    ll sum=0;
    bool jd=true;
    for(int i=0;i<N;i++){
      auto &I=Str[i];
      if(A[I[0]]==0 && (int)I.size()!=1){jd=false; break;}
      ll k=0;
      for(auto &J:I){k*=10; k+=A[J];}
      sum+=(i+1==N?-1LL:1LL)*k;
    }
    //cout<<A<<endl;
    //cout<<jd<<" "<<sum<<endl;
    if(!jd || sum!=0){continue;}
    ans++;
  }while(next_permutation(A.begin(),A.end()));
  ll uku=1;
  for(ll i=10;i>cnt;i--){uku*=11-i;}
  ans/=uku;
  cout<<ans<<endl;
  
  return true;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while(solve());


  return 0;
}



Measured memory_bytes: 3132
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
    auto val = table(args...);
    return vector<decltype(val)>(n, move(val));
}
const ll INF = 1e18;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,r;
    cin >> n >> r;
    if (n >= 10) PRINT(r);
    else PRINT(r+100*(10-n));
}

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

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

    int a;
    string s;
    cin >> a >> s;
    if(a >= 3200) {
        cout << s;
    } else if(a < 3200) {
        cout << "red";
    }

    return 0;
}


Measured memory_bytes: 3652
N, K = map(int, input().split())

AB = [list(map(int, input().split())) for i in range(N)]

AB.sort(key=lambda x:x[0])
i = 0

while K-AB[i][1]>0:
    K -= AB[i][1]
    i += 1

print(AB[i][0])

Measured memory_bytes: 29144
class Info:
  def __init__(self, num, p, y, id):
    self.num = num
    self.p = p
    self.y = y
    self.id = id
    
n, m = map(int, input().split())
info = [Info(0, 0, 0, '')]
for num in range(1, m + 1):
  p, y = map(int, input().split())
  info.append(Info(num, p, y, ''))

info = sorted(info, key=lambda x: (x.p, x.y))

cnt = 1
for i in range(1, m + 1):
  if info[i].p != info[i-1].p:
    cnt = 1
  else:
    cnt += 1
  info[i].id = "{0:06d}{1:06d}".format(info[i].p, cnt)

info = sorted(info, key=lambda x: x.num)
info.pop(0)

for x in info:
  print(x.id)

Measured memory_bytes: 43804
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <bitset>
#include <set>
#include <iomanip>
#include <functional>
using namespace std;
typedef long long ll;
//'A' = 65, 'a' = 97

int main()
{
    string s;
    cin >> s;
    int a[4];
    for (int i = 0; i < 4; i++) {
        a[i] = s[i] - '0';
    }

    for (int i = 0; i < (1 << 3); i++) {
        int sum = a[0];
        string ans;
        ans += (char)(a[0] + '0');
        for (int j = 0; j < 3; j++) {
            if (i & (1 << j)) {
                sum += a[j + 1];
                ans += '+';
                ans += (char)(a[j + 1] + '0');
            } else {
                sum -= a[j + 1];
                ans += '-';
                ans += (char)(a[j + 1] + '0');
            }
        }
        if (sum == 7) {
            cout << ans << "=7" << endl;;
            return 0;
        }
    }

}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int N;
int a[100005];
int b[100005];
int main() {
    scanf("%d",&N);
    for (int i = 0; i < N+1; i++) {
        scanf("%d",&a[i]);
    }
    for (int i = 0; i < N; i++) {
        scanf("%d",&b[i]);
    }
    long long ans = 0;
    for (int i = 0; i < N+1; i++) {
        if (i == N) {
            if (a[i] <= b[N-1]) {
                ans += a[i];
            } else {
                ans += b[N-1];
            }
            break;
        }

        if (i != 0 && b[i-1] > 0) {
            if (a[i] <= b[i-1]) {
                ans += a[i];
                a[i] = 0;
                b[i-1] -= a[i];

            } else {
                ans += b[i-1];
                a[i] -= b[i-1];
                b[i-1] = 0;
            }
        }
        if (a[i] <= b[i]) {
            b[i] -= a[i];
            ans += a[i];
            a[i] = 0;
        } else {
            a[i] -= b[i];
            ans += b[i];
            b[i] = 0;
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<cstdlib>
#include<math.h>
using namespace std;
int main(void){
    int ans=0;
    string s;
    cin >> s;
    char ch;
    for(int i = 0; i < (int)s.size(); ++i){
        ch = s[i];
        if(ch=='o'){
            ans+=100;
        }
    }
    
    printf("%d",ans+700);
}


Measured memory_bytes: 256
import sys
import math
import copy
import heapq
from functools import cmp_to_key
from bisect import bisect_left, bisect_right
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(1000000)

# input aliases
input = sys.stdin.readline
getS = lambda: input().strip()
getN = lambda: int(input())
getList = lambda: list(map(int, input().split()))
getZList = lambda: [int(x) - 1 for x in input().split()]

INF = float("inf")
MOD = 10**9 + 7
divide = lambda x: pow(x, MOD-2, MOD)

def nck(n, k, kaijyo):
    return (npk(n, k, kaijyo) * divide(kaijyo[k])) % MOD

def npk(n, k, kaijyo):
    if k == 0 or k == n:
        return n % MOD
    return (kaijyo[n] * divide(kaijyo[n-k])) % MOD

def fact_and_inv(SIZE):
    inv = [0] * SIZE  # inv[j] = j^{-1} mod MOD
    fac = [0] * SIZE  # fac[j] = j! mod MOD
    finv = [0] * SIZE  # finv[j] = (j!)^{-1} mod MOD
    inv[1] = 1
    fac[0] = fac[1] = 1
    finv[0] = finv[1] = 1
    for i in range(2, SIZE):
        inv[i] = MOD - (MOD // i) * inv[MOD % i] % MOD
        fac[i] = fac[i - 1] * i % MOD
        finv[i] = finv[i - 1] * inv[i] % MOD

    return fac, finv

class TwoDimGrid:
    # 2次元座標 -> 1次元
    def __init__(self, h, w, wall="#"):
        self.h = h
        self.w = w
        self.size = (h+2) * (w+2)
        self.wall = wall
        self.get_grid()
        self.init_cost()

    def get_grid(self):
        grid = [self.wall * (self.w + 2)]
        for i in range(self.h):
            grid.append(self.wall + getS() + self.wall)

        grid.append(self.wall * (self.w + 2))
        self.grid = grid
    def init_cost(self):
        self.cost = [INF] * self.size

    def pos(self, x, y):
        return y * (self.w + 2) + x
    def getgrid(self, x, y):
        return self.grid[y][x]
    def get(self, x, y):
        return self.cost[self.pos(x, y)]
    def set(self, x, y, v):
        self.cost[self.pos(x, y)] = v
        return
    def show(self):
        for i in range(self.h+2):
            print(self.cost[(self.w + 2) * i:(self.w + 2) * (i+1)])

    def search(self, s, g):
        grid = self.grid
        move = [(0, 1), (0, -1), (1, 0), (-1, 0)]
        move_eight = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]



def solve():
    n = getN()
    nums = []
    for i in range(n):
        nums.append(getN())
    # for i, num in nums:
    #     if num > i + 1:
    #         print(-1)
    #         return
    # nums.reverse()
    # next = nums[0]
    # ans = 0
    # if next != 0:
    #     ans += 1
    #
    # for num in nums[1:]:
    #     if next != 0:
    #         ans +=
    if nums[0] != 0:
        print(-1)
        return
    prev = 0
    ans = 0
    for num in nums[1:]:
        if num > prev + 1:
            print(-1)
            return
        if num == prev + 1:
            ans += 1
        if num<= prev:
            ans += num
        prev = num
    print(ans)
    return
def main():
    n = getN()
    for _ in range(n):
        solve()

    return
if __name__ == "__main__":
    # main()
    solve()

Measured memory_bytes: 85288