akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
int main(void)
{
  int i,j;
  
  int n; 
  scanf("%d",&n);
  int S[n];
  for(i=0;i<n;i++) {
    scanf("%d",&S[i]);
  }

  int q;
  scanf("%d",&q);
  int T[q];
  for(i=0;i<q;i++) {
    scanf("%d",&T[i]);
  }

  int count=0;
  for(i=0;i<q;i++) {
    for(j=0;j<n;j++) {
      if(S[j]==T[i]) {
	    count++;
	    break;
      }
    }
  }

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


Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;

char c;

int main(){ 

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

cin>>c;

for(int i=0; i<1e8; i++){
	int x=0;
	x++;
}

if(c=='a'){
	cout<<"vowel"<<endl;
	return 0;
}
if(c=='e'){
	cout<<"vowel"<<endl;
	return 0;
}
if(c=='i'){
	cout<<"vowel"<<endl;
	return 0;
}
if(c=='o'){
	cout<<"vowel"<<endl;
	return 0;
}
if(c=='u'){
	cout<<"vowel"<<endl;
	return 0;
}

cout<<"consonant"<<endl;

}



Measured memory_bytes: 256
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,m;
string s;

int main()
{
	//fuck
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		cin>>s;
		cout<<s<<endl<<s<<endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;

ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
ll fact[200003];
ll ifact[200003];
ll Combination(ll a,ll b) {
  ll s = (fact[a] * ifact[b]) % Mod;
  return (s * ifact[a-b]) % Mod;
}

int main() {
  fact[0] = 1;
  ifact[0] = 1;
  for (ll i = 1; i < 200003; i++) {
    fact[i] = fact[i-1] * i;
    fact[i] %= Mod;
    ifact[i] = modinv(fact[i],Mod);
  }
  int S;
  cin >> S;
  ll ans = 0;
  for (ll i = 1; i < S; i++) {
    ll N = i;
    ll M = S - (3*i);
    if (M < 0) {
      continue;
    }
    ans += Combination(N+M-1,N-1);
    ans %= Mod;
  }
  if (ans < 0) ans += Mod;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6752
N,M = map(int,input().split())
es = [tuple(map(lambda x:int(x)-1,input().split())) for i in range(M)]

indeg = [0 for i in range(N)]
outdeg = [[] for i in range(N)]
for a,b in es:
    indeg[b] += 1
    outdeg[a].append(b)

heads = []
for i in range(N):
    if indeg[i]: continue
    heads.append(i)

dp = [0] * N
while heads:
    a = heads.pop()
    for b in outdeg[a]:
        indeg[b] -= 1
        if indeg[b] == 0:
            heads.append(b)
        dp[b] = max(dp[b], dp[a] + 1)
print(max(dp))

Measured memory_bytes: 32936
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;

  vector<long long> a(n*3);
  for (int i = 0; i < n*3; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long sum = 0;
  for (int i = n; i < 3*n; i += 2) {
    sum += a[i];
  }

  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c;
  	cin >> a >> b;
  	
   	if(a==1) {
      if(b==2) {
        c = 3;
      }
      if(b==3) {
        c = 2;
      }
    } else if(a==2) {
      if(b==1) {
        c = 3;
      }
      if(b==3) {
        c = 1;
      }
    } else if(a==3) {
      if(b==1) {
        c=2;
      }
      if(b==2) {
       	c=1;
      }
    }
  
	cout << c << endl;
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;
const int N = 1100000;
ll fact[N], ifact[N];

ll powmod(ll a, ll b){
    ll ans = 1;
    while(b){
        if(b & 1)ans = (ans * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return ans;
}

void init(){
    fact[0] = ifact[0] = 1;
    for(int i = 1; i < N; i++){
        fact[i] = (fact[i-1] * i) % mod;
        ifact[i] = powmod(fact[i], mod - 2);
    }
}

ll nCr(ll n, ll r){
    return fact[n] * ifact[r] % mod * ifact[n - r] % mod;
}

int main(){
    init();
    ll h, w, a, b;
    cin >> h >> w >> a >> b;
    ll ans = 0;
    for(int i = b + 1; i <= w; i++){
        ans = (ans + nCr(h - a + i - 2, i - 1) * nCr(a - 1 + w - i, a - 1)) % mod;
    }
    ans = (ans % mod + mod) % mod;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 17408
N  = int(input())
A = list(map(int, input().split()))
status = 0 # 0 = defalt, 1 = up, 2 = down
cnt = 1
for i in range(1,N):
    if A[i-1] < A[i]: #up petern
        if status == 0 or status == 1:
            status = 1
        else:
            status = 0
            cnt += 1
    elif A[i-1] > A[i]:
        if status == 0 or status == 2:
            status = 2
        else:
            status = 0
            cnt += 1
    else:
        continue
print(cnt)

Measured memory_bytes: 62704
package main 

import (
	"fmt"
)

func main() {
	var n, a, temp int
	var arr []int
	fmt.Scanln(&n)
	if n <= 100 {
		for i := 0; i < n; i++{
			fmt.Scan(&a)
			if a >= 0 && a < 1000 {
				arr = append(arr, a)
			}
		}
			
		for i := 0; i < n / 2; i++ {
			temp = arr[i]
			arr[i] = arr[n - 1 - i]
			arr[n - 1 - i] = temp
		}
		
		for i := 0; i < len(arr) - 1; i++ {
			fmt.Printf("%d ",arr[i])
		}
		fmt.Printf("%d\n",arr[len(arr) - 1])
	}
}


Measured memory_bytes: 1120
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <limits.h>
#include <cmath>
#include <queue>
#include <map>
#include <iomanip>
#include <random>
#include <fstream>
#define rep(i, n) for (int i = 0; i < n; i++)
#define PI 3.14159265358979323846
#define MOD 1000000007
using namespace std;
using ll = long long;

const int MAX = 1000000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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


int main()
{
  COMinit();
  int x,y; cin >> x >> y;
  if ((-x+2*y)%3!=0 || (2*x-y)%3!=0){
    cout << 0 << endl;
  } else {
    int a=(-x+2*y)/3;
    int b=(2*x-y)/3;
    cout << COM(a+b,a) << endl;
  }


  return 0;
}


Measured memory_bytes: 23680
use std::cmp::{self, Ordering};
use std::collections::*;
use std::io::{self, Read};

const MOD: usize = 1000000007;

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock());

    let n: usize = sc.read().unwrap();
    let m: usize = sc.read().unwrap();
    let q: usize = sc.read().unwrap();

    let mut t1 = Vec::with_capacity(n);
    for _ in 0..n {
        t1.push(vec![0 as i32; n]);
    }
    for _ in 0..m {
        let li: usize = sc.read().unwrap();
        let ri: usize = sc.read().unwrap();
        t1[li - 1][ri - 1] = t1[li - 1][ri - 1] + 1;
    }

    let mut t2 = Vec::with_capacity(n);
    for _ in 0..n {
        t2.push(vec![0 as i32; n]);
    }
    for i in 0..n {
        for j in 0..n {
            t2[i][j] = match (i > 0, j > 0) {
                (false, false) => t1[i][j],
                (false, true) => t1[i][j] + t2[i][j - 1],
                (true, false) => t1[i][j] + t2[i - 1][j],
                (true, true) => t1[i][j] + t2[i - 1][j] + t2[i][j - 1] - t2[i - 1][j - 1],
            };
        }
    }

    // for l in &t1 {
    //     println!("{:?}", l);
    // }
    // println!("----------");
    // for l in &t2 {
    //     println!("{:?}", l);
    // }

    for i in 0..q {
        let pi: usize = sc.read().unwrap();
        let pi = pi - 1;
        let qi: usize = sc.read().unwrap();
        let qi = qi - 1;

        if pi == 0 {
            println!("{}", t2[qi][qi]);
        } else {
            println!(
                "{}",
                t2[qi][qi] - t2[qi][pi - 1] - t2[pi - 1][qi] + t2[pi - 1][pi - 1]
            );
        }
    }
}

struct Scanner<R: Read> {
    reader: R,
}

impl<R: Read> Scanner<R> {
    fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }

    fn read<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>()
            .parse()
            .ok()
    }

    fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Option<Vec<T>> {
        (0..n).map(|_| self.read()).collect()
    }

    fn read_vec2d<T: std::str::FromStr>(&mut self, m: usize, n: usize) -> Option<Vec<Vec<T>>> {
        (0..m).map(|_| self.read_vec(n)).collect()
    }

    fn read_board(&mut self, n: usize) -> Option<Vec<Vec<char>>> {
        (0..n)
            .map(|_| {
                self.read::<String>()
                    .map(|s| s.chars().collect::<Vec<char>>())
            })
            .collect()
    }
}


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

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

  vector<int> l(n);
  rep(i, n) cin >> l.at(i);

  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());

  int ans = 0;
  rep(i, k) ans += l.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    X = [int(a) for a in input().split()]
    mi = 10**9
    for i in range(1, max(X) + 1):
        hp = sum([(X[j] - i)**2 for j in range(N)])
        if hp < mi:
            mi = hp
    print(mi)
if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#require 'pp'

h, w = gets.split.map(&:to_i)
matrix = Array.new(h + 1)
matrix[0] = ("." * (w + 2)).chars
1.upto(h) do |i|
    s = ".#{gets.chomp!}."
    matrix[i] = s.chars
end
matrix.push(("." * (w + 2)).chars)

ans = Array.new(h)


1.upto(h) do |i|
    ans[i] = Array.new(w, 0)
    1.upto(w) do |j|
        if matrix[i][j] == "#"
            print "#"
            next
        end

        count = 0
        count += matrix[i-1][j-1] == "#" ? 1 : 0
        count += matrix[i-1][j  ] == "#" ? 1 : 0
        count += matrix[i-1][j+1] == "#" ? 1 : 0
        count += matrix[i  ][j-1] == "#" ? 1 : 0
        #count += matrix[i  ][j  ] == "#" ? 1 : 0
        count += matrix[i  ][j+1] == "#" ? 1 : 0
        count += matrix[i+1][j-1] == "#" ? 1 : 0
        count += matrix[i+1][j  ] == "#" ? 1 : 0
        count += matrix[i+1][j+1] == "#" ? 1 : 0
        print count
    end
    puts ""
end


Measured memory_bytes: 2172
#-*- coding:utf-8 -*-

# Pythonのソートが安定であることを利用する
# まず、得点で降順でソートして、市名で昇順ソートする

N = int(input())
ls = [None]*N
for i in range(N):
    s, p = input().split()
    ls[i] = (i+1, s, int(p))
ls.sort(key=(lambda x: -x[2]))  # pで降順ソート
ls.sort(key=(lambda x: x[1]))   # sで昇順ソート (安定ソートなので、同じsについてpが降順となる)

for i, s, p in ls:
    print(i)




Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <vector>
#define rep(i,x,n) for(int i=x;i<n;i++)
#define repd(i,x,n) for(int i=x;i<=n;i++)
#define pii pair<int,int>
#define pll pair<long long ,long long>
#define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MSC0(X) memset((X), '\0', sizeof((X)))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define gg(x) getInt(&x)
using namespace std;
typedef long long ll;
inline void getInt(int* p);
const int maxn=1000010;
const int inf=0x3f3f3f3f;
/*** TEMPLATE CODE * * STARTS HERE ***/
int n,m;
int w[maxn];
ll v[maxn];
ll dp[maxn];
int main()
{
    gbtb;
    cin>>n>>m;
    repd(i,1,n)
    {
        cin>>w[i]>>v[i];
    }
    repd(i,1,n)
    {
        for(int j=m;j>=w[i];j--)
        {
            dp[j]=max(dp[j],1ll*dp[j-w[i]]+v[i]);
        }
    }
    cout<<dp[m];
    return 0;
}

inline void getInt(int* p) {
    char ch;
    do {
        ch = getchar();
    } while (ch == ' ' || ch == '\n');
    if (ch == '-') {
        *p = -(getchar() - '0');
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 - ch + '0';
        }
    }
    else {
        *p = ch - '0';
        while ((ch = getchar()) >= '0' && ch <= '9') {
            *p = *p * 10 + ch - '0';
        }
    }
}

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

using namespace std;

int main(){

int n;

cin>>n;

set<int> a;

a.insert(n);

for(int i=2;;i++){

	if(n%2==0)

		n/=2;

	else

		n=n*3+1;

	a.insert(n);

	if(i!=a.size()){

		cout<<i;

		return 0;}
	}
}


Measured memory_bytes: 256
from sys import stdin, stdout
import sys
INF=1e9
def get_int(): return int(stdin.readline().strip())
def get_ints(): return map(int,stdin.readline().strip().split()) 
def get_array(): return list(map(int,stdin.readline().strip().split()))
def get_string(): return stdin.readline().strip()
def op(c): return stdout.write(c)
#from collections import defaultdict 
#for _ in range(int(stdin.readline())):
x,y=get_ints()
if y%2==0:
    if y>=2*x and y<=4*x:
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9200
#include <stdio.h>
 
int main(void) {
	unsigned long long num5=0;
	int in,intmp;
	while(scanf("%d",&in),in) {
		num5=0;
		for(;in>0;in--){
			intmp=in;
			while(!(intmp%5)) {
				intmp/=5;
				num5++;
			}
		}
		printf("%lld\n",num5);
	}
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repi(i, a, b) for (int i = (a); i < int(b); i++)
#define all(a) (a).begin(), (a).end()
#define bit(b) (1ull << (b))

using namespace std;
using i32 = int;
using i64 = long long;
using f64 = double;
using vi32 = vector<i32>;
using vi64 = vector<i64>;
using vf64 = vector<f64>;
using vstr = vector<string>;

template<typename T, typename S> void amax(T &x, S y) { if (x < y) x = y; }
template<typename T, typename S> void amin(T &x, S y) { if (y < x) x = y; }

class UnionFind {
public:
  vector<int> par;
  vector<int> cnt;
  UnionFind(int n) {
    par = vector<int>(n + 1);
    cnt = vector<int>(n + 1, 1);
    for (int i = 1; i <= n; i++) {
      par[i] = i;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    par[x] = y;
    cnt[y] += cnt[x];
  }
  int size(int x) {
    return cnt[root(x)];
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(16);
  i64 n, m;
  cin >> n >> m;
  vector<pair<int, int>> ab;
  rep(i, m) {
    int a, b; 
    cin >> a >> b;
    ab.emplace_back(a, b);
  }
  reverse(all(ab));
  i64 ans = n * (n - 1) / 2;
  vi64 answers;
  answers.push_back(ans);
  auto uf = UnionFind(n);
  rep(i, m) {
    int a = ab[i].first, b = ab[i].second;
    if (uf.same(a, b)) {
      answers.push_back(ans);
    } else {
      ans -= (i64) uf.size(a) * uf.size(b);
      answers.push_back(ans);
      uf.unite(a, b);
    }
  }
  reverse(all(answers));
  reps(i, m) {
    cout << answers[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3828
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<queue>
using namespace std;
typedef long long ll;

const int INF = 1001001001;

int main() {
    int n; cin >> n;
    ll k; cin >> k;
    vector<ll> a(n), f(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    for (int i = 0; i < n; i++) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.begin(), f.end());
    reverse(f.begin(), f.end());

    ll left = -1, right = 1e12;
    while (left + 1 < right) {
        ll mid = (left+right)/2;
        ll cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt += max(0ll, a[i]-mid/f[i]);
        }
        if (cnt <= k) right = mid;
        else left = mid;
    }
    cout << right << endl;
    return 0;
}

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

int main( )
{
	map<int, int>m;
	map<int, int>::iterator pm;
	int size, rect, h, w;
	for(h = 1; h < 151; h++){
		for(w = 1; w < 151; w++){
			if(w > h){
				size = (h * h + w * w ) * 1000 + h;
				rect = h * 1000 + w;
				m.insert(pair<int, int>(size, rect));
			}
		}
	}
	while(1){
		cin >> h;
		cin >> w;
		if (h == 0 && w == 0)
			break;
		size = (h * h + w * w ) * 1000 + h;
		pm = m.find(size);
		pm++;
		rect = pm->second;
		w = rect % 1000;
		h = rect / 1000;
		cout << h << " " << w << endl;
	}

	return 0;
}

Measured memory_bytes: 1716
from collections import Counter
n=int(input())
a=list(map(int,input().split()))
s=[0]*(n+1)
for i in range(n):
    s[i+1] = s[i] + a[i]
c = Counter(s)
n = set(s)
ans = 0
for i in n:
    ans += ((c[i]*(c[i]-1))//2)
print(ans)

Measured memory_bytes: 52372
import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

H, W = map(int,input().split())
#A = [list(map(int,input().split())) for _ in range(H)]
A = np.array([list(input()) for _ in range(H)], 'U1')
eq = A == '.'

dp = np.zeros(W+1, dtype=int)
dp[1] = 1

for i in range(1,H+1):
    prev = dp.copy()
    for j in range(1,W+1):
        if eq[i-1][j-1]:
            dp[j] = prev[j] + dp[j-1]
        else:
            dp[j] = 0
    dp %= mod

print(dp[-1])

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

long long dp[101];

int main() {
    int N; cin >> N;
    vector<int> b(N);
    for (int i = 0; i < N-1; i++) cin >> b[i];
    b[N-1]=100001;

    for (int i = 0; i < 101; i++) dp[i] = 0;
    dp[0] = b[0];

    for (int i = 1; i < N; i++) {
        dp[i]=min(b[i-1],b[i]);
    }
  
    int sum=0;
    for(int i=0;i<N;i++){
      sum +=dp[i];
    }

    cout << sum << endl;
}

Measured memory_bytes: 256
# coding: utf-8
# Here your code !
N = int(input())

for i in range(N):
    a,b,c = map(int, input().split())
    flg = 0
    if a*a + b*b == c*c:
        flg = 1
    if c*c + a*a == b*b:
        flg = 1
    if b*b + c*c == a*a:
        flg = 1
    if flg == 1:
        print('YES')
    else:
        print('NO')

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long  ll; typedef vector<int> VI; typedef pair<int,int> pii;
typedef vector<ll> VL; const int MD = 1e9 + 7;
void dbg(){cerr<<"\n";} template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }


int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);

	int x[5];
	rep(i, 5) cin >>x[i];
	
	rep(i, 5){
		if(x[i]==0){
			cout <<i+1<<"\n"; return 0;
		}
	}
	return 0;
}


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

#include "bits/stdc++.h"
using namespace std;
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define REP(i,n)  FOR(i,0,(n))


class ADiagonalString {
public:
	void solve(std::istream& in, std::ostream& out) {
    vector<vector<char>> c(3, vector<char>(3));
    REP(i,3)REP(j,3){
      in >> c[i][j];
    }
    string s({c[0][0], c[1][1], c[2][2]});
    out << s << endl;
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	ADiagonalString solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3648
n = int(input())
w = list(map(int,input().split()))

r_total = [0]*(n+1)
l_total = [0]

for i in range(n):
  x = l_total[i] + w[i]
  l_total.append(x)
  r_total[n-1-i] = r_total[n-i] + w[n-i-1]
#print(r_total)
#print(l_total)

ans = r_total[0]
for i in range(n+1):
  x = abs(l_total[i] - r_total[i])
  if ans >= x:
    ans = x
print(ans)

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

int main() {
  int64_t n;
  cin >> n;
  int64_t s;
  s=sqrt(n);
  int64_t x,y;
  for(int64_t i=s;i>0;i--){
    if(n%i==0){
      x=i;
      y=n/i;
      break;
    }
  }
  cout << x+y-2 << endl;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

int main() {

    string a, b, c; cin >> a >> b >> c;

    if (a[a.size()-1] == b[0] && b[b.size()-1] == c[0]) {
        puts("YES");
    } else {
        puts("NO");
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define LEN 100005
#define F -1
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head=1, tail=1, n;

void enqueue(P x){
  
  Q[tail] = x;
  if ((tail + 1) == LEN)
    tail = 0;
  else
    tail++;
}

P dequeue(){
  P x;
  
  x = Q[head];
  if ((head + 1) == LEN)
    head = 0;
  else
    head++;
  return x;
    }


int main(){
  int elaps=0,c=0;
  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);
    tail++;

    
  }
  while(c!=n){
    u=dequeue();
    if(u.t>q){
      elaps+=q;
      u.t=u.t-q;
      enqueue(u);
    }
    else{
      elaps+=u.t;
      printf("%s %d\n",u.name,elaps);
      c++;
    }   
  }

  return 0;
}




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

bool custom1(pair<ll,ll>& a, pair<ll,ll>& b)
{
	return a.first+a.second>b.first+b.second;
}

bool custom2(pair<ll,ll>& a, pair<ll,ll>& b)
{
	return a.first-a.second>b.first-b.second;
}

void solve()
{
	ll n;
	cin>>n;
	vector<pair<ll,ll>> v(n);
	for (int i = 0; i < n; ++i)
	{
		cin>>v[i].first>>v[i].second;
	}
	sort(v.begin(),v.end(),custom1);
	ll ans1 = abs(v[0].first-v[n-1].first) + abs(v[0].second-v[n-1].second);
	sort(v.begin(),v.end(),custom2);
	ll ans2 = abs(v[0].first-v[n-1].first) + abs(v[0].second-v[n-1].second);
	cout<<max(ans1,ans2)<<endl;
}

int main()
{
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		solve();
	}
}

Measured memory_bytes: 6432
a=1/3
while 1:
    z=int(input())
    if z==0:break
    m=0
    zz=z*z*z
    for x in range(1,int(z/pow(2,a))+1):
        xx=x*x*x
        y=int(pow(zz-xx,a))
        yy=y*y*y
        m=max(m,yy+xx)
    print(zz-m)

Measured memory_bytes: 7620
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
typedef long long ll;

std::vector<std::pair<ll,ll> > p;
ll a,b,c,d,px,py,pz;
const int Mod=1000000007;

inline bool Cmp(const std::pair<ll,ll> &a,const std::pair<ll,ll> &b){return a.first*b.second<a.second*b.first;}

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0),std::cout.tie(0);
    std::cin>>a>>b>>c>>d;
    for(int i=0;i<=d;++i)
    {
        if(i<a)p.push_back(std::make_pair(i,a)),p.push_back(std::make_pair(a-i-1,a));
        if(i<b)p.push_back(std::make_pair(i,b)),p.push_back(std::make_pair(b-i-1,b));
        if(i<c)p.push_back(std::make_pair(i,c)),p.push_back(std::make_pair(c-i-1,c));
    }
    std::sort(p.begin(),p.end(),Cmp);
    ll Ans=(std::min(a-1,d)+1)*(std::min(b-1,d)+1)*(std::min(c-1,d)+1);
    for(int i=1;i<(int)p.size();++i)
    {
        ll nx=a*p[i].first/p[i].second;
        ll ny=b*p[i].first/p[i].second;
        ll nz=c*p[i].first/p[i].second;
        ll dx=std::min(a-1,px+d)-std::max(0ll,px-d)+1;
        ll dy=std::min(b-1,py+d)-std::max(0ll,py-d)+1;
        ll dz=std::min(c-1,pz+d)-std::max(0ll,pz-d)+1;
        if(nx+d<a)Ans+=(nx-px)*dy%Mod*dz%Mod;
        if(ny+d<b)Ans+=(ny-py)*dz%Mod*dx%Mod;
        if(nz+d<c)Ans+=(nz-pz)*dx%Mod*dy%Mod;
        px=nx,py=ny,pz=nz;
    }
    std::cout<<Ans%Mod<<std::endl;
    return 0;
}

Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<pair<int, int>> A;
    if (N == 1) goto END;
    for (int j = 0; j+1 < N; j += 2) A.emplace_back(1, j);
    for (int j = 1; j+1 < N; j += 3) {
        for (int i = 2 + (j % 2 == 0); i < N; i += 2) {
            A.emplace_back(i, j);
        }
    }
    for (int i = 0 + ((N-1) % 2 == 0); i < N; i += 2) {
        A.emplace_back(i, N-1);
    }
END:
    cout << A.size() << '\n';
    for (auto &a : A) cout << a.first << ' ' << a.second << '\n';
    return 0;
}

Measured memory_bytes: 2928
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define pi 3.14159
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define tc int t; cin >> t; while(t--)

using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}

void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n,k;
  cin>>n>>k;
  if(n%k==0) cout<<0<<endl;
  else cout<<1<<endl;
}
int main(){
    optimizeIO();
    // tc
    { solve();
    }
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,s,e) for (int i=s;i<e;i++)
#define FOE(i,s,e) for (int i=s;i<=e;i++)
#define FOD(i,s,e) for (int i=s;i>=e;i--)
#define SET(a,e) memset(a,e,sizeof(a))
#define LL long long
#define LD long double
#define pb push_back
#define x first
#define y second
#define PII pair<int,int>
#define PLI pair<LL,int>
#define PIL pair<int,LL>
#define PLL pair<LL,LL>
#define PDD pair<LD,LD>
#define eps 1e-9
#define HH1 402653189
#define HH2 1610612741

int n, m, k;

int main() {
	
	scanf("%d%d%d", &n, &m, &k);
	
	FOE(i, 0, n) FOE(j, 0, m) if (i * m + j * n - 2 * i * j == k) return 0 * printf("Yes\n");
	
	printf("No\n");
	
	return 0;
}

Measured memory_bytes: 256
import           Control.Monad
import qualified Data.ByteString.Char8 as BS
import           Data.Maybe

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
  x <- getInt
  let n = x `div` 11
      r = x `mod` 11
      ans | r == 0    = n * 2
          | r <= 6    = n * 2 + 1
          | otherwise = n * 2 + 2
  print ans

Measured memory_bytes: 380
# 2019-11-10 17:11:42(JST)
import sys
# import collections
# import math
# from string import ascii_lowercase, ascii_uppercase, digits
# from bisect import bisect_left as bi_l, bisect_right as bi_r
# import itertools
# from functools import reduce
# import operator as op
# from scipy.misc import comb # float
# import numpy as np 

def main():
    n = list(sys.stdin.readline().rstrip())
    for i in range(len(n)):
        if n[i] == '9':
            n[i] = '1'
        else:
            n[i] ='9'

    
    print(''.join(n))

if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
using System;
using System.Text;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
class Problem
{
    static void Main()
    {
        //--------------------------------input--------------------------------//

        int n = Convert.ToInt32( Console.ReadLine() );
        var a = Array.ConvertAll( Console.ReadLine().Split(), Convert.ToInt32 );

        //--------------------------------solve--------------------------------//

        var L = new int[n];
        var R = new int[n];
        L[0] = a[0];
        R[n - 1] = a[n - 1];
        for(int i = 1 ; i < n ; i++)
            L[i] = GCD( L[i - 1], a[i] );
        for(int i = n - 2 ; i >= 0 ; i--)
            R[i] = GCD( R[i + 1], a[i] );
        int max = Math.Max( L[n - 2], R[1] );
        for(int i = 1 ; i < n-1 ; i++)
            max=Math.Max(max,GCD(L[i-1],R[i+1]));
        Console.WriteLine( max );

    }

    private static int GCD(int a, int b)
    {
        while(a * b != 0)
        {
            if(a > b)
                a %= b;
            else
                b %= a;
        }
        return a + b;
    }




}

Measured memory_bytes: 23900
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define ll long long
#define F first
#define S second
#define pb push_back
#define endl '\n'
#define all(v) (v).begin(),(v).end()

using namespace std;

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int l, r;
    cin >> l >> r;
    if (r - l + 1 >= 2019) {
        cout << 0 << endl;
    } else {
        int res = 2019;
        for (int i = l; i <= r; i++) {
            for (int j = i + 1; j <= r; j++) {
                res = min(res, (int)(1LL * i * j % 2019));
            }
        }
        cout << res << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long n,m;
  cin >> n >> m;
  long ans=0;
  if(n == 1 && m == 1){
    ans = 1;
  }else if(n == 1 || m == 1){
    ans = n * m -2;
  }else{
    ans = (n-2) * (m-2);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG //GCC環境での[]デバッグ
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
int main(void){
    // Your code here!
    int H, W;
    cin >> H >> W;
    std::vector<std::vector<char>> mass(H,std::vector<char>(W));
    rep(i, H){
        rep(j, W){
            cin >> mass[i][j];
        }
    }
    
    //横が一致
    int cnt = 0;
    std::vector<int> yoko(W+H, -1);
    rep(i, H){
        rep(j, W){
            if(mass[i][j] == '.')cnt++;
        }   
       // cout << cnt <<  endl;
        if(cnt == W ) {
            yoko[i] = i;
          //  cout << yoko[i];
        }
        cnt = 0;
    }    
    
    //縦が一致
    cnt = 0;
    std::vector<int> tate(W+H, -1);
    rep(j, W){
        rep(i, H){
            if(mass[i][j] == '.')cnt++;
        }   
       // cout << cnt <<  endl;
        if(cnt == H ) {
            tate[j] = j;
          //  cout << tate[j];
        }
        cnt = 0;
    }    
    
    int flag1 = 0, flag2 = 0;
    rep(i, H){
        rep(k,yoko.size()){
            if(i == yoko[k]){
                flag1 = 1;
                break;
            }
        } 
        if(flag1 == 1) {
            flag1 =0;
            continue;
        }
        rep(j, W){
            rep(k,tate.size()){
                if(j == tate[k]){
                    flag2 = 1;
                    break;
                }
            } 
            if(flag2 == 1) {
                flag2 =0;
                continue;
            }            
            
            cout << mass[i][j]  ;
            
            
        }
    cout << endl;
    }
    
    
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>

using namespace std;


int main()
{
	string str,str2[200000],strmemo="";
	long long int n, m, a[20], b[20] = {}, c, d, e, f, now[200][200] = {}, x[200006], y[200006], X = 0, Y = 0;
	const long long int mod = 1000000007;
	
	for (int i = 1; i<= 6; i++) {
		cin >> a[i];
		b[a[i]]++;
	}
	sort(b + 1, b + 5);
	if (b[4] == 3) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
	
}


Measured memory_bytes: 1792
#include <stdio.h>
#include <math.h>

int isPrime(int x);

main(){

  int N;
  int i,j,a;
  int count = 0;

  scanf("%d",&N);

  for (i=0;i<N;i++){
    scanf("%d",&a);
    count += isPrime(a);
  }

  printf("%d\n",count);

}

int isPrime(int x){

  int i;
  int limit = sqrt(x) + 1;

  if(x>2 && x%2==0){
    return 0;
  }

  for (i=3;i<limit;i+=2){
    if(x%i==0){
      return 0;
    }
  }
  return 1;

}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <stdlib.h>
#include <cstdint>
using namespace std;

#define N 100000

int a[N];
int n, k;

int main()
{
	int ans = 1;

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

	int kremain = n - k;
	ans = kremain / (k -1);
	if( kremain % (k -1) ) {
		ans++;
	}

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


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;

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

int main(){
    int h, w;
    cin >> h >> w;
    char field[60][60];
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            cin >> field[i][j];
        }
    }

    bool ans = true;
    for (int i = 0; i < h; i++){
        for (int j = 0; j < w; j++){
            if (field[i][j] == '.') continue;
            bool found = false;
            for (int k = 0; k < 4; k++){
                int nx = i + dx[k], ny = j + dy[k];
                if (0 <= nx && nx < h && 0 <= ny && ny < w && field[nx][ny] == '#'){
                    found = true;
                }
            }
            if (!found){
                ans = false;
                break;
            }
        }
    }

    cout << (ans?"Yes":"No") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 2*asin(1.0)
#define MAX 10000000
#define MOD 1000000007
 
 
vector<long> fac(MAX);
vector<long> finv(MAX);
vector<long> inv(MAX);
 
//template functions
/////////////////////////
void Cominit(){
  fac.at(0)=fac.at(1)=1;
  finv.at(0)=finv.at(1)=1;
  inv.at(1)=1;
  for(long i=2;i<MAX;i++){
      fac.at(i)=(fac.at(i-1)*i)%MOD;
      inv.at(i)=MOD-inv.at(MOD%i)*(MOD/i)%MOD;
      finv.at(i)=finv.at(i-1)*inv.at(i)%MOD;
  }
}
 
long facComb(long N,long M){// nCm%
if(N<M) return 0;
if(N<0||M<0) return 0;
return fac.at(N)*(finv.at(M)*finv.at(N-M)%MOD)%MOD;
}
 
long Comb(long N,long M){// nCm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
for(long i=M;i>0;i--){
    ans=ans/i;
}
return ans;
}
 
long Perm(long N,long M){// nPm
long ans=1;
for(long i=N;i>N-M;i--){
    ans=ans*i;
}
return ans;
}
 
long GCM(long A,long B){
            long W,r;
    if(A<B){
 
        W=B;
        B=A;
        A=W;
    }
    while(A%B!=0){
        r=A%B;
        A=B;
        B=r;
    }
    return B;
}
long LCM(long A,long B){
    return (A*B)/GCM(A,B);
}
 
long upDiv(long a,long b){
  return (a+b-1)/b;
}
 
/////////////////////////
 
 
 
//Answer
 
 
int main() {
 
typedef pair<long,long> P;
deque<P> que;
 
long H,W,Ch,Cw,Dh,Dw;
cin>>H>>W;
cin>>Ch>>Cw;
cin>>Dh>>Dw;
Ch=Ch-1;
Cw=Cw-1;
Dh=Dh-1;
Dw=Dw-1;
vector<vector<char>> S(H,vector<char>(W));
vector<vector<long>> X(H,vector<long>(W,1000000));
vector<long> dx;
vector<long> dy;
dx={0,1,0,-1};
dy={1,0,-1,0};
vector<long> dxx;
vector<long> dyy;
dxx={2,2,2, 2, 2,1,1, 1, 1,0, 0,-1,-1,-1,-1,-2,-2,-2,-2,-2};
dyy={2,1,0,-1,-2,2,1,-1,-2,2,-2, 2, 1,-1,-2, 2, 1, 0, -1,-2};
for(long i=0;i<H;i++){
    for(long j=0;j<W;j++){
        cin>>S.at(i).at(j);
    }
}
P p=make_pair(Ch,Cw);
que.push_back(p);
X.at(Ch).at(Cw)=0;
while(que.size()!=0){
    P pp=que.front();
    que.pop_front();
    if(pp.first==Dh&&pp.second==Dw){
        continue;
    }
    for(int i=0;i<4;i++){
        long nx=pp.first+dx.at(i);
        long ny=pp.second+dy.at(i);
        if(0<=nx&&nx<=H-1&&0<=ny&&ny<=W-1&&S.at(nx).at(ny)!='#'){
            if(X.at(nx).at(ny)>X.at(pp.first).at(pp.second)){
                X.at(nx).at(ny)=X.at(pp.first).at(pp.second);
                P np=make_pair(nx,ny);
                que.push_front(np);
            }
        }
    }
    for(long i=0;i<20;i++){
            long nx=pp.first+dxx.at(i);
            long ny=pp.second+dyy.at(i);
            if(0<=nx&&nx<=H-1&&0<=ny&&ny<=W-1&&S.at(nx).at(ny)!='#'){
            	if(X.at(nx).at(ny)>X.at(pp.first).at(pp.second)+1){
                  	X.at(nx).at(ny)=X.at(pp.first).at(pp.second)+1;
               	 	P np=make_pair(nx,ny);
                	que.push_back(np);
            		}
        	}
        
        }
}
  /*
for(long i=0;i<H;i++){
    for(long j=0;j<W;j++){
        cout<<X.at(i).at(j)<<endl;
    }
}
*/
if(X.at(Dh).at(Dw)==1000000){
  X.at(Dh).at(Dw)=-1;
}
cout<<X.at(Dh).at(Dw)<<endl;
 
 
 
 
}


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

// using mint = modint1000000007;
// using mint = modint998244353;

typedef int64_t Int;
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << '\n'; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) std::cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << '\n';
}

void solve() {
    Int n, x, m;
    cin >> n >> x >> m;
    Int cur = x;
    Int cycle_start = 0;
    map<Int, Int> mp;
    for (Int i = 0; i < m + 1; i++) {
        if (mp[cur] >= 2) {
            cycle_start = cur;
            break;
        }
        cur = cur * cur % m;
        mp[cur]++;
    }
    Int res = 0;
    cur = x;
    for (Int i = 0; i < m + 1; i++) {
        if (mp[cur] >= 2) {
            break;
        }
        res = (res + cur);
        cur = cur * cur % m;
        n--;
        if (n == 0) {
            print(res);
            return;
        }
    }
    Int cnt = 1;
    Int sum = cycle_start;
    cur = cur * cur % m;
    while (mp[cur] == 1) {
        sum = (sum + cur);
        cur = cur * cur % m;
        cnt++;
    }
    //print(sum);
    Int add = sum * (n / cnt);
    // print(n, cnt, n % cnt);
    res = (res + add);
    cur = cycle_start;
    n %= cnt;
    for (Int i = 0; i < n; i++) {
        res = (res + cur);
        cur = cur * cur % m;
    }
    print(res);
}

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


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

using namespace std;

const int p = 2019;


int main() {

	int m = 2019;

	int L,R;
	cin >> L >> R;

	if (R - L >= 2019) {
		cout << 0 << endl;
		return 0;
	}

	for (int i = L; i < R ; i++) {
		for (int j = i + 1; j <= R; j++) {

			m = min(m, (i % 2019) * (j % 2019) % 2019);

		}
	}

	cout << m << endl;


}

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

int main() {
    int N;
    cin >> N;
    
    vector<string> blue(N);
    for (int i = 0; i < N; i++){
        string s;
        cin >> s;
        blue.at(i) = s;
    }
    
    int M;
    cin >> M;
    
    vector<string> red(M);
    for (int i = 0; i < M; i++){
        string s;
        cin >> s;
        red.at(i) = s;
    }
    
    int ans = 0;
    int btimes = 0;
    int rtimes = 0;
    
    for (int i = 0; i < N+M; i++){
        btimes = 0;
        rtimes = 0;
        
        for (int j = 0; j < N+M; j++){
            
            if (i < N && j < N){
              if (blue.at(i) == blue.at(j)){
                btimes++;
              }
            }
                
            if (i < N && N-1 < j){
              if (blue.at(i) == red.at(j-N)){
                rtimes++;
              }  
            }
                
            if (N-1 < i && j < N){
              if (red.at(i-N) == blue.at(j)){
                btimes++;
              }  
            }
              
            if (N-1 < i && N-1 < j){
              if (red.at(i-N) == red.at(j-N)){
                rtimes++;
              }
            }
        }
        
        if (ans < btimes - rtimes){
          ans = btimes - rtimes;
        }
        
    }
    
    if (ans > -1){
      cout << ans << endl;
    }
      
    else {
      cout << 0 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  vector<int> t(n);
  int sum=0;
  for(int i =0;i<n;i++){
    cin >> t.at(i);
    sum +=t.at(i);
  }
  int m;
  cin >> m;
  vector<int>ans(m);
  for(int i=0;i<m;i++){
    int p,x;
    cin >> p >> x;
    ans.at(i) = sum + x -t.at(p-1);
  }
  for(int i :ans){
    cout << i<< endl;
  }
    
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#ifndef err
#define err(...)(void)0
#endif
using namespace std;
using ll = long long;
using ull = decltype(1ull);
template<class T>int size(T&&a) { return a.size(); }
#define REP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.first,_l##t=a.second;t<_l##t;t++)
#define RREP(t,a)for(typename make_signed<decltype(a.second)>::type t=a.second-1,_l##t=a.first;t>=_l##t;t--)
template<class B>pair<int, B>make_pair(B b) { return{ 0,b }; }
#define rep(t,...)REP(t,make_pair(__VA_ARGS__))
#define rrep(t,...)RREP(t,make_pair(__VA_ARGS__))
#define all(a)begin(a),end(a)
#define rall(a)a.rbegin(),a.rend()
#define var(t, ...) t __VA_ARGS__;in,__VA_ARGS__;

void Calc();
int main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);
  cin.exceptions(istream::failbit | istream::badbit);
  cout << fixed << setprecision(15); Calc(); cout.flush(); return 0;
}
template<class A>void amax(A&a, A b) { a = max(a, b); }
template<class A>void amin(A&a, A b) { a = min(a, b); }
template<class A>int comp(A a, A b) { return a < b ? 1 : b < a ? -1 : 0; }
struct Scanner {
  template<class A = string>A Next() { A a; cin >> a; return a; }
  template<class A = int>vector<A>Array(int n) { vector<A>a(n); for (A&i : a) cin >> i; return a; }
  string Line() const { string s; getline(cin, s); return s; }
  template<class A>Scanner&operator,(A&a) { a = Next<A>(); return *this; }
  template<class A>operator A() { return Next<A>(); }
}in;

/*---------------------------------------------------------------------*/


void Calc() {
  int n = in;
  auto a = in.Array(n);
  int cnt = 1;
  for (auto& i : a) {
    cnt *= (i & 1) ? 1 : 2;
  }
  ll ans = 1;
  rep(i, n) {
    ans *= 3;
  }
  err(cnt, ans - cnt);
  cout << (ans - cnt) << endl;
}


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



int main() {
    int x, y;
    cin >> x >> y;
    
    bool tf = false;
    for(int i = 0; i <= x; i++) {
        if(i * 4 + (x - i) * 2 == y) {
            tf = true;
            break;
        }
    }
    
    if(tf)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    
    return 0;
}


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

int main() {
	char a,b,c,d,e,r;
	cin >> a >> b >> c >> d >> e >> r;
	if (c == d && b == e && a == r) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
}

Measured memory_bytes: 256
n,m =map(int,input().split())
cake = []
for i in range(n):
    cake.append(list(map(int,input().split())))
ans=[]
for i in range(8):
    a = []
    if i ==0:
        for j in range(n):
            a.append(cake[j][0]+cake[j][1]+cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
    elif i ==1:
        for j in range(n):
            a.append(cake[j][0]+cake[j][1]-cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
    elif i ==2:
        for j in range(n):
            a.append(cake[j][0]-cake[j][1]+cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
    elif i ==3:
        for j in range(n):
            a.append(cake[j][0]-cake[j][1]-cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
    elif i ==4:
        for j in range(n):
            a.append(-cake[j][0]+cake[j][1]+cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
    elif i ==5:
        for j in range(n):
            a.append(-cake[j][0]+cake[j][1]-cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
    elif i ==6:
        for j in range(n):
            a.append(-cake[j][0]-cake[j][1]+cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
    else:
        for j in range(n):
            a.append(-cake[j][0]-cake[j][1]-cake[j][2])
        a.sort(reverse=True)
        ans.append(sum(a[:m]))
print(max(ans))

Measured memory_bytes: 3316
# import numpy as np
# A=np.zeros((3,3))
# A[0][:]=[int(i) for i in input().split()]
# A[1][:]=[int(i) for i in input().split()]
# A[2][:]=[int(i) for i in input().split()]
# N=int(input())
# B=np.zeros((N,1))
# B[:][0]=[int(i) for i in input().splitlines()]
# print(B)

# # A=[]
# # for i in range(3)

A=[]
answer=[[0,0,0],[0,0,0],[0,0,0]]
for i in range(3):
    A.append(list(map(int,input().split())))
N=int(input())
B=[int(input()) for i in range(N)]
for j in range(N):
    for k in range(3):
        for l in range(3):
            if B[j]==A[k][l]:
                answer[k][l]=1
i=0
J=0
for i in range(3):
    if answer[i][0]==answer[i][1]==answer[i][2]==1:
        print("Yes")
        J=J+1
        break
    elif answer[0][i]==answer[1][i]==answer[2][i]==1:
        J=J+1
        print("Yes")
        break
if J==0 and answer[0][0] == answer[1][1] == answer[2][2] == 1:
    J=J+1
    print("Yes")
if J == 0 and answer[0][2] == answer[1][1] == answer[2][0]== 1:
    J=J+1
    print("Yes")
if J == 0:
    print("No")

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>

#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long int
#define mod 1000000007
#define inf 1e18+42
#define endl "\n"
#define pi 3.1415926535897932384626433832795028841971693993751058
#define maxn 100005

#define out1(a) cout<<#a<<" "<<a<<endl
#define out2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define out3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl

#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define fori(it,A) for(auto it=A.begin();it!=A.end();it++)

#define ft first
#define sd second
#define pb push_back
#define mp make_pair
#define pq priority_queue
#define all(x) (x).begin(),(x).end()
#define zero(x) memset(x,0,sizeof(x));
 
using namespace std;

int binpow(int a, int b) {
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}

//START OF CODE ->->->->->->->

void solve()
{
    int n;
    cin>>n;

    vector<int> a(n);

    rep(i,0,a.size())
    {
        cin>>a[i];
    }

    vector<int> mx;
    mx.pb(a[0]);
    rep(i,1,a.size())
    {
        mx.pb(max(mx[i-1],a[i]));
    }

    vector<int> dif;
    int f = 0;
    rep(i,0,a.size())
    {
        dif.pb(mx[i]-a[i]);
        if ( dif[i] != 1 && dif[i] != 0 )
        {
            f = 1;
            break;
        }
    }

    if ( f == 1 )
    {
        cout<<"No"<<endl;
    }
    else
    {
        cout<<"Yes"<<endl;
    }
    
    
}

//END OF CODE ->->->->->->->->

signed main()
{
    fast;
    int t = 1;
    // cin>>t;

    while(t--)
    {
        solve();
    }
    return 0;
}



Measured memory_bytes: 3316
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
read = sys.stdin.read

#n,m = [int(i) for i in readline().split()]
#d = [int(i) for i in readline().split()]
MOD = 10**9+7

n = int(input())
a = [int(i) for i in readline().split()]

from fractions import gcd

def lcm(a,b):
    return a//gcd(a,b)*b

b = a[:]
N = len(bin(n))-1
for i in range(N):
    d = 1<<i
    for k in range(d,n,2*d):
        a[k-d] = lcm(a[k],a[k-d])
m = a[0]

ans = 0
for i in b:
    ans += m//i

print(ans%MOD)




Measured memory_bytes: 6192
isprime :: Int -> Bool
isprime 1 = False
isprime 2 = True
isprime n = not $ or (map ((0==).(mod n)) [2..ceil])
    where ceil = ceiling (sqrt (fromIntegral n))

getNLines :: Int -> IO [String]
getNLines n = do
    ans <- sequence $ take n (repeat getLine)
    return ans

main = do
    n <- getLine >>= return . read
    numbers <- getNLines n
    let integers = map read numbers
    print $ foldl (\acc x -> if isprime x then acc+1 else acc) 0 integers 




Measured memory_bytes: 9260