akhauriyash/Code-Regression huggingface dataset:
use std::cmp::max;
use std::collections::HashMap;
use std::collections::HashSet;
use std::io::prelude::*;
fn main() {
    let stdin = std::io::stdin();
    let s: String = stdin
        .lock()
        .lines()
        .skip(1)
        .next()
        .expect("not two lines")
        .expect("read error");
    println!("{}", solve(&s.trim()));
}

fn solve(s: &str) -> u32 {
    let mut right: HashMap<char, u32> = HashMap::new();
    let mut left: HashSet<char> = HashSet::new();
    for c in s.chars() {
        let count = right.entry(c).or_insert(0);
        *count += 1;
    }
    let mut commons_max = 0;
    let mut commons = 0;
    for c in s.chars() {
        let right_count = right.get_mut(&c).unwrap();
        *right_count -= 1;
        if left.insert(c) {
            if *right_count > 0 {
                commons += 1;
                commons_max = max(commons, commons_max);
            }
        } else {
            if *right_count == 0 {
                commons -= 1;
            }
        }
    }
    commons_max
}


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

int main() {
	int N,K;
	int x[100000];
	cin >> N >> K;

	rep(i, N) cin >> x[i];

	int minimum = 300000001;
	rep(i, N) {
		if (i + K <= N) {
			int kari = abs(x[i]) + abs(x[i + K - 1] - x[i]);
			minimum = min(kari, minimum);
		}
		if (i - K + 1 >= 0) {
			int kari = abs(x[i]) + abs(x[i - K + 1] - x[i]);
			minimum = min(kari, minimum);
		}
	}
	cout << minimum << "\n";

	Would you please return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <list>
#include <cmath>
#include <iomanip>
using namespace std;

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

int main() {
    int N;
    cin >> N;
    int p[N];
    for(int i = 0; i < N; i++) cin >> p[i];
    int q[N];
    for(int i = 0; i < N; i++) {
        q[i] = p[i];
    }
    sort(p, p+N);
    int cnt = 0;
    for(int i = 0; i < N; i++) {
        if(q[i] != p[i]) {
            cnt++;
        }
    }
    if(cnt <= 2) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }
    return 0;
}

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

int main(int argc, char *argv[]) {
  int N;
  cin >> N;
  int X[N];
  int X_sorted[N];
  for(int i = 0; i < N; i++) {
    cin >> X[i];
    X_sorted[i] = X[i];
  }
  sort(X_sorted, X_sorted + N);
  int max_med = X_sorted[N / 2];
  int min_med = X_sorted[N / 2 - 1];
  for(int i = 0; i < N; i++) {
    if(X[i] <= min_med) {
      cout << max_med << endl;
    } else {
      cout << min_med << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3712
N_masu, M_exp, X_pos = map(int, input().split())
exp_pos = list(map(int, input().split()))

cos_1 = 0
cos_2 = 0

for i in range(M_exp):
    pos = exp_pos[i]
    
    if (pos <= X_pos):
        cos_1 += 1
    else:
        cos_2 += 1

print(min(cos_1,cos_2))

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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

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

    int n;
    cin >> n;

    vector<int> a;
    for(int i=0; i<n; i++){
        int t;
        cin >> t;
        a.pb(t);
    }

    vector<int> a1 = a;

    ll ans1 = 100;
    for(int i=0; i<n-1; i++){

        //printf("%d %d\n", a[i], i+1);
        if(a[i] == i+1){
            int t = a[i+1];
            a[i+1] = a[i];
            a[i] = t;
            ans1++;
        }
    }
    if(a[n-1] == n) ans1++;

    a = a1;

    ll ans2 = 0;
    for(int i=n-1; i>=1; i--){
        //printf("%d %d\n", a[i], i+1);
        if(a[i] == i+1){
            int t = a[i-1];
            a[i-1] = a[i];
            a[i] = t;
            ans2++;
        }
    }
    if(a[0] == 1) ans2++;

    cout << min(ans1, ans2) << endl;
    
    return 0;
}


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

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

    int num;
    map<int, int> a;
    for (int i = 0; i < n; i++) {
        cin >> num;
        a[num] = ((a[num] == 0) ? 1 : 0);
    }

    int cnt = 0;
    for (auto p : a) {
        cnt += p.second;
    }

    cout << cnt << endl;
    return 0;
}

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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	long long n;
	cin >> n;
	long long ans = 0;
	for (int i = 1; i < n; i++) {
		long long check = n - i;
		if (check / i <= i) break;
		if (check % i == 0) ans += check / i;
	}
	cout << ans << "\n";
}


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


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        
        Scanner sn = new Scanner(System.in);
        int N = sn.nextInt();
        int[] valueArray = new int[N];
        int[] costArray = new int[N];
        int maxValue = 0;
        
        for(int i = 0; i< N; i++) {
            valueArray[i] = sn.nextInt();
        }
        
        for(int i=0; i < N; i++){
            costArray[i] =sn.nextInt();
        }
        
        for(int i=0; i < N; i++){
            
            int diff = valueArray[i] - costArray[i];
            if(diff > 0){
                maxValue = maxValue + diff;
            }
        }
        System.out.println(maxValue);
        
    }
}

Measured memory_bytes: 22612
import java.util.Scanner;

class Node {
	int id;
	Node left, right;

	public Node(int id) {
		super();
		this.id = id;
	}

}

public class Main {

	static Node[] preorder, inorder;
	static int pre;
	static StringBuilder sb;

	public static int nextPre() {
		return preorder[pre++].id;
	}

	public static int find(int c, Node[] inorder, int l, int r) {
		for (int i = l; i < r; i++) {
			if (c == inorder[i].id) {
				return i;
			}
		}
		return -1;
	}

	public static void reconstruction(int l, int r, Node[] inorder) {
		if (l >= r) {
			return;
		}

		int c = nextPre();
		int m = find(c, inorder, l, r);

		reconstruction(l, m, inorder);
		reconstruction(m + 1, r, inorder);

		sb.append(c + " ");
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		preorder = new Node[n]; inorder = new Node[n];

		for (int i = 0; i < n; i++) {
			preorder[i] = new Node(sc.nextInt());
		}
		for (int i = 0; i < n; i++) {
			inorder[i] = new Node(sc.nextInt());
		}

		sb = new StringBuilder();
		reconstruction(0, n, inorder);
		sb.deleteCharAt(sb.length() - 1);
		System.out.println(sb.toString());
	}
}


Measured memory_bytes: 26432
#include <cstdio>
 
char c[15][15],d[15],e[15];
int i,m,n;
 
inline bool dfs2(int x)
{
    if (x>m)
        return true;
    if (e[x])
        return dfs2(x+1);
    else
    {
        int t=0,r=0;
        for (int i=x;i<=m;i++)
            if (! e[i])
                t++;
        for (int i=x;i<=m;i++)
            if (! e[i])
            {
                e[x]=i,e[i]=x,r=1;
                for (int j=1;j<=n;j++)
                    if ((c[j][x]!=c[d[j]][i]) || (c[d[j]][x]!=c[j][i]))
                    {
                        r=0;
                        break;
                    }
                if(i==x){
                    if(r&&(t&1)&&dfs2(x+1))return true;
                }
                else{
                    if(r){
                        if(dfs2(x+1))return true;else return false;
                    }
                }
                /*if ((r) && ((t&1) || (i!=x)) && (dfs2(x+1)))
                    return true;
                else if(i!=x)return false;*/
                e[x]=0,e[i]=0;
            }
    }
    return false;
}
 
inline bool dfs1(int x)
{
    if (x>n)
        return dfs2(1);
    if (d[x])
        return dfs1(x+1);
    else
    {
        int t=0;
        for (int i=x;i<=n;i++)
            if (! d[i])
                t++;
        for (int i=x;i<=n;i++)
            if (! d[i])
            {
                d[x]=i,d[i]=x;
                if (((t&1) || (i!=x)) && (dfs1(x+1)))
                    return true;
                d[x]=0,d[i]=0;
            }
    }
    return false;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
        scanf("%s",c[i]+1);
    if (dfs1(1))
        puts("YES");
    else
        puts("NO");
    return 0;
}

Measured memory_bytes: 128
n = int(input())
list_s = []
list_t = []
for i in range(0,n):
    list_s.append(str(input()))
m = int(input())
for i in range(0,m):
    list_t.append(str(input()))
ans = 0
for card in list_s:
    if ans < list_s.count(card) - list_t.count(card):
        ans = list_s.count(card) - list_t.count(card)
print(ans)


Measured memory_bytes: 3060
#include <iostream>

#define MAX_N 20
#define MAX_M 2015

int main(){
  int n,q,a[MAX_N],x;
  std::cin >> n;
  for(int i = 0 ; i < n ; i++){
    std::cin >> a[i];
  }
  bool dp[MAX_M] = {0}; dp[0] = true;
  for(int i = 0 ; i < n ; i++){
    for(int j = MAX_M-1 ; j >= 0 ; j--){
      if(dp[j] && j+a[i] < MAX_M){
        dp[j+a[i]] = true;
      }
    }
  }
  std::cin >> q;
  for(int i = 0 ; i < q ; i++){
    std::cin >> x;
    std::cout << (dp[x] ? "yes" : "no") << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define pb push_back
#define ll long long
#define f(i,a,b) for(int i=a;i<b;i++)
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
 
const int N = 1e5 + 5;
 
int32_t main()
{
	IOS;
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	std::vector<ll> arr;
	ll n,a,k,sum=0;cin>>n>>k;
	f(i,0,n){
		cin>>a;arr.pb(a);
	}
	sort(arr.begin(),arr.end());
	f(i,0,k){
		sum+=arr[i];
	}
	cout<<sum<<endl;

	return 0;
}

Measured memory_bytes: 3676
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scanner = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String input = scanner.nextLine();
        String[] numbers = input.split(" ");

        int numContest = Integer.parseInt(numbers[0]);
        int innerRating = Integer.parseInt(numbers[1]);
        if (numContest >= 10) {
            System.out.println(innerRating);
        } else {
            System.out.println(innerRating + 100 * (10 - numContest));
        }
    }

}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
int a[N],b[N];
int main()
{
    ft
    int t,i,j,n,m,l,r,z=0;
    cin>>n;
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    for(i=1;i<n;i++)
    {
        if(a[i]<=a[i-1])
        {
            b[i]=b[i-1]+1;
            z=max(z,b[i]);
        }
        else
        {
            b[i]=0;
        }
    }
    cout<<z<<"\n";
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
int N;
bool vis[50][100005];
deque<pair<int, int>> dq;
 
int main(){
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> N;
    dq.push_back({0, 0});
    bool isstart = 1;
    while(dq.size()){
        pair<int, int> p = dq.front();
        dq.pop_front();
        int s = p.first, m = p.second;
        int d = 0;
        if(isstart){
            d = 1;
        }
        for(; d<=9; d++){
            if(s + d < 50 && !vis[s+d][(m*10+d)%N]){
                vis[s+d][(m*10+d)%N] = 1;
                dq.push_back({s+d, (m*10+d)%N});
            }
        }
        isstart = 0;
    }
    int ans = 50;
    for(int i = 0; i<50; i++){
        if(vis[i][0]){
            ans = i;
            break;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 21176
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(ll i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(ll i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
ll gcd(ll a,ll b){
    return b==0?a:gcd(b,a%b);
}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}
bool solve(){
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    if(a<b){
        return false;
    }
    if(d<b){
        return false;
    }
    if(b<=c){
        return true;
    }
    ll g=gcd(b,d);
    return b-g+a%g<=c;
}
int main(){
    int _;
    cin>>_;
    REP(i,_){
        if(solve()){
            cout<<"Yes"<<endl;
        }else{
            cout<<"No"<<endl;
        }
    }
    return 0;
}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;
    cin >> s;
    reverse(ALL(s));
    OP(s);
    return 0;
}


Measured memory_bytes: 3068
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
using ll=long long;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    ll sum=0;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    //a[i]<=b[i]の場合はa[i]を1ずつ増やせるため問題なし
    //a[i]>b[i]はj(i以外)のa[j]を選んで2増やし、b[i]を1ずつa[i]
    //に近づける.つまり、a[i]+2<=b[i]となるiからのa[i]-b[i]の和S
    //を用いて,S/2回が行わなければいけない回数より多ければよい
    rep(i,n){
        if(a[i]>b[i])sum+=a[i]-b[i];
        else sum-=(b[i]-a[i])/2;
    }
    if(sum>0)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    return 0;
    }


Measured memory_bytes: 384
/* Author: Akkapaka Saikiran (@saikidon911) */
#include <bits/stdc++.h>
using namespace std;
using ll = long long; using vi = vector<int>; using vll = vector<long long>; 
using vvi = vector<vector<int> >; using vb = vector<bool>;
#define pb push_back
#define all(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
//////////////////////////////////////////
#define test(t) int t; cin>>t; while(t--)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
////////////////////////////////////////////
#define tki take_input 
#define tkii take_input<int>
template <typename T> void take_input(vector<T> &a,int sz){
	T t;rep(i,sz){cin>>t;a.pb(t);}}
#define prv print_vector
#define prvi print_vector<int> 
template <typename T> void print_vector(vector<T> v){
	rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl;}
/////////////////////////////////////////

int main(){
	fastio;

	int a,b,c,k; cin>>a>>b>>c>>k;

	while(b <= a){
		b *= 2;
		k--;
	}
	while(c <= b){
		c *= 2;
		k--;
	}

	if(k >= 0) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9 + 7;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w;
    cin >> h >> w;
    char a[h][w];
    ll dp[h][w];
    rep (i, h) {
        rep (j, w) {
            cin >> a[i][j];
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;
    rep (i, h) {
        rep (j, w) {
            if (i + 1 < h && a[i + 1][j] == '.') dp[i + 1][j] = (dp[i + 1][j] + dp[i][j]) % Inf;
            if (j + 1 < w && a[i][j + 1] == '.') dp[i][j + 1] = (dp[i][j + 1] + dp[i][j]) % Inf;
        }
    }
    cout << dp[h - 1][w - 1] % Inf << endl;

    return 0;
}



Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define M 200005
int fir,sec;
int A[M],n;
int B[M],m;
bool Mark[M];
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)scanf("%d",A+i);
	for(int i=n; i>=1; --i) {
		int res=0;
		for(int j=i; j<=n; j+=i)
			if(Mark[j])res^=1;
		if(res!=A[i]) {
			bool flag=1;
			for(int j=i; j<=n; j+=i)
				if(!Mark[j]) {
					Mark[j]=1;
					flag=0;
					B[++m]=j;
					break;
				}
			if(flag)return !puts("-1");
		}
	}
	printf("%d\n",m);
	for(int i=1; i<=m; i++)printf("%d\n",B[i]);
}



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

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

    vector<int> ans(n);
    ans[0] = b[0];
    for(int i=1; i<n-1; i++){
        ans[i] = min(b[i-1], b[i]);
    }
    ans[n-1] = b[n-2];

    int sum = 0;
    for(int i=0; i<n; i++){
        sum += ans[i];
    }

    cout << sum << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    string S;
    cin >> S;

    int count = 0;
    int length = S.length();

    for (int i = 0; i < length/2; i++) {
        if(S.at(i) != S.at(length-i-1)){
            count++;
        }
    }

    cout << count << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <cstring>
#include <iostream>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#define int long long
#define lowbit(x) (x &(-x))
#define me(ar) memset(ar, 0, sizeof ar)
#define mem(ar,num) memset(ar, num, sizeof ar)
#define rp(i, n) for(int i = 0, i < n; i ++)
#define rep(i, a, n) for(int i = a; i <= n; i ++)
#define pre(i, n, a) for(int i = n; i >= a; i --)
#define IOS ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
const int way[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
const int  INF = 0x3f3f3f3f3f3f3f3f;
const double PI = acos(-1.0);
const double EXP = 1e-8;
const ll   MOD = 1e9 + 7;
const int  N = 2e5 + 5;
int a, b, a1, a2, b1, b2, ans;
signed main()
{
    IOS;
    cin >> a >> b;
    if(!a || !b){
        cout << -1 << endl;
    }
    a1 = a / 0.08; a2 = (a + 1) / 0.08 + 1;
    b1 = b * 10; b2 = (b + 1) * 10 + 1;
    a1 = max(a1, b1); b1 = min(a2, b2);
    for(int i = a1; i < b1; i ++){
        a2 = i * 0.08;
        b2 = i * 0.1;
        if(a2 == a && b2 == b){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
N,K = map(int,input().split())
x = [0]*N
for i in range(K):
  d = int(input())
  l = list(map(int,input().split()))
  for i in l : x[i-1]+=1

count = 0
for i in x:
  if i == 0: count+=1
    
print(count)

Measured memory_bytes: 9124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll in_max = 1e18;

int main()
{
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++) cin >> arr[i];
  ll dp[n][n];
  ll res[n][n];
  for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) dp[i][j] = in_max;
  for(int i = 0; i < n; i++) dp[i][i] = 0;
  for(int i = 0; i < n; i ++){
    res[i][i] = arr[i];
    for(int j = i+1; j < n; j++){
        res[i][j] = arr[j] + res[i][j-1];
    }
  }

  for(int i = n - 2; i >= 0; --i)
  {
    dp[i][i] = 0;
    for(int j = i+1; j < n; j++)
    {
      if(j - i == 1) dp[i][j] = (arr[i]+arr[j])*1LL;
      for(int k = i; k < j; k++)
      {
        dp[i][j] = min(dp[i][j], dp[i][k]+ dp[k+1][j]+res[i][j]);
      }
    }
  }
  cout << dp[0][n-1] << endl;
  //for(int i = 0; i < 1; i++) for(int j = i; j < n; j++) cout << dp[i][j] << " " <<res[i][j] << endl;
}


Measured memory_bytes: 2688
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

def main():
    N = int(input())
    X = list(map(int,input().split()))

    ans = 0
    fact = [1]
    for i in range(1,N):
        fact.append(fact[-1]*i%MOD)
    inv_fact = [1] * N
    inv_fact[-1] = pow(fact[N - 1],MOD - 2,MOD)
    for i in range(N - 1,0,-1):
        inv_fact[i - 1] = inv_fact[i]*i%MOD
    
    cum = 0
    for i in range(N - 1):
        cum += fact[N - 1] * inv_fact[i + 1] * fact[i] % MOD
        cum %= MOD
        ans += cum * (X[i + 1] - X[i])
        ans %= MOD
    print(ans)
if __name__ == '__main__':
    main()

Measured memory_bytes: 15248
a,b,c=map(int,input().split())
k=int(input())
while a>=b and k!=0:
  k-=1
  b*=2
if a>=b:
  k=0
while b>=c and k!=0:
  k-=1
  c*=2
if a<b and b<c:
  print("Yes")
else:
  print("No")

Measured memory_bytes: 9184
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char
import qualified Data.Vector.Unboxed as U
import qualified Data.ByteString.Char8 as BS

main = do
  n <- readLn
  ws <- U.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  let wss = U.scanl' (+) 0 ws
      total = U.last wss
  print $ U.minimum $ U.map (\s -> abs (total - 2 * s)) wss


Measured memory_bytes: 508
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<ll> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(ll i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
int main()
{
	ll n;
	cin>>n;
	vi a(n),b(n),c(n);
	for0(i,n) cin>>a[i];
	for0(i,n) cin>>b[i];
	for0(i,n) cin>>c[i];
	sort(a.begin(),a.end());
	sort(c.begin(),c.end());
	ll x,y,ans=0;
	for0(i,n){
		x = lower_bound(a.begin(),a.end(),b[i])-a.begin();
		y = upper_bound(c.begin(),c.end(),b[i]) - c.begin();
		//cout<<x<<" "<<y<<nw;
		ans += (x)*(n-y);
		}
	cout<<ans<<nw;
	
	return 0;
}

Measured memory_bytes: 2560
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

struct Info
{
	int a, b;

	Info()
	{

	}

	Info(int x, int y)
	{
		a = x;
		b = y;
	}
};

int main()
{
	cin.tie(nullptr);
	ios::sync_with_stdio(false);


	int n;
	cin >> n;

	vector<Info> info(n);

	for (int i = 0; i < n; i++)
	{
		int x;
		cin >> x;

		info.at(i) = Info(i + 1, x);
	}

	sort(info.begin(), info.end(), [](const Info& a, const Info& b)
		{
			return a.b <  b.b;
		});



	for (int i = 0; i < n; i++)
	{
		cout << (i == 0 ? "" : " ") << info.at(i).a;
	}
	cout << endl;
}


Measured memory_bytes: 1664
#include <iostream>

using namespace std;

const int NMAX=1000*100+1;
int n,val,compteurs[NMAX];

int main(){
	
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> val;
		for(int aj=-1;aj<=1;aj++){
			compteurs[val+aj]++;
		}
	}
	int maximum=0;
	
	for(int val=0;val<NMAX;val++){ 
		if(compteurs[val]>maximum){
			maximum=compteurs[val];
		}
	}
	
	cout << maximum << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int mo=998244353,N=5050;
int ksm(int a,int b){
	int ans=1;
	while (b){
		if (b&1) ans=ans*a%mo;
		a=a*a%mo;
		b>>=1;
	}
	return ans;
}
int _2[N],fac[N],inv[N],k,n;
int C(int x,int y){return x<y?0:fac[x]*inv[y]%mo*inv[x-y]%mo;}
signed main(){
	scanf("%lld%lld",&k,&n);
	fac[0]=1;
	_2[0]=1;
	for (int i=1;i<=n+k;++i)
		fac[i]=fac[i-1]*i%mo,_2[i]=_2[i-1]*2%mo;
	inv[n+k]=ksm(fac[n+k],mo-2);
	for (int i=n+k-1;i>=0;--i)
		inv[i]=inv[i+1]*(i+1)%mo;	
	for (int i=2;i<=2*k;++i){
		int p=abs(k-i+1),ans=0,z=(k-p)/2;
		if (i&1){
			for (int j=0;j<=z;++j){
				(ans+=C(z,j)*_2[j]%mo*C(n+p-1,p+j-1)%mo)%=mo;
			}
		}else{
			for (int j=0;j<=z;++j){
				(ans+=C(z,j)*_2[j]%mo*(C(n+p-1,p+j-1)+C(n+p-2,p+j-1))%mo)%=mo;
			}		
		}
		printf("%lld\n",ans);
	}
}


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

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

    long long N;
    cin >> N;

    if (N == 0) {
        cout << 0 << endl;
        return 0;
    }

    vector<int> v;

    while (N != 0) {
        if (N % 2 != 0) {
            v.push_back(1);
            N --;
        } else {
            v.push_back(0);
        }
        N /= -2;
    }
    reverse(v.begin(), v.end());

    for (int i=0; i<v.size(); ++i) {
        cout << v[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
//
// Created by yamunaku on 2019/08/10.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int a,b;
    cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << 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)
#define REP(i,n)  FOR(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define SUM(a)  accumulate((a).begin(),(a).end(),0)
#define SORT(a) sort(ALL(a))
#define REV(a) reverse(ALL(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long ll;
const int INTINF = 1<<30;
const ll LLINF = 1LL<<62;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const int DX[8]={ 0, 1, 0,-1, 1, 1,-1,-1};
const int DY[8]={ 1, 0,-1, 0, 1,-1, 1,-1};

int check(string S,int i,vector<char> T,vector<char>D){
    REP(j,T.size()){
        if (S[i]==T[j]){
            if (D[j]=='L'){
                i--;
            }else{
                i++;
            }
        }
    }
    return i;
}


int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  string S;
  cin >> S;
  char t, d;
  vector<char> T,D;
  S = "#" + S + "#";
  REP(i,q){
      cin >> t >> d;
      T.push_back(t);
      D.push_back(d);
  }
  //cout << S << endl;
  int ans = 0;
    int right = n+1;
    int left = 1;
    int mid = 0;

    while(left<right){
        mid = (left+right)/2;
        if(check(S,mid,T,D)==0){
            left = mid+1;
        }else
        {
            right = mid;
        }
    }

    ans -= left;
    right = n+1;
    left = 1;
    mid = 0;
    while(left<right){
        mid = (left+right)/2;
        if(check(S,mid,T,D)!=(n+1)){
            left = mid+1;
        }else
        {
            right = mid;
        }
    }

    ans += right;
    // FOR(i,1,n+1){
    //     cout << check(S,i,T,D) << " ";
    // }
    cout << ans << endl;
}


Measured memory_bytes: 1640
import sys
sys.setrecursionlimit(10**9)
def input():
	return sys.stdin.readline()[:-1]

EPS = 1e-10
k, L, R = map(int, input().split())
p = float(input())
e = float(input())
t = float(input())

def search(l, r, prob, depth):
	#print(l, r, prob, depth) 
	if depth == k:
		h = (l+r)/2
		if abs(h-t) + EPS < e:
			return prob
		else:
			return 0
	else:
		if l - EPS > t + e or r + EPS < t - e:
			return 0
		elif l + EPS > t - e and t + e > r - EPS:
			return prob
		else:
			h = (l+r)/2
			if h >= t:
				return search(h, r, prob * p, depth+1) + search(l, h, prob * (1-p), depth+1)
			else:
				return search(h, r, prob * (1-p), depth+1) + search(l, h, prob * p, depth+1)

ans = search(L, R, 1, 0)
print('{:.12f}'.format(ans))


Measured memory_bytes: 5636
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define int long long

signed main(){
    string S;
    char a,b,c;
    cin >>S;
    for(int i=-1;i<=1;i+=2){
        for(int j=-1;j<=1;j+=2){
            for(int k=-1;k<=1;k+=2){   
                if((S[0]-'0')+(S[1]-'0')*i+(S[2]-'0')*j+(S[3]-'0')*k==7){
                  	if(i==1){
                        a='+';
                    }
                    if(i==-1){
                        a='-';
                    }
                    if(j==1){
                        b='+';
                    }
                    if(j==-1){
                        b='-';
                    }
                    if(k==1){
                        c='+';
                    }
                    if(k==-1){
                        c='-';
                    }
                }
            }
        }
    }
    cout<<S[0]<<a<<S[1]<<b<<S[2]<<c<<S[3]<<"=7"<<endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> P;

template <typename T>
struct BIT
{
    int n;
    vector<T> bit;
    
    BIT(){}
    
    BIT(int n) : n(n){
        bit.resize(n + 1);
    }
    
    T sum(int i){
        i++;
        T res = 0;
        while(i){
            res += bit[i];
            i -= (i & -i);
        }
        return res;
    }
    
    void add(int i, T x){
        i++;
        while(i <= n){
            bit[i] += x;
            i += (i & -i);
        }
    }
};

int main()
{
    int n;
    cin >> n;
    int a[20][2];
    for(int i = 0; i < n; i++) cin >> a[i][0];
    for(int i = 0; i < n; i++) cin >> a[i][1];
    int ans = 10000000;
    for(int b = 0; b < (1 << n); b++){
        P p[20];
        for(int i = 0; i < n; i++){
            p[i] = P(a[i][(b >> i) & 1], i);
        }
        sort(p, p + n);
        BIT<int> bit(60);
        int s = 0;
        bool f = true;
        for(int i = 0; i < n; i++){
            s += i - bit.sum(p[i].second);
            bit.add(p[i].second, 1);
        }
        for(int i = 0; i < n; i++){
            if(abs(i - p[i].second) % 2 != ((b >> p[i].second) & 1)){
                bool g = false;
                for(int j = i + 1; j < n; j++){
                    if(p[i].first != p[j].first) break;
                    if(abs(i - p[j].second) % 2 == ((b >> p[j].second) & 1)){
                        g = true;
                        s += j - i;
                        int t = p[j].second;
                        for(int k = j; k > i; k--){
                            p[k].second = p[k - 1].second;
                        }
                        p[i].second = t;
                        break;
                    }
                }
                if(!g){
                    f = false;
                    break;
                }
            }
        }
        if(f) ans = min(ans, s);
    }
    if(ans == 10000000) cout << -1 << endl;
    else cout << ans << endl;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.math;

void main() {
	auto input = getStdin!(int[])()[0];
	
	auto result = pow(input, 3);
	result.writeln;
}

T getStdin(T)() {
	string[] cmd;
	string line;
	while ((line = chomp(stdin.readln())) != "") cmd ~= line;
	return to!(T)(cmd);
}

Measured memory_bytes: 2420
using System;

class Program
{
  static void Main()
  {
    var str = Console.ReadLine();
    var l = str.Length;
    var a = 0;
    var z = l;
    for (int i=0; i<l; i++)
    {
      if (str[i]=='A') { a=i; break;}
    }
    for (int j=l-1; j>0; j--)
    {
      if (str[j]=='Z') { z=j; break;}
    }
    Console.WriteLine(z-a+1);
  }
}


Measured memory_bytes: 13664
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = ll(1e12);
const ll mod = ll(1e9+7);
const double pi = acos(-1);
#define rep0(i,n) for(ll (i) = 0; (i) < (n); ++(i))
#define rrep0(i,n) for(ll (i) = (n) - 1; (i) >= 0; --(i))
#define rep1(i,n) for(ll (i) = 1; (i) <= (n); ++(i))
#define rrep1(i,n) for(ll (i) = (n); (i) >= 1; --(i))
#define nfor(i,a,b) for(ll (i) = (a); (i) < (b); ++(i))
#define pf(x) cout << (x) << endl
#define all(x) (x).begin(),(x).end()
#define yes pf("Yes")
#define no pf("No")
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};

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

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

ll factorial(ll n){
    ll ans = 1;
    rep1(i, n){
        ans *= i;
        ans %= mod;
    }
    return ans;
}

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

//modの値の確認をすること
int main(){
    ll n;
    cin >> n;
    bool f = false;
    rep0(i, n){
        ll a;
        cin >> a;
        if(a % 2 == 1)f = true;
    }
    pf(f? "first":"second");
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int h, w;
	cin>>h>>w;
	int a[10][10];
	for(int i = 0; i<10 ;i++)
		for(int j = 0; j<10; j++)
			cin>>a[i][j];

	for(int k = 0; k<10 ;k++)
		for(int i = 0; i<10; i++)
			for(int j = 0; j<10; j++)
				a[i][j] = min(a[i][j], a[i][k]+a[k][j]);

	int b[h][w];
	for(int i = 0; i<h; i++)
		for(int j= 0 ; j<w; j++)
		{
			cin>>b[i][j];
			if(b[i][j]==-1) b[i][j] = 0;
			else
				b[i][j] = a[b[i][j]][1];
		}
	ll sum = 0;
	for(int i = 0; i<h; i++)
		for(int j =0 ;j<w; j++)
			sum += b[i][j];
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch SumOfGcdOfTuplesEasy | diff SumOfGcdOfTuplesEasy.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address SumOfGcdOfTuplesEasy.cpp && ./a.out

/*
 
 4/12/2020
 
 5:07-
 
 */

LL K;

LL gcd(LL a, LL b) { return b==0?a:gcd(b,a%b); }
void solve() {
  LL res=0;
  FORE(a,1,K)FORE(b,1,K)FORE(c,1,K) res+=gcd(gcd(a,b),c);
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>K;
  solve();
  
  return 0;
}


Measured memory_bytes: 3648
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
const LL INF=1e18;
const int MAXN=2e5+100;
const double eps=1e-10;
bool vi[MAXN];

int main()
{
    int n,m;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        int u,v;
        bool flag=false;
        for(int i=1;i<=n;i++)
            vi[i]=false;
        for(int i=1;i<=m;i++)
        {
            scanf("%d%d",&u,&v);
            if(flag) continue;
            if(u==1)
            {
                if(vi[v])
                {
                    flag=true;
                }
                vi[v]=true;
            }else if(v==n)
            {
                if(vi[u])
                {
                    flag=true;
                }
                vi[u]=true;
            }
        }
        if(flag) 
            cout<<"POSSIBLE";
        else 
        cout<<"IMPOSSIBLE";
    }
    return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        String w = input.readLine();

        boolean[] checkedArr = new boolean[w.length()];
        boolean isBeautiful = true;


        for (int i = 0; i < w.length(); i++) {
            int testChar = w.charAt(i);
            int count = 0;
            for (int j = 0; j < w.length(); j++) {
                if (testChar == w.charAt(j)) {
                    count += 1;
                }
            }

            if (!isEven(count)) {
                isBeautiful = false;
                break;
            }
        }

        if (isBeautiful) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    private static boolean isEven(int n) {
        return n % 2 == 0;
    }
}

Measured memory_bytes: 22356
#include <stdio.h>
#include <string.h>

void addstr(char *str1, char *str2)
{
	char temp[1000];
	int max;
	int i;
	
	if (strlen(str1) > strlen(str2)){
		max = strlen(str1);
	}
	else {
		max = strlen(str2);
	}
	
	memset(temp, '\0', 1000);
	strcpy(&temp[max - strlen(str1) + 1], str1);
	i = 0;
	while (temp[i] == '\0'){
		 temp[i] = '0';
		 i++;
	}
	strcpy(str1, temp);
	
	memset(temp, '\0', 1000);
	strcpy(&temp[max - strlen(str2) + 1], str2);
	i = 0;
	while (temp[i] == '\0'){
		 temp[i] = '0';
		 i++;
	}
	strcpy(str2, temp);
	
	for (i = max; i >= 0; i--){
		str1[i] += str2[i] - '0';
		if (str1[i] > '9'){
			str1[i] -= 10;
			str1[i - 1] += 1;
		}
	}
	if (str1[0] == '0'){
		memset(temp, '\0', 1000);
		strcpy(temp, &str1[1]);
		memset(str1, '\0', 1000);
		strcpy(str1, temp);
	}
}

int main(void)
{
	char str[1000], str2[1000];
	int n;
	
	scanf("%d", &n);
	
	while (n-- != 0){
		memset(str, '\0', 1000);
		memset(str2, '\0', 1000);
		
		scanf("%s", str);
		getchar();
		scanf("%s", str2);
		getchar();
		
		addstr(str, str2);
		
		if (strlen(str) < 81){
			printf("%s\n", str);
		}
		
		else {
			printf("overflow\n");
		}
	}
	
	return (0);
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

vector < vector < int > > arr;
int cache[100010];

int dfs(int i)
{
    int &res = cache[i];
    if(res != -1)
        return res;
    
    int maxele = 0;
    for(int it : arr[i])
        maxele = max(maxele, dfs(it) + 1);
        
    return res = maxele;
}

int main()
{
    fastIO
    int n, m;
    cin >> n >> m;
    
    memset(cache, -1, sizeof(cache));
    
    arr = vector < vector < int > >(n + 1);
    for(int i = 0; i < m; ++i)
    {
        int u, v;
        cin >> u >> v;
        
        arr[u].push_back(v);
    }
    
    int maxele = 0;
    for(int i = 1; i <= n; ++i)
        maxele = max(maxele, dfs(i));
    
    cout << maxele;

    return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#define lld long long
#define pb push_back
#define mk make_pair
#define MAX (lld)1e18+7
#define lim (lld)1e9+7
#define MAX2 (lld)2e5+9
#define ff first
#define ss second
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

const lld mod=lim;

lld power(lld x, lld y, lld p)  
{   lld res = 1;     x = x % p; if (x == 0) return 0;  
  
    while (y > 0)  
    { if (y & 1) res = (res*x) % p;  y = y>>1; x = (x*x) % p;   }  
    return res;  } 


lld extend_gcd(lld a, lld b, lld& x, lld& y) {
    if (b == 0) { x = 1;y = 0;return a;}
    lld x1, y1;
    lld d = extend_gcd(b, a % b, x1, y1);
    x = y1; y = x1 - y1 * (a / b);return d;	}

lld rowNum[]={-1,0,0,1};
lld colNum[]={0,-1,1,0};

std::vector<lld> v[MAX2];
std::vector<bool> vis(MAX2);
std::vector<bool> vis2(MAX2);
std::vector<lld> depth(MAX2);

lld cycver;
lld n,k;


void dfs(lld u)
{
	if(vis[u]) return;

	vis[u]=1;

	for(lld i:v[u])
	{
		if(!vis[i])
		{
			depth[i]=depth[u]+1;
			dfs(i);
		}	
		else
			cycver=i;
	}
}

lld len=1;

void dfs2(lld u)
{
	if(vis2[u]) return;

	vis2[u]=1;

	for(lld i:v[u])
	{
		if(!vis2[i])
		{
			depth[i]=depth[i]-depth[cycver];
			len++;
			dfs2(i);
		}	
	}
}

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

	for(lld i=1;i<=n;i++)
	{
		lld x;
		cin>>x;
		v[i].pb(x);
	}

	dfs(1);

	for(lld i=1;i<=n;i++)
	{
		if(vis[i] && depth[i]==k)
		{
			cout<<i<<endl;
			return 0;
		}	
	}

	k=k-depth[cycver];
	dfs2(cycver);
	depth[cycver]=0;
	k=(k%len+len)%len;

	for(lld i=1;i<=n;i++)
	{
		if(vis2[i]==1 && depth[i]==k)
		{
			cout<<i<<endl;
			return 0;
		}	
	}
}

Measured memory_bytes: 25092
#include <bits/stdc++.h>
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 27;

string a[MAX_N][MAX_N];

int main()
{
	int n,m;
	cin >> n >> m;
	rep(i,n){
		rep(j,m){
			cin >> a[i][j];
		}
	}
	rep(i,n){
		rep(j,m){
			if(a[i][j] == "snuke"){
				cout << (char)('A' + j) << i+1 << "\n";
				break;
			}
		}
	}
}

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

typedef long long ll;
typedef long double ld; 
typedef double db; 
typedef string str; 

typedef pair<int, int> pi;
typedef pair<ll,ll> pl; 
typedef pair<ld,ld> pd; 

typedef vector<int> vi; 
typedef vector<ll> vl;
typedef vector<ld> vd; 
typedef vector<str> vs; 
typedef vector<pi> vpi;
typedef vector<pl> vpl; 

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)

#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound 
#define ub upper_bound 

const int MOD = 998244353;
const ll INF = 1e18;
const int MX = 1000001;

int N;
str S;

int main() {
	cin.sync_with_stdio(0); cin.tie(0);
    cin >> N >> S;
    int ans = 0;
    F0R(i, N - 2) {
        ans += (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C');
    }
    cout << ans;
    return 0;
    // You should actually read the stuff at the bottom
}

/* Stuff to Look For
 * -----------------
 * Int overflow, array bounds
 * Initializing all variables, avoid weird behavior
 * Edge cases(n = 0, n = 1)
 * Just return 0 after result
 */


Measured memory_bytes: 256
using System;
    using System.Text;
    using System.Collections.Generic;
    using static System.Math;
    using System.Linq;
    using static System.Array;

    namespace ConsoleApp2
    {
        class Program
        {


            static void Main(string[] args)
            {
            var a = long.Parse(Console.ReadLine());
            var b = long.Parse(Console.ReadLine());
            var h = long.Parse(Console.ReadLine());
            //var AB = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToArray();


                Console.WriteLine(h*(a+b)/2);
            }
        }
    }


Measured memory_bytes: 11092
#include<iostream>
#include<vector>
#include<string>

using namespace std;

string S;

int main() {
	cin >> S;
	int N = (int)S.size();
	vector<int> ans(N, 1);
	int left = 0, right = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'L' && S[i - 1] == 'R') {
			left = i;
			ans[i] += ans[i - 1] / 2;
			ans[i - 1] = ans[i - 1] / 2 + ans[i - 1] % 2;
		}
		else if (S[i] == 'L' && S[i - 1] == 'L') {
			if ((i - left) % 2 == 0) {
				ans[left] += ans[i];
			}
			else {
				ans[left - 1] += ans[i];
			}
			ans[i] = 0;
		}
		else if (S[i] == 'R' && S[i + 1] == 'R') {
			right = i + 1;
			ans[right] += ans[i];
			ans[i] = 0;
		}
	}

	for (int i = 0; i < N; i++) {
		cout << ans[i] << " " << flush;
	}
	cout << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <queue>
#include <set>
#include <cstdlib>

using namespace std;
typedef long long int ll;

bool debug = false;
#define show(x) if (debug) {cout << "" # x << " = " << x << endl;}
#define rep(x, a, b) for (int x = a; x < b; x++)

int main()
{
  string pohe = "CODEFESTIVAL2016", fuga;

  cin >> fuga;

  int cnt = 0;

  rep (i, 0, (int)pohe.size()) {
    cnt += pohe[i] != fuga[i];
  }

  cout << cnt << endl;    
  
  return 0;
}


Measured memory_bytes: 256