akhauriyash/Code-Regression huggingface dataset:
import numpy as np
from scipy import signal


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

    dA = list()
    for i in range(N-1):
        dA.append(A[i+1]-A[i])

    idn = list()
    upflag = False
    downflag = False
    if dA[0] > 0:
        upflag = True
        tmp = 0
    elif dA[0] < 0:
        downflag = True
    for i, a in enumerate(dA[1:], 1):
        if downflag and a > 0:
            tmp = i
            upflag = True
            downflag = False
        elif upflag and a < 0:
            idn.append((tmp, i))
            upflag = False
            downflag = True
        elif (upflag is False) and (downflag is False):
            if a > 0:
                upflag = True
                tmp = i - 1
            elif a < 0:
                downflag = True
    if upflag:
        idn.append((tmp, N-1))

    ans = 1000
    for n in idn:
        ans = (ans//A[n[0]]) * A[n[1]] + (ans % A[n[0]])

    print(ans)


if __name__ == "__main__":
    main()


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

int main() {
  int m, d;
  cin >> m >> d;
  
  int i, j, a, b, ans = 0;
  for(i = 1; i <= m; i++){
    for(j = 1; j <= d; j++){
      a = j % 10;
      b = j / 10;
      if(a >= 2 && b >= 2 && a * b == i) ans++;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.math.*;
     
class Main{
    public static void main(String[] args) {
        
        try(Scanner sc = new Scanner(System.in)){
            String s = sc.next();
            String t = sc.next();

            int diff = 0;

            for(int i = 0; i < s.length(); i++){
                String subStrS = s.substring(i, i + 1);
                String subStrT = t.substring(i, i + 1);

                if(!subStrS.equals(subStrT)) diff++;
            }

            System.out.println(diff);


        }catch(Exception e){
            e.printStackTrace();
        }        
    }
}

Measured memory_bytes: 55768
<?php

$number = trim(fgets(STDIN));
$length = strlen($number);
$res = substr($number, ($length - 1), 1);

if ($res == 2 || $res == 4 || $res == 5 || $res == 7 || $res == 9) {
    echo "hon\n";
} elseif ($res == 0 || $res == 1 || $res == 6 || $res == 8) {
    echo "pon";
} else {
    echo "bon";
}


Measured memory_bytes: 16148
N=int(input())
xyh=[list(map(int,input().split(' '))) for i in range(N)]
for i in range(101):
    for j in range(101):
        H_0=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh])
        H_1=set([h+abs(x-i)+abs(y-j) for x,y,h in xyh if h!=0])
        if len(H_0)==1:
            print(i,j,max(H_0))
            exit()
        if len(H_1)==1:
            cx,cy,H=i,j,max(H_1)
print(cx,cy,H)

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <map>

using namespace std;

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

        sort(A.begin(), A.end());
        sort(B.rbegin(), B.rend());
    if(N%2) {
        int ans = B[N/2] - A[N/2] + 1;
        cout << ans << endl;
    } else {
        int min = A[N/2-1] + A[N/2];
        int max = B[N/2-1] + B[N/2];
        cerr << min << ' ' << max << endl;
        cout << max - min + 1 << endl;
    }
    return 0;
}


Measured memory_bytes: 4840
#include <bits/stdc++.h>
#define int long long
#define gcd            __gcd
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x,y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;

int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int modi(int a, int m)
{
    return power(a, m - 2, m);
}
int32_t main()
{
    nitin;
    string S;
    cin>>S;
    int n,s,w,e;
    n=0;
    s=0;
    w=0;
    e=0;
    for(auto c:S)
    {
        if(c=='S')
            s++;
        if(c=='N')
            n++;
        if(c=='W')
            w++;
        if(c=='E')
            e++;
    }
    if((s!=0 && n==0)||(s==0 && n!=0)||(e==0 && w!=0)||(e!=0 && w==0)){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3624
// OPTIMAL GAME STRATEGY-I
// Piyush and Nimit are playing a coin game. They are given n coins with values x1, x2 …. xn where 'n' is always even. They take alternate terms. In each turn, a player picks either the first coin or the last coin from the row and removes it from the row. The value of coin is received by that player. Determine the maximum value that piyush can win if he moves first. Both the players play optimally.


// Input Format:
// First line contains the number of coins 'n'. Second line contains n space separated integers which is the value of ith coin.

// Constraints:
// N < 30

// Output Format:
// Print a single line with the maximum possible value.

// Sample Input:
// 4
// 1 2 3 4
// Sample Output:
// 6
// Explanation:
// Piyush will pick the coin 4. Then nimit can pick either 1 or 3. In both the cases piyush picks coin 2 and wins with a total of 6.
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll dp[3001][3001];
ll GETSCORE(ll array[],ll startingIndex,ll endingIndex)
{
    if(endingIndex<startingIndex)
    {
        return 0;
    }
    if(dp[startingIndex][endingIndex]!=-1)
    {
        return dp[startingIndex][endingIndex];
    }
    ll score=0;
   
    ll start=array[startingIndex]+min(GETSCORE(array,startingIndex+1,endingIndex-1),GETSCORE(array,startingIndex+2,endingIndex));
    ll end=array[endingIndex]+min(GETSCORE(array,startingIndex+1,endingIndex-1),GETSCORE(array,startingIndex,endingIndex-2));
    score+=max(start,end);
    dp[startingIndex][endingIndex]=score;
    return score;
    
}
int main()
{
    ll N;
   
    cin>>N;
     ll array[N];
     ll sum=0;
    for(ll p=0;p<N;p++)
    {
        cin>>array[p];
        sum+=array[p];
    }
    memset(dp,-1,sizeof(dp));
  
     ll count= GETSCORE(array,0,N-1);
     ll ScoreY=sum-count;
    cout<<count-ScoreY<<endl;
	
}

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

using namespace std;
using ll = long long;

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#ifdef LOCAL
	#define lcout(a) cout << a;
	#define lcoutln(a) cout << a << endl;
	#define lcerr(a) cerr << a;
	#define lcerrln(a) cerr << a << endl;
#else
	#define lcout(a) 
	#define lcoutln(a) 
	#define lcerr(a) 
	#define lcerrln(a) 
#endif

int H, W, N, a[10000], pos;

void ne()
{
	if (a[pos]) a[pos]--;
	else {
		pos++;
		a[pos]--;
	}
}

int main()
{
	cin >> H >> W >> N;
	rep(i, N) cin >> a[i];
	rep(i, H) {
		vector<int> v;
		rep(j, W) {
			ne();
			v.PB(pos+1);
		}
		if (i % 2) reverse(all(v));
		rep(j, W) cout << v[j] << " \n"[j==W-1];
	}
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
#include <utility>
#include <cstring>
#include <numeric>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define repll(i,n) for(long long int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
template <typename T_char>
char ToUpper (char cX) { return toupper(cX); }
//g++ -std=c++1z temp.cpp
//./a.exe
ll digit(ll a){
    ll count = 0;
    for (ll i = 0; i < a; i++)
    {   if (a == 0)
        {
            break;
        }else
        {
            a = a/10;
            count++;
        }
    }
    return count;
}
//桁数のカウント
//pow(x,n) == x^n
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a;}
ll lcm(ll a, ll b) { return a / gcd(a,   b) * b;}



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

int a,b;
cin >> a >> b;

if(a == b) cout << "Yes" << endl;
else cout << "No" << endl;


//////////////////////////////////////////////////////
return 0;}

Measured memory_bytes: 256
# coding: utf-8
import sys

# from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
printout = sys.stdout.write
sprint = sys.stdout.flush
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
#import math
# from itertools import product, accumulate, combinations, product
#import bisect
# import numpy as np
# from copy import deepcopy
from collections import deque
# from decimal import Decimal
# from numba import jit

INF = 1 << 50
EPS = 1e-8
mod = 998244353


def intread():
    return int(sysread())
def mapline(t=int):
    return map(t, sysread().split())
def mapread(t=int):
    return map(t, read().split())

def dfs(c, to, seen, g = None):
    if g == None:g = set()
    g.add(c)
    seen.add(c)
    for n in to[c]:
        if not n in seen:
            dfs(n, to, seen, g)
    return g, seen


def run():
    N, M = mapline()
    to = [[] for _ in range(N+1)]
    for _ in range(M):
        a,b = mapline()
        to[a].append(b)
        to[b].append(a)

    seen = set()
    G = []
    for i in range(1, N+1):
        if not i in seen:
            g, seen = dfs(i, to, seen)
            #print(i, seen)
            G.append(g)
    #print(G)
    print(len(G) -1)



if __name__ == "__main__":
    run()


Measured memory_bytes: 60120
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main() {
  int N, M;
  int wa[SIZE] = {}, ans1 = 0, ans2 = 0;

  cin >> N >> M;

  for (int i=0; i<M; i++) {
    int p;
    string s;

    cin >> p >> s;

    if (s == "AC") {
      ans1 += wa[p] >= 0;
      ans2 += max(0, wa[p]);
      wa[p] = -INF;
    } else {
      wa[p]++;
    }
  }

  cout << ans1 << " " << ans2 << endl;

  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <math.h>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i=s;i<n;i++)
#define repe(i,s,n)for(ll i=s;i<=n;i++)
#define rep_r(i,s,n)for(ll i=n-1;i>=s;i--)
#define repe_r(i,s,n)for(ll i=s;i<=n;i++)
static const ll MOD = 1e9 + 7;
static const ll MAX_L = (ll)1 << 55;

ll a[100001] = {};
ll b[100001] = {};
vector<pair<ll, ll>> v;

int main() {
	ll n; cin >> n;
	rep(i, 0, n) {
		cin >> a[i] >> b[i];
		v.push_back(make_pair(a[i] + b[i], i));
	}

	sort(v.begin(), v.end());
	reverse(v.begin(), v.end());

	ll taka = 0, aoki = 0;
	rep(i, 0, n) {
		if (!(i & 1)) taka += a[v[i].second];
		else aoki += b[v[i].second];
	}
	cout << taka - aoki << endl;
	return 0;
}

Measured memory_bytes: 3444
#include "bits/stdc++.h"
using namespace std;

//

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

int n,k;
int a[100000];

int cover(){
  return (n-k)%(k-1)==0?1+(n-k)/(k-1):2+(n-k)/(k-1);
}

int main(){
  cin>>n>>k;
  REP(i,n){
    cin>>a[i];
  }
  cout<<cover()<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <cstdlib>
#include <cmath>

using namespace std;

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(C>=A && C<=B)  cout << "Yes" << endl;
  else  cout << "No" << endl;
  
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		int v=Math.min(getInt()*4,Math.min(getInt()*2,getInt())),d=getInt();
		long n=getInt();
		System.out.println(
				Math.min(n*v,n/2*d+n%2*v)
				);
	}
}

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

int main(){
  string yobi;
  cin>>yobi;
  //cout<<yobi<<endl;
  if(yobi=="SUN")cout<<7<<endl;
  if(yobi=="MON")cout<<6<<endl;
  if(yobi=="TUE")cout<<5<<endl;
  if(yobi=="WED")cout<<4<<endl;
  if(yobi=="THU")cout<<3<<endl;
  if(yobi=="FRI")cout<<2<<endl;
  if(yobi=="SAT")cout<<1<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    char c[3][3];
    for (int i = 0; i < 3;i++){
        for (int j = 0; j < 3;j++){
            cin >> c[i][j];
        }
    }
    cout << c[0][0] << c[1][1] << c[2][2];
}

Measured memory_bytes: 256
# countBcd[i] : 最大公約数がiとなる数列の個数
# 全てiの倍数である数列の数はint(K/i) ** N ただし、全てi*2,i*3・・・の場合を除く

N, K = [int(x) for x in input().split()]
countBcd = [0]*(K+1)
mod=10**9+7
sumTotal=0
for i in range(K,0,-1):
    countBcd[i] = pow(K//i,N,mod)

    for j in range(i*2,K+1,i):
        countBcd[i] -= countBcd[j]

    sumTotal += i*countBcd[i]%mod

print(sumTotal%mod)


Measured memory_bytes: 11220
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define sz(a) (ll)(a.size())
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int n;
	cin>>n;
	vector<int> vec;
	for(int i=1;i<=n;i++)
	{
		int x;
		cin>>x;
		vec.pb(x);
	}
	sort(all(vec));
	int ans = 0;
	for(int i=0;i<sz(vec);i++)
	{
		for(int j=i+1;j<sz(vec);j++)
		{
			for(int k=j+1;k<sz(vec);k++)
			{
				if(vec[i]==vec[j] || vec[j] == vec[k])
					continue;
				if(vec[k]<vec[i]+vec[j])
					ans++;
			}
		}
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 3660
N = int(input())
A = list(map(int, input().split()))

A_diff = []
for i, a in enumerate(A):
    A_diff.append(a - (i + 1))
    

A_diff.sort()
A_diff.reverse()

print(sum(list(map(lambda x : abs(x - A_diff[N//2]), A_diff))))

Measured memory_bytes: 26808
#include <bits/stdc++.h>
using namespace std;
//int num[100000];
int main(){
	int x=0,y=0,z=0;long long a=0,b=0,c=0;
	char m,n,p;
	scanf("%c%c%c",&m,&n,&p);
	if(m==n&&m==p)printf("No");else printf("Yes");
	//printf("%d",x);
}

Measured memory_bytes: 256
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(c) string(1,c)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[100010];

int main() {
	string ss[4] = {"dream", "dreamer", "erase", "eraser"};
	string s;
	cin >> s;
	clr(dp, 0);
	dp[0] = 1;
	rep(i, 1, s.sz+1) {
		rep(j, 0, 4) {
			ll l = ss[j].sz;
			if (i >= l) {
				int flag = 1;
				rep(k, 0, l) {
					if (s[i - l + k] != ss[j][k]) {
						flag = 0;
					}
				}
				if (flag == 1 && dp[i - l] == 1) {
					dp[i] = 1;
				}
			}
		}
	}
	if (dp[s.sz] == 1) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define rrep2(ri,x,n) for(int ri = (int)(n-1); ri >= (int)(x); ri--)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int n, m;
  cin >> n >> m;
  vector<vector<int>> tree(n, vector<int>());
  vector<int> indeg(n, 0);
  rep(i, n-1+m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree.at(a).push_back(b);
    indeg.at(b)++;
  }
  vector<int> ans(n, -1);
  int root = -1;
  rep(i, n){
    if(indeg.at(i) == 0) root = i;
  }

  queue<int> q;
  q.push(root);
  while(!q.empty()){
    int now = q.front(); q.pop();
    for(int nx : tree.at(now)){
      indeg.at(nx)--;
      if(indeg.at(nx) == 0){
        ans.at(nx) = now;
        q.push(nx);
      }
    }
  }
  for(auto i : ans){
    cout << i+1 << endl;
  }
  return 0;
}

Measured memory_bytes: 9536
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <string>
#include <bitset>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10


int main() {
	int x, a; cin >> x >> a;
	print((x < a) ? 0 : 10);

	return 0;
}


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

int main()
{
  int a,b;
  cin>>a>>b;
  if(a>=13)
  {
    cout<<b<<endl;
  }
  else if(a>=6)
  {
    cout<<b/2<<endl;
  }
  else
  {
    cout<<0<<endl;
  }
}


Measured memory_bytes: 256
n,q=map(int, raw_input().split())
s=list(raw_input())
cum=0
cum_array=[0]
for p in range(len(s)-1):
    if s[p] == 'A' and s[p+1] == 'C':
        cum+=1
    cum_array.append(cum)
cum_array.append(cum)
for i in range(q):
    l,r=map(int, raw_input().split())
    print(cum_array[r-1]-cum_array[l-1])

Measured memory_bytes: 10612
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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字くらい使った方がいいかも
*/

class UnionFind{
public:
    //親の番号を格納する。親だった場合はー（その集合のサイズ）
    vector<int> parents;

    //作る時はparentsを-1で初期化する
    //こうすることで全部ばらばらになる
    UnionFind(int n){
        parents = vector<int>(n, -1);
    }

    //Aがどのグループにいるか調べる
    int root(int A){
        if(parents[A]<0) return A;
        return parents[A] = root(parents[A]);
    }

    //自分のいるグループの大きさを調べる
    int size(int A){
        return -parents[root(A)];
    }

    //AとBをくっつける
    bool connect(int A, int B){
        //AとBを直接ではなく親同士をくっつける
        A=root(A);
        B=root(B);
        if(A==B){
            return false;
        }

        //大きい方（A)に小さい方（B)をくっつけたい
        if(size(A)<size(B)) swap(A, B);

        parents[A] += parents[B];
        parents[B] = A;

        return true;
    }
};

int main(){
    int N, M; cin >> N >> M;
    vector<int> p(N, 0);
    for(int i=0; i<N; i++){
        int a; cin >> a; a--;
        p[i] = a;
    }

    UnionFind uni(N);

    for(int i=0; i<M; i++){
        int x, y; cin >> x >> y;
        x--, y--;
        uni.connect(x, y);
    }

    int ans = 0;
    for(int i=0; i<N; i++) if(uni.root(i) == uni.root(p[i])) ans++;

    cout << ans << endl;
}

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

#define int long long
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz(v) (int) v.size()
#define TASK ""

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

signed main() {
#ifdef LOCAL
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
if (strlen(TASK) > 0)
	freopen(TASK".in", "r", stdin),
	freopen(TASK".out", "w", stdout);
#endif
	ios_base::sync_with_stdio(0);
	cin.tie(0);

  int n;
  cin >> n;
  set<int> have;
  int x, ans = 0;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (have.empty() || *have.begin() >= x) {
     ++ans;
    }
    have.insert(x);
  }
  cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 9600
N = int(input())
num_list = list(map(int, input().split())) 

num_list.sort()
num_list.reverse()

for i in range(N):
  if i==0:
    sum = num_list[0]
  elif i%2==0:
    sum = sum + num_list[i]
  else:
    sum = sum - num_list[i]

print(sum)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int a1[100000],a2[100000];
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	for(int i=1;i<=c;i++){
		cin >> a1[i];
	}
	for(int i=1;i<=c;i++){
		a2[a1[i]]++;
	}
	int t=0;
	for(int i=1;i<=a;i++){
		if(t<a2[i]){
			t=a2[i];
		}
	}
	for(int i=1;i<=a;i++){
		if(b-c+a2[i]>0){
			if(i!=a){
				cout<<"Yes"<<endl;
			}else{
				cout<<"Yes";
			}
			
		}else{
			if(i!=a){
				cout<<"No"<<endl;
			}else{
				cout<<"No";
			}
		}

	}
}

Measured memory_bytes: 1408
from __future__ import division, print_function
from sys import stdin
r, c = (int(s) for s in stdin.readline().split())
sheet = [[int(s) for s in stdin.readline().split()] for _ in range(r)]
sheet.append([sum(row[i] for row in sheet) for i in range(c)])
for row in sheet:
    row.append(sum(row))
    print(*row)

Measured memory_bytes: 4316
use proconio::input;
use std::cmp;
#[allow(non_snake_case)]
fn main() {
    input! {
        a: i64,
        b: i64,
        c: i64,
        d: i64
    }

    let res = cmp::max(cmp::max(a * c, a * d), cmp::max(b * c, b * d));
    println!("{}", res);
}


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

bool specialEvent(int i, int n, vector<int> lb){
    bool boooo = false;
    for(int k=0; k<n && lb[k]<=i; ++k){                  
        if(lb[k]==i){
            boooo = true;
            break;
        }
    }
    return boooo;
}

int main(void){
    int N,T,L,B;
    double p1 = (double)1/(double)6;
    while(cin >> N >> T >> L >> B){
        if(N==0 && T == 0 && L == 0 && B ==0){break;}

        vector<int> lose(L);
        for(int i=0; i<L; ++i){cin >> lose[i];}
        vector<int> back(B);
        for(int i=0; i<B; ++i){cin >> back[i];}
        
        vector<double> a(T+1,(double)0);
        vector< vector<double> > p(N, a);
        vector< vector<double> > ex(N, a);


        for(int i=0; i<N;++i){                             //set p[i][1]
            bool loseOneTurn = specialEvent(i,L,lose);
            bool backToStart = specialEvent(i,B,back);

            if(loseOneTurn){
                p[i][1] = (double)0;
                if(i+6>=N){
                    ex[i][1] = p1;
                }
            } else if(backToStart){
                p[i][1] = p[0][1];
            } else {
                if(i+6>=N){
                    p[i][1] = p1;
                } else {
                    p[i][1] = (double)0;
                }
            }
        }

        for(int j=2; j<T+1; ++j){                    //calculate p[i][j] (j=2 to T)
            for(int i=0; i<N; ++i){
                bool loseOneTurn = specialEvent(i,L,lose);
                bool backToStart = specialEvent(i,B,back);

                if(loseOneTurn){
                    p[i][j] = ex[i][j-1];
                    for(int index=1; index<7; ++index){
                        int loc = i+index;
                        if(loc<N){
                            ex[i][j] += p1 * p[loc][j-1];
                        } else if(loc>N){
                            loc = 2*N-loc;
                            ex[i][j] += p1 * p[loc][j-1];
                        } else{
                            ex[i][j] += p1;
                        }
                    }
                } else if(backToStart){
                    p[i][j] = p[0][j];
                } else {
                    for(int index=1; index<7; ++index){
                        int loc = i+index;
                        if(loc<N){
                            p[i][j] += p1 * p[loc][j-1];
                        } else if(loc>N){
                            loc = 2*N-loc;
                            p[i][j] += p1 * p[loc][j-1];
                        } else {
                            p[i][j] += p1;
                        }
                    }
                }
            }
        }

        printf("%.6lf\n", p[0][T]);
    }

return 0;

}


Measured memory_bytes: 3244
import java.util.Scanner;
 
public class Main {
 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int ans = 0;
		for(int i = 1; i <= x; i++) {
			int temp = 0;
			for(int j = 2; j <= 10; j++) {
				int judge = (int) Math.pow(i, j);
				if(judge > x) {
					break;
				}
				temp = judge;
			
			}
			ans = Math.max(temp, ans);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22356
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <climits>

using namespace std;

int main() {
   int n;

   cin >> n;

   vector<int> h(n);

    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }

    int min = h[0];

    int maxCnt = 0;
    int cnt = 0;


    for (int j = 1; j < n; ++j) {
        if (min >= h[j]) {
            cnt++;
            maxCnt = max(cnt, maxCnt);
        } else {
            cnt = 0;
        }
        min = h[j];

    }
    

    cout << maxCnt << endl;


}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;
#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define PI 3.1415926535
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<Pll> vPll;
typedef vector<vector<int>> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<vector<ll>> vvll;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<double>> vvd;
typedef vector<vector<Pi>> vvPi;
typedef priority_queue<int, vector<int>, greater<int>> pqli;
typedef priority_queue<ll, vector<ll>, greater<ll>> pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi>> pqlP;
string YN(bool y) { return (y?"YES":"NO"); }
string yn(bool y) { return (y?"Yes":"No"); }
string ON(bool y) { return (y?"OK":"NG"); }
int main(void)
{
	ll n, k;

	cin>>n>>k;

	vPll a(n);

	rep(i, n){
		cin>>a[i].first>>a[i].second;
	}
	sort(all(a));

	vll sum(n+1, 0);

	rep(i, n){
		sum[i+1]=sum[i]+a[i].second;
	}

	int j=0;
	while(sum[j]<k) j++;

	cout<<a[j-1].first<<endl;
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <sstream>
#include <list>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cstdio>


using namespace std;

int main(){
    int N;
    cin >> N;
    vector<double> v(N);
    for(int i = 0; i < N; ++i) cin >> v[i];
    sort(v.begin(), v.end());

    for(int i = 0; i < N - 1; ++i) v[i + 1] = (v[i] + v[i + 1]) / 2.0;
    
    cout << v[N - 1] << endl;

    return 0;
}


Measured memory_bytes: 256
K = int(input())
A = list(map(int, input().split()))
min = 2
max = 2
for i in range(K-1, -1, -1):
    if max < A[i]:
        print(-1)
        exit()
    min = (min + A[i] - 1) // A[i] * A[i]
    max = (max // A[i] + 1) * A[i] - 1
    if max < min:
        print(-1)
        exit()
print(min, max)


Measured memory_bytes: 14252
class BinomialCoefficient(object):

    def __init__(self, N=510000, MOD=10**9+7):
        self.fac = [1, 1]
        self.finv = [1, 1]
        self.inv = [0, 1]
        self.MOD = MOD
        for i in range(2, N + 1):
            self.fac.append((self.fac[-1] * i) % MOD)
            self.inv.append((-self.inv[MOD % i] * (MOD // i)) % MOD)
            self.finv.append((self.finv[-1] * self.inv[-1]) % MOD)

    def comb(self, n, r):
        if r < 0 or n < r or r < 0:
            return 0
        return self.fac[n] * self.finv[r] * self.finv[n - r] % self.MOD


N, K = map(int, input().split())
A = list(map(int, input().split()))
MOD = 10 ** 9 + 7

A.sort()
bc = BinomialCoefficient(N)
nCk = bc.comb(N, K)
ans = 0
for i in range(N - 1):
    c = nCk - bc.comb(i + 1, K) - bc.comb((N - i - 1), K)
    ans += c * (A[i + 1] - A[i]) % MOD
    ans %= MOD
print(ans)


Measured memory_bytes: 78376
// AOJ 323 ruins
// 2018.2.25 bal4u

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define LIM		30
#define MAX		1000002
#define EPS		1e-8
 
typedef struct { int x, r; double r2; } T;
T tbl[100002];
int n;

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int check(double d)
{
	int i;
	double xmin, xmax, xx, d2;

	d2 = d*d;
	xmin = -MAX, xmax = MAX;
	for (i = 0; i < n; i++) {
		if (tbl[i].r < d) return 0;
		xx = sqrt(tbl[i].r2 - d2);
		if (tbl[i].x - xx > xmin) xmin = tbl[i].x - xx;
		if (tbl[i].x + xx < xmax) xmax = tbl[i].x + xx;
		if (xmin > xmax) return 0;
	}
	return 1;
}

int cmp(T *a, T *b) { if (a->r - b->r) return a->r - b->r; return a->x - b->x; }

int main()
{
	int i;
	double a, hi, lo, mi;

	n = in();
	for (i = 0; i < n; i++) {
		tbl[i].x = in(), a = tbl[i].r = in();
		tbl[i].r2 = a*a;
	}
	if (i == 1) { printf("%.12lf\n", (double)tbl[0].r); return 0; }

	qsort(tbl, n, sizeof(T), cmp);
	lo = 0, hi = MAX;
	for (i = 0; i < LIM; i++) {
		mi = 0.5*(lo + hi);
		if (check(mi)) lo = mi; else hi = mi;
	}
	printf("%.12lf\n", lo);
	return 0;
}


Measured memory_bytes: 4480
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>
 
using namespace std;
using std::cout;
using ll =long long;
bool is_int_lround(double x){
  return std::lround(x)==x;
}
int ketasuu(int x){
  int n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}
ll gcd11(ll x, ll y){
  long long a= max(x,y), b=min(x,y), c=a%b;
  while( c!=0){
    a =b;
    b =c;
    c = a%b;
  }
  return b;
}

int ab(int x, int y){
  if(x>=y){
    return x-y;
  }
  else if(y>x){
    return y-x;
  }
}
int main(){
  int A,B;
  cin>>A>>B;
  if(A%2 ==0 || B%2 ==0){
    cout<<"No"<<endl;
  }
  else{
    cout<<"Yes"<<endl;
  }

}


Measured memory_bytes: 256
//subset sum problem

#include <bits/stdc++.h>
using namespace std;
#define mp make_pair
typedef long long int ll;
typedef unsigned long long int ull;
#define fi first
#define se second
#define pb push_back
ll mod1=pow(10,9)+7;
int mod2=998244353;
ll inf=1e9;
ll maxxy=1e6+9;
typedef long double ld;
const double PI =  3.141592653589793238;

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

ll modInverse(ll n, ll pp)
{
    return power(n, pp-2, pp);
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,k;
    cin>>n>>k;
    vector<ll> h(n);
    for (int i = 0; i <n ; ++i) {
        cin>>h[i];
    }
    ll dp[n];
    dp[0]=0;
    for (int i = 1; i <n ; ++i) {
        dp[i]=1e9+7;
        for (int j = 1; j <=k ; ++j) {
            if(i-j>=0){
                dp[i]=min(dp[i],dp[i-j]+abs(h[i]-h[i-j]));
            }
        }
    }
    cout<<dp[n-1]<<"\n";
    return 0;
}


Measured memory_bytes: 4752
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;

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

    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());

    double m = a[n - 1] / 2.0;
    vector<LL>::iterator c = lower_bound(a.begin(), a.end() - 2, m);
    vector<LL>::iterator b = c - 1;
    if (*c - m > m - *b) {
        cout << a[n - 1] << " " << *b << endl;
    } else {
        cout << a[n - 1] << " " << *c << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <string>
#include <cstdio>
using namespace std;

#define int long long
#define INF 1e18

signed main() {
    int n; cin >> n;
    vector<int> a(n); for(int i = 0; i < n; i++) cin >> a[i];
    int cnt = 0;
    bool flag = true;
    while(flag) {
        for(int i = 0; i < n; i++) {
            if(a[i] % 2 == 0) {
                a[i] /= 2;
            } else {
                cout << cnt << endl;
                return 0;
            }
        }
        cnt++;
    }
}


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

int main(){
    using namespace std;
    unsigned long R, G, B, N;
    cin >> R >> G >> B >> N;
    unsigned long ans{0};
    for(unsigned long i = 0; i * R <= N; ++i){
        for(unsigned long j = 0; i * R + j * G <= N; ++j){
            unsigned long k = N - (i * R + j * G);
            if(!(k % B))++ans;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define sz(x) (int)(x.size())
#define fi first
#define se second
#define pii pair<int, int>

signed main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n, m;
    cin >> n >> m;
    int ans = min(n, m / 2);
    m -= 2 * ans;
    ans += m / 4;
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  int i,j,n;
  char str[20];
  scanf("%s",str);
  i=strlen(str);
  for(j=i-1;j>=0;j--){
    printf("%c",str[j]);
  }
  printf("\n");
  return (0);
}

Measured memory_bytes: 524
function m(input){
  var a = input.split(' ');
  var K = parseInt(a[0]);
  var S = parseInt(a[1]);
  var s = 0;
  for(let i=0;i<=K;i++){
    for(let j=0;j<=K;j++){
      var v = S-(i+j);
      if(v >= 0 && v <= K){
        s++;
      }
    }
  }
  console.log(s);
}
m(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32248
import math
n = int(input())
pair = []
divisors = []
for i in range(1, int(n**0.5)+1):
  if n % i == 0:
    divisors.append(i)
    if i != n // i:
      divisors.append(n//i)
ans = float('inf')
for i in divisors:
  ans = min(ans, i + int(n / i))
print(ans-2)

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

int main()
{

   long long a,b,c,d,x1,x2,y1,y2,m1,m2,m3,m4;
   cin>>a>>b>>c>>d;
   x1=max(a,b);
   x2=min(a,b);
   y1=max(c,d);
    y2=min(c,d);

   m1=x1*y1;
   m2=x1*y2;
   m3=x2*y1;
   m4=x2*y2;

   cout<<max(m4,max(m1,max(m2,m3)))<<endl;


  return 0;
}


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

int main() {
  int N;
  string s;
  int sum=0;
    cin>> N;
    cin>> s;
  for(int i=0; i<N; i++){
    if (s.at(i)=='R'){
      sum = sum +1;
    }
  }
  if(2*sum>N){
    cout<<"Yes"<<endl;
  }
  else{
    cout<<"No"<<endl;
  }
    
 
}

Measured memory_bytes: 256
s_dash_rev = input()[::-1]
t_rev = input()[::-1]
s_length = len(s_dash_rev)
t_length = len(t_rev)
matched = False
for begin_index in range(s_length - t_length + 1):
    end_index = begin_index + t_length
    part_s_dash_rev = s_dash_rev[begin_index:end_index]
    part_matched = True
    for i in range(t_length):
        if part_s_dash_rev[i] != '?' and part_s_dash_rev[i] != t_rev[i]:
            part_matched = False
            break
    if part_matched:
        # replace by `T`
        matched = True
        s_rev = s_dash_rev[:begin_index] + t_rev + s_dash_rev[end_index:]
        break
if not matched:
    print('UNRESTORABLE')
else:
    s = s_rev[::-1]
    print(s.replace('?', 'a'))

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

int main() {
	int64_t n, x;
	cin >> n >> x;
	int64_t a[n];
	for (auto &i : a) {
		cin >> i;
	}
	int64_t dp[n][n]{};
	for (int i = 0; i < n; i++) {
		dp[i][0] = a[i];
		for (int j = 1; j < n; j++) {
			dp[i][j] = min(dp[i][j - 1], a[(i - j + n) % n]);
		}
	}
	int64_t ans = numeric_limits<int64_t>::max();
	for (int64_t k = 0; k < n; k++) {
		int64_t puni = 0;
		for (int i = 0; i < n; i++) {
			puni += dp[i][k];
		}
		ans = min(ans, x * k + puni);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 31488
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <bitset>

using namespace std;

typedef long long int ll;
typedef vector<ll> vl;
typedef vector<string> vs;

#define MAX(a,b) ((a)>(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define ABS(a) ((a)>0 ? (a) : (a * -1))



int main(){
	ll n, t, ans;
	ans = 0;
	cin >> n >> t;
	vl a(n);

	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	for (int i = 0; i < n; i++) {
		if (i == n-1) {
			ans += t;
			continue;
		}
		if (a[i+1] - a[i] > t) {
			ans += t;
		} else {
			ans += a[i+1] - a[i];
		}
	}


	cout << ans << endl;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define FOR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (b), i ## __end = (e); i < i ## __end; ++ i)
#define FORR(i,b,e) for (common_type_t <decltype (b), decltype (e)> i = (e), i ## __begin = (b); i -- > i ## __begin;)
#define rep(i,n) for (decay_t <decltype (n)> i = 0, i ## __len = (n); i < i ## __len; ++ i)
#define ALL(x) begin (x), end (x)
using namespace std;

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

  size_t n, q; cin >> n >> q;
  vector <char> s (n);
  for (auto && elem : s) cin >> elem;

  vector <int64_t> v (n);
  rep (i, n - 1)
  {
    if (s [i] == 'A' && s [i + 1] == 'C')
    {
      ++ v [i];
    }
  }

  vector <int64_t> a (v.size () + 1, 0);
  partial_sum (ALL (v), next (begin (a)));
  rep (i, q)
  {
    size_t l, r; cin >> l >> r;
    -- l;
    if (s [r - 1] == 'A') -- r;
    cout << a [r] - a [l] << endl;
  }
}



Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define INF 1145141919364364
#define int long long
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mood) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mood;
		}
		x = x * x % mood;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x)* mod_pow(kai(x - y), mod - 2, mod) % mod * mod_pow(kai(y), mod - 2, mod) % mod;
}

int n;
string s;

signed main() {
	cin >> n >> s;
	if (n % 2) {
		cout << "No" << endl;
		return 0;
	}
	for (int i = 0; i < n / 2; i++) {
		if (s[i] != s[i + n / 2]) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
}

Measured memory_bytes: 256
def main():
    H, W, A, B = map(int, input().split())
    l1 = [0]*A + [1]*(W-A)
    l2 = [1]*A + [0]*(W-A)
    s1 = ''.join(map(str, l1))
    s2 = ''.join(map(str, l2))
    for i in range(B):
        print(s1)
    for i in range(B, H):
        print(s2)

if __name__ == '__main__':
    main()


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

int Na,Nt,Ng,Nc;
int M;

string S[51];
vector<string> v[51];
int dp[2][53][53][53];

#define MOD (1000000007)

void add(int &a,int b){
  a = (a+b)%MOD;
}

int main(){
  cin >> Na >> Nt >> Ng >> Nc;
  cin >> M;
  for(int i=0;i<M;i++){
    cin >> S[i];
    S[i].erase(S[i].end()-1);    
    string buf;
    getline( cin, buf );
    stringstream sin(buf);
    string tmp;
    while( sin >> tmp ) v[i].push_back( tmp );
    /*
      cout << S[i] << " : " << endl;
      for(int j=0;j<(int)v[i].size();j++) cout << v[i][j] << " ";
      cout << endl;
    */
  }
  bool f = true;
  map<string,vector<vector<char> > > fie;
  for(int i=M-1;i>-1;i--){
    vector<vector<char> > &vc = fie[S[i]];
    for(int j=0;j<(int)v[i].size();j++){
      if( v[i][j][0] == '[' ){
        vc.push_back( vector<char>() );
        for(int k=1;k<(int)v[i][j].size()-1;k++){
          vc.back().push_back( v[i][j][k] );
        }
      } else
        for(int k=0;k<(int)fie[v[i][j]].size();k++)
          vc.push_back( fie[v[i][j]][k] );        
    }
    if( (int)vc.size() > Na + Nt + Ng + Nc ) { f = false; break;   }
  }

  vector<vector<char> > A = fie[S[0]];
  int N = A.size();
  dp[0][0][0][0] = 1;

  if( N - Na - Nt - Ng != Nc || !f) { cout << 0 << endl; return 0; }
  
  for(int i=0;i<N;i++){
    int now = i&1;
    int nex = 1-now;
    memset(dp[nex],0,sizeof(dp[nex]));
    for(int a = 0; a <= Na; a++){
      for(int t = 0; t <= Nt; t++){
        for(int g = 0; g <= Ng; g++ ){
          int c = i - a - t - g;

          if( !dp[now][a][t][g] ) continue;
          if( c > Nc ) continue;


                    
          for(int j=0;j<(int)A[i].size();j++){
            if( A[i][j] == 'A' ) add(dp[nex][a+1][t][g],dp[now][a][t][g]);
            else if( A[i][j] == 'T' ) add(dp[nex][a][t+1][g],dp[now][a][t][g]);
            else if( A[i][j] == 'G' ) add(dp[nex][a][t][g+1],dp[now][a][t][g]);
            else add(dp[nex][a][t][g],dp[now][a][t][g]);            
          }
        }
      }
    }
  }
  cout << dp[N&1][Na][Nt][Ng] << endl;

  
  
}

Measured memory_bytes: 2520
#include<cstdio>
using namespace std;
char ch[110];
int ans,sign;
int main()
{
	scanf("%s",ch);
	for(int i=1;;i++)
	{
		if(ch[i]!=0)
			ans++;
		else
		{
			sign=i-1;
			break;
		}
	}
	printf("%c%d%c",ch[0],ans-1,ch[sign]);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define all(v) v.begin(),v.end()

int main()
{
    int n;
    cin>>n;
    set<string>st;
    for(int i=1;i<=n;i++){
        string s;
        cin>>s;
        st.insert(s);
    }
    cout<<st.size()<<endl;


}


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

int main (void){
    ll n,m;
    cin>>n>>m;
    vector<ll>x(n+1),y(m+1);
    REP(i,1,n+1)cin>>x[i];
    REP(i,1,m+1)cin>>y[i];
    ll tx=0,ty=0;
    REP(i,1,n+1)tx+=(2*i-1-n)*x[i];
    REP(i,1,m+1)ty+=(2*i-1-m)*y[i];
    tx%=mod;
    tx*=ty%mod;
    cout<<tx%mod<<endl;
    return 0;

}

Measured memory_bytes: 1792
package main

import (
	"fmt"
)

func main() {
	var S, T string
	fmt.Scan(&S, &T)

	res := "No"
	if (len(S) + 1 == len(T)) && T[0:len(T)-1] == S {
		res = "Yes"
	}
	

	fmt.Println(res)
}


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

vector<bool> a(200010), b(200010);

int main(){
	int n, m;
	cin >> n >> m;
	rep(i, m){
		int ia, ib;
		cin >> ia >> ib;
		if(ia == 1) a[ib] = true;
		if(ib == n) b[ia] = true;
	}
	
	for(int i = 2; i < n; ++i){
		if(a[i] && b[i]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	
	cout << "IMPOSSIBLE" << endl;
	
	return 0;
}



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

int main()
{
    int answers[] = {1, 2, 3};
    int A, B;
    cin >> A;
    cin >> B;
    for (auto ans : answers)
    {
        if (ans != A && ans != B)
        {
            cout << ans << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
S = input()
L = list(S)
N = len(L)
bitmask = 2 ** (N - 1)

totals = []
for mask in range(bitmask):
    total = 0
    digit = 0
    for i in range(N):
        num = int(L[N - i - 1])
        total += num * (10 ** digit)
        # bitにi番目のフラグが立っているかどうか
        if mask & (1 << i):
            digit = 0
        else:
            digit += 1
    totals.append(total)

print(sum(totals))

Measured memory_bytes: 68020
#include<stdio.h>


int bitcnt( int bit )
{
	int ret = 0 ;

	int i ;
	for( i = 0 ; i < 3 ; ++i )
	{
		ret += ( bit >> i ) & 1 ;
	}

	return ret ;
}


int main()
{
	int n ,m ;
	
	while( 1 )
	{
		int lp ;
		for( lp = m = 0 ; lp < 3 ; ++lp )
		{
			scanf( "%d" ,&n ) ;

			m += n ;
		}

		if( m == 0 )
		{
			return 0 ;
		}

		scanf( "%d" ,&n ) ;

		int ans[ 1000 + 1 ] ;

		for( lp = 1 ; lp <= m ; ++lp )
		{
			ans[ lp ] = 2 ;
		}

		int i[ 1000 + 1 ] ,I[ 1000 + 1 ] = { 0 } ;
		int j[ 1000 + 1 ] ,J[ 1000 + 1 ] = { 0 } ;
		int k[ 1000 + 1 ] ,K[ 1000 + 1 ] = { 0 } ;

	


		for( lp = 1 ; lp <= n ; ++lp )
		{
			int ifs ;

			scanf( "%d %d %d %d" ,&i[ lp ] ,&j[ lp ] ,&k[ lp ] ,&ifs ) ;


			if( ifs )
			{
				I[ i[ lp ] ] = 4 ;
				J[ j[ lp ] ] = 2 ;
				K[ k[ lp ] ] = 1 ;

				ans[ i[ lp ] ] = ans[ j[ lp ] ] = ans[ k[ lp ] ] = 1 ;
			}
		}

		for( lp = 1 ; lp <= n ; ++lp )
		{
			if( bitcnt( I[ i[ lp ] ] | J[ j[ lp ] ] | K[ k[ lp ] ] ) == 2 )
			{
				ans[ ( I[ i[ lp ] ] & 7 ) == 0 ? i[ lp ] : ( J[ j[ lp ] ] & 7 ) == 0 ? j[ lp ] : ( K[ k[ lp ] ] & 7 ) == 0 ? k[ lp ] : 0 ] = 0 ;
			}
		}

		for( lp = 1 ; lp <= m ; ++lp )
		{
			printf( "%d\n" ,ans[ lp ] ) ;
		}
	}
}

Measured memory_bytes: 1800