akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        if ((a * b) % 2 == 0)
            System.out.println("Even");
        else
            System.out.println("Odd");
        sc.close();
    }
}

Measured memory_bytes: 35540
memo = []
counter = 0
while(True):
    m,f,r = list(map(int,input().split()))
    if m is -1 and r is -1 and f is -1:
        break
    elif m is -1 or f is -1 or m + f < 30:
        memo.append("F")
    elif 30 <= m + f < 50 :
        if r >= 50:
            memo.append("C")
        else:
            memo.append("D")
    elif 50 <= m + f < 65:
        memo.append("C")
    elif 65 <= m + f < 80:
        memo.append("B")
    elif 80 <= m + f:
        memo.append("A")
    counter += 1
for i in range(counter):
    print(memo[i])

Measured memory_bytes: 7648
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C: 
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_M = 100000;

/* typedef */

typedef vector<int> vi;

struct UFT {
  int links[MAX_N], ranks[MAX_N], sizes[MAX_N];

  void clear(int n) {
    for (int i = 0; i < n; i++) links[i] = i, ranks[i] = sizes[i] = 1;
  }
  UFT() {}
  UFT(int n) { clear(n); }

  int root(int i) {
    int i0 = i;
    while (links[i0] != i0) i0 = links[i0];
    return (links[i] = i0);
  }

  int rank(int i) { return ranks[root(i)]; }
  int size(int i) { return sizes[root(i)]; }
  bool same(int i, int j) { return root(i) == root(j); }

  int merge(int i0, int i1) {
    int r0 = root(i0), r1 = root(i1), mr;
    if (r0 == r1) return r0;
    if (ranks[r0] == ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      ranks[r0]++;
      mr = r0;
    }
    else if (ranks[r0] > ranks[r1]) {
      links[r1] = r0;
      sizes[r0] += sizes[r1];
      mr = r0;
    }
    else {
      links[r0] = r1;
      sizes[r1] += sizes[r0];
      mr = r1;
    }
    return mr;
  }
};

/* global variables */

vi ps[MAX_M];
UFT uft;

/* subroutines */

/* main */

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

  for (int i = 0; i < n; i++) {
    int ki;
    cin >> ki;
    for (int j = 0; j < ki; j++) {
      int lj;
      cin >> lj;
      lj--;
      ps[lj].push_back(i);
    }
  }

  uft.clear(n);
  int cnt = 0;

  for (int i = 0; i < m; i++)
    if (! ps[i].empty()) {
      int pi0 = ps[i][0];
      for (int j = 1; j < ps[i].size(); j++) {
	int &pij = ps[i][j];
	if (! uft.same(pi0, pij)) uft.merge(pi0, pij), cnt++;
      }
    }

  //printf("cnt=%d\n", cnt);
  cout << (cnt == n - 1 ? "YES" : "NO") << endl;
  return 0;
}


Measured memory_bytes: 4988
def d_wall(H, W, C, A):
    import scipy.sparse
    # cost[i][j]:数字iからjに移行するための最小コスト(float64で格納される)
    cost = scipy.sparse.csgraph.floyd_warshall(C)

    # 壁の各数字ごとにコストの値を参照、和を取る
    ans = 0
    for h in range(H):
        for w in range(W):
            if A[h][w] != -1:
                ans += cost[A[h][w]][1]  # 壁の数字から1へ変えるための最小コスト
    return int(ans)

H,W = [int(i) for i in input().split()]
C = [[int(i) for i in input().split()] for j in range(10)]
A = [[int(i) for i in input().split()] for j in range(H)]
print(d_wall(H, W, C, A))

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

using namespace std;
#define ll long long
#define ld long double

int main()
{
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n;
    string s, t;
    cin >> n >> s >> t;
    string ans = "";
    for(int i=0;i<n;i++) {
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
n = gets.to_i
a = [0, *gets.split.map(&:to_i), 0] # a[0] = a[n] = 0 とおいてよいはず

costs = Array.new(a.size, 0)
1.upto(a.size - 1) do |i|
  costs[i] = (a[i - 1] - a[i]).abs
end
sum = costs.inject(:+)

(1..n).each do |i|
  d1 = costs[i..i + 1]
  d2 = (a[i + 1] - a[i - 1]).abs

  puts sum - d1.inject(:+) + d2
end


Measured memory_bytes: 13060
#include<cstdio>
#include<cstring>
#include<algorithm>
#define MAXS 262144
#define MO 1000000007
int dp[2][MAXS+5];
using namespace std;
int N,X,Y,Z;
int PowMod(int a,int b)
{
	int ret=1;
	a%=MO;
	while(b)
	{
		if(b&1)
			ret=1LL*ret*a%MO;
		a=1LL*a*a%MO;
		b>>=1;
	}
	return ret;
}
int main()
{
	scanf("%d %d %d %d",&N,&X,&Y,&Z);
	int tot=(1<<(X+Y+Z-1));
	int all=(1<<(X+Y+Z));
	dp[0][0]=1;
	int ans=0;
	for(int i=1;i<=N;i++)
	{
		int id=i%2;
		for(int s1=0;s1<all;s1++)
			for(int k=1;k<=10;k++)
			{
				int s2=((s1<<k)+(1<<(k-1)))%all;
				dp[id][s2]=(1LL*dp[id][s2]+dp[!id][s1])%MO;
			}
		for(int s2=0;s2<all;s2++)
		{
			if((s2&tot)&&((1<<(Y+Z-1))&s2)&&((1<<(Z-1))&s2)&&(dp[id][s2]!=0))
				ans=(1LL*ans+1LL*dp[id][s2]*PowMod(10,N-i)%MO)%MO,dp[id][s2]=0;
		}
		memset(dp[!id],0,sizeof(dp[!id]));
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2176
# -*- coding: utf-8 -*-
"""
Created on Sun Apr 19 21:18:34 2020

@author: arute
"""

# -*- coding: utf-8 -*-

# -*- coding: utf-8 -*-


from sys import stdin
import numpy as np


############################################

# read data for n sequences.
temp = stdin.readline().split()
N = int(temp[0])

count = 3.14*2*N
        
print(count)

Measured memory_bytes: 26980
def main
  gets
  values = gets.chomp.split(' ').map(&:to_i)
  pre = values.pop
  values.reverse.each do |v|
    if v > pre + 1
      puts 'No'
      return
    elsif v > pre
      pre = v - 1
    else
      pre = v
    end
  end
  puts 'Yes'
end

main if $0 == __FILE__

Measured memory_bytes: 10500
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<60;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

int main(){
    string N; cin >> N;
    int n = N.size();

    ll tmp = 0;
    rep(i,n){
        tmp += N[i]-'0';
    }

    if (tmp %  9 == 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;

int main(){
    DRIII(N,A,B);
    if(A>B||(N==1&&A!=B)){
        cout<<0;
        return 0;
    }
    LL x=(N-1LL)*A+B;
    LL y=(N-1LL)*B+A;
    cout<<y-x+1;
    return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def read_ints():
    return list(map(int, read().split()))


def read_a_int():
    return int(read())


def read_tuple(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(tuple(map(int, read().split())))
    return ret


def read_col(H):
    '''
    H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return tuple(map(list, zip(*ret)))


def read_matrix(H):
    '''
    H is number of rows
    '''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, read().split())))
    return ret
    # return [list(map(int, read().split())) for _ in range(H)] # 内包表記はpypyでは遅いため


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from collections import defaultdict, Counter, deque
from operator import itemgetter
from itertools import product, permutations, combinations
from bisect import bisect_left, bisect_right  # , insort_left, insort_right

# https://atcoder.jp/contests/abc042/tasks/arc058_a

# 制約が小さいので愚直に全探索すればいい気もする
N, K = read_ints()
D = set(input())
# print(D)
for n in range(N, N + 10 ** 6):
    n_str = str(n)
    for c in n_str:
        if c in D:
            break
    else:
        print(n)
        exit()
# print(n)


Measured memory_bytes: 40412
/*
 * FileName:     A
 * CreatedDate:  2020-05-30 20:53:32 +0900
 * LastModified: 2020-05-30 21:20:54 +0900
 */

#include <stdio.h>
#include <stdlib.h>
int main(void){
    int h_1,m_1,h_2,m_2,k;
    scanf("%d%d%d%d%d",&h_1,&m_1,&h_2,&m_2,&k);
    if(h_1<=h_2&&m_1<=m_2){
        printf("%d\n",(h_2-h_1)*60+(m_2-m_1)-k);
        return 0;
    }
    else if(h_1<=h_2&&m_1>m_2){
        printf("%d\n",(h_2-h_1-1)*60+(m_2+60-m_1)-k);
        return 0;
    }
    else if(h_1>h_2&&m_1<=m_2){
        printf("%d\n",((h_2+24)-h_1)*60+(m_2-m_1)-k);
        return 0;
    }
    printf("%d\n",((h_2+24)-h_1-1)*60+(m_2+60-m_1)-k);
    return 0;
}


Measured memory_bytes: 1724
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
#include <array>
#include <numeric>
#include <regex>
#include <bitset>
#include <deque>

using namespace std;
typedef long long ll;
typedef pair<int, int> p_ii;

const ll INF = 1e15;
const double PI = acos(-1.0);
const ll MOD = 1e9 + 7;



int main() {
    int N, K, cnt=0;
    cin>>N>>K;
    vector<int> a(N);
    vector<ll> cum(N+1), pcum(N+1);
    for (int i = 0; i < N; i++) {
        cin>>a[i];
    }

    cum[0]=0; pcum[0]=0;
    for (int i = 0; i < N; i++) {
        pcum[i+1]=pcum[i]+a[i];
        cum[i+1]=cum[i]+max(0, a[i]);
    }

    ll res = 0;
    for (int i = 0; i <= N-K; i++) {
        ll t = max(pcum[i+K]-pcum[i], 0LL);
        t+=cum[N]-cum[i+K];
        t+=cum[i]-cum[0];
        res = max(res, t);
    }

    cout<<res<<endl;

    return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b ;

  if (a % 2 == 1 && b % 2 == 1) {
    cout << "Odd" << endl;
  }
  else {
    cout << "Even" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define P pair<int,int>
#define rep(i,n) for(int i=0;i<n;i++)
#define mod 1000000007;
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n;
    cin>>n;
    int a[n];
    rep(i,n){
        cin>>a[i];
    }
    rep(i,n-1){
        a[i+1]=gcd(a[i],a[i+1]);
    }
    cout<<a[n-1]<<endl;
}


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

using namespace std;

int dp[101][101][5],w,h;

int func(int i, int j, int p){
  if(i>w || j>h)return 0;
  if(i==w && j==h)return 1;
  if(dp[i][j][p]>0)return dp[i][j][p];

  int res=0;
  if(p==1)res=func(i,j+1,3);
  else if(p==2)res=func(i+1,j,4);
  else if(p==3)res=func(i+1,j,2)+func(i,j+1,3); 
  else if(p==4)res=func(i+1,j,4)+func(i,j+1,1);
  else if(p==0)res=func(i,j+1,3)+func(i+1,j,4);

  return dp[i][j][p]=res%100000;
}

int main(void){

  while(cin >> w >> h,w|h){
    for(int i=0;i<101;i++)
      for(int j=0;j<101;j++)
	for(int p=0;p<5;p++)
	dp[i][j][p]=0;

    cout << func(1,1,0) << endl;
  }

  return 0;
}

Measured memory_bytes: 1368
#include <bits/stdc++.h>
using namespace std;
int main(){
  int A,B,C,K;
  cin >> A >> B >> C >> K;
  for (int i = 0; i < K; i++){
    if (A >= B && A >= C){
      A*=2;
    } else if (B >= C){
      B*=2;
    } else {
      C*=2;
    }
  }
  cout << A + B + C;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

void solve() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0;
    rep(i, n) {
        r += s[i] == 'R';
    }
    int cnt = 0;
    rep(i, r) {
        if (s[i] == 'W') cnt++;
    }
    cout << cnt << endl;
}

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

Measured memory_bytes: 3744
#include <stdio.h>

int parent[100005];
int isClear[100005];

void init(void) {
    for (int i = 0; i < 100005; i++) {
        parent[i] = -1;
    }
}

int root(int x) {
    if (parent[x] < 0) {
        return x;
    }

    return parent[x] = root(parent[x]);
}

void unite(int x, int y) {
    x = root(x);
    y = root(y);

    if (x == y) {
        return;
    }

    parent[x] += parent[y];
    parent[y] = x;

    return;
}

int main()
{
    init();
    
    int n, m;
    int x, y;
    int ans = 0;

    scanf("%d %d", &n, &m);
    for (int i = 0; i < m; i++) {
        scanf("%d %d %*d", &x, &y);

        unite(x, y);
    }

    for (int i = 1; i <= n; i++) {
        int r = root(i);

        if (isClear[r] == 0) {
            isClear[r] = 1;
            ans++;
        }
    }

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

    return 0;
}


Measured memory_bytes: 896
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextInt()
    val w = sc.nextInt()
    val a = (0 until h).map { sc.next().toCharArray() }
    println(problem002a(h, w, a))
}

fun problem002a(h: Int, w: Int, a: List<CharArray>): String {
    for (i in 0 until h) {
        for (j in 0 until w) {
            if (a[i][j] != '#') continue
            if (i == h - 1 && j == w - 1) continue

            val top = if (i == 0) '.' else a[i - 1][j]
            val bottom = if (i == h - 1) '.' else a[i + 1][j]
            val left = if (j == 0) '.' else a[i][j - 1]
            val right = if (j == w - 1) '.' else a[i][j + 1]
            if (right == '#' && bottom == '#') {
                return "Impossible"
            }
            if (i == 0 && j == 0) continue
            if (listOf(top, bottom, left, right).count { it == '#' } != 2) {
                return "Impossible"
            }
        }
    }
    return "Possible"
}

Measured memory_bytes: 34028
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long double ld;
int main()
{
  int n;
  cin >> n;
  vector<int> x(n), y(n), h(n);
  int x0,y0,h0=0;
  REP(i,n){
    cin >> x[i] >> y[i] >> h[i];
    if(h0==0 && h[i]>0) x0=x[i], y0=y[i], h0=h[i];
  }
  REP(cx,101){
    REP(cy,101){
      bool flg = true;
      int h_ans = h0+abs(cx-x0)+abs(cy-y0);
      if(h_ans<=0) continue;
      REP(i,n){
        if(max(h_ans-abs(cx-x[i])-abs(cy-y[i]), 0) != h[i]){
          flg = false;
          break;
        }
      }
      if(flg){
        cout << cx << " " << cy << " " << h_ans << '\n';
        return 0;
      }
    }
  }
  return 0;
}

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

int64_t luca(int N, vector<int64_t> &memo)
{
	if (N == 0) {
		return 2;
	}
	if (N == 1) {
		return 1;
	}
	int64_t tmp1;
	int64_t tmp2;
	if (memo.at(N - 1) != 0) {
		tmp1 = memo.at(N - 1);
	} else {
		memo.at(N - 1) = luca(N - 1, memo);
		tmp1 = memo.at(N - 1);
	}
	if (memo.at(N - 2) != 0) {
		tmp2 = memo.at(N - 2);
	} else {
		memo.at(N - 2) = luca(N - 2, memo);
		tmp2 = memo.at(N - 2);
	}
	return tmp1 + tmp2;
}

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

	vector <int64_t> memo(N, 0);

    cout << luca(N, memo) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <set>
using namespace std;
int main()
{
    int l,r,n;
    set<int>s;
    set<int>::iterator ii;
    cin >> l >> r >> n;
//    for(int i=l;i<=r;i++)
//    {
//            memset(vis,0,sizeof(vis));
        for(int j=0;j<n&&l+j<=r;j++)
        {
//            cout << l+j<< endl;
            s.insert(l+j);
        }
        for(int j=n-1;j>=0&&r-j>=l;j--)
        {
           s.insert(r-j);
        }

         for(ii=s.begin();ii!=s.end();ii++)
            cout<<(*ii)<<endl;
//    }
    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> v(20,0);
  vector<int> c(20,0);
  vector<int> b(20,0);
  for(int i=0; i<n; i++){
    cin >> v[i];
  }
  for(int i=0; i<n; i++){
    cin >> c[i];
  }
  for(int i=0; i<n; i++){
    b[i] = v[i]-c[i];
  }
  int ans=0;
  for(int i=0; i<n; i++){
    if(b[i]>0){
      ans += b[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <sstream>
#include <algorithm>
#include <bitset>
#include <utility>
#include <iostream>
#include <cmath>
#include <deque>
#include <string>
#include <time.h>
#include <stack>

#define pii pair<ll,ll>
#define X first
#define Y second
#define mp make_pair

typedef long long ll;
using namespace std;
#define MAXN 30000
#define MOD 998244353
#define N 1048576
ll n, x, k, z, m, pos, q, ans_v, y;


ll b[200500];
ll a[200500];
vector<ll> prs;

ll binpow(ll x, ll y) {
    if (y == 0) {
        return 1;
    }
    ll tmp = binpow(x, y / 2);
    tmp = tmp * tmp % MOD;
    if (y % 2) {
        return x * tmp % MOD;
    }
    return tmp;
}

ll inv(ll x) {
    return binpow(x, MOD-2);
}

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

ll used[1005000], sum[1005000], calced[1005000];
vector<pii> g[1005000];

vector<ll> f;


void try_fill(ll pp) {
    ll y = pp;
    for (auto x : prs) {
        if (x * x > pp) {
            break;
        }
        ll p = 0;
        while (y % x == 0) {
            y /= x;
            p++;
        }
        if (p) {
            g[pp].push_back(mp(x, p));
        }
    }
    if (y > 1) {
        g[pp].push_back(mp(y, 1));
    }
}

void push(ll x, ll n, ll val) {
    if (n == g[x].size()) {

        sum[val] += x;
        if (!used[val]) {
            used[val] = 1;
            try_fill(val);
        }
        return;
    }
    ll p = 1;
    for (int i = 0; i <= g[x][n].Y; i++) {
        push(x, n+1, val * p);
        p *= g[x][n].X;
    }
}

void po(ll x, ll n, ll val) {
    if (n == g[x].size()) {
        f.push_back(val);
        return;
    }
    ll p = 1;
    for (int i = 0; i <= g[x][n].Y; i++) {
        po(x, n+1, val * p);
        p *= g[x][n].X;
    }
}

ll dp[1005000], dpu[1005000];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    for (int i = 2; i <= 1000; i++) {
        if (is_p(i)) {
            prs.push_back(i);
        }
    }
    cin >> n;
    for (int i = 0; i < n; i++) {
        f.clear();
        cin >> a[i];
        if (!used[a[i]]) {
            used[a[i]] = 1;
            try_fill(a[i]);
        }
        push(a[i], 0, 1);
    }
    ll ans = 0;

    for (int i = 0; i < n; i++) {
        f.clear();
        if (calced[a[i]] != 0) {
            ans = (ans + calced[a[i]]) % MOD;
            continue;
        }
        po(a[i], 0, 1);
        sort(f.begin(), f.end());
        reverse(f.begin(), f.end());
        ll cur_sum = 0;
        for (auto v : f) {
            dp[v] = sum[v];
            for (auto v1 : f) {
                if (v1 == v) {
                    break;
                }
                if (v1 % v == 0) {
                    dp[v] -= dp[v1];
                }
            }
            cur_sum += dp[v] * a[i] / v;
        }
        cur_sum -= a[i];
        ans = (ans + cur_sum) % MOD;
        calced[a[i]] = cur_sum;
    }
    cout << ans * inv(2) % MOD << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define FAST ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mp make_pair
#define pb push_back
#define lp(i,s,f) for(ll i = s; i < ll(f); i++)
#define inF freopen("input.in", "r", stdin);
#define outF freopen("output.in", "w", stdout);
#define endl '\n'
#define MOD 1000000007
#define mm(arr) memset(arr, 0, sizeof(arr))

int main(){
    FAST
    int n; cin >> n;
    int ans = 1000 - (n%1000);
    if(ans == 1000)ans = 0;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3628
N,K=map(int,input().split())
D=[]
X=[]
Y=[]
 
for i in range(N):
    x,y=map(int,input().split())
    D.append([x,y])
    X.append(x)
    Y.append(y)
    
X.sort()
Y.sort()
ans=10**20
for a in range(len(X)):
    for b in range(len(X)-a):
        for c in range(len(Y)):
            for d in range(len(Y)-c):
                cnt=0
                for e in range(N):
                    if X[a]<=D[e][0]<=X[len(X)-1-b] and Y[c]<=D[e][1]<=Y[len(Y)-1-d]:
                        cnt+=1
                if cnt>=K and ans>abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d]):
                    ans=abs(X[a]-X[len(X)-1-b])*abs(Y[c]-Y[len(Y)-1-d])
print(ans)

Measured memory_bytes: 48980
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

int main() {
   cin.tie(0);
   ios_base::sync_with_stdio(0);
   string s, t;
   cin >> s >> t;
   int n = s.size();
   int ans = 0;
   rep(i, 0, n) {
      if (s[i] != t[i]) ans++;
   }
   cout << ans << endl;
   return 0;
}

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


int main(){
    int n;

    string s;

    cin>>n>>s;

    if(s.substr(0,n/2) == s.substr(n/2,n)) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    int n = s.length()+1;
    vll a(n, INF);

    if (s[0] == '<') a[0] = 0;
    if (s[n-2] == '>') a[n-1] = 0;
    rep(i, n-2) {
        if (s[i] == '>' && s[i+1] == '<') a[i+1] = 0;
    }

    rep(i, n-1) {
        if (s[i] == '<') a[i+1] = a[i]+1;
    }
    rrep(i, n-1) {
        if (s[i] == '>') {
            if (a[i] == INF) a[i] = a[i+1]+1;
            else a[i] = max(a[i], a[i+1]+1);
        }
    }
    ll ans = accumulate(all(a), 0ll);

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

Measured memory_bytes: 4740
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		String ball = "A";
		while(scan.hasNext()){
			String[] str = scan.nextLine().split(",");
			if(str[0].equals(ball)){
				ball = str[1];
			}else if(str[1].equals(ball)){
				ball = str[0];
			}
		}
		System.out.println(ball);
	}
}

Measured memory_bytes: 17160
#include <stdio.h>
int main() {
  int a, b, c;
  int count = 0;
  scanf("%d %d %d", &a, &b, &c);
  if (a == b || a == c) {
    if (b != c) {
      printf("Yes\n");
    } else {
      printf("No\n");
    }
  } else if (a != b && a != c) {
    if (b == c) {
      printf("Yes");
    } else {
      printf("No");
    }
  } else {
    printf("No\n");
  }
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ABC048C - Boxes and Candies
  // ai + ai+1 <= xとなるように順に操作していく。常にai+1を減じるのが最適
  ll N, x; cin >> N >> x;
  vector<ll> a(N);
  REP(i, N) cin >> a[i];
  ll cnt = 0;
  REP(i, N-1){
    if(a[i] + a[i+1] > x){
      ll tmp = a[i] + a[i+1] - x; // いくつ引かなければならないか計算する
      cnt += tmp;
      a[i+1] = max((ll)0, a[i+1] - tmp); // ll同士の比較をするためキャスト演算子を用いた
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  long long h,w;
  cin >> h >> w;
  if(h==1 or w==1){
    cout << "1\n";
  }else{
    cout << (h*w)/2ll+(h*w)%2 << endl;
  }
  return 0;
}

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

int compare_int(const void *a, const void *b){
  return *(int *)b - *(int *)a;
}

int main(int argc, char const *argv[]) {

  int N;
  scanf("%d", &N);
  int M = 3 * N;
  int a[M];
  for (int i = 0; i < M; i++) {
    scanf("%d", a + i);
  }
  qsort(a, M, sizeof(int), compare_int);

  // for (int i = 0; i < M; i++) {
  //   printf("a[%d] = %d\n", i, a[i]);
  // }

  long long int sum = 0;
  for (int i = 0; i < N; i++) {
    //printf("a[%d] = %d\n", 1 + 2 * i, a[1 + 2 * i]);
    sum += a[1 + 2 * i];
  }

  printf("%lld\n", sum);

  return 0;
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 2000005;

/* ...o(^-^)o... */

int main(){
    string s,t; cin >>s>>t;
    int n = s.size();
    int res = 0;
    rep(i, n){
        if(s[i] != t[i]) res++;
    }
    out(res);
}

Measured memory_bytes: 3848
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include <cinttypes>

#define max(a,b) (((a) > (b)) ? (a) : (b))
#define min(a,b) (((a) < (b)) ? (a) : (b))
#define abs(a) (((a) < 0) ? -(a) : (a))

#define FOR(var, to)          for (register int var = 0; var < to; var++)
#define FROMTO(var, from, to) for (register int var = from; var <= to; var++)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

static inline int ri() {
	int a;
	scanf("%d", &a);
	return a;
}

static inline s64 rs64() {
	s64 a;
	scanf("%" SCNd64, &a);
	return a;
}

static inline void wi(int a) {
	printf("%d", a);
}

static inline void wu64(u64 a) {
	printf("%" PRIu64, a);
}

int main() {
	int a = ri();
	int b = ri();
	int k = ri();
	
	int last = 0;
	
	for (int i = 0; i < k; i++) {
		if (a+i <= b) wi(a+i);
		last = max(last,a+i);
		printf("\n");
	}
	int start = max(last+1, b-k+1);
	for (int i = start; i <= b; i++) {
		wi(i);
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <climits>
#include <cstdio>
#include <stdio.h> 
#include <map>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <vector>
#include <algorithm>
using namespace std;


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

int main() {
	long long a,b;
	cin>>a>>b;
	
	cout << (a*b*1ll)/gcd(a,b);	
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)


func main() {
	var s string
	fmt.Scan(&s)
	ans:=true
	for i:=0;i<len(s)-1;i++{
		a,_ := strconv.Atoi(string(s[i]))
		b,_ := strconv.Atoi(string(s[i+1]))
		if a== b{
			ans =false
			break
		}
	}
	if ans{
		fmt.Println("Good")
	} else{
		fmt.Println("Bad")
	}
}

Measured memory_bytes: 512
import java.util.*

fun main(args : Array<String>) {
    val sc = Scanner(System.`in`)
    val N = sc.nextInt()
    val M = sc.nextInt()
    var A = 0

    for (i in 0 until M) {
        A += sc.nextInt()
    }
    if (N < A) {
        println(-1)
    } else {
        println(N-A)
    }

}


Measured memory_bytes: 47000
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

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

ll lcm(ll x, ll y) {
    return x*y / gcd(x,y);
}

int main(void)
{
    IOS
    int n; cin >> n;
    vector<ll> v(n);
    REP(i,n) cin >> v[i];
    ll ans = 1;
    const ll pten = 1e9;
    REP(i,n) {
        ll a = ans;
        ll b = v[i];
        if (a < pten && b < pten) ans = lcm(a,b);
        else {
            if (a < b) swap(a,b);
            ll ax = 1;
            while(a * ax % b != 0) {
                ax++;
            }
            ans = a*ax;
        }

    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
N = gets.to_i
s = N.times.map{gets.chomp}
ans = {}

s.sort!
(0..(N-1)).each do |i|
  if ans[s[i]].nil?
    ans[s[i]] = 0
  end
  ans[s[i]] += 1
end
max = ans.values.max

ans.each do |k, v|
  if v == max
    puts k
  end
end

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

const int N = 1e5 + 233;

int n, m, tot, vis[N], out[N];

struct Edge { int x, y; } E[N];
struct Node { int y, id, t; };
std::vector<Node> G[N];

void dfs1(int x, int fa) {
  vis[x] = 1;
  for (int i = 0; i < G[x].size(); ++i) {
    int y = G[x][i].y;
    if (y == fa) G[x][i].t = 1;
    else if (!vis[y]) {
      G[x][i].t = 1; dfs1(y, x);
    } else if (!E[G[x][i].id].x) {
      E[G[x][i].id] = { x, y };
      ++out[x];
    }
  }
}

void dfs2(int x, int fa) {
  for (auto w : G[x]) {
    if (!w.t || w.y == fa) continue;
    int y = w.y; dfs2(y, x);
    if (out[y] & 1)
      E[w.id] = { y, x };
    else {
      ++out[x];
      E[w.id] = { x, y };
    }
  }
}

int main() {
  scanf("%d %d", &n, &m);
  if (m & 1) { puts("-1"); return 0; }
  for (int i = 1; i <= m; ++i) {
    int x, y; scanf("%d %d", &x, &y);
    G[x].push_back({ y, i, 0 });
    G[y].push_back({ x, i, 0 });
  }
  dfs1(1, 0);
  dfs2(1, 0);
  for (int i = 1; i <= m; ++i)
    printf("%d %d\n", E[i].x, E[i].y);
  return 0;
}


Measured memory_bytes: 16256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
#define mod 1000000007
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define setA0(a) for(ull i =0;i<n;i++){a[i] = 0;}
#define aout(a) for(auto x : a){cout<<x<<' ';} // array output macro 
#define ain(a) for(ull i =0;i<n;i++){cin>>a[i];} //array input macro
#define NofSetBits(x) __builtin_popcount(x);
#define InpGrph(g,e) while(e--){ll x;ll y;cin>>x>>y ;g[x].pub(y);g[y].pub(x);}
#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll N =1000007;
vector<bool>primes(1000007,1);


int main(){
  FastIO;
  int n =5;
  int an =0;
  for(ll i=1;i<=5;i++){
    ll x;
    cin>>x;
    if(x==0){
      an =i;
    }
  }
  cout<<an;
  return 0;
}


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

#define fi first
#define se second
#define pii pair<int,int>
using namespace std;
const int maxn = 2e5+15;
int n,Q,a,b,c,d,cnt,head[maxn],ans[maxn];
struct edge{
    int to,nxt,col,len;
}e[maxn<<1];
struct query{
    int l,r,x,y,id;
}q[maxn<<1];
pii p[maxn];
inline void add(int u,int v,int c,int d){
    e[++cnt] = (edge){v,head[u],c,d};
    head[u] = cnt;
}
int dp[maxn][20],deep[maxn],st[maxn],ed[maxn],tot,A[maxn<<1];
void dfs(int x,int fa,int depth){
    A[++tot] = x; st[x] = tot; deep[x] = depth;
    for(int i = head[x];i > 0;i = e[i].nxt){
        int v = e[i].to;
        if(v == fa) continue;
        p[v] = pii(e[i].col,e[i].len);
        dp[v][0] = x; dfs(v,x,depth+1);
    }
    A[++tot] = x; ed[x] = tot;
}
void init(){
    for(int i = 1;(1<<i)<=n; ++i)
    for(int j = 1;j <= n; ++j)
    dp[j][i] = dp[dp[j][i-1]][i-1];
}
int LCA(int u,int v){
    if(deep[u] < deep[v]) swap(u,v);
    int h = deep[u] - deep[v];
    for(int i = 0;i < 20; ++i){
        if(h&(1<<i)) u = dp[u][i];
    }
    if(u == v) return u;
    for(int i = 19; ~i; --i){
        if(dp[u][i] != dp[v][i]){
            u = dp[u][i];
            v = dp[v][i];
        }
    }
    return dp[u][0];
}
int block,num[maxn],sum[maxn],vis[maxn],res;
bool cmp(query a,query b){
    return a.l/block==b.l/block ? a.r<b.r : a.l<b.l;
}
void add(int v){
    if(vis[v]) {num[p[v].fi]--;sum[p[v].fi]-=p[v].se;res-=p[v].se;}
    else {num[p[v].fi]++;sum[p[v].fi]+=p[v].se;res+=p[v].se;}
    vis[v] ^= 1;
}
void del(int v){
    if(vis[v]) {num[p[v].fi]--;sum[p[v].fi]-=p[v].se;res-=p[v].se;}
    else {num[p[v].fi]++;sum[p[v].fi]+=p[v].se;res+=p[v].se;}
    vis[v] ^= 1;
}
int main(){
    scanf("%d %d",&n,&Q); block = sqrt(n*1.0);
    for(int i = 1;i < n; ++i){
        scanf("%d %d %d %d",&a,&b,&c,&d);
        add(a,b,c,d); add(b,a,c,d);
    }
    dfs(1,0,1); init();
    for(int i = 0;i < Q; ++i){
        scanf("%d %d %d %d",&a,&b,&c,&d);
        if(st[c] > st[d]) swap(c,d);
        if(LCA(c,d) == c) q[i] = (query){st[c]+1,st[d],a,b,i};
        else q[i] = (query){ed[c],st[d],a,b,i}; 
    }
    sort(q,q+Q,cmp);
    int L = 2,R = 1; res = 0;
    for(int i = 0;i < Q; ++i){
        while(R > q[i].r) del(A[R]),--R;
        while(R < q[i].r) ++R,add(A[R]);
        while(L < q[i].l) del(A[L]),++L;
        while(L > q[i].l) --L,add(A[L]);
        ans[q[i].id] = res-sum[q[i].x]+num[q[i].x]*q[i].y;
    }
    for(int i = 0;i < Q; ++i) printf("%d\n",ans[i]);
    return 0;
}

Measured memory_bytes: 30208
n , m , c = map(int , input().split())
list_=[]
num=0
for a in range(n+1):
  list_.append(list(map(int , input().split())))
for b in range(1,n+1):
  sum_= c
  for d in range(m):
    sum_ = sum_ + (list_[0][d]*list_[b][d])
  if sum_ > 0:
    num = num + 1
print(num)

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

using namespace std;

typedef pair<int,int> pii;

#define size(x) ((int) x.size())

int main() {
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int n, ans = 0, x = 0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'I')
            x++;
        else
            x--;
        ans = max(ans, x);
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
    int a,b;
    cin >> a >> b;
    if (a==b){
        cout << "a == b" << endl;
    }
    else if(a>b){
        cout << "a > b" << endl;
    }
    else {
        cout << "a < b" << endl;
    }
    return 0;
}



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

int main(){
  int a, b, c;
  cin >> a >> b >> c;
  if(a == b && b == c){
    cout << 1 << endl;
  }
  else if(a != b && b != c && c != a){
    cout << 3 << endl;
  } else {
    cout << 2 << endl;
  }
  return 0;
}

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

#define for_(i,a,b) for(int i=(a);i<(b);++i)

int main() {
	int b, r, g, c, s, t;
	
	while (cin >> b >> r >> g >> c >> s >> t, t) {
		int B = 5 * b + 3 * r;
		int T = t - B - s;
		
		cout << 100 + 15 * (b + r) + 13 * B + 7 * g + 2 * c - 3 * T << endl;
	}
}

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

int main(){
    int n;
    cin>>n;
    vector<vector<int>>happy(n,vector<int>(3));
    for(int i=0;i<n;i++)for(int j=0;j<3;j++) cin>>happy[i][j];
    vector<vector<int>>dp(n+1,vector<int>(3));
	for(int i=0;i<n;i++){
		dp[i+1][0]=max(dp[i][1]+happy[i][1],dp[i][2]+happy[i][2]);
		dp[i+1][1]=max(dp[i][0]+happy[i][0],dp[i][2]+happy[i][2]);
		dp[i+1][2]=max(dp[i][0]+happy[i][0],dp[i][1]+happy[i][1]);
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;;

    
    return 0;
}

Measured memory_bytes: 14080
//in the name of god
//if you read this code please search about imam hussain
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

#define pb push_back;
#define endl "\n";
#define X first;
#define Y second;
#define pii pair<int,int>;
#define migmig ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define read freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);

const int maxn=1e5+5;
const int mod=1e9+7;
const int inf=1e9;
const int del=728729;

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}
ll dp[maxn];
int main(){
	migmig;
	int a,b,c,d;
	string s;
	cin >> s;
	a=s[0]-'0';
	b=s[1]-'0';
	c=s[2]-'0';
	d=s[3]-'0';
	if(a+b+c+d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"+"<<d;	cout<<"=7";
		return 0;
	}
	if(a+b+c-d==7){
		cout<<a<<"+"<<b<<"+"<<c<<"-"<<d;	cout<<"=7";
		return 0;
	}
	if(a+b-c+d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"+"<<d;	cout<<"=7";
		return 0;
	}
	if(a-b+c+d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"+"<<d;	cout<<"=7";
		return 0;
	}
	if(a-b-c+d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"+"<<d;	cout<<"=7";
		return 0;
	}
	if(a-b+c-d==7){
		cout<<a<<"-"<<b<<"+"<<c<<"-"<<d;	cout<<"=7";
		return 0;
	}
	if(a+b-c-d==7){
		cout<<a<<"+"<<b<<"-"<<c<<"-"<<d;
			cout<<"=7";
		return 0;
	}if(a-b-c-d==7){
		cout<<a<<"-"<<b<<"-"<<c<<"-"<<d;
		cout<<"=7";
		return 0;
	}

	return 0;
}



Measured memory_bytes: 256
n = int(input())
s = input()
MOD = 10 ** 9 + 7

# dp[i][j]
# i回目のキーを押し終えたときに、文字列の長さがjになるときの通り数
dp = [[0] * (n + 1) for i in range(n + 1)]
dp[0][0] = 1

for i in range(n):
    for j in range(n + 1):
        # Bを押したとき
        dp[i + 1][max(j - 1, 0)] += dp[i][j]
        dp[i + 1][max(j - 1, 0)] %= MOD
        if j + 1 <= n:
            # 0を押したとき
            dp[i + 1][j + 1] += dp[i][j]
            # 1を押したとき
            dp[i + 1][j + 1] += dp[i][j]
            dp[i + 1][j + 1] %= MOD

ptn = pow(2, len(s), MOD)
print(dp[-1][len(s)] * pow(ptn, MOD - 2, MOD) % MOD)

Measured memory_bytes: 231816
#include <bits/stdc++.h>
#define maxn (int)(1e5)
#define i64 long long
#define pii pair<i64,i64>
#define all(x) x.begin(),x.end()
#define LB(x,v) lower_bound(all(x), v) - x.begin()
#define fread() freopen("in.txt", "r", stdin);
using namespace std;
int d[110];

int solve(int n){
    int sum =0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++) sum+=d[i]*d[j];
    }
    return sum;
}

int main() {
    /*BEFORE SUBMIT, CHECK
    sample i/o format
    statements for debugging are removed/comment out
    global values / stl containers are initialized/cleared for each test (if needed)
    all array size are sufficient
    loop variable or output value doesn't cross min/max limit of input
    // */
   
    
    int n;
    while(scanf("%d",&n)==1){
        for(int i=0;i<n;i++) scanf("%d",&d[i]);
        printf("%d\n", solve(n));     
    }
    return 0;
}

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

#define Fast cin.tie(0), ios::sync_with_stdio(0)
#define All(x) x.begin(), x.end()
#define louisfghbvc int t; cin >> t; while(t--)
#define sz(x) (int)(x).size()
using namespace std;
typedef long long LL;
typedef pair<LL, LL> ii;
typedef vector<LL> vi;

template<typename T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep = ""; for(const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }

void dbg_out() { cerr << "\n"; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }

const int mod = 1e9+7;
const int N = 1e5+5;
LL arr[105];
LL dp[105][N];

void solve(){
    int n, k;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i) cin >> arr[i];

    memset(dp, 0, sizeof dp);

    dp[0][0] = 1;
    for(int i = 1; i <= n; ++i){
        int sum[k+1];
        sum[0] = dp[i-1][0];
        for(int j = 1; j <= k; ++j)
            sum[j] = (sum[j-1] + dp[i-1][j]) % mod;
        for(int j = 0; j <= k; ++j){
            int tmp = sum[j];
            int cur = j-arr[i]-1;
            if(cur >= 0){
                tmp = (tmp - sum[cur]+ mod) % mod;
            }
            dp[i][j] = tmp;
        }
    }
    cout << dp[n][k] << "\n";
}

int main()
{
    Fast;
    //louisfghbvc{
        solve();
    //}
    return 0;
}


Measured memory_bytes: 85976
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define FOR(i,a,b) for(int (i)=(a);(i)<=(b);(i)++)
#define rep(i,n) FOR(i,0,n-1)
#define int long long

int e[300005], w[300005];

signed main() {

	int n; cin >> n;
	string s; cin >> s;

	e[0] = 0, w[0] = 0;
	if (s[0] == 'E') e[0]++;
	else w[0]++ ;

	FOR(i,1, n-1)
	{
		if (s[i] == 'E')
		{
			e[i] = e[i - 1] + 1;
			w[i] = w[i - 1];
		}
		else
		{
			e[i] = e[i - 1];
			w[i] = w[i - 1] + 1;
		}
	}
	int emax = e[n-1], wmax = w[n-1];

	int ans = emax-e[0];


	rep(i, n)
	{
		if (i == 0)continue;
		int num = w[i - 1] + emax - e[i - 1] - (e[i] - e[i - 1]);
		ans = min(ans, num);
	}

	cout << ans << endl;

}

//cout << ans << endl;

Measured memory_bytes: 5380
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CGeTAC solver = new CGeTAC();
        solver.solve(1, in, out);
        out.close();
    }

    static class CGeTAC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int length = in.nextInt();
            int q = in.nextInt();

            String s = in.next();
            int[] substringArray = new int[length];

            for (int i = 0; i < length; i++) {
                int lastCount = i > 0 ? substringArray[i - 1] : 0;
                substringArray[i] = lastCount;
                if (s.charAt(i) == 'A' && length > i + 1 && s.charAt(i + 1) == 'C') {
                    substringArray[i + 1] = lastCount + 1;
                    i++;
                }
            }

            for (int i = 0; i < q; i++) {
                int l = in.nextInt() - 1;
                int r = in.nextInt() - 1;

                out.println(substringArray[r] - substringArray[l]);
            }
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 41848
#include<stdio.h>
int main(){
  int i ,j ,n ,old[7]={0};

  while( scanf( "%d",&j ) != EOF ){
    if( j == 0 ){
      break;
    }
    
    for( i=0 ; i<j ; i++ ){
      scanf( "%d",&n );
      
      if( n < 10 ){
	old[0]++;
      }
      
      else if( n >= 10 && n < 20 ){
	old[1]++;
      }
      
      else if( n >= 20 && n < 30 ){
	old[2]++;
      }
      
      else if( n >= 30 && n < 40 ){
	old[3]++;
      }
      
      else if( n >= 40 && n < 50 ){
	old[4]++;
      }
      else if( n >= 50 && n < 60 ){
	old[5]++;
      }
      
      else if( n >= 60 ){
	old[6]++;
      }
    }
    
    for( i=0 ; i<7 ; i++ ){
      printf( "%d\n",old[i] );
    }
    memset( old ,0 ,sizeof(old) );
  }  

  return 0;
}

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

int main(){

	string str;
	getline(cin,str);

	for(int i=0; i<str.size(); i++){
		char c = str[i];
		
		if('A'<=c && c<='Z'){
			cout << (char)(c-'A'+'a');
		}
		else if('a'<=c && c<='z'){
			cout << (char)(c-'a'+'A');
		}
		else{
			cout << c;
		}
	}
	cout << endl;
}

Measured memory_bytes: 1172
#include<iostream>
using namespace std;
int main(void) {
    int a, b;
    cin >> a >> b;
    if(a > b){
        cout << "a > b" << endl;
    }else if(a < b){
        cout << "a < b" << endl;
    }else{
        cout << "a == b" << endl;
    }
    return 0;
}

Measured memory_bytes: 3080