akhauriyash/Code-Regression huggingface dataset:
//include
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath> 
#include <iomanip>
#include <math.h>
#include <utility>
#include <functional>
//using
using namespace std;
using vl = vector <long long>;
using vs = vector <string>;
using vc = vector <char>;
using ll= long long;
using vvl = vector<vector<ll> >;
using vd = vector <double>;
//define
//#define int long long
#define rep(i,n) for(int i=0; i<n; i++)
#define print(n) cout<<n<<endl;
#define sortp(d) sort(d.begin(),d.end()) //1234
#define sortm(d) sort(d.rbegin(),d.rend()) //4321
//グローバル変数宣言
 ll p=0,q=0,r=0;


int main(){
   ll s;
   cin>>s;
   vl a(1000000);
   rep(i,1000000){
      if (i==0)
      {
         a[i]=s;
      }else if (a[i-1]%2==0)
      {
         a[i]=a[i-1]/2;
      }else  a[i]=a[i-1]*3+1;
      if (a[i]==4||a[i]==2||a[i]==1)
      {
         p=i+4;break;
      }
      
      
   }
   print(p)
      
}


Measured memory_bytes: 11124
package main

import (
	"bufio"
	"fmt"
	basicIO "io"
	"os"
	"strconv"
)

func main() {
	protagonist(os.Stdin, os.Stdout)
}

func protagonist(r basicIO.Reader, w basicIO.Writer) {
	io := NewIO(r, w)
	a := io.readInt()
	io.putInt(a*a*a + a*a + a)
}

type IO struct {
	Scanner *bufio.Scanner
	Writer  basicIO.Writer
}

func NewIO(r basicIO.Reader, w basicIO.Writer) *IO {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	return &IO{
		Scanner: s,
		Writer:  w,
	}
}

func (io *IO) readString() string {
	io.Scanner.Scan()
	return io.Scanner.Text()
}

func (io *IO) readStringSlice(num int) []string {
	slice := make([]string, num)
	for i, _ := range slice {
		slice[i] = io.readString()
	}
	return slice
}

func (io *IO) readInt() int {
	io.Scanner.Scan()
	i, _ := strconv.Atoi(io.Scanner.Text())
	return i
}

func (io *IO) readIntArray(num int) []int {
	slice := make([]int, num)
	for i, _ := range slice {
		slice[i] = io.readInt()
	}
	return slice
}

func (io *IO) putInt(v int) {
	fmt.Fprintf(io.Writer, "%d\n", v)
}

func (io *IO) putString(s string) {
	fmt.Fprintf(io.Writer, "%s\n", s)
}


Measured memory_bytes: 1772
import math


def solve():
    a, b, x = read()
    result = think(a, b, x)
    write(result)


def read():
    return read_int(3)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_float(n):
    return list(map(lambda x: float(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(a, b, x):
    eps = 1e-6

    degree_floor = 0.0
    degree_ceil = 90.0

    radian_floor = radian(degree_floor)
    radian_ceil = radian(degree_ceil)

    while True:
        radian_mid = (radian_floor + radian_ceil) / 2.0
        volume = calc_volume(a, b, radian_mid)
        if abs(volume - x) < eps:
            return degree(radian_mid)
        if volume > x:
            radian_floor = radian_mid
        else:
            radian_ceil = radian_mid

    return 0.0


def write(result):
    print(result)


def radian(degree):
    return degree / 180.0 * math.pi


def degree(radian):
    return radian / math.pi * 180.0


def calc_volume(a, b, theta):
    theta_threshold = math.atan(b / a)

    if theta >= theta_threshold:
        a_dash = b * math.cos(theta) / math.sin(theta)
        v = a * a_dash * b / 2.0
        return v
    else:
        h_dash = a * math.tan(theta)
        h_dash_dash = b - h_dash
        v_1 = a * a * h_dash / 2.0
        v_2 = a * a * h_dash_dash
        return v_1 + v_2


if __name__ == '__main__':
    solve()

Measured memory_bytes: 3316
#include<iostream>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a>b){
    int t;
    t=a;
    a=b;
    b=t;}
  if(a==b)
    cout<<a*2<<endl;
  else if((b-a)>=2)
    cout<<b+b-1<<endl;
  else
    cout<<a+b<<endl;
}

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

const int N = 300;
int a[N][N];

int main() {
    ios::sync_with_stdio(false);
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            cin >> a[i][j];
        }
    }
    for (int k = 0; k < n; ++k) {
        for (int u = 0; u < n; ++u) {
            for (int v = 0; v < n; ++v) {
                if (a[u][k] + a[k][v] < a[u][v]) {
                    cout << -1 << '\n';
                    return 0;
                }
            }
        }
    }
    long long res = 0;
    for (int u = 0; u < n; ++u) {
        for (int v = u + 1; v < n; ++v) {
            bool need = true;
            for (int k = 0; k < n; ++k) if (k != u && k != v && a[u][k] + a[k][v] == a[u][v]) {
                need = false;
                break;
            }
            if (need) res += a[u][v];
        }
    }
    cout << res << '\n';
}


Measured memory_bytes: 640
//b.c B-Shiritori
#include<stdio.h>
#include<string.h>
#include<stdbool.h>

int main(void){
    int n;
    scanf("%d",&n);
    char buf[n][11];
    bool flag = true;
    for(int i=0;i<n;++i){
        scanf("%s",buf[i]);
    }

    for(int i=0;i<n-1;++i){
        int len = strlen(buf[i]);
        if(buf[i][len-1]!=buf[i+1][0]){
            flag = false;
        }
        for(int j=0;j<n;++j){
            if(i!=j&&strcmp(buf[i],buf[j])==0){
                flag = false;
            }
        }
    }
    if(flag){
        printf("Yes\n");
    }else{
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int k, x;
    cin >> k >> x;
    yns(500*k>=x);
    return 0;
}

Measured memory_bytes: 256
N = gets.to_i

M = N / 2

ans = 100

(1..M).each do |a|
  b = N - a
  k = [a, b].map { |v| v.to_s.chars.map(&:to_i).reduce(&:+) }.reduce(&:+)
  ans = [ans, k].min
end

puts ans


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



int main(){
    long long n, m;
    cin >> n >> m;

    long long ball_count[n+1];
    for(long long i = 1; i <= n; i++){
        ball_count[i] = 1;
    }

    bool red[n+1];
    for(long long i = 1; i <= n; i++){
        red[i] = false;
    }
    
    red[1] = true;


    

    for(long long j = 0; j < m; j++){
        long long x, y;
        cin >> x >> y;
        ball_count[x] -= 1;
        ball_count[y] += 1;

        if(red[x] == true){
            red[y] = true;
        }

        if(ball_count[x] == 0){
            red[x] = false;
        }
    }

    long long count = 0;

    for(long long i = 1; i <= n; i++){
        if(red[i] == true and ball_count[i] >= 1){
            count++;
        }
    }
    cout << count << endl;

    return 0;
}

Measured memory_bytes: 1152
/************************************************************
/  AUTHOR :  DEVANSHU SINGLA                                /
/  NICK :  DSINGLA                                          /
/  INSTITUTE :  IITK                                        /
************************************************************/
//                     TEMPLATE                            //

#include <bits/stdc++.h>
#define ll long long
#define N 100005
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define F first
#define S second
#define MAX(x, y) (x) > (y) ? (x) : (y)
#define MIN(x, y) (x) < (y) ? (x) : (y)

using namespace std ;

void solve(){
    int x,y ;
    cin>>x>>y ;
    if(y>=x) cout<<"unsafe";
    else cout<<"safe" ;    
}

int main(){
    #ifndef ONLINE_JUDGE 
 
    freopen("/home/devanshu/Desktop/cp/cp_questions/input.txt", "r", stdin);  
    freopen("/home/devanshu/Desktop/cp/cp_questions/output.txt", "w", stdout); 

    #endif
    ios_base::sync_with_stdio(false) ;
    cin.tie(NULL) ;

    solve() ;
}

Measured memory_bytes: 3640
#include<iostream>

using namespace std;

int main(){
     int r,D,x2000,x2001;
     cin>>r>>D>>x2000;
     for(int i= 0 ; i<10 ; i++){
          x2001 = r*x2000 - D ;
          cout<<x2001<<endl;
          x2000=x2001;
     }
}


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

typedef long long ll;
const ll INF = 1LL << 50;
ll dp[20010][260];
ll c[16];
ll x[20000];

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

	int n, m;
	while(cin >> n >> m, n) {
		for(int i = 0; i < m; i++) {
			cin >> c[i];
		}
		for(int i = 0; i < n; i++) {
			cin >> x[i];
		}

		fill((ll*)begin(dp), (ll*)end(dp), INF);
		dp[0][128] = 0;

		for(int i = 0; i < n; i++) {
			for(int j = 0; j <= 255; j++) {
				for(int k = 0; k < m; k++) {
					int nj = max(min(j + c[k], 255LL), 0LL);
					dp[i + 1][nj] = min(dp[i + 1][nj], dp[i][j] + (x[i] - nj) * (x[i] - nj));
				}
			}
		}

		ll ans = INF;
		for(int j = 0; j <= 255; j++) {
			ans = min(ans, dp[n][j]);
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 43888
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <numeric>
#include <string>
#include <functional>

using namespace std;

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

int main(void){
    int N;
    cin>>N;
    vector<int> H(N);
    rep(i,N) cin>>H[i];
    H[0]--;
    bool ans=true;
    for(int i=1;i<N;i++){
        if(H[i]>H[i-1]){H[i]--;continue;}
        else if(H[i]<H[i-1]){ans=false;break;}
    }
    string s=ans?"Yes":"No";
    cout<<s<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>

#define NUMBER 100000

int sum_at(int n,int a[])
{
    int i;
    int c = 0;
    for (i = 0;i < n;i++){
        c = c + a[i];
    }
    return c;
}

int main(void)
{
    int h,n;
    int a[NUMBER];
    int i;
    
    scanf("%d %d",&h,&n);
    for (i = 0;i < n;i++){
        scanf("%d",&a[i]);
    }
    
    if (h > sum_at(n,a)){
        printf("No\n");
    }
    
    else
        printf("Yes\n");
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define INF 1000000000
#define MAX_V 100
#define MAX_E 1000
using namespace std;
struct edge {
	int to, cap, rev;
	edge(int to_, int cap_, int rev_) : to(to_), cap(cap_), rev(rev_) {};
};

int V, E;
vector<edge> G[MAX_V];
bool used[MAX_V];

void AddEdge(int from, int to, int cap) {
	G[from].push_back(edge(to, cap, G[to].size()));
	G[to].push_back(edge(from, 0, G[from].size() - 1));
}

int DFS(int v, int t, int f) {
	if (v == t) return f;
	used[v] = true;
	for (size_t i = 0; i < G[v].size(); i++) {
		edge &e = G[v][i];
		if (!used[e.to] && e.cap > 0) {
			int d = DFS(e.to, t, min(f, e.cap));
			if (d > 0) {
				e.cap -= d;
				G[e.to][e.rev].cap += d;
				return d;
			}
		}
	}
	return 0;
}

int Ford_Fulkerson(int s, int t) {
	int flow = 0;
	while (true) {
		fill(used, used + V, 0);
		int f = DFS(s, t, INF);
		if (f == 0) return flow;
		flow += f;
	}
}

int main()
{
	cin >> V >> E;
	for (int i = 0, u, v, c; i < E; i++) {
		cin >> u >> v >> c;
		AddEdge(u, v, c);
	}
	cout << Ford_Fulkerson(0, V - 1) << endl;
	return 0;
}

Measured memory_bytes: 3120
#include<bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
	
using namespace std;
const int MAX_N=30,MAX_M=30;
int N,M,K[MAX_N];
bool lik[MAX_N][MAX_M];
int main(){
	cin>>N>>M;
	REP(i,N){
		cin>>K[i];
		REP(j,K[i]){
			int a;
			cin>>a;
			lik[i][a-1]=true;
		}
	}
	int ans=0;
	REP(i,M){
		bool flg=true;
		REP(j,N){
			flg&=lik[j][i];
		}
		if(flg){
			ans++;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

A = ord(input()[0])

print("A" if ord("A") <= A <= ord("Z") else "a")


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

typedef long long LL;
typedef pair<int, int> PII;
typedef vector<int> VI;
#define MP make_pair
#define PB push_back
#define X first
#define Y second

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); --i)
#define ALL(a) a.begin(), a.end()
#define SZ(a) (int)((a).size())
#define FILL(a, value) memset(a, value, sizeof(a))
#define debug(a) cout << #a << " = " << a << endl;

const double PI = acos(-1.0);
const LL INF = 1e9 + 47;
const LL LINF = INF * INF;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
int a, b;
cin >> a >> b;
cout << max(a + b, max(a * b, a - b));
	cerr << "Time elapsed: " << clock() / (double)CLOCKS_PER_SEC << endl;
	return 0;
}



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

int main () {
        int n; cin >> n;
        set <int> s;
        for (int i = 0; i < n; ++i) {
                int x; cin >> x;
                s.insert (x);
        }
        if (n != s.size()) cout << "NO" << endl;
        else cout << "YES" << endl;
        return 0;
}

Measured memory_bytes: 9600
import itertools
n = int(input())
s = input()
t = [''] * n
for p in itertools.product(['o', 'x'], repeat=2):
  t[-1] = p[0]
  t[0] = p[1]
  for i in range(1, n - 1):
    if (t[i - 2] + t[i - 1] + s[i - 1]).count('x') % 2 == 0:
      t[i] = 'o'
    else:
      t[i] = 'x'
  if (t[-3] + t[-2] + t[-1] + s[-2]).count('x') % 2 == 0 and (t[-2] + t[-1] + t[0] + s[-1]).count('x') % 2 == 0:
    ans = []
    for c in t:
      if c == 'o':
        ans.append('S')
      else:
        ans.append('W')
    print(*ans, sep='')
    break
else:
  print(-1)


Measured memory_bytes: 7804
#include <bits/stdc++.h>
#define mod 1000000007
#define ll long long
using namespace std;


ll dp[2000][2000];
ll func(pair<ll,int> *arr, int N, int i=0, int first=0)
{
	if(i==N)
		return 0;

	if(dp[i][first]==-1)
	{
		int last=N-1-(i-first);
		ll frontMove=abs(arr[i].second-first);
		ll backMove=abs(arr[i].second-last);
		dp[i][first]=max(func(arr,N,i+1,first+1)+arr[i].first*frontMove,func(arr,N,i+1,first)+arr[i].first*backMove);
	}
	return dp[i][first];

}
int main() 
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   	int N;
   	cin>>N;
   	pair<ll,int> arr[N];
   	for(int i=0;i<N;i++)
   	{
   		cin>>arr[i].first;
   		arr[i].second=i;
   	}
   	for(int i=0;i<N;i++)
   		for(int j=0;j<N;j++)
   			dp[i][j]=-1;
   	sort(arr,arr+N,greater<pair<ll,int>>());
   	cout<<func(arr,N)<<endl;
}

Measured memory_bytes: 35076
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    int64_t n;
    cin >> n;
    for (int64_t i = 1; i < 10; i++) {
	    auto j = n / i;
        if (j < 10 && (i * j) == n) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

int main() {
  char c;
  cin >> c;
    
  if(c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') {
    cout << "vowel" << endl;
    }
  else {
    cout << "consonant" << endl;
  }
  
}

Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <math.h>

using namespace std;

int main() {
	int n, m;
	cin >>  n >> m;
	cout << (m + n) * (m + n - 1) / 2 - m * n << endl;

	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<unordered_set>
#include<map>
#include<unordered_map>
#include<cstring>
#include<complex>
#include<cmath>
#include<iomanip>
#include<numeric>
#include<algorithm>
#include<list>
#include<functional>
#include<cassert>
#define mp make_pair
#define pb push_back
#define X first
#define Y second
#define y0 y12
#define y1 y22
#define INF 987654321987654321
#define PI 3.141592653589793238462643383279502884
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset((a),0,sizeof(a));
#define MEM_1(a) memset((a),-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
#define SYNC ios_base::sync_with_stdio(false);cin.tie(0)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef tuple<int, int, int> iii;
typedef tuple<ll, ll, ll> LLL;
typedef vector<iii> Viii;
typedef vector<LLL> VLLL;
typedef complex<double> base;
const ll MOD = 1000000007;
ll POW(ll a, ll b, ll MMM = MOD) {ll ret=1; for(;b;b>>=1,a=(a*a)%MMM)if(b&1)ret=(ret*a)% MMM; return ret; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { if (a == 0 || b == 0)return a + b; return a*(b / gcd(a, b)); }
int dx[] = { 0,1,0,-1,1,1,-1,-1 }, dy[] = { 1,0,-1,0,1,-1,1,-1 };

int main() {
	SYNC;
	ll i,o,t,j,l,s,z;
	cin>>i>>o>>t>>j>>l>>s>>z;
	ll ans=o;
	if(i>0 && j>0 && l>0)
	{
		int c=(i&1)+(j&1)+(l&1);
		if(c>1)
		{
			ans+=3;
			i--,j--,l--;
		}
	}
	ans+=i/2*2;
	ans+=j/2*2;
	ans+=l/2*2;
	cout<<ans;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<ll, ll> LLP;

const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;
// const double PI = M_PI;

int V, E;
vector<vector<int> > d;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> E;
  d.resize(V, vector<int>(V, INF));
  rep(i, E) {
    int si, ti, di;
    cin >> si >> ti >> di;
    d[si][ti] = di;
  }

  int dp[1 << V][V];
  rep(i, 1 << V) { fill(dp[i], dp[i] + V, INF); }
  dp[0][0] = 0;

  rep(i, 1 << V) {
    rep(s, V) {
      rep(t, V) {
        if (s == t) {
          continue;
        }
        if ((i & (1 << t)) > 0) {
          continue;
        }
        if (d[s][t] == INF) {
          continue;
        }
        dp[i | (1 << t)][t] = min(dp[i | (1 << t)][t], dp[i][s] + d[s][t]);
      }
    }
  }

  if (dp[(1 << V) - 1][0] == INF) {
    cout << -1 << endl;
  } else {
    cout << dp[(1 << V) - 1][0] << endl;
  }
  return 0;
}



Measured memory_bytes: 5096
<?php
fscanf(STDIN, "%d", $n);
for ($i = 0; $i < $n; $i++) {
 fscanf(STDIN, '%s %d', $s, $p);
 $locations[] = $s;
 $points[] = $p;
 $saves[] = $i + 1;
}
array_multisort($locations, SORT_ASC, $points, SORT_DESC, $saves);

for ($i = 0; $i < $n; $i++) {
 echo $saves[$i] . "\n";
}


Measured memory_bytes: 4728
using System;

class Program
{
    static void Main(string[] args)
    {
        int n = Input.nextInt();
        int nowx = 0;
        int nowy = 0;
        int nowt = 0;
        int tmpx;
        int tmpy;
        int tmpt;
        for (int i = 0; i < n; i++)
        {
            tmpt = Input.nextInt();
            tmpx = Input.nextInt();
            tmpy = Input.nextInt();
            
            if (tmpt - nowt < Math.Abs(tmpx - nowx) + Math.Abs(tmpy - nowy) || ((tmpt - nowt) - (Math.Abs(tmpx - nowx) + Math.Abs(tmpy - nowy))) % 2 != 0)
            {
                Console.WriteLine("No");
                return;
            }
            nowx = tmpx;
            nowy = tmpy;
            nowt = tmpt;
        }
        Console.WriteLine("Yes");


    }

}


class Input
{
    static string[] line = { };
    static int index = 0;
    static void readLine()
    {
        line = Console.ReadLine().Split(' ');
        index = 0;
    }
    public static int nextInt()
    {
        if (index == line.Length)
        {

            readLine();
        }
        index++;
        return int.Parse(line[index - 1]);
    }
    public static long nextLong()
    {
        if (index == line.Length)
        {

            readLine();
        }
        index++;
        return long.Parse(line[index - 1]);
    }
    public static string next()
    {
        if (index == line.Length)
        {

            readLine();
        }
        index++;
        return line[index - 1];
    }
}




Measured memory_bytes: 15288
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;
ll MOD = 1000000000 + 7;

bool debug = 0;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = 1;
    if (n % 2) {
        if (a[0] != 0) ans = 0;
        for (int i = 1; i * 2 < n; i++) {
            if (a[i * 2 - 1] != i * 2) ans = 0;
            if (a[i * 2] != i * 2) ans = 0;
        }
    } else {
        for (int i = 0; i * 2 < n; i++) {
            if (a[i * 2] != i * 2 + 1) ans = 0;
            if (a[i * 2 + 1] != i * 2 + 1) ans = 0;
        }
    }
    for (int i = 0; i < n / 2; i++) {
        ans = (ans * 2) % MOD;
    }
    cout << ans << endl;
}

int main() {
    if (debug) {
        while (true) {
            cout << "********" << endl;
            solve();
        }
    } else {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3708
score = []
while True:
    n = int(raw_input())
    a = 0
    b = 0
    if n == 0:
        break
    for i in range(0, n):
        line = raw_input()
        (ta, tb) = map(int, line.strip().split())
        if ta > tb:
            a += ta + tb
        elif ta < tb:
            b += ta + tb
        elif ta == tb:
            a += ta
            b += tb
    score.append([a, b])
for (a, b) in score:
    print a, b

Measured memory_bytes: 6472
# Wrote in Feb 29, 2020 13:34 by reetok
require 'time'
def inp(type=:to_i,spst=" ")
  return eval("gets.chomp.split(#{spst}).map(&:#{type})")
end
def inpf() return self.inp(:to_f," ") end
def inps() return self.inp(:to_s," ") end
def r_up(a, b) (a/b).ceil end
def r_down(a, b) (a/b).floor end
def sum(a) a.inject(:+) end
def big(a,b) return (a>b)? a:b end
def small(a,b) return (a<b)? a:b end
def minp(n,datatype=:to_i)
  t = []
  n.times do
    t.push(eval("gets.chomp.#{datatype.to_s}"))
  end
end
def yes() puts "Yes" end
def no() puts "No" end
def ynju(bool,yes="Yes",no="No") puts (bool ? yes : no) end
#---------------

puts inp.sort.join(" ")


Measured memory_bytes: 7024
#pragma GCC optimize("Ofast,inline,unroll-loops,fast-math")
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <climits>
#define N 120
#define S 26
using namespace std;

char a[N];
int f[N][S];
int g[S][S], h[S];

int main(void)
{
    int n, k;
    int i, j, t, l;
    long long o;

    scanf("%s %d", a, &k);
    n = strlen(a);

    if(k == 1)
    {
        for(l = 0, o = n; l < S; l ++)
        {
            for(i = 0; i < S; i ++)
                f[0][i] = n;
            f[0][l] = l != a[0] - 97;
            for(i = 1; i < n; i ++)
                for(j = 0; j < S; j ++)
                    for(t = 0, f[i][j] = n; t < S; t ++)
                        if(j != t)
                            f[i][j] = min(f[i][j], f[i - 1][t] + (j != a[i] - 97));

            for(i = 0; i < S; i ++)
                o = min(o, (long long)f[n - 1][i]);
        }
        printf("%lld\n", o);
    }
    else
    {
        for(l = 0, o = LLONG_MAX; l < S; l ++)
        {
            for(i = 0; i < S; i ++)
                f[0][i] = n;
            f[0][l] = l != a[0] - 97;
            for(i = 1; i < n; i ++)
                for(j = 0; j < S; j ++)
                    for(t = 0, f[i][j] = n; t < S; t ++)
                        if(j != t)
                            f[i][j] = min(f[i][j], f[i - 1][t] + (j != a[i] - 97));
            for(i = 0; i < S; i ++)
                g[l][i] = f[n - 1][i];
        }
        for(i = 0; i < S; i ++)
            for(j = 0, h[i] = n; j < S; j ++)
                h[i] = min(h[i], g[j][i]);

        for(i = 0; i < S; i ++)
            for(j = 0; j < S; j ++)
                if(i != j)
                    for(t = 0; t < S; t ++)
                        if(j != t)
                            o = min(o, h[i] + (long long)(k - 1) * g[j][t]);

        for(i = 0; i < S; i ++)
            h[i] = g[i][i];
        sort(h, h + S);

        printf("%lld\n", min(o, (long long)h[0] * ((k + 1) / 2) + (long long)h[1] * (k / 2)));
    }

    return 0;
}


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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  cout << ((N - 1) % (K - 1) == 0 ? (N - 1) / (K - 1) : (N - 1) / (K - 1) + 1)
       << endl;
  return 0;
}

Measured memory_bytes: 640
open Batteries

let () = 
        Scanf.sscanf (read_line ()) "%d" (
        fun n -> 
                let a = n mod 10 in
                        if a = 2 || a = 4 || a = 5 || a = 7 || a = 9 then
                                "hon"
                        else if a = 0 || a = 6 || a = 1 || a = 8 then
                                "pon"
                        else
                                "bon"
        ) |> Printf.printf "%s\n"


Measured memory_bytes: 5336
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define FORR(x, arr) for(auto& x:arr)
#define ITR(x, c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;
typedef pair<int, int> P;

int c[5][5];

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	FOR(i, 3) FOR(j, 3) cin >> c[i][j];
	bool ok = true;
	FOR(i, 2) {
		FOR(j, 2) {
			if (c[i][j+1]-c[i][j]!=c[i+1][j+1]-c[i+1][j]) ok = false;
			if (c[j+1][i]-c[j][i]!=c[j+1][i+1]-c[j][i+1]) ok = false;
		}
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;
 
// 基本的な演算
namespace BasicMath {
    // 二つの値の最大値を求める関数
    static Int Max(const Int a, const Int b);
    // 絶対値を求める
    static UInt Abs(const Int a);
    // 二つの値の最大値を求める関数
    Int Max(const Int a, const Int b) {
        if (a >= b) {
            return a;
        } else {
            return b;
        }
    }
    // 絶対値を求める
    UInt Abs(const Int a) {
        return a > 0 ? a : -a;
    }
}
using namespace BasicMath;
 
int main(void) {
    Int a, b, c;
    cin >> a >> b >> c;
    Int d, e, f;
    d = Abs(b - a);
    e = Abs(c - b);
    f = Abs(a - c);
    Int maxAbs = Max(Max(d, e), f);
    cout << d + e + f - maxAbs << endl;
    return 0;
}

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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    string S, T;
    cin >> S >> T; 

    ll ans = 0;
    rep (i, 3) {
        if (S[i] == T[i]) {
            ans++;
        }
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<int(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define show(x) cout<< #x << " = " << x << endl
using namespace std;

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

int vx[]={0,0,-1,1};
int vy[]={1,-1,0,0};
int dx[]={1,0,-1,1,-1,1,0,-1};
int dy[]={1,1,1,0,0,-1,-1,-1};

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

const ll mod=998244353;
const int INF=INT_MAX/2;
const int N_MAX=100010;
const double PI=3.14159265359;

int main(){
	int A,B,M;
	cin>>A>>B>>M;
	int a[A], b[B];
	int x[M], y[M], c[M];
	int min_a = INT_MAX/2;
	int min_b = INT_MAX/2;
	REP(i,A){
		cin>>a[i];
		min_a = min(min_a, a[i]);
	}
	REP(i,B){
		cin>>b[i];
		min_b=min(min_b, b[i]);
	}
	REP(i,M){
		cin>>x[i]>>y[i]>>c[i];
		x[i]--; y[i]--;
	}
	int ans=INT_MAX/2;
	REP(i,M){
		ans=min(ans,a[x[i]]+b[y[i]]-c[i]);
	}
	ans=min(ans, min_a+min_b);
	cout<<ans<<endl;
}

Measured memory_bytes: 2176
/*
      HET PAGHADAR
      DA-IICT
      @HET262
*/
 
#include<bits/stdc++.h>
using namespace std;
 
typedef long double ld;
typedef long long ll;
 
typedef vector<ll> vec;
#define INF LLONG_MAX
 
#define P pair<ll,ll>
#define int long long int
 
#define ff first
#define ss second
 
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
 
#define N 100005
#define MOD 1000000007

ll n,kk;
ll a[105];
ll dp[N][2];

ll solve(ll k,bool curr)
{           
      ll &ans=dp[k][curr];
      if(ans!=-1)
            return ans;
      
      ans=0;
      for(int i=1;i<=n && k-a[i]>=0;i++)
      {
            bool flag=solve(k-a[i],1^curr);
            if(!flag)
                  ans=1;
      }
      
      return ans;
}

signed main()
{
      FAST;
      
      cin>>n>>kk;
      
      for(int i=1;i<=n;i++)
            cin>>a[i];
            
      memset(dp,-1,sizeof(dp));  
      bool ans=solve(kk,0);
      
      if(ans==1)
            cout<<"First\n";
      else
            cout<<"Second\n";
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    string S;cin >> S;
    int N = S.size();

    stack<char> s;
    int ans = 0;
    s.push('a');
    rep(i,N){
        char t = s.top();
        int tmp = t - '0';

        if(tmp + S[i] - '0' == 1){
            ans += 2;
            s.pop();
        }
        else{
            s.push(S[i]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 512
N = int(input())
MOD = 10**9 + 7

A = list(map(lambda x: int(x)%MOD, input().split()))
S = []

tmp_s = 0
for A_i in A[::-1]:
    tmp_s += A_i
    S.append(tmp_s%MOD)
S.pop(-1)
S = S[::-1]

ans = 0
for i in range(N-1):
    ans += (A[i] * S[i])%MOD
    ans = ans%MOD
print(ans)

Measured memory_bytes: 31608
#include <bits/stdc++.h>
using namespace std;
int main() {
  int x;
  cin >> x;
  int ans=1;
  for(int i=2; i<=40; i++){
    int p = i*i;
    for(int j=2; j<=10; j++){
      if(p>x) break;
      ans = max(ans, p);
      p *= i;
    } 
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i;
    long long int k = 1;
	int j;
	
	scanf("%d",&i);
	j = i;
	
	while(i > 0){
		k *= i;
		i--;
	}
	
	printf("%lld\n",k);
	
	return(0);
}

Measured memory_bytes: 592
A, B, M = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = list(map(int, input().split()))
ans = min(a_list)+ min(b_list)
for i in range(M):
  x, y, c = map(int, input().split())
  ans = min(ans, a_list[x-1] + b_list[y-1] - c)
print(ans)

Measured memory_bytes: 18612
#include <algorithm>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;

int maxRectangleArea(const vector<int>& heights) {
  const int n = heights.size();
  vector<int> L(n), R(n), stk;
  for (int i = 0; i < n; i++) {
    while (!stk.empty() && heights[stk.back()] >= heights[i]) {
      stk.pop_back();
    }
    L[i] = stk.empty() ? 0 : stk.back() + 1;
    stk.push_back(i);
  }
  stk.clear();
  for (int i = n - 1; i >= 0; i--) {
    while (!stk.empty() && heights[stk.back()] >= heights[i]) {
      stk.pop_back();
    }
    R[i] = stk.empty() ? n : stk.back();
    stk.push_back(i);
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, heights[i] * (R[i] - L[i] + 1));
  }
  return ans;
}

int main() {
  int H, W;
  while (cin >> H >> W) {
    vector<vector<int>> S(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
      string line;
      cin >> line;
      for (int j = 0; j < W; j++) {
        S[i][j] = line[j] == '#' ? 1 : 0;
      }
    }
    static int dp[4][2010][2010];
    memset(dp, 0, sizeof(dp));
    for (int f = 0; f < 4; f++) {
      int f0 = f / 2, f1 = f % 2;
      for (int i = 1; i < H; i++) {
        for (int j = W - 1; j >= 0; j--) {
          if ((S[i - 1][j] ^ f0) == (S[i][j] ^ f1)) {
            dp[f][i][j] = dp[f][i][j + 1] + 1;
          } else {
            dp[f][i][j] = 0;
          }
        }
      }
    }
    int ans = max(W, H);
    for (int j = 0; j < W; j++) {
      vector<int> widths;
      for (int i = 1; i < H; i++) {
        widths.push_back(dp[(S[i - 1][j] ^ 1) * 2 + (S[i][j] ^ 1)][i][j]);
      }
      ans = max(ans, maxRectangleArea(widths));
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 79104
#include <stdio.h>

int main(void) {

  while (1) {
    int i,j;
    int H, W;
    scanf("%d %d", &H, &W);

    if ((H == 0) && (W == 0))
      break;

    for (i = 0; i < H; i++) {
      for (j = 0; j < W; j++)
        printf("#");
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}

Measured memory_bytes: 572
import numpy as np
H,W=map(int,input().split(' '))
maze = [list(input()) for i in range(H)]
maze = (np.array(maze) == '.')*1
L=np.zeros((H,W),dtype=int)
R=np.zeros((H,W),dtype=int)
U=np.zeros((H,W),dtype=int)
D=np.zeros((H,W),dtype=int)
for i in range(W):
    if i==0:
        L[:,i]=maze[:,i]
        R[:,W-i-1]=maze[:,W-i-1]
    else:
        L[:,i]=(L[:,i-1]+1)*maze[:,i]
        R[:,W-i-1]=(R[:,W-i]+1)*maze[:,W-i-1]
for i in range(H):
    if i==0:
        U[i,:]=maze[i,:]
        D[H-i-1,:]=maze[H-i-1,:]
    else:
        U[i,:]=(U[i-1,:]+1)*maze[i,:]
        D[H-i-1,:]=(D[H-i]+1)*maze[H-i-1,:]
print(max(np.max(U+D+L+R-3),0))

Measured memory_bytes: 266544
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)
#define rrep(i, j, n) for (int i = (int)n - 1; j <= i; --i)

bool ok[10];
int main() {
  int n, k;
  cin >> n >> k;
  rep(i, 0, k) {
    int d;
    cin >> d;
    ok[d] = true;
  }

  auto check = [&](int m) {
    bool res = true;
    while (m > 0) {
      if (ok[m % 10]) res = false;
      m /= 10;
    }
    return res;
  };

  int ans = n;
  while (true) {
    if (check(ans)) {
      cout << ans << endl;
      return 0;
    }
    ++ans;
  }

  return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

int n;
ld dp[305][305][305];
bool mark[305][305][305];

ld solve(int i, int j, int k)
{
  if(i < 0 || j < 0 || k < 0 || (!i && !j && !k))
    return 0;
  ld &ans = dp[i][j][k];
  if(mark[i][j][k])
    return ans;
  mark[i][j][k] = 1;
  return ans = ((ld)i / n * solve(i - 1, j , k) + (ld)j / n * solve(i + 1, j - 1, k) + (ld)k / n * solve(i, j + 1, k - 1) + 1) /
                (1 - ((ld)(n - i - j - k)) / n);
}

int main()
{
  cin >> n;
  int arr[3] = {};
  for(int i = 0; i < n; i++)
  {
    int x;
    cin >> x;
    arr[x - 1]++;
  }
  cout << fixed << setprecision(12) << solve(arr[0], arr[1], arr[2]);
  return 0;
}


Measured memory_bytes: 465152
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <bitset>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<P> vp;
#define rep(i,a,n) for(ll i = (a);i < (n);i++)
#define per(i,a,n) for(ll i = (a);i > (n);i--)
#define lep(i,a,n) for(ll i = (a);i <= (n);i++)
#define pel(i,a,n) for(ll i = (a);i >= (n);i--)
#define clr(a,b) memset((a),(b),sizeof(a))
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define sz size()
#define endl "\n"
#define print(X) cout << (X) << "\n"
// // #define input(X) getline(cin,X)
static const int INF = 1e+9+7;
static const ll INFL = 1e+18+7;
ll n,m,l;
string s,t;
ll d[200010],e[200010],dp[1001][1001];
char field[200][200];

int main(){
  cin >> n;
  if(n == 3 || n == 5 || n == 7)puts("YES");
  else puts("NO");
  return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a, b = n.times.map{gets.split.map(&:to_i)}.transpose
cnt = 0
flg = false
n.times do |i|
  if a[i] == b[i]
    cnt += 1
    if cnt == 3
      flg = true
    end
  else
    cnt = 0
  end
end
if flg
  puts "Yes"
else
  puts "No"
end

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

using namespace std;
typedef long long ll;

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];

    for (int i = 0; i < k; i++) {
        vector<ll> c_sum(n + 1);
        for (int j = 0; j < n; j++) {
            c_sum[max((ll) 0, j - a[j])]++;
            c_sum[min((ll) n, j + a[j] + 1)]--;
        }
        for (int j = 0; j < n; j++)c_sum[j + 1] += c_sum[j];
        c_sum.pop_back();

        if (a == c_sum)break;
        a = c_sum;
    }

    for (int i = 0; i < n; i++) {
        if (i > 0)cout << " ";
        cout << a[i];
    }
    return 0;
}

Measured memory_bytes: 6376
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef ::std::int_fast64_t i64;
typedef ::std::uint_fast64_t u64;
typedef ::std::int_fast32_t i32;
typedef ::std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(::std::istream& is, ::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    vector.reserve(size);
    ::std::copy_n(::std::istream_iterator<T>(is), size, ::std::back_inserter(vector));
  }
  template <typename T>
  void read(::std::vector<T>& vector, const typename ::std::vector<T>::size_type size) {
    ::tools::read(::std::cin, vector, size);
  }

  template <typename T, ::std::size_t N>
  void read(::std::istream& is, ::std::array<T, N>& array) {
    ::std::copy_n(std::istream_iterator<T>(is), N, array.begin());
  }
  template <typename T, ::std::size_t N>
  void read(::std::array<T, N>& array) {
    ::tools::read(::std::cin, array);
  }
}

#endif

// main.cpp

enum class Piece { UNDEF, A, BC };

class Chunk {
public:
  std::vector<i64> A;
  std::vector<i64> BC;
};

int main() {
  std::string s;
  std::cin >> s;
  const i64 N = s.size();

  std::vector<std::vector<Piece>> chunks1;
  chunks1.emplace_back();
  for (i64 i = 0; i < N; ++i) {
    if (s[i] == 'A') {
      chunks1.back().push_back(Piece::A);
    } else if (i + 1 < N && s[i] == 'B' && s[i + 1] == 'C') {
      chunks1.back().push_back(Piece::BC);
      ++i;
    } else if (!chunks1.back().empty()) {
      chunks1.emplace_back();
    }
  }
  if (chunks1.back().empty()) {
    chunks1.pop_back();
  }

  std::vector<Chunk> chunks2;
  for (std::vector<Piece>& from_chunk : chunks1) {
    chunks2.emplace_back();
    Chunk& to_chunk = chunks2.back();

    Piece prev_piece = Piece::UNDEF;
    auto it = from_chunk.begin();
    Piece piece;
    for (; it != from_chunk.end(); prev_piece = piece, ++it) {
      piece = *it;
      if (piece == prev_piece) {
        switch (piece) {
        case Piece::A:
          ++to_chunk.A.back();
          break;
        case Piece::BC:
          ++to_chunk.BC.back();
          break;
        default:
          return EXIT_FAILURE;
        }
      } else {
        switch (piece) {
        case Piece::A:
          if (to_chunk.A.empty() && prev_piece == Piece::BC) {
            to_chunk.BC.pop_back();
          }
          to_chunk.A.push_back(1);
          break;
        case Piece::BC:
          to_chunk.BC.push_back(1);
          break;
        default:
          return EXIT_FAILURE;
        }
      }
    }

    if (to_chunk.A.size() > to_chunk.BC.size()) {
      to_chunk.A.pop_back();
    }
  }

  i64 answer = 0;
  for (Chunk chunk : chunks2) {
    std::vector<i64> partial_sum_A;
    std::partial_sum(chunk.A.begin(), chunk.A.end(), std::back_inserter(partial_sum_A));
    for (auto it1 = partial_sum_A.begin(), it2 = chunk.BC.begin(); it1 != partial_sum_A.end() && it2 != chunk.BC.end(); ++it1, ++it2) {
      answer += *it1 * *it2;
    }
  }

  std::cout << answer << std::endl;
  return 0;
}

Measured memory_bytes: 9016
#include <iostream>
#include <cstdio>
#include <string>
#include <sstream>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>

#define PI 3.14159265359

#define INF 99999999;

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

typedef long long ll;

using namespace std;



/*
class LightSwitchingPuzzle
{
public:
	int minFlips(string s)
	{

	}
}
*/


int main()
{
	int n, p, d1, d2, max_p, max_d;
	
	while (cin >> n, n)
	{
		max_d = 0;
		
		REP(n)
		{
			cin >> p >> d1 >> d2;
			if (d1 + d2 > max_d)
			{
				max_d = d1 + d2;
				max_p = p;
			}
		}
		
		cout << max_p << " " << max_d << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include <iostream>

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

    char mark;
    int num;

    int array[52] = {};






    for (int i = 0; i < n; i++) {
        std::cin >> mark;
        std::cin >> num;

        if (mark == 'S') {
            num -= 1;
        } else if (mark == 'H') {
            num += 12;
        } else if (mark == 'C') {
            num += 25;
        } else if (mark == 'D') {
            num += 38;
        } else {
            std::cout << "S, H, C, D for mark" << std::endl;
        }

        array[num] = 1;
    }

    for (int i = 0; i < 52; i++) {
        if (array[i] != 1) {
            if (i < 13) {
                std::cout << "S " << i+1 << std::endl;
            } else if (i < 26) {
                std::cout << "H " << i-12 << std::endl;
            } else if (i < 39) {
                std::cout << "C " << i-25 << std::endl;
            } else {
                std::cout << "D " << i-38 << std::endl;
            }
        }
    }

    return 0;
}

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


void solve(ll N, ll K, std::vector<ll> A){
  vector<ll> v(N, 0);
  rep(i, K) {
    vector<ll> v(N+1);
    rep(j, N) {
      int l = max(0, j-(int)A[j]);
      int r = min((int)N, j+(int)A[j]+1);
      v[l]++;
      v[r]--;
    }

    rep(j, N) v[j+1] += v[j];
    v.pop_back();
    if (A == v) break;
    A = v;
  }

  rep(i, N) cout << A[i] << endl;
}

int main(){
  ll N;
  scanf("%lld",&N);
  ll K;
  scanf("%lld",&K);
  std::vector<ll> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  solve(N, K, std::move(A));
  return 0;
}


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

int main() {
    int sum = 0, naname = 0;
    rep(i, 3) {
        rep(j, 3) {
            int a;
            cin >> a;
            sum += a;
            if (i == j)
                naname += a;
        }
    }
    if (sum % 3 == 0 && sum / 3 == naname)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

int N, M, C;
vector<vector<int>> A;
vector<int> B; 

int main() {
  cin >> N >> M >> C;
  B.resize(M);
  for (int i = 0; i < M; i++) cin >> B[i];
  A.resize(N, vector<int>(M));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++) {
      cin >> A[i][j];
    }
  }


  int cnt = 0;
  for (int i = 0; i < N; i++) {
    int re = 0;
    for (int j = 0; j < M; j++) {
      re += A[i][j] * B[j];
    }
    re += C;
    if (re > 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 100010

int Map[MAX];

int MaxSix(int i) {
	int k = 6;
	int min = MAX;
	while (i - k >= 0) {
		if (Map[i - k] < min)min = Map[i - k];
		k *= 6;
	}
	return min;
}

int MaxNine(int i) {
	int k = 9;
	int min = MAX;
	while (i - k >= 0) {
		if (Map[i - k] < min)min = Map[i - k];
		k *= 9;
	}
	return min;
}

int Minimum(int a, int b, int c) {
	if (a <= b && a <= c)return a;
	else if (b <= c)return b;
	else return c;
}

int main() {
	int N;
	Map[1] = 1; Map[2] = 2; Map[3] = 3; Map[4] = 4;
	Map[5] = 5; Map[6] = 1; Map[7] = 2; Map[8] = 3;
	Map[9] = 1; Map[10] = 2;
	scanf("%d", &N);

	for (int i = 11; i <= N; i++) {
		Map[i] = Minimum(MaxNine(i), MaxSix(i), Map[i - 1]) + 1;
	}

	printf("%d\n",Map[N]);

	return 0;
}

Measured memory_bytes: 512