akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Diagnostics;
using static System.Math;
using static System.Array;

//var input = Console.ReadLine().Split().Select(int.Parse).ToArray();
namespace AtCoderSolve
{

    class Solve
    {
        const int mod = 1000000007;
        const int INF = 2147483647;
        const long SINF = 9223372036854775807;

        //static int N;
        static string S;
        static int[] p;
       

        public static void Input()
        {
            var cin = new Scanner();
            S = Console.ReadLine();
            p = new int[4];
            for(var i = 0; i < 4; i++)
            {
                p[i] = S[i] - '0';
            }
        }

        static void Main(string[] args)
        {
            Input();

            //var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            //Console.SetOut(sw);

            for(var bit = 0; bit < (1 << 3); bit++)
            {
                int sum = p[0];
                var ans = new StringBuilder();
                ans.Append($"{p[0]}");
                for(var i = 0; i < 3; i++)
                {
                    if ((bit & (1 << i)) != 0)
                    {
                        sum += p[i + 1];
                        ans.Append($"+{p[i + 1]}");
                    }
                    else
                    {
                        sum -= p[i + 1];
                        ans.Append($"-{p[i + 1]}");
                    }
                }

                if (sum == 7)
                {
                    ans.Append("=7");
                    Console.WriteLine(ans);
                    return;
                }

            }
            

            //Console.Out.Flush();

        }

       
    }

    public class Scanner
    {
        public int[] SplitReader()
        {
            int[] array = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return array;
        }
        public long[] SplitReaderL()
        {
            long[] array = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return array;
        }

    }

    public class Graph
    {
        
    }
}

    



Measured memory_bytes: 13268
import sys
import math

mod = 10 ** 9 + 7

def myf(j, i):
    if i>=0 and j>=1:
        return math.factorial(i+j-1) // math.factorial(i) // math.factorial(j-1)
    else:
        return 0

def main():
    n, k = [int(i) for i in sys.stdin.readline().strip().split()]
    for i in range(1, k+1):
        print(myf(i, k-i) * myf(i+1, n-k-i+1) % mod)

    
main()

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

#define pq priority_queue
#define mp make_pair
#define cauto const auto &

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#define clr(ar, val) memset(ar, val, sizeof(ar))

typedef long long int64;
typedef long long lint;
typedef long long lli;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;

typedef pair<int, int> pint;
typedef pair<long, long> plong;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

template <class T> bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T = ll> T in() {
    T x;
    cin >> x;
    return (x);
}
template <class T> void print(T &x) {
    cout << x << '\n';
    return;
}

template <class T> ll iterate_sized_subset(T &comb) {
    T x = comb & -comb, y = x + comb;
    return ((comb & ~y) / x) >> 1 | y;
}

struct union_find {
    int size;
    vector<int> par;
    union_find(int N) : size(N), par(N) { REP(i, N) par[i] = i; }
    int root(int x) {
        if (par[x] == x)
            return x;
        else {
            par[x] = root(par[x]);
            return par[x];
        }
    }
    void unite(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry)
            return;
        else {
            par[rx] = ry;
            return;
        }
    }
    bool same(int x, int y) { return root(x) == root(y); }
};

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

ll f(ll x) {
    switch (x % 4) {
    case 0:
        return x;
        break;
    case 1:
        return 1;
        break;
    case 2:
        return x + 1;
        break;
    case 3:
        return 0;
        break;
    }
}

int main() {
    // ll a = in(), b = in();
    ll a,b;
    cin>>a>>b;
    printf("%lld\n", f(b) ^ f(a - 1));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	if(n>1&&m>1){
		printf("%lld",(n*m+1)/2);
	}else{
		puts("1");
	}
}

Measured memory_bytes: 128
import itertools
N,W=map(int,input().split())
item=[[] for i in range(4)]
for i in range(N):
    w,v=map(int,input().split())
    if(i==0):
        base=w
        item[0].append(v)
    else:
        item[w-base].append(v)
for i in range(4):
    item[i].sort(reverse=True)
l1=len(item[0]);l2=len(item[1]);l3=len(item[2]);l4=len(item[3])
res=0
for x in itertools.product(range(l1+1),range(l2+1),range(l3+1),range(l4+1)):
    if(x[0]*base+x[1]*(base+1)+x[2]*(base+2)+x[3]*(base+3)>W):
        continue
    tmp=sum(item[0][:x[0]])+sum(item[1][:x[1]])+sum(item[2][:x[2]])+sum(item[3][:x[3]])
    res=max(res,tmp)
print(res)

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

int main(){
 	int n,m,tmp = 0;
	cin >>n;
	for(int i = 1; i <= n; i+=2) {
      	m = 0;
		for(int j  =1; j <= i; j+=2) {
        	if(i%j == 0)	
              	m++;
        }
      	if(m == 8)
          	tmp++;
	}
  	cout << tmp << endl;
	
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] && s[1] == s[2]) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
    return 0;
}


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

int GCD(int a, int b)
{
    int t;
    while(b != 0)
    {
        t = b;
        b = a % b;
        a = t;
    }
    return a;
}

int main ()
{
    int a, b, gcd;
    cin >> a >> b;
    
    gcd = GCD(a, b);
    
    cout << gcd << endl;
    return 0;
}


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

using namespace std;

int main(void) {
    long n,m;
    cin >> n >>m;
    vector<int> a(m), b(m), c(m);
    for(int i=0; i<m; i++) {
        cin >> a[i] >> b[i];
        for(int j=0; j<b[i]; j++) {
            int cc;
            cin >> cc;
            cc--;
            c[i] |= 1<<cc;
        }
    }
    
    int d1[1<<12] = {};
    fill(begin(d1), end(d1), 1e8);
    d1[0] = 0;
    for(int i=0; i<m; i++)
        d1[c[i]] = min(d1[c[i]], a[i]);

    for(int k=1; k<=n; k++) {
        for(int i=0; i<1<<n; i++) {
            if (__builtin_popcount(i) != k) continue;
            for(int j=0; j<1<<n; j++) {
                int l = i & (~j);
                d1[i] = min(d1[i], d1[j]+d1[l]);
            }
        }
    }

    if(d1[(1<<n)-1] == 1e8) d1[(1<<n)-1] = -1;
    cout << d1[(1<<n)-1] << endl;
}


Measured memory_bytes: 256
import sys

n = int(input())
h = list(map(int, input().split()))

for i in range(n-1) :
  j = (n-1)-i
  if h[j-1]-h[j] >= 2 :
    print('No')
    sys.exit()
  elif h[j-1]-h[j] == 1 :
    h[j-1] -= 1

print('Yes')

Measured memory_bytes: 14396
// #include <stdio.h>
// #include <string.h>
//#include <iostream>
#include <utility>
#include <cstdio>
#include <stack>
#include <queue>
#include <algorithm>
#include <map>
#include <string>
#include <set>

using namespace std;
typedef pair<int, int> XY;// Pair型変数の宣言
    
int main()
{
    
  	int Nmax = 100000;
    int N,K;
    int A[Nmax];
    int B[Nmax];
    
    int i,j,k;
    int len;   // 文字列の長さ
    int flag=0;

/*    
    // int型スタック
    stack<int> stack;   
    stack.push(777);
    stack.push(778);
    stack.push(779);
  
	int tmpsl = stack.top();  // LAST要素の参照
 // 	int tpmsf = stack.back(); // FIRST要素の参照
 //	printf("%d %d \n",tmpsl,tmpsf);
    stack.pop();// LAST要素の削除（取出しではない）
 // 	if( stack.empty() == true) printf("empty stack\n");
     
    // int型キュー
    queue<int> que;
  	que.push(999);
  	que.push(998);   
  	que.push(997);    
  	int tmpqs = que.front(); // FIRST要素の参照
  	int tmpqe = que.back();  // LAST要素の参照
 //	printf("%d %d \n",tmpqs,tmpqe);
  	que.pop();  // FIRST要素の削除（取出しではない）
  //	if( que.empty() == true) printf("empty que\n");
    
    // ２次元座標を扱うキュー
    queue<XY> xyque; // ２次元座標型変数のキュー
  	XY p; 
  	xyque.pop();	// FIRST要素の削除。キューが空のときは削除が予約されて次のPOPが即削除される
  	xyque.push( XY(5,5) );
    xyque.push( XY(5,5) );
   	p = xyque.front();  // FIRST要素からのコピー
 // 	printf("%d %d\n", p.first, p.second);
  	
    
  que.back();
  //  sort(&(que.front()), &(que.back()));
     */   
    
      
    // 入力読込
    // 文字列
//    scanf("%s", String);   
    
    // 数列
    scanf("%d ", &N);
    for(i=1;i<=N;i++){
        scanf("%d ",&A[i]);
    }
    
//    sort(&A[0],&A[N]); // 昇順ソート
    

    // 文字列の長さをチェック
    // 文字列は配列の0からlen-1に格納されてる
//    len = strlen( String );
//  	printf("%d\n",len);
    

    for(i=1;i<=N;i++){
        B[A[i]] = i;
    }
    
    
  // 結果出力
    for(j=1;j<=N;j++){
    printf("%d ",B[j]);
    }
                     
  
  return 0;
   
}
   

Measured memory_bytes: 1536
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>
# include <iostream>
# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define FOR(i, m, n) for (int i = int(m); i < (int)(n); i++)

using namespace std;

int main(){
  int N,W;
  int v[1005];
  int w[1005];
  int dp[1005][1005];
  cin >> N >> W;
  rep(i, N){
    cin >> v[i] >> w[i];
  }

  irep(i, N+1){
    rep(j,W+1){
      if(i == N){
        dp[i][j] = 0;
      }
      if(j == 0){
        dp[i][j] = 0;
      }
      if(j - w[i] > -1){
      	dp[i][j] = max(dp[i][j-w[i]]+v[i], max(dp[i+1][j-w[i]]+v[i], dp[i+1][j]));
      }else{
        dp[i][j] = dp[i+1][j];
      }
    }
  }
  cout << dp[0][W] << endl;
}

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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

vector<int64_t> fact, seq_inv, fact_inv;

void create_fact_mod(int num){
    fact[0] = 1;
    fact[1] = 1;
    for(int i=2; i<=num; i++){
        fact[i] = fact[i-1] * i % MOD;
    }
}

void create_seq_inv_mod(int num){
    seq_inv[0] = 1;
    seq_inv[1] = 1;
    for(int i=2; i<=num; i++){
        seq_inv[i] = (MOD - MOD/i) * seq_inv[MOD%i] % MOD;
    }
}

void create_fact_inv_mod(int num){
    fact_inv[0] = 1;
    fact_inv[1] = 1;
    for(int i=2; i<=num; i++){
        fact_inv[i] = fact_inv[i-1] * seq_inv[i] % MOD;
    }
}

void create_mod_tables(int num){
    fact.resize(num+1);
    seq_inv.resize(num+1);
    fact_inv.resize(num+1);
    create_fact_mod(num);
    create_seq_inv_mod(num);
    create_fact_inv_mod(num);
}

int64_t comb_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD * fact_inv[k] % MOD;
}

int64_t perm_mod(int n, int k){
    return fact[n] * fact_inv[n-k] % MOD;
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int main(){
    int N, M, A[18];
    cin >> N >> M;
    A[0] = 1;
    for(int i=1; i<=M; i++) cin >> A[i];
    A[M+1] = (1<<N)+1;

    create_mod_tables(1<<16);

    static int64_t dp[1<<16];
    dp[0] = 1;

    for(int t=0; t<=M; t++){
        for(int i=0; i<N; i++) for(int bits=0; bits<(1<<N); bits++) if(nth_bit(bits, i)) add(dp[bits], dp[bits - (1<<i)]);

        int d = A[t+1] - A[t] - 1;
        for(int bits=0; bits<(1<<N); bits++){
            int capacity = 1;
            for(int i=0; i<N; i++) if(nth_bit(bits, i)) capacity += 1<<i;
            capacity -= A[t];
            if(capacity >= d){
                mul(dp[bits], perm_mod(capacity, d));
            }else{
                dp[bits] = 0;
            }
        }

        for(int i=0; i<N; i++) for(int bits=0; bits<(1<<N); bits++) if(nth_bit(bits, i)) add(dp[bits], MOD - dp[bits - (1<<i)]);

        if(t == M) break;
        
        for(int bits=0; bits<(1<<N); bits++){
            int capacity = 1;
            for(int i=0; i<N; i++) if(nth_bit(bits, i)) capacity += 1<<i;
            capacity -= A[t+1] - 1;
            if(capacity > 0){
                mul(dp[bits], capacity);
            }else{
                dp[bits] = 0;
            }
        }
    }

    int64_t ans = dp[(1<<N) - 1];
    mul(ans, 1<<N);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2304
import java.util.*;

public class Main {
    static Scanner sc;
    public static void main(String[] args) {
        sc=new Scanner(System.in);
        //a();
        b();
        //c();
        //d();
    }
    public static void a(){
        int a=sc.nextInt();int b=sc.nextInt();
        System.out.println((a>9||b>9)?-1:a*b);
    }
    public static void b(){
        int n=sc.nextInt();
        int po[]=new int[81];
        boolean b=false;
        for(int i=0;i<9;i++)
        for(int j=0;j<9;j++)if((i+1)*(j+1)==n)b=true;
        System.out.println(b?"Yes":"No");
    }
    public static void c(){
        long n=sc.nextLong();
        long q=(long)Math.sqrt(n);
        long index=n;
        for(int i=2;i<=q;i++){
            if(n%i==0)index=i;
        }
        System.out.println(index+(n/index)-2);
    }
    public static void d(){
        int a=sc.nextInt();
        int b=sc.nextInt();
        int x=sc.nextInt();
        if((double)2*x/(a*a)-b>=0){
            double bb=((double)2*x)/(a*a)-b;
            System.out.println(Math.atan((-bb+b)/a)*180/Math.PI);
        }
        else{
            double aa=((double)2*x)/(a*b);
            System.out.println(Math.atan(((double)b)/aa)*180/Math.PI);
        }
        
    }
}


Measured memory_bytes: 23124
n=int(input())
t=list(map(int,input().split()))
m=int(input())
p=[tuple(map(int,input().split()))for i in range(m)]
total=sum(t)
for i in range(m):
    a=p[i][1]
    b=t[p[i][0]-1]
    print(total+(a-b))
    

Measured memory_bytes: 3060
W, H, N = map(int, input().split())
rec = []
for h in range(H):
    rec.append([])
    for w in range(W):
        rec[h].append(1)
        
for i in range(N):
    x, y, a = map(int, input().split())
    if a == 1:
        for h in range(H):
            for _x in range(x):
                rec[h][_x] = 0
    elif a == 2:   
        for h in range(H):
            for _x in range(x, W):
                rec[h][_x] = 0
    elif a == 3:
        for w in range(W):
            for _y in range(y):
                rec[_y][w] = 0
    else:   
        for w in range(W):
            for _y in range(y, H):
                rec[_y][w] = 0
    # print(rec)
for h in range(H):
    rec[h] = sum(rec[h])
print(sum(rec))

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n,m = map(int, raw_input().split())
# 文字列の入力
# 出力
gate = [[0,0]]*m
for i in range(m):
    gate[i]=raw_input().split()

cnt = 0
min_r = n
max_l = 0
for i in range(m):
    g0 = int(gate[i][0])
    g1 = int(gate[i][1])

    if max_l < g0:
        max_l = g0

    if min_r > g1:
        min_r = g1

for j in range(n):
    j=j+1
    if j >= max_l and min_r >= j:
            cnt += 1

print cnt

Measured memory_bytes: 34076
#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define pdi pair<db,int>
#define mp make_pair
#define pb push_back
#define enter putchar('\n')
#define space putchar(' ')
#define eps 1e-8
#define mo 974711
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;char c = getchar();T f = 1;
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 + c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
const int MOD = 1000000007;
int N;
struct node {
    int to,next;
}E[MAXN * 2];
int head[MAXN],sumE,siz[MAXN],son[MAXN];
int C[MAXN][MAXN],fac[MAXN],val[MAXN],tot,f[MAXN];
int inc(int a,int b) {
    return a + b >= MOD ? a + b - MOD : a + b;
}
int mul(int a,int b) {
    return 1LL * a * b % MOD;
}
void add(int u,int v) {
    E[++sumE].next = head[u];
    E[sumE].to = v;
    head[u] = sumE;
}
void dfs(int u,int fa) {
    siz[u] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa) {
	    dfs(v,u);
	    siz[u] += siz[v];
	    son[u] = max(son[u],siz[v]);
	}
    }
    son[u] = max(son[u],N - siz[u]);
}
void Init() {
    read(N);
    int x,y;
    for(int i = 1 ; i < N ; ++i) {
	read(x);read(y);
	add(x,y);add(y,x);
    }
    C[0][0] = 1;
    for(int i = 1 ; i <= N ; ++i) {
	C[i][0] = 1;
	for(int j = 1 ; j <= N ; ++j) {
	    C[i][j] = inc(C[i - 1][j],C[i - 1][j - 1]);
	}
    }
    fac[0] = 1;
    for(int i = 1 ; i <= N ; ++i) fac[i] = mul(fac[i - 1],i);
}
void Solve() {
    dfs(1,0);
    int g = 1;
    for(int i = 2 ; i <= N ; ++i) {
	if(son[i] < son[g]) g = i;
    }
    if(N % 2 == 0 && son[g] == N / 2) {
	out(mul(fac[N / 2],fac[N / 2]));enter;return;
    }
    for(int i = head[g] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(siz[v] < siz[g]) val[++tot] = siz[v];
    }
    if(g != 1) val[++tot] = N - siz[g];
    int s = 0;f[0] = 1;
    for(int i = 1 ; i <= tot ; ++i) {
	for(int t = s + val[i] ; t >= 0 ; --t) {
	    for(int j = 1 ; j <= val[i] ; ++j) {
		if(j > t) break;
		f[t] = inc(f[t],mul(mul(f[t - j],C[val[i]][j]),mul(C[val[i]][j],fac[j])));
	    }
	}
	s += val[i];
    }
    int t = 1,ans = 0;
    for(int i = 0 ; i <= N - 1; ++i) {
	ans = inc(ans,mul(mul(t,f[i]),fac[N - i]));
	t = mul(t,MOD - 1);
    }
    out(ans);enter;
}
int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Init();
    Solve();
}


Measured memory_bytes: 98304
#include<iostream>
#include<stdio.h>
#include<string>
#include<cmath>
#include<math.h>
#include<vector>
#include<algorithm>
#include<map>
#include<unordered_map>
#pragma warning(disable: 4996)
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;


int main() {

	int n, m;

	cin >> n >> m;

	vector<ll> H(n);
	vector<bool> h(n, true);

	rep(i, n)cin >> H[i];

	rep(i, m) {
		int a, b;
		cin >> a >> b;
		if (H[a - 1] > H[b - 1])h[b - 1] = false;
		else if (H[b - 1] > H[a - 1])h[a - 1] = false;
		else if (H[a - 1] == H[b - 1]){h[a - 1] = false; h[b - 1] = false;	}

	}

	int ans = 0;

	rep(i, n)if (h[i])ans++;

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 4048
#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#define endl "\n"
#define ll long long
using namespace std;

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

    int data;
    int sum = 0;
    for(int i = 0; i < m; i ++)
    {
    	cin >> data;
    	sum += data;
    }
    int ans = max(n - sum, -1);
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <array>
#include <algorithm>
#include <functional>
using namespace std;

long long GetMax(size_t M, vector<long long> x, vector<long long> y, vector<long long> z){
    auto N = x.size();
    long long maxN = 0;
    vector<array<int, 3>> signList;
    signList.push_back(array<int,3>{+1, +1, +1});
    signList.push_back(array<int,3>{+1, +1, -1});
    signList.push_back(array<int,3>{+1, -1, +1});
    signList.push_back(array<int,3>{+1, -1, -1});
    signList.push_back(array<int,3>{-1, +1, +1});
    signList.push_back(array<int,3>{-1, +1, -1});
    signList.push_back(array<int,3>{-1, -1, +1});
    signList.push_back(array<int,3>{-1, -1, -1});
    for(auto sign : signList){
        int signX = sign[0];
        int signY = sign[1];
        int signZ = sign[2];
        vector<long long> values;
        for(size_t i=0; i<N; i++){
            auto v = x.at(i) * signX + y.at(i) * signY + z.at(i) * signZ;
            values.push_back(v);
        }
        sort(values.begin(), values.end(), greater<>());
        long long maxNCand = 0;
        for(size_t i=0;i<M;i++) maxNCand+=values[i];
        if(maxNCand > maxN) maxN = maxNCand;
    }

    return maxN;
}

int main()
{
    size_t N, M;
    cin >> N >> M;
    long long xi, yi, zi;
    vector<long long> x,y,z;
    for(size_t i=0;i<N;i++){
        cin >> xi >> yi >> zi;
        x.push_back(xi);
        y.push_back(yi);
        z.push_back(zi);
    }
    auto v = GetMax(M, x, y, z);
    cout << v << endl;
    return 0;
}


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

const int N = 1e6+10;
char s[N];

void solve(){
    scanf("%s",s+1);
    int n=strlen(s+1);
    ll ans=0;
    for(int l=1,r=1;l<=n;l=r,r=l){
        int cnt1=0,cnt2=0;
        while(r<=n && s[r]=='<') r++,cnt1++;
        while(r<=n && s[r]=='>') r++,cnt2++;
        ans+=1LL*(1LL*cnt1*cnt1+1LL*cnt2*cnt2+abs(cnt1-cnt2))/2;
        //cout<<cnt1<<' '<<cnt2<<' '<<ans<<endl;
    }
    printf("%lld\n",ans);
}

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

Measured memory_bytes: 768
def prim():
    mindist[0] = 0
    parent[0] = -1 

    while True:
        #MSTに追加する頂点を決定
        mincost = INF
        u = -1
        for i in range(n):
            if color[i] != black and mindist[i] < mincost:
                mincost = mindist[i]
                u = i
        if u == -1: break
        color[u] = black
        # MSTに含まれていないMSTとつながる隣接頂点の最小コストを探索
        for v in range(n):
            if color[v] == black: continue
            if M[u][v] == INF: continue
            if M[u][v] >= mindist[v]: continue
            mindist[v] = M[u][v] 
            parent[v] = u
            color[v] = gray
        
    sumcost = 0
    for i in range(n):
        if parent[i] == -1: continue
        sumcost += M[i][parent[i]]

    return sumcost

if __name__ == "__main__":
    n = int(input())
    INF = float("inf")
    M = [list(map(lambda x: INF if x == "-1" else int(x), input().split())) for _ in range(n)]
    white = 0; gray = 1; black =2
    color = [white]*n #各頂点の訪問状態 （white:未訪問 gray:暫定 black:確定）
    mindist = [INF]*n # 各頂点のMSTとつながる辺の最小コスト
    parent = [-1]*n #各頂点の親

    print(prim())


Measured memory_bytes: 5908
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define mod 1000000007

const int sz=1e6+5;
ll inf=1e15;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    // cin>>t;
    
    while(t--)
    {
        
        int n;
        cin>>n;
        ll ar[n];
        for(int i=0;i<n;i++)
            cin>>ar[i];
        ll dp[n+1];
        for(int i=1;i<=n;i++)
            dp[i]=inf;
        dp[0]=0;
        dp[1]=0;
        for(int i=2;i<=n;i++)
        {
            if(i-3>=0)
            dp[i]=min(min(dp[i-1]+abs(ar[i-1]-ar[i-2]),dp[i-2]+abs(ar[i-1]-ar[i-3])),dp[i]);
            else
                dp[i]=min(dp[i],dp[i-1]+abs(ar[i-1]-ar[i-2]));
        }

        cout<<dp[n];
    }

    return 0;
}

Measured memory_bytes: 5152
n = int(input())
b = [input() for _ in range(n)]
m = int(input())
r = [input() for _ in range(m)]
c = list(set(b+r))
ans = 0
for i in range(len(c)):
  d = b.count(c[i])-r.count(c[i])
  ans = max(0, ans, d)
print(ans)

Measured memory_bytes: 9144
#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	int h, w, m;
	cin >> h >> w >> m;
	map<ii, int> mp;
	map<int, int> rwmp, clmp;
	for(int i = 0, x, y; i < m; i++) {
		cin >> x >> y;
		mp[ii(x, y)]++;
		rwmp[x]++;
		clmp[y]++;
	}
	int mxr = 0, mxc = 0;
	for(auto el: rwmp) mxr = max(mxr, el.se);
	for(auto el: clmp) mxc = max(mxc, el.se);

	vector<int> rws, cls;
	for(auto el: rwmp)
		if(mxr == el.se) rws.push_back(el.fi);
	for(auto el: clmp)
		if(mxc == el.se) cls.push_back(el.fi);
	for(auto a: rws) {
		for(auto b: cls) {
			if(!mp.count(ii(a, b))) {
				cout << mxr + mxc << '\n'; exit(0);
			}
		}
	}
	cout << mxr + mxc - 1 << '\n';
}



Measured memory_bytes: 54280
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

int a[3];

signed main() {
    while(cin >> a[0] >> a[1] >> a[2], a[0] || a[1] || a[2]) {
        sort(a, a+3);
        int cheese = a[0] * a[0] + a[1] * a[1];
        int n; cin >> n;
        rep(i,0,n) {
            int inp; cin >> inp;
            if(4 * inp * inp > cheese) cout << "OK" << endl;
            else cout << "NA" << endl;
        }
    }
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int red = 0;
    int blue = 0;
    for(int i = 0; i < S.size(); ++i){
        if(S.at(i) == '0') ++ red;
        else ++ blue;
    }
    if(red >= blue) cout << blue*2 << endl;
    else cout << red*2 << endl;
}

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

int main() {
	int x;
	cin >> x;
	int happy500 = 1000, happy5 = 5, cnt500 = 0, cnt5 = 0;
	cnt500 = x/500;
	cnt5 = (x % 500)/5;
	cout << cnt500*happy500 + cnt5*happy5 << endl;
}


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

sys.setrecursionlimit(10**7)
inf = 10**3
eps = 1.0 / 10**10
mod = 10**9+7

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


def main():
    rr = []
    n = I()
    a = [LI() for _ in range(n)]

    def f(y,m,d):
        t = (y-1) * 195
        t += (y-1) // 3 * 5
        t += (m-1) * 20
        if y % 3 > 0:
            t -= (m-1) // 2
        t += d - 1
        return t

    t = f(1000,1,1)
    for y,m,d in a:
        k = f(y,m,d)
        rr.append(t - k)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9040
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ; 
  vector <int> c(N);
  for ( int i=0 ; i<N ; i++ ){
    cin >>c.at(i) ;
  }
  sort (c.begin() , c.end());
  int sum=0;
  for (int i=0 ; i<N ; i++){
    sum +=c.at(N-i-1)*( i%2==0 ? 1:-1);
  }
    cout << sum << endl;
}

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


int main() {
    long pay = 0;
    long number_of_one = 0;
    cin >> pay >> number_of_one;
    if (pay % 500 <= number_of_one) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np


def solve(S):
    dp = np.zeros(2019, np.int64)
    pow10 = 1
    answer = 0
    for x in S[::-1]:
        dp[0] += 1
        x = x * pow10 % 2019
        newdp = np.empty_like(dp)
        newdp[x:] = dp[:-x]
        newdp[:x] = dp[-x:]
        dp = newdp
        answer += dp[0]
        pow10 *= 10
        pow10 %= 2019
    return answer


def cc_export():
    from numba.pycc import CC
    cc = CC('my_module')
    cc.export('solve', '(i4[:],)')(solve)
    cc.compile()


try:
    from my_module import solve
except:
    cc_export()
    exit()

S = np.array(list(read().rstrip()), dtype=np.int32) - ord('0')
print(solve(S))


Measured memory_bytes: 29012
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define sc scanf
#define pf printf
#define r0 return 0
int main()
{
    ll n,a,b;
    cin >> n >> a >> b;
    ll num = n/(a+b)*a;
    ll rem = n%(a+b);
    num += min(rem,a);
    cout << num << endl;
    r0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main() {
    int k;
    vector<ll> a(3);
    cin >> a[0] >> a[1] >> a[2]>>k;
    for(int i=0;i<k;i++){
        sort(a.begin(),a.end());
        a[2] *=2;
    }
    cout << accumulate(a.begin(),a.end(),0LL) <<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();

    if(b % a == 0) {
      System.out.println(a+b);
    } else {
      System.out.println(b-a);
    }

  }

}


Measured memory_bytes: 22612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct {
  int key;
  int *left;
  int *right;
  int *parent;
} node;

node *root, *NIL;

void insert(int k)
{

  node *x, *y, *z;
  
  y = NIL; // x の親
  x = root;
  z = (node *)malloc(sizeof(node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  
  while(x != NIL){
    y = x;// 親を設定
    if(z->key < x->key){
      x = x->left; // 左の子へ移動
    }
    else{ 
      x = x->right;
    }// 右の子へ移動
  }
  z->parent = y;
  if(y == NIL){ // T が空の場合
    root = z;
  }
  else{
    if(z->key < y->key){
    y->left = z;// z を y の左の子にする
  }
    else{
      y->right = z; // z を y の右の子にする
    }
  }

}

void inorder(node *u)
{

  if(u==NIL) return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}

void preorder(node *u)
{

  if(u==NIL) return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);

}

int main()
{

  int n, i, x;
  char com[7];

  scanf("%d",&n);

  for(i=0;i<n;i++){
    scanf("%s",com);
    if(com[0]=='i'){
      scanf("%d",&x);
      insert(x);
    }
    else if(com[0]=='p'){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;

}



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

vector<int> arr[1000001];
int main(){
    int n;
    cin>>n;
    // arr[1].push_back(1);
    for(int i=2; i<1000001; i++){
        if(arr[i].size()==0){
            int k=i;
            while(k<1000001){
                arr[k].push_back(i);
                k+=i;
            }
        }
    }
    int coun[1000001];
    for(int i=0; i<1000001; i++){
        coun[i]=0;
    }
    int max=0;
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        for(int k:arr[a]){
            coun[k]++;
            if(coun[k]>max)
                max=coun[k];
        }
    }
    // cout<<max<<endl;
    if(max==n){
        cout<<"not coprime"<<endl;
    }
    else if(max==1||max==0){
        cout<<"pairwise coprime"<<endl;
    }
    else{
        cout<<"setwise coprime"<<endl;
    }
    return 0;
}

Measured memory_bytes: 62932
import bisect, collections, copy, heapq, itertools, math, numpy, string
import sys
from bisect import bisect_left, bisect_right, insort
from collections import deque
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int, sys.stdin.readline().rstrip().split())
def MS(): return map(str, sys.stdin.readline().rstrip().split())
def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
# N = I()
# A = [LI() for _ in range(N)]
s = S()
print(s[:3])



Measured memory_bytes: 27204
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

ll A[200010];
ll cnt[200010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		cnt[A[i]]++;
	}
	ll ans = 0;
	for (int i = 1; i <= N; i++) {
		ans += cnt[i] * (cnt[i] - 1) / 2;
	}
	for (int i = 0; i < N; i++) {
		cout << ans - cnt[A[i]] + 1 << endl;
	}
	
}

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

int main() {
    string S;
    cin >> S;

    S.insert(S.begin(), '>');
    S.push_back('<');
    vector<int64_t> a(S.size() - 1, -1);
    for (uint64_t i = 0; i < S.size() - 1; i++) {
        a[i] = ((S[i] == '>' && S[i + 1] == '<') ? 0 :
                 S[i] == '<' ? a[i - 1] + 1 : a[i]);
    }

    for (int64_t i = S.size() - 2; i >= 0; i--) {
        a[i] = max(a[i], (S[i + 1] == '>' ? a[i + 1] + 1 : a[i]));
    }
    
    cout << accumulate(a.begin(), a.end(), (int64_t)0) << endl;
}

Measured memory_bytes: 4740
main :: IO ()
main = readLn >>= putStrLn . f ""

f :: String -> Int -> String
f "" 0 = "0"
f s  0 = s
f s n | n `mod` 2 == 0 = f ('0' : s) $ n `div` (-2)
      | otherwise      = f ('1' : s) $ (n - 1) `div` (-2)


Measured memory_bytes: 508
#include<bits/stdc++.h>
using namespace std;
#define dist(l,r) (abs(x[l]-x[r])+min(abs(x[r]),abs(x[l])))
int main(){
  int n,k,res;
  cin>>n>>k;
  vector<int> x(n);
  for(int i=0;i<n;++i)cin>>x[i];
  res=dist(0,k-1);
  for(int l=1;l+k-1<n;++l)res=min(res,dist(l,l+k-1));
  cout<<res;
  return 0;
}

Measured memory_bytes: 640
N,M=map(int,input().split())
H=[0]
H+=list((map(int,input().split())))
way=[[] for _ in range(N+1)]
ans=0
flag=0
for i in range(M):
    a,b=(map(int,input().split()))
    way[a].append(b)
    way[b].append(a)
#print(way)
for i in range(1,N+1):
    flag=0
    for j in way[i]:
        if H[j] >= H[i]:
            flag=1
            break
    if flag==0:
        ans+=1
        #print(i)
print(ans)

Measured memory_bytes: 29384
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <inttypes.h>
#include <string.h>
#include <math.h>

int main (void)
{
    intmax_t N, A[(int)1e5 - 1], B[(int)1e5 - 1];
    intmax_t sum = 0;

    scanf("%jd", &N);
    for (size_t i = 0; i < N; i++) {
        scanf("%jd", &A[i]);
        sum += A[i];
    }

    B[0] = sum;
    for (size_t i = 1; i < N; i += 2) {
        B[0] -= 2 * A[i];
    }

    for (size_t i = 1; i < N; i++) {
        B[i] = 2 * A[i - 1] - B[i - 1];
    }

    for (size_t i = 0; i < N; i++) {
        printf("%jd", B[i]);
        if (i < (N - 1)) {
            printf(" ");
        } else {
            printf("\n");
        }
    }

    return 0;
}


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

using namespace std;

int main(void)
{
    int N, s[101], i, sum=0, judge;

    cin >> N;

    for(i=1; i<=N; i++){
        cin >> s[i];

        sum += s[i];
    }

    sort(s+1, s+N+1);

    if(sum % 10 != 0){
        cout << sum << endl;
    }

    else{
        i = 1;

        judge = 1;

        while(1){
            if(i == N+1){
                judge = 0;
                break;
            }

            if(s[i] % 10 != 0){
                break;
            }

            i++;
        }

        if(judge == 0){
            cout << 0 << endl;
        }

        else{
            cout << sum-s[i] << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 256
def bb099up(a,b):
    tou = 0
    for i in range(1, 1000):
        tou += i
        if tou > a:
            snow = tou - a
            if snow+b == tou+i+1:
                return snow

def bb099():
    a,b = list(map(int, input().split()))
    print(bb099up(a, b))

bb099()

Measured memory_bytes: 2940
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;


int main() {
	int a, b;
	char op;
	cin >> a >> op >>b;
	switch (op) {
	case '+':
		cout << a + b << endl;
		break;
	default:
		cout << a-b << endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
sx, sy, tx, ty = map(int, input().split())

hight = ty - sy
width = tx - sx

res = ''

res += 'U' * hight
res += 'R' * width
res += 'D' * hight
res += 'L' * width
res += 'L'
res += 'U' * (hight + 1)
res += 'R' * (width + 1)
res += 'DR'
res += 'D' * (hight + 1)
res += 'L' * (width + 1)
res += 'U'

print(res)

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

typedef long long ll;
const ll INF = (1ll << 32);
const int MAX_V = 201;
const int MAX_R = 1001;
int N, M, R;
int z[MAX_R];
ll sea[MAX_V][MAX_V];
ll land[MAX_V][MAX_V];
ll dp[MAX_R][MAX_V];

ll solve(){
	// warshall-floyd
	for(int k=0 ; k < N ; k++ ){
		for(int i=0 ; i < N ; i++ ){
			for(int j=0 ; j < N ; j++ ){
				land[i][j] = min(land[i][j], land[i][k] + land[k][j]);
				sea[i][j] = min(sea[i][j], sea[i][k] + sea[k][j]);
			}
		}
	}
	
	// initialize
	for(int i=0 ; i < MAX_R ; i++ ){
		for(int j=0 ; j < MAX_V ; j++ ){
			dp[i][j] = INF;
		}
	}
	
	// dynamic programming
	dp[0][z[0]] = 0;
	for(int i = 1 ; i < R ; i++ ) {
		for(int j = 0 ; j < N ; j++ ) {
			// テゥツ卍クティツキツッテ」ツ?ョテ」ツ?ソテ」ツ?ョテァツァツサテ・ツ仰?
			// dp[i][j] := テゥツ崢?ァツゥツ催ァツ閉ェテ・ツ渉キ i, ティツ按ケテ」ツ?ョテ、ツスツ催ァツスツョ j テ」ツ?ョテ」ツ?ィテ」ツ?催」ツ?ョテ」ツつウテ」ツつケテ」ツδ?
			dp[i][j] = min(dp[i][j], dp[i-1][j] + land[z[i-1]][z[i]]);
			
			// テヲツオツキティツキツッテ」ツつ津ァツ板ィテ」ツ??」ツ?淌ァツァツサテ・ツ仰?
			for(int k = 0 ; k < N ; k++ ) {
				ll cost = dp[i-1][j] + land[z[i-1]][j]+ sea[j][k] + land[k][z[i]];
				dp[i][k] = min(dp[i][k], cost);
			}
		}
	}
	ll res = INF;
	for(int i=0 ; i < N ; i++ ){
		res = min(res, dp[R-1][i]);
	}
	return res;
}

int main(){
	while( cin >> N >> M , N || M ){
		// initialize
		for(int i=0 ; i < MAX_V ; i++ ){
			for(int j=0 ; j < MAX_V ; j++ ){
				land[i][j] = (i == j)? 0 : INF;
				sea[i][j] = (i == j)? 0 : INF;
			}
		}
		
		for(int i=0 ; i < M ; i++ ){
			int x, y;
			ll t;
			char sl;
			cin >> x >> y >> t >> sl;
			x--; y--;
			
			if( sl == 'S' ){
				sea[x][y] = sea[y][x] = min(sea[x][y], t);
			}else{
				land[x][y] = land[y][x] = min(land[x][y], t);
			}
		}
		cin >> R;
		for(int i=0 ; i < R ; i++ ){
			cin >> z[i];
			z[i]--;
		}
		cout << solve() << endl;
	}
}

Measured memory_bytes: 3372
from collections import deque
N = int(input())
A = list(map(int, input().split()))
B = deque()

if N % 2 == 0:
	for i in range(N):
		if i % 2 == 0:
			B.append(A[i])
		else:
			B.appendleft(A[i])
else:
	for i in range(N):
		if i % 2 == 0:
			B.appendleft(A[i])
		else:
			B.append(A[i])
			
print(*B)

Measured memory_bytes: 25412
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1001001001;
const ll LINF = 1001001001001001001;
#define fori(i,a,b) for(ll i=(a);i<=(b);i++)
#define repi(i,n) fori(i,0,(n)-1)
#define forr(i,a,b) for(ll i=(b);i>=(a);i--)
#define repr(i,n) forr(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
#define pb push_back
#define mp make_pair
#define pcnt __builtin_popcount
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;}

ll f(vec a){
    ll len=a.size();
    ll ret=0;
    ll base=1;
    fori(i,1,len-1)base*=i;
    repi(i,len){
        ret+=(a[i]-1)*base;
        if(len-1-i)base/=len-1-i;
        fori(j,i+1,len-1){
            if(a[j]>a[i])a[j]--;
        }
    }
    return ret;
}
void solve(){
    ll n;
    cin>>n;
    vec p(n),q(n);
    repi(i,n)cin>>p[i];
    repi(i,n)cin>>q[i];
    cout<<abs(f(p)-f(q))<<endl;
}

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


Measured memory_bytes: 256
package main

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

const MaxBuf = 200100
var buf []byte = make([]byte,MaxBuf)
var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(buf,MaxBuf)
}

func readString() string {
	sc.Scan()
	return sc.Text()
}

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

func readInt64() int64 {
	sc.Scan()
	r,_ := strconv.ParseInt(sc.Text(),10,64)
	return r
}

func readFloat64() float64 {
	sc.Scan()
	r,_ := strconv.ParseFloat(sc.Text(),64)
	return r
}

func main() {

	for {
		x := readInt()
		y := readInt()
		if x == 0 && y == 0 {
			break
		}
		if x > y {
			fmt.Println(y,x)
		} else {
			fmt.Println(x,y)
		}
	}

}


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

int main() {
    string r, g, b;
    cin >> r >> g >> b;
    if (stoi(r + g + b)  % 4 == 0) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

int main() {
  string s; cin>>s;
  int n,q,f; cin>>n;
  string t;
  int count1=0;
  rep(i,n){
    cin>>q;
    if(q==1){count1++;}
    if(q==2){
      cin>>f>>t;
      if((count1+f)%2==0){s.append(t);}
      if((count1+f)%2==1){s.insert(0,t);}
    }
  }
  if(count1%2==1){reverse(s.begin(), s.end());}
  cout<<s<<endl;
}



Measured memory_bytes: 3908
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

typedef long long lld;

void solve(){
    lld n;
    cin>>n;
    string ans;
    while(n>0){
        n--;
        lld delta=n%26;
        char c='a'+delta;
        ans=c+ans;
        n/=26;
    }
    cout<<ans;
}

int main()
{
    //freopen("IN.txt","r",stdin);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

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

int main(){
    int H,W;
    cin>>H>>W;
    char s[50][50];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            cin>>s[i][j];
        }
    }
    
    string ans="Yes";
    //上左右下
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(s[i][j]=='#'){
                if(i==0){
                    //右下
                    if(j==0){if(s[i][j+1]!='#' && s[i+1][j]!='#'){ans="No";}}
                    //左下
                    else if(j==W-1){if(s[i][j-1]!='#' && s[i+1][j]!='#'){ans="No";}}
                    //左右下
                    else{if(s[i][j-1]!='#' && s[i][j+1]!='#' && s[i+1][j]!='#'){ans="No";}}                
                }
                else if(i==H-1){
                    //右上
                    if(j==0){if(s[i][j+1]!='#' && s[i-1][j]!='#'){ans="No";}}
                    //左上
                    else if(j==W-1){if(s[i][j-1]!='#' && s[i-1][j]!='#'){ans="No";}}
                    //左右上
                    else{if(s[i][j-1]!='#' && s[i][j+1]!='#' && s[i-1][j]!='#'){ans="No";}}
                }
                else if(j==0){
                    //右上下
                    if(s[i-1][j]!='#' && s[i][j+1]!='#' && s[i+1][j]!='#'){ans="No";}
                }
                else if(j==W-1){
                    //左上下
                    if(s[i-1][j]!='#' && s[i][j-1]!='#' && s[i+1][j]!='#'){ans="No";}
                }
                else{
                    //上下左右
                    if(s[i-1][j]!='#' && s[i][j-1]!='#' && s[i][j+1]!='#' && s[i+1][j]!='#'){ans="No";}
                }
            }
        }
    }//end for

    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long int
#define mp(a, b) make_pair(a, b)
using namespace std;
typedef pair<ll, ll> pairs;
typedef pair<ll, pairs> tpl;
ll n;
double p[3000], dp[3000][3000];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	for (ll i = 0; i < n; i++)
		cin >> p[i];
	double ans = 0;
	dp[0][0] = (1.0 - p[0]);
	dp[0][1] = p[0];
	for (ll i = 1; i < n; i++)
	{
		for (ll j = 0; j <= n; j++)
		{
			dp[i][j] += dp[i - 1][j] * (1.0 - p[i]);
			if (j > 0)
				dp[i][j] += dp[i - 1][j - 1] * (p[i]);
		}
	}
	for (ll i = n / 2 + 1; i <= n; i++)
		ans += dp[n - 1][i];
	cout << setprecision(9);
	cout << fixed;
	cout << ans;
}


Measured memory_bytes: 74044