akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

int main()
{
    while(true)
    {
        int N; cin >> N;
        if(N == 0) return 0;

        vector<string> F(N);
        rep(i, N)
        {
            cin >> F[i];
        }

        int cnt = 0;
        rep(i, N / 2)
        {
            if(F[i * 2][0] != F[i * 2 + 1][0])
            {
                cnt++;
            }
        }

        cout << cnt << endl;
    }
}



Measured memory_bytes: 3152
n, m = map(int,input().split())
a = [input().split() for i in range(m)]
p = [int(i[0]) for i in a]
q = [j[1] for j in a]

ac = 0
wa = 0
wa_c = [0] * n
ac_c = [False] * n

for t in range(m):
    if ac_c[p[t]-1]:
        continue
    if q[t] == 'AC':
        ac += 1
        ac_c[p[t]-1] = True
        wa += wa_c[p[t]-1]
    else:
        wa_c[p[t]-1] += 1
print(ac,wa)

Measured memory_bytes: 38632
#include<iostream>
using namespace std;
int main()
{
    int ara[5],i,j,temp;
    for(i=0; i<5; i++)
    {
        cin>>ara[i];
    }
    for(i=0; i<4; i++)
    {
        for(j=i+1; j<5; j++)
        {
            if(ara[i]<ara[j])
            {
                temp=ara[j];
                ara[j]=ara[i];
                ara[i]=temp;
            }
        }
    }
    for(i=0; i<5; i++)
    {
        cout<<ara[i];
        if(i<4)
        {
            cout<<" ";
        }
    }
    cout<<endl;
}

Measured memory_bytes: 1164
open Printf open Scanf
let input_int_array n =
	Array.init n (fun _ -> Scanf.scanf " %d" (fun v -> v))	
let get_int () = Scanf.scanf " %d" (fun v -> v)
let get_2_ints () = Scanf.scanf " %d %d" (fun u v -> u,v)
let get_3_ints () = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w)
let get_4_ints () = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x)
let get_5_ints () = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)

let print_int_endline n = n |> string_of_int |> print_endline


let () =
	let n = get_int ()
	in let a = input_int_array n
	in
	let newv p n =
		let c = ref (n+p)
		in let f = ref true
		in
		while !f do
			if !c=n || !c=p || !c<1 || !c>10000 then
				c := 1 + Random.int 10000
			else f := false
		done; !c
	in
	let prev,c = ref a.(0),ref 0
	in
	for i=1 to n-1 do
		if a.(i) = !prev then (
			c := !c + 1;
			a.(i) <-
				if i=n-1 then newv !prev 0
				else newv !prev a.(i+1)
		);
		prev := a.(i)
	done;
	!c |> print_int_endline

Measured memory_bytes: 384
#define _USE_MATH_DEFINES

#include <iostream>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <set>
#include <utility>
#include <vector>
#include <list>
#include <algorithm>
#include <regex>
#include <cmath>
#include <map>
#include <iterator>
#include <climits>
#include <numeric>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <array>
#include <valarray>
#include <complex>
#include <random>
#include <functional>
#include <cassert>
#include <chrono>
#include <memory>

using namespace std;

#define int long long
//region TEMPLATE
////@formatter:off
#define double long double
typedef long long ll;
typedef unsigned long long ull;
template<typename T>void __read(T &a) { cin >> a; }
template<typename T, typename ... Args> void __read(T &a, Args &... args) { cin >> a;__read(args...);}
#define make(t, ...) t __VA_ARGS__; __read(__VA_ARGS__)
#define makev(a, n) VI a(n); FOR(n) cin >> a[i];
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define FORIT(p) for(auto it = p.begin(); it != p.end(); it++)
#define FOR(b) for(signed i = 0; i <(b); i++)
#define FORE(i, l, r) for(int i = (l); i < (r); i++)
#define NFOR(i, n) for(int i = (((int) n)-1); i >= 0; i--)
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<pair<int, int>, int> PPII;
constexpr ll M7 = 1000000007ll;
constexpr ll M9 = 1000000009ll;
constexpr ll MFFT = 998244353ll;
template<class T> void outv(T &a) { for (auto &x : a) cout << x << ' '; }
static mt19937 rnd(static_cast<unsigned>(chrono::steady_clock::now().time_since_epoch().count())); // NOLINT(cert-err58-cpp)
auto __fast_io__ = (ios_base::sync_with_stdio(false), cin.tie(nullptr)); // NOLINT(cert-err58-cpp,cppcoreguidelines-interfaces-global-init)
////@formatter:on
//endregion


int32_t main() {
    make(int, x, y, a, b, c);
    makev(p, a);
    makev(q, b);
    makev(r, c);
    sort(RALL(p));
    sort(RALL(q));
    sort(RALL(r));
    multiset<int> f, s;
    for (int i = 0; i < x; ++i) {
        f.insert(p[i]);
    }
    for (int i = 0; i < y; ++i) {
        s.insert(q[i]);
    }
    int i = 0;
    while(i < c && r[i] > min(*f.begin(), *s.begin())){
        if (*f.begin() < *s.begin()){
            f.erase(f.begin());
            f.insert(r[i]);
        } else {
            s.erase(s.begin());
            s.insert(r[i]);
        }
        i++;
    }
    cout << accumulate(ALL(f), 0ll) + accumulate(ALL(s), 0ll);
    return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <cstdio>

int main() {
  int n;
  while(scanf("%d", &n) != EOF) {
    int ans=0;
    for(int i=0;i<=9;i++) {
      for(int j=0;j<=9;j++) {
        for(int k=0;k<=9;k++) {
          for(int l=0;l<=9;l++) {
            if(i+j+k+l==n)
              ans++;
          }   
        }
      }
    }
    std::cout << ans << std::endl;
  }
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char a[15];
	int i,j=0,k=0;
	scanf("%s",a);
	for(i=0;i<=sizeof(a);i++)
	{
    if(a[i]=='x')
		{
			k=k+1;
		}
	}
	if(k>=8)
	{
		printf("NO");
	}

	else
	{
		printf("YES");
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const int INF = 100100100;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

int n, m, l, r;
int res = 0;

int main(int argc, char *argv[]){
    cin >> n >> m;
    vec L(m);
    vec R(m);
    l = 1;
    r = INF;
    rep(i, m){
        cin >> L[i] >> R[i];

        if(l <= L[i]) l = L[i];
        if(R[i] <= r) r = R[i];
    }
    if(l <= r) cout << r - l + 1 << endl;
    else cout << 0 << endl;
    return 0;
}

Measured memory_bytes: 1024
//$ darklife_12
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <random>
#include <deque>
#include <queue>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <bitset>
#include <sstream>
#include <cstring>
#include <bits/stdc++.h>
#include <iostream>
#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define for0(i, n) for (int i = 0; i < (int)(n); ++i) // 0 based indexing
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i) // 1 based indexing
#define forc(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i) // closed interver from l to r r inclusive
#define forr0(i, n) for (int i = (int)(n) - 1; i >= 0; --i) // reverse 0 based.
#define forr1(i, n) for (int i = (int)(n); i >= 1; --i) // reverse 1 based
#define enterarray(a,n) for(int i=0;i<(int)(n);++i)cin>>a[i];
#define ins insert
const int MOD =998244353;
const int MX = int(2e6+9);
using namespace std;
int even(ll num){
    if(num%2==0)return 1;
    else return 0;
}
void printvector(vector<int> v){
    int i;
    for0(i,v.size())cout<<v[i]<<" ";
}
void solve()              
{
    int n,m,i,j,k;
    int a[200005],b[200005];
    int ans=0,res;
    bool flag=true;
    vector<int> v;
    string s1,s2;
    set<int> s;
    int h,w;
    char col[6][6];
    cin>>h>>w>>k;
    for0(i,h)for0(j,w)cin>>col[i][j];
    for0(i,1<<h){
        for0(j,1<<w){
            int cl=0;
            for0(n,h){
                for0(m,w){
                    if((i>>n&1)&&(j>>m&1)&&(col[n][m]=='#'))cl++;
                }//cout<<cl;
            }
            if(cl==k)ans++;
        }
    }
    cout<<ans;
    
}
 
int main()
{
    FAST;
   int t;
    t=1;
    while(t--)
    {
        solve();
       cout<<"\n";
    }
}

Measured memory_bytes: 3596
N = int(input())
x = [0] * N
y = [0] * N
h = [0] * N
for i in range(N):
  x[i], y[i], h[i] = map(int, input().split())

hi = -1
for i in range(N):
  if h[i] > 0:
    hi = i
    break
if hi == -1:
  exit()

for X in range(101):
  for Y in range(101):
    H = h[hi] + abs(X - x[hi]) + abs(Y - y[hi])
    flag = 1
    for i in range(N):
      if h[i] != max(H - abs(X - x[i]) - abs(Y - y[i]), 0):
        flag = 0
        break
    if flag:
      break
  if flag:
    break
print(X, Y, H)

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

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b, a % b);
}

using Graph = vector<vector<int>>;

ll calc(ll a, ll b, ll p){//aのb乗をpで割った余り
  if(b == 0) return 1;

  else if(b%2 == 0){
    ll d = calc(a,b/2,p);
    return (d*d)%p;
  }
  else if(b%2 == 1){
    return (a * calc(a,b-1,p))%p;
  }
}

typedef pair<int,int> P;

bool is_prime(int n){//nが素数であるかどうか判定 iで割り切れると素数でない
    if(n == 1) return false;//1は例外
    for(int i = 2;i*i <= n;i++){
        if(n%i == 0) return false;
    }
    
    return true;
}

int main(){
  int r;
  cin >> r;
  cout << r*r << endl;
 }

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = l[0], B = l[1], C = l[2];

            if (A % 2 == 0 && A == B && B == C && A == C)
            {
                Console.WriteLine(-1);
                return;
            }

            var count = 0;
            while (A % 2 == 0 && B % 2 == 0 && C % 2 == 0)
            {
                count++;
                var a = A / 2;
                var b = B / 2;
                var c = C / 2;
                A = b + c;
                B = a + c;
                C = a + b;
            }

            Console.WriteLine(count);
        }
    }
}


Measured memory_bytes: 13396
#include<bits/stdc++.h>
using namespace std;
#define mem(a) memset(a,0,sizeof(a))
#define dbg(x) cout<<#x<<" = "<<x<<endl
#define ll long long
//不要再爆long long了！！！！！！！！不要再爆long long了！！！！！！！ 
void solve(ll n)
{
	if(n)
	{
		n--;
		solve(n/26);
		putchar('a'+n%26);
	}
}
int main()
{
	ll n,i,t;
	cin>>n;
	solve(n);
	return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;

int main(){
    while(1){
        int n,m;
        cin >> n >> m;
        if(n==0 && m==0) break;
        vector<P> pd(n);
        rep(i,n) cin >> pd[i].second >> pd[i].first;
        sort(pd.begin(),pd.end(),greater<P>());
        int ans = 0;
        rep(i,n){
            if(pd[i].second <= m) m -= pd[i].second;
            else if(m==0) ans += pd[i].first * pd[i].second;
            else{
                pd[i].second -= m;
                m = 0;
                ans += pd[i].first * pd[i].second;
            }
        }
        cout << ans << endl;
    }
    return 0;
}



Measured memory_bytes: 3156
/* ex3_2
   kohei_suzuki */

#include <stdio.h>
int main(void){
    int num, rem; //本数numとnumの一の位rem

    scanf("%d",&num);
    rem = num % 10; //numの一の位を取り出す

    if(rem==0 || rem==1 || rem==6 || rem==8){ //remが0,1,6,8の場合
        printf("pon\n");
    }else if(rem == 3){ //remが3の場合
        printf("bon\n");
    }else{ //remが2,4,5,7,9の場合
        printf("hon\n");
    }

    return 0;
}

Measured memory_bytes: 1644
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC080A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n, a, b, p, i;

            var word = Console.ReadLine().Split(' ');
            n = int.Parse(word[0]);
            a= int.Parse(word[1]);
            b= int.Parse(word[2]);

            if (n * a <= b)
                Console.WriteLine(a * n);

            else if (n * a >= b)
                Console.WriteLine(b);



            Console.ReadKey();


        }
    }
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int n,x,c=0;
    while(true){
        cin>>n>>x;
        if(n == 0 && x == 0) break;
        else for(int i=1;i<=n;i++){
            for(int j=1;j<i;j++){
                for(int k=1;k<j;k++){
                    if(i+j+k==x) c++;
                }
            }
        }
        cout<<c<<endl;
        c = 0;
    }
    return 0;
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = 1'010'000'000'000'000'017LL;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

int main() {
    // AtCoder
    // template
    ll r;
    cin >> r;
    long double pi = 3.1415926535;
    cout << fixed << setprecision(15) << (long double)r * pi * 2.0;
}


Measured memory_bytes: 3804
s,t = gets.split(" ").map(&:to_s)
a,b = gets.split(" ").map(&:to_i)
u = gets.to_s

s = s.chomp
t = t.chomp
u = u.chomp

if u == s
    a = a - 1
elsif u == t
    b = b - 1
end

puts "#{a} #{b}".chomp

Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define PQ priority_queue
#define UM unordered_map
#define ALL(a) (a).begin(),(a).end()
typedef vector<ll> vi;
typedef vector<vector<ll>> vvi;
const ll INF = (1ll << 60);
typedef pair<ll,ll> pii;
struct Edge {ll s,t,d;};
struct vector<vector<Edge>> Graph;

int main(){
  string s; cin>>s;
  if(s.length()>=4&&s.substr(0,4)=="YAKI") cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 764
<?php
$input = fgets(STDIN);
$inputs = explode(" ", $input);
$kosuu = $inputs[0];
$aji   = $inputs[1];
$flg   = 0;
$ajiSum = 0;

for ($i = 0; $i < $kosuu;  $i++  ) {
	if (0 == $aji + $i) {
      	$flg = 1;
		continue;
	} else {
		$ajiSum = $ajiSum + $aji + $i;
	}
}

if ($flg === 0) {
  if ($aji > 0) {
	$ajiSum = $ajiSum - $aji;
  } else {
	$ajiSum = $ajiSum - ($aji + $kosuu - 1);
  }
}
echo $ajiSum;

?>

Measured memory_bytes: 4604
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))

int N;
vector<vector<int>> edges;

int dfs(int par, int now) {
	vector<int> res;
	for (int next : edges[now])if (next != par) {
		res.push_back(dfs(now, next));
	}
	if (res.empty())return 0;
	sort(res.begin(), res.end(), greater<int>());
	rep(i, res.size())res[i] += i;
	return *max_element(res.begin(), res.end()) + 1;
}

int main()
{
	cin >> N;
	edges.resize(N);
	REP(i, 1, N) {
		int a;
		cin >> a;
		a--;
		edges[i].push_back(a);
		edges[a].push_back(i);
	}
	cout << dfs(-1, 0) << endl;
	return 0;
}


Measured memory_bytes: 15104
// C - Alchemist

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

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

	priority_queue<double, vector<double>, greater<double>> PQ;

	double v;
	for (int i=0; i<N; i++) {
		cin >> v;
		PQ.push(v);
	}

	double ans;
	while(true) {
		double min_v = PQ.top();
		PQ.pop();

		if (PQ.empty()) {
			ans = min_v;
			break;
		}

		double second_min_v = PQ.top();
		PQ.pop();

		PQ.push((min_v + second_min_v) / 2);
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}


int main() {
    ll n, k;
    cin >> n >> k;

    vector<ll> numbers(n), values(n);
    rep(i, n) cin >> numbers[i] >> values[i];

//    cout << bitset<8>(k) << endl;
//    rep(i, n) cout << bitset<8>(numbers[i]) << ' ' << values[i] << endl;

    vector<ll> candidate;
    {
        ll sum = 0;
        rep(i, n) {
            if ((k | numbers[i]) == k) sum += values[i];
        }
        candidate.push_back(sum);
    }

    rep(i, 35) {
        bool d = (k >> i) & 1;
        if (!d) continue;

        ll sum = 0;

        ll target = k >> (i + 1);
        rep(j, n) {
            ll l = numbers[j];
            bool b = ((l >> i) & 1);
            if (b) continue;
            ll c = (l >> (i + 1));
            if ((target | c) != target) continue;
            sum += values[j];
        }
        candidate.push_back(sum);
    }

    // 0

    cout << *max_element(candidate.begin(), candidate.end()) << endl;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
 
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 
//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF=INT_MAX;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

int rd(int num){
	return min(255,max(0,num));
}

bool ch(char c){
	return (c>='0'&&c<='9');
}
int dp[20002][256];
int main(){
	int W,H;
	while(cin>>W>>H){
		if(W==0)return 0;
		char C[75][75];
		REP(i,75)REP(j,75)C[i][j]='#';
		REP(i,H)REP(j,W)cin>>C[i+1][j+1];
		string dp[75][75];
		REP(i,75)REP(j,75)dp[i][j]="";
		string res="";
		FOR(h,1,H+1)FOR(w,1,W+1){
			string tmp="";
			if(!ch(C[h][w]))continue;
			
			tmp=dp[h][w-1];
			/*if(SZ(tmp)<SZ(dp[h][w-1])||(SZ(tmp)==SZ(dp[h][w-1])&&tmp<=dp[h][w-1])){
				tmp=dp[h][w-1];
			}*/
			if(SZ(tmp)<SZ(dp[h-1][w])||(SZ(tmp)==SZ(dp[h-1][w])&&tmp<=dp[h-1][w])){
				tmp=dp[h-1][w];
			}
			if(tmp!="0")dp[h][w]=tmp+C[h][w];
			else dp[h][w]=C[h][w];
			if(SZ(res)<SZ(dp[h][w])||(SZ(res)==SZ(dp[h][w])&&res<=dp[h][w])){
				res=dp[h][w];
			}
		}
		cout<<res<<endl;
	}
	return 0;
}
/*
7 4
0000AAA
AAAA1AA
AAAAA0A
AAAAAA1
*/

Measured memory_bytes: 1384
#include <cstdio>
#include <iostream>
using namespace std;
int N, arr[100005], Sum[100005];

int abs(int num)
{
    return num > 0 ? num : -num;
}

int main()
{
    scanf("%d", &N);
    for(int i = 1; i <= N; i++)
    {
        scanf("%d", &arr[i]);
        Sum[i] = Sum[i - 1] + abs(arr[i] - arr[i - 1]);
    }
    Sum[N + 1] = Sum[N] + abs(arr[N]);
    for(int i = 1; i <= N; i++)
    {
        printf("%d\n", Sum[N + 1] - Sum[i + 1] + Sum[i - 1] + abs(arr[i - 1] - arr[i + 1]));
    }
}

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

int main(void){
	int sx,sy,tx,ty;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	int a,b,c,d,e,f,g,h;
	a = ty-sy;
	b = tx-sx;
	c = a;
	d = b;
	e = a+1;
	f = b+1;
	g = e;
	h = f;
	int i;
	for(i=1;i<=a;i++){
		printf("U");
	}
	for(i=1;i<=b;i++){
		printf("R");
	}
	for(i=1;i<=c;i++){
		printf("D");
	}
	for(i=1;i<=d;i++){
		printf("L");
	}
	printf("L");
	for(i=1;i<=e;i++){
		printf("U");
	}
	for(i=1;i<=f;i++){
		printf("R");
	}
	printf("DR");
	for(i=1;i<=g;i++){
		printf("D");
	}
	for(i=1;i<=h;i++){
		printf("L");
	}
	printf("U\n");
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int n,a;
	int flag=1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a;
		if(a%2==0){
			if(a%3==0||a%5==0){
			}
			else{
				cout<<"DENIED";
				return 0;
			}
		}
	}
	cout<<"APPROVED";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
//#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
int N, A, B, C, D;
string S;

bool IsOkay(int s, int g)
{
    for (int i = s; i < g; ++i)
    {
        if (S[i] == '#' && S[i + 1] == '#')
        {
            return false;
        }
    }
    return true;
}

bool IsOkay2(int s, int g)
{
    for (int i = s; i < g - 1; ++i)
    {
        if (S[i] == '.' && S[i + 1] == '.' && S[i + 2] == '.')
        {
            return true;
        }
    }
    return false;
}

void _main()
{
    cin >> N >> A >> B >> C >> D;
    cin >> S;
    const bool isSnukeOkay = IsOkay(A - 1, C - 1);
    const bool isFnukeOkay = IsOkay(B - 1, D - 1);
    if (C < D)
    {
        cout << (isSnukeOkay && isFnukeOkay ? "Yes" : "No") << endl;
    }
    else
    {
        cout << (isSnukeOkay && isFnukeOkay && IsOkay2(B - 2, D) ? "Yes" : "No") << endl;
    }
}


Measured memory_bytes: 592
h,n=map(int,input().split())
INF=float('inf')
dp=[INF for i in range(h+1)]
dp[0]=0
for i in range(n):
    a,b=map(int,input().split())
    for i in range(1,h+1):
        dp[i]=min(dp[i],dp[max(i-a,0)]+b)
print(dp[-1])

Measured memory_bytes: 50780
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <iostream>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <cmath>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cfloat>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cctype>
#include <cstdio>
#include <cassert>
using namespace std;

#define EPS 1e-12
#define ull unsigned long long
#define ll long long
#define VI vector<ll>
#define PII pair<ll, ll> 
#define VVI vector<vector<ll> >
#define VVVI vector<vector<vector<ll>>>
#define VVVVI vector<vector<vector<vector<ll>>>>
#define REP(i,n) for(int i=0,_n=(n);(i)<(int)_n;++i)
#define REPR(i,n) for(int i=(int)(n)-1;0<=(i);--i)
#define RANGE(i,a,b) for(int i=(int)a,_b=(int)(b);(i)<_b;++i)
#define RANGER(i,a,b) for(int i=(int)(b)-1,_a=(int)(a);(_a)<=i;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define ALLR(c) (c).rbegin(), (c).rend()
#define PB push_back
#define MP(a, b) make_pair(a, b)
#define POPCOUNT __builtin_popcount
#define POPCOUNTLL __builtin_popcountll
#define CLEAR(table, v) memset(table, v, sizeof(table));
#define UNIFORM_DOUBLE(a, b) (((b-a)*(double)rand()/RAND_MAX)+a) // [a, b) 
#define UNIFORM_LL(a, b) (ll)UNIFORM_DOUBLE(a, b) // [a, b) 
#define IN(v, lo, hi) ((lo)<=(v) && (v)<(hi))
#define DD(v) cout<<#v<<": "<<v<<endl
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const map<T0, T1>& v) { for( typename map<T0, T1>::const_iterator p = v.begin(); p!=v.end(); p++ ){os << p->first << ": " << p->second << " ";} return os; }
template <typename T0, typename T1> std::ostream& operator<<(std::ostream& os, const pair<T0, T1>& v) { os << v.first << ": " << v.second << " "; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<T>& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << " "; } return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const set<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const deque<T>& v) { vector<T> tmp(v.begin(), v.end()); os << tmp; return os; }
template <typename T> std::ostream& operator<<(std::ostream& os, const vector<vector<T> >& v) { for( int i = 0; i < (int)v.size(); i++ ) { os << v[i] << endl; } return os; }
template<typename T>void maxUpdate(T& a, T b) {a = max(a, b);}
template<typename T>void minUpdate(T& a, T b) {a = min(a, b);}

#define MOD 1000000007LL
#define INF (1LL<<60)

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	while(cin>>s) {
		string ans;
		if(s=="A") ans = "T";
		if(s=="T") ans = "A";
		if(s=="G") ans = "C";
		if(s=="C") ans = "G";
		cout<<ans<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

INF = 10 ** 20

def main():
  n = int(input())
  edges = [[] for _ in range(n)]
  for _ in range(n - 1):
    s, t, w = map(int, input().split())
    edges[s].append((w, t))
    edges[t].append((w, s))
  
  def func(start):
    cost = [INF] * n
    que = [(0, start)]
    cost[start] = 0
    
    while que:
      acc, num = heappop(que)
      for weight, to in edges[num]:
        if weight + acc < cost[to]:
          cost[to] = weight + acc
          heappush(que, (weight + acc, to))
    return cost
  
  cost1 = func(0)
  max_ind = cost1.index(max(cost1))
  cost2 = func(max_ind)
  
  print(max(cost2))
main()


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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

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

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	string s;
	cin >> s;
	
	int mindif = INF;
	rep(i, s.length() - 2) {
		int n = 0;
		n = (s[i] - '0') * 100 + (s[i + 1] - '0') * 10 + (s[i + 2] - '0');
		mindif = min(abs(n - 753), mindif);
	}
	
	cout << mindif << endl;
	
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    a.push_back(num);
  }
  sort(a.begin(), a.end());
  deque<int> d;
  int l = 1, r = n - 2;
  d.push_back(a[0]);
  d.push_back(a[n - 1]);
  while (l <= r) {
    int mx = a[r], mi = a[l];
    int f = d.front(), b = d.back();
    if (d.front() >= d.back()) {
      if (abs(f - mi) >= abs(b - mx)) {
        d.push_front(mi);
        l++;
      } else {
        d.push_back(mx);
        r--;
      }
    } else {
      if (abs(f - mx) >= abs(b - mi)) {
        d.push_front(mx);
        r--;
      } else {
        d.push_back(mi);
        l++;
      }
    }
  }
  //cout << endl << d.size() << endl;
  int before = d.front();
  d.pop_front();
  //cout << before << endl;
  long long ans = 0;
  while (!d.empty()) {
    int next = d.front();
    //cout << next << endl;
    d.pop_front();
    ans += abs(before - next);
    before = next;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1016
//設定言語check
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <limits.h>
#include <algorithm>
#include <iomanip>
#include <math.h>
using namespace std;

int main(){
  int N, Q, check = 0, power = 1 ;
  long long int ans = 0 ;
  cin >> N ;
  int A[N], Num[100001] = {} ;
  for(int i=0;i<N;i++){
    cin >> A[i] ;
    Num[A[i]]++ ;
    ans += A[i] ;
  }
  cin >> Q ;
  int B[Q], C[Q] ;
  for(int i=0;i<Q;i++){
    cin >> B[i] >> C[i] ; 
    ans += ( Num[B[i]] * (C[i] - B[i]) ) ;
    cout << ans << endl ;
    Num[C[i]] += Num[B[i]] ;
    Num[B[i]] = 0 ;
  }
  return 0 ;
}  

Measured memory_bytes: 5148
def resolve():
    s=input()
    t=input()
    n=len(s)
    m=len(t)
    if n>=11:
        print("No")
        exit()
    if m!=n+1:
        print("No")
        exit()
    for i in range(n):
        if s[i]!=t[i]:
            print("No")
            exit()
    print("Yes")
resolve()

Measured memory_bytes: 61700
#include <iostream>
#include  <string.h>
using namespace std;

int main(void)
{
    char s[200000];
    cin>>s;
    int x,y;
    int m = strlen(s);
    for(int i =0;i<m;i++)
    {
        if(s[i]=='A')
        {
            x=i;
            break;
        }
    }
    for(int j=m-1;j>=0;j--)
    {
        if(s[j]=='Z')
        {
            y=j;
            break;
        }
    }
    cout << y-x+1<<endl;
    return 0;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		String s = scan.next();

		int nextDay = 0;

		// 次の日曜日
		switch (s) {
			case "SUN":
				nextDay = 7;
				break;
			case "MON":
				nextDay = 6;
				break;
			case "TUE":
				nextDay = 5;
				break;
			case "WED":
				nextDay = 4;
				break;
			case "THU":
				nextDay = 3;
				break;
			case "FRI":
				nextDay = 2;
				break;
			case "SAT":
				nextDay = 1;
				break;
		}

		System.out.println(nextDay);
	}
}

Measured memory_bytes: 21844
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<functional>
#include<string>
#include<cstring>
#include <sstream>
using namespace std;
class charToInt{
    public:
    int ctoi(const char c){
        switch(c){
            case '0': return 0;
            case '1': return 1;
            case '2': return 2;
            case '3': return 3;
            case '4': return 4;
            case '5': return 5;
            case '6': return 6;
            case '7': return 7;
            case '8': return 8;
            case '9': return 9;
            default: return -1;
        }
    }
};
int main(void){
    string s;
    cin >> s;
    int sint = atoi(s.c_str());
    int tmp = 0;
    charToInt cti;
    for(int i = 0; i < s.size(); i++){
        tmp += cti.ctoi(s.at(i));
    }
    if(sint % tmp == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
/*
 * “The difference between a master and a novice - is that the master has failed more times,
 *  than the novice has tried.”
 */
#include <bits/stdc++.h>
#define pvar(x) clog<<"["<<#x<<":"<<x<<"]\n"
using namespace std;
using ll = long long int;
void solve(){
	int n;
	cin>>n;
	vector<int> v(n);
	for(int i=0;i<n;i++)cin>>v[i];
	ll ans = 0,mx=v[0];
	for(int i=1;i<n;i++){
		if(v[i] < mx){
			ans += abs(mx - v[i]);
		}
		else mx = v[i];
	}
	cout<<ans<<endl;
}
int main(){
	ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  t = 1;
  while(t--){
		solve();
	}
}
 


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
	long long n = 0;
	cin >> n;
	vector <long long> vect(100001,0);
	long long sum = 0;
	long long temp = 0;
	for (long long i = 0; i < n; i++)
	{
		cin >> temp;
		sum = sum + temp;
		vect[temp]++;
	}
	long long q = 0;
	cin >> q;
	long long t1 = 0;
	long long t2 = 0;
	for (long long i = 0; i < q; i++)
	{
		cin >> t1 >> t2;
		if (vect[t1] != 0)
		{
			vect[t2] = vect[t2] + vect[t1];
			sum = sum - (t1*vect[t1]) + (t2*vect[t1]);
			cout << sum << endl;
			vect[t1] = 0;
		}
		else
		{
			cout << sum << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long N,R,B;
    //scanf("%ld %ld %ld",&N,&B,&R);
    cin>>N>>B>>R;
    long long res = B*(N/(B+R));
    if(B == 0) cout<<"0\n";
    else{
        long long r = N%(B+R);
        if(r<=B){
            cout<<res+r<<"\n";
        }
        else{
            cout<<res+B<<"\n";
        }
    }
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define MAX 300005
#define SZ 500
#define INF (1000000007)
typedef pair<int,int> P;
int a[MAX];
int A[MAX];
int b[MAX];
int B[MAX];
vector< P > ma,mb,mA,mB;

void update(int a[MAX],int A[MAX],vector< P > &ma,vector< P > &mA,int i,int x){
  int I=i/SZ;

  ma.push_back( P(i,a[i]) );
  a[i]=x;
  ma.push_back( P(i,a[i]) );
  
  int mini=INF;
  for(int i=0;i<SZ;i++){
    mini=min(mini, a[ I*SZ + i ] );
  }

  mA.push_back( P(I,A[I]) );
  A[I]=mini;
  mA.push_back( P(I,A[I]) );
}

int query(int a[MAX],int A[MAX],int l,int r){
  int res=INF;
  int i=l;
  while(i<r){
    if(i%SZ==0 && i+SZ <= r){
      res=min(res,A[i/SZ]);
      i+=SZ;
    }else{
      res=min(res,a[i]);
      i++;
    }
  }
  return res;
}


void q5(){
  reverse(ma.begin(),ma.end());
  for(int i=0;i<(int)ma.size();i++){
    P p=ma[i];
    a[ p.first ] = p.second;
  }
  reverse(mA.begin(),mA.end());
  for(int i=0;i<(int)mA.size();i++){
    P p=mA[i];
    A[ p.first ] = p.second;
  }
  
  for(int i=0;i<(int)mb.size();i++){
    P p=mb[i];
    a[ p.first ] = p.second;
  }
  for(int i=0;i<(int)mB.size();i++){
    P p=mB[i];
    A[ p.first ] = p.second;
  }
  
  ma.clear();
  mA.clear();
  mb.clear();
  mB.clear();
}

void q6(){
  reverse(mb.begin(),mb.end());
  for(int i=0;i<(int)mb.size();i++){
    P p=mb[i];
    b[ p.first ] = p.second;
  }
  reverse(mB.begin(),mB.end());
  for(int i=0;i<(int)mB.size();i++){
    P p=mB[i];
    B[ p.first ] = p.second;
  }
  
  for(int i=0;i<(int)ma.size();i++){
    P p=ma[i];
    b[ p.first ] = p.second;
  }
  for(int i=0;i<(int)mA.size();i++){
    P p=mA[i];
    B[ p.first ] = p.second;
  }
  
  ma.clear();
  mA.clear();
  mb.clear();
  mB.clear();
}
int N,Q;

int main(){
  scanf("%d",&N);
  
  for(int i=0;i<N;i++){
    int x;
    scanf("%d",&x);
    update(a,A,ma,mA,i,x);
  }
  
  for(int i=0;i<N;i++){
    int x;
    scanf("%d",&x);
    update(b,B,mb,mB,i,x);
  }

  scanf("%d",&Q);
  while(Q--){
    int x,y,z;
    scanf("%d %d %d",&x,&y,&z);
    if(x==1){
      update(a,A,ma,mA,y-1,z);
    }
    if(x==2){
      update(b,B,mb,mB,y-1,z);
    }
    if(x==3){
      printf("%d\n", query(a,A,y-1,z) );
    }
    if(x==4){
      printf("%d\n", query(b,B,y-1,z) );
    }
    if(x==5){
      q5();
    }
    if(x==6){
      q6();
    }
  }
  return 0;
}

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

int table[505][505];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // init
    int N, M, Q; cin >> N >> M >> Q;
    int l, r, p[101010], q[101010];
    for(int i=0; i < M; ++i) {
        cin >> l >> r;
        ++table[l][r];
    }
    for(int i=0; i < Q; ++i) cin >> p[i] >> q[i];

    // sum
    for(int i=0; i <= N; ++i)
        for(int j=0; j <= N; ++j)
            table[i+1][j+1] += table[i+1][j] + table[i][j+1] - table[i][j];

    // calc
    for(int i = 0; i < Q; ++i)
        cout << table[q[i]][q[i]] - table[q[i]][p[i]-1] - table[p[i]-1][q[i]] + table[p[i]-1][p[i]-1] << '\n';

    return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>  // min, max
#include <fstream>  // ifstream
#include <iomanip>  // setprecision
using namespace std;
typedef long long ll;

int main(void)
{
#ifdef FILE_DEBUG
    ifstream inputFile("data/input.txt");
    cin.rdbuf(inputFile.rdbuf());
#endif
    // これより下にコードを書く

    int A, B;
    cin >> A >> B;

    for (int i = 1; (i <= 3); ++i) {
        if ((A * B * i) % 2 != 0) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
  int score;
  int sum_of_scores = 0;
  int max = 0;
  int min = 100;

  for (int i = 0; i < 6; i++) {
    cin >> score;
    if (i < 4) {
      sum_of_scores += score;
      if (score < min) min = score;
    } else {
      if (score > max) max = score;
    }
  }
  sum_of_scores  = sum_of_scores  - min + max;

  cout << sum_of_scores << endl;
}



Measured memory_bytes: 3096
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>

using namespace std;

int main()
{
	int n;
	long long int c, x[100001], v[100001];
	long long int vsum[100001], vsum1[100001];
	vsum[0]=0;
	vsum1[0]=0;
	scanf("%d %lld", &n, &c);
	for(int i=1; i<=n; i++){
		scanf("%lld %lld", &x[i], &v[i]);
		if(i==1){
			vsum[1]=v[1];
		}else{
			vsum[i]=vsum[i-1]+v[i];
		}
	}
	for(int i=1; i<=n; i++){
		if(i==1){
			vsum1[1]=v[n];
		}else{
			vsum1[i]=vsum1[i-1]+v[n+1-i];
		}
	}
	long long int vmax1[100001]={}, vmax2[100001]={}, vmaxinv1[100001]={}, vmaxinv2[100001]={};
	for(int i=1; i<=n; i++){
		if(vmax1[i-1]<vsum[i]-x[i]){
          vmax1[i]=vsum[i]-x[i];
        }else{
          vmax1[i]=vmax1[i-1];
        }
      
	}
	for(int i=1; i<=n; i++){
		if(vmax2[i-1]<vsum[i]-2*x[i]){
          vmax2[i]=vsum[i]-2*x[i];
        }else{
          vmax2[i]=vmax2[i-1];
        }
	}
	for(int i=1; i<=n; i++){
		if(vmaxinv1[i-1]<vsum1[i]-(c-x[n+1-i])){
          vmaxinv1[i]=vsum1[i]-(c-x[n+1-i]);
        }else{
          vmaxinv1[i]=vmaxinv1[i-1];
        }
	}
	for(int i=1; i<=n; i++){
		if(vmaxinv2[i-1]<vsum1[i]-2*(c-x[n+1-i])){
          vmaxinv2[i]=vsum1[i]-2*(c-x[n+1-i]);
        }else{
          vmaxinv2[i]=vmaxinv2[i-1];
        }
	}
	long long int ans=0;
	for(int i=0; i<=n; i++){
		if(ans<vmax1[i]+vmaxinv2[n-i]) ans=vmax1[i]+vmaxinv2[n-i];
		if(ans<vmax2[i]+vmaxinv1[n-i]) ans=vmax2[i]+vmaxinv1[n-i];
	}
 
	printf("%lld\n", ans );
	return 0;
}

Measured memory_bytes: 6400
#include <iostream>
using namespace std;
#include <vector>
#include <algorithm>
#include <cmath>

int main(int argc, char **argv)
{
	int N, T, A;

	cin.tie(NULL);

	cin >> N >> T >> A;

	int H[N];

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

	float h[N];

	for (int i = 0; i < N; i++)
	{
		h[i] = T - H[i] * 0.006;
	}

	int nearest_index = 0;
	float nearest_value = abs(h[0] - A);

	for (int i = 1; i < N; i++)
	{
		float tmp = abs(h[i] - A);
		if (tmp < nearest_value)
		{
			nearest_value = tmp;
			nearest_index = i;
		}
	}

	cout << nearest_index + 1;

	return 0;

}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<iostream>
using namespace std;
#define AMA (10000)
int N,K;
int D[111];
int dp[111][4][4];
int solve(int day,int k,int r){
  if(dp[day][k][r]!=-1) return dp[day][k][r];
  if(day==N+1) return dp[day][k][r]=1;
  if(D[day]){
    if(r==2 && D[day]==k) return dp[day][k][r]=0;
    if(D[day]==k)
      return dp[day][k][r]=solve(day+1,D[day],r+1);
    else
      return dp[day][k][r]=solve(day+1,D[day],1);   
  }
  int ret=0;
  for(int i=1;i<=3;i++){
    if(r==2 && i==k) continue;
    if(i==k)
      ret+=solve(day+1,i,r+1);
    else
      ret+=solve(day+1,i,1);
    ret%=AMA;
  }
  return dp[day][k][r]=ret;
}
main(){
  memset(dp,-1,sizeof(dp));
  scanf("%d %d",&N,&K);
  for(int i=0;i<K;i++){
    int a,b;
    scanf("%d %d",&a,&b);
    D[a]=b;
  }
  printf("%d\n",solve(1,0,0)%AMA);
}

Measured memory_bytes: 1204
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>
#define LL long long
#define INF 1<<31-1
#define LNF 9223372036854775807
#define PI 3.14159265358979
#define MIN(x,y) ((x)<(y)?(x):(y))
#define MAX(x,y) ((x)<(y)?(y):(x))
#define FOR(i,a,n) for(i=a;i<n;i++)
#define MOD 1000000007
//#define MOD 998244353
#define NUM 1000005

void swap(int* a,int* b){int tmp=*a;*a=*b;*b=tmp;}
int dup(int a,int d){if(a%d==0)return a/d;else return a/d+1;}
int mod(int a,int m){if(a<0)return a%m+m;else return a%m;}
int GCD(int a,int b){int c=1,tmp=MAX(a,b);b=MIN(a,b);a=tmp;while(c!=0){c=a%b;a=b;b=c;}return a;}
int LCM(int a,int b){return a*b/GCD(a,b);}
int POW(int a,int n){LL ans=1;while(n>0){if(n&1)ans=ans*a%MOD;a=a*a%MOD;n>>=1;}return (int)ans;}
int icmp(const void* a,const void* b){return *(int*)a-*(int*)b;}
int lcmp(const void* a,const void* b){if(*(LL*)a>*(LL*)b)return 1;if(*(LL*)a<*(LL*)b)return -1;return 0;}
int ccmp(const void* a,const void* b){return *(char*)a-*(char*)b;}
int scmp(const void* a,const void* b){return strcmp(*(char**)a,*(char**)b);}
LL fac[NUM],finv[NUM],inv[NUM];
void comi(){int i;fac[0]=fac[1]=1;finv[0]=finv[1]=1;inv[1]=1;FOR(i,2,NUM){fac[i]=fac[i-1]*i%MOD;inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;finv[i]=finv[i-1]*inv[i]%MOD;}}
int com(int n,int k){if(n<k||n<0||k<0)return 0;return fac[n]*(finv[k]*finv[n-k]%MOD)%MOD;}


typedef struct{int A,B;}P;
int cmp(const void* a,const void* b){return ((P*)a)->A-((P*)b)->A;}

int main(){
  int N,T,i,n,t,ans=0;
  scanf("%d%d",&N,&T);
  P p[N];
  FOR(i,0,N)scanf("%d%d",&p[i].A,&p[i].B);
  qsort(p,N,sizeof(P),cmp);
  int dp[N+1][T+1][2];
  FOR(i,0,T+1)dp[0][i][0]=0,dp[0][i][1]=0;
  FOR(n,0,N)FOR(t,0,T+1){
    if(t>=p[n].A)dp[n+1][t][0]=MAX(dp[n][t-p[n].A][0]+p[n].B,dp[n][t][0]);
    else dp[n+1][t][0]=dp[n][t][0];
    if(t>0)dp[n+1][t][1]=MAX(MAX(dp[n+1][t][0],dp[n][t-1][0]+p[n].B),dp[n][t][1]);
  }

  printf("%d\n",dp[N][T][1]);
	return 0;
}


Measured memory_bytes: 70524
def main():
    n, m = map(int, input().split())
    info = [list(map(int, input().split())) for _ in range(n)]
    ans = 0
    for i in range(1 << 3):
        now_ans = [0] * n
        for j in range(3):
            d = 1
            if (i >> j) & 1:
                d *= -1
            for k in range(n):
                now_ans[k] += d * info[k][j]
        now_ans.sort(reverse=True)
        ans = max(ans, sum(now_ans[:m]))
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ft first
#define sd second
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    char s;
    int c[256]={},cn=0;
    fr(i,4){
        cin>>s;
        c[s]++;
    }
    fr(i,256) cn+=(c[i]==2);
    cout<<(cn==2?"Yes":"No")<<endl;
}

Measured memory_bytes: 256
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

A, B, C, D = map(int, list(read().rstrip().decode('utf-8')))

def F(op, v1, v2):
    if op == "1":
        return v1 + v2
    else:
        return v1 - v2

for operators in [list(format(i, "03b")) for i in range(2**3)]:
    op1, op2, op3 = operators
    tmp = F(op1, A, B)
    tmp = F(op2, tmp, C)
    tmp = F(op3, tmp, D)

    if tmp == 7:
        op1 = "+" if op1 == "1" else "-"
        op2 = "+" if op2 == "1" else "-"
        op3 = "+" if op3 == "1" else "-"
        answer = str(A) + op1 + str(B) + op2 + str(C) + op3 + str(D) + "=7"
        print(answer)
        quit()

Measured memory_bytes: 3064
// Template from https://techracho.bpsinc.jp/jhonda/2019_08_05/78537

// input macro for competive-programming from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

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

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

fn main() {
    use std::io::Read;
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();

    println!("{}", solve(&s));
}

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
        #[test]
        fn solve_test() {
            $(
                assert_eq!(solve($input), $output);
            )*
        }
    };
}

test! {
r#"11"# => r#"Yes"#,
r#"3"# => r#"No"#,
}

fn solve(src: &str) -> String {
    input! {
        source = src,
        n: usize,
    }
    let mut ans = "No";

    'outer: for i in 0..25 {
        for j in 0..15 {
            let x = 4 * i + 7 * j;
            if n < x {
                break;
            }
            if n == x {
                ans = "Yes";
                break 'outer;

            }
        }
    }

    ans.to_string()
}

Measured memory_bytes: 4352
#include <iostream>
#include<bits/stdc++.h>
 
using namespace std;
 
int main() 
{ 
int N;
cerr<<"Enter N";
  cin>>N;
for(int i=1;i<=N;i++)
{
  int a,b;

  if(N%i==0)
   {
     a=i;
      b=N/i;
      //cout<<"a is= "<<a<<endl<<"b is= "<<b<<endl;
        if(a>0 && a< 10 && b>0 && b<10)
        {cout<<"Yes";
          return 0;
        }
   }

}
 cout<<"No";
  return 0;
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
using ll = long long;

using namespace std;



int main() {
    string s,t;
    cin >> s >> t;
    int ans = s.length();
    bool e = false;
    rep(i,s.length()) {
        int same = 0;
        rep(j,t.length()) {
            if(i+j >= s.length()) {
                e = true;
                break;
            }
            if(s[i+j]==t[j]) same++;
        }
        if(e) break;
        ans = min(ans,(int)(t.length()-same));
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3624
import fractions
x1,y1,x2,y2 = map(int,input().split())
if x1 == x2 or y1 == y2:
    print(0)
    exit()

dx,dy = abs(x1-x2),abs(y1-y2)
g = fractions.gcd(dx,dy)
print(g * (dx//g + dy//g - 1))


Measured memory_bytes: 5984