akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;

class Program
{
	//Main
	static void Main(string[] args)
	{
		//出力準備（AutoFlushを切る）
		var sw = new StreamWriter(Console.OpenStandardOutput()){AutoFlush = false};
		Console.SetOut(sw);
		//解答
		Solve();
		//出力終了
		Console.Out.Flush();
	}

	static void Solve(){
		//読み込む
		int N = int.Parse(Console.ReadLine());
		long[] An = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

		//貪欲に最適な手段を取っていく
		//（i日目後半とi+1日目前半とをセットにするのがポイント）
		long money = 1000;
		long stock = 0;
		for(int i=0; i<N-1; i++){
			//翌日、株価が下がる場合
			if(An[i] > An[i+1]){
				//今のうちに全部売っておき、次回は買う
				//売る（i日目）
				money += (stock * An[i]);
				stock = 0;
				//買う（i+1日目）
				stock += money / An[i+1];
				money = money % An[i+1];
			}
			//そうではない場合
			else{
				//買えるだけ買った後、次回売る
				//買う（i日目）
				stock += money / An[i];
				money = money % An[i];
				//売る（i+1日目）
				money += (stock * An[i+1]);
				stock = 0;
			}

			//debug
			//Console.WriteLine("{0}日目,money={1},stock={2}",i+1,money,stock);
		}

		//最後に、全て換金
		money += (stock * An[N-1]);

		//答え
		Console.WriteLine(money);
	}
}


Measured memory_bytes: 18976
import sys
input = sys.stdin.readline

S = input().strip()
m = int(input())

for _ in range(m):
    ope = input().strip().split()
    a, b = int(ope[1]), int(ope[2])
    if ope[0] == "print":
        print(S[a:b+1])
    elif ope[0] == "reverse":
        S = S[:a] + S[a:b+1][::-1] + S[b+1:]
    elif ope[0] == "replace":
        S = S[:a] + ope[3] + S[b+1:]


Measured memory_bytes: 5620
from collections import defaultdict
import sys

input = sys.stdin.buffer.readline
h, w, n = map(int, input().split())
count = defaultdict(int)
# 3＊3の左上の位置でカウント
for i in range(n):
    a, b = map(int, input().split())
    for s in range(3):
        if a + s - 2 < 1 or a + s - 2 > h - 2:
            continue
        for t in range(3):
            if b - 2 + t < 1 or b - 2 + t > w - 2:
                continue
            count[(a - 2 + s, b - 2 + t)] += 1
ans = [0] * 10
for key, val in count.items():
    ans[val] += 1
ans[0] = (h - 2) * (w - 2) - sum(ans[1:])
print(*ans, sep="\n")


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

typedef long long ll;

const int N = 21;
int n, sum;
int c[N], v[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
    }
    for (int i = 0; i < n; ++i) {
        int d = v[i] - c[i];
        if (d > 0)
            sum += d;
    }
    cout << sum << endl;

    return 0;
}



Measured memory_bytes: 3604
s = input().rstrip()

odd = 'RUD'
even = 'LUD'

for i in range(len(s)):
    if i % 2 == 0:
        if s[i] not in odd:
            print('No')
            exit(0)
    else:
        if s[i] not in even:
            print('No')
            exit(0)
print('Yes')

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
int x[100];
int main() {
	int N, K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) cin >> x[i];
	int sum = 0;
	for (int i = 0; i < N; i++) {
		sum += min(x[i], abs(x[i] - K)) * 2;
	}
	cout << sum << endl;
}

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

int main(){
  int n, m, a[1002], sum=0;
  int i, j;
  scanf("%d%d", &n, &m);
  for(i=0; i<n; i++){
    scanf("%d", &a[i]);
    sum += a[i];
  }
  for(i=0; i<n-1; i++){
    for(j=n-1; j>i; j--){
      if(a[j] > a[j-1]){
	int t = a[j];
	a[j] = a[j-1];
	a[j-1] = t;
      }
    }
  }
  for(i=0; i<m; i++){
    if((double)a[i] < (double)(sum*1.0/4/m)){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
using namespace std;

int main() {
	#ifdef LOACL
	freopen("in.txt","r",stdin);
	freopen("out.txt","w",stdout);
	#endif 
	double a,b;
	scanf("%lf %lf",&a,&b);
	printf("%lf\n",a/b);
	return 0;
}

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

#define MAXN 100100
int n,a[MAXN],dp[MAXN];

int main (){
    cin >> n;
    for (int i=0;i<n;++i){
        cin >> a[i];
    }
    for (int i=0;i<n;++i){
        if (i==1){
            dp[i]=abs(a[i]-a[0]);
        }
        if (i>1){
            dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
    }
    cout << dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define  rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef vector<int> vi;
typedef long int li;
typedef unsigned long long ull;


int main(int argc,char* argv[])
{
    string S;
    cin>>S;
    int L=S.size(),ans=0;
    rep(i,L-1) if(S[i]!=S[i+1]) ans++;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

int main(){
   int n,t;
   cin >> n >> t;
   vector<int> v(n,0);
   ll sum=0;
   ll now=0;
   now=t;
   sum=t;
   ll s;
   cin >> s;
   rep(i,n-1){
     int tmp;
     cin >> tmp;
     if (now < tmp) {
       sum+=t;
       now=tmp+t;
     }
     else{
        sum+=(tmp+t)-now;
        now=tmp+t;
     }
   }
   cout << sum << endl;
   return 0;
}



Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	int n,m;
	cin>>n>>m;
	cout<<pow(2,m)*(1800*m+100*n)<<endl;
	return 0;
}

Measured memory_bytes: 512
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>
#include <random>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

int main() {
	int N,K;
	cin >> N >> K;
	if(N==K){
		cout << 1 << endl;
		return 0;
	}
	cout << (N-K-1)/(K-1)+2 << endl;

	return 0;
}



Measured memory_bytes: 256
#include "iostream"
#include "string"


int main()
{
	int W, H;
	char rect[300][300];

	while (true) {
		std::cin >> H >> W;

		if (W == 0 && H == 0)
			break;

		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++)
				rect[i][j] = '.';

		for (int i = 0; i < H; i++)
			for (int j = 0; j < W; j++) {
				rect[0][j] = '#';
				rect[i][0] = '#';
				rect[H-1][j] = '#';
				rect[i][W-1] = '#';
			}

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				std::cout << rect[i][j];
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3128
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
# import statistics
import bisect
import copy
import fractions
import math
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) 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 MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers):
    return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers):
    return reduce(LCM, numbers)
def LCM(m, n):
    return (m * n // fractions.gcd(m, n))
def unite(x, y):
    # それぞれのノードの根を求める
    x = root(x)
    y = root(y)
    if x == y:
        return
    # node[x]の根をyに変更する
    node[x] = y
def same(x,y): return bool(root(x) == root(y))
def root(x):
    if node[x] == x:  # xが根の場合
        return x
    else:
        node[x] = root(node[x])  # 経路圧縮
        return node[x]
def dfs(v):
    # ノードに訪れた
    visited[v] = True
    for v2 in range(n):
        if graph[v][v2] == False:  # そもそもvとv2が辺でつながっていない
            continue
        if visited[v2] == True:  # もう見た
            continue
        dfs(v2)

n , k = MI()
ans = []
s = IS()
for i, st in enumerate(s):
    if i+1 == k:
        ans.append(st.lower())
    else:
        ans.append(st)
print(''.join(ans))





Measured memory_bytes: 67180
#include <stdio.h>

int main() {
  int X,sum=0;
  scanf("%d",&X);
  if(X/500!=0) {
    sum+=(X/500)*1000;
    X = X%500;
  }
  if(X/5!=0) {
    sum+=(X/5)*5;
    X = X%5;
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 1736
/***********************************************************
	When you are inspired by passion 
	and you want to live for the current moment

	When your every thought and action
	has the power to become the story of your future

	When difficulties stand to demolish your Glory
	Just remember that Life is a 'Golden adverse Story'

	Withstand it to acheive your passion and dreams
	more amazingly more easily.

	Why then? When writing the story of your Life
	You want to Let someone else hold your pen

					huzaifa242©

***********************************************************/
#include "bits/stdc++.h"
using namespace std;
#define int int32_t
#define MAX 100005
#define x first 
#define y second

int seed;
mt19937 rng(seed=chrono::steady_clock::now().time_since_epoch().count());
inline int rnd(int l = 0, int r = numeric_limits <int>::max())
{return uniform_int_distribution<int> (l, r)(rng);}

template <typename T, typename G>
ostream& operator << (ostream& out, const pair <T, G> &a) 
{return out << "( " << a.x << ", " << a.y << ")";}

template <typename T>
ostream& operator << (ostream& out, const vector <T> &a) 
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

template <typename T>
ostream& operator << (ostream& out, const set <T> &a) 
{out << "{ "; for(const auto &i: a) out << i << ", "; return out << "}" << endl;}

template <typename T, typename G>
ostream& operator << (ostream& out, const map <T, G> &a) 
{out << "< "; for(const auto &i: a) out << i << ", "; return out << ">" << endl;}

template <typename T, size_t N>
typename enable_if<!is_same <typename remove_cv <T>::type, char>::value,
ostream&>::type operator << (ostream& out, T (&a)[N])
{out << "[ "; for(const auto &i: a) out << i << ", "; return out << "]" << endl;}

void debug_out(){cerr << endl;} 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{cerr << (H) << ' '; debug_out(T...);}
 
#ifdef LOCAL
#define debug(...) cerr << '#' << #__VA_ARGS__ << ":\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 24
#endif

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int n, k;
	cin >> n >> k;
	vector <int> a(n);
	for (int i = 0; i < n; ++i) 
		cin >> a[i];
	vector <long double> lg;
	long double cur = 0;
	for (int i = 0; i < k; ++i) {
		cur += (long double)log(a[i]);
	}
	lg.push_back(cur);
	for (int i = k; i < n; ++i) {
		cur -= (long double)log(a[i - k]);
		cur += (long double)log(a[i]);
		lg.push_back(cur);
	}
	for (int i = 0; i < lg.size() - 1; ++i) {
		if (lg[i + 1] > lg[i])
			cout << "Yes\n";
		else
			cout << "No\n"; 
	}
	return 0;
}


Measured memory_bytes: 8580
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Competitive
{
    internal class Solution
    {
        public int N, K;
        public string S;
        public long MOD = 1000000007;

        public void Run()
        {
            {
                var line = Input.ReadIntArray();
                N = line[0];
                K = line[1];
            }

            S = Console.ReadLine();

            List<int> lst = new List<int>();

            {
                int last = '1';
                int i = 0;
                int c = 0;
                while (true)
                {
                    if (last != S[i])
                    {
                        lst.Add(c);
                        last = S[i];
                        c = 1;
                    }
                    else
                    {
                        c++;
                    }

                    i++;

                    if (i == N)
                    {
                        lst.Add(c);
                        if (last == '0')
                        {
                            // 1で終わるようにする
                            lst.Add(0);
                        }
                        break;
                    }
                }
            }

            Console.WriteLine(Calc(lst));
          
        }

        int Calc(List<int> lst)
        {
            int N = lst.Count;
            int[] S = new int[N];
            for (int i = 0; i < N; i++)
            {
                S[i] = lst[i] + (i == 0 ? 0 : S[i - 1]);
            }

            int ret = 0;
            for (int i = 0; i < N; i += 2)
            {
                int sl = i == 0 ? 0 : S[i - 1];
                int r = Math.Min(lst.Count - 1, i + 2 * K);
                int sr = S[r];
                ret = Math.Max(ret, sr - sl);
            }

            return ret;
        }
    }

    // libs ----------
    

    // common ----------

    internal static class Input
    {
        public static string ReadString()
        {
            string line = Console.ReadLine();
            return line;
        }

        public static int ReadInt()
        {
            string line = Console.ReadLine();
            return int.Parse(line);
        }

        public static int[] ReadIntArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(int.Parse).ToArray();            
        }

        public static long ReadLong()
        {
            string line = Console.ReadLine();
            return long.Parse(line);
        }

        public static long[] ReadLongArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(long.Parse).ToArray();
        }

        public static double[] ReadDoubleArray()
        {
            string line = Console.ReadLine();
            return line.Split(' ').Select(double.Parse).ToArray();
        }
    }
    
    internal class Program
    {
        public static void Main(string[] args)
        {
            var s = new Solution();
            s.Run();
        }
    }
}

Measured memory_bytes: 14944
/* SANDEEP YADAv*/
#include<bits/stdc++.h>
using namespace std;
#define lld long long int
#define pb push_back
#define mkp make_pair
#define fi first
#define se second
#define mod 1000000007
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
lld gcd(lld a,lld b){ if(a<b) { a=a+b; b=a-b; a=a-b;}while(b!=0){lld r=a%b; a=b; b=r;} return a;}
long long power(long long a, long long b, long long m) {a %= m;long long res = 1;while (b > 0) {if (b & 1)res = res * a % m;a = a * a % m;b >>= 1;}return res;}
void judge()
{
      #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    freopen("error.txt","w",stderr);
    #endif
}

int main()
{
    fastio;
    //judge();
    
    lld a,b;
    cin>>a>>b;
    cout<<a*b;

    return 0;
}

Measured memory_bytes: 3636
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#define PB push_back
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
void FAIL() { printf("No"); exit(0); }
const int N=3e5+10;
int n;
int p[N];
//int main() {
//	rd(n);
//	int flg=1;
//	for(int i=1;i<=n;++i) {
//		rd(p[i]);
//		flg&=(p[i]&1)==(i&1);
//	}
//	if(flg) printf("Yes");
//	else printf("No");
//	return 0;
//}
void sol(int l,int r) {
	for(int i=l;i<=r;++i) if(p[i]<l||p[i]>r) FAIL();
	vector<int> a,b;
	for(int i=l;i<=r;i+=2)
		if(p[i]>i) a.PB(p[i]);
		else b.PB(p[i]);
	for(int i=0;i+1<a.size();++i) if(a[i+1]<a[i]) FAIL();
	for(int i=0;i+1<b.size();++i) if(b[i+1]<b[i]) FAIL();
}
int main() {
	rd(n);
	for(int i=1;i<=n;++i) rd(p[i]);
	for(int i=1;i+2<=n;++i)
		if(p[i]!=i&&p[i+1]!=i+1&&p[i+2]!=i+2) FAIL();
	int l=1;
	while(1) {
		while(l<=n&&p[l]==l) l++;
		if(l>n) break;
		int r=l;
		while(r+2<=n&&p[r+1]==r+1&&p[r+2]!=r+2) r+=2;
		sol(l,r);
		l=r+1;
	}
	printf("Yes");
	return 0;
}

Measured memory_bytes: 2620
export class Main {
  static main(input): string {
    const tmp: string[] = input.split("\n");
    const [n, d]: number[] = tmp[0].split(" ").map(a => parseInt(a));
    const x: number[][] = [];
    for (let i = 1; i <= n; ++i) {
      x.push(tmp[i].split(" ").map(a => parseInt(a)));
    }
    let result = 0;
    for (let i = 0; i < n - 1; ++i) {
      for (let j = i + 1; j < n; ++j) {
        let distance = 0;
        for (let k = 0; k < d; ++k) {
          distance += (x[i][k] - x[j][k]) ** 2;
        }
        distance = Math.sqrt(distance);
        if (distance == Math.floor(distance)) {
          ++result;
        }
      }
    }
    return `${result}`;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
typedef long long lint;
typedef unsigned int uint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
typedef unsigned long long ulint;
#define endl '\n'
#define fst first
#define sed second
#define pb push_back
#define mp make_pair
#define rint register int
#define SZ(x) (int((x).size()))
#define all(x) (x).begin(), (x).end()
#define reveal(x) cerr << #x << " = " << (x) << endl
#define rep(it, f, e) for (rint it = (f); it <= (e); ++it)
#define per(it, f, e) for (rint it = (f); it >= (e); --it)
#define repe(it, x) for (auto it = (x).begin(); it != (x).end(); ++it)
vector<int> a, f;
inline lint check(lint mid) {
	lint res = 0;
	rep (i, 0, SZ(a) - 1) {
		if (a[i] * 1ll * f[i] > mid) {
			res += (a[i] * 1ll * f[i] - mid + f[i] - 1) / f[i];
		}
	}
	return res;
}
int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL), cout.tie(NULL);
	int n;
	lint k;
	cin >> n >> k;
	a.resize(n);
	f.resize(n);
	for (auto & x : a) cin >> x;
	for (auto & x : f) cin >> x;
	sort(all(a));
	sort(all(f));
	reverse(all(f));
	lint L = 0, R = 1e12;
	while (L <= R) {
		lint mid = (L + R) >> 1;
		if (check(mid) <= k) {
			R = mid - 1;
		} else {
			L = mid + 1;
		}
	}
	cout << R + 1 << endl;
	return 0;
}

Measured memory_bytes: 1792
main(){
    int h,w;
    for(int i=0;;i++){
        scanf("%d%d",&h,&w);
        if(h==0 && w==0)break;
        for(int j=1;j<=h;j++){
            for(int k=1;k<=w;k++){
                if(j==1 || j==h || k==1 || k==w){printf("#");}
                else {printf(".");}
            }
            printf("\n");
        }
        printf("\n");
    }
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll h,w;cin>>h>>w;
	if(h==1||w==1){
		cout<<1<<endl;
		return 0;
	}
	ll ans=0;
	ans+=h/2*w;
	if(h%2==1)ans+=w/2+w%2;
	cout<<ans<<endl;
}


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

int main(){
    string s, p;
    cin >> p;
    cin >> s;
    p += p;
    if(p.find(s) == string::npos){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}



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

string reverse(string s)
{
    reverse(begin(s), end(s));
    return s;
}

bool all_zero(const string& s)
{
    for (const char c : s)
        if (c != '0')
            return false;
    return true;
}

// You have a list of pairs (a_i, b_i).
// Minimize A + B, subject to the constraint that
// for each i, either a_i <= A or b_i <= B
int f(vector<pair<int, int>> costs)
{
    if (costs.empty()) return 0;

    sort(begin(costs), end(costs));
    int x = costs.back().first, y = 0, result = x+y;
    while (!costs.empty())
    {
        y = max(y, costs.back().second);
        costs.pop_back();
        x = costs.empty() ? 0 : costs.back().first;
        result = min(result, x+y);
    }
    return result;
}

int solve(const string& A, const string& B)
{
    if (all_zero(B))
        return all_zero(A) ? 0 : -1;

    const int N = int(A.length());

    vector<int> forward_cost(N), backward_cost(N);
    forward_cost[N-1] = B[N-1] == '1' ? 0 : 1 + int(B.find('1'));
    for (int i = N-2; i >= 0; i--)
        forward_cost[i] = B[i] == '1' ? 0 : forward_cost[i+1] + 1;
    backward_cost[0] = B[0] == '1' ? 0 : 1 + int(reverse(B).find('1'));
    for (int i = 1; i < N; i++)
        backward_cost[i] = B[i] == '1' ? 0 : backward_cost[i-1] + 1;

    int result = numeric_limits<int>::max();
    for (int shift = 0; shift < N; shift++)
    {
        int mismatches = 0;
        for (int i = 0; i < N; i++)
            mismatches += A[i] != B[(i+shift)%N];

        vector<pair<int, int>> costs;
        for (int i = 0; i < N; i++)
            if (A[i] != B[(i+shift)%N] && forward_cost[i] > shift)
                costs.push_back({backward_cost[i], forward_cost[i]-shift});

        result = min(result, shift + 2*f(costs) + mismatches);
    }
    return result;
}

int main()
{
    string A, B;
    cin >> A >> B;
    cout << min(solve(A, B), solve(reverse(A), reverse(B))) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <map>
#include <cstdlib>
#include <cctype>

using namespace std;

void str2arr(string s, string A[]) {
    int n = 0;
    string tmp = "";

    for (int i = 0; s[i] != '=' ; i++) {
        if ('0' <= s[i] && s[i] <= '9') {
            tmp += s[i];
        }
        else {
            if (tmp != "") { 
                A[n++] = tmp;
                tmp = "";
            }
            A[n++] = s[i];
        }
    }
    if (tmp != "") { A[n++] = tmp; }
    A[n++] = "=";
}

void Generate_RPN(string A[], string B[]) {
    map<string, int> table;
    stack<string> St;
    table["*"] = 1;
    table["/"] = 1;
    table["+"] = 0;
    table["-"] = 0;
    table["("] = -1;
    table[")"] = -1;

    int j = 0;
    for (int i = 0; A[i] != "="; i++) {
        if ('0' <= A[i][0] && A[i][0] <= '9') {
            B[j++] = A[i];
        }
        else if (A[i] == "(") {
            St.push(A[i]);
        }
        else if (A[i] == ")") {
            while (St.top() != "(") {
                B[j++] = St.top(); St.pop();
            }
            St.pop();
        }
        else {
            while ((!St.empty()) && (table[St.top()] >= table[A[i]])) {
                B[j++] = St.top(); St.pop();
            }
            St.push(A[i]);
        }
    }
    while (!St.empty()) {
        B[j++] = St.top(); St.pop();
    }
    B[j] = "=";
}

int Calculate_RPN(string s[]) {
    stack<double> St;
    double a, b;

    for (int i = 0; s[i] != "="; i++) {
        if (s[i] == "+") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a+b);
        }
        else if (s[i] == "-") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a-b);
        }
        else if (s[i] == "*") {
            b = int(St.top()); St.pop();
            a = int(St.top()); St.pop();
            St.push(a*b);
        }
        else if (s[i] == "/") {
            b = int(St.top()); St.pop();
            a = St.top(); St.pop();
            St.push(a/b);
        }
        else {
            St.push(atoi(s[i].c_str()));
        }
    }
    return int(St.top());
}

int main() {
    int n;
    string A[100], B[100];
    string in;

    cin >> n;

    while (n--) {
        cin >> in;
        str2arr(in, A);
        Generate_RPN(A, B);
        cout << Calculate_RPN(B) << endl;
    }

    return 0;
}

Measured memory_bytes: 3176
#include <iostream>
#include <string>

using namespace std;

int main(){
	int n;
	long long cnt;
	cin >> n;
	cnt = 0;
	for (int i = 0; i <= n; i++)
	{
		if(i % 3 != 0 && i % 5 != 0){
			cnt += i;
		}
		/* code */
	}
	cout << cnt << endl;
	return 0;
	
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <typeinfo>
#include <cxxabi.h>
#ifdef LOCAL
#include "dbgtoki.hpp"
#define DUMP(i) dump((string)TOSTRING(i), demangle(typeid(i).name()), __LINE__ , i) 
#else
#define DUMP(i)
#endif

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(s) (s).begin(), (s).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()) , v.end());
#define dis distance
#define so sort
#define rev reverse
#define pub push_back
#define sec second
#define fir first

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector <int> > vvi;
const int EPS = 1e-9;
const int MOD = 1e9+7;
const int INF = (1 << 30);

ll mod_pow(ll x, ll n, ll mod){
	if(n == 0)return 1;
	ll res;
	if(mod == -1)res = mod_pow(x * x,n/2,mod);
	else res = mod_pow(x * x % mod,n/2,mod);
	if(n%2 == 1 && mod != -1)res = res * x % mod;//(nが2の累乗ではない時にもう一度処理を行う)
	else if(n%2 == 1)res = res * x;
	return res;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<int> V(n);
	REP(i,n){
		int a;
		cin >> a;
		if(n%2==0){//全てのAは奇数である。
			if(a%2==0){
				cout << 0 << endl;
				return 0;
			}
		}else{//全てのAは偶数である。
			if(a%2==1){
				cout << 0 << endl;
				return 0;
			}
		}
		V[a]++;
	}
	DUMP(V);
	int cnt = 0;
	if(n % 2 == 0){//全てのAは奇数である。
		REP(i,n/2){
			if(V[i*2+1] == 2){
				cnt++;
			}else{
				cout << 0 << endl;
				return 0;
			}
		}
	}else{//全てのAは偶数である。
		REP(i,n/2+1){
			DUMP(i);

			if((i == 0) && (V[i] == 1)){
				continue;
			}else if(i == 0){
				cout << 0 << endl;
				return 0;
			}
			DUMP(i*2);
			if(V[i*2] == 2){
				cnt++;
			}else{
				cout << 0 << endl;
				return 0;
			}
		}
	}
	ll ans = mod_pow(2,cnt,MOD);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
vector<unsigned long long> S;
map<unsigned long long,unsigned long long> m;
int main()
{
	ios::sync_with_stdio(false);
	int N,K;
	cin>>N>>K;
	S.resize(N+1,0);
	for(int i=0;i<N;i++)
	{
		unsigned long long A;
		cin>>A;
		S[i+1]=A+S[i];
	}
	for(int i=0;i<=N;i++)
	{
		S[i]=(S[i]-i)%K;
	}
	unsigned long long ans=0;
	for(int j=1;j<=N;j++)
	{
		if(j==1)
			for(int i=j-K+1;i<j;i++)
			{
				if(i<0) continue;
				m[S[i]]++;
			}
		else
		{
			if(j-K>=0) m[S[j-K]]--;
			m[S[j-1]]++;
		}
		ans+=m[S[j]];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 14336
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int> 
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fi first
#define se second
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
int h,n;
int a[100005];
int main(){
    scanf("%d %d",&h,&n);
    for(int i=0;i<n;i++) scanf("%d",&a[i]);
    int sum=0;
    for(int i=0;i<n;i++) sum+=a[i];
    if(sum>=h)
        puts("Yes");
    else
        puts("No");
    return 0;
}

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

long long n, a[200005], suf[200005], ans, mod = 1e9+7;

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++){
        cin >> a[i];
    }
    for (int i = n-1; i >= 0; i--){
        suf[i] = suf[i+1]+a[i];
        suf[i] %= mod;
    }
    for (int i = 0; i < n; i++){
        ans += a[i]*suf[i+1];
        ans %= mod;
    }
    cout << ans << "\n";
}


Measured memory_bytes: 6728
# -*- coding: utf-8 -*-
n = int(input())
a = list(map(int, input().split()))
total = 1

if a.count(0) > 0:
    print(0)
else:
    for num in a:
        total *= num
        if total > 1000000000000000000:
            total = -1
            break
    print(total)

Measured memory_bytes: 21780
package main

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

func main() {
	sc := NewScanner()
	A, B := sc.NextInt(), sc.NextInt()
	fmt.Println(2*B-A)

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
using namespace std;
struct Node{
        int value;
        Node *left,*right,*parent;
};
Node *nil,*root;
void print(Node *now,bool sign){
        if(now==nil)return;
        if(!sign)
                cout<<" "<< now->value;
        print(now->left,sign);
        if(sign)
                cout <<" "<< now->value ;
        print(now->right,sign);
}
string find(int x){
        Node *now=root;
        while(now!=nil){
                if(now->value==x)
                        return "yes";
                else if(now->value > x)
                        now=now->left;
                else
                        now=now->right;
        }
        return "no";
}
void insert(int x){
        Node *now;
        now=root;
        while(now!=nil){
                if(x>now->value){
                        if(now->right==nil)break;
                        now=now->right;
                }
                else{
                        if(now->left==nil)break;
                        now=now->left;
                }
        }
        Node *in;
        in=(Node *)malloc(sizeof(Node));
        if(now->value < x)
                now->right=in;
        else now->left=in;
        in->parent=now;
        in->left=in->right=nil;
        in->value=x;
        return;
}
int main(){
        nil=(Node *)malloc(sizeof(Node));
        root=(Node *)malloc(sizeof(Node));
        root->left=root->right=nil;
        root->parent=root;
        nil->parent=root;
        nil->left=nil->right=nil;
        int N,x;
        string str;
        cin >> N;
        bool signal=true;
        for(int i=0 ; i<N ; i++ ){
                cin >> str;
                if(str=="insert"){
                        cin >> x;
                        if(signal){
                                signal=false;
                                root->value=x;
                        }else
                                insert(x);
                }else if(str=="find"){
                        cin >> x;
                        cout << find(x) << endl;
                }else{
                        print(root,1);
                        cout << endl;
                        print(root,0);
                        cout << endl;
                }
        }
        return 0;
}


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

typedef struct node {
  long key;
  struct node *left;
  struct node *right;
} Node;

Node *root = NULL;

void insert(long key) {
  Node *newNode, *current;

  newNode = (Node *)malloc(sizeof(Node));
  newNode->key = key;
  newNode->left = NULL;
  newNode->right = NULL;

  if (root == NULL) {
    root = newNode;
    return;
  }

  current = root;
  while (1) {
    if (newNode->key < current->key) {
      if (current->left == NULL) {
	current->left = newNode;
	break;
      } else {
	current = current->left;
      }
    } else {
      if (current->right == NULL) {
	current->right = newNode;
	break;
      } else {
	current = current->right;
      }
    }
  }
  current = newNode;

}

void inorderTreeWalk(Node* node) {
  if (node != NULL) {
    inorderTreeWalk(node->left);
    printf(" %ld", node->key);
    inorderTreeWalk(node->right);
  }
}

void preorderTreeWalk(Node* node) {
  if (node != NULL) {
    printf(" %ld", node->key);
    preorderTreeWalk(node->left);
    preorderTreeWalk(node->right);
  }
}

int main(void) {
  int n, i;
  long arg;
  char command[80];

  scanf("%d", &n);

  for (i = 0; i < n; i++) {
    scanf("%s", command);
    if (strcmp(command, "insert") == 0) {
      scanf("%ld", &arg);
      insert(arg);
    } else {
      inorderTreeWalk(root);
      printf("\n");
      preorderTreeWalk(root);
      printf("\n");
    }
  }


  return 0;
}

Measured memory_bytes: 16228
X = int(input())

a = 1999/X

if a >= 1999/599:
  print(8)
elif a >= 1999/799:
  print(7)
elif a >= 1999/999:
  print(6)
elif a >= 1999/1199:
  print(5)
elif a >= 1999/1399:
  print(4)
elif a >= 1999/1599:
  print(3)
elif a >= 1999/1799:
  print(2)
elif a >= 1999/1999:
  print(1)


Measured memory_bytes: 9000
<?php

$n = trim(fgets(STDIN));
$p = explode(' ', trim(fgets(STDIN)));

for ($i = 0; $i < $n; $i++) {
    $n_arr[$i] = (string)$i + 1;
}

$result = array_diff_assoc($n_arr, $p);
if (count($result) === 2 || count($result) === 0) {
    echo "YES" . PHP_EOL;
} else {
    echo "NO" . PHP_EOL;
}


Measured memory_bytes: 4604
N, M = map(int, input().split())
L = {}
for i in range(N):
    A = list(map(int, input().split()))
    for j, a in enumerate(A):
        if j == 0:
            continue
        if not a-1 in L.keys():
            L[a-1] = [i]
        else:
            L[a-1].append(i)

class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

union = UnionFind(N)

for list_l in L.values():
    for l in list_l:
        union.Unite(l, list_l[0])

ans = "YES"
for i in range(N):
    if not union.isSameGroup(0, i):
        ans = "NO"
print(ans)


Measured memory_bytes: 16324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#define all(v) v.begin(), v.end()
#define repi(i, n, init) for (ll i = init; i < (n); i++)
#define repd(i, n, init) for (ll i = (n); i >= init; i--)
#define repm(i, m) for (auto i = m.begin(); i != m.end(); i++)
#define repb(bit, n, init) for (ll bit = init; bit < (1 << n); ++bit)

int main()
{
    int N;
    cin >> N;
    vector<int> X(N), tmp(N);
    repi(i, N, 0)
    {
        cin >> X[i];
        tmp[i] = X.at(i);
    }
    sort(all(X));
    repi(i, N, 0)
    {
        cout << (tmp.at(i) <= X.at(N / 2 - 1) ? X.at(N / 2) : X.at(N / 2 - 1)) << endl;
    }
    return 0;
}

Measured memory_bytes: 3712
#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;

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

    ll count = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] != t[i])
        {
            count++;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define For(i, l, r) for (register int i = l, _r = r; i <= _r; ++i)
#define Ford(i, l, r) for (register int i = r, _l = l; i >= _l; --i)
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 20;
ll a,b,c,ans;
inline int read()
{
	int x = 0, f = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){if (ch == '-')f = -1;ch = getchar();}
	while (ch >= '0' && ch <= '9'){x = (x << 3) + (x << 1) + ch - '0';ch = getchar();}
	return x * f;
}

int main()
{
	a=read(),b=read(),c=read();
	if(c-a-b>=0&&(c-a-b)*(c-a-b)>4*a*b)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

int main(){

  int n,i,j;

  while(1){

    scanf("%d",&n);

    if(n==0){
      break;
    }

  int data[10][10]={0};
  int sum[10]={0};
  int sum2[10]={0};
  int sum3=0;

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&data[i][j]);
      sum[i]+=data[i][j];
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      sum2[i]+=data[j][i];
    }
  }

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      printf("%5d",data[i][j]);
    }
    printf("%5d\n",sum[i]);
    sum3+=sum[i];
  }

  for(i=0;i<n;i++){
    printf("%5d",sum2[i]);
  }
  printf("%5d\n",sum3);

  }

  return 0;
}

 

Measured memory_bytes: 1200
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0);
#define Mod 1000000007
#define eps 1e-6
#define ll long long
#define INF 0x3f3f3f3f 
#define MEM(x,y) memset(x,y,sizeof(x))
#define Maxn 100005
#define P pair<int,int>
using namespace std;
int main()
{
	char a[100005];
	scanf("%s", &a);
	int ans = 0;
	int p=0;
	int g=0;
	int n=strlen(a)/2;
	for (int i = 0; i < strlen(a); i++)
	{
		if(a[i]=='g')
		g++;
		if(a[i]=='p')
		p++;
	}
	cout << n-p;
}

Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, d, tong = 0;
    cin >> n >> d;
    while (n--)
    {
        long long int a, b;
        cin >> a >> b;
        if (sqrt(a * a + b * b) <= d)
        {
            tong++;
        }
    }
    cout << tong << endl;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define eb emplace_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
constexpr double eps=1e-8;
const double pi=acos(-1);
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int Random(int mi,int ma){
    random_device rnd;
    mt19937 mt(rnd());//32bit
    //[mi,ma]
    uniform_int_distribution<int>engine(mi,ma);
    return engine(mt);
}
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
vector<int>kaijo,invkaijo;
void init_fact(int n){
    kaijo.resize(n+1);
    invkaijo.resize(n+1);
    kaijo[0]=1;
    for(int i=1;i<=n;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
    rep(i,n+1)invkaijo[i]=modpow(kaijo[i],mod-2);
}
int comb(int a,int b){
    if(a<b)return 0;
    if(a<0||b<0)return 0;
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
signed main(){
    cin.tie(0);ios::sync_with_stdio(false);
    string s;
    cin>>s;
    cout<<s.substr(0,3)<<endl;
    return 0;
}

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

using int64 = long long;

int64 gcd(int64 a, int64 b) {
  while (int64 c = a % b) {
    a = b;
    b = c;
  }
  return b;
}

int main() {
  int64 a, b;
  cin >> a >> b;
  int64 g = gcd(a, b);

  int64 ret = 1;
  for (int64 p = 2; p * p <= g; ++p) {
    if (g % p)
      continue;
    ++ret;
    while (g % p == 0) g /= p;
  }
  if (g != 1)
    ++ret;

  cout << ret << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, m, dp[1001][1001], pref[mxn], cnt = 0, x, y;
char a[1001][1001];

int main(){
    cin >> x >> y;
    if((x > 0 && y < 0) || (x < 0 && y > 0)){
        cout << abs(x + y) + 1;
    }else if(x == y){
        cout << 0;
    }else if(x > y && ((x > 0 && y > 0) || (x < 0 && y < 0))){
        cout << abs(abs(x) - abs(y)) + 2;
    }else if(y > x && ((x > 0 && y > 0) || (x < 0 && y < 0))){
        cout << abs(abs(y) - abs(x));
    }else if(x > y && (y == 0 || x == 0)){
        cout << abs(x + y) + 1;
    }else if(x < y && (y == 0 || x == 0)){
        cout << abs(abs(x) - abs(y));
    }
    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main(void){
    vector<int> v;
    int ans,rans=1e9;
    int cnt=0;
    string s;
    cin>>s;
    for(char a='a';a<='z';a++){
        v={};
        cnt=0;
        for(int i=0;i<s.size();i++){
            if(s[i]!=a){
                cnt++;
            }
            else {v.push_back(cnt);cnt=0;}
        }
        v.push_back(cnt);
        //for(auto x:v)cout<<x<<" ";
        //cout<<endl;
        sort(v.begin(),v.end());
        ans=v[v.size()-1];
        rans=min(ans,rans);
    }
    cout<<rans<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<queue>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<ctime>
#define R(i, n) for(int i = 0;i < n;i++)
#define S(a) scanf("%d", &a)
#define S2(a, b) scanf("%d%d", &a, &b)
#define S3(a, b, c) scanf("%d%d%d", &a, &b, &c)
#define SL(a) scanf("%lld", &a)
#define SA(i, n, a) R(i, n) scanf("%d", a + i)
#define SAL(i, n, a) R(i, n) scanf("%lld", a + i)
#define P(a) printf("%d", a)
#define PL(a) printf("%lld", a)
using namespace std;
using ll = long long;
using PR = pair<int, int>;
const ll MOD = 1e+9 + 7;
const int INF = 1e+9;

int N;

int main() {
	S(N);
	vector<int> l;
	R(i, N) {
		int num = 0;
		S(num);
		l.push_back(num);
	}
	sort(l.begin(), l.end());
	int ans = 0;
	R(i, N) {
		for (int j = i + 1; j < N; j++) {
			for (int k = j + 1; k < N; k++) {
				if (l[k] < l[i] + l[j]) ans++;
			}
		}
	}
	P(ans);
}
	

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

public class Main {

	public static void main(String[] args) {
		int monthTerm = Integer.parseInt(input());

		int principal = 100000;

		while (monthTerm != 0) {
			principal += principal * 0.05;
			int fraction = principal % 1000;
			if (fraction != 0) {
				principal += 1000 - fraction;
			}
			monthTerm--;
		}

		System.out.println(principal);

	}

	private static String input() {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
		String input = null;
		try {
			input = br.readLine();
		} catch (IOException e) {
			System.out.println("読み込みに失敗しました");
			e.printStackTrace();
		}
		return input;
	}


}

Measured memory_bytes: 15012
/*
  AOJ 2522
  Title:Register Phase
  @kankichi573
*/
#include <stdio.h>
#include <string.h>


char passwd[21];
main()
{
  int i,u,l,n,len,flag;
  char c;

  while(EOF!=scanf("%s",passwd))
    {
      if((len=strlen(passwd))>=6)
	{

	  u=l=n=0;
	  for(i=0;i<len;i++)
	  {
	    c=passwd[i];
	    if(isupper(c))
	      u=1;
	    if(islower(c))
	      l=1;
	    if(isdigit(c))
	      n=1;
	  }

	  flag=(u && l && n);
	}
      else
	flag=0;
      printf("%s\n",flag?"VALID":"INVALID");
    }
  return(0);
}

Measured memory_bytes: 524
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <queue>
#include <utility>
#include <vector>

using namespace std;

typedef pair<int, int> P;

int n;
map<int, int> mp;
long long ans;

int main(void) {
  cin >> n;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans += mp[i-a];
    mp[a+i]++;
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 20688
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	int n;
	cin >> n;
	int arr[n];
	for(int i=0;i<n;i++)
		cin >> arr[i];
 
	int min_jumps[n];
	min_jumps[0] = 0;
	min_jumps[1] = abs(arr[0]-arr[1]);
	for(int i=2;i<n;i++){
		min_jumps[i] = INT_MAX;
		// cout << min_jumps[i] << " " << i << " " << abs(arr[i]-arr[i-1])+min_jumps[i-1] << endl;
		if(min_jumps[i] > abs(arr[i]-arr[i-1])+min_jumps[i-1])
			min_jumps[i] = abs(arr[i]-arr[i-1])+min_jumps[i-1];
		if(min_jumps[i] > abs(arr[i]-arr[i-2])+min_jumps[i-2])
			min_jumps[i] = abs(arr[i]-arr[i-2])+min_jumps[i-2];
 
	}
	// for(int i =0; i<n;i++)
	cout << min_jumps[n-1] << endl;
	return 0;
}

Measured memory_bytes: 1024