akhauriyash/Code-Regression huggingface dataset:
import java.util.Arrays;
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int W = scanner.nextInt();

    long[] w = new long[N];
    long[] v = new long[N];

    for (int i = 0; i < N; i++) {
      w[i] = scanner.nextInt();
      v[i] = scanner.nextInt();
    }

    long[][] vw = new long[4][N + 1];
    int[] idx = new int[4];
    for (int i = 0; i < N; i++) {
      int d = (int) (w[i] - w[0]);
      vw[d][idx[d]++] = v[i];
    }
    for (int i = 0; i < 4; i++) {
      Arrays.sort(vw[i]);
      reverse(vw[i], 1, N);
      for (int j = 1; j < N + 1; j++) vw[i][j] += vw[i][j - 1];
    }

    long max = 0;
    for (int a = 0; a <= N; a++) {
      for (int b = 0; b <= N - a; b++) {
        for (int c = 0; c <= N - a - b; c++) {
          for (int d = 0; d <= N - a - b - c; d++) {
            long tw = w[0] * a + (w[0] + 1) * b + (w[0] + 2) * c + (w[0] + 3) * d;
            long tv = vw[0][a] + vw[1][b] + vw[2][c] + vw[3][d];
            if (tw > W) continue;
            max = Math.max(max, tv);
          }
        }
      }
    }
    System.out.println(max);
  }

  private static void swap(long[] a, int i, int j) {
    long tmp = a[i];
    a[i] = a[j];
    a[j] = tmp;
  }

  private static void reverse(long[] a, int i, int j) {
    if (i > j) throw new IllegalArgumentException("i must be less than j");
    while (i < j) {
      swap(a, i, j);
      i++;
      j--;
    }
  }
}


Measured memory_bytes: 22228
#include<stdio.h>
int main()
{
    int a[4],i,max=-99999999,min=9999999,mid,s=0;
    scanf("%d%d%d",&a[0],&a[1],&a[2]);
    for(i=0;i<3;i++)
    {
        if(a[i]>max)
            max=a[i];
        if(a[i]<min)
            min=a[i];
    }
    s=(max-min);
    printf("%d\n",s);
    return 0;


}


Measured memory_bytes: 128
#include <iostream>
#define llint long long

using namespace std;

llint n;
llint a[100005];

int main(void)
{
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> a[i];
	
	llint ans = 0, mul = 1;
	bool update = true, flag;
	while(update){
		flag = false, update = false;
		for(int i = 1; i <= n; i++){
			if(a[i] <= mul){
				flag = false;
				continue;
			}
			if(!flag){
				flag = true;
				ans++, update = true;
			}
			else{
				if(a[i] < mul*2) flag = false;
			}
		}
		mul *= 2;
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1024
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|i| i.parse().ok().unwrap())
        .collect()
}

fn main() {
	let input = read_vec::<i32>();
    if input[0] == input[1] {
    	println!("Yes");
    } else {
    	println!("No");
    }
}

Measured memory_bytes: 4352
#pragma warning disable IDE1006
#pragma warning disable IDE0011
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using static System.Convert;
using static System.Math;
using static Extentions;

class IO
{
    int idx;
    string[] line;

    public void R(params char[] sep) { line = Console.ReadLine().Split(sep); idx = 0; }
    public string S => line[idx++];
    public string[] Ss => line.Skip(idx++).ToArray();
    public char C => char.Parse(line[idx++]);
    public char[] Cs => line.Skip(idx++).Select(char.Parse).ToArray();
    public int I => int.Parse(line[idx++]);
    public int[] Is => line.Skip(idx++).Select(int.Parse).ToArray();
    public long L => long.Parse(line[idx++]);
    public long[] Ls => line.Skip(idx++).Select(long.Parse).ToArray();
    public double F => double.Parse(line[idx++]);
    public double[] Fs => line.Skip(idx++).Select(double.Parse).ToArray();
    public decimal D => decimal.Parse(line[idx++]);
    public decimal[] Ds => line.Skip(idx++).Select(decimal.Parse).ToArray();
    public BigInteger B => BigInteger.Parse(line[idx++]);
    public BigInteger[] Bs => line.Skip(idx++).Select(BigInteger.Parse).ToArray();

    public void Write<T>(params T[] xs)
    {
        Console.Write(xs.First());
        foreach (var x in xs.Skip(1)) Console.Write(" " + x);
        Console.WriteLine();
    }
    public void Write(params object[] xs)
    {
        Console.Write(xs.First());
        foreach (var x in xs.Skip(1)) Console.Write(" " + x);
        Console.WriteLine();
    }
}

static class Extentions
{
}

static class Program
{
    public static void Main()
    {
#if !DEBUG
        Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });
#endif
        Solve(new IO());
        Console.Out.Flush();
    }

    public static void Solve(IO io)
    {
        io.R();
        var a = io.I;
        var b = io.I;

        if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) io.Write("Possible");
        else io.Write("Impossible");
    }
}

Measured memory_bytes: 13396
import math
k = int(input())
ans = 0
ab = {}

for a in range(1,k+1):
  for b in range(1,k+1):
    tmp = math.gcd(a, b)
    if tmp not in ab:
      ab[tmp] = 1
    else:
      ab[tmp] += 1

for c in range(1,k+1):
  for d in ab.keys():
    ans += math.gcd(c, d) * ab[d]

print(ans)

Measured memory_bytes: 9172
#include <iostream>
#include <string>
using namespace std;
const int MAXN=1e5+100;
int a[MAXN]={0};
int N;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        int tmp;
        cin>>tmp;
        a[++tmp]=i;
    }
    for(int i=2;i<N+1;i++)
        cout<<a[i]<<' ';
    cout<<a[N+1];
    cout<<endl;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    map<string, string> mp;
    mp["Sunny"] = "Cloudy";
    mp["Cloudy"] = "Rainy";
    mp["Rainy"] = "Sunny";
    string s;
    cin >> s;
    cout << mp[s];
    return 0;
}


Measured memory_bytes: 256
// 2019/06/20
// AtCoder Beginner Contest 077 - B

#include <bits/stdc++.h>
using namespace std;

int main() {
    int n, wn, i, ans;
    cin >> n;
    i = 0;
    while(wn < n){
        i += 1;
        wn = i * i;
    }
    if(wn > n){
        ans = (i - 1) * (i - 1);
    } else {
        ans = wn;
    }
    cout << ans;
}


Measured memory_bytes: 256
import bisect
import copy
import heapq
import math
import sys
from collections import *
from itertools import accumulate, combinations, permutations, product
from math import gcd
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

a,b,c,d=map(int,input().split())

cnt=0
while a>0 and c>0:
    if cnt%2==0:
        c-=b
    else:
        a-=d
    if a<=0:
        print("No")
    elif c<=0:
        print("Yes")
    cnt+=1

Measured memory_bytes: 68952
#include<iostream>
#include<deque>
using namespace std;
int main(){
	int n;
	cin >> n;
	deque<char> s,t;
	for(int i=0;i<n;i++){
		char c;
		cin >> c;
		s.push_back(c);
		t.push_back(c);
	}
	for(int i=0;i<s.size()-1;i++){
		if(s[i]=='(' && s[i+1]==')'){
			s.erase(s.begin()+i,s.begin()+i+2);
			i=-1;
		}
		if(s.size()==0) break;
	}
	int l=0,r=0;
	for(int i=0;i<s.size();i++){
		if(s[i]==')') l++;
		else r++;
	}
	for(int i=0;i<l;i++) t.push_front('(');
	for(int i=0;i<r;i++) t.push_back(')');
	for(int i=0;i<t.size();i++) cout << t[i];
	cout << endl;
	
}


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

#define pb push_back
#define mp make_pair

using namespace std;

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


int DP[100005][3];
int V[100005][3];
bool ok[100005][3];
int N;

int dp(int i, int m) {
    if (ok[i][m]) {
        return DP[i][m];
    }
    
    if (i == N+1) {
        return 0;
    } else {
        int res = 0;
        if (m == 0) {
            res = max(dp(i+1, 1) + V[i][1], dp(i+1, 2) + V[i][2]);
        } else if (m == 1) {
            res = max(dp(i+1, 0) + V[i][0], dp(i+1, 2) + V[i][2]);
        } else {
            res = max(dp(i+1, 0) + V[i][0], dp(i+1, 1) + V[i][1]);
        }
        
        ok[i][m] = true;
        DP[i][m] = res;
        return DP[i][m];
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    
    cin >> N;
    
    for (int i = 1; i <= N; ++i) {
        cin >> V[i][0] >> V[i][1] >> V[i][2];
    }
    
    int res = 0;
    res = dp(1, 1);
    memset(DP, 0, sizeof(DP));
    memset(ok, 0, sizeof(ok));
    res = max(res, dp(1, 2));
    memset(DP, 0, sizeof(DP));
    memset(ok, 0, sizeof(ok));
    res = max(res, dp(1, 3));
    
    cout << res << endl;
    
	return 0;
}

Measured memory_bytes: 12508
import java.util.Scanner;

public class Main {
    
    private static final int N = 50000;
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String c = s.nextLine();
        if (Character.isUpperCase(c.charAt(0))) {
           System.out.println("A");
        } else {
            System.out.println("a");
        }
    }
}


Measured memory_bytes: 26920
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n, k;
  cin >> n >> k;

  n += 2;
  vll hs(n, 0);
  rep(i, n - 1) cin >> hs[i + 1];
  hs[n - 1] = 0;

  vvll con(n, vll(n));
  rep(ii, n - 1) {
    repLRE(jj, ii + 1, n - 1) {
      con[ii][jj] = con[ii][jj - 1];
      if (hs[ii] != hs[jj]) con[ii][jj]++;
    }
  }

  vvll dp(n, vll(k + 1, INF));
  rep(kk, k + 1) dp[0][kk] = 0;
  repLRE(ii, 1, n - 1) {
    dp[ii][0] = dp[ii - 1][0] + max(0LL, hs[ii] - hs[ii - 1]);
    rep(kk, k + 1) {
      rep(jj, ii) {
        ll nkk = kk - con[jj][ii - 1];
        if (nkk >= 0)
          chmin(dp[ii][kk], dp[jj][nkk] + max(0LL, hs[ii] - hs[jj]));
      }
    }
  }

  cout << dp.back().back() << endl;

  return 0;
}


Measured memory_bytes: 5052
import java.io.*;
import java.util.*;

public class Main{
	public static void main(String[] args){
		solve();
	}
	public static void solve(){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		if(n.charAt(0)==n.charAt(1) && n.charAt(1)==n.charAt(2)){
			System.out.println("Yes");
		}
		else if(n.charAt(1)==n.charAt(2) && n.charAt(2)==n.charAt(3)){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}
	}
}


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

const string seg[] = {"0111111", "0000110",
		      "1011011", "1001111",
		      "1100110", "1101101",
		      "1111101", "0100111",
		      "1111111", "1101111"};

int main()
{
  int n;
  while (cin >> n) {
    if (n == -1)
      break;

    string s = "0000000";
    while (n--) {
      int d;
      cin >> d;
      for (int i = 0; i < 7; ++i) {
	if (s[i] == seg[d][i])
	  cout << "0";
	else
	  cout << "1";
      }
      cout << endl;
      s = seg[d];
    }
  }
  return 0;
}

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

using namespace std;

#define all(c) (c).begin(), (c).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

int dp[1003][1003];
int N, K;
int dfs(int idx, int pre) {
    if (N == idx) return 1;
    if (pre != -1 && dp[idx][pre] != -1) return dp[idx][pre];
    int ret = 0;
    rep(i, K) if (pre != i) { ret += dfs(idx + 1, i); }
    return dp[idx][pre] = ret;
}

int main() {
    memset(dp, -1, sizeof(dp));
    cin >> N >> K;
    cout << dfs(0, -1) << endl;

    return 0;
}


Measured memory_bytes: 4224
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        string n = Console.ReadLine();
        int sum = 0;
        for (int i = 0; i < n.Length; i++)
        {
            sum += int.Parse(n[i].ToString());
        }
        if (long.Parse(n) % sum == 0) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }
}

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

#define true 1
#define false 0

typedef struct {
  int y, x;
} P;

typedef struct node {
  P p;
  struct node *next;
} list;

_Bool empty(list **q) {
  return *q == NULL;
}

void push(list **q, P p) {
  list *ptr, *n = (list*)malloc(sizeof(list));
  n->p = p;
  n->next = NULL;
  if (*q == NULL) {
    *q = n;
  } else {
    for (ptr = *q; ptr->next != NULL; ptr = ptr->next);
    ptr->next = n;
  }
}

P front(list **q) {
  P ret;
  list *n;
  ret = (*q)->p;
  n = (*q)->next;
  free(*q);
  *q = n;

  return ret;
}

_Bool inside(int y, int x, int h, int w) {
  return 0 <= y && 0 <= x && y < h && x < w;
}

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

int main(void) {
  while (true) {
    int i, j;
    int res = 0;
    int field[20][20];
    for (i = 0; i < 12; ++i) {
      for (j = 0; j < 12; ++j) {
        if (scanf("%1d", &field[i][j]) == EOF) return 0;
      }
    }

    for (i = 0; i < 12; ++i) {
      for (j = 0; j < 12; ++j) {
        if (!field[i][j]) continue;
        list *q = NULL;
        push(&q, (P){i, j});
        field[i][j] = 0;
        while (!empty(&q)) {
          int k;
          P t = front(&q);
          for (k = 0; k < 4; ++k) {
            int ny = t.y + dy[k], nx = t.x + dx[k];
            if (!inside(ny, nx, 12, 12)) continue;
            if (!field[ny][nx]) continue;
            field[ny][nx] = 0;
            push(&q, (P){ny, nx});
          }
        }
        ++res;
      }
    }
    printf("%d\n", res);
    scanf("%*c");
  }

  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
using namespace std;
 
void solve() {
    int n; cin >> n;
    double a[n+1];
    for(int i = 1; i <= n; i++) cin >> a[i];
    double dp[n+5][n+5];
    memset(dp,0,sizeof(dp));
    dp[0][0] = 1;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= i; j++) {
            if(j == 0) dp[i][j] = dp[i-1][j]*(1-a[i]);
            else dp[i][j] = dp[i-1][j-1]*a[i]+dp[i-1][j]*(1-a[i]);
        }
    }
    double ans = 0;
    for(int i = 1; i <= n; i++) {
        if(i > n-i)ans += dp[n][i];
    }
    cout << fixed << setprecision(15) << ans;
}
int main()
{
  solve();
  return 0;
}

Measured memory_bytes: 70784
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    int H, W;
    cin >> H >> W;
    vector<vector<string> > s(H, vector<string>(W));
    REP(i, H)REP(j, W) cin >> s[i][j];
    REP(i, H){
        REP(j, W){
            if(s[i][j] == "snuke"){
                cout << (char)('A'+j) << i+1 << "\n";
                return 0;
            }
        }
    }
    return 0;
}

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

double a,b,c,d,e,f;

int main(void){
	//cin>>a>>b>>c>>d>>e>>f;
	while(cin>>a>>b>>c>>d>>e>>f){
		double x,y;
		/*
		ax+by=c;
		dx+ey=f;
		ax=c-by;
		x=(c-by)/a;
		d(c-by)/a+ey=f;
		dc/a-dby/a+ey=f;
		-dby/a+ey=f-dc/a;
		(e-db/a)y=f-dc/a;
		y=(f-dc/a)/(e-db/a);
		y=(fa-dc)/(ae-db)
		x=(c-by)/a;
		*/
		y=(f*a-d*c)/(a*e-d*b);
		x=(c-b*y)/a;
		cout<<fixed<<setprecision(3);
		cout<<x<<" "<<y<<endl;
	}
		//cin>>a;
}

Measured memory_bytes: 1280
import numpy as np

D = int(input())
Cs = list(map(int, input().split()))
Ss = []
for d in range(D):
    s = list(map(int, input().split()))
    Ss.append(s)

Ss = np.array(Ss)

solution = np.argmax(Ss, axis=1)
#
# days_till_next = np.ones_like(Ss) * (D - 1) - np.arange(D).reshape((D, 1))
#
#
# def update_days_till_next(d):
#     contest = solution[d]
#     for _d in range(d - 1, -1, -1):
#         if solution[_d] == contest or _d == 0:
#             days_till_next[_d:d, contest] -= days_till_next[d, contest]
#             break
#
#
# for d in range(D - 1, -1, -1):
#     update_days_till_next(d)
#
# for _ in range(10):
#     n_contests = len(Ss[0])
#     days_since_last = np.zeros(n_contests)
#     for d, i in enumerate(solution):
#         days_since_last += 1
#         new_scores = days_till_next[d] * days_since_last[d] * Cs + Ss[d]
#         new_i = new_scores.argmax()
#         days_since_last[new_i] = 0
#         if new_i != i:
#             solution[d] = new_i
#             update_days_till_next(d)
#

for s in solution:
    print(s + 1)


Measured memory_bytes: 27412
#include <iostream>
#include <algorithm>
#include<string>
#include<cmath>
#include<stack>
#include<queue>
using namespace std;


int main() {
	int a, b, c, x, ans = 0;
	cin >> a >> b >> c >> x;
	int fa = 1, fb = 1, fc = 1;
	for (int i = 0; i <= a ; i++) {
		for (int j = 0; j <= b ; j++) {
			for (int k = 0; k <= c ; k++) {
				if (500 * i + 100 * j + 50 * k == x) {
					ans++;
				}
			}
		}
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
//#define MOD 1000000007
#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;

int dp[10010];

int main(){
    int H,N; cin >> H >> N;
    vector<int> A(N),B(N);
    rep(i,N) cin >> A[i] >> B[i];
    rep(i,10010) dp[i] = INF;
    dp[0] = 0;
    rep(i,N)rep(j,H+1){
        if(j >= A[i]) dp[j] = min(dp[j],dp[j-A[i]]+B[i]);
        if(j == H) repr(k,max(0,j-A[i]),j) dp[j] = min(dp[j],dp[k]+B[i]);
    }
    cout << dp[H] << endl;
}



Measured memory_bytes: 256
# https://onlinejudge.u-aizu.ac.jp/courses/library/4/CGL/all/CGL_3_C
# 本の説明を図に書き出してみるとよく理解できる。
from math import sqrt


class Vector:
    def __init__(self, ls):
        '''
        ls ... list
        '''
        self.vec = ls

    def __len__(self):
        return len(self.vec)

    def __getitem__(self, idx):
        return self.vec[idx]

    def __repr__(self):
        return f'Vector({self.vec})'

    def add(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a + b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def sub(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a - b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def mul(self, vec):
        '''
        vec ... vector class
        '''
        assert len(self) == len(vec)
        ret = [a * b for a, b in zip(self.vec, vec.vec)]
        return Vector(ret)

    def norm(self):
        tmp = sum([x * x for x in self.vec])
        return sqrt(tmp)


def norm(vec):
    '''
    vec ... Vector class
    '''
    return vec.norm()


def cross(a, b):
    '''
    Outer product for 2d
    a,b ... Vector class
    '''
    assert len(a) == 2 and len(b) == 2
    first = a[0] * b[1]
    second = a[1] * b[0]
    return first - second


def dot(a, b):
    return sum(a.mul(b))


EPS = 1e-10


def contains(G, p):
    '''
    Gは多角形を表すリストで、今回ならばvectorが中に並んでいることとする
    pは内容しているか判別したい点で、Vectorで表す

    pが多角形Gの辺上にあれば1
    pが多角形Gに内包されていれば2
    それ以外は0をreturnする
    '''
    is_contain = False  # 内包してるか
    for i in range(len(G)):
        a = G[i].sub(p)
        b = G[(i + 1) % len(G)].sub(p)  # i+1が0に戻るようにこのような形式にしている。
        # もしpがG[i]とG[i+1]の線分上にある場合は即座に1をreturnします
        if abs(cross(a, b)) < EPS and dot(a, b) < EPS:
            # 外積が0→a,bが同一直線上
            # かつ 内積が負→a,bは逆を向いている
            # ならばpは線分上に存在する
            return 1
        # 内包を判定する。前処理として、yの座標によってa,bを入れ替える
        if a[1] > b[1]:  # aの方のy座標を小さくしたい
            a, b = b, a
        if a[1] < EPS and b[1] > EPS and cross(a, b) > EPS:  # 実際に判別する
            is_contain = (not is_contain)
    return (0, 2)[is_contain]  # 書き方キモいけど三項演算子の短い書き方


# load data
N = int(input())
G = []
for _ in range(N):
    g = Vector(list(map(int, input().split())))
    G.append(g)

# answer query
Q = int(input())
for _ in range(Q):
    p = Vector(list(map(int, input().split())))
    print(contains(G, p))


Measured memory_bytes: 5760
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int M=200005;
int n,a[M];
int ans[M];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	if(n&1){
		int l=n/2+1,r=n/2+2;
		for(int i=1;i<=n;i+=2)ans[l--]=a[i];
		for(int i=2;i<=n;i+=2)ans[r++]=a[i];
	}else {
		int l=n/2+1,r=n/2;
		for(int i=1;i<=n;i+=2)ans[l++]=a[i];
		for(int i=2;i<=n;i+=2)ans[r--]=a[i];
	}
	for(int i=1;i<=n;i++)printf("%d ",ans[i]);putchar('\n');
	return 0;
}

Measured memory_bytes: 3712
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    N, M = LI()
    KA = []
    [KA.append(LI()) for i in range(N)]

    result = 0
    for i in KA[0][1:]:
        if all([i in j[1:] for j in KA]):
            result += 1

    print(result)

main()


Measured memory_bytes: 6724
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0].split(" ")[0]);
  var K = parseInt(input[0].split(" ")[1]);
  var d = new Array([0,K]);
  for(var i=1;K>=1;i++){
    K=K/2;
    d.push([i,Math.ceil(K)]);
  }
  var ans=0;
  var N2=N;
  for(var i=0;i<d.length;i++){
    if(N>=d[i][1]){
      p=(N-d[i][1]+1)*(1/N2)*Math.pow(1/2,d[i][0]);
      ans+=p;
      N=N-(N-d[i][1]+1);
    }
  }
  console.log('%s', ans);
  return ans;
}

function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 21064
#include<stdio.h>
int main()
{
	char s[1003], t[1003];
	scanf("%s%s", s, t);
	int n, m, i, j;
	n = 0;
	while (s[n] != '\0')
		n++;
	m = 0;
	while (t[m] != '\0')
		m++;
	int ans = m, cnt;
	for (i = 0; i <= n - m; i++)
	{
		cnt = 0;
		for (j = 0; j < m; j++)
			if (s[i + j] != t[j])
				cnt++;
		if (ans > cnt)
			ans = cnt;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1724
#!/usr/bin/env python3

'''
Author: andyli
Time: 2020-07-25 19:57:00
'''

import os
from io import BytesIO, IOBase
import sys


def main():
    n = int(input())
    if n in range(400,600): print(8)
    elif n in range(600,800): print(7)
    elif n in range(800,1000): print(6)
    elif n in range(1000,1200): print(5)
    elif n in range(1200,1400): print(4)
    elif n in range(1400,1600): print(3)
    elif n in range(1600,1800): print(2)
    elif n in range(1800,2000): print(1)
    
    return


# region fastio
BUFSIZE = 1048576


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = 'x' in file.mode or 'r' not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b'\n') + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode('ascii'))
        self.read = lambda: self.buffer.read().decode('ascii')
        self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
def input(): return sys.stdin.readline().rstrip('\r\n')

# endregion


if __name__ == '__main__':
    main()


Measured memory_bytes: 62928
/*
hon when the digit in the one's place of N is 2, 4, 5, 7, or 9
;
pon when the digit in the one's place of N
is 0, 1, 6 or 8
;
bon when the digit in the one's place of N
is 3.
*/

#include<bits/stdc++.h>
using namespace std;

signed main()
{
	int n ;cin>>n;
  	map<int,string> m ;
  	m[3] = "bon";
  	m[0] =  "pon"; m[1] = "pon";m[6] = "pon";m[8] = "pon";
  	m[2] = "hon";m[4] = "hon";m[5] = "hon";m[7] = "hon";m[9] = "hon";
	cout<<m[n%10]<<endl; 

}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)

constexpr ll mod = 1000000000 + 7;

ll dp[200][10];

void init() {
    rep(i, 0, 200) rep(j, 0, 10) dp[i][j] = 0;
}

int main(){

    init();

    // input
    ll h, w, k;
    cin >> h >> w >> k;

    // dp
    dp[0][0] = 1;
    rep(i, 0, h) {
        rep(j, 0, w) {
            for(int bit = 0; bit < (1<<(w-1)); bit++) {
                bool f = true;
                rep(k, 0, w-2) {
                    if((bit & (1<<k)) && (bit & (1<<(k+1)))) f = false;
                }
                if(!f) continue;
                if(j >= 1 && (bit & (1 << (j-1) ) ) ) {
                    dp[i+1][j-1] += dp[i][j];
                    dp[i+1][j-1] %= mod;
                }else if(j <= w-2 && (bit & (1<<j) ) ) {
                    dp[i+1][j+1] += dp[i][j];
                    dp[i+1][j+1] %= mod;
                }else{
                    dp[i+1][j] += dp[i][j];
                    dp[i+1][j] %= mod;
                }
            }
        }
    }
    
    cout << dp[h][k-1] << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;
#define all(x) (x).begin(), (x).end()
#define REP(i, N) for (int i = 0; i < N; i++)
constexpr ll M = 1e9 + 7;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,0));
    for (int i = 0; i < n + 1; i++) {
        for (int j = 0; j < n + 1; j++) {
            if (j == 0) {
                dp[i][j] = 1;
            } else if (j == 1) {
                dp[i][j] = i;
            } else {
                dp[i][j] = 0;
            }
        }
    }
    for (int i = 2; i < n + 1; i++) {
        for (int j = 2; j < n + 1; j++) {
            dp[i][j] = (dp[i - 1][j] + dp[i - 1][j - 1]) % M;
        }
    }
    for (int i = 1; i < k + 1; i++) {
        cout << (dp[n - k + 1][i] * dp[k - 1][i - 1]) % M << endl;
    }
    return 0;
}


Measured memory_bytes: 31616
N,K= map(int,raw_input().split())
x = map(int,raw_input().split())

min_path=4*(10**8)
for i in range(N-K+1):
	if x[i]<0 and x[i+K-1]<0:
		if min_path>-x[i]:
			min_path=-x[i]
	if x[i]<0 and x[i+K-1]>=0:
		if -x[i]>x[i+K-1]:
			if min_path > -x[i]+2*x[i+K-1]:
				min_path=-x[i]+2*x[i+K-1]
		else:
			if min_path > -x[i]*2 + x[i+K-1]:
				min_path=-x[i]*2 + x[i+K-1]
	if x[i]>=0 and x[i+K-1]>=0:
		if min_path>x[i+K-1]:
			min_path=x[i+K-1]

			
print min_path


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

int main() {
  int N;
  cin>>N;
  int abc[N][3], dp[N][3];
  for(int i=0;i<N;i++){
    cin>>abc[i][0]>>abc[i][1]>>abc[i][2];
    for(int j=0;j<3;j++){
      dp[i][j]=0;
    }
  }
  
  for(int j=0;j<3;j++){
    dp[0][j]=abc[0][j];
  }
  for(int i=1;i<N;i++){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+abc[i][0];
    dp[i][1]=max(dp[i-1][2],dp[i-1][0])+abc[i][1];
    dp[i][2]=max(dp[i-1][0],dp[i-1][1])+abc[i][2];
  }
  cout<<max(dp[N-1][0], max(dp[N-1][1], dp[N-1][2]))<<endl;
}

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

vector<pair<ll,ll>> tasks;
int main(){
    ll i,n;
    cin >> n;
    ll a,b;
    for(i = 0; i < n; i++){
        cin >> a>> b;
        tasks.emplace_back(b, a);
    }
    sort(tasks.begin(),tasks.end());
    bool ans = true;
    ll judge = 0;
    for(i = 0; i < n;i++){
        judge += tasks[i].second;
        if(judge > tasks[i].first){
            ans = false;
            break;
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 6128
import bisect
import sys
input = sys.stdin.readline
from collections import deque
def solve():
  
  n,m = (int(i) for i in input().split())
  a = list(int(i) for i in input().split())
  a = deque(sorted(a))
  tmp = deque([])
  for i in range(m):
    r,l = (int(i) for i in input().split())
    tmp.append((l,r))
  tmp= deque(sorted(tmp,reverse =True))
  ans = 0
  while tmp:
    c,b = tmp.popleft()
    place = bisect.bisect_left(a,c)-1
    if place == -1:
      break
    else:
        if len(a) == 0:
           break
        for i in range(min(1+place,b)):
           a.popleft()
        ans += c*(min(1+place,b))
    #print(a)
  if a:
   ans += sum(a)
  print (ans)
solve()

Measured memory_bytes: 65944
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
ll a,b,c,d,dp[105][100005],cost[100005],weight[100005];

ll func(ll i,ll w)
{
    if(i>a)
    {
        return 0;
    }
    ll p=0,q=0;
    if(dp[i][w]!=-1)
    {
        return dp[i][w];
    }
    if(w+weight[i]<=b)
    {
        p=cost[i]+func(i+1,w+weight[i]);
    }
    q=func(i+1,w);
    dp[i][w]=max(p,q);
    //cout<<dp[i][w]<<endl;
    return dp[i][w];
}

int main()
{
    memset(dp,-1,sizeof(dp));
    ll ans;
    cin>>a>>b;
    for(int i=0; i<a; i++)
    {
        cin>>c>>d;
        weight[i]=c;
        cost[i]=d;
    }
    ans=func(0,0);
    cout<<ans<<endl;
    //cout<<nCr(a,b)<<endl;

}


Measured memory_bytes: 82304
#include <stdio.h>
int MTS(int);
 int G[100];
 int A[100][100];
 int main(){
   int i,j,n;
  int sum;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&A[i][j]);
    }
  }
  sum=MTS(n);
  printf("%d\n",sum);
  return 0;
}

int MTS(int n){
  int i,j;
  int k=1;
  int max,min;
  int count=0;
 int R[100];
  G[0]=1;
  R[0]=0;
  for(i=1;i<n;i++){
    G[i]=0;
  }
  while(1){
    max=2001;
    for(i=0;i<k;i++){
      for(j=0;j<n;j++){
	if(A[R[i]][j] < max && A[R[i]][j] != -1 && G[j]!=1){
	    max=A[R[i]][j];
	    min=j;
	  }
	  }
      }
      if(k!=n){
	R[k]=min;
	G[min]=1;
	count+=max;
	k++;
      }
      else break;
  }
  return count;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  int c[3][3];
  REP(i,3){
    REP(j,3){
      scanf("%d", &c[i][j]);
    }
  }
  
  REP(i,101){
    int a[3], b[3];
    a[0] = i;
    a[1] = a[0] - (c[0][0] - c[1][0]);
    a[2] = a[0] - (c[0][0] - c[2][0]);
    b[0] = c[0][0] - a[0];
    b[1] = c[0][1] - a[0];
    b[2] = c[0][2] - a[0];
    bool make = true;
    REP(j,3){
      if(a[j] < 0 || a[j] > 100 || b[j] < 0 || b[j] > 100){
        make = false;
        break;
      }
    }
    if(make){
      REP(j,3){
        REP(k,3){
          if(c[j][k] != a[j] + b[k]){
            make = false;
          }
        }
      }
      if(make){
        printf("Yes\n");
        return 0;
      }
    }
  }
  printf("No\n");
  return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int N = 410;

int n, m;
char s[N][N];
int f[N * N], cnt[N * N], sum[N * N];

int gi(int x, int y) { return x * m + y; }

int find(int x) { return f[x] == x ? x : f[x] = find(f[x]); }

int main() {

  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; ++i)
    scanf("%s", s[i]);
  iota(f, f + n * m, 0);
  fill(cnt, cnt + n * m, 1);
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j)
      if (s[i][j] == '#')
        sum[gi(i, j)] = 1;
  for (int i = 0; i < n; ++i)
    for (int j = 0; j < m; ++j) {
      if (i && s[i][j] != s[i - 1][j]) {
        int u = find(gi(i - 1, j)), v = find(gi(i, j));
        if (u != v) {
          f[u] = v;
          cnt[v] += cnt[u];
          sum[v] += sum[u];
        }
      }
      if (j && s[i][j] != s[i][j - 1]) {
        int u = find(gi(i, j - 1)), v = find(gi(i, j));
        if (u != v) {
          f[u] = v;
          cnt[v] += cnt[u];
          sum[v] += sum[u];
        }
      }
    }
  ll ans = 0;
  for (int i = 0; i < n * m; ++i)
    if (f[i] == i) {
      ans += sum[i] * (ll) (cnt[i] - sum[i]);
    }
  printf("%lld\n", ans);

  return 0;
}


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

int main() {
  double N;
  cin >> N;
  
  for(int i=0; i<=50000; i++) {
    int ibuff=i*1.08;
    if (N==ibuff) {
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
  return 0;
}

Measured memory_bytes: 256
package main

import "bufio"
import "fmt"
import "os"
import "strconv"

func main() {
        var H, N, i int
        fmt.Scanf("%d %d", &H, &N)
        sc := bufio.NewScanner(os.Stdin)
        sc.Split(bufio.ScanWords)
        for i = 0; i < N; i++ {
                sc.Scan()
                n, e := strconv.Atoi(sc.Text())
                if e != nil {
                        panic(e)
                }
                H = H - n
                if H <= 0 {
                        break
                }
        }
        if H > 0 {
                fmt.Println("No")
        } else {
                fmt.Println("Yes")
        }
}


Measured memory_bytes: 1152
#include<cstdio>
#include<iostream>
#include<cmath>
#include<ctype.h>
#include<vector>
#include<cstdlib>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<time.h>

#define ll long long
#define LL long long
#define ULL unsigned long long 
#define ull unsigned long long 
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
const int INF = 100000000;
using namespace std;




int main()
{
	
	char tmp[4] = {'N','W','S','E'};
	int num[4] = {};
	string S;
	cin >> S;
	REP(i, S.length()) {
		REP(j, 4) {
			if (S[i] == tmp[j]) {
				num[j]++;
			}
		}
	}


	if (num[0]==0&&num[2]!=0) {
		cout << "No" << endl;
	}
	else if (num[0] != 0 && num[2] == 0) {
		cout << "No" << endl;
	}
	else if (num[1] == 0 && num[3] != 0) {
		cout << "No" << endl;
	}
	else if (num[1] != 0 && num[3] == 0) {
		cout << "No" << endl;
	}
	else cout << "Yes" << endl;
	

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)

const string YES = "YES";
const string NO = "NO";

void solve(long long X){
    if(X == 3 || X==5 || X==7){
        cout << YES << "\n";

    }else{
        cout << NO << "\n";
    }
}

int main(){

    long long X;
    scanf("%lld",&X);
    solve(X);
    return 0;
}



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

int main(){
  int N; vector<int> W(N);
  cin >>N;
  int sum=0;
  
  for(int i=0; i<N; i++){
    cin >> W.at(i); 
  sum += W.at(i);
  }
  
 int s;
  int wum=0;  
  vector<int> X(N);
  
  for(int i=0; i<N; i++){
    wum+=W.at(i);
    X.at(i)=fabs(sum-2*wum);
  }
  
  int ans=X.at(0);
  
  for(int i=0; i<N-1;i++){
    ans=min(ans,X.at(i+1));}
    
  cout << ans << endl;}
    
    

Measured memory_bytes: 16640
import java.util.Scanner;

class Main {

    private static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int x = sc.nextInt(), a = sc.nextInt(), b = sc.nextInt();
        if (Math.abs(x - a) > Math.abs(x - b)) {
            System.out.println("B");
        } else {
            System.out.println("A");
        }
    }
}

Measured memory_bytes: 23892
#include <iostream>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <algorithm>

 
using namespace std;

typedef long long ll;
typedef long double ld;
#define L(ID) ((ID*2)+1)
#define R(ID) ((ID*2)+2)
#define M(L,R) ((L+R)/2)
#define forr(start,end) for(int i = start; i < end; i++)
#define gap ' '
 
const int MAXN = 1e5 + 5;

ll largest(ll a, ll b){
	return (a<b)?b:a;
}
ll smallest(ll a, ll b){
	if(a < b)return a;
	return b;
}

int main(){
	int c[3][3];
	int a[3];
	int b[3];
	for(int i = 0; i < 3; ++i){
		for(int j = 0; j < 3; ++j){
			cin >> c[i][j];
		}	
	}
	for(a[0] = 0; a[0] <= 100; a[0]++){
		for(a[1] = 0; a[1] <= 100; a[1]++){
			for(a[2] = 0; a[2] <= 100; a[2]++){
				b[0] = c[0][0] - a[0];
        		b[1] = c[0][1] - a[0];
        		b[2] = c[0][2] - a[0];
        		bool correct = true;
        		for(int i = 0; i < 3; ++i){
        			for(int j = 0; j < 3; ++j){
        				correct &= c[i][j] == a[i] + b[j];
         			}
        		}
        		if(correct){
        			cout << "Yes" << endl;
        			return 0;
        		}
			}
		}
	}
	cout << "No" << endl;

    return 0;
}


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

using namespace std;
typedef long long int ll;

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  int n;
  ll aux, ans = 0;
  cin >> n;
  while(n--){
    cin >> aux;
    ans += aux - 1;
  }

  cout << ans << "\n";
  return 0;
}


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

using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) { cin >> a[i]; }

	set<int> st1, st2;
	for (int i = 0; i < K; ++i) {
		st1.insert(a[i]);
		st2.insert(a[i]);
	}

	int ans = 1;
	for (int i = 1; i + K <= N; ++i) {
		int min_a = *st1.lower_bound(-1);
		st2.insert(a[i+K-1]);
		auto max_itr = st2.upper_bound(a[i+K-1]);
		if (min_a != a[i-1] || (max_itr != st2.end())) {
			++ans;
		}
		st1.erase(a[i-1]);
		st1.insert(a[i+K-1]);
		st2.erase(a[i]);
	}

	int cnt = 1;
	int x = 0;
	for (int i = 1; i < a.size(); ++i) {
		if (a[i - 1] < a[i]) {
			++cnt;
		} else {
			if (cnt >= K) { ++x; }
			cnt = 1;
		}
	}
	if (cnt >= K) { ++x; }
	ans -= (x > 1 ? x - 1 : 0);
	cout << ans << endl;

	return 0;
}


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

//int dp[207][207];
//int judge(const string &a, const string &b){
//    memset(dp, 0, sizeof(dp));
//    for(int i=0; i<a.size(); ++ i){
//        for(int j=0; j<b.size(); ++ j){
//            if(dp[i] == dp[j])
//                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
//            else
//                dp[i+1][j+1] = max(dp[i][j+1], dp[i+1][j]);
//        }
//    }
//    return dp[a.size()][b.size()];
//}

list<int>lt;
vector<int> arr(200007);
int main() {

    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for(int i=0; i<n; ++ i)
        cin >> arr[i];
    int flag = 1;
    for(int i=0; i<n; ++ i){
        flag = (flag + 1) % 2;
        if(flag == 0)
            lt.push_back(arr[i]);
        else
            lt.push_front(arr[i]);
    }

    if(flag == 1){
        cout << lt.front();
        lt.pop_front();
        while(!lt.empty()){
            cout << " " << lt.front();
            lt.pop_front();
        }
    }
    else{
        cout << lt.back();
        lt.pop_back();
        while(!lt.empty()){
            cout << " " << lt.back();
            lt.pop_back();
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 9216
a,b,c,x,y = map(int,input().split())

ans = float('inf')
for i in range(0,max(x,y)*2 + 1,2):
  price = i*c+ max(x-i//2,0)*a + max(y-i//2,0)*b
  ans = min(price,ans)
print(ans)



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

typedef long long ll;

int main(){
    int W,H;
    cin >> H >> W;
    char pixel[H][W];

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin >> pixel[i][j];
        }
    }

    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            printf("%c",pixel[i][j]);
        }
        printf("\n");
        for(int j=0;j<W;j++){
            printf("%c",pixel[i][j]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
using System.Text;//テキストの高速出力に必要
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		int n = int.Parse(input[0]);
		long k = long.Parse(input[1]);
    long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
		long sum = 0;
    for(int i = 0; i < n; i++) sum += nums[i];
    List<long> divisors = Divisors(sum);
    int divCount = divisors.Count();
    bool answer = true;
    List<long> restList = new List<long>();
    long sumLeft = 0;
    long sumRight = 0;

    for(int i = divCount-1; i >= 0; i--)
    {
      restList.Clear();
      answer = false;
      sumLeft = 0;
      sumRight = 0;

      for(int j = 0; j < n; j++)
      {
        long addNum = nums[j] % divisors[i];
        restList.Add(addNum);
        sumRight += (divisors[i]-addNum)%divisors[i];
      }
      restList.Sort();

      for(int j = 0; j < n-1; j++)
      {
        sumLeft += restList[j];
        sumRight -= (divisors[i]-restList[j])%divisors[i];
        //Console.WriteLine(j+" "+sumLeft+" "+sumRight+" "+divisors[i]);
        if(Math.Max(sumLeft,sumRight) <= k) answer = true;
      }

      if(answer)
      {
        Console.WriteLine(divisors[i]);
        break;
      }
    }
	}

  static List<long> Divisors(long num)
  {//引数に対し、1以上の約数全てをO(√nlog√n)で返す
  //例えば4なら{1,2,4}、0なら{}を返す
    List<long> answers = new List<long>();
  
    for(long i = 1; i <= Math.Sqrt(num); i++)
    {
      if(num % i == 0)
      {
        answers.Add(i);
        if(i < num/i) answers.Add(num/i);
      }
    }
    answers.Sort();

    return answers;
  }
  
}

Measured memory_bytes: 13500
import * as fs from "fs";

const input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const [w, h, x, y] = input[0].split(" ").map((x: string): number => +x);

// 重心を求める
const cx = w/2;
const cy = h/2;

let pattern = 0;
if(cx===x && cy===y){
  // 重心と与えられた点が一致する場合は分割方法は無数にある
  pattern = 1;
}

console.log(w*h/2, pattern);


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

using namespace std;

set<string> S;
string s;
int k;
int main() {
	cin >> s >> k;
	for(int i = 0; i < s.size(); i++) {
		for(int j = 1; j <= 5; j++) {
			S.insert(s.substr(i, j));
		}
	}
  /*auto itr = S.begin();
  while(itr!=S.end()){
  cout << *itr << "\n"; 
  itr++;
}*/
	int cnt = 1;
	for(auto x : S) {
		if(cnt == k) {
			cout << x << endl;
			break;
		}
		cnt++;
	}
}

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

int main(){
	int n,m;
	cin>>n>>m;
	int sum=0;
	for(int i=4;i<=n;i++){
		for(int j=22;j<=m;j++){
			int j1=j;
			int dx=j1%10; 
			j1/=10;
			int dy=j1%10; 
			if(dx*dy==i&&dx>=2&&dy>=2){
				sum++;
			}
		}
	}
	cout<<sum<<endl;
	
	return 0;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
n = int(input())
arr = [0] + list(map(int, input().split()))

res = []
for i in range(1, n+1):
    res.extend([i] * arr[i])

tmp = 0
for i in range(h):
    s = res[tmp:tmp+w]
    if i % 2 == 1:
        s.reverse()
    print(*s)
    tmp += w


Measured memory_bytes: 3828
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i,n) for (ll i=0; i<(n); ++i)
#define rep1(i,n) for (ll i=1; i<=(n); ++i)
typedef long long ll;
bool debug=false;
string yes = "Yes";
string no = "No";
const ll mod = 998244353;
const double e = 0.000000001;

int main(){
  ll n; cin >> n;
  string s; cin >> s;
  vector<ll> e(n+1);
  vector<ll> w(n+1);
  e[0]=0, w[0]=0;
  rep1(i,n){
    e[i]=e[i-1];
    w[i]=w[i-1];
    char c = s[i-1];
    if(c=='E'){
      e[i]++;
    }else{
      w[i]++;
    }
  }
  ll ans=n;
  rep(i,n){
    ans=min(ans, w[i]+e[n]-e[i+1]);
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 5380