akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<sstream>
#include<algorithm>
#include<stack>
#include<bitset>
#include<map>
#include<set>
#define rep(i,n) for(int i=0;(i)<(n);i++)
#define rep1(i,n) for(int i=1;(i)<=(n);i++)
#define mst(a,b) memset(a,b,sizeof(a))
#define scd(a) scanf("%d",&a)
#define scdd(a,b) scanf("%d%d",&a,&b)
#define scddd(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define dbg(a) cout<<"* "<< #a <<" : "<<a<<endl
#define fr first
#define se second
#define ls x<<1
#define rs x<<1|1
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define lowbit(x) x&(-x)
#define ac cout<<ans<<endl
//#define DEBUG 0
using namespace std;
const double pi=acos(-1.0);
const double eps=1e-8;
const ull hashp=131;
const ll INF=0x3f3f3f3f3f3f3f3fll;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=1e5+100;
map<string,int>mp;
int cnt;
void solve(){
	int n;cin>>n;
	string s;
	rep1(i,n){
		cin>>s;
		if(!mp.count(s))mp[s]=++cnt;
	}
	printf("%d",cnt);
}
int main(){
    //IOS;
    //freopen("fenwick.in","r",stdin);
    //freopen("fenwick.out","w",stdout);
    solve();
    
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;                                             ;;
	;;         ;;            ;;;;;;;;;       ;;    ;;
	;;        ;; ;;        ;;                ;;    ;;
	;;       ;;   ;;       ;;                ;;    ;;
	;;      ;;;;;;;;;      ;;                ;;    ;;
	;;     ;;       ;;     ;;                      ;;
    ;;    ;;         ;;      ;;;;;;;;;       ;;    ;;
    ;;                                             ;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    return 0;
}

Measured memory_bytes: 18848
# import sys
# input = sys.stdin.readline

def mp(): return map(int, input().split())
def lmp(): return list(map(int, input().split()))

n = int(input())
a =[chr(ord('a') + i) for i in range(26)]
u = []
while n!=0:
    k = (n+25) % 26
    u.append(k)
    n = (n-1)//26
ans = []
for i in range(len(u)):
    ans.append(a[u[i]])
ans.reverse()
print("".join(ans))





Measured memory_bytes: 61768
if __name__ == '__main__':
    n = int(input())
    h = [int(i) for i in input().split()]

    s = h[0] - 1
    for i in range(1, n):
        if s <= h[i] - 1:
            s = h[i] - 1
        elif s <= h[i]:
            s = h[i]
        else:
            print('No')
            break
    else:
        print('Yes')





Measured memory_bytes: 63984
import sys

l = []
for input in sys.stdin:
    l.append(input.split())

for i in range(0,len(l)):
    for j in range(0,len(l[i])):
        l[i][j] = int(l[i][j])

if(l[0][0] * l[2][0] + (l[0][0] / 10) * l[2][2] + l[0][1] * l[2][1] + (l[0][1] / 20) * l[2][3] > l[1][0] * l[2][0] + (l[1][0] / 10) * l[2][2] + l[1][1] * l[2][1] + (l[1][1] / 20) * l[2][3]):
    print 'hiroshi'
elif((l[0][0] * l[2][0] + (l[0][0] / 10) * l[2][2] + l[0][1] * l[2][1] + (l[0][1] / 20) * l[2][3] < l[1][0] * l[2][0] + (l[1][0] / 10) * l[2][2] + l[1][1] * l[2][1] + (l[1][1] / 20) * l[2][3])):
    print 'kenjiro'
else:
    print 'even'


Measured memory_bytes: 4692
exception Not_equal of int

let cmp_sa rank a b n k =
  if rank.(a) <> rank.(b) then compare rank.(a) rank.(b)
  else
    compare
      (if a + k <= n then rank.(a+k) else (-1))
      (if b + k <= n then rank.(b+k) else (-1))

let construct_sa t n =
  let sa = Array.make (n + 1) 0 in
  let rank = Array.make (n + 1) 0 in
  let tmp = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    sa.(i) <- i;
    rank.(i) <- Char.code t.[i];
  done;
  sa.(n) <- n;
  rank.(n) <- (-1);
  let rec doit k =
    if k > n then ()
    else begin
      Array.fast_sort (fun a b -> cmp_sa rank a b n k) sa;
      tmp.(sa.(0)) <- 0;
      for i = 1 to n do
        tmp.(sa.(i)) <-
          tmp.(sa.(i-1)) + (if cmp_sa rank sa.(i-1) sa.(i) n k = (-1) then 1 else 0);
      done;
      for i = 0 to n do rank.(i) <- tmp.(i) done;
      doit (2 * k)
    end in
  doit 1;
  sa

let range_cmp t n offset p k =
  let m = n - offset in
  let m = if m < k then m else k in
  try
    for i = 0 to m - 1 do
      if t.[i+offset] <> p.[i] then
        raise (Not_equal (compare t.[i+offset] p.[i]));
    done;
    if m = k then 0
    else (-1)
  with Not_equal i -> i

let () =
  let t = read_line () in
  let n = String.length t in
  let sa = construct_sa t n in
  let q = read_int () in
  for _ = 0 to q - 1 do
    let p = read_line () in
    let k = String.length p in
    let rec doit l r =
      if r - l <= 1 then l
      else
        let m = (l + r) / 2 in
        if range_cmp t n sa.(m) p k <= 0 then doit m r
        else doit l m in
    let l = doit 0 (n + 1) in
    Printf.printf "%d\n" (if range_cmp t n sa.(l) p k = 0 then 1 else 0);
  done

Measured memory_bytes: 75520
import sys, array, math, re, functools
input = lambda: sys.stdin.readline()
@functools.lru_cache(maxsize = 10000)

def Main():
  W, a, b = map(int ,input().split())
  A = a + W
  B = b + W
  if b <= A <= b+W:
    print(0)
  elif a <= B <= a+W:
    print(0)
  elif A < b:
    print(b - A)
  elif B < a:
    print(a - B)
  elif A > b:
    print(abs(a - b))
  elif B > a:
    print(abs(b - a))
    
if __name__ == '__main__':
  Main()

Measured memory_bytes: 3952
N = int(input())

p_list = []
for i in range(N):
  x, y = map(int, input().split())
  p_list.append((x, y))

f0_list = [x+y for x, y in p_list]
f1_list = [x-y for x, y in p_list]

max_f0 = max(f0_list) - min(f0_list)
max_f1 = max(f1_list) - min(f1_list)

print(max([max_f0, max_f1]))


Measured memory_bytes: 119516
#include <bits/stdc++.h>
#include <numeric>
#include <limits>
#include <numeric>
#include <type_traits>
using namespace std;
typedef pair<int, int> P;

typedef long long ll;
const int MOD = 1000000007;

    bool cmp(const P &A, const P &B){
        return (A.second < B.second);
    }


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

int main(){  
    int N,a,b;
    P pairs[200000];
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> a >> b;
        pairs[i] = P(a, b);
    }
    sort(pairs, pairs+N, cmp);
    int progress = 0;
    for(int i=0;i<N;i++){
        progress += pairs[i].first;
        if(progress > pairs[i].second){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes";
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
const int mod = 998244353;
struct mint {
    ll x;
    mint(ll x=0):x( (x%mod + mod) % mod ) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ( (x += a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ( ( x += mod - a.x) >= mod ) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        ( x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }

    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) { return mint(*this) /= a; }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator() (int n, int k) {
        if ( k < 0 || k > n ) return 0;
        return fact[n] * ifact[k] * ifact[n-k];
    }
} c(200005);
 
int main() {
  int n, m, k;
  cin >> n >> m >> k;
 
  mint ans = 0;
  mint col = m;
  for (int x = n-1; x >= 0; --x) {
    mint now = col;
    now *= c(n-1,x);
    if (x <= k) ans += now;
    col *= m-1;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6236
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        long X = scan.nextLong();
        if(N == 0){
            System.out.println(0);
        }
        else{
            System.out.println(Hamb(N,X));
        }
    }
    static long Hamb(int N, long X){
        if(N <= 0){
            return 1;
        }
        long thick = HambThickness(N-1);
        if(X == 1){
            return 0;
        }
        else if(X <= 1 + thick){
            return Hamb(N-1,X-1);
        }
        else if(X == 2 + thick){
            return Patty(N-1)+1;
        }
        else if(X < 2 + 2 * thick){
            return Patty(N-1) + 1 + Hamb(N-1, X - 2 - thick);
        }
        else{
            return 2 * Patty(N-1) + 1;
        }
    }
    static long HambThickness(int N){
        if(N <= 0){
            return 1;
        }
        else{
            return (2 * HambThickness(N-1) + 3);
        }
    }
    static long Patty(int N){
        if(N <= 0){
            return 1;
        }
        else{
            return (2 * Patty(N-1) + 1);
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define PI acos(-1.0)
#define mem(a,b) memset((a),b,sizeof(a))
#define TS printf("!!!\n")
#define pb push_back
#define inf 1e9
//std::ios::sync_with_stdio(false);
using namespace std;
//priority_queue<int,vector<int>,greater<int>> que;
const double eps = 1.0e-8;
typedef pair<int, int> pairint;
typedef long long ll;
typedef unsigned long long ull;
const int maxn = 1e6 + 10;
const int  maxm = 300;
const int turn[4][2] = {{1, 0}, { -1, 0}, {0, 1}, {0, -1}};
//next_permutation
ll mod = 1e9 + 7;
map<int, int> mp;
int num[1000005];
int main()
{
        //freopen("out1.txt", "w", stdout);
        int ans = -1;
        int aim;
        int n;
        cin >> n;
        for (int i = 1; i <= n; i++)
        {
                scanf("%d", &num[i]);
                if (abs(num[i]) > ans)
                {
                        ans = abs(num[i]);
                        aim = i;
                }
        }
        if (num[aim] == 0)
        {
                cout << 0 << endl;
        }
        else if (num[aim] > 0)
        {
                cout << 2 * n - 2 << endl;
                for (int i = 1; i <= n; i++)
                {
                        if (i == aim)
                        {
                                continue;
                        }
                        cout << aim << " " << i << endl;
                }
                for (int i = 1; i < n; i++)
                {
                        cout << i << " " << i + 1 << endl;
                }
        }
        else
        {
                cout << 2 * n - 2 << endl;
                for (int i = 1; i <= n; i++)
                {
                        if (i == aim)
                        {
                                continue;
                        }
                        cout << aim << " " << i << endl;
                }
                for (int i = n; i > 1; i--)
                {
                        cout << i << " " << i - 1 << endl;
                }
        }

}


Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		HashSet<Long> l = new HashSet<>();
		long j = s.nextLong();
		long k = j - 1;

		for (long i = 2; i * i <= j; ++i) {
			if (j % i == 0) {
				f(i, j, l);
				f(j / i, j, l);
			}

			if (k % i == 0) {
				f(i, j, l);
				f(k / i, j, l);
			}
		}
		System.out.println(j <= 3 ? j - 1 : l.size() + 2);
	}

	private static void f(long i, long k, HashSet<Long> l) {
		while (k % i == 0) {
			k /= i;
		}
		if (k % i == 1)
			l.add(i);
	}
}


Measured memory_bytes: 23764
# coding: utf-8
# Your code here!

n = int(input())
s = input()

west = [0]*n
east = [0]*n

cnt = 0
for i in range(1,n):
    cnt = cnt + 1 if s[i-1] == 'W' else cnt
    west[i] = cnt

cnt = 0
for i in range(n-2, -1, -1):
    cnt = cnt + 1 if s[i+1] == 'E' else cnt
    east[i] = cnt

cntMin = n
for i in range(0,n):
    cntMin = min(cntMin, west[i]+east[i])
    #print("cntMin:{0} \t west:{1} \t east:{2}".format(cntMin, west[i], east[i]))
    
print(cntMin)

Measured memory_bytes: 17604
n = int(input())
h = [tuple(map(int, input().split())) for _ in range(n)]
h.sort(key = lambda x : x[1])
l = [0]*(n+1)
r = l[:]
for i in range(n):
  r[i+1] = r[i] + h[i][1]
h.sort(reverse=True)
for i in range(n):
  l[i+1] = l[i] + h[i][0]
ans = 0
for _j in (-1, 0, 1):
  for i in range(n):
    j = i + _j
    if i + j <= n and j >= 0:
      ans = max(ans, l[i] - r[j])
print(ans*2) 

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

int main(){
    int n; cin >> n;
    string s; cin >> s;
    int cnt = 0;
    int mx = 0;
    rep(i,n){
        if(s[i] == '(') --cnt;
        else ++cnt;
        mx = max(cnt,mx);
    }
    int nx = mx-cnt;
    cout << string(mx,'(') << s << string(nx,')') << endl;
}

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

int main()
{
  int x,n;
  cin>>x>>n;
  if(n==0)
    cout<<x;
  else
  {
  	int p[n+1];
  	set<int> s;
  	for(int i=0;i<n;i++)
  	{
    	cin>>p[i];
    	s.insert(p[i]);
  	}
  	int ans1=x,ans2=x,cnt1=0,cnt2=0;
  	while(true)
  	{
      	if(s.count(ans1)==0)
      		break;
    	ans1=ans1-1;
    	cnt1++;
      	if(s.count(ans2)==0)
      		break;
    	ans2=ans2+1;
    	cnt2++;
  	}
  	if(cnt1<=cnt2)
    	cout<<ans1;
  	else
    	cout<<ans2;
  }
  return 0;
}


Measured memory_bytes: 3176
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
int compare_int(const void *a, const void *b) {
  return *(long long int*)a - *(long long int*)b;
}

int main() {

  int H, W;
  // scanf("%d%d", &H, &W);
  double tmp;
  //int a,b;
  long long int ans;

  long long int a, b, c;
  long long int d, e, f;

  scanf("%lld%lld%lld", &a, &b, &c);
  d = (10*a) + b + c;
  e = (10*b) + c + a;
  f = (10*c) + b + a;
  long long int t[3];
  t[0] = d;
  t[1] = e;
  t[2] = f;
  
  qsort(t, 3, sizeof(long long int), compare_int);
  printf("%lld\n", t[2]);
  // if (d > e) {
  //   printf("%lld\n", d);
  // }
  // else {
  //   printf("%lld\n", e);

  // }    
  
  // if (H>W) {
  //   int tmm;
  //   tmm = W;
  //   H = tmm;
  //   W = H;
  // }

  
  // tmp = (double)((double)W / 3);
  // if (int(tmp - 0.5) == (int)tmp) {
  //   a = (int)tmp + 1;
  // }
  // else {
  //   a = (int)tmp;
  // }
  
  // b = (H / 2);
  // long long int S[3];
  
  // // printf("a = %d,, b = %d\n",a,b);
  // // printf("aa");
  // S[0] = (long long int)H * (long long int)a;
  // S[1] = (long long int)b * (long long int)(W - a);
  // S[2] = (long long int)(H - b) *(long long int) (W - a);

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

  // qsort(S, 3, sizeof(long long int), compare_int);
  // for (int i = 0; i < 3; i++) {
  //    // printf("S[%d] = %lld\n", i, S[i]);
  // }

  // ans = S[2] - S[0];

  // if (W % 3 == 0 || H % 3 == 0) {
  //   ans = 0;
  // }
  // printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 128
import unittest


class TestB(unittest.TestCase):
    def test_1(self):
        self.assertEqual(think('ZABCDBABCQ'), 2)

    def test_2(self):
        self.assertEqual(think('THREEONEFOURONEFIVE'), 0)

    def test_3(self):
        self.assertEqual(think('ABCCABCBABCCABACBCBBABCBCBCBCABCB'), 5)


def solve():
    data = read()
    result = think(data)
    write(result)


def read():
    n = read_int(1)[0]
    return read_line(n)


def read_int(n):
    return read_type(int, n, sep=' ')


def read_float(n):
    return read_type(float, n, sep=' ')


def read_type(t, n, sep):
    return list(map(lambda x: t(x), read_line().split(sep)))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(data):
    term = 'ABC'
    return data.count(term)


def write(result):
    print(result)


if __name__ == '__main__':
    # unittest.main()
    solve()

Measured memory_bytes: 51308
n,m=map(int,input().split())
a=[input() for i in range(n)]
b=[input() for _ in range(m)]

for i in range(n-m+1):
    for j in range(n-m+1):
        flag=True
        for k in range(m):
            for l in range(m):
                if a[i+k][j+l]!=b[k][l]:
                    flag=False
        if flag:
            print("Yes")
            exit()
print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#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
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;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
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;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
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;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    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;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
double l;
signed main(){
    cin>>l;
    double a=l/3;
    printf("%.12lf\n",a*a*a);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a) for(int i=0; i<(a); i++)
typedef long long ll;
template<typename T>
struct edge {
  int src, to;
  T cost;
  edge(int to, T cost) : src(-1), to(to), cost(cost) {}
  edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
  edge &operator=(const int &x) {
    to = x;
    return *this;
  }
  operator int() const { return to; }
};
template<typename T>
using Edges = vector<edge<T>>;
template<typename T>
using WeightedGraph = vector<Edges<T>>;
using UnWeightedGraph = vector<vector<int>>;
template<typename T>
using Matrix = vector<vector<T>>;

/////////////////////////////////////////////////////////////////////

const ll inf = 1LL<<60;

int main()
{
  string s; cin>>s;
  int x = s.back() - '0';
  if (x==3) {
    cout << "bon" << endl;
  } else if (x==0 || x==1 || x==6 || x==8) {
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }


  return 0;
}


Measured memory_bytes: 3624
#include<stdio.h>
int main()
{

     int k,a,b,c=0;
     scanf("%d%d%d",&k,&a,&b);
     for(int i=a;i<=b;i++)
     {
          if(i%k==0)
               c++;

               }

       if(c>0)
     printf("OK\n");
else
     printf("NG\n");

}


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

int main()
{
    string S;
    cin >> S;
    if (S.size() == 1)
    {
        cout << 0 << endl;
        return 0;
    }

    int ans = 0;
    for (int i = 1; i < S.size(); i++)
    {
        if (S[i] != S[i - 1])
        {
            ans += 2;
            S.erase(S.begin() + (i - 1), S.begin() + i + 1);
            // cout << S << endl;
            if (i == 0 || i == 1 || i == 2)
            {
                i = 0;
            }
            else
            {
                i -= 2;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

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

bool isReverse(string str)
{
    string t = str;
    reverse(t.begin(), t.end());
    return t == str;
}

int main()
{
    string s;
    cin >> s;
    int len = s.length();
    string s1 = s.substr(0,(len-1)/2);
    string s2 = s.substr((len+2)/2, (len-1)/2);

    if(isReverse(s) && isReverse(s1) && isReverse(s2))
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define sort_1(v) sort(v.begin(),v.end())
#define sort_2(v) sort(v.begin(),v.end(),greater<ll>())
#define reverse(v) reverse(v.begin(),v.end())
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);

    int diff = 0;

    rep(i,0,n){
        cin >> a[i];
        b[i] = a[i];
    }

    sort_1(b);

    rep(i,0,n){
        if(a[i] != b[i]) diff++;
    }

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

    int q;
    cin >> q;

    rep(i,0,q){
        int x,y;
        cin >> x >> y;

        if(a[x-1] != b[x-1]){
            diff--;
        }
        if(a[y-1] != b[y-1]){
            diff--;
        }

        swap(a[x-1], a[y-1]);

        if(a[x-1] != b[x-1]){
            diff++;
        }
        if(a[y-1] != b[y-1]){
            diff++;
        }

        if(diff == 0){
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}


Measured memory_bytes: 5228
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
ll power(ll a,ll b){ll r=1;for(;b;b>>=1){if(b&1)r=r*a%mod;a=a*a%mod;}return r;}
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n;
	cin>>n;
	int a[n];
	for(int i = 0; i<n; i++) cin>>a[i];
	vector<ar<int,2> > v;
	int x = *min_element(a,a+n);
	if(x<=0)
	{
		int f = *max_element(a,a+n);
		if(f>=0)
		{
			if(abs(x)<f)
			{
				int j = -1;
				for(int i= 0; i<n;i++)
				{
					if(a[i]==f)
						j = i;
				}
				for(int i = 0; i<n;i++)
				{
					if(i==j) continue;
					a[i] += a[j];
					v.pb({j+1,i+1});
				}
				for(int i = 1;i<n; i++)
				{
					a[i] += a[i-1];
					v.pb({i,i+1});
				}
			}
			else
			{
				int j = -1;
				for(int i= 0; i<n;i++)
				{
					if(a[i]==x)
						j = i;
				}
				for(int i = 0; i<n;i++)
				{
					if(i==j) continue;
					a[i] += a[j];
					v.pb({j+1,i+1});
				}
				for(int i = n-2;i>=0; i--)
				{
					a[i] += a[i+1];
					v.pb({i+2,i+1});
				}
			}
		}
		else
		{
			for(int i = n-2; i>=0; i--)
			{
				a[i] += a[i+1];
				v.pb({i+2,i+1});
			}
		}
	}
	else
	{
		for(int i = 1; i<n; i++)
		{
			a[i] += a[i-1];
			v.pb({i,i+1});
		}
	}
	cout<<v.size()<<endl;
	for(auto it:v)
		cout<<it[0]<<" "<<it[1]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 500000
#define INFTY 1000000001

int L[N],R[N],count;

void merge(int *A, int left, int mid, int right){
    int i,j,k,n1,n2;
    n1 = mid - left;
    n2 = right - mid;
    //L[0...n1], R[0...n2] を生成
    for(i=0;i<n1;i++)
        L[i] = A[left + i];
    for(i=0;i<n2;i++)
        R[i] = A[mid + i];
    L[n1] = INFTY;
    R[n2] = INFTY;
    i = 0;
    j = 0;
    for(k=left;k<right;k++){
        count++;
        if(L[i] <= R[j]){
            A[k] = L[i];
            i++;
        }
        else{
            A[k] = R[j];
            j++;
        }
    }
}

void mergeSort(int *A, int left, int right){
    if(left+1 < right){
        int mid = (left + right)/2;
        mergeSort(A, left, mid);
        mergeSort(A, mid, right);
        merge(A, left, mid, right);
    }
}

int main(void){
    int n,i,A[N];
    scanf("%d",&n);
    for(i=0;i<n;i++)
        scanf("%d",&A[i]);
    mergeSort(A, 0, n);
    for(i=0;i<n-1;i++)
        printf("%d ",A[i]);
    printf("%d\n%d\n",A[i],count);
}





Measured memory_bytes: 5600
#include <iostream>
#include <fstream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <utility>
#include <map>
#include <set>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <functional>
#include <sstream>
#include <cstring>
#include <bitset>
#include <stack>
using namespace std;
#define MP make_pair
#define PB push_back
const int INF=1e9;
const int mod=1e9+7LL;

int n,a[100005];
long long f[100005],inv[100005],fi[100005],s,appear[100005];

inline void init()
{
	f[0]=f[1]=1LL;
	inv[0]=inv[1]=1LL;
	fi[0]=fi[1]=1LL;
	for (int i=2;i<=100001;i++)
	{
		f[i]=f[i-1]*(long long)i%(long long)mod;
		inv[i]=-(inv[mod%i]*(long long)(mod/i)%(long long)mod)+(long long)mod;
		fi[i]=fi[i-1]*inv[i]%(long long)mod;
	}
}

inline long long C(long long x,long long y)
{
	if (x<y) return 0LL;
	return ((f[x]*fi[y]%(long long)mod)*fi[x-y])%(long long)mod;
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n+1;i++) scanf("%d",&a[i]);
	init();
	for (int i=1;i<=n+1;i++) 
	{
		if (appear[a[i]])
			s=(long long)n-((long long)i-appear[a[i]]);
		else 
			appear[a[i]]=(long long)i;
	}
	for (int i=1;i<=n+1;i++)
	{
		long long p=C((long long)(n+1),(long long)i);
		long long q=C(s,(long long)(i-1));
	//	cout<<p<<" "<<q<<endl;
		long long ans=p-q;
		if (ans<0LL) ans+=(long long)mod;
		cout<<ans<<endl;
	}
	return 0;
}

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

#define int long long
struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 1e9 + 7;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))

signed main() {
    int n, k;
    cin >> n >> k;
    int ans = k;
    rep(i,n-1) ans *= k - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#define N 100100
using namespace std;

int n,mx,num[N];

inline bool pd(int u)
{
	int tt=0,i,cnt=0;
	bool have=0;
	for(i=1;i<=n;i++)
	{
		if(num[i]==u)
		{
			cnt++;
			continue;
		}
		if(u-num[i]>=2) return 0;
		tt++;
	}
	return u>=(tt+(!!cnt))&&u<=(tt+cnt/2);
}

int main()
{
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&num[i]);
		mx=max(mx,num[i]);
	}
	if(pd(mx)||pd(mx+1))
	{
		puts("Yes");
	}
	else puts("No");
}

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

map<int, int> m;
int n;

int main() 
{
	scanf("%d", &n);
	long long r = 0;
	for (int i = 0; i < n; ++i) {
		int v;
		scanf("%d", &v);
		r += m[i - v];
		++m[v + i];
	}
	printf("%lld\n", r);
	return 0;
}


Measured memory_bytes: 20200
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <cmath>
using namespace std;
typedef vector<int> VI;
#define REP( i, m, n ) for ( int i = (int)( m ); i < (int)( n ); ++i )

int main() {
    int tmp;
    VI heights;
    while (cin >> tmp) {
        heights.push_back(tmp);
    }
    sort(heights.begin(), heights.end(), [](int a, int b){return a > b;});
    
    REP(i, 0, 3) {
        cout << heights[i] << endl;
    }
    
    return 0;
}

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

int main() {
    int n; cin >> n;
    vector<int> v(n);

    rep(i, v.size())
        cin >> v.at(i);
    
    sort(v.begin(), v.end());
    double ave = v.at(0);
    for (int i = 1; i < v.size(); i++) {
        ave = (ave + v.at(i)) / 2;
    }

    cout << ave << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

// 解説は条件付き期待値
// （ゲームの回数の期待値）= 
// Σ(ゲーム中AかBが出る回数がM回である確率(A Bは正規化する)) * (ゲーム中AかBが出る回数がM回である時に、Cが出る回数も含めた総合回数の期待値)
// https://www.creativ.xyz/best-of-2n-1-1080/


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

    string s; cin >> s;
    
    if(s == "SUN") cout << 7 << endl;
    if(s == "MON") cout << 6 << endl;
    if(s == "TUE") cout << 5 << endl;
    if(s == "WED") cout << 4 << endl;
    if(s == "THU") cout << 3 << endl;
    if(s == "FRI") cout << 2 << endl;
    if(s == "SAT") cout << 1 << endl;

    
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;

template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b){
    if(a < b){
        a = b;
        return true;
    }
    return false;
}

int main(){

    int n, m, x;
    cin >> n >> m >> x;
    vector<int> c(n);
    int a[12][12];
    for(int i = 0; i < n; i++){
        cin >> c[i];
        for(int j = 0; j < m; j++){
            cin >> a[i][j];
        }
    }

    int cost;
    int ans = INF;
    for(int s = 0; s < (1 << n); s++){
        cost = 0;
        vector<int> v(m);
        bool flg = true;
        for(int i = 0; i < n; i++){
            if((s >> i) & 1){
                cost += c[i];
                for(int j = 0; j < m; j++){
                    v[j] += a[i][j];
                }
            }
        }
        for(int j = 0; j < m; j++){
            if(v[j] < x) flg = false;
        }
        if(flg) ans = min(ans, cost); 
    }
    if(ans == INF) cout << -1 << endl;
    else cout << ans << endl;
    return 0;
}

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

int main()
{
   int i,j,k;
   char mae[1024];
   char ato[1024];
   char str[10240];
  
   scanf("%s",mae);
   scanf("%s",ato);
  
   sprintf(str,"%s%s\0",ato,mae);
  
   printf("%s\n",str);
  
   return 0;
  
}

Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<queue>
#include<set>
#include<ctime>
#include<vector>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;

int ck[200005];

int main(){
    ios::sync_with_stdio(0); cin.tie(0), cout.tie(0);
    int n; cin >> n;
    for(int i = 1 ; i <= n ; i++){
      int tmp; cin >> tmp;
      ck[tmp] = ck[tmp-1]+1;
    }
    int mx = 0;
    for(int i = 1 ; i <= n ; i++){
      mx = max(mx, ck[i]);
    }
    cout << n - mx;
}


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

int main(){
    ll n;
    cin >> n;
    
    ll x, y;
    x = n / 500;
    y = n % 500;
    y = y / 5;
    y *= 5;
    x *= 1000;
    ll ans = x + y;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.text.*;
import java.util.zip.Adler32;

public class Main {
    static long[]val;

    static void calc(int n){
        val= new long[n+1];
        for (int i =1;i<=n;i++)
            for (int j =i;j<=n;j+=i)
                val[j]++;
        for (int i =1;i<=n;i++) {
            val[i] *= i;
            val[i]+=val[i-1];
        }
    }
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);
        calc((int)1e7);
        pw.println(val[sc.nextInt()]);
        pw.flush();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

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

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

        public String nextLine() throws IOException {
            return br.readLine();
        }

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

        public int[] nextIntArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }

        public boolean ready() throws IOException {
            return br.ready();
        }

    }
}

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

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> num(N, 0);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int nn;
      cin >> nn;
      nn--;
      num[nn]++;
    }
  }
  
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (num[i] == 0) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 3632
import sys
from collections import deque

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,m,k = map(int, input().split())
f = [[] for _ in range(n)]
g = [[] for _ in range(n)]

for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    f[a].append(b)
    f[b].append(a)

for _ in range(k):
    c, d = map(int, input().split())
    c, d = c - 1, d - 1
    g[c].append(d)
    g[d].append(c)

d = {}
parent = [-1] * n
seen = [False] * n

for i in range(n):
    if seen[i]:
        continue
    stack = deque()
    d[i] = set([i])
    stack = [i]
    while stack:
        v = stack.pop()
        seen[v] = True
        parent[v] = i
        for nv in f[v]:
            if seen[nv]:
                continue
            d[i].add(nv)
            stack.append(nv)

ans = [0] * n
for i in range(n):
    group = d[parent[i]]
    tmp = len(group) - len(f[i]) - 1
    for j in g[i]:
        if j in group:
            tmp -= 1
    ans[i] = tmp

print(*ans)


Measured memory_bytes: 134048
process.stdin.resume();
process.stdin.setEncoding('utf8');
 
process.stdin.on('data', function(input){
    input.trim().split('\n').forEach(function(val){
        var N = parseInt(val);
        if( N === 1 ){
            console.log(0);
        }
        else if(N===2){
            console.log(1);
        }
        else{
            var prime = new Array(N);
            var sq, i, j, found, cnt;
            sq = Math.sqrt(N);
            cnt = 1;
            prime[0] = 2;
            
            for(i=3;i<=N;++i){
                found = 1;
                for(j=0;prime[j]<=sq;++j){
                    if( i % prime[j] === 0 ){
                        found = 0;
                        break;
                    }
                }
                if( found ){
                    prime[cnt++] = i;
                }
            }
            console.log(cnt);
        }
    });
});

Measured memory_bytes: 26976
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <unordered_map>

using namespace std;

using ll = long long;
using ld = long double;

template<class T> using vec = vector<T>;
template<class T> using vvec = vector<vector<T>>;

#define REP(i, s, e) for (ll i = s; i < e; ++i)

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

    int N, M; cin >> N >> M;
    vec<int> ns(N, -1);
    REP(i, 0, M)
    {
        int s, c; cin >> s >> c; --s;

        if (ns[s] != -1 && ns[s] != c)
        {
            cout << -1 << endl;
            return 0;
        }

        ns[s] = c;
    }

    if (N == 1)
    {
        cout << (ns[0] == -1 ? 0 : ns[0]) << endl;
        return 0;
    }

    bool topFilled = false;
    REP(i, 0, N)
    {
        if (!topFilled && ns[i] == 0)
        {
            cout << -1 << endl;
            return 0;
        }

        cout << (ns[i] == -1 ? (topFilled ? 0 : 1) : ns[i]);
        topFilled = true;
    }

    return 0;
}


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

const int side[6][6] = {
	{-1, 3, 5, 2, 4, -1},
	{4, -1, 1, 6, -1, 3},
	{2, 6, -1, -1, 1, 5},
	{5, 1, -1, -1, 6, 2},
	{3, -1, 6, 1, -1, 4},
	{-1, 4, 2, 5, 3, -1}
};

const int rotation[4][6] = {
	{1, 5, 2, 0, 4, 3},
	{2, 1, 5, 3, 0, 4},
	{3, 0, 2, 5, 4, 1},
	{4, 1, 0, 3, 5, 2}
};

struct Dice {
	int num[6];
	Dice(int top, int front) {
		num[0] = top;
		num[1] = front;
		num[2] = side[top - 1][front - 1];
		num[3] = 7 - front;
		num[4] = 7 - num[2];
		num[5] = 7 - top;
	}

	void rotate(int dir) {
		dir--;
		int cp[6];
		for(int i = 0; i < 6; i++)
			cp[i] = num[i];
		for(int i = 0; i < 6; i++) {
			num[rotation[dir][i]] = cp[i];
		}
	}
};

int level[210][210];
int field[210][210];

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main() {
	for(int N; cin >> N, N;) {
		memset(level, 0, sizeof level);
		memset(field, -1, sizeof field);
		for(int n = 0; n < N; n++) {
			int t, f;
			cin >> t >> f;
			Dice d(t, f);
			int x = 100;
			int y = 100;
			while(true) {
				if(level[x][y] == 0) break;
				int s = -1;
				int index = -1;
				for(int i = 1; i <= 4; i++) {
					if(d.num[i] <= 3) continue;
					int nx = x + dx[i - 1];
					int ny = y + dy[i - 1];
					if(level[x][y] > level[nx][ny]) {
						if(s < d.num[i]) {
							s = d.num[i];
							index = i;
						}
					}
				}
				if(s == -1) break;
				d.rotate(index);
				int nx = x + dx[index - 1];
				int ny = y + dy[index - 1];
				x = nx;
				y = ny;
			}

			field[x][y] = d.num[0];
			level[x][y]++;
		}

		int cnt[6];
		memset(cnt, 0, sizeof cnt);
		for(int x = 0; x < 210; x++) {
			for(int y = 0; y < 210; y++) {
				if(field[x][y] != 0)
					cnt[field[x][y] - 1]++;
			}
		}
		for(int i = 0; i < 5; i++) {
			cout << cnt[i] << " ";
		}
		cout << cnt[5] << endl;
	}
}

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

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

  int count = 0;
  for (int i = 0; i < str.size(); i++) {
    if (str.at(i) == '1') {
      count++;
    }
  }

  cout << count << endl;
}




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

int main() {
	vector<int> vec = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

	int k;
	cin >> k;

	cout << vec.at(k - 1) << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;

#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(x) ((x).begin()), ((x).end())

#define READ(x) (cin >> (x))
#define WRITE_N(x) (cout << (x) << endl)
#define WRITE(x) (cout << (x))
#define WRITE_YESNO(x) (WRITE_N((x) ? "Yes" : "No"))

#define PRECISE_COUT std::cout << std::setprecision(15) << std::fixed

bool xor_logic(bool x, bool y) { return (x && y) || (!x && !y); }

ll solve(vector<ll>& A) {
  ll money = 1000;

  ll tmp_min = A[0];

  for (size_t i = 1; i < A.size(); i++) {
    if (A[i] > tmp_min) {
      money += (A[i] - tmp_min) * (ll)(money / tmp_min);
      tmp_min = A[i];
    } else {
      tmp_min = A[i];
    }
  }

  return money;
}

int main() {
  // get values from input
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin >> N;

  std::vector<ll> A(N, 0);
  for (size_t i = 0; i < N; i++) {
    cin >> A[i];
  }

  // main procedure
  ll ans = solve(A);

  // output
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3636
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<stack>
#include<tuple>
using namespace std;
#define INF 1100000000000
#define MAX 100000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)

double dp[3100][3100];

int main(){
    int N;
    cin>>N;
    dp[0][0]=1;
    for(int i=0;i<N;i++){
        double q; cin>>q;
        for(int j=0;j<=i;j++){
            dp[i+1][j+1]+=dp[i][j]*q;
            dp[i+1][j]+=dp[i][j]*(1-q);
        }
    }
    double ans=0;
    for(int i=N/2+1;i<=N;i++){
        ans+=dp[N][i];
    }
    printf("%.10lf\n",ans);
}



Measured memory_bytes: 72320
using System;

namespace AtCoder2020Ned
{
    class Program
    {
        private static int bingoCardSize = 3;
        static void Main(string[] args)
        {
            var numberOfDocuments = int.Parse(Console.ReadLine());
            var documents = Console.ReadLine().Split(' ');

            for (int i = 0; i < documents.Length; i++)
            {
                var document = int.Parse(documents[i]);

                if (document % 2 == 0)
                {
                    if (!(document % 3 == 0 || document % 5 == 0))
                    {
                        Console.WriteLine("DENIED");
                        Console.Read();
                        return;
                    }
                }
            }

            Console.WriteLine("APPROVED");
            Console.Read();
        }
    }
}


Measured memory_bytes: 13140
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
#include<map>
using namespace std;

//#define int long long
using namespace std;

class UF {
public:
	vector<int> rank;
	vector<int> p;

	UF() {}
	UF(int size) {
		rank.resize(size, 0);
		p.resize(size, 0);
		for (int i = 0;i < size;i++) makeSet(i);
	}
	
	void makeSet(int x) {
		p[x] = x;
		rank[x] = 0;
	}
	
	bool same(int x, int y) {
		return findSet(x) == findSet(y);
	}

	void unite(int x, int y) {
		link(findSet(x), findSet(y));
	}

	void link(int x, int y) {
		if (rank[x] > rank[y]) {
			p[y] = x;
		}
		else {
			p[x] = y;
			if (rank[x] == rank[y]) {
				rank[y]++;
			}
		}
	}

	int findSet(int x) {
		if (x != p[x]) {
			p[x] = findSet(p[x]);
		}
		return p[x];
	}
};


int main() {
	int N, Q;
	cin >> N >> Q;
	UF u = UF(N);

	for (int i = 0;i < Q;i++) {
		int com, x, y;
		cin >> com >> x >> y;
		//x--; y--;//0-indexed
		
		if (com == 0) u.unite(x, y);
		else cout << u.same(x, y) << endl;
	}

}

Measured memory_bytes: 3116
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
 
//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
signed main() {
	int n, Ma, Mb; cin >> n >> Ma >> Mb;
	vector<int>a(n), b(n), c(n);
	rep(i, 0, n) {
		cin >> a[i] >> b[i] >> c[i];
 
	}
	vector<vector<vector<int>>>dp(n + 1, vector<vector<int>>(409, vector<int>(409, INF)));
	dp[0][0][0] = 0;
	rep(i, 0, n) {
		rep(j, 0, 409) {
			rep(k, 0, 409) {
				if (dp[i][j][k] != INF) {
					dp[i + 1][j][k] = min(dp[i][j][k], dp[i + 1][j][k]);
 
					dp[i + 1][j+a[i]][k+b[i]] = min(dp[i + 1][j+a[i]][k+b[i]], dp[i][j][k] + c[i]);
				}
			}
		}
	}
	int ans = INF;
	rep(i, 1, 409) {
		rep(j, 1, 409) {
			if (i*Mb == j*Ma)ans = min(ans, dp[n][i][j]);
		}
	}
	cout << ((ans == INF) ? -1 : ans) << endl;
	return 0;
}

Measured memory_bytes: 28288
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,takoyaki[100],sum=0;
  cin >>n;
  for(int i=0;i<n;i++)
    cin>>takoyaki[i];
  for(int i=0;i<n-1;i++)
    for(int j=i+1;j<n;j++)
      sum+=takoyaki[i]*takoyaki[j];
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 256
// ???????????????????????¶?????????
 
#include <cstdio>
#include <algorithm>
 
int replacement[4][2][5] = {
    {{1, 2, 3, 15, 19}, {28, 29, 30, 16, 21}},
    {{7, 8, 9, 13, 10}, {22, 23, 24, 18, 12}},
    {{1, 4, 7, 10, 16}, {24, 27, 30, 21, 18}},
    {{3, 6, 9, 12, 13}, {22, 25, 28, 19, 15}}
};
 
int p[31];
 
bool isComplete(){
    for(int i=1;i<=9;i++){
        if(p[i] != p[1]){return false;}
    }
 
    for(int i=22;i<=30;i++){
        if(p[i] != p[22]){return false;}
    }
 
    for(int i=10;i<=21;i++){
        if(p[i] != p[10+(i-10)/3*3]){return false;}
    }
 
    return true;
}
 
void replace(int index){
    for(int i=0;i<5;i++){
        std::swap(p[replacement[index][0][i]],
                  p[replacement[index][1][i]]);
    }
}
 
int dfs(int t){
    if(isComplete()){return t;}
    if(t >= 8){return 1001001001;}
 
    int res = 1001001001;
    for(int i=0;i<4;i++){
        replace(i);
        res = std::min(res, dfs(t+1));
        replace(i);
    }
 
    return res;
}
     
int main(){
    int N;
    scanf("%d", &N);
 
    while(N--){
        for(int i=1;i<=30;i++){
            scanf("%d", p+i);
        }
 
        printf("%d\n", dfs(0));
    }
}

Measured memory_bytes: 1008
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

class Program
{
    public static long Div(long A,long B)
    {
        if (A == 0)
            return 0;
        else
            return A / B;
    }

    public static void Main()
    {
        var s = Console.ReadLine().Split(' ');
        long A = long.Parse(s[0]);
        long B = long.Parse(s[1]);
        long C = long.Parse(s[2]);
        long D = long.Parse(s[3]);

        long dc = Div(B, C) - Div(A - 1, C);
        long dd = Div(B, D) - Div(A - 1, D);
        long dcom = Div(B, Lcm(C, D)) - Div(A - 1, Lcm(C, D));

        Console.WriteLine((B - A + 1) - (dc + dd - dcom));
    }

    public static long Lcm(long a, long b)
    {
        return a * b / Gcd(a, b);
    }
    
    public static long Gcd(long a, long b)
    {
        if (a < b)
            return Gcd(b, a);
        while (b != 0)
        {
            var remainder = a % b;
            a = b;
            b = remainder;
        }
        return a;
    }
}

Measured memory_bytes: 13140