akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <stdlib.h>
#define N 100

void push(int);
int pop(void);
int isEmpty(void);
int isFull(void);

int stack[N];
int top=0;

int main(){
  int a,b;
  char n[N];

  while(scanf("%s",n)!=EOF){
  
  if(n[0]=='+'){
    a=pop();
    b=pop();
    push(b+a);
  }else if(n[0]=='-'){
    a=pop();
    b=pop();
    push(b-a);
  }else if(n[0]=='*'){
    a=pop();
    b=pop();
    push(b*a);
  }else
    push(atoi(n));

  
  }

  printf("%d\n",pop());
  
    return 0;
}

void push(int x){
  if(isFull()==0){
  top++;
  stack[top]=x;
   }else exit(1);
}

int pop(){
  if(isEmpty()==0){
  top--;
  return stack[top+1];
  }else exit(2);
}

int isEmpty(){
  if(top==0) return 1;
  else return 0;
}

int isFull(){
  if(top==N)return 1;
  else return 0;
}
  
  


  



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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	vector<int> col(8);
	int n;
	cin >> n;
	int rem = 0;
	for(int i = 0; i < n; i++) {
		int a;
		cin >> a;
		if(a / 400 >= 8) rem++;
		else col[a / 400]++;
	}	
	int x = 0;
	for(int i = 0; i < col.size(); i++) {
		if(col[i]) x++;
	}
	if(x == 0) {
		cout << 1 << " " << rem << endl;
	} else {
		cout << x << " " << x + rem << endl;
	}
	return 0;	
}


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

int main()
{
  int n;cin>>n;
  vector<string> s(n);
  int i;
  for(i=0;i<n;i++)cin>>s.at(i);
  sort(s.begin(),s.end());
  vector<int> count(1,1);
  vector<int> fin1(1,0);
  int nown=0;
  string now=s.at(0);
  for(i=1;i<n;i++)
  {
    if(now!=s.at(i))
    {
      nown++;
      count.emplace_back(1);
      fin1.emplace_back(i);
      now=s.at(i);
    }
    else
    {
      count.at(nown)++;
    }
  }
  int m=count.size();
  int maxn=0;
  for(i=0;i<m;i++)
  {
    if(maxn<count.at(i))maxn=count.at(i);
    //cout<<count.at(i)<<endl;
  }
  for(i=0;i<m;i++)
  {
    if(count.at(i)==maxn)cout<<s.at(fin1.at(i))<<endl;
  }
  
}


Measured memory_bytes: 17516
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

class Myon

{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
    static Scanner cin;

    void calc()
    {
        int N = cin.nextInt();
        int D = cin.nextInt();
        int[,] X = new int[N, D];
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < D; j++)
            {
                X[i, j] = cin.nextInt();
            }
        }

        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < i; j++)
            {
                long dis = 0;
                for (int k = 0; k < D; k++)
                {
                    dis += dd(X[i, k] - X[j, k]); 
                }
                if (isSquare(dis)) ans++;
            }
        }
        Console.WriteLine(ans);
    }

    long dd(long a)
    {
        return a * a;
    }

    bool isSquare(long a)
    {
        long b = (long)Math.Sqrt(a + 0.5);
        return b * b == a;
    }
}


class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}





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

using namespace std;

int main() {
	long long n, sum = 0, ans;
	scanf("%lld", &n);
	for (int i = 1; i < 1e5; i++) {
		sum += (long long)i;
		if (n <= sum) {
			ans = (long long)i;
			break;
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 256
N=int(input())
s=list(map(int,input().split()))
s_max=max(s)
s_min=min(s)
A=[]
for i in range(s_min,s_max+1):
  b=0
  for j in s:
    b+=(j-i)**2
  A.append(b)
print(min(A))

Measured memory_bytes: 9180
# -*- coding: utf-8 -*-
N = int(input())
A_list = list(map(int, input().split()))
 
div_sum_A = sum(A_list) / 2
ans = 0
calculator = 0
for i in range(N):
    calculator += A_list[i]
    if calculator >= div_sum_A:
        if calculator == div_sum_A:
            ans = 0
            break
        elif A_list[i] > div_sum_A:
            ans = 2 * A_list[i] - calculator
            break
        else:
            cand_1 = calculator - (2 * div_sum_A - calculator)
            cand_2 = abs((calculator - A_list[i]) - (2 * div_sum_A - (calculator - A_list[i])))
            ans = min(cand_1, cand_2)
            break

print(int(ans))

Measured memory_bytes: 27120
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fixed cout.setf(ios::fixed);
#define rep1    for( i=0; i<n; i++)
#define Precise cout.precision(7);
#define yes cout<<"Yes"<<'\n'
#define no cout<<"No"<<'\n'
using namespace std;

int main()
{
    ll i,j,a,b,c;
    cin>>a>>b>>c;
    (a+b>=c)?yes:no;


    return 0;
}





Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] x = new int[n];
		int[] y = new int[n];
		for(int i = 0; i < n; i++) {
			x[i] = sc.nextInt();
			y[i] = sc.nextInt();
		}
		double z = 0;
		for(int i = 0; i < n; i++) {
			for(int j = i+1; j < n; j++) {
				z += Math.sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
			}
		}
		z *= 2;
		z /= n;
		System.out.println(z);
	}

}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> x(n);
    for(int i=0;i<n;i++){
        cin>>x.at(i);
    }
    vector<int> y(n);
    for(int i=0;i<n;i++){
        cin>>y.at(i);
    }
    int sum=0;
    for(int i=0;i<n;i++){
        int z=x.at(i)-y.at(i);
        if(z>0) sum+=z;
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {
	
	HashMap<Integer, Integer> map;
	long sum;

	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
	
		map = new HashMap<>();
		sum = 0;
		
		int n = fs.nextInt();
		for(int i = 0; i < n; i++) {
			int a = fs.nextInt();
			incrementMap(a);
		}
		int q = fs.nextInt();
		
		for(int i = 0; i < q; i++) {
			int b = fs.nextInt();
			int c = fs.nextInt();
			replace(b,c);
		}
	}
	
	void incrementMap(int val) {
		if(map.containsKey(val)) {
			int num = map.get(val);
			map.put(val, num+1);
		}else {
			map.put(val, 1);
		}
		sum += val;
	}
	
	void replace(int from, int to) {
		
		if(!map.containsKey(from)){
			System.out.println(sum);
			return;
		}
		
		int fromNum = map.get(from);
		map.remove(from);
		if(map.containsKey(to)) {
			int toNum = map.get(to);
			map.put(to, fromNum+toNum);
		}else {
			map.put(to, fromNum);
		}
		
		
		sum -= (long)from * (long)fromNum;
		sum += (long)to * (long)fromNum;
		
		System.out.println(sum);
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 73256
import java.util.Scanner;
 
public class Main {
 
    public static void main(String[] args) {
        new Main().compute();
    }
 
    void compute() {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        int G = sc.nextInt();
        System.out.println(R + (G - R) * 2);
    }
}

Measured memory_bytes: 23636
lst = []
n, m  = map(int, input().split())
for _ in range(m):
    i, h = input().split()
    lst.append([int(i), str(h)])

jdg_wa = [0] * n 
jdg_ac = [0] * n

penalty = 0
for _ in lst:
    idx = _[0] - 1
    if  jdg_ac[idx] != 1:
        if _[1] == 'WA':
            jdg_wa[idx] += 1
        elif _[1] == 'AC':
            jdg_ac[idx] = 1
            penalty +=  jdg_wa[idx]
print(sum(jdg_ac), penalty)


Measured memory_bytes: 23456
#include <malloc.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

//ABC174D

//ABC174C

//ABC174B
int main(void) {
  long long n, d, k, i, cou=0, tmp;
  scanf("%lld %lld", &n, &d);
  long long x[n], y[n];
  for(i=0; i<n; i++){
    scanf("%lld %lld", &x[i], &y[i]);
    if(pow(x[i], 2)+pow(y[i], 2)<=d*d) cou++;
  }
  printf("%lld", cou);

}

Measured memory_bytes: 4848
#include <bits/stdc++.h>
#define int long long
#define INF "{"
#define mp make_pair
using namespace std;
 
struct edge{ int to; string s; };
typedef pair<int,int> pi;
typedef pair<string,pi> psi;
 
signed main(){
    int n,a,s,g;
    while(cin >> n >> a >> s >> g,n){
        string d[45][500];
        vector<edge> G[45];
        for(int i = 0;i < a;i++){
            int u,v;
            string s;
            cin >> u >> v >> s;
            G[u].push_back({v,s});
        }
        for(int i = 0;i < n;i++){
            for(int j = 0;j < 500;j++) d[i][j] = INF;
        }
        d[s][0] = "";
        priority_queue<psi,vector<psi>,greater<psi>> que;
        que.push(mp("",mp(s,0)));
        while(!que.empty()){
            psi p = que.top();que.pop();
            string dist = p.first;
            int v = p.second.first,len = p.second.second;
            if(dist > d[v][len]) continue;
            for(edge e : G[v]){
                string ns = dist + e.s;
                if(len + e.s.length() < 500 && ns < d[e.to][len + e.s.length()]){
                    d[e.to][len + e.s.length()] = ns;
                    que.push(mp(ns,mp(e.to,len + e.s.length())));
                }
            }
        }
        string ans = INF;
        for(int i = 1;i < 500;i++) ans = min(ans,d[g][i]);
        if(ans == INF || ans.length() >= 240) cout << "NO" << endl;
        else cout << ans << endl;
    }
}


Measured memory_bytes: 24988
#input of int(split by space)
def get_i()
  return gets.chomp.split(" ").map(&:to_i)
end
#input of float(split by space)
def get_f()
  return gets.chomp.split(" ").map(&:to_f)
end
#input of string(split by space)
def get()
  return gets.chomp.split(" ")
end
#input of string(split per one character)
def get_nsp()
  return gets.chomp.split("")
end
#yes or no decision
def yn_judge(bool,y="Yes",n="No")
  return bool ? y : n 
end
#create of array
def array(size1,init=nil,size2=-1)
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

def max(a,b)
    return a>b ? a : b
end

def min(a,b)
    return a>b ? b : a
end

INF=Float::INFINITY

N=gets.to_i
cfs=array(N-1)
(N-1).times do|i|
  cfs[i]=get_i
end

def simulation(train,now)
  t=0
  now.upto(N-2) do|i|
    if train[i][1]>=t
        t=train[i][1]
    else
        unless (t%train[i][2]).zero?
          t+=train[i][2]-t%train[i][2]
        end
    end
    t+=train[i][0]
  end
  return t
end
(N-1).times do|i|
    puts simulation(cfs,i)
end
puts 0

Measured memory_bytes: 1788
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>
#include <cmath>
#include <queue>
#include <set>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<P,int> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int x;

int main(){
	cin>>x;
	cout<<360/gcd(360,x)<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    ll k;
    cin >> k;
    int n = 8;
    VI a;
    REP(j,200) REP(i,n-1) a.push_back(i);
    REP(i,n-1) REP(j,250) a.push_back(i);
    int m = a.size();
    VVL cnt(m + 1, VL(n));
    REP(i,m){
        REP(j,n) cnt[i + 1][j] = cnt[i][j];
        if (a[i] == 0) cnt[i + 1][0]++;
        else cnt[i + 1][a[i]] += cnt[i][a[i] - 1];
    }
    // REP(i,m) cout << cnt[i][n - 2] << " ";
    // cout << endl;
    // REP(i,m-1) if (cnt[i][n - 2]) cout << cnt[i+1][n-2] / cnt[i][n-2] << " ";
    // cout << endl;
    VL b(m);
    FORR(i,m-1,0){
        if (cnt[i + 1][n - 2] == 0) continue;
        b[i] = k / cnt[i + 1][n - 2];
        k -= b[i] * cnt[i + 1][n - 2];
    }
    // REP(i,m) cout << b[i] << " ";
    // cout << endl;
    string ans, s = "FESTIVAL";
    REP(i,m){
        ans += s[a[i]];
        ans += string(b[i], 'L');
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
from math import cos, radians, sqrt

A, B, H, M = map(int, input().split())
minutes = H * 60 + M

short = (minutes / (12 * 60)) * 360
long = ((minutes / 60) % 60) * 360
if short >= long:
    arg = short - long
else:
    arg = long - short

a = (A ** 2) + (B ** 2) - (2 * A * B * cos(radians(arg)))
print(sqrt(a))


Measured memory_bytes: 62372
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;

int N;
vector<vector<ll>> dp;
vector<ll> a;

ll rec(int l = 0, int r = N) {
    if (r == l) return 0;
    ll &ret = dp[l][r];
    if (ret != INF) return ret;

    if ((N - (r - l)) % 2 == 0) {  // 先手
        ret = max(a[l] + rec(l + 1, r), rec(l, r - 1) + a[r - 1]);
    } else {  // 後手
        ret = min(-a[l] + rec(l + 1, r), rec(l, r - 1) - a[r - 1]);
    }

    return ret;
}

int main() {
    cin >> N;
    a.assign(N, 0);
    dp.assign(N + 5, vector<ll>(N + 5, INF));
    for (int i = 0; i < N; i++) {
        cin >> a.at(i);
    }

    cout << rec() << endl;

    return 0;
}


Measured memory_bytes: 71040
# しゃくとり法 xor

n = gets.to_i
nums = gets.split.map(&:to_i)
sum = 0
right = 0
ans = 0
0.upto(n - 1) do |left|
  # right を次に進めても OK かどうか確認してから、right を 1 進める
  while right < n  && (sum + nums[right]) == (sum ^ nums[right])
    sum += nums[right]
    right += 1
  end
  ans += right - left
  sum -= nums[left]
end
puts ans


Measured memory_bytes: 15364
N, M = map(int, input().split())

H = list(map(int, input().split()))

good_H = [1] * N

for i in range(M):
    A, B = map(int, input().split())
    if H[A-1] <= H[B-1]:
        good_H[A-1] = 0
    if H[A-1] >= H[B-1]:
        good_H[B-1] = 0

print(good_H.count(1))

Measured memory_bytes: 20100
class String
  def is_upper?
    self==self.upcase
  end
end

s=gets.chomp
if s[0]!="A"
  puts "WA"
  exit
end
if s.slice(2..s.size-2).scan(/C/).size!=1
  puts "WA"
  exit
else
  cindex=s.index("C")
end
1.upto(s.size-1) do |i|
  if i!=cindex
    if s[i].is_upper?
      puts "WA"
      exit
    end
  end
end
puts "AC"


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


int main()
{
	int a;
	scanf("%d", &a);
	
	if(a == 1 || a == 2 ||a==3||a==5||a==7||a==11||a==13||a==15||a==17||a==19||a==23||a==29||a==31)
	{
		printf("1");
	}
	else if(a==4||a==6||a==9||a==10||a==14||a==21||a==22||a==25||a==26)
	{
		printf("2");
	}
	else if(a==28||a==30)
	{
		printf("4");
	}
	else if(a==8||a==12||a==18||a==20||a==27)
	{
		printf("5");
	}
	else if(a==16)
	{
		printf("14");
	}
	else if(a==24)
	{
		printf("15");
	}
	else if(a==32)
	{
		printf("51");
	}
}

Measured memory_bytes: 128
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#define MOD 1000000007LL
using namespace std;

int main()
{
	long long int n;
	scanf("%lld", &n);
	int nd[60];
	long long int ans[60]={}, ans1[60]={};
	long long int q=n;
	for(int i=0; i<60; i++){
		nd[i]=q%2;
		q=q/2;
	}
	long long int p3[60];
	for(int i=0; i<60; i++){
		if(i==0){
			p3[0]=1;
		}else{
			p3[i]=p3[i-1]*3%MOD;
		}
	}
	for(int i=0; i<60; i++){
		if(i==0){
			if(nd[0]==1){
				ans[0]=2;
				ans1[0]=1;
			}else{
				ans[0]=1;
				ans1[0]=0;
			}
		}else{
			if(nd[i]==0){
				ans[i]=ans[i-1];
				ans1[i]=0;
			}else{
				int i0;
				for(i0=i-1; i0>=0; i0--){
					if(nd[i0]==1){
						break;
					}
				}
				if(i0==-1){
					for(int j=0; j<=i; j++){
						if(j==0){
							ans[i]=ans[i-1]+1;
							ans1[i]=1;
						}else{
							ans[i]=(ans[i]+1+p3[j-1])%MOD;
							ans1[i]=(ans1[i]+1+p3[j-1])%MOD;
						}
					}
				}else{
					for(int j=0; j<=i0; j++){
						if(j==0){
							ans[i]=ans[i-1]+1;
							ans1[i]=1;
                       
						}else{
							ans[i]=(ans[i]+2*p3[j-1])%MOD;
							ans1[i]=(ans1[i]+2*p3[j-1])%MOD;
						}
					}
					for(int j=i0+1; j<=i; j++){
						if(j==i0+1){
							ans[i]=(ans[i]+ans1[i0]+p3[j-1])%MOD;
							ans1[i]=(ans1[i]+ans1[i0]+p3[j-1])%MOD;
						}else{
							ans[i]=(ans[i]+ans[i0]+p3[j-1])%MOD;
							ans1[i]=(ans1[i]+ans[i0]+p3[j-1])%MOD;
						}
					}
				}
			}
		}
	}
	printf("%lld\n", ans[59]);
	return 0;
}

Measured memory_bytes: 128
n, m = map(int, input().split())
As = list(map(int, input().split()))

def solve(n, m, As):
    weighted_sum = [0] * m
    row_sum = [0] * m
    col_sum = [0] * m
    delta_sum = [0] * m
    delta_sum0 = 0
    delta_weighted = 0
    sol = 0
    As = [a - 1 for a in As]
    for i in range(n - 1):
        a = As[i]
        b = As[i + 1]
        sol += (b - a) % m
        if a == b or (a + 1)%m == b: continue
        row_sum[a] += 1
        col_sum[b] += 1
        weighted_sum[b] += (b - a - 1) % m
        if (a > b and a != m - 1):
            delta_sum0 += 1
            delta_weighted += m - a - 1
    delta_sum[0] = delta_sum0
    for i in range(1, m):
        delta_sum0 = delta_sum0 + row_sum[i - 2] - col_sum[i - 1]
        delta_sum[i] = delta_sum0
    record = delta_weighted
    for x in range(1, m):
        delta_weighted += delta_sum[x] - weighted_sum[x - 1]
        record = max(record, delta_weighted)
    return sol - record
    
print(solve(n, m, As))


Measured memory_bytes: 59500
#include <iostream>
#include <vector>

using namespace std;

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

    vector< int > b(N);

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

    vector< int > ans(N);

    for (int i = N - 1; i >= 0; i--) {
        bool ac = false;
        for (int j = i; j >= 0; j--) {
            // cout << "j: " << j << ", b[j]: " << b[j] << endl;
            if (b[j] == j + 1) {
                ac = true;
                b.erase(b.begin() + j);
                ans[i] = j + 1;
                break;
            }
        }

        if (!ac) {
            cout << -1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 256
#!/usr/bin/env ruby

@n, @w = gets.split(' ').map &:to_i
@items = []
@n.times.each do
  v, w = gets.split(' ').map &:to_i
  @items << {v: v, w: w}
end

# ans_map[i][w]
# i: 0..i番目のitemまで含めた状態での最大価値
# w: i番目において、各重量での最大価値
@ans_map = []
(0...@n).each do |i|
  (0..@w).each do |j|
    @ans_map[i] ||= []
    @ans_map[i][j] = 0
  end
end

def calc(i)
  item = @items[i]
  if i == 0
    @ans_map[i][item[:w]] = item[:v]
    return
  end

  (0..@w).each do |j|
    if j - item[:w] < 0
      @ans_map[i][j] = @ans_map[i-1][j]
      next
    end
    c1 = @ans_map[i-1][j-item[:w]] + item[:v]
    c2 = @ans_map[i-1][j]
    @ans_map[i][j] = c1 > c2 ? c1 : c2
  end
end

(0...@n).each do |i|
  calc(i)
end

puts @ans_map[@n-1].max



Measured memory_bytes: 14752
#![allow(clippy::needless_range_loop)]
#![allow(unused_macros)]
#![allow(dead_code)]
#![allow(unused_imports)]

use proconio::input;
use proconio::marker::*;
use itertools::Itertools;

fn main() {
    input! {
        s: String
    }

    let ans = match s.as_str() {
        "SSS" => 0,
        "RRS" | "SRR" => 2,
        "RRR" => 3,
        _ => 1
    };

    println!("{}", ans);
}


Measured memory_bytes: 2084
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, math.MaxInt64)
}

func readInt() int {
	sc.Scan()
	r, _ := strconv.Atoi(sc.Text())
	return r
}

func main() {
	a := make([][]int, 3)
	for i := 0; i < 3; i++ {
		for j := 0; j < 3; j++ {
			a[i] = append(a[i], readInt())
		}
	}
	n := readInt()
	for k := 0; k < n; k++ {
		hit := readInt()
		for i := 0; i < 3; i++ {
			for j := 0; j < 3; j++ {
				if a[i][j] == hit {
					a[i][j] = 0
				}
			}
		}
	}
	switch {
	case ((a[0][0] == 0) && (a[0][1] == 0) && (a[0][2] == 0)) ||
		((a[1][0] == 0) && (a[1][1] == 0) && (a[1][2] == 0)) ||
		((a[2][0] == 0) && (a[2][1] == 0) && (a[2][2] == 0)) ||
		((a[0][0] == 0) && (a[1][0] == 0) && (a[2][0] == 0)) ||
		((a[0][1] == 0) && (a[1][1] == 0) && (a[2][1] == 0)) ||
		((a[0][2] == 0) && (a[1][2] == 0) && (a[2][2] == 0)) ||
		((a[0][0] == 0) && (a[1][1] == 0) && (a[2][2] == 0)) ||
		((a[0][2] == 0) && (a[1][1] == 0) && (a[2][0] == 0)):
		fmt.Println("Yes")
	default:
		fmt.Println("No")
	}
}


Measured memory_bytes: 640
{-# LANGUAGE BangPatterns #-}
import Control.Arrow
import Control.Monad.Fix
import Data.Char
import Data.Int
import Data.Foldable
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

unew :: VU.Unbox a => Int -> VUM.IOVector a
unew !n = accursedUnutterablePerformIO $ VUM.unsafeNew n

uread :: VU.Unbox a => Int -> VUM.IOVector a -> a
uread !i !v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VU.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite !i !a !v =
  accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

umodify :: VU.Unbox a => Int -> (a -> a) -> VUM.IOVector a -> VUM.IOVector a
umodify !i !f !v =
  accursedUnutterablePerformIO $ VUM.unsafeModify v f i >> return v

uthaw :: VU.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw !v = accursedUnutterablePerformIO $ VU.unsafeThaw v

ufreeze :: VU.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze !v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uset :: VU.Unbox a => a -> VUM.IOVector a -> VUM.IOVector a
uset !i !v = accursedUnutterablePerformIO $ VUM.set v i >> return v

solve :: Int -> VU.Vector (Int, Int, Int) -> VU.Vector Int
solve !n !uvw = ufreeze $ (\(_, _, !y, _) -> y) $ dfs
 where
  dfs = fix
    (\(!f) (!parent, !node, !acc, !cost) ->
      let edges = filter (\(e, _) -> parent /= e) $ graph V.! node
      in  if null edges
            then (parent, node, acc, cost)
            else (\(!y) -> (parent, node, y, cost)) $ foldl'
              (\(!acc) (!e, !c) ->
                let acc' = if odd (cost + c) then uwrite e 1 acc else acc
                in  (\(_, _, !y, _) -> y) $ f (node, e, acc', cost + c)
              )
              acc
              edges
    )
    (-1, 0, uset 0 $ unew n, 0)

  graph :: V.Vector [(Int, Int)]
  graph = V.accumulate (flip (:)) (V.replicate n []) $ V.convert $ VU.concatMap
    (\(x, y, z) -> VU.fromList [(x, (y, z)), (y, (x, z))])
    uvw

main = do
  let readInt :: Integral a => B.ByteString -> Maybe (a, B.ByteString)
      readInt = fmap (first fromIntegral . second B.tail) . B.readInt

  n   <- (\vec -> (vec VU.! 0)) . VU.unfoldrN 1 readInt <$> B.getLine
  uvw <-
    VU.replicateM (n - 1)
    $   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1, vec VU.! 2))
    .   VU.unfoldrN 3 readInt
    <$> B.getLine
  VU.mapM_ print $ solve n uvw


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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll, ll> pi;

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

ll find_lower(ll *a, ll n, ll v){
    ll l = -1, r = n;

    while (r>l+1){
        ll m = (l+r)/2;

        if (a[m] >= v) r = m;
        else l = m;
    }
    if (r == n) return n-1;
    if (a[r] == v) return r;
    return r == 0 ? 0 : r-1;
}

ll *num;

void init(){
}

void solve(){
    int n,k;
    cin >> n >> k;
    int *p = new int[n];
    forn cin >> p[i];
    sort(p, p+n);
    int sum = 0;
    int i = 0;
    do{
        sum += p[i++];
    } while (i < n && i < k);
    cout << sum << "\n";
}

int main(){
    //init();

    ios::sync_with_stdio(0);
    cin.tie(0);

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<utility>

using namespace std;

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

  int swaps{0};
  for (int i = 0; i < n; ++i) {
    int minidx = i;
    for (int j = i; j < n; ++j) {
      if (A[j] < A[minidx]) minidx = j;
    }
    if (minidx != i) ++swaps, swap(A[minidx], A[i]);
  }
  
  for (int i = 0; i < n; ++i) {
    if(i) cout << " ";
    cout << A[i];
  }

  cout << endl << swaps << endl;
}


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

int main(){
    int a,b;
    do{
        cin >> a >> b;
        if(a==0&&b==0) break;
        if(a<b) { cout << a << " " << b << endl; }
        else { cout << b << " " << a << endl; }
    } while(1);
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.begin(), v.end(),greater<int>());
#define INF 999999999
#define MOD 1000000007
#define M_PI 3.14159265358979323846
#define ALL(X) (X).begin(),(X).end()

#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
#else
    #define DBG(X)
    #define SAY(X)
#endif

#ifdef __LOCAL
    #include <filesystem>
    namespace fs = std::filesystem;
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 0};
int dy[]={0, 1, 0, -1, 0};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
 
std::string pad(int num){ char buffer[4]; std::snprintf(buffer, sizeof(buffer), "%03d", num); return buffer;}
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

ll N;
ll B[11][11];

void input(){
  #ifdef __LOCAL
    fs::path p = __FILE__;
    fs::path input,output;
    input = output = p.parent_path();
    input += string("/input/") + string(p.stem()) + string(".txt");
    output += string("/output/") + string(p.stem()) + string(".txt");
    freopen(input.c_str(), "r", stdin);
    freopen(output.c_str(), "w", stdout);
  #endif
  cin >> N;
}

int top(int x){
  string s;
  s = to_string(x);
  return s[0]-'0';
}

int bottom(int x){
  string s;
  s = to_string(x);
  return s[s.size()-1]-'0';
}

int solve(){
  input();
  memset(B,0,sizeof(B));
  for(int i=1;i<=N;i++){
    B[top(i)][bottom(i)]++;
  }
  ll ans=0;
  for(int i=1;i<=9;i++){
    for(int j=1;j<=9;j++){
      ans+= B[i][j]*B[j][i];     
    }
  }
  cout << ans << endl;
  return 0;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#ifdef DEBUG
	#define D(x...) printf(x);
#else
	#define D(x...)
#endif
int n;
int ans = 1e9;
int sumofdigits(int a)
{
	int ans = 0;
	while (a)
	{
		ans += a%10;
		a/=10;
	}
	return ans;
}
int main()
{
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		ans = min(ans, sumofdigits(i) + sumofdigits(n-i));
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
M = 10**9 + 7
a = [1] + [0] * 12
p = 1
for c in reversed(input()):
    if c == '?':
        a = [sum(x) % M for x in zip(*(a[j % 13:] + a[:j % 13]
                              for j in range(0, -p * 10, -p)))]
    elif c > '0':
        j = -p * int(c) % 13
        a = a[j:] + a[:j]
    p = p * 10 % 13
print(a[5])


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

int f(int n) {
	if (n & 1) {
		return 3 * n + 1;
	}
	else {
		return n >> 1;
	}
}

int solve(int a) {
	int b[1000001] = {};
	int i = 1;
	while (b[a] == 0) {
		b[a] ++;
		a = f(a);
		i++;
	}
	return i;
}


int main() {
	int n;
	cin >> n;
	cout << solve(n) << endl;
	return 0;
}

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

#define INF 0x3fffffff

int N;
int M;
int C[114514];
int R[114514];
int D[5145][5145];
int mind[5145];
bool used[5145];
vector<int> es[114514];

void Bfs(int s) {
  queue<int> q;

  fill(mind, mind+N, INF);
  q.push(s);
  mind[s] = 0;
  while (!q.empty()) {
    int v = q.front(); q.pop();
    for (int u : es[v]) {
      if (mind[u] != INF) continue;
      mind[u] = mind[v]+1;
      q.push(u);
    }
  }

  for (int i=0; i<N; i++) {
    if (mind[i] <= R[s]) {
      D[s][i] = min(D[s][i], C[s]);
    }
  }
}

int Dijkstra(int s, int t) {
  fill(mind, mind+N, INF);
  mind[s] = 0;
  for (int i=0; i<N; i++) {
    int v = -1;
    for (int j=0; j<N; j++) {
      if (used[j]) continue;
      if (v == -1 || mind[v] > mind[j]) v = j;
    }
    if (v == -1) break;
    used[v] = true;

    for (int u=0; u<N; u++) {
      if (mind[u] > mind[v] + D[v][u]) {
        mind[u] = mind[v] + D[v][u];
      }
    }
  }
  return mind[t];
}

int main() {
  scanf("%d%d", &N, &M);
  for (int i=0; i<N; ++i) {
    scanf("%d%d", &C[i], &R[i]);
    for (int j=0; j<N; ++j) {
      if (i == j) continue;
      D[i][j] = INF;
    }
  }

  for (int i=0; i<M; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    es[a].emplace_back(b);
    es[b].emplace_back(a);
  }

  for (int i=0; i<N; i++) {
    Bfs(i);
  }

  printf("%d\n", Dijkstra(0, N-1));
}

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

#define M 1000000/* your task*/
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return /* your task */ key % M ; }
int h2(int key){ return /* your task */ 1 + (key % (M-1)); }

int find(char str[]){

    /* your task */
  long long key, i, h;
  key = getKey(str);
  for (i = 0;;i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],str) == 0){
      return 1;
    }
    else if( strlen(H[h]) == 0){
      return 0;
    }
  }
  return 0;
}

int insert(char str[]){

    /* your task */
  long long key, i ,h;
  key = getKey(str);
  for (i = 0;;i++){
    h = (h1(key) + i*h2(key)) % M;
    if(strcmp(H[h],str) == 0) {
      return 1;
    }
    else if(strlen(H[h]) == 0) {
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}



Measured memory_bytes: 15412
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    ll a, b, x;
    cin >> a >> b >> x;
    if(a > 0) cout << b / x - (a - 1) / x << endl;
    else cout << b / x + 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int N;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		int A;
		cin >> A;
		if (A % 2 == 0 && A % 3 != 0 && A % 5 != 0) {
			cout << "DENIED" << endl;
			return 0;
		}
	}
	cout << "APPROVED" << endl;
}

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

a = list(map(int,input().split()))

memo = [0]*n

memo[0] = 1000

for i in range(1,n):
    memo[i] = max((memo[i-1]%a[i-1]+a[i]*(memo[i-1]//a[i-1])),memo[i-1])

print(memo[-1])

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

int main(){
  int i,j,n,a[50000];
  a[0] = 0;
  a[1] = 0;
  for(i=2;i<50000;i++) a[i] = 1;
  for(i=2;i<=25000;i++){
    if(a[i] == 1){
      for(j=i*2;j<50000;j+=i) a[j] = 0;
    }
  }

  while(1){
    int ans;
    cin >> n;
    if(n == 0) break;
    ans = 0;
    for(i=2;i*2<=n;i++){
      if(a[i] == 1 && a[n-i] == 1) ans++;
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1060
import math
A = [0] * 5
A[0] = int(input())
A[1] = int(input())
A[2] = int(input())
A[3] = int(input())
A[4] = int(input())
ans = 0
min1 = 10
for i in range(0,5):
    m = A[i] % 10
    if ((m > 0) and (m < min1)):
        min1 = m        
    ans += math.ceil(A[i] / 10) * 10
print(ans - (10 - min1))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using st = string;
using P = pair<int, int>;
#define mrep(i, m, n) for(int i = m; i < n; i++)
#define rep(i, n) mrep(i, 0, n)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)

#define NINF (ll)-1e18

int main() {
    vector<ll> num1(2), num2(2);
    rep(i, 2) cin >> num1[i];
    rep(i, 2) cin >> num2[i];
    ll ans = NINF;
    rep(i, 2){
        rep(j, 2){
            ll now = num1[i] * num2[j];
            chmax(ans, now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3640
package main

import "fmt"

const lim = 1e5

func main() {
	var q int
	fmt.Scan(&q)


	primes := primes(lim)

	cnt := 0
	ans := make([]int, lim+1)
	for n := 1;  n <= lim; n++ {
		if primes[n] == 0 && (primes[(n+1)/2]) == 0 {
			cnt++
		}
		ans[n] = cnt
	}

	for i := 0 ;i < q ;i++ {
		var l, r int
		fmt.Scan(&l, &r)
		fmt.Println(ans[r] - ans[l-1])
	}
}
func primes(n int) []int {
	np := make([]int, n+1)
	np[0] = 1
	np[1] = 1
	for i := 2; i*i <= n; i++ {
		if np[i] == 0 {
			for j := i + i; j <= n; j += i {
				np[j] = 1
			}
		}
	}
	return np
}


Measured memory_bytes: 6344
#include<iostream>
#include<cmath>

using namespace std;

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

  int dp[N+1] = {0};

  int arr[N+1];

  for(int i = 1 ; i<=N ; i++)
  {
    cin>>arr[i];
  }

  dp[0] = 0;
  dp[1]  = 0;
  dp[2] = abs(arr[2] - arr[1]);

  for(int i = 3 ; i<=N ; i++)
  {
    int op1 = dp[i-2] + abs(arr[i] - arr[i-2]);
    int op2 = dp[i-1] + abs(arr[i] - arr[i-1]);
    dp[i] = min(op1,op2);
  }

  cout<<dp[N];

  
  return 0;
}

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

#define   ll     long long int

const int N = 200005;
ll ara[N];

int main( )
{
    ll s = 0, i, j, k, t, n;
    cin >> n >> t;
    for (i = 1; i <= n; i++) {
        cin >> ara[i];
    }
    s += t;
    for (i = 2; i <= n; i++) {
        if (ara[i - 1] + t < ara[i]) {
            s += t;
        }
        else {
            s += (ara[i] - ara[i - 1]);
        }
    }
    cout << s << '\n';
    return 0;
}


Measured memory_bytes: 1792
from sys import exit

N = int(input())
t = [0]*(N+1)
x = [0]*(N+1)
y = [0]*(N+1)
for i in range(1,N+1):
    t[i],x[i],y[i] = map(int,input().split())

for i in range(N):
    d = abs(x[i]-x[i+1]) + abs(y[i]-y[i+1])
    s = t[i+1] -t[i]
    if d > s or d%2!=s%2:
        print('No')
        exit()

print('Yes')


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

int main(void)
{
        int i,m,nmin,nmax,Diff,num;

        while(1){
                num = 0;
                Diff = 0;
                cin >> m >> nmin >> nmax;
                if(m == 0 && nmin == 0 && nmax == 0){
                        break;
                }

                vector<int> data(m);
                for(i = 0; i < m; i++){
                        cin >> data[i];
                }

                vector<int> diff(m-1);
                for(i = 0; i < m-1; i++){
                        diff[i] = data[i] - data[i+1];
                }

                for(i = nmin-1; i < nmax; i++){
                        if(diff[i] >= Diff){
                                Diff = diff[i];
                                num = i;
                        }
                }
                cout << num + 1 << endl;
                vector<int>().swap(data);
                vector<int>().swap(diff);
        }
        return 0;
}

Measured memory_bytes: 3104
object Main extends App {
    val x = io.StdIn.readInt

    if (x == 1) println(1)
    else {

        def exponentiation(base: Int): Int = {
            var tmp = base
            while (tmp < x) tmp *= base

            if (tmp == x) x
            else tmp/base
        }

        // 1 <= 基数 <= √x
        val result = (2 to math.sqrt(x).toInt).map(exponentiation _).max
        println(result)

    }
}

Measured memory_bytes: 54772
#include <bits/stdc++.h>
using namespace std;
#define Hello ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define endl '\n'
int main()
{
    Hello
    int n, k;
    cin >> n >> k;
    int arr[n + 5], freq[n + 5] = {}, mn = 1e9, mx = 0;
    set<int> st;
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        freq[arr[i]]++;
        st.insert(arr[i]);
        mn = min(mn, arr[i]);
        mx = max(mx, arr[i]);
    }
    if(st.size() <= k)
        return cout << 0, 0;
    pair<int, int> pr[n + 5];
    int idx = 0, ans = 0;
    for(int i = mn; i <= mx; i++)
    {
        if(freq[i])
        {
            pr[idx].first = freq[i];
            pr[idx].second = i;
            idx++;
        }
    }
    sort(pr, pr + idx);
    //for(int i = 0; i < idx; i++)
    //    cout << pr[i].first << " " << pr[i].second << endl;
    for(int i = 0; i < idx; i++)
    {
        ans += pr[i].first;
        st.erase(pr[i].second);
        if(st.size() <= k)
            return cout << ans, 0;
    }
    cout << ans, 0;
    return 0;
}


Measured memory_bytes: 12800
n = int(input())
e = []
m = []
for i in range(n+1):
    if i % 15 == 0:
        e.append(i)
    elif i % 3 == 0:
        e.append(i)
    elif i % 5 == 0:
        e.append(i)
    else:
        m.append(i)
print(sum(m))

Measured memory_bytes: 48560
#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 n, m;
    cin >> n >> m;
    vint h(n);
    rep(i, n) cin >> h[i];
    vint edge[100005];
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }

    int ans = 0;
    rep(i, n) {
        bool c = true;
        for (int v : edge[i]) {
            if (h[i] <= h[v]) c = false;
        }
        if (c) ans++;
    }

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

Measured memory_bytes: 8732
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int n;
vector<bool> match(string a, string b) {
    vector<bool> m(n, true);
    for (int i = 0; i <= a.size(); ++i) {
        bool ok = true;
        for (int j = 0; j < b.size() && i + j < a.size(); ++j) {
            if (a[i + j] != b[j] && a[i + j] != '?' && b[j] != '?') {
                m[i] = false;
                break;
            }
        }
    }
    return m;
}

int solve(string a, string b, string c) {
    auto mab = match(a, b);
    auto mbc = match(b, c);
    auto mac = match(a, c);
    int ans = 1 << 30;
    for (int i = 0; i < n; ++i) {
        if (!mab[i]) continue;
        for (int j = 0; i + j < n; ++j) {
            if (!mbc[j]) continue;
            if (mac[i + j]) {
                ans = min(ans, int(max({a.size(), i + b.size(), i + j + c.size()})));
            }
        }
    }
    return ans;
}

int main() {
    string s[3];
    for (int i = 0; i < 3; ++i) {
        cin >> s[i];
        n += s[i].size();
        cerr << "length: " << s[i].size() << endl;
    }
    int p[] = {0, 1, 2};
    int ans = 1 << 30;
    while (true) {
        int scr = solve(s[p[0]], s[p[1]], s[p[2]]);
        cerr << scr << endl;
        ans = min(ans, scr);
        if (!next_permutation(begin(p), end(p))) break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

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

  // Simply add the number if it doesn't satisfy the conditions.
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i % 3 && i % 5) {
      ans += i;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3180
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,w = li()
INF = float('inf')

dp = [[INF]*(n*1000+1) for _ in range(n+1)]
for i in range(n+1):
    dp[i][0] = 0
    
for i in range(1,n+1):
    wi, vi = li()
    for j in range(1, n*1000+1):
        if j-vi >= 0:
            dp[i][j] = min(dp[i][j],
                           dp[i-1][j],
                           dp[i-1][j-vi] + wi)
        else:
            dp[i][j] = min(dp[i][j],
                           dp[i-1][j])
        
ans = 0
for i in range(n*1000+1):
    if dp[n][i] <= w:
        ans = i
        
print(ans)

Measured memory_bytes: 310056