akhauriyash/Code-Regression huggingface dataset:
#!/usr/bin/env python3
import numpy as np

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    H, W, M = list(map(int, input().split()))
    h = np.zeros(M, dtype=int)
    w = np.zeros(M, dtype=int)

    sum_h = np.zeros(H, dtype=int)
    sum_w = np.zeros(W, dtype=int)



    for m in range(M):
        tmp = list(map(int, input().split()))
        tmp_h = tmp[0]-1
        tmp_w = tmp[1]-1

        h[m] = tmp_h
        w[m] = tmp_w

        sum_h[tmp_h] += 1
        sum_w[tmp_w] += 1

    if H == 1:
        print(sum_w.sum())
        return
    elif W == 1:
        print(sum_h.sum())
        return

    ans1 = 0

    ans_h = np.argmax(sum_h) # hについては決定
    ans1 += max(sum_h)

    sum_w_dup = sum_w.copy()
    for m in range(M):
        if h[m] == ans_h:
            sum_w_dup[w[m]] -= 1

    ans_w = np.argmax(sum_w_dup)
    ans1 += max(sum_w_dup)

    ans2 = 0

    ans_w = np.argmax(sum_w)
    ans2 += max(sum_w)

    sum_h_dup = sum_h.copy()
    for m in range(M):
        if w[m] == ans_w:
            sum_h_dup[h[m]] -= 1

    ans_h = np.argmax(sum_h_dup)
    ans2 += max(sum_h_dup)

    print(max(ans1, ans2))
    pass


if __name__ == '__main__':
    main()


Measured memory_bytes: 40880
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
ll powmod(ll n, ll k, ll m) {
ll r=1;
 for(; k>0; k >>=1) {
   if(k&1) r=(r*n)%m;
   n=(n*n)%m;
 }
  return r;
}

ll fact(ll n) {
ll a=1;
rep(i,n) {
a=a*(n-i);
}
return a;
}

ll pow(ll a, ll b) {
ll x=1;
rep(i,b) {
x=x*a;
}
return x;
}

int main() {
ll X;
  cin >>X;
  bool dp[1000000];
  dp[0]=true;
  repl(i,1,100) {
dp[i]=false;
  }

  dp[100]=true;
  dp[101]=true;
  dp[102]=true;
  dp[103]=true;
  dp[104]=true;
  dp[105]=true;
  
repl(i,106,1000000) {
  if((dp[i-100]) ||(dp[i-105])||(dp[i-101])||(dp[i-102])||(dp[i-103])||(dp[i-104])) {
    dp[i]=true;
  }
  else {
dp[i]=false;
  }
}
  
  
  
  if(dp[X]) {
    cout<<1<<endl;
  }
else {
cout<<0<<endl;
}

  
  
}

Measured memory_bytes: 4588
using System;
using System.Linq;

namespace ABC121
{
    class B
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int N = int.Parse(input[0]);
            int M = int.Parse(input[1]);
            int C = int.Parse(input[2]);

            int counnt = 0;
            int res = 0;

            int[] B = Console.ReadLine().Split().Select(int.Parse).ToArray();

            for (int i = 0; i < N; i++)
            {
                res = 0;
                int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
                for (int j = 0; j < M; j++)
                {
                    res += A[j] * B[j];
                }
                if (res + C > 0) { counnt++; }
            }
            Console.WriteLine(counnt);
        }
    }
}


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

typedef struct {
    int num[6], temp;
} dice_struct;
dice_struct dice;

void setting(int d[]) {
    for (int i = 0; i < 6; i++) {
        dice.num[i] = d[i];
    }
}

int right(int top, int front) {
    int zero = dice.num[0];
    int one = dice.num[1];
    int two = dice.num[2];
    int three = dice.num[3];
    int four = dice.num[4];
    int five = dice.num[5];


    if (top == zero) {
        if (front == one) {
            return two;
        } else if (front == two) {
            return four;
        } else if (front == four) {
            return three;
        } else if (front == three) {
            return one;
        }
    } else if (top == one) {
        if (front == two) {
            return zero;
        } else if (front == zero) {
            return three;
        } else if (front == three) {
            return five;
        } else if (front == five) {
            return two;
        }
    } else if (top == two) {
        if (front == zero) {
            return one;
        } else if (front == one) {
            return five;
        } else if (front == five) {
            return four;
        } else if (front == four) {
            return zero;
        }
    } else if (top == three) {
        if (front == zero) {
            return four;
        } else if (front == four) {
            return five;
        } else if (front == five) {
            return one;
        } else if (front == one) {
            return zero;
        }
    } else if (top == four) {
        if (front == zero) {
            return two;
        } else if (front == two) {
            return five;
        } else if (front == five) {
            return three;
        } else if (front == three) {
            return zero;
        }
    } else if (top == five) {
        if (front == one) {
            return three;
        } else if (front == three) {
            return four;
        } else if (front == four) {
            return two;
        } else if (front == two) {
            return one;
        }
    }
}

int main(int argc, char const *argv[]) {
    int number[6];
    for (int i = 0; i < 6; i++) {
        cin >> number[i];
    }
    setting(number);

    int q;
    cin >> q;

    int t, f, r;

    for (int i = 0; i < q; i++) {
        cin >> t >> f;
        r = right(t, f);
        cout << r << endl;
    }   
       
    return 0;
}



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

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

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let nmd = read_vec::<f64>();
    let (n,m,d) = (nmd[0],nmd[1],nmd[2]);
    let diff  = if d == 0. {
        n-d
    }else {
        (n-d)*2.
    };
    println!("{:.12}",((diff/ (n*n) * (m-1.))));
}

Measured memory_bytes: 4352
N = input()
Ws = {}
for i in range(int(N)):
  a = input()
  if a in Ws.keys():
    Ws[a] += 1
  else:
    Ws[a] = 0
m = max(Ws.values())
for i in sorted([k for k, v in Ws.items() if v == m]):
  print(i)

Measured memory_bytes: 32988
K, N = map(int, input().split())
A = list(map(int, input().split()))

A.append(A[0] + K)
max_d = 0
for i in range(N):
	d = A[i + 1] - A[i]
	if max_d < d:
		max_d = d
print(K - max_d)

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

using namespace std;

string s, fr, ba;
int len, ans;

int main()
{
	cin>>s;
	len = s.length();
	fr = s.substr(0, len / 2);
	if(len % 2) ba = s.substr(ceil(len / 2) + 1, len / 2);
	else ba = s.substr(len / 2, len / 2);
	//cout<<fr<<endl<<ba<<endl;
	for(int i = 0; i < len / 2; i ++)
	{
		if(fr[i] != ba[len / 2 -i - 1]) ans ++;
	}
	cout<<ans;
	return 0;
}

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

int main(){
    int N=0;
    scanf("%d",&N);
    long ans=0;
    for(int i = 1; i <= N;i++){
        if(i%15!=0) if(i%3!=0) if(i%5!=0) ans+=i;
    }
    printf("%ld\n",ans);
    return 0;
}

Measured memory_bytes: 1728
#include <cstdio>
using namespace std;
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
long long f[100008];
int x[100008];
int main(){
	register int n, e, t, i, j;
	register long long fmin = 3000000000ll;
	scanf("%d %d %d", &n, &e, &t);
	for (i = 1; i <= n; ++i) scanf("%d", &x[i]);
	f[0] = 0;
	for (j = 0, i = 1; i <= n; ++i) {
		while (2 * (x[i] - x[j + 1]) > t) {
			cmin(fmin, f[j] - x[j + 1] * 2);
			++j;
		}
		f[i] = dmin(fmin + 2 * x[i], f[j] + t);
	}
	printf("%lld\n", f[n] + e);
	return 0;
}

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

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < 4; i++) cout << s[i];
    cout << " ";
    for(int i = 4; i < 12; i++) cout << s[i];
    cout << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct pp{
    char name[100];
    int t;
} P;

P Q[LEN];
int head, tail, n;

void enque(P x){
    Q[tail] = x;
    tail = (tail+1)%LEN;
}

P deque(){
    P x = Q[head];
    head = (head+1)%LEN;
    return x;
}

int min(int a, int b){return a<b?a:b;}

int main(){
    int elaps = 0, c;
    int i, q;
    P u;
    scanf("%d %d", &n, &q);
    for(i=1;i<=n;i++){
        scanf("%s", Q[i].name);
        scanf("%d", &Q[i].t);
    }
    head = 1;tail = n+1;

    while(head != tail){
        u = deque();
        c = min(q, u.t);
        u.t -= c;
        elaps += c;
        if(u.t>0)enque(u);
        else{
            printf("%s %d\n", u.name, elaps);
        }
    }
    return 0;
}

Measured memory_bytes: 11184
#include <iostream>
#include<string>
#include<map>
#include<iostream>
#include<math.h>
#include<vector>
#include<algorithm>
#include <time.h>
#include<limits.h>
#include<unordered_map>
#include <set>
using namespace std;
const long long m = 1e18;
int main() {
    int n; cin >> n;
    long long a[n];
    long long pr = 1;
    bool f = false;
    bool z = false;
    for (int i = 0; i < n; i ++) {
        cin >> a[i];
        if (a[i] == 0) z = true;
    }
    if (z) {
        cout << 0;
        return 0;
    }
    long long mn = m + 1;
    for (int i = 0; i < n; i ++) {
        if (a[i] > mn) {
            cout << - 1 << endl;
            return 0;
        }
        pr = pr * 1ll * a[i];
        mn = ceil(double(m) / pr);
    }
    if (pr > m || pr < 0) {
            cout << - 1 << endl;
            return 0;
    }
    cout << pr << endl;
        
        
}


Measured memory_bytes: 4472
X = int(input())

ok = [False for _ in range(100000 + 1)]
ok[0] = True

target = [100, 101, 102, 103, 104, 105]

for x in target:
    for i in range(100000 + 1 - x):
        ok[i + x] |= ok[i]

print(1 if ok[X] else 0)

Measured memory_bytes: 45424
#include <bits/stdc++.h>
#include <array>
using namespace std;
using ULL = unsigned long long;
using UL = unsigned;
using LL = long long;
#define rep(i, n) for(UL i = 0; i < (n); i++)

struct Problem {

	void Solve() {
		LL a, b, c; cin >> a >> b >> c;
		ULL K; cin >> K;
		if (K % 2) swap(a, b);
		cout << (a - b) << endl;
	}


	Problem();
};
int main() {
	unique_ptr<Problem> p(new Problem());
	p->Solve();
	return 0;
}
Problem::Problem() {
	cout << fixed << setprecision(10);
}

Measured memory_bytes: 256
#include <iostream>

int main() {
	int N;
	std::cin >> N;
	int a[N];
	int ans = 0;
	int k = 1;
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
		if (i > 0) {
			if (a[i] == a[i - 1]) {
				k++;
			} else {
				ans += (k / 2);
				k = 1;
			}
		}
	}
	ans += (k / 2);
	std::cout << ans << std::endl;
}

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

namespace PaizaSkillCheck
{
    public class Program
    {
        public static void Main(string[] args)
        {
            string[] line = Console.ReadLine().Split(' ');
            int AB = int.Parse(line[0]);
            int BC = int.Parse(line[1]);
            Console.WriteLine(AB * BC / 2);
        }
    }
}


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


typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ld;

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll a,b,n;
    cin>>a>>b>>n;
    ll x=min(b-1,n);
    ll ans=(a*x)/b - a*(x/b);
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3624
#include <stdio.h>

int main()
{
	int N,A,B;
	scanf ("%d %d %d",&N,&A,&B);
	if (A > B) puts("0");
	else if (N == 1){
		if (A != B) puts("0");
		else puts("1");
	}
	else{
		printf ("%lld\n",(long long)(N-2)*(B-A)+1);
	}

	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using i32 = int;
#define REP(i,n) FOR(i,0,n)
template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
inline i32 read() {
    i32 x = 0, f = 1;
    char ch = std::getchar();
    while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = std::getchar(); }
    while (ch >= '0' && ch <= '9') x = (x << 3) + (x << 1) + (ch ^ 48), ch = std::getchar();
    return x * f;
}
void put(i32 x) {
    if (x < 0) std::putchar('-'), x = -x;
    if (x >= 10) put(x / 10);
    std::putchar(x % 10 + '0');
}
i32 main() {
    using namespace std;
    i32 N = read();
    i32 A, B = 0, C = 0, ans = 0;
    for (i32 i = 0; i < N; i++) {
        A = read();
        if (B >= A) C++;
        else        C=0;
        chmax(ans,C);
        B = A;
    }
    put(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    string s, t;
    cin >> s;
    cin >> t;
    int p = s.length();
    int count = 0;
    for (int i = 0; i <= p; i++){
        if (s[i] != t[i]){
            count+=1;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3472
#include <iostream>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned ll
#define db double
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PII pair<int, int>

string str;
const string s = "CODEFESTIVAL2016";

int main() {
    cin >> str;
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != str[i]) {
            ans++;
        }
    }
    cout << ans << endl;
}

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

int main(void){

  int A_in[3],B_in[3],C_in[3],A_out[3],B_out[3],C_out[3],timeA,timeB,timeC,timeA_in,timeA_out,timeB_in,timeB_out,timeC_in,timeC_out,hourA=0,hourB=0,hourC=0,minA=0,minB=0,minC=0,secA=0,secB=0,secC=0;

  //テ・ツ?・テ・ツ環?
  cin >> A_in[0] >> A_in[1] >> A_in[2];
  cin >> A_out[0] >> A_out[1] >> A_out[2];
  cin >> B_in[0] >> B_in[1] >> B_in[2];
  cin >> B_out[0] >> B_out[1] >> B_out[2];
  cin >> C_in[0] >> C_in[1] >> C_in[2];
  cin >> C_out[0] >> C_out[1] >> C_out[2];

  //テァツァツ津ヲツ閉ーテ」ツ?ォテヲツ渉崚ァツョツ?
  timeA_in = A_in[0]* 3600 + A_in[1]*60 + A_in[2];
  timeA_out = A_out[0]* 3600 + A_out[1]*60 + A_out[2];
  timeB_in = B_in[0]* 3600 + B_in[1]*60 + B_in[2];
  timeB_out = B_out[0]* 3600 + B_out[1]*60 + B_out[2];
  timeC_in = C_in[0]* 3600 + C_in[1]*60 + C_in[2];
  timeC_out = C_out[0]* 3600 + C_out[1]*60 + C_out[2];

  //テゥツ鳴禿ゥツ堋氾」ツつ津ィツィツ暗ァツョツ?
  timeA = timeA_out - timeA_in;
  timeB = timeB_out - timeB_in;
  timeC = timeC_out - timeC_in;

  //A
  while(1){ //Aテ」ツ?ョテヲツ卍づゥツ鳴禿」ツ?ョティツィツ暗ァツョツ?
    if(timeA - 3600 >= 0){
      timeA -= 3600;
      hourA++;
    }else{
      break;
    }
  }
  while(1){ //Aテ」ツ?ョテ・ツ按?」ツ?ョティツィツ暗ァツョツ?
    if(timeA - 60 >= 0){
      timeA -= 60;
      minA++;
    }else{
      break;
    }
  }

  secA = timeA;

  //B
  while(1){ //Bテ」ツ?ョテヲツ卍づゥツ鳴禿」ツ?ョティツィツ暗ァツョツ?
    if(timeB - 3600 >= 0){
      timeB -= 3600;
      hourB++;
    }else{
      break;
    }
  }
  while(1){ //Bテ」ツ?ョテ・ツ按?」ツ?ョティツィツ暗ァツョツ?
    if(timeB - 60 >= 0){
      timeB -= 60;
      minB++;
    }else{
      break;
    }
  }

  secB = timeB;

  //C
  while(1){ //Cテ」ツ?ョテヲツ卍づゥツ鳴禿」ツ?ョティツィツ暗ァツョツ?
    if(timeC - 3600 >= 0){
      timeC -= 3600;
      hourC++;
    }else{
      break;
    }
  }
  while(1){ //Cテ」ツ?ョテ・ツ按?」ツ?ョティツィツ暗ァツョツ?
    if(timeC - 60 >= 0){
      timeC -= 60;
      minC++;
    }else{
      break;
    }
  }

  secC = timeC;
  
  cout << hourA << ' '<< minA << ' '<< secA << endl;
  cout << hourB << ' '<< minB << ' '<< secB << endl;
  cout << hourC << ' '<< minC << ' '<< secC << endl;

  return 0;
}

Measured memory_bytes: 1160
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cs = Counter(s)
freq = Counter(cs).most_common()
cnt = Counter(cs).most_common()[0][1]
ans = []
for i, c in freq:
  if c == cnt:
    ans.append(i)
    
ans.sort()

for i in ans:
  print(i)

Measured memory_bytes: 71660
/*

Coded by peyha X

*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int NMAX=3*1e3+2,AUCUN=0;
string s,t;
char used[NMAX][NMAX];
int n,m,dp[NMAX][NMAX];
pair<int,int> last[NMAX][NMAX];

void retrieve(int k,int l){
	if(k==0 || l==0){
		return;
	}
	
	int nextK=last[k][l].first,nextL=last[k][l].second;
	retrieve(nextK,nextL);
	if(used[k][l]!=AUCUN){
		cout << used[k][l];
	}
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> s >> t;
	n=s.size();
	m=t.size();
	
	for(int k=0;k<=n;k++){
		used[k][0]=AUCUN;
	}
	for(int l=0;l<=m;l++){
		used[0][l]=AUCUN;
	}
	
	for(int k=1;k<=n;k++){
		for(int l=1;l<=m;l++){
			
			
			//cout << k << ' ' << l << endl;
			if(dp[k-1][l]>dp[k][l]){
				dp[k][l]=dp[k-1][l];
				used[k][l]=AUCUN;
				last[k][l]=make_pair(k-1,l);
			}
			if(dp[k][l-1]>dp[k][l]){
				dp[k][l]=dp[k][l-1];
				used[k][l]=AUCUN;
				last[k][l]=make_pair(k,l-1);
			}
			if(s[k-1]==t[l-1] && dp[k-1][l-1]+1>dp[k][l]){
				dp[k][l]=dp[k-1][l-1]+1;
				used[k][l]=s[k-1];
				last[k][l]=make_pair(k-1,l-1);
			}
				
		}
	}
	
	retrieve(n,m);
	cout << '\n';
}


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

const int R = 3;
const int L = R*R;
string P[L];
pair<int,int> G[R][R];
bool used[L];

char getC(const string &s, int diff, int dir) {
  return s[(dir-diff+4)%4];
}

int rec(int x, int y, int k) {
  if(x == 3) {
    x = y+2;
    y = 2;
  } else if(y == -1) {
    y = x;
    x = 0;
  }
  int res = 0;
  if(k == L) return 1;
  for(int i = 0; i < L; ++i) {
    if(used[i]) continue;
    for(int j = 0; j < 4; ++j) {
      if(x != 0) {
        char t = getC(P[G[y][x-1].first], G[y][x-1].second, 1);
        char s = getC(P[i], j, 3);
        if((isupper(t) ^ isupper(s)) && toupper(t) == toupper(s)) {
        } else {
          continue;
        }
      }
      if(y != 0) {
        char t = getC(P[G[y-1][x].first], G[y-1][x].second, 2);
        char s = getC(P[i], j, 0);
        if((isupper(t) ^ isupper(s)) && toupper(t) == toupper(s)) {
        } else {
          continue;
        }
      }
      G[y][x] = make_pair(i, j);
      used[i] = true;
      res += rec(x+1, y-1, k+1);
      used[i] = false;
    }
  }
  return res;
}

int main() {
  int T;
  cin >> T;
  while(T--) {
    for(int i = 0; i < L; ++i) cin >> P[i];
    fill(used, used+L, false);
    cout << rec(0,0,0) << endl;
  }
  return 0;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 1e5 + 5;
const ll LINF = 1e18 + 5;
int n, a[N], p[N];
int l1[N], l2[N], r1[N], r2[N]; 
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	cin >> n;
 	for(int i=1; i<=n; i++)
 	{
 		cin >> a[i];
 		p[a[i]] = i;
 	}
 	set <int> s;
 	for(int i=1; i<=n; i++) s.insert(i);
 	for(int i=1; i<=n; i++)
 	{
 		s.erase(p[i]);
 		auto it = s.lower_bound(p[i]);
 		if(it!=s.end())
 		{
 			int x = *it;
 			r1[i] = x;
 			s.erase(it);
 			auto it2 = s.lower_bound(p[i]);
 			if(it2!=s.end()) r2[i] = *it2;
 			else r2[i] = n+1;
 			s.insert(x);
 		}
 		else r1[i] = r2[i] = n+1;
 	}
 	for(int i=1; i<=n; i++) s.insert(i);
 	for(int i=1; i<=n; i++)
 	{
 		s.erase(p[i]);
 		auto it = s.lower_bound(p[i]);
 		if(it!=s.begin())
 		{
 			--it;
		 	int x = *it;
 			l1[i] = x;
 			s.erase(it);
 			auto it2 = s.lower_bound(p[i]);
 			if(it2!=s.begin()) l2[i] = *(--it2);
 			else l2[i] = 0;
 			s.insert(x);
 		}
 		else l1[i] = l2[i] = 0;
 	}
 	ll ans = 0;
 	for(int i=1; i<=n; i++)
 	{
 		//cout << l2[i] << ' ' << l1[i] << ' ' << r1[i] << ' ' << r2[i] << '\n';
 		ans += 1ll * (l1[i]-l2[i]) * (r1[i]-p[i]) * i;
 		ans += 1ll * (p[i]-l1[i]) * (r2[i]-r1[i]) * i;
 	}
 	cout << ans;
	return 0;
}


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

lst_s = ['S 1','S 2','S 3','S 4','S 5','S 6','S 7','S 8','S 9','S 10','S 11','S 12','S 13']
lst_h = ['H 1','H 2','H 3','H 4','H 5','H 6','H 7','H 8','H 9','H 10','H 11','H 12','H 13']
lst_c = ['C 1','C 2','C 3','C 4','C 5','C 6','C 7','C 8','C 9','C 10','C 11','C 12','C 13']
lst_d = ['D 1','D 2','D 3','D 4','D 5','D 6','D 7','D 8','D 9','D 10','D 11','D 12','D 13']

lst_all = lst_s + lst_h + lst_c +lst_d

lst_ipt = []

for i in range (n):
     lst_ipt.append(input())

for j in range(n):
    lst_all.remove(lst_ipt[j])

for h in range(52-n):
    print(lst_all[h])


Measured memory_bytes: 5608
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto S = readln.chomp.to!long;

    auto p = S.to!double.sqrt.to!long;
    if (p^^2 < S) ++p;
    auto d = p^^2 - S;

    writefln("%d %d %d %d %d %d", 0, 0, p, 1, d, p);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,b,a) for(ll i=b-1;i>=a;i--)
#define pq_min priority_queue<pair<ll,ll>,vector<pair<ll,ll>>,greater<pair<ll,ll>>>
#define pq_max priority_queue<pair<ll,ll>>
#define forx(i,a,b) for(ll i=a;i<b;i++)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define endl "\n"
typedef pair<pp,pp> ppll;
const ll mod=998244353;
const ld pi = 3.14159265359;
const ll N=100005;
ll n,q;

bool isOverflow(long long a, long long b) 
{ 
    // Check if either of them is zero 
    if (a == 0 || b == 0)  
        return false; 
      
    long long result = a * b;
    ll d=1e18; 
    if (a == result / b && result<=d) 
        return false; 
    else
        return true; 
}

ll power(ll a,ll b)
{
    ll res=1;
    a%=mod;
    while(b>0)
    {
        if(b%2==1)
        {
            res = (res * a)%mod;
        }
        b/=2;
        a = (a*a)%mod;
    }
    return res;
}


int main()
{
  fast;
  ll n;
  cin>>n;
  ld a[n];
  ll z=0;
  f(i,0,n) 
  {
    cin>>a[i];
    if(a[i]==0) z=1;
  }
  if(z==1)
  {
    cout<<"0";
    return 0;
  }
  ld ans=1;
  ld d = 1e18;
  f(i,0,n)
  {
     ans *= a[i];
     if(ans > d)
     {
       ans=-1;
       break;
     }
  }
  precision(ans,0);
}

Measured memory_bytes: 5396
#include <stdio.h>
#include <string.h>
#define min(a,b) a > b ? b : a

int main(void){
	int n, m, i, j, c[16], x, t;
	long long int f[2][256], k;
	while(1){
		scanf("%d%d",&n,&m);
		if(n == 0 && m == 0)
			break;
		for(i = 0;i < m;i++)
			scanf("%d",&c[i]);
		memset(f,-1,sizeof(f));
		f[0][128] = 0;
		for(i = 0;i < n;i++){
			scanf("%d",&x);
			for(k = 0;k < 256;k++){ // 現在位置
				if(f[i % 2][k] != -1){
					for(j = 0;j < m;j++){
						t = k + c[j];
						if(t < 0)
							t = 0;
						else if(t > 255)
							t = 255;
						if(f[(i + 1) % 2][t] == -1 || f[(i + 1) % 2][t] > f[i % 2][k] + (x - t) * (x - t))
							f[(i + 1) % 2][t] = f[i % 2][k] + (x - t) * (x - t);
					}
				}
			}
			for(j = 0;j < 256;j++)
				f[i % 2][j] = -1;
		}
		k = 0x7FFFFFFF;
		for(i = 0;i < 256;i++){
			if(f[n % 2][i] != -1)
				k = min(f[n % 2][i],k);
		}
		printf("%d\n",k);
	}
	return 0;
}

Measured memory_bytes: 1032
#import<iostream>
int main(){int K,n,i=-1,j,k;std::cin>>K;std::cout<<(n=(K+3)/4*2);while(++i<n){std::cout<<'\n';j=-1;while(++j<n)std::cout<<((k=i%2*n+(i+j)%n)>=K?k-n:k)%K+1<<' ';}}

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

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


int N;
int A[333333];

int S[333333],dp[333333];

bool check(int x){
    S[1]=A[0];
    for(int i=1;i<N/2+1;i++){
        S[i+1]=S[i]+A[i*2]-A[i*2-1];
    }

    //S[i+1]-S[j+1]+A[j*2+1]>=x

    memset(dp,0,sizeof(dp));

    dp[0]=1;
    int uku=0;
    rep(i,N/2+1){
        if(S[i+1]>=x+uku){
            dp[i+1]=1;
            chmin(uku,S[i+1]-A[i*2+1]);
        }
    }
    return dp[N/2+1];
}

signed main(){
    cin>>N;
    rep(i,N)cin>>A[i];

    int sum[2]={};
    rep(i,N)sum[i&1]+=A[i];


    if(N%2==0){
        cout<<*max_element(sum,sum+2)<<" "<<*min_element(sum,sum+2)<<endl;
    }
    else{
        int lb=0,ub=1001001001;
        while(ub-lb>1){
            int mid=(ub+lb)/2;
            if(check(mid-sum[1]))lb=mid;
            else ub=mid;
        }
        cout<<lb<<" "<<sum[0]+sum[1]-lb<<endl;
    }
    return 0;
}


Measured memory_bytes: 7808
#include <bits/stdc++.h>
	using namespace std;
	#define sim template < class c
	#define ris return * this
	#define dor > debug & operator <<
	#define eni(x) sim > typename \
	enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
	sim > struct rge { c b, e; };
	sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
	sim > auto dud(c* x) -> decltype(cerr << *x, 0);
	sim > char dud(...);
	struct debug {
	#ifdef LOCAL
	~debug() { cerr << endl; }
	eni(!=) cerr << boolalpha << i; ris; }
	eni(==) ris << range(begin(i), end(i)); }
	sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
	}
	sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
	}
	#else
	sim dor(const c&) { ris; }
	#endif
	};
	#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define deb debug()
	#define lel(...) deb << " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
	#define ll long long
	#define all(x) (x).begin(), (x).end()
	// 
using namespace std;
 
const int N = 50010;
ll mod = 998244353;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} 


int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int x, y, A, B, C;
	cin >> x >> y >> A >> B >> C;
	vector<int> all, tab;
	for (int a = 1; a <= A; a++) {
		int v;
		cin >> v;
		tab.push_back(v);
	}
	sort(tab.begin(), tab.end());
	reverse(tab.begin(), tab.end());
	for (int a = 1; a <= x; a++) all.push_back(tab[a - 1]);
	tab.clear();

	for (int a = 1; a <= B; a++) {
		int v;
		cin >> v;
		tab.push_back(v);
	}
	sort(tab.begin(), tab.end());
	reverse(tab.begin(), tab.end());
	for (int a = 1; a <= y; a++) all.push_back(tab[a - 1]);
	tab.clear();
	
	for (int a = 1; a <= C; a++) {
		int v;
		cin >> v;
		tab.push_back(v);
	}
	sort(tab.begin(), tab.end());
	reverse(tab.begin(), tab.end());
	for (int a = 1; a <= min(x + y, C); a++) all.push_back(tab[a - 1]);
	tab.clear();

	sort(all.begin(), all.end());
	reverse(all.begin(), all.end());
	ll ans = 0;
	int n = all.size();
	for (int a = 1; a <= min(x + y, n); a++) ans += all[a - 1];
	cout << ans << endl;

	
	
	return 0;
}

Measured memory_bytes: 2804
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();
	int c;
	while(!(a==b)){
		if(a<b){
			c=b-a;
			b=c;
		}else{
			c=a-b;
			a=c;
		}
	}
	System.out.println(a);
}
}



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

int main()
{
    //i枚目の青・・si
    //i枚目の赤・・ti
    int plus = 0;
    int minus = 0;
    int ans = 0;
    int N;
    cin >> N;
    vector<string> s(N);
    rep(i,N) cin >> s[i];
    int M ;
    cin >> M;
    vector<string> t(M);
    rep(i,M) cin >> t[i];
    rep(i,N){
        plus = count(s.begin(),s.end(),s[i]);
        minus = count(t.begin(),t.end(),s[i]);
        if(plus >= minus && (plus - minus) > ans){
            ans = plus - minus;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
	
	int sum;
	char str[1100];
	int i;
	
	for(i=0;i<1100;i++){
		str[i]=0;
	}
	
	while(1){
		scanf("%s",str);
		if(strcmp(str,"0")==0){
			break;
		}
		sum=0;
		for(i=0;str[i]!='\0';i++){
			sum+=str[i]-'0';
		}
		printf("%d\n",sum);
	}
	
	return 0;
}

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

int main(void){
    int a, b;
    cin >> a >> b;
    bool flg = false; 
    for(int k = 0; k <= 1000000000; k++){
        if(abs(a - k) == abs(b - k)){
            flg = true;
            cout << k << endl;
            break; 
        }
    }
    if(!flg) cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int d,n;
  scanf("%d %d",&d,&n);
  int ans=1;
  while(d>0){
    ans*=100;
    d-=1;
  }
  if(n<100){
    printf("%d",n*ans);
  }else{
    printf("%d",101*ans);
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <set>
#include <cstring>
using namespace std;

int    N,K;
bool   v[10];
string s[10];
set<string> c;

void f(int k, string str)
{
	if(k==K)
	{
		c.insert(str);
		return;
	}

	for(int i=0; i<N; i++)
	{
		if(v[i]) continue;

		v[i]=1;
		f(k+1, str+s[i]);
		v[i]=0;
	}
}


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

		c.clear();
		memset(v, 0, sizeof(v));
		f(0, "");
		cout << c.size() << endl;
	}
}

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



int main(){
    ld A, B;
    cin >> A >> B;
    ll ans = A * B;
    
    cout << ans << endl;
}

Measured memory_bytes: 3732
from collections import defaultdict

n = int(input())
height = list(map(int, input().split()))
ans = 0

d = defaultdict(int)

for i in range(n):
    x = i+height[i]
    d[x] += 1

for i in range(n):
    x = i-height[i]
    ans += d[x]

print(ans)


Measured memory_bytes: 61520
#include<iostream>
#include<string>
using namespace std;
 
int main(){
  int N;
  int A;
  cin >> N;

  int counter = 0;
  for(int i = 1;i<=N;++i){
    cin >> A;
    if(A != i) counter++;
  }
  
  if(counter == 2 || counter == 0) cout << "YES" << endl;
  else cout << "NO" << endl;
}

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

int main() {
  int N;
  cin >> N;
  string s;
  vector<string> blue(N);
  
  for(int i=0; i<N; i++){
    cin >> s;
    blue.at(i) = s;
  }
  
  int M;
  cin >> M;
  string t;
  vector<string> red(M);
  
  for(int i=0; i<M; i++){
    cin >> s;
    red.at(i) = s;
  }
  //出力
  int max=0;
  for(int i=0; i<N; i++){
    int x=0;
    for(int j=0; j<N; j++){
      if(blue.at(i)==blue.at(j)){
        x++;
      }
    }
    for(int j=0; j<M; j++){
      if(blue.at(i)==red.at(j)){
        x--;
      }
    }
    if(max<x){
      max=x;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
N = int(input())
x = list(map(int,input().split()))
T = x[0]
A = x[1]

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

difference = 10000
ans = 0
for i in range(0,N):
	if(difference > abs(A-(T-H[i]*0.006))):
		ans = i
		difference = abs(A-(T-H[i]*0.006))
	
print(ans+1)


Measured memory_bytes: 3064
from copy import deepcopy

HEIGHT, WIDTH, K = map(int, input().split())
CELLS = [list(input()) for i in range(HEIGHT)]

ans = 0

for maskY in range(1<<HEIGHT):
  for maskX in range(1<<WIDTH):
    black=0
    for y in range(HEIGHT):
      for x in range(WIDTH):
        if (maskY >> y & 1) == 0 and (maskX >> x & 1) == 0 and CELLS[y][x] == '#':
          black+=1
    if K == black:
      ans+=1


print(ans)


Measured memory_bytes: 9284
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
  "sort"
)

func Solve() {
  var N, ma, mb int
  NextInt(&N)
  A := make([]int, N)
  B := make([]int, N)
  for i := range A {
    NextInt(&A[i], &B[i])
  }
  sort.Ints(A)
  sort.Ints(B)
  if N % 2 == 0 {
    ma = A[N / 2 - 1] + A[N / 2]
    mb = B[N / 2 - 1] + B[N / 2]
  } else {
    ma = A[N / 2]
    mb = B[N / 2]
  }
  Write(mb - ma + 1)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntVec(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatVec(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(s interface{}) {
  fmt.Fprintln(writer, s)
}
func WriteIntVec(A []int) {
  S := make([]string, len(A))
  for i, a := range A {
    S[i] = strconv.Itoa(a)
  }
  Write(strings.Join(S, " "))
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

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

int asc(const long long *a, const long long *b) {
  return *a - *b;
}

int main(void) {
  int N, curi;
  long long H, *a, *b, cur = 0;
  long long a_max = 0, cnt = 0;
  scanf("%d %lld", &N, &H);
  a = (long long*)malloc(sizeof(long long) * N);
  b = (long long*)malloc(sizeof(long long) * N);
  for (int i = 0; i < N; i++) {
    scanf("%lld %lld", &a[i], &b[i]);
  }

  for (int i = 0; i < N; i++) {
    if (a[i] > a_max) {
      a_max = a[i];
    }
  }
  qsort(b, N, sizeof(long long), asc);
  for (int i = N-1; i >= 0 && b[i] > a_max; i--) {
    H -= b[i];
    cnt++;
    if (H <= 0) {
      printf("%lld\n", cnt);
      return 0;
    }
  }
  if (H % a_max == 0) {
    printf("%lld\n", cnt + H / a_max);
  } else {
    printf("%lld\n", cnt + H / a_max + 1);
  }

  return 0;
}


Measured memory_bytes: 2556
N, K, Q = list(map(int, input().split()))
W = [0] * N
for _ in range(Q):
	i =int(input())
	W[i - 1] += 1
	
for i in range(N):
	if K - Q + W[i] > 0:
		print('Yes')
	else:
		print('No')


Measured memory_bytes: 9600
#include<iostream>
#include<algorithm>
#define INF 100000000
using namespace std;
int m[1000001],W,H;

int find(int x){
  if(m[x]==x) return m[x];
   return m[x]=find(m[x]);
}

void unite(int b,int a){
  int x=find(b);
  int y=find(a);
  if(x<y) swap(x,y);
  m[x]=y;
}

int cha(int x,int y){
  return y*W+x;
}

int main(){
  int dx[4]={-1,0,1,0};
  int dy[4]={0,-1,0,1};
  int N,wp,now,aft;
  string str;

  cin>>W>>H;
  for(int i=0;i<H;i++){
    cin>>str;
    for(int j=0;j<W;j++){
      int p=cha(j,i);
      if(str[j]=='t') wp=p;
      if(str[j]=='#') m[p]=INF;
      else  m[p]=p;
    }
  }
  
  int ax,ay,ans=-1;
  
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      for(int k=0;k<4;k++){
      now=cha(j,i);
      ax=j+dx[k],ay=i+dy[k];
      if(ax<0 || ay<0 || ax>=W || ay>=H || m[now]==INF) continue;
      aft=cha(ax,ay);
      if(m[aft]<INF ) unite(now,aft);
      }
    }
  }
  if(find(m[wp])==0) ans=0; 
  
   cin>>N;
  
   int x,y;

  for(int i=1;i<=N;i++){
    cin>>x>>y;
    int a=cha(x,y);
    if(m[a]==INF) m[a]=a;
    for(int j=0;j<4;j++){
      ax=x+dx[j],ay=y+dy[j];
      if(ax<0 || ay<0 || ax>=W || ay>=H ||m[cha(ax,ay)] == INF) continue;
   aft=cha(ax,ay);
      unite(a,aft);
      }
    if(find(m[wp])==0 && ans==-1) ans=i;
  }
   cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 5108
N = int(input())
abc = [[0]*3 for i in range(N)]
for n in range(N):
    abc[n][0], abc[n][1], abc[n][2] = map(int, input().split())

dp = [[0]*3 for i in range(N)]
dp[0][0] = abc[0][0]
dp[0][1] = abc[0][1]
dp[0][2] = abc[0][2]

for i in range(1,N):
    for j in range(3):
        dp[i][j] = max(dp[i][j],dp[i-1][(j+1)%3]+abc[i][j])
        dp[i][j] = max(dp[i][j],dp[i-1][(j+2)%3]+abc[i][j])
    
print(max(dp[N-1]))

Measured memory_bytes: 71660
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Pine1999
 */

#include <bits/stdc++.h>
//#include "../library/dsu.hpp"
//#include "../library/fenwicktree.hpp"
//#include "../library/modint.hpp"
//#include "../library/segtree.hpp"
//#include "../library/string.hpp"
//#include "../library/math.hpp"

using namespace std;
//using namespace atcoder;

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

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

void BProductMax(std::istream& in, std::ostream& out) {
    ll a[2], b[2];
    rep(i, 2) in >> a[i];
    rep(i, 2) in >> b[i];
    ll ans = -9e18;
    rep(i, 2) rep(j, 2) ans = max(ans, a[i] * b[j]);
    out << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    BProductMax(in, out);
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <vector>
#include <iomanip>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;

typedef long long ll;




int main(){

    int N;

    cin>>N;

    cout<<(1+N)*N/2<<endl;

    
    
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;
int dy[]={1,-1,0,0};
int dx[]={0,0,1,-1};

int main(){
  ll X,Y;
  cin>>X>>Y;
  ll ans=0;
  while(X<=Y){
    ans++;
    X*=2;
  }
  cout<<ans<<endl;
  return 0;
}



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

signed main(){
  LL n,k;
  cin>>n>>k;
  vector<LL> t(n),d(n);
  for(LL i=0;i<n;i++) cin>>t[i]>>d[i],t[i]--;
  {
    using P = pair<LL, LL>;
    vector<P> vp;
    for(LL i=0;i<n;i++) vp.emplace_back(d[i],t[i]);
    sort(vp.rbegin(),vp.rend());
    for(LL i=0;i<n;i++) tie(d[i],t[i])=vp[i];    
  }
  
  priority_queue<LL, vector<LL>, greater<LL> > pq;
  
  LL res=0;
  vector<LL> used(n,0);
  for(LL i=0;i<k;i++){
    if(used[t[i]]) pq.emplace(d[i]);
    used[t[i]]=1;
    res+=d[i];
  }
  LL cnt=0;
  for(LL i=0;i<n;i++) cnt+=used[i];

  LL ans=res+cnt*cnt;
  for(LL i=k;i<n;i++){
    if(used[t[i]]) continue;
    if(pq.empty()) break;
    used[t[i]]=1;
    cnt++;
    res-=pq.top();pq.pop();
    res+=d[i];
    ans = max(ans, res+cnt*cnt);
  }  
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>

using namespace std;


int main()
{
	int N;
	int max_n = 0;
	vector<int> list;
	vector<int> copy;
	cin >> N;	


	int n;
	for (int ni = 0; ni < N; ni++){
		cin >> n;
		list.push_back(n);
		copy.push_back(n);
	}


	sort(copy.begin(), copy.end(), greater<int>());

	int max_1 = copy[0];
	int max_2 = copy[1];

	for (int ni = 0; ni < N; ni++){
		if (list[ni] == max_1){
			printf("%d\n",max_2);
		}else{
			printf("%d\n",max_1);
		}
	}

	//printf("%d",ans);



	return 0;
}



Measured memory_bytes: 3436
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll; 
 
int A, B, T;
 
int main() {
    cin >> A >> B >> T;
    int aaa = (T + 1/2);
    cout << B * (aaa / A)<< endl;
    return 0;    
}

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

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

using namespace std;
const int IINF = INT_MAX;
typedef pair<int,int> ii;

int h,w,answer[200010],pos[200010],thsudao[200010];

int getLeftIndex(int x,int y){
  y %= ( w << 1 );
  while( y > 0 ){
    int diff=IINF;
    if( ( x & 1 ) == ( y & 1 ) ) diff = min(y,x); // back
    else                         diff = min(y,w-1-x); // front
    assert( diff != IINF );
    if( ( x & 1 ) == ( y & 1 ) ) x -= diff;
    else                         x += diff;
    y -= diff;
    if( diff == 0 ) --y;
    //cout << "diff = " << diff << endl;
    //cout << x << "," << y << endl << endl;
  }
  return x;
}


int main(){
  /*  
  int x,y;
  cin >> h >> w;
  while( cin >> x >> y ) {
    cout << getLeftIndex(x,y) << endl;
  }
  */
  /*
  for(int W=2;W<=10;W+=2){
    vector<int> state(W,-1);
    rep(i,W) state[i] = i;
    swapEven(state);    
    int cnt = 1;
    bool phase = true;
    while(1){
      bool fin = true;
      rep(i,W) if( state[i] != i ) { fin = false; break; }
      if( fin ) break;
      ++cnt;
      if( phase ) swapOdd(state);
      else        swapEven(state);
      phase = !phase;
    }
    cout << W << " : " << cnt << endl;
  }
  */

  int n;
  scanf("%d %d %d",&h,&w,&n);
  rep(i,w) answer[i] = getLeftIndex(i,h), pos[i] = i;
  vector<ii> vec(n);
  rep(i,n) scanf("%d %d",&vec[i].first,&vec[i].second);
  sort(vec.begin(),vec.end());
  rep(i,n) {
    //puts("");
    //cout << "(" << vec[i].first << "," << vec[i].second << endl;
    int p1 = getLeftIndex(vec[i].second-1,vec[i].first-1);
    int p2 = getLeftIndex(vec[i].second  ,vec[i].first-1);
    //cout << p1 << " x " << p2 << endl;
    swap(pos[p1],pos[p2]);
  }
  //rep(i,w) cout << pos[i] << " "; puts("");
  rep(i,w) thsudao[pos[answer[i]]] = i+1;
  rep(i,w) printf("%d\n",thsudao[i]);
  
  return 0;
}

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

int main()
{
    char memo[3];
    cin >> memo;

    int price = 700;
    for(int i; i < 3; i++) {
        if(memo[i] == 'o') {
            price = price + 100;
        }
    }
    cout << price << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll K;
    cin >> K;
    auto f = [&](ll x) {
        string s = to_string(x);
        ll n = s.size();
        ll cnt = 0;
        vector<vector<vector<ll>>> dp(n + 2, vector<vector<ll>>(2, vector<ll>(10, 0)));
        rep2(i, 1, s[0] - '0') {
            dp[1][1][i] = 1;
        }
        dp[1][0][s[0] - '0'] = 1;
        rep2(i, 1, n) {
            ll now = s[i] - '0';
            rep2(m, 1, 10) {
                dp[i + 1][1][m] = 1;
            }
            rep(j, 2) {
                rep(k, 10) {
                    rep2(m, -1, 2) {
                        if (k + m < 0 || k + m > 9) continue;
                        if (j == 0 && k + m > now) continue;
                        dp[i + 1][j == 1 || (k + m < now)][k + m] += dp[i][j][k];
                    }
                }
            }
        }
        rep(j, 10) {
            cnt += dp[n][0][j] + dp[n][1][j];
        }
        return cnt >= K;
    };

    ll ok = INF;
    ll ng = 0;
    while (ok - ng > 1) {
        ll mid = (ok + ng) / 2;
        if (f(mid)) {
            ok = mid;
        } else {
            ng = mid;
        }
    }
    cout << ok << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  double n,m;
  cin>>n>>m;
  vector<double> a(n);
  double ans=0;
  long double all=0;
  for(int i=0; i<n; i++){
    cin>>a.at(i);
    all+=a.at(i);
  }
  for(int i=0; i<n; i++){
    if(a.at(i)>=all/(4*m)){
      ans++;
    }
  }
  if(ans>=m){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <climits>
#include <numeric>
#include <cmath>
#include <queue>
#include <sstream>
#include <string.h>

using namespace std;
typedef long long ll;

int main() {
  int N;
  cin >> N;
  
  vector<ll> A(N), B(N), C(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];
  
  sort(A.begin(), A.end());
  sort(C.begin(), C.end());

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll x = lower_bound(A.begin(), A.end(), B[i]) - A.begin();
    ll y = C.end() - upper_bound(C.begin(), C.end(), B[i]);
    ans += x * y;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
using namespace std;
int n,a,b;
int main()
{
	cin>>n>>a>>b;
	while (a<b)
	{
		a++;
		if (a==b)
		{
			cout<<"Borys";
			return 0;
		}
		b--;
		if (a==b)
		{
			cout<<"Alice";
			return 0;
		}
	}
	while (a>b)
	{
		a--;
		if (a==b)
		{
			cout<<"Borys";
			return 0;
		}
		b++;
		if (a==b)
		{
			cout<<"Alice";
			return 0;
		}
	}
	cout<<"Borys";
	return 0;
}

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

using namespace std;

int main(){
    int N;
    bool flag = true;
    cin >> N;
    vector<int> H(N);
    for(int i=0;i<N;i++){
        cin >> H[i];
    }

    for(int i=0;i<N-1;i++){
        if(H[i+1]==H[i]-1){
            H[i+1]++;
        }else if(H[i+1]<H[i]-1){
            flag = false;
        }
    }

    if(flag){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

int main() {
	// your code goes here
	int h,m,s,hh,mm,ss;
	for(int i=0;i<3;i++){
		cin >> h >> m >> s >> hh >> mm >> ss;
		int times=(hh-h)*3600+(mm-m)*60+(ss-s);
		cout << times/3600 << " "<< (times%3600)/60<< " " << (times%60)<<  endl;
	}
	return 0;
}

Measured memory_bytes: 1160