akhauriyash/Code-Regression huggingface dataset:
#include <set>
#include <iostream>
#include <algorithm>
#include <queue>
#include <sstream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

using namespace std;

string sss(vector<string> v){
 loop:
  REP(i,v.size()){
    REP(j,v.size()) if(i != j){
      if(string::npos != v[i].find(v[j])){
	v.erase(v.begin() + j);
	goto loop;
      }
    }
  }

  int n = v.size();
  vector<vector<int> > same(n, vector<int>(n));

  REP(i,n) REP(j,n){
    for(int ii = 0; ii <= v[i].size(); ii++){
      bool ok = true;
      for(int jj = 0; ii + jj < v[i].size() && jj < v[j].size(); jj++){
	if(v[i][ii + jj] != v[j][jj]){
	  ok = false;
	  break;
	}
      }
      if(ok){
	same[i][j] = ii;
	break;
      }
    }
  }

  string ret = ""; REP(i, n) ret += v[i];
  vector<int> pm(n); REP(i,n) pm[i] = i;

  do{
    int len = v[pm[0]].size();
    REP(i, n - 1){
      int a = pm[i + 1];
      int b = pm[i];
      len += v[a].size() - (v[b].size() - same[b][a]);
    }    

    if(len <= ret.size()){
      stringstream ss; ss << v[pm[0]];
      
      REP(i, n - 1){
	int a = pm[i + 1];
	int b = pm[i];
	
	ss << v[a].substr(v[b].size() - same[b][a]);
      }

      string tmp = ss.str();
      
      if(tmp.size() < ret.size()) ret = tmp;
      else if(tmp.size() == ret.size()){
	if(ret > tmp) ret = tmp;
      }
    }
  }while(next_permutation(pm.begin(), pm.end()));

  return ret;
}

int main(){
  int n;
  while(cin >> n, n){
    vector<string> v(n);
    REP(i,n) cin >> v[i];
    cout << sss(v) << endl;
  }
  return 0;
}

Measured memory_bytes: 944
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
signed main(){  
  cin.tie(0);
  ios::sync_with_stdio(0);
  string s;
  while(getline(cin,s),s!="0"){
    Int m=count(s.begin(),s.end(),'x')*2-1;
    if(m==1){
      cout<<s<<endl;
      continue;
    }
    
    Int cur=0;
    vector<Int> L(m,-1),R(m,-1);
    
    function<Int(string)> dfs=[&](string s){
      //cout<<s<<endl;
      Int v=cur++;
      if(s=="x"){
	return v;
      }
      Int op=0;
      for(Int i=0;i<(Int)s.size();i++){
	if(s[i]=='(') op++;
	if(s[i]==')') op--;
	if(op==1&&s[i]==' '){
	  string ls=s.substr(1,i-1);
	  string rs=s.substr(i+1,s.size()-(i+2));
	  L[v]=dfs(ls);
	  R[v]=dfs(rs);
	  return v;
	}
      }
    };
    dfs(s);
    //for(Int i=0;i<m;i++) cout<<i<<":"<<L[i]<<" "<<R[i]<<endl; 

    vector<string> sh(m);
    vector<set<string> > dp(m);
    vector<Int> p(m),q(m);
    vector<Int> p1(m),q1(m);
    vector<Int> p2(m),q2(m);

    auto check=[&](Int a,Int b,Int c,Int d){
      return a*d>c*b;
    };
    
    function<void(Int)> dfs2=[&](Int v){
      if(L[v]<0){
	p[v]=0;q[v]=1;
	sh[v]="()";
	dp[v].emplace(sh[v]);
	return;
      }
      dfs2(L[v]);
      dfs2(R[v]);
      
      set<string> uni;
      dp[v]=dp[R[v]];
      for(auto ss:dp[L[v]]){
	dp[v].emplace(ss);
	if(dp[R[v]].count(ss))
	  uni.emplace(ss);
      }
      p[v]=uni.size();
      q[v]=dp[v].size();
      //cout<<v<<":"<<p[v]<<":"<<q[v]<<endl;
      //for(auto ss:dp[v]) cout<<v<<":"<<ss<<endl;
      
      sh[v]="("+(sh[L[v]]<sh[R[v]]?sh[L[v]]+sh[R[v]]:sh[R[v]]+sh[L[v]])+")";      
      dp[v].emplace(sh[v]);

      p1[v]=L[v];p2[v]=R[v];
    };
    dfs2(0);

    function<void(Int, Int)> dfs4=[&](Int v,Int k){
      if(L[v]<0) return;
      function<Int(int,Int)> ccc=[&](Int a,Int b)->Int{
	if(check(p[a],q[a],p[b],q[b])){
	  return 1;
	}
	
	if(check(p[b],q[b],p[a],q[a])){
	  return 0;
	}
	
	if(!p[a]&&!p[b]){
	  return 0;
	}

	if(ccc(p1[a],p2[a])){
	  swap(p1[a],p2[a]);
	}

	if(ccc(p1[b],p2[b])){
	  swap(p1[b],p2[b]);
	}
	
	if(ccc(p1[a],p1[b])){
	  return 1;
	}
	
	if(ccc(p1[b],p1[a])){
	  return 0;
	}
	
	if(ccc(p2[a],p2[b])){
	  return 1;
	}
	
	return 0;
      };
      //cout<<v<<" "<<k<<":"<<ccc(L[v],R[v])<<endl;
      if(k^ccc(L[v],R[v])) swap(L[v],R[v]);
      dfs4(L[v],0);
      dfs4(R[v],1);
    };
    dfs4(0,0);

    stringstream ss;
    function<void(Int)> dfs3=[&](Int v){
      if(L[v]<0){
	ss<<"x";
	return;
      }
      ss<<"(";
      dfs3(L[v]);
      ss<<" ";
      dfs3(R[v]);
      ss<<")";
    };
    dfs3(0);
    string ans=ss.str();
    if(0){
      reverse(ans.begin(),ans.end());
      for(auto &c:ans){
	if(c=='(') c=')';
	else if(c==')') c='(';
      }
    }
    cout<<ans<<endl;
  }
  return 0;
}



Measured memory_bytes: 3168
N=int(input())
x=[0]*N
y=[0]*N
h=[0]*N
for i in range(N):
    x[i],y[i],h[i]=map(int,input().split())
ansx=-1
ansy=-1
ansh=-1
for i in range(101):
    for j in range(101):
        P=True
        tmph=-1
        for k in range(N):
            if h[k]>0:
                tmph=h[k]+abs(i-x[k])+abs(j-y[k])
                break
        for l in range(N):
            if h[l]!=max(0,tmph-abs(i-x[l])-abs(j-y[l])):
                P=False
        if P==True:
            ansx=i
            ansy=j
            ansh=tmph
print(ansx,ansy,ansh)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        long answer = 0;

        if (n < a) {
            answer = n;
        } else if (n <= a + b) {
            answer = a;
        } else if (n > a + b) {
            if (n % (a + b) == 0) {
                answer = a * (n / (a + b));
            } else if (n % (a + b) >= a) {
                answer = a * (n / (a + b)) + a;
            } else
            //(n%a+b<a)
            {
                answer = a * (n / (a + b)) + n % (a + b);
            }

        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 23124
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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 = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

// -------------------------------------------------------

int N;
string s;

int main() {
  cin >> s;
  int ans = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (i % 2 == 0 && s[i] == 'p') {
      --ans;
    } else if (i % 2 == 1 && s[i] == 'g') {
      ++ans;
    }
  }
  cout << ans;
}


Measured memory_bytes: 3744
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e9;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W;
typedef long long ll;
typedef pair<ll, ll> Pa;

int arr[200000];
map<int, int> cnt;
int main()
{
	cin >> N;
	rep(i, N) {
		cin >> arr[i];
		if (cnt.find(arr[i] - i) == cnt.end()) cnt[arr[i] - i] = 1;
		else cnt[arr[i] - i]++;
	}
	ll sum = 0;
	rep(i, N) {
		if (cnt.find(arr[i] - i) != cnt.end()) sum += cnt[- arr[i] - i];
	}
	cout << sum;
}


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

int main()
{
	int N,sum, i;
    long long int K,cnt;
	cin >> N>>K;
	vector<int>a(N);
	vector<int>b(N);
	long long int c[100001] = {};
	for (i = 0; i < N; i++) {
		cin >> a[i] >> b[i];
	}
	for (i = 0; i < N; i++) {
		c[a[i]] += b[i];
	}
	cnt = 0;
	for (i = 1; i < 100001; i++) {
		cnt += c[i];
		if (K <= cnt) {
			cout << i << endl;
			break;
		}
		
	}
    return 0;
}



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

int main()
{
    int N;
    cin>>N;
    vector<int> V(N);
    for (int i = 0;i < N;i++) {
        cin >> V[i];
    }
    vector<int> C(N);
    for (int i = 0;i < N;i++) {
        cin >> C[i];
    }
    int ans = 0;
    for (int i = 0;i < N;i++) {
        if(V[i] > C[i]){
          ans+=V[i] - C[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
input:
3
abcbdab
bdcaba
abc
abc
abc
bc

output:
4
3
2

"""
import sys


def lcs(A, B):
    m, n = len(A), len(B)
    count_list = [[0] * (n + 1) for _ in range(m + 1)]

    for i in range(1, m + 1):
        for j in range(1, n + 1):
            if A[i - 1] == B[j - 1]:
                count_list[i][j] = count_list[i - 1][j - 1] + 1
            elif count_list[i - 1][j] >= count_list[i][j - 1]:
                count_list[i][j] = count_list[i - 1][j]
            else:
                count_list[i][j] = count_list[i][j - 1]

    return count_list[m][n]


def lcs_better(A, B):
    costs = [0]
    for c in B:
        for index in range(len(costs) - 1, -1, -1):
            # print(costs, index + 1)
            x_findex_index = A.find(c, costs[index])
            if x_findex_index != -1:
                if index + 1 < len(costs):
                    costs[index + 1] = min(costs[index + 1], x_findex_index + 1)
                else:
                    costs.append(x_findex_index + 1)
    return len(costs) - 1


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    pair_num = int(_input[0])

    word_list = _input[1:]
    # assert len(word_list) == 2 * pair_num
    for k in range(0, len(word_list), 2):
        print(lcs_better(word_list[k].strip(), word_list[k + 1].strip()))

Measured memory_bytes: 7788
answer = []

while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)

    result = 0
    if op == "?":
        break
    elif op == "+":
        result = a + b
    elif op == "-":
        result = a - b
    elif op == "*":
        result = a * b
    elif op == "/":
        result = int(a / b)

    answer.append(result)

[print(answer[i]) for i in range(len(answer))]


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

typedef long long ll;
ll n,m,ans;
char a[100010],b[100010];

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

int main (){
	int i;
	scanf ("%lld%lld",&n,&m);
	scanf ("%s",a+1);
	scanf ("%s",b+1);
	ans=n*m/gcd(n,m);
	ll da=ans/m;
	ll db=ans/n;
	for (i=0;i*da+1<=n&&i*db+1<=m;i++){
		if (a[i*da+1]!=b[i*db+1])break;
	}
	if (i*da+1<=n&&i*db+1<=m)printf("-1\n");
	else printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	int N; cin >> N;
	map<long long int, int>mp;
	vector<long long int>sums;
	long long int now = 0;
	for (int i = 0; i < N; ++i) {
		long long int a; cin >> a;
		now += a;
		sums.emplace_back(now);
	}
	int ans = 0;
	mp[0] = 0;
	for (int i = 0; i < N; ++i) {
		long long int sum = sums[i];
		if (mp.find(sum) != mp.end()) {
			ans = max(ans, i+1 - mp[sum]);
		}
		else mp[sum] = i+1;
	}
	cout << ans << endl;
	return 0;
}

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

int main()
{
    int n;
    cin >> n;
    int p[20003];
    int nth[20003];
    for(int i = 0; i < n; i++){
        cin >> p[i];
        nth[p[i]] = i;
    }
    for(int i = 1; i <= n; i++) cout << 20000 * i + (nth[i] - 10000) << " ";
    cout << endl;
    for(int i = 0; i < n; i++){
        cout << 20000 * (n - i) << " ";
    }
    cout << endl;
}

Measured memory_bytes: 768
#include <bits/stdc++.h> 
#include<cmath>
#include<string>
#define pb push_back
#define x first
#define y second
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define all(x) x.begin(),x.end()
#define int long long
using namespace std;
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
//void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
// look for  all edge cases
//search for a pattern

int dp[(int)1e6+2][2][2];
const int mod = 1e9+7;
int n;

int calc(int idx , int b1 , int b2){
	if(idx == n && b1 == 1 && b2 == 1){
		return 1;
	}
	if(idx == n){
		return 0;
	}
	
	if(dp[idx][b1][b2] != -1){
		return dp[idx][b1][b2];
	}
	
	int ways = 0;
	
	
	for(int i =0 ; i <= 9 ; i++){
		if(i == 0 ){
			ways = (ways + calc(idx+1, 1 , b2 ))%mod;
		}
		else if (i == 9){
			ways = (ways + calc(idx + 1 , b1 , 1))%mod;
		}
		else{
			ways = (ways + calc(idx +1 , b1 , b2))%mod;
		}
	}
	
	dp[idx][b1][b2] = ways;
	
	return ways%mod;
	
}

signed main() {    
	ios::sync_with_stdio(0);
	cout.tie(0);
	cin.tie(0);
		
	//int n;
	cin >> n;
	
	
	//memset(dp , sizeof(int) , -1);
	
	
	for(int i =0 ; i < 1e6+2 ; i++){
		for(int j =0 ; j < 2 ;j++){
			for(int k =0 ; k < 2; k++){
				dp[i][j][k] = -1;
			}
		}
	}
	
	int ans = calc(0 , 0 , 0);
	cout<<ans;
	 
	return 0;
}


Measured memory_bytes: 97232
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	long INF = (long) 1e18 + 5;
	long mod = (long) 1e9 + 7;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int N = in.nextInt();
		long arr[] = new long[N];
		for (int i = 0; i < N; i++) {
			arr[i] = in.nextLong();
		}
		long dp[][] = new long[N][N];
		for (int i = N - 1; i >= 0; i--) {
			for (int j = i; j < N; j++) {
				if (i == j) {
					dp[i][j] = 0;
				} else {
					dp[i][j] = INF;
					long sum = sum(i, j, arr);
					for (int k = i; k < j; k++) {
						dp[i][j] = Math.min(dp[i][j], dp[i][k] + dp[k + 1][j] + sum);
					}
				}
			}
//			pw.println();
		}
		pw.println(dp[0][N - 1]);
//
//		for (int i = 0; i < N; i++) {
//			pw.println(Arrays.toString(dp[i]));
//		}
	}

	long sum(int i, int j, long arr[]) {
		long sum = 0;
		for (int k = i; k <= j; k++) {
			sum += arr[k];
		}
		return sum;
	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

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

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

	public long nextLong() {
		return Long.parseLong(next());
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


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

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**13
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

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


def main():
    n = I()
    a = LI()
    av = 1.0 * sum(a) / len(a)
    m = inf
    mi = -1
    for i in range(n):
        c = a[i]
        t = abs(c-av)
        if m > t + eps:
            m = t
            mi = i

    return mi


print(main())


Measured memory_bytes: 8132
#include <iostream>

using namespace std;

int main()
{
	int n;
	char c;
	int ans[4] = {0};
	int num = 0;
	
	cin >> n;
	
	for (int i = 0; i < n; i++) {
		cin >> c;
		if (c == 'P') {
			ans[0]++;
		}
		else if (c == 'W') {
			ans[1]++;
		}
		else if (c == 'G') {
			ans[2]++;
		}
		else {
			ans[3]++;
		}
	}
	
	for (int i = 0; i < 4; i++) {
		if (ans[i] > 0) {
			num++;
		}
	}
	
	cout << (num == 3 ? "Three" : "Four") << endl;
	
	return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const ll mod=998244353;
const ll N=2e5+5;
using namespace std;
ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
ll lcm(ll a,ll b) { return a*b/gcd(a,b);    }
ll qp(ll a,ll b, ll p){ll ans = 1;while(b){if(b&1){ans = (ans*a)%p;--b;}a = (a*a)%p;b >>= 1;}return ans%p;}
ll Inv(ll x){ return qp(x,mod-2,mod);}
ll C(ll n,ll m){if (m>n) return 0;ll ans = 1;for (int i = 1; i <= m; ++i) ans=ans*Inv(i)%mod*(n-i+1)%mod;return ans%mod;}
int main()
{
    int c,d;
    string a,b,e;
    cin>>a>>b;
    cin>>c>>d;
    cin>>e;
    if(e==a) c--;
    else     d--;
    printf("%d %d\n",c,d);
    return 0;
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> a(n);
  for(int i = 0 ; i < n ; i++)
    cin >> a[i];
  
  int ans = 1e9;
  for(int i = 0 ; i <= n-k ; i++){
    int l = a[i];
    int r = a[i + k -1];
    if( r < 0 ){
      ans = min(-l, ans);
    }else if( l > 0 ){
      ans = min(r, ans);
    }else{
      ans = min(2 * min(-l,r) + max(-l, r), ans);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(){
  string a;
  cin>>a;
  int s=a.size();
  int count=0;
  for(int i=0;i<s/2;i++){
    //cout<<a[i]<<" "<<a[s-i]<<endl;
    if(a[i]!=a[s-i-1]){
      count++;
    }
  }
  cout<<count<<endl;
  return 0;
}


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

int main(void) {
    int a,b,c,d=0;
    cin >> a >> b >> c;
    for (int i=a; i <= b;i++) {
        d += (c % i == 0)?1:0;
    }
    cout << d << endl;
    return 0;
}

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

class dice_class:
    def __init__(self, list):
        self.num = list

    def roll(self, s):
        for i in s:
            if i == 'E':
                self.rollE()
            elif i == 'N':
                self.rollN()
            elif i == 'S':
                self.rollS()
            elif i == 'W':
                self.rollW()

    def rollE(self):
        self.num = [self.num[3], self.num[1], self.num[0], self.num[5], self.num[4], self.num[2]]

    def rollN(self):
        self.num = [self.num[1], self.num[5], self.num[2], self.num[3], self.num[0], self.num[4]]

    def rollS(self):
        self.num = [self.num[4], self.num[0], self.num[2], self.num[3], self.num[5], self.num[1]]

    def rollW(self):
        self.num = [self.num[2], self.num[1], self.num[5], self.num[0], self.num[4], self.num[3]]


if __name__ == "__main__":
    dice = dice_class(map(int, raw_input().split()))
    s = str(raw_input())
    dice.roll(s)
    print dice.num[0]

Measured memory_bytes: 6500
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

// [0,n) init!!
template<class T>
struct Dinic{
    const static int N = 10101 , M = N * 10;
    int s , t , n , h[N] , cur[N] , level[N] , q[N] , e , ne[M] , to[M];
    T cap[M] , flow;
    void liu(int u,int v,T w){ to[e] = v;ne[e] = h[u];cap[e] = w;h[u] = e++;}
    void link(int u,int v,T w){ liu(u , v , w);liu(v , u , 0);}
    void ini(int _n = N) { fill(h , h + (n=_n) , -1);e = 0;}
    bool bfs(){
        int L = 0 , R = 0;
        fill(level , level + n , -1);
        level[q[R++] = s] = 0;
        while(L < R && level[t] == -1){
            int c = q[L++];
            for(int k=h[c];~k;k=ne[k])
                if(cap[k] > 0 && level[to[k]] == -1)
                    level[q[R++] = to[k]] = level[c] + 1;
        }
        return ~level[t];
    }
    T dfs(int c,T mx){
        if(c == t) return mx;
        T ret = 0;
        for(int &k = cur[c];~k;k = ne[k]){
            if(level[to[k]] == level[c] + 1 && cap[k] > 0){
                T flow = dfs(to[k] , min(mx , cap[k]));
                ret += flow;cap[k] -= flow , cap[k^1] += flow;mx -= flow;
                if(!mx) return ret;
            }
        }
        level[c] = -1;
        return ret;
    }
    T run(int _s,int _t){
        s = _s , t = _t;
        flow = 0;
        while(bfs()){
            copy(h , h + n , cur);
            flow += dfs(s,~0U>>1);
        }
        return flow;
    }
};

Dinic<int> it;
int H , W;
string s[101];

int main(){
    cin >> H >> W;
    rep(i,0,H) cin >> s[i];
    int S = H + W , T = S + 1;
    pii start , finish;
    rep(i,0,H) rep(j,0,W) {
        if(s[i][j] == 'S') start = mp(i , j);
        if(s[i][j] == 'T') finish = mp(i , j);
    }
    if(start.fi == finish.fi || start.se == finish.se)
        cout << -1 << endl;
    else {
        it.ini(T + 1);
        it.link(S , start.fi , H * W);
        it.link(S , start.se + H , H * W);
        it.link(finish.fi , T , H * W);
        it.link(finish.se + H , T , H * W);
        rep(i,0,H) rep(j,0,W) if(s[i][j] == 'o') {
            it.link(i , j + H , 1);
            it.link(j + H , i , 1);
        }
        cout << it.run(S , T) << endl;
    }
    return 0;
}


Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;
  cin>>n>>k;
  int a[k];
  string ver;
  for(int i=0;i<k;i++)
  {
      cin>>a[i];
      ver+=to_string(a[i]);
  }
  string s=to_string(n);
  size_t found=s.find_first_of(ver);
  while(true)
  {
      if(found!=string::npos){
          n++;
          s=to_string(n);
          found=s.find_first_of(ver);
      }else{
        break;
      }
  }
  cout<<n<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#define mod 1000000007
#define ten5 100005
#define PI 3.1415926
using namespace std;

int num[26];

int main()
{
    //int m,n,o=0,i,j,k;
    long long int sum=0,sum2=0,n1=0,n2=0,n3;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=1,now=1;
    long long int a,a1,a2,a3,a4;
    //float f,g,h;
    //char now,pre;
    string s,s1;
    cin>>n>>k;
    sum=1;
    for(i=0;i<n;i++)
    {
        if(sum<=k) sum=sum<<1;
        else sum+=k;
    }
    cout<<sum;
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>

int main() {
  long long A, B;
  std::priority_queue<long long> aque, bque;
  std::vector<long long> d;
  scanf("%lld %lld", &A, &B);
  int amin = (int)std::sqrt(A), bmin = std::sqrt(B);
  for (int i = 1; i <= amin; ++i) {
    if (A%i == 0) {
      aque.push(i);
      if (i != A/i) aque.push(A/i);
    }
  }
  for (int i = 1; i <= bmin; ++i) {
    if (B%i == 0) {
      bque.push(i);
      if (i != B/i) bque.push(B/i);
    }
  }
  while (!aque.empty() && !bque.empty()) {
    if (aque.top() == bque.top()) {
      d.push_back(aque.top());
      aque.pop(); bque.pop();
    } else if (aque.top() > bque.top()) {
      aque.pop();
    } else {
      bque.pop();
    }
  }
  std::reverse(d.begin(), d.end());
  for (int i = 1; i < d.size(); ++i) {
    for (auto j = d.begin()+i+1; j < d.end(); ++j) {
      if ((*j) % d[i] == 0) {
        d.erase(j);
        --j;
      }
    }
  }
  std::cout << d.size() << std::endl;
  return 0;
}


Measured memory_bytes: 512
H,W =list(map(int,input().split(" ")))
mass  = []
for _ in range(H):
    mass.append(input() + "#")

mass.append((W+1)*"#")
tate = [[0 for _ in range(W+1)] for _ in range(H+1)]
yoko = [[0 for _ in range(W+1)] for _ in range(H+1)]
co = 0
for w in range(W+1):
    st = 0
    for h in range(H+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,h):
                tate[temp][w] = co
            st = h + 1
            co = 0
        else:
            co += 1

co = 0
for h in range(H+1):
    st = 0
    for w in range(W+1):
        c = mass[h][w]
        if c == "#":
            for temp in range(st,w):
                yoko[h][temp] = co
            st = w + 1
            co = 0
        else:
            co += 1



ans = 0
for h in range(H):
    for w in range(W):
        cand = tate[h][w] + yoko[h][w]
        if tate[h][w] > 0 and yoko[h][w] > 0:
            cand -= 1
        if cand > ans and mass[h][w] != "#":
            ans =  cand


print(ans)

Measured memory_bytes: 128600
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <tuple>
# include <unordered_map>
# include <numeric>
# include <complex>
# include <bitset>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
typedef pair<LL, LL> P;
constexpr int INF = 2000000000;
constexpr int HINF = INF / 2;
constexpr double DINF = 100000000000000000.0;
constexpr long long LINF = 9223372036854775807;
constexpr long long HLINF = 4500000000000000000;
constexpr long long MMOD = 500000004;
const double PI = acos(-1);
int dx[4] = { 0,1,0,-1 }, dy[4] = { 1,0,-1,0 };
# define ALL(x)      (x).begin(),(x).end()
# define UNIQ(c)     (c).erase(unique(ALL((c))), end((c)))
# define mp          make_pair
# define eb          emplace_back
# define FOR(i,a,b)  for(int i=(a);i<(b);i++)
# define RFOR(i,a,b) for(int i=(a);i>=(b);i--)
# define REP(i,n)    FOR(i,0,n)
# define INIT        std::ios::sync_with_stdio(false);std::cin.tie(0)

int a, b, c, x;

int main() {
	int ans = 0;
	cin >> a >> b >> c >> x;
	REP(i, a + 1) {
		REP(j, b + 1) {
			REP(k, c + 1) {
				if (500 * i + 100 * j + 50 * k == x)ans++;
			}
		}
	}
	cout << ans << endl;
}

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

int tbl[11] = { 0,0,10000,464,100,39,21,13,10,7,6 };

int sb(int a)
{
	int s = 0;
	while (a) {
		s += a % 10;
		a /= 10;
	}
	return s;
}

int main()
{
	int a, n, m;
	int x, y, lim, ans;

	scanf("%d%d%d", &a, &n, &m);
	lim = tbl[n] - a, ans = 0;
	for (y = 1; y <= lim; y++) {
		x = (int)pow(y + a, n);
		if (x > m) break;
		if (sb(x) == y) ans++;
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define loop(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
using ll = int64_t;
using P = pair<int, int>;

int main(){
    int n, m; cin >> n >> m;
    int h[n];
    rep(i, n) cin >> h[i];
    vector<int> obs[n];
    rep(i, m){
        int a, b; cin >> a >> b;
        a--; b--;
        obs[a].push_back(b);
        obs[b].push_back(a);
    }

    int ans = 0;
    rep(i, n){
        if(obs[i].empty()) ans++;
        else {
            bool flag = true;
            for(int num : obs[i]){
                if(h[i] <= h[num]) flag = false;
            }
            if(flag) ans++;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 9120
def solve(n,A):
    MOD = 10**9+7

    freq = [0 for i in range(n)]
    for x in A:
        freq[x] += 1

    ans = 1
    if n&1:
        if freq[0] != 1:
            return 0

    for pos in range(n//2):
        r = abs(pos-(n-1-pos))
        if freq[r]==0:
            ans = (ans*1)%MOD
        elif freq[r]==2:
            ans = (ans*2)%MOD
        else:
            return 0
    return ans

n = int(input())
A = [int(x) for x in input().split()]
print(solve(n,A))

Measured memory_bytes: 20012
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); ++i)
#define outl(x) cout<< (x) << '\n'
#define fi first
#define se second
using pii = pair<int,int>;
using ll = long long;
using vi = vector<int>;

int f(int len, int n)
{
    if (len <= n) return 1;

    int cnt = 1;
    for (int i=n; i < len; i += n-1) {
        ++cnt;
    }

    return cnt;
}

int main()
{
    cin.tie(0), ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    outl(f(n, k));
}



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

int a[5100],b[5100];
int main(){
	int i,j,n,m,x;
	
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		memset(b,0,sizeof(b));
		m=0;
		for(i=1;i<=n/2;i++){
			x=(i*i)%n;
			for(j=0;j<m;j++)if(a[j]==x)break;
			if(j==m)a[m++]=x;
		}
		for(i=0;i<m;i++){
			for(j=0;j<m;j++){
				if(i!=j){
					x=a[i]-a[j];
					if(x<0)x+=n;
					if(x>(n-1)/2)x=n-x;
					b[x]++;
				}
			}
		}
		for(i=1;i<=n/2;i++)printf("%d\n",b[i]);
	}
	
	return 0;
}

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

int main(){
    int a,b;
    while(scanf("%d %d",&a,&b) != EOF){
        int sum = a + b, cnt = (sum == 0 ? 1 : 0);
        while(sum > 0){
            sum /= 10;
            cnt++;
        }
        cout << cnt << endl;
    }

    return 0;
}


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


int main() {
	int N, M;
	cin >> N >> M;
 
	vector<vector<int>> adj(N);
	while (M--) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		adj[a].push_back(b);
	}
	
	vector<int> res;
    for (int s = 0; s < N; s++) {  // Loop for all vertices; s as the starting vertex.
		vector<int> pred(N, -1);
		queue<int> q;
		q.push(s);
 
		while (q.size()) {
			int i = q.front();
			q.pop();
			for (int j: adj[i]) {
				if (j == s) {
					vector<int> cur = {i};
					while (i != s) i = pred[i], cur.push_back(i);
					if (res.size() == 0 || cur.size() < res.size()) res = cur;
					while (q.size()) q.pop();
					break;
				}
				if (pred[j] != -1) continue;
				pred[j] = i;
				q.push(j);
			}
		}
	}
 
	if (res.size()) {
		cout << res.size() << endl;
		for (int x: res) cout << x + 1 << endl;
	} else {
		cout << -1 << endl;
	}

    return 0;
}

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

int main(){
	int N,M,p,count;
	vector<int> N_n(1500000,0),M_n(1500000,0);
	vector<int> N_s,M_s;
	while(cin>>N>>M,N){
		count=0;
		for(int i=0;i<N;i++){
			cin>>p;
			N_s.push_back(p);
		}
		for(int i=0;i<M;i++){
			cin>>p;
			M_s.push_back(p);
		}
		for(int i=0;i<N;i++){
			p=0;
			for(int j=i;j<N;j++){
				p+=N_s[j];
				N_n[p-1]++;
			}
		}
		for(int i=0;i<M;i++){
			p=0;
			for(int j=i;j<M;j++){
				p+=M_s[j];
				M_n[p-1]++;
			}
		}
		for(int i=0;i<1500000;i++){
			count+=M_n[i]*N_n[i];
			if(M_n[i]!=0||N_n[i]!=0)
			M_n[i]=N_n[i]=0;
		}
		cout<<count<<endl;
		N_s.clear();
		M_s.clear();


	}
	return 0;
}

Measured memory_bytes: 14256
import java.io.*;
import java.util.*;

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        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());
    }
}

public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        String str = in.next();
        char ch = str.charAt(0);
        if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
            System.out.println("vowel");
        } else {
            System.out.println("consonant");
        }
    }
}

Measured memory_bytes: 22228
N = gets.to_i
A = gets.split.map(&:to_i)
B = gets.split.map(&:to_i)
ans = 0
N.times do |i|
  if A[i] >= B[i]
    ans += B[i]
  else
    ans += A[i]
    B[i] -= A[i]
    if A[i + 1] >= B[i]
      ans += B[i]
      A[i + 1] -= B[i]
    else
      ans += A[i + 1]
      A[i + 1] = 0
    end
  end
end
puts ans

Measured memory_bytes: 17312
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n];
  int ans=0;
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]%2==0 && a[i]%3!=0 && a[i]%5!=0){
      ans=1;}}

  if(ans==0){
    printf("APPROVED\n");}
  else{
    printf("DENIED\n");}

  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const ll mod = 1e9+7;

ll factori(ll i){
  ll ans=1;
  while(i>1){
    ans*=i;
    ans%=mod;
    i--;
  }
  return ans;
}

int main(){
  ll N,M;cin>>N>>M;
  if(abs(N-M)>1) cout << 0 <<endl;
  else if(abs(N-M)==1){
    cout << factori(N)*factori(M)%mod << endl;    
  }
  else {
    cout << 2*factori(N)*factori(M)%mod << endl;
  }
}

Measured memory_bytes: 384
using System;
using System.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        this.Range = long.Parse(Reader.ReadLine());

        long ans = GetAns(1, this.Range);

        Console.WriteLine(ans);


        
    }

    private long Range = 0;

    private long GetAns(long min, long max)
    {
        if (max - min <= 1)
        {
            if (CanReach(min))
            {
                return min;
            }
            return max;
        }
        long mid = (min + max) / 2;
        if (CanReach(mid))
        {
            return GetAns(min, mid);
        }
        else
        {
            return GetAns(mid, max);
        }
    }

    private bool CanReach(long val)
    {
        return (val * (val + 1) / 2) >= this.Range;
    }



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


11


";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 11092
// Problem Code: abc177_c

#include <iostream>
#include <vector>

using namespace std;

int get_sum(int N, vector<int>& A) {
	int sum = 0, mod = 1e9 + 7;
	vector<int> prefix(N + 1);
	
	for (int i = 0; i < N; i++)
		prefix[i + 1] = (prefix[i] + A[i]) % mod;
	
	for (int i = 0; i < N - 1; i++) {
		long long inner_sum = (prefix[N] - prefix[i + 1] + mod) % mod;
		sum = (sum + A[i] * inner_sum) % mod;
	}
	
	return sum;
}

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	for (int i = 0; i < N; i++)
		cin >> A[i];
	cout << get_sum(N, A);
	return 0;
}

Measured memory_bytes: 4828
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1e9+7;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
    /*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
ll modpow(ll a,ll n, ll mod){ll res = 1;while(n>0){if (n%2==1){res = res * a % mod;}a = a * a % mod;n/=2;}return res;}
int main() {
    string s,t;
    cin >>s >>t;
    cout<<t+s<<endl;
}
    



Measured memory_bytes: 3596
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

const long long MOD = 1000000007;

int main(){
  string s;
  int ans = 0;
  cin>>s;
  for(int i=1; i<s.size(); i++) {
      int x = s.size()-i;
      if(x%2==0) {
	if(s.substr(0,x/2)==s.substr(x/2,x/2)) {
	  ans = x;
	  break;
	}
      } else if(x==1) {
	ans = x;
      }
  }
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repd(i,a,b) for (int i = (a); i < (b); i++)
#define INF LLONG_MAX
#define mod 1000000007
typedef long long ll;
int main(void)
{
	int H, A;
	cin >> H >> A;
	cout << (H+(A-1))/A << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#define rep(i,n)for(int i=0;i<n;i++)

using namespace std;

typedef long long ll;

int main()
{
    ll n;
    cin>>n;
    ll ans=1e18;
    for(ll i=1;i*i<=n;i++)
    {
        if(n%i!=0)continue;
        ll j=n/i;
        ans=min(ans,i+j-2);
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 256
n=int(input())
dp=[[0 for i in range(n+1)] for j in range(3)]
for i in range(1,n+1):
    a,b,c=map(int,input().split())
    dp[0][i]=max(dp[1][i-1]+a,dp[2][i-1]+a)
    dp[1][i]=max(dp[0][i-1]+b,dp[2][i-1]+b)
    dp[2][i]=max(dp[0][i-1]+c,dp[1][i-1]+c)
print(max(dp[0][n],dp[1][n],dp[2][n]))    


Measured memory_bytes: 14976
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <functional>
using namespace std;
#define int long long
#define All(v) (v).begin(),(v).end()
int dy[4] = {-1,0,1,0};
int dx[4] = {0,1,0,-1};
int Dy[8] = {-1,-1,0,1,1,1,0,-1};
int Dx[8] = {0,1,1,1,0,-1,-1,-1};
const int mod = 1000000007;
const int inf = mod*mod;
const int d5 = 100100;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s[3]={"Sunny","Cloudy","Rainy"};
    string a;
    cin>>a;
    for(int i=0;i<3;i++){
        if(s[i]==a)cout<<s[(i+1)%3]<<endl;
    }
}

Measured memory_bytes: 256
m=10**9+7
x=[[0,765144583,346175634,347662323,5655049,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286],[539588932,729548371,700407153,404391958,962779130,184117322,927321758,444014759,542573865,237315285,417297686,471090892,183023413,660103155,727008098,869418286]]
for _ in range(int(input())):
	n=int(input())
	print(sum([n**j*x[n&1][j]for j in range(16)])%m)

Measured memory_bytes: 71316
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
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; }
 
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  int n; cin>>n;
  
  if(n==3){
    cout<<"2 5 63"<<endl;
    return 0;
  }
  if(n==4){
    cout<<"2 5 20 63"<<endl;
    return 0;
  }
  
  int a,b;
  if(n%2==1){
    a=min((n/4-1)*4+3,9999);
    b=n-a;
  }else{
    a=min((n-1)/4*4,10000);
    b=n-a;
  }
  reps(i,a) cout<<3*i<<" ";
  int cnt=0, x=2;
  while(true){
    if(x%3==0){
      x+=2;
      continue;
    }else{
      cout<<x<<((cnt!=b-1) ? " ":"\n");
      if(cnt==b-1) break;
      else cnt++;
      x+=2;
    }
  }
}

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

int main()
{
	int A, B, C;
	//パネルの数字を設定
	cin >> A >> B >> C;
	int MaxNum;
	MaxNum = max({ A, B, C });
	int ans;
	ans = A + B + C + 9* MaxNum;
	cout << ans << endl;
}

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

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

    ll ans = a / __gcd(a, b) * b;

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


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

visited = [False for _ in range(N)]
now = 0

cycle = []

while True:
    cycle.append(now)
    visited[now] = True
    now = A[now] - 1

    if visited[now]:
        break

total_len = len(cycle)

cycle_start = 0

for i in range(total_len):
    if cycle[i] == now:
        cycle_start = i
        break

cycle_len = total_len - cycle_start

if K < cycle_start:
    print(cycle[K] + 1)
else:
    print(cycle[cycle_start + (K - cycle_start) % cycle_len] + 1)


Measured memory_bytes: 32380
/*...Part - 01...*/

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <queue>
#include <deque>
#include <iterator>
#include <bitset>
#include <assert.h>
#include <new>
#include <sstream>
//#include <bits/stdc++.h>
using namespace std ;

/*...Part - 02...*/

typedef long long               ll ;
typedef long double             ld ;
typedef unsigned long long      ull ;
typedef pair<int,int>           pii ;
typedef pair<ll,ll>             pll ;
typedef vector<int>             vi ;
typedef vector<ll>              vll ;
typedef vector<vector<int>>     vvi ;

int Int(){int x ; scanf("%d",&x) ; return x ;}
ll Long(){ll x ; scanf("%lld",&x) ; return x ;}

/*...Part - 03...*/
/*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl ;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

/*...Part - 04...*/
/*...Needed to change according to problem requirements...*/

const int N          = (int)2e5 + 5 ;
const int maxN       = (int)1e6 + 6 ;
const ll  Mod        = (ll)1e9 + 7 ;
const int inf        = (int)2e9 ;
const ll  Inf        = (ll)1e18 ;

/*..........................................................*/
/*...Part - 05...*/

#define     debug(x)    cerr << #x << " = " << x << '\n' ;
#define     rep(i,b,e)  for(__typeof(e) i = (b) ; i != (e + 1) - 2 * ((b) > (e))  ; i += 1 - 2 * ((b) > (e)))
#define     Int         Int()
#define     Long        Long()
#define     all(x)      x.begin() , x.end()
#define     sz(x)       (int)x.size()
#define     ff          first
#define     ss          second
#define     pb          push_back
#define     eb          emplace_back
#define     mem(a)      memset(a , 0 ,sizeof a)
#define     memn(a)     memset(a , -1 ,sizeof a)

/*...Part - 06...*/
/*...... ! Code start from here ! ......*/

const int max_n = 3003 ;

ll dp[max_n][max_n][2] ;
int a[max_n] ;

ll call(int l, int r, int person){
	if(l > r)return 0 ;
	ll& ret = dp[l][r][person] ;
	if(ret != -Inf)return ret ;
	if(!person){
		ret = call(l + 1, r, !person) + a[l] ;
		ret = max(ret, call(l, r - 1, !person) + a[r]) ;
	}
	else{
		ret = call(l + 1, r, !person) - a[l] ;
		ret = min(ret, call(l, r - 1, !person) - a[r]) ;
	}
	return ret ;
}

int main(){
    int test = 1 , tc = 0 ;
    while(test--){
        int n = Int ;
        for(int i = 0 ; i < n ; ++i)a[i] = Int ;
        for(int i = 0 ; i < n ; ++i)
    		for(int j = 0 ; j < n ; ++j)
        		for(int k = 0 ; k < 2 ; ++k)
        			dp[i][j][k] = -Inf ;
    	cout << call(0, n - 1, 0) << '\n' ;
    }
    return 0 ;
}

/*...Always look at the part - 04...*/
/*...............END................*/




Measured memory_bytes: 141184