akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

namespace {
  ll read() {
    ll x;
    cin >> x;
    return x;
  }

  string reads() {
    string s;
    cin >> s;
    return s;
  }

  template<class T>
  void write(T x) {
    cout << x << ' ';
  }

  void newline() {
    cout << '\n';
  }
}

struct mincostflow {
  struct edge {
    int v;
    long long c;
    long long w;
    int r;
  };

  vector<vector<edge>> G;

  mincostflow(int n) : G(n) {}

  void add(int u, int v, long long c, long long w) {
    int i = G[u].size();
    int j = G[v].size();
    G[u].push_back({v, c, w, j});
    G[v].push_back({u, 0, -w, i});
  }

  long long run(int s, int t, long long f) {
    const int N = G.size();
    long long res = 0;
    vector<long long> H(N);
    vector<long long> D(N);
    const long long INF = 1e18;
    vector<int> PE(N), PV(N);
    while (f > 0) {
      priority_queue<pair<long long, int>> q;
      fill(D.begin(), D.end(), INF);
      D[s] = 0;
      q.emplace(0, s);
      while (!q.empty()) {
        long long d = -q.top().first;
        int u = q.top().second;
        q.pop();
        if (D[u] < d) continue;
        for (int i = 0; i < G[u].size(); i++) {
          edge e = G[u][i];
          if (e.c > 0 && D[e.v] > D[u] + e.w + H[u] - H[e.v]) {
            D[e.v] = D[u] + e.w + H[u] - H[e.v];
            q.emplace(-D[e.v], e.v);
            PV[e.v] = u;
            PE[e.v] = i;
          }
        }
      }
      if (D[t] == INF) return -1;
      for (int i = 0; i < N; i++) H[i] += D[i];
      long long d = f;
      for (int i = t; i != s; i = PV[i]) {
        d = min(d, G[PV[i]][PE[i]].c);
      }
      f -= d;
      res += d * H[t];
      for (int i = t; i != s; i = PV[i]) {
        edge &e = G[PV[i]][PE[i]];
        e.c -= d;
        G[i][e.r].c += d;
      }
    }
    return res;
  }
};

int main() {
  int N = read();
  mincostflow mcf(N * 2 + 6);
  int s = N * 2 + 4;
  int t = N * 2 + 5;
  const ll INF = 1e10;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    ll x = read(), y = read(), c = read();
    sum += c;
    mcf.add(s, i, c, 0);
    mcf.add(i, N * 2 + 0, 1e9, +x + y + INF);
    mcf.add(i, N * 2 + 1, 1e9, +x - y + INF);
    mcf.add(i, N * 2 + 2, 1e9, -x + y + INF);
    mcf.add(i, N * 2 + 3, 1e9, -x - y + INF);
  }
  for (int i = 0; i < N; i++) {
    ll x = read(), y = read(), c = read();
    mcf.add(N + i, t, c, 0);
    mcf.add(N * 2 + 0, N + i, 1e9, -(+x + y) + INF);
    mcf.add(N * 2 + 1, N + i, 1e9, -(+x - y) + INF);
    mcf.add(N * 2 + 2, N + i, 1e9, -(-x + y) + INF);
    mcf.add(N * 2 + 3, N + i, 1e9, -(-x - y) + INF);
  }
  ll ans = -mcf.run(s, t, sum) + INF*sum*2;
  write(ans);
  newline();
}

struct init {
  init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} init_;




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

int main(){
  string s,t;
  std::cin >> s >>t;

  int ans=0;
  rep(i,s.size()){
    if(s[i]!=t[i])ans++;
  }
  std::cout << ans << '\n';



  return 0;
}


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

using namespace std;

int main(){
	vector <int> w1,w2,e1,e2;
	int n;
	cin >> n;
	w1.resize(n);
	w2.resize(n);
	e2.resize(n);
	e1.resize(n);
	string s;
	cin >> s;
	int w = 0, e = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'W') w++;
		else e++;
		w1[i] = w;
		e1[i] = e;
	}
	w = 0, e = 0;
	for(int i = n-1; i >= 0; i--){
		if(s[i] == 'W') w++;
		else e++;
		w2[i] = w;
		e2[i] = e;
	}
	int sol = 9000000;
	for(int i = 0; i < n; i++){
		if(s[i] == 'E'){
			sol = min(sol, w1[i] + e2[i] - 1);
		}
		else sol = min(sol, w1[i] + e2[i] - 1);
	}
	cout << sol;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int K, N;
  int a[210000];
  int res=INF;
  cin >> K >> N;

  FOR(i,1, N) cin >> a[i];
  a[0] = a[N];
  FOR(i, 1, N) {
    int d = a[i-1] - a[i];
    if (d <= 0) d+= K;
    res = min(d, res);
  }

  cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
using namespace std;
int power(int i,int j)
{
	int ans=1;
	for (int k=1;k<=j;k++)  ans*=i;
	return ans;
}
int main()
{
	int x,maxv=0;
	cin>>x;
	if (x==1)
	{
		cout<<'1'<<endl;
		return 0;
	}
	for (int i=2;i*i<=x;i++)
	  for (int j=2;j<=10;j++)
		if (power(i,j)<=x&&power(i,j)>maxv)  maxv=power(i,j);
	cout<<maxv<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<map>
#include<utility>
#include<tuple>
#include<algorithm>
#include<cmath>
using namespace std;

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

int main(){
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0] << endl;
  return 0;
}

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

int main(void) {
    u_int a, b, n;
    const int NOT_ASSIGNED = -1;

    std::cin >> a >> b;
    for (; a != 0 && b != 0; std::cin >> a >> b) {
        /*
         * 初期化
         */
        std::vector<std::vector<int>> dp(a);
        for (u_int x = 0; x < a; ++x) {
            if (x == 0) {
                // x = 0 上はそれぞれ1通り
                dp[x].resize(b, 1);
            } else {
                dp[x].resize(b, NOT_ASSIGNED);
            }
            dp[x][0] = 1;  // y = 0 上はそれぞれ1通り
        }
        // 原点
        dp[0][0] = 0;

        /*
         * 行き止まりを反映する
         */
        std::cin >> n;
        for (u_int i = 0, x, y; i < n; ++i) {
            std::cin >> x >> y;
            dp[--x][--y] = 0;  // 行き止まり

            // x = 0 上に行き止まりがあるとき、y 以降は通ることができない
            if (x == 0) {
                auto it = dp[0].begin();
                for (std::advance(it, y + 1); it != dp[0].end(); ++it) {
                    *it = 0;
                }
            }
            // y = 0 上に行き止まりがあるとき、x 以降は通ることができない
            if (y == 0) {
                for (u_int j = x + 1; j < a; ++j) {
                    dp[j][0] = 0;
                }
            }
        }

        /*
         * 経路の計算
         */
        for (u_int x = 1; x < a; ++x) {
            for (u_int y = 1; y < b; ++y) {
                if (dp[x][y] == NOT_ASSIGNED) {
                    dp[x][y] = dp[x][y-1] + dp[x-1][y];
                }
            }
        }

        std::cout << dp[a-1][b-1] << std::endl;
    }

    return 0;
}

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

using namespace std;

int main(){
	int x,n;
	cin>>x>>n;
	vector<int> v(101,0);
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		v[a]=1;
	}
	for(int i=0;;i++){
		if(v[x-i]==0){
			cout<<x-i<<endl;
			return 0;
		}
		else if(x+i>100||v[x+i]==0){
			cout<<x+i<<endl;
			return 0;
		}
	}
}



Measured memory_bytes: 3600
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

template<class T> T gcd(T a, T b){ return ((b == 0) ? a : gcd(b, a % b)); }

bool cmp(pair<ll, ll> a, pair<ll, ll> b){
	return a.fi < b.fi;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	ll n, d, a;
	cin >> n >> d >> a;
	vector<pair<ll, ll>> x(n);
	rep(i, n) cin >> x[i].fi >> x[i].se;
	sort(all(x));
	ll ans = 0;
	vector<ll> sum(n, 0LL);
	rep(i, n){
		ll now = 0;
		if(!i) now = (x[i].se + a - 1) / a;
		else{
			int ind = lb(all(x), mp(x[i].fi - 2 * d, 0), cmp) - x.begin();
			ll nm;
			if(ind == 0) nm = 0;
			else nm = sum[ind - 1] * a;
			ll sm = (a * sum[i - 1]) - nm;
			now = max(0LL, (x[i].se - sm + a - 1) / a);
		}
		if(i) sum[i] = sum[i - 1] + now; //maintain prefix sums
		else sum[i] = now;
		ans += now;
	}
	cout << ans << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 4992
#pragma once
#include <stdio.h>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <sstream>
#include <vector>
#include <math.h>
#include <set>

using namespace std;

long long N,M,K,re,C,CC;
long long A[200001];
bool f;
string S;
set <long long>sll;
vector <long long>vl;
vector <long long>vll;


int main() {
	cin >>N>>K>>M;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
		sll.insert(A[i]);
	}
	re = 200000000000;

	for (auto x : sll) {
		vl.clear();
		vll.clear();
		C = 0;
		CC = 0;

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

			if (A[i] < x) {

				if (C-1 >= K) {
					for (int j = i - C + 1; j < i; j++) {
						vll.push_back(A[j]);
					}
					CC += C - K;
					sort(vll.begin(), vll.end());
					for (int j =0; j < C-K; j++) {
						vl.push_back(vll[j]);
					}
					vll.clear();
				}
				C = 0;
			}
			else if (i==N-1) {

				if (C >= K) {
					for (int j = i - C + 1; j <= i; j++) {
						vll.push_back(A[j]);
					}
					CC += C - K+1;
					sort(vll.begin(), vll.end());
					for (int j = 0; j < C - K+1; j++) {
						vl.push_back(vll[j]);
					}
					vll.clear();
				}
				C = 0;
			}

		}

		if (CC >= M) {
			sort(vl.begin(), vl.end());
			re = min(re, vl[M - 1] - vl[0]);
		}

	}


	cout << re << endl;

	return 0;
}


Measured memory_bytes: 384
a, b = map(int, input().split())

if a <= 0  <= b: #0が含まれている時
    print ('Zero')
    exit()

if 0 < a: #全て正のとき
    print ('Positive')
    exit()

num = min(-1, b) - a + 1
if num % 2 == 0:
    print ('Positive')
else:
    print ('Negative')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int w, a, b;
    cin >> w >> a >> b;
    if(b >= a+w){
        printf("%d\n", b-a-w);
    }
    else if(a >= b+w){
        printf("%d\n", a-b-w);
    }
    else{
        printf("%d\n", 0);
    }
}

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

int main()
{
    int N;
    int A[210];

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

    int count = 0, flag = 0;

    while (1)
    {
        for (int i = 0; i < N; i++)
        {
            if (A[i] % 2 != 0)
            {
                flag = 1;
            }
            A[i] = A[i] / 2;
        }

        if (flag == 1)
            break;

        count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    P = list(map(int, input().split()))

    ans = 1
    min_val = P.pop(0)
    for p in P:
        if p <= min_val:
            ans += 1
            min_val = p

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 24744
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;
using System.Text;
using System.IO;
using static System.Math;
using System.Numerics;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
            Solve();
            //Out.Flush();
            Read();
        }

        static void Solve()
        {
            var S = ReadLine();
            var hst = new HashSet<char>();
            foreach(var s in S)
            {
                if(hst.Contains(s))
                {
                    WriteLine("no");
                    return;
                }
                hst.Add(s);
            }
            WriteLine("yes");
        }


        static long Mod = (long)1e9 + 7;
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<long> Slist() { return ReadLine().Split().Select(long.Parse).ToList(); }
        static public (T1 a, T2 b) Slice<T1, T2>()
        {
            var t = ReadLine().Split();
            return (
            (T1)Convert.ChangeType(t[0], typeof(T1)),
            (T2)Convert.ChangeType(t[1], typeof(T2)));
        }
        static public (T a, T b) Slice2<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)));
        }
        static public (T a, T b, T c) Slice3<T>()
        {
            var t = ReadLine().Split();
            return (
            (T)Convert.ChangeType(t[0], typeof(T)),
            (T)Convert.ChangeType(t[1], typeof(T)),
            (T)Convert.ChangeType(t[2], typeof(T)));
        }
    }
}

Measured memory_bytes: 26204
#include <iostream>
#include <cstdio>
#include <string.h>
#include <cstring>
using namespace std;
int main(void) {
  char s[100];
  int cnt, len;

  while(scanf("%s", s) != EOF) {
    len = strlen(s);
    for(int i = 0 ; i < len ; i++) {
      
      if(s[i] == '@') {
	cnt = s[i+1] - '0';
	for(int j = 0 ; j < cnt ; j++) {
	  cout << s[i+2];
	}
      }
      else if(s[i] != '@' && s[i-2] != '@' && s[i-1] != '@') cout << s[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 0
#!/usr/bin/env python3

import math

a, b, c = map(int, input().split())

# ポイント: 誤差を回避するため、整数で計算する
# sqrt(a) + sqrt(b) < sqrt(c)
# \equiv 2 * sqrt(a * b) < c - a - b
# \equiv 4 * a * b < (c - a - b)^2

if 4 * a * b < (c - a - b) ** 2 and c - a - b > 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 38384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
    cin>>n;
  	int arr[n];
  	double result=0; 
  	int a;
  	for(int i=0;i<n;i++){
    	cin>>a;
      	result+=(double)1/a;
    }
    result = 1/result;
  	cout<<result;
	return 0;
}

Measured memory_bytes: 256
#dpテーブルのみでの解法(順方向)
n,w=map(int,input().split())
a=[]
dp=[]
res=0
for c in range(n):
   a.append(list(map(int,input().split())))
for v in range(n):
    tmp=a[v][0]
    a[v][0]=a[v][1]
    a[v][1]=tmp
b=max(a)[0]
for k in range(n+1):
  dp.append([])
  for l in range(n*b+1):
      if l==0 and k==0:
          dp[k].append(0)
      else:
          dp[k].append(10000000000)
for i in range(n):
   for j in range(b*n+1):
       if j>=a[i][0]:
           dp[i+1][j]=min(dp[i+1][j],dp[i][j-a[i][0]]+a[i][1],dp[i][j])
       else:
           dp[i+1][j]=min(dp[i+1][j],dp[i][j])
for s in range(n*b+1):
    if dp[n][s]<=w:
        res=s
print(res)

Measured memory_bytes: 144972
#include"bits/stdc++.h"
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    set<int> pl, mi;
    rep(i, n){
        int x, y; cin >> x >> y;
        pl.insert(x + y);
        mi.insert(x - y);
    }
    ll ans = max(abs(*pl.begin() - *pl.rbegin()), abs(*mi.begin() - *mi.rbegin()));
    cout << ans << endl;
    return;
}

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

Measured memory_bytes: 22380
def main():
    a, b = map(int, input().split())

    l = []
    for i in range(2, 1001):
        h = 0
        for j in range(1, i):
            h = h + j
        l.append(h)

    for i in range(len(l) - 1):
        if l[i] - a == l[i + 1] - b:
            print(l[i] - a)
            break


def main2():
    a, b = map(int, input().split())
    x = b - a

    s = 0
    for i in range(1, x):
        s = s + i

    print(s - a)


if __name__ == '__main__':
    main2()


Measured memory_bytes: 3064
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		Scanner in = new Scanner(System.in);

		int N = in.nextInt();

		// 偶数の項の数
		int M = 0;

		for(int i = 0; i<N; i++) {
			int a = in.nextInt();
			if(a % 2 == 0) {
				M++;
			}
		}

		int all_paterns_num = (int) Math.pow(3.0, (double) N);
		int all_kisu_num = (int) Math.pow(2.0, (double) M);

		System.out.println(all_paterns_num - all_kisu_num);
	}

}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std ;
 int main()
 {
    int n;
    cin>>n;
    int a[n];int inc[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        inc[i]=1;
    }  
    for(int i=1;i<n;i++)
    {
     if(a[i]<=a[i-1])
     {
        inc[i]=inc[i]+inc[i-1];
     }
    }
    int max=0;

for(int i=0;i<n;i++)
{  // cout<<inc[i]<<' ';
        if(inc[i]>max)
            max=inc[i];
 }
 cout<<max-1<<endl;

}


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

int main()
{
	int a;
	int b;
	int c;
	int d;
	int e;
	int f;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> f;
	d = (a + b + c + f) / 60;
	e = (a + b + c + f) % 60;
	cout << d << endl;
	cout << e << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <iostream>
using namespace std;
int n, k, d[10];
int main(void){
    // Your code here!
    cin >> n >> k;
    for (int i = 0; i < k; i++) cin >> d[i];
    for (int i = n; i < n * 10; i++) {
        int num = i, cou = 0;
        while (num > 0) {
            int t = num % 10;
            for (int j = 0; j < k; j++) {
                if (d[j] == t) cou++;
            }
            num /= 10;
        }
        if (cou == 0) {
            cout << i << endl;
            break;
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


int main() {
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;

	int ans = 0;
	rep(i, n) {
		if (a[i] != b[i] && b[i] != c[i] && c[i] != a[i]) {
			ans += 2;
		}
		else if(a[i] == b[i] && a[i] == c[i]){
			
		}
		else {
			ans += 1;
		}
	}
	cout << ans << endl;
	return 0;
}





Measured memory_bytes: 256
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	a := readInt()
	b := readInt()

	if a+b < 10 {
		println(a + b)
	} else {
		println("error")
	}
}


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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

int main() {
  ll x;
  cin >> x;
  ll r = 0;
  r += x / 500 * 1000;
  x %= 500;
  r += x / 5 * 5;
  x %= 5;
  cout << r << endl;
}


Measured memory_bytes: 3560
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
// #define int ll
using namespace std;
const int INF (1 << 30);
const ll LLINF (1LL << 55LL);
const int MOD = 1000000007;
const int MAX = 510000;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    string s;
    ll k,now = 1,nowr = 1,nowl = 1,ans = 0;
    vll v;
    cin >> s >> k;
    ll n = s.size();
    ll r = n-1,l = 0;
    bool flag = true;
    rep(i,n){
        if(s[i]!= s[0]){
            flag = false;
        }        
    }
    if(flag){
        cout<<n*k/2<<endl;
        return 0;
    }
    if(s[0]==s[n-1]){
        rep(i,n-1){
            if(s[i]==s[i+1]){
                nowl++;
            }
            else{
                l=i+1;
                break;
            }
        }
        for(ll i=n-1;i>0;i--){
            if(s[i]==s[i-1]){
                nowr++;
            }
            else{
                r=i-1;
                break;
            }
        }
    }
    rep2(i,l,r){
        if(s[i]==s[i+1]){
            now++;
        }
        else{
            if(now!=1)v.push_back(now);
            now=1;
        }
    }
    if(now!=1)v.push_back(now);
    for(ll i:v){
        ans+=(i/2*k);
    }
    ans+=nowr/2;
    ans+=nowl/2;
    if(s[0]==s[n-1])ans+=(nowr+nowl)/2*(k-1);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string s; cin >> s;
	if (s == "zyxwvutsrqponmlkjihgfedcba")puts("-1");
	else if (s.size() == 26) {
		for (int i = 25; i >= 0; i--) {
			if (s[i] > s[i - 1]) {
				for (int j = 25; j > i; j--) {
					if (s[j] > s[i - 1]) {
						cout << s.substr(0, i - 1) << s[j] << endl;
						return 0;
					}
				}
				if (i == 1)cout << s[i] << endl;
				else cout << s.substr(0, i - 1) << s[i] << endl;
				return 0;
			}
		}
	}
	else {
		for (char c = 'a'; c <= 'z'; c++) {
			for (int i = 0; i < s.size(); i++) {
				if (c == s[i])goto heaven;
			}
			cout << s << c << endl;
			return 0;
		heaven:;
		}
	}
	return 0;
}

Measured memory_bytes: 888
#include "bits/stdc++.h"
using namespace std;
int main() {
	string S;
	cin >> S;
	if (S.at(0) != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	bool check = false;
	for (int i = 2; i < S.size() - 1; i++) {
		if (S.at(i) == 'C') check = true;
	}
	if (!check) {
		cout << "WA" << endl;
		return 0;
	}
	int num = 0;
	for (int i = 1; i < S.size(); i++) {
		
		if (S.at(i) == 'C' || S.at(i) < 97 || S.at(i) > 122) {
			num++;
		}
		if (num == 2) {
			cout << "WA" << endl;
			return 0;
		}
	}
	cout << "AC" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int n;
    cin>>n;
    vector<int> vec(n);
    for(int i=0;i<n;i++){
        cin>>vec[i];
    }
    for(int i=0;i<n;i++){
        if(i != n-1){cout<<vec[i]<<" ";}
      	else{cout<<vec[i];}
    }
    cout<<endl;
    int v;
    for(int i= 1;i<n;i++){
        v=vec[i];
        int j=i-1;
        while(j>=0&&vec[j]>v){
            vec[j+1]=vec[j];
            j--;
        }
        vec[j+1]=v;
    for(int i=0;i<n;i++){
        if(i != n-1){cout<<vec[i]<<" ";}
      	else{cout<<vec[i];}
        }
    cout<<endl;
    }
}


Measured memory_bytes: 3096
#include <iostream>

using namespace std;

int main()
{
	int N, K, S[101], Bij;
	for(;cin>>N>>K,N&&K;)
	{
		for (int i = 0; i < K; i++) cin>>S[i];

		for (int i = 0; i < N; i++)
		{
			for (int j = 0; j < K; j++)
			{
				cin>>Bij;
				S[j] -= Bij;
			}
		}

		int ok = 1;
		for (int i = 0; i < K; i++)
		{
			if (S[i] < 0)
			{
				ok = 0;
				break;
			}
		}
		cout << (ok ? "Yes" : "No") << endl;
	}
	return 0;
}

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

int main(){
  int N,A;
  cin >> N;
  A=N%10;
  if(A==3){
    cout << "bon" << endl;
  }
  else if(A==0 || A==1 || A==6 || A==8){
    cout << "pon" << endl;
  }
  else{
    cout << "hon" << endl;
  }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
int main(){
    int H,W; cin >> H >> W;
    vector<vector<int>> d(10,vector<int>(10));
    for(int i=0; i<10; i++){
        for(int j=0; j<10; j++){
            int c;
            cin >> c;
            d[i][j]=c;
        }
    }
    vector<vector<int>> A(H,vector<int>(W));
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            cin >> A[i][j];
        }
    }
    for(int k=0; k<10; k++){
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
            }
        }
    }
    int cost=0;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            if(A[i][j]==-1||A[i][j]==1) continue;
            cost+=d[A[i][j]][1];
        }
    }
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#define N 100
#define M 100
int main(void)
{
	int n, m, i, j;
	int A[N][M];
	int b[M];
	int c[N] = {0};
	scanf("%d %d", &n, &m);
	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
		scanf("%d", &A[i][j]);
		}
	}
	for(j=0; j<m; j++){
		scanf("%d", &b[j]);
	}
	for(i=0; i<n; i++){
		for(j=0; j<m; j++){
			c[i] += A[i][j] * b[j];
		}
		printf("%d\n", c[i]);
	}
	return 0;
}

Measured memory_bytes: 636
# n = int(raw_input())
# a = [int(raw_input()) for i in xrange(n)]
a,b,c,d = map(int, raw_input().split())

# print "".join(["a","b"])

# print "Yes" if 3 > 0 else "No"

if abs(a - c) <= d:
    print "Yes"
elif abs(a-b) <= d and abs(b-c) <= d:
    print "Yes"
else:
    print "No"

Measured memory_bytes: 2568
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

int main(){
    vi v;
    rep(i,2){
        int n;
        cin >> n;
        rep(j,n){
            int a,b;
            cin >> a >> b;
            v.pb(a*100+b);
        }
    }
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    rep(i,v.size()){
        printf("%d:%02d%c", v[i]/100, v[i]%100, i+1==(int)v.size() ? 10 : 32);
    }
}

Measured memory_bytes: 1208
import sys
sys.setrecursionlimit(10**6)
input = sys.stdin.readline
mod = 10**9+7
 
fact = [1,1]
finv = [1,1]
inv = [0,1]
 
for i in range(2,2*10**5+5):
    fact.append((fact[-1]*i)%mod)
    inv.append((inv[mod%i]*(mod-mod//i))%mod)
    finv.append((finv[-1]*inv[-1])%mod)
 
def nCr(n,r,mod):
      
    return (fact[n]*finv[r])%mod*finv[n-r]%mod

n = int(input())
e = [[] for i in range(n)]
for i in range(n-1):
    a,b = map(int,input().split())
    e[a-1].append(b-1)
    e[b-1].append(a-1)

numl = [0]*n
resl = [0]*n
def dfs(x,pre):
    num = 0
    res = 1
    for nex in e[x]:
        if nex == pre:
            continue
        dfs(nex,x)
        num += numl[nex]
        res *= nCr(num,numl[nex],mod)*resl[nex]
        res %= mod
    numl[x] = num+1
    resl[x] = res

    return 

dfs(0,-1)

ans = [0]*n
ans[0] = resl[0]
def dfs2(x,pre):
    
    for nex in e[x]:
        if nex == pre:
            continue
        pres = [resl[x], numl[x], resl[nex], numl[nex]]
        resl[x] *= pow(nCr(numl[x]-1,numl[nex],mod)*resl[nex],mod-2,mod)
        resl[x] %= mod
        numl[x] -= numl[nex]
        resl[nex] *=  nCr(numl[x]+numl[nex]-1,numl[x],mod)*resl[x]
        resl[nex] %= mod
        numl[nex] += numl[x]
        ans[nex] = resl[nex]
        dfs2(nex,x)
        resl[x], numl[x], resl[nex], numl[nex] = pres
    return
dfs2(0,-1)
for i in ans:
    print(i)

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

using namespace std;

main(){
    int n;
    scanf("%d",&n);
    vector<int> arr (n);
    int maxi = 0;
    int maxVal = 0;
    int a,b;
    for(int i=0;i<n;++i){
        scanf("%d %d",&a,&b);
        if(a>maxVal) maxi = b, maxVal=a;
        arr[i] = a;
    }
    sort(arr.begin(),arr.end());
    int diff = 0;
    diff += arr[0] - 1;
    for(int i=1;i<arr.size();++i){
        diff += arr[i] - arr[i-1] - 1;
    }
    diff += maxi;
    cout << diff + n << endl;
}

Measured memory_bytes: 640
using System;

    class Program
    {
        static void Main(string[] args)
        {
            int[,] array = new int[4, 13];
            int n;
            int num = 0;
            char cha;

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    array[i, j] = 0;
                }
            }

            string str1 = Console.ReadLine();
            n = int.Parse(str1);

            for (int h = 0; h < n; h++)
            {
                string[] str2 = Console.ReadLine().Split(' ');
                cha = char.Parse(str2[0]);
                num = int.Parse(str2[1]);

                switch (cha)
                {
                    case 'S':
                        array[0, num - 1] = 1;
                        break;
                    case 'H':
                        array[1, num - 1] = 1;
                        break;
                    case 'C':
                        array[2, num - 1] = 1;
                        break;
                    case 'D':
                        array[3, num - 1] = 1;
                        break;
                }
            }

            for (int i = 0; i < 4; i++)
            {
                for (int j = 0; j < 13; j++)
                {
                    if (array[i, j] == 0)
                    {
                        if (i == 0)
                        {
                            Console.WriteLine("S " + (j + 1));
                        }
                        if (i == 1)
                        {
                            Console.WriteLine("H " + (j + 1));
                        }
                        if (i == 2)
                        {
                            Console.WriteLine("C " + (j + 1));
                        }
                        if (i == 3)
                        {
                            Console.WriteLine("D " + (j + 1));
                        }
                    }
                }
            }
        }
    }



Measured memory_bytes: 9160
#include <iostream>
using namespace std;
const int inf = 0x7fffff;
int main()
{
    int n,min = inf,t,cnt;
    cin >> n;
    for(int i = 0;i < n;i++)
    {
        cin >> t;
        cnt = 0;
        while(t % 2 == 0)
        {
            t /= 2;
            cnt++;
        }
        if(min > cnt)
        {
            min = cnt;
        }
    }
    cout << min << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> IP;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

double a(double x1, double y1, double x2, double y2) {
	double a = 0;
	if (y1 == y2) {
		a = 114514;
	}
	else {
		a = -(x1 - x2) / (y1 - y2);
	}
	return a;
}
double b(double x1, double y1, double x2, double y2) {
	double b = 0;
	if (y1 == y2) {
		b = 114514;
	}
	else {
		b = ((x1 - x2) * (x1 + x2) / (y1 - y2) + (y1 + y2)) / 2;
	}
	return b;
}

double cal_X(double a, double b, double c, double d, double e, double f) {
	double Y = (c * d - a * f) / (b * d - a * e);
	double X;
	if (a != 0) {
		X = (c - b * Y) / a;
	}
	else {
		X = (f - e * Y) / d;
	}
	return X;
}

double cal_Y(double a, double b, double c, double d, double e, double f) {
	double Y = (c * d - a * f) / (b * d - a * e);
	double X;
	if (a != 0) {
		X = (c - b * Y) / a;
	}
	else {
		X = (f - e * Y) / d;
	}
	return Y;
}

int main() {
	int N;
	cin >> N;
	rep(i, N) {
		double x1, y1, x2, y2, x3, y3;
		cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3;
		double a1 = a(x3, y3, x2, y2);
		double b1 = b(x3, y3, x2, y2);
		double a2 = a(x1, y1, x2, y2);
		double b2 = b(x1, y1, x2, y2);
		double a3 = a(x1, y1, x3, y3);
		double b3 = b(x1, y1, x3, y3);
		vector<double>V;
		if (a1 != 114514) {
			V.push_back(a1);
		}
		if (b1 != 114514) {
			V.push_back(b1);
		}
		if (a2 != 114514) {
			V.push_back(a2);
		}
		if (b2 != 114514) {
			V.push_back(b2);
		}
		if (a3 != 114514) {
			V.push_back(a3);
		}
		if (b3 != 114514) {
			V.push_back(b3);
		}
		double X = cal_X(V[0] * (-1), 1, V[1], V[2] * (-1), 1, V[3]);
		double Y = cal_Y(V[0] * (-1), 1, V[1], V[2] * (-1), 1, V[3]);
		double R = sqrt(pow(X - x1, 2) + pow(Y - y1, 2));
		cout <<fixed<<setprecision(3)<< X << ' ' << Y <<' '<< R << endl;
	}
}


Measured memory_bytes: 3212
# n = gets.split.map(&:to_i)
# array = readlines.map(&:chomp!).map { |e| e.split.map(&:to_i) }
### SNIPPET
  # array = [*1..q].map { |_| gets.split.map(&:to_i) }
  # n = gets.split.map(&:to_i)
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さh = a * Math.sin(w / 180.0 * Math::PI)
  # 底辺 = a * Math.cos(w / 180.0 * Math::PI)
def chmin(a, b) a < b ? a : b end
  
  
n,w = gets.split.map(&:to_i)
wv = [*1..n].map { |_| gets.split.map(&:to_i) }

dp = Hash.new(Float::INFINITY)
dp[0] = 0
0.upto(n-1) do |k|
  lw,lv = wv[k]
  dp_dup = dp.dup
  dp_dup.each do |key, value|
    next if (lw + value) > w
    dp[lv + key] = chmin(dp[lv + key] , lw + value) 
  end
end

puts dp.keys.max


Measured memory_bytes: 79308
n, m = gets.split.map(&:to_i)
a = n.times.map { gets.chomp }
b = m.times.map { gets.chomp }
ans = 0
(0..(n - m)).each do |i|
  (0..(n - m)).each do |j|
    flag = true
    m.times do |k|
      flag = false if a[i + k][j, m] != b[k]
    end
    ans += 1 if flag
  end
end

puts ans > 0 ? "Yes" : "No"


Measured memory_bytes: 2044
n = input()
a = []
for i in range(n):
    a.append(raw_input().split())
for j in range(1,14):
    if ['S', str(j)] not in a:
        print 'S', str(j)
for j in range(1,14):
    if ['H', str(j)] not in a:
        print 'H', str(j)
for j in range(1,14):
    if ['C', str(j)] not in a:
        print 'C', str(j)
for j in range(1,14):
    if ['D', str(j)] not in a:
        print 'D', str(j)

Measured memory_bytes: 6432
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
const int MOD = 1e9+7;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

bool is_prime(int x){
	for (int i = 2; i*i <= x; i++){
		if (x % i == 0) return false;
	}
	return true;
}


int main(){
	int n;
	cin >> n;
	int coun = 0;
	for (int i = 2; i <= 55555; i++){
		if (is_prime(i)){
			string s = to_string(i);
			if (s[s.length()-1] == '1'){
				cout << i << endl;
				coun++;
			}
			if (coun == n) return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 3680
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
typedef long long ll;
int n, a[maxn];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = i + 1; j <= n; j++) {
            for (int z = j + 1; z <= n; z++) {
                if(a[i] == a[j] || a[i] == a[z] || a[j] == a[z]) continue;
                vector<int> v;
                v.push_back(a[i]);
                v.push_back(a[j]);
                v.push_back(a[z]);
                sort(v.begin(), v.end());
                if(v[0] + v[1] > v[2]) ans++;
            }
        }
    }
    printf("%d\n", ans);
}


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

using namespace std;
#define lint long long



int main() {
    int N;
    cin >> N;
    
    int a[N][3];
    
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 3; ++j){
            cin >> a[i][j];
        }
    }
    
    lint dp[N + 1][3];
    
    for(int i = 0; i < N + 1; ++i){
        for(int j = 0; j < 3; ++j){
            dp[i][j] = 0;
        }
    }
    
    for(int i = 0; i < N; ++i){
        for(int j = 0; j < 3; ++j){
            for(int k = 0; k < 3; ++k){
                if(j == k){
                    continue;
                }
                dp[i + 1][j] = max(dp[i + 1][j], dp[i][k] + a[i][j]);
            }
        }
    }
    
    cout << max(dp[N][0], max(dp[N][1], dp[N][2])) << endl;
}
    


Measured memory_bytes: 3712
/*Lower_Rating*/
/*Dwango Programming Contest 6th B*/
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<vector>
#include<queue>
#include<bitset>
using namespace std;

#define LL long long
#define DB double
#define MOD 1000000007
#define Pr pair<DB,int>
#define X first
#define Y second
#define MAXN 100000
#define INF 20000000000000000LL
#define mem(x,p) memset(x,p,sizeof(x))

LL read(){
  LL x=0,F=1;char c=getchar();
  while(c<'0'||c>'9'){if(c=='-')F=-1;c=getchar();}
  while(c>='0'&&c<='9'){x=(x<<3)+(x<<1)+c-'0';c=getchar();}
  return x*F;
}

int add(int a,int b){return (a+b>=MOD)?a+b-MOD:a+b;}
int dec(int a,int b){return (a-b<0)?a-b+MOD:a-b;}
int mul(int a,int b){return 1LL*a*b%MOD;}
int fst_pow(int a,int b){
    int res=1;
    while(b){
        if(b&1)res=mul(res,a);
        a=mul(a,a);
        b>>=1;
    }return res;
}

int n,x[MAXN+5],v[MAXN+5],ans,p,sum;

int main()
{
    n=read();p=1;
    for(int i=1;i<=n;i++)
        x[i]=read();
    for(int i=1;i<n;i++)
    v[i]=x[i+1]-x[i],p=mul(p,i);
    for(int i=1;i<n;i++){
        sum=add(sum,fst_pow(i,MOD-2));
        ans=add(ans,mul(v[i],sum));
    }
    printf("%d",mul(ans,p));
}


Measured memory_bytes: 1024
// God put a smile upon your face <3

#include <bits/stdc++.h>`

#define slld(longvalue) scanf("%lld", &longvalue)

#define ll long long
#define ull unsigned long long
#define pll pair < long long, long long >

#define fastio ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0)

#define pb push_back

#define bug printf("BUG\n")

#define mxlld LLONG_MAX
#define mnlld -LLONG_MAX

#define mxd 2e8
#define mnd -2e8

#define pi 3.14159265359

using namespace std;

bool check(ll n, ll pos)
{
	return n & (1LL << pos);
}

ll Set(ll n, ll pos)
{
	return n = n | (1LL << pos);
}

int main()
{
    ll i, j, k, l, m, n, o, r, q;
    ll testcase;
    ll input, flag, tag, ans;

//    freopen("input.txt", "r", stdin);

//    freopen("output.txt", "w", stdout);


    while(cin >> n)
    {
		ans = 0;
		for(ll i = 1; i <= n; i++)
		{
			ans = (ans + (i * (n - i + 1)));
		}

		for(ll i = 1; i < n; i++)
		{
			ll u, v;
			slld(u);
			slld(v);

			if(u > v) swap(u,v);

			ans -= u * (n - v + 1);
		}

		printf("%lld\n", ans);
    }


}





Measured memory_bytes: 3812
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}
pub fn read_n<T: FromStr>(n: usize) -> Vec<T> {
    read_n_logic::<T>(n, vec![])
}
pub fn read_n_logic<T: FromStr>(n: usize, mut a: Vec<T>) -> Vec<T> {
    match n {
        0 => a,
        _ => {
            a.push(read::<T>());
            read_n_logic(n - 1, a)
        }
    }
}

use std::cmp::{max, min};

fn main() {
    let a: usize = read();
    let b: String = read();
    let b_char: Vec<char> = b.chars().collect();
    let ascii_uppercase: Vec<_> = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".chars().collect();

    let ans = b_char
        .iter()
        .map(|&c| {
            ascii_uppercase[((0..26).find(|&i| ascii_uppercase[i] == c).unwrap() + a) % 26]
                .to_string()
        })
        .collect::<Vec<_>>()
        .join("");
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <stdio.h>

int main()
{
	int i, N, A[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int j, count[5] = {1, 0, 0, -1, -1};
	long long ans = (A[1] == 0)? 3: 0;
	for (i = 2; i <= N; i++) {
		for (j = 0; j < 3; j++) {
			if (A[i] == count[j]) break;
		}
		if (j == 3) ans = 0;
		else {
			if (j < 2 && count[j+1] == count[j]) {
				if (j == 0 && count[j+2] == count[j]) ans = ans * 3 % 1000000007;
				else ans = ans * 2 % 1000000007;
			}
			count[j]++;
		}
	}
	
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define pb push_back
#define ll long long
#define pii pair<int, int>
#define pll pair<long long, long long>
#define ull unsigned long long
#define mp make_pair
#define F first
#define S second
ll  mod = 998244353;


int main()
{
    int n, k;
    cin >> n >> k;
    vector<pair<int, int> > ranges;

    ll l,r;
    for(int i =0 ;i <k; i++)
    {
        cin >> l >> r; 
        ranges.pb(mp( l,r ));
    }

    vector<ll> dp(2*n+2, 0);
    dp[1] = 1;

    ll sum = 0;
    for(int i = 1; i < n+2; i++)
    {   
        sum = (sum + dp[i]) % mod;

        for(int j = 0; j<k; j++)
        {
            int lind = i + ranges[j].F;
                //if(ranges[j].F != ranges[j].S)
                //{
                    dp[lind] = (dp[lind] + sum)%mod;
                    int rind =  i + ranges[j].S + 1; 
                    dp[rind] = (dp[rind] - sum + mod)%mod;
                //}else
                //{
                  //  dp[lind] +=  dp[i];
                //}
               
        }
    }

    //for(int i = 0 ;i < n+1; i++ )
      //  cout << dp[i] << " ";
    //cout << endl;

    cout << dp[n]%mod << endl;


    
}


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

int main () {
    ios::sync_with_stdio(0);
    cin.tie(0);
  	int a[9];
    
  	for(int i = 0; i<9; i++){
    	cin>>a[i];
    }
    int x;
    while(cin>>x){
      for(int i = 0; i<9; i++){
    	  if(a[i] == x)
          a[i] = -1;
      }
    }

    if((a[0] == -1 && a[3] == -1 && a[6] == -1) ||  (a[0] == -1 && a[4] == -1 && a[8] == -1) || (a[0] == -1 && a[1] == -1 && a[2] == -1) || (a[1] == -1 && a[4] == -1 && a[7] == -1) || (a[2] == -1 && a[5] == -1 && a[8] == -1) || (a[2] == -1 && a[4] == -1 && a[6] == -1)|| (a[3] == -1 && a[4] == -1 && a[5] == -1) || (a[6] == -1 && a[7] == -1 && a[8] == -1))
      cout << "Yes";
    else
      cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;
	while(cin>>n){
		if(n==0){
			break;
		}
		int ans=0;
		for(int i=2;n>=((1+i)*i/2);i++){
			if(i%2==1){
				if(n%i==0){
					ans++;
				}
			}
			else{
				if(n%i==(i/2)){
					ans++;
				}
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,K;
    scanf("%lld",&n);

    const ll MOD = 1e9 + 7;

    vector<vector<int> > a(n, vector<int> (n,0) );
    for(int i =0; i<n; i++)
        for(int j = 0; j<n; j++)
            scanf("%d",&a[i][j]);

    int max_mask = (1<<n);
    vector<ll> dp(max_mask);
    dp[0] = 1;
    for(int mask = 0; mask < max_mask - 1; mask++)
    {
        int i = __builtin_popcount(mask);
        for(int j = 0; j<n; j++)
        {
            if(a[i][j] && !(mask&(1<<j)))
                dp[mask ^ (1<<j)] = (dp[mask^(1<<j )] + dp[mask] )%MOD;
        }
    }
    cout<<dp[max_mask - 1]<<"\n";
    

}

Measured memory_bytes: 16640