akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define ZERO (1e-10)
#define INF (1<<29)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define DEB printf("DEB!\n");
#define D(X) cout<<"  "<<#X": "<<X<<endl;
#define EQ(A,B) (A+ZERO>B&&A-ZERO<B)
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define IN(n) int n;scanf("%d",&n);
#define FOR(i, m, n) for (int i(m); i < n; i++)
#define REP(i, n) FOR(i, 0, n)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define FT(m, n) FOR(k, m, n)
#define aa first
#define bb second
void ga(int N,int *A){F(N)scanf("%d",A+i);}
#define MX (1<<18)
char s[MX],r[][32]={"dream","dreamer","erase","eraser"};
int N,cn[MX];
bool ok(char*s,char*r){
    int L=strlen(r);
    F(L)if(s[i]^r[i])return 0;
    return 1;
}
bool rec(int u){
    if(u==N)return 1;
    if(cn[u]++)return 0;
    F(4)if(ok(s+u,r[i])&&rec(u+strlen(r[i])))return 1;
    return 0;
}
int main(void){
    scanf("%s",s),N=strlen(s);
    puts(rec(0)?"YES":"NO");
    return 0;
}


Measured memory_bytes: 1536
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

mt19937 mrand(random_device{} ()); 

int rnd(int x) {
  return mrand() % x;
}

typedef long double ld;
typedef long long ll;

#ifdef DEBUG
#define eprintf(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
#else
#define eprintf(...) ;
#endif

#define pb push_back
#define mp make_pair
#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const ld eps = 1e-9;
const ld pi = acos((ld) -1.0);

void precalc() {
}

const int maxn = (int) 300 + 10;
char s[maxn][maxn];

int n, m;

int read() {
  if (scanf("%d%d", &n, &m) < 2) {
    return 0;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%s", s[i]);
  }
  return 1;
}

int a[maxn], b[maxn];

int dp[maxn][maxn];

int prec[maxn][maxn];

void getdp() {
  for (int i = n; i >= 0; --i) {
    for (int j = n; j >= 0; --j) {
      int &cur = prec[i][j];
      if (i == n || j == n) {
        cur = 0;
        continue;
      }
      cur = (a[i] == b[j]) + prec[i + 1][j + 1];
    }
  }
  for (int i = 0; i <= n; ++i) {
    for (int j = 0; j <= n; ++j) {
      int &cur = dp[i][j];
      if (!i && !j) {
        cur = 0;
        continue;
      }
      cur = inf;
      if (i) {
        cur = min(cur, dp[i - 1][j] + prec[i - 1][j]);
      }
      if (j) {
        cur = min(cur, dp[i][j - 1] + prec[i][j - 1]);
      }
    }
  }
}

void solve() {
  long long res = 0;
  for (int i = 0; i < m - 1; ++i) {
    for (int j = 0; j < n; ++j) {
      a[j] = s[j][i] - 'a';
      b[j] = s[j][i + 1] - 'a';
    }
    reverse(a, a + n);
    reverse(b, b + n);
    getdp();
    res += dp[n][n];
  }
  printf("%lld\n", res);
}

int main() {
  precalc();
#ifdef LOCAL
  freopen(TASK ".out", "w", stdout);
  assert(freopen(TASK ".in", "r", stdin));
#endif

  while (1) {
    if (!read()) {
      break;
    }
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 1152
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		String[][] s = new String[n][];
		for (int i = 0; i < n; i++)
			s[i] = sc.next().split("");
		List<String> ans = new ArrayList<String>();
		for (int i = 0; i < s[0].length; i++) {
			boolean exist = true;;
			for (int j = 1; j < n; j++) {
				exist = false;
				for (int k = 0; k < s[j].length; k++) {
					if (s[0][i].equals(s[j][k])) {
						exist = true;
						s[j][k] = "";
						break;
					}
				}
				if (!exist)
					break;
			}
			if (exist)
				ans.add(s[0][i]);
		}
		Collections.sort(ans);
		for (int i = 0; i < ans.size(); i++)
			System.out.print(ans.get(i));
		System.out.println();
	}
}

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

using namespace std;

int main()
{
    string str;
    vector<int> res;

    while(cin >> str){
        if(str == "0") break;

        int sum=0;
        for(char c: str){
            sum += (c-'1'+1)%10;
        }

        // cout << sum;
        res.push_back(sum);
    }

    for(int x: res)
        cout << x << endl;
        
    return 0;
}


Measured memory_bytes: 3244
def wei(A,B,T):
    if T+0.5 > A:
        return int(T/A)*B
    else:
        return 0

A,B,T = map(int,input().split(" "))
print(wei(A,B,T))

"""print(wei(3,5,7) == 10)
print(wei(3,2,9) == 6)
print(wei(20,20,19) == 0)"""



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

int main() {
    int x,n;
    cin >> x >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int sa_ans=0;
    bool sa_condition =true;
    bool wa_condition =true;
    while(sa_condition && wa_condition){
        sa_condition =false;
        wa_condition =false;
        rep(i,n){
            if(a[i]==x-sa_ans) sa_condition=true;
            if(a[i]==x + sa_ans) wa_condition=true;
        }
        if(sa_condition && wa_condition) sa_ans+=1;
        else if(sa_condition==false){
            cout << x-sa_ans << endl;
            return 0;
        }
        else if(wa_condition==false){
            cout << x+sa_ans << endl;
            return 0;
        }
    }



}


Measured memory_bytes: 3628
import java.util.*;
//import java.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int aji[] = new int[N+1];
        int pi_aji = 0;
        int i;
        int min = 1000;
        int min_num = 1000;

        for (i = 1 ; i < N+1 ; i++) {
            aji[i] = L+i-1;
            if (Math.abs(min) > Math.abs(aji[i])) {
                min = aji[i];
                min_num = i;
            }
        }
        // System.out.println("min: "+ min);
        // System.out.println("min_num: "+ min_num);
        for (i = 1 ; i < N+1 ; i++) {
            if (i != min_num) {
                pi_aji += aji[i];
            }
        }
        System.out.println(pi_aji);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
main(){
int i,j,k,l,m;
char s1[200000],s2[200000];
while(cin>>s1>>s2){
    i=strlen(s1);
    j=strlen(s2);
    if(i>j) cout<<"GREATER"<<endl;
    else if(i<j) cout<<"LESS"<<endl;
    else{ l=0;
        for(k=0;k<i;k++){
            if(s1[k]>s2[k]){cout<<"GREATER"<<endl;l++; break;  }
            else if(s1[k]<s2[k]) {cout<<"LESS"<<endl;l++; break;  }
        }
        if(l==0) cout<<"EQUAL"<<endl;
    }
} return 0;
}


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll x, y;
    cin >> x >> y;

    if(x >= 0 && y >= 0) {
        if(x <= y) PR(y-x);
        else if(y == 0) PR(x-y+1);
        else PR(x-y+2);
    }
    else if(x >= 0 && y < 0) {
        if(abs(x) <= abs(y)) PR(-y-x+1);
        else PR(y+x+1);
    }
    else if(x < 0 && y >= 0) {
        if(abs(x) <= abs(y)) PR(y+x+1);
        else if(y == 0) PR(-x);
        else PR(-x-y+1);
    }
    else {
        if(x <= y) PR(y-x);
        else PR(x-y+2);
    }

    return 0;
}

/*



*/

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF (1 << 30)
#define LLINF (1LL << 60)
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> N;
    vector<string> s(N);
    vi t(N);
    for (int i = 0; i < N; i++)
        cin >> s[i] >> t[i];
    cin >> S;
    bool flag = 0;
    for (int i = 0; i < N; i++) {
        if (flag) {
            ans += t[i];
        }
        if (s[i] == S) {
            flag = 1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ratio>
const long long INF = LLONG_MAX / 2;
const long long MOD = 1000000007;
const long double PI = 3.1415926;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
using namespace std;
vector<ll> v;
vector<pair<ll, ll>> vp;
vector<vector<ll>> vv(110, vector<ll>(50, 0));
vector<tuple<ll, ll, ll>> vt;
set<ll> st;
map<ll, ll> mp;

int main()
{
	ll n;
	cin >> n;
	v.resize(n);
	REP(i, n) {
		cin >> v[i];
		mp[v[i]]++;
	}
	sort(ALL(v), greater<ll>());
	REP(i, v.size() - 1)
	{
		if (v[i] == v[i + 1])
		{
			v.erase(v.begin() + i);
			i--;
		}
	}
	ll sum = 0;
	REP(i,v.size())
	{
		if (mp[v[i]] - 1 > 0) {
			vp.emplace_back(v[i], mp[v[i]] - 1);
			sum += mp[v[i]] - 1;
		}
	}
	//sort(ALL(vp),greater<ll>());
	if (!sum) cout << n << endl;
	else cout << n-((sum - 1) / 2 + 1)*2 << endl;
}

Measured memory_bytes: 7296
import sys
S = input()
while len(S)>5:
  if S[-7:] == "dreamer":
    S = S[:-7]
  elif S[-6:] == "eraser":
    S = S[:-6]
  elif S[-5:] == "dream" or S[-5:] == "erase":
    S = S[:-5]
  else:
    print("NO")
    sys.exit()
print("YES")

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int n, m, k, nrp;
char color[10][10];
bool lin_chosen[10], col_chosen[10];

bool good(int lin, int col) {
    for (int i = 1; i <= n; i++)
        lin_chosen[i] = false;
    for (int j = 1; j <= m; j++)
        col_chosen[j] = false;

    for (int i = 1, cnt = 1; i <= lin; i <<= 1, cnt++)
        if (i & lin)
            lin_chosen[cnt] = true;

    for (int i = 1, cnt = 1; i <= col; i <<= 1, cnt++)
        if (i & col)
            col_chosen[cnt] = true;

    int remaining = 0;
    for (int i = 1; i <= n; i++)
        if (!lin_chosen[i])
            for (int j = 1; j <= m; j++)
                if (!col_chosen[j] && color[i][j] == '#')
                    remaining++;

    return remaining == k;
}

int main() {
    cin.tie(0); ios::sync_with_stdio(0);
    cin >> n >> m >> k;
    for (int i = 1; i <= n; i++)
        for (int j = 1; j <= m; j++)
            cin >> color[i][j];


    int end_lin = (1 << n) - 1;
    int end_col = (1 << m) - 1;
    for (int i = 0; i <= end_lin; i++)
        for (int j = 0; j <= end_col; j++)
            nrp += good(i, j);

    cout << nrp;
    return 0;
}


Measured memory_bytes: 3636
import math

num = int(input())

res = float("inf")
for i in range(1, math.ceil(pow(num, 0.5))+1):
    if num % i == 0:
        if max(len(str(i)), len(str(int(num/i)))) < res:
            res = max(len(str(i)), len(str(int(num/i))))
print(res)

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

typedef long long int in;


int main() 
{
	in n,m,k,ans=1e18,i,j,mask;
    cin>>n>>m>>k;

    in c[n],a[n][m];

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

    for(mask=1;mask<(1<<n);++mask)
    {
        bool r=1;

        in val=0,b[m]={0};

        for(i=0;i<n;++i)
        if((1<<i)&mask)
        {
            for(j=0;j<m;++j)
            b[j]+=a[i][j];

            val+=c[i];
        }

        for(j=0;j<m;++j)
        if(b[j]<k)
        r=0;

        if(r)
        if(ans>val)
        ans=val;
    }

    if(ans==1e18)
    cout<<"-1";
    else
    cout<<ans;

	return 0;
}





Measured memory_bytes: 3656
h,w,d=map(int,input().split())
a=[]
l=[[] for i in range(h*w+1)]
for i in range(h):
    p=[int(j) for j in input().split()]
    a.append(p)
    for j in range(w):
        l[int(p[j])].append(i)
        l[int(p[j])].append(j)
cost=[0 for i in range(h*w+1)]
for i in range(1,h*w+1-d):
    cost[i+d]=cost[i]+abs(l[i+d][0]-l[i][0])+abs(l[i][1]-l[i+d][1])
q=int(input())
lr=[]
for i in range(q):
    lr=[int(j) for j in input().split()]
    print(cost[lr[1]]-cost[lr[0]])

Measured memory_bytes: 23860
#include<cstdio>
#include<cstring>
#include<algorithm>
#define SF scanf
#define PF printf
#define MAXN 2000010
#define MOD 1000000007
using namespace std;
typedef long long ll;
int x1,x2,x3,x4,x5,x6,y1,y2,y3,y4,y5,y6;
int f[4][4];
int g[4][4];
ll fac[MAXN],ifac[MAXN];
ll ans;
ll fsp(ll x,int y){
	ll res=1;
	while(y){
		if(y&1)
			res=res*x%MOD;
		x=x*x%MOD;
		y>>=1;
	}
	return res;
}
ll C(int n,int m){
	return fac[n+m]*ifac[m]%MOD*ifac[n]%MOD;	
}
ll cal(int tag1,ll xl,ll yl,int tag2,ll xr,ll yr){
	ll res=0;
	for(ll i=x3;i<=x4;i++){
		res=(res-C(i-xl,y3-1-yl)*(i+y3)%MOD*C(xr-i,yr-y3))%MOD;
		res=(res+C(xr-i,yr-y4-1)*(i+y4+1)%MOD*C(i-xl,y4-yl))%MOD;	
	}
	for(ll i=y3;i<=y4;i++){
		res=(res-C(i-yl,x3-1-xl)*(i+x3)%MOD*C(yr-i,xr-x3))%MOD;
		res=(res+C(yr-i,xr-x4-1)*(i+x4+1)%MOD*C(i-yl,x4-xl))%MOD;	
	}
	return res*tag1*tag2;
	
}
int main(){
	fac[0]=1;
	for(int i=1;i<=2000000;i++)
		fac[i]=fac[i-1]*i%MOD;
	ifac[2000000]=fsp(fac[2000000],MOD-2);
	for(int i=2000000;i>=1;i--)
		ifac[i-1]=ifac[i]*i%MOD;
	SF("%d%d%d%d%d%d",&x1,&x2,&x3,&x4,&x5,&x6);
	SF("%d%d%d%d%d%d",&y1,&y2,&y3,&y4,&y5,&y6);
	f[0][0]=1,f[0][1]=x1-1,f[0][2]=y1-1;
	f[1][0]=-1,f[1][1]=x1-1,f[1][2]=y2;
	f[2][0]=-1,f[2][1]=x2,f[2][2]=y1-1;
	f[3][0]=1,f[3][1]=x2,f[3][2]=y2;
	g[0][0]=1,g[0][1]=x6+1,g[0][2]=y6+1;
	g[1][0]=-1,g[1][1]=x6+1,g[1][2]=y5;
	g[2][0]=-1,g[2][1]=x5,g[2][2]=y6+1;
	g[3][0]=1,g[3][1]=x5,g[3][2]=y5;
	for(int i=0;i<4;i++)
		for(int j=0;j<4;j++)
			ans=(ans+cal(f[i][0],f[i][1],f[i][2],g[j][0],g[j][1],g[j][2]))%MOD;
	PF("%lld",(ans+MOD)%MOD);
}	

Measured memory_bytes: 31360
package main

import (
	"bufio"
	"fmt"
	"os"
	_ "sort"
	"strconv"
	_ "strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func convertToInt(s []string, len int) []int {
	ret := make([]int, len)
	for i := 0; i < len; i++ {
		ret[i], _ = strconv.Atoi(s[i])
	}
	return ret
}

var N int

func main() {
	N, _ = strconv.Atoi(nextLine())

	for i := N; i <= 999; i++ {
		if i%111 == 0 {
			fmt.Println(i)
			break
		}
	}
}


Measured memory_bytes: 640
c = [list(map(int, input().split())) for _ in range(3)]

c0 = [c[0][0]-c[0][1], c[0][0]-c[0][2], c[0][1]-c[0][2]]
c1 = [c[1][0]-c[1][1], c[1][0]-c[1][2], c[1][1]-c[1][2]]
c2 = [c[2][0]-c[2][1], c[2][0]-c[2][2], c[2][1]-c[2][2]]

if c0 == c1 == c2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9172
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long[] a = new long[N];
        int count = 0;
        
        for(int i=0; i<N; i++){
            a[i] = sc.nextLong();
        }
        for(int i=0; i<N; i++){
            while(a[i]%2==0){
                a[i]/=2;
                count++;
            }
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 48844
n = int(input())

# 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...
# 1, 2, 2, 3, 3, 3, 4, 4, 4, 4, ...

A = [0] * (n + 1)
A[1] = 1 
for i in range(1, n):
    A[i + 1] = A[i] + i

from bisect import bisect_left

idx = bisect_left(A, n)

if n == A[idx]:
    for i in range(1, idx + 1):
        if i == idx - 1: continue
        print(i)
else:
    for i in range(1, idx):
        if i == idx - 1 - (n - A[idx - 1] + 1): continue
        print(i)

Measured memory_bytes: 146392
#include  <iostream>
#include  <stdio.h>
#include <algorithm>
#include <map>
#include <math.h>

using namespace std;
#include <vector>
#define rep(i,n) for (ll i = 0; i < (n) ; i++)
#define INF 1e9
#define llINF 1e18
#define base10_4 10000      //1e4
#define base10_5 100000     //1e5
#define base10_6 1000000    //1e6
#define base10_7 10000000   //1e7
#define base10_8 100000000  //1e8
#define base10_9 1000000000 //1e9

#define MOD 1000000007
#define pb push_back
#define ll long long
#define ull unsigned long long
#define vint vector<int>
#define vll vector<ll>

//#include <stack>
//#include <queue>

string ans_Yes = "Yes"; 
string ans_No = "No"; 
string ans_yes = "yes"; 
string ans_no = "no"; 

ll N;

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    cin >> N;

    bool flag = false;

    for( ll ni = 1 ; ni <=9 ; ni++ ){
        ll mi = N/ni;
        if(mi<=9 && mi*ni==N){
            flag = true;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3608
r, g, b, n = map(int,input().split())

ans = 0
for i in range(n//r+1):
    for j in range(n//g+1):
        bule_ball = (n - (r * i + g * j)) // b
        sum_ball = bule_ball * b + i * r + j * g
        #print(i,j,bule_ball)
        if bule_ball >= 0 and sum_ball == n:
            ans += 1

print(ans)

Measured memory_bytes: 40940
N = int(input())
A = list(str(input()))
B = list(str(input()))
C = list(str(input()))

ans = 0
for i in range(N):
  if [A[i] == B[i], B[i] == C[i], C[i] == A[i]].count(False) == 2:
    ans +=  1
  elif [A[i] == B[i], B[i] == C[i], C[i] == A[i]].count(False) == 3:
    ans += 2
  else:
    pass
    
print(ans)


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

using namespace std;

#define int long long
#define all(v) begin(v), end(v)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, s, n) for(int i = (int)(s); i < (int)(n); i++)
#define min(...) min({__VA_ARGS__})
#define max(...) max({__VA_ARGS__})

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using pint = pair<int, int>;
using tint = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

string S, T[2];
int K;

int dp[2][2][2002][2002];

char magic(char c) {
  switch(c) {
  case 'L': return 'R';
  case 'R': return 'L';
  case 'U': return 'D';
  case 'D': return 'U';
  }
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> S >> K;
  T[0] = T[1] = "";
  rep(i, S.size()) {
    if(S[i] == 'L' || S[i] == 'R') T[0] += S[i];
    else T[1] += (S[i] == 'U' ? 'R' : 'L');
  }
  rep(i, 2) rep(j, 2) rep(k, 2002) rep(l, 2002) dp[i][j][k][l] = -inf;
  dp[0][0][0][0] = dp[0][1][0][0] = dp[1][0][0][0] = dp[1][1][0][0] = 0;
  rep(i, 2) {
    rep(j, 2) {
      rep(k, T[i].size()) {
	rep(l, K+1) {
	  if(l%2) T[i][k] = magic(T[i][k]);
	  if(T[i][k] == 'R') {
	    chmax(dp[i][j][k+1][l], dp[i][j][k][l]+1);
	    chmax(dp[i][j][k+1][l+1], dp[i][j][k][l]-1);
	  } else {
	    chmax(dp[i][j][k+1][l], dp[i][j][k][l]-1);
	    chmax(dp[i][j][k+1][l+1], dp[i][j][k][l]+1);
	  }
	  if(l%2) T[i][k] = magic(T[i][k]);
	}
      }
      rep(k, T[i].size()) T[i][k] = magic(T[i][k]);
    }
  }
  int ans = -inf;
  rep(i, K+1) rep(j, K+1) {
    if(i+j > K) continue;
    int x = max(dp[0][0][T[0].size()][i], dp[0][1][T[0].size()][i]);
    int y = max(dp[1][0][T[1].size()][j], dp[1][1][T[1].size()][j]);
    chmax(ans, x+y);
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 128472
let mcm p n =
  let m = Array.make_matrix (n + 1) (n + 1) max_int in
  for i = 1 to n do m.(i).(i) <- 0 done;
  for l = 1 to n - 1 do
    for i = 1 to n - l do
      let j = i + l in
      for k = i to j - 1 do
        m.(i).(j) <- min m.(i).(j) (m.(i).(k) + m.(k+1).(j) + p.(i-1)*p.(k)*p.(j))
      done
    done
  done;
  m.(1).(n)

let () =
  let n = read_int () in
  let p = Array.make (n + 1) 0 in
  for i = 0 to n - 1 do
    let (r, c) = Scanf.scanf "%d %d\n" (fun r c -> (r, c)) in
    p.(i) <- r;
    p.(i+1) <- c;
  done;
  mcm p n |> Printf.printf "%d\n"

Measured memory_bytes: 2432
//package atcoder.yahoo;

import java.io.*;
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int k = s.nextInt();
        if(n % 2 == 0) {
            if(k <= n/2) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } else {
            if(k <= n/2 + 1) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1e9+7,INF=mod*mod*3;//M_PI
#define rep(i,N) for(ll i=0; i<(N); i++)
#define rep1(i,N) for(ll i=1; i<(N); i++)
#define pb push_back

ll N;
ll a[200005];

int main(){

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N;
rep(i,N) cin>>a[i];
ll now=1; 
ll cnt=0;
bool can=false;
rep(i,N){
    if(a[i]==now){
        can=true;
        now++;
        cnt++;
    }
}
if(!can) cout<<-1<<endl;
else cout<<N-cnt<<endl;

}
    


Measured memory_bytes: 1792
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
	buf := make([]byte, 0, 1000000)
	for {
		l, p, e := rdr.ReadLine()
		if e != nil {
			panic(e)
		}
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}

func strSprit(str string) []string {
	cols := strings.Split(str, " ")
	return cols
}

func parseInt(str string) int {
	n, _ := strconv.Atoi(str)
	return n
}

func intSprit(str string) []int {
	strs := strSprit(str)
	cols := make([]int, len(strs))
	for i, v := range strs {
		cols[i] = parseInt(v)
	}
	return cols
}

func bitCount(n uint) int {

	x := uint64(n)

	const m = 1<<64 - 1
	const m0 = 0x5555555555555555
	const m1 = 0x3333333333333333
	const m2 = 0x0f0f0f0f0f0f0f0f

	x = x>>1&(m0&m) + x&(m0&m)
	x = x>>2&(m1&m) + x&(m1&m)
	x = (x>>4 + x) & (m2 & m)
	x += x >> 8
	x += x >> 16
	x += x >> 32

	return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
	return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
	line := nextLine()
	N := float64(parseInt(line))

	nl := nextLine()
	ns := strSprit(nl)

	nums := make([]float64, int(N))
	for i := 0; i < int(N); i++ {
		nums[i] = float64(parseInt(ns[i]))
	}

	sum := 0.0
	for _, n := range nums {
		sum += float64(n)
	}
	ave := sum / N

	r := 0
	diff := 1000.0
	for i, n := range nums {
		if math.Abs(n-ave) < diff {
			r = i
			diff = math.Abs(n - ave)
		}
	}
	fmt.Println(r)
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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 ll INF = 1e15;
const int MOD = 1e9+7;
const ll LINF = 1e18;



signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll a,b,k; cin>>a>>b>>k;
  vll c;
  reps(i,min(a,b)){
    if(a%i==0&&b%i==0) c.push_back(i);
  }
  reverse(all(c));
  cout<<c[k-1]<<endl;
}

Measured memory_bytes: 256
n = int(input())
one = [0 for i in range(70)]
zero = [n for i in range(70)]
for c in input().split():
  b = list(bin(int(c)))
  b.reverse()
  j = 0
  for i in b:
    if i == "b":
      break
    else:
      if i == '1':
        one[j] += 1
        zero[j] -= 1
    j += 1
ans = 0
mod = 10 ** 9 + 7

for j in range(70):
  ans += one[j] * zero[j] * 2 ** j
  ans %= mod
print(ans)
  

Measured memory_bytes: 125624
#include<bits/stdc++.h>
#define ll long long int
#define ar array
#define pb push_back
#define input(arr,n) for(int i = 0; i<n; i++) cin>>arr[i]
const int mod = 998244353;
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);
	ll n,k;
	cin>>n>>k;
	vector<ar<ll,2>> v;
	ll dp[n+2] = {0};
	dp[1] = 1;
	for(int i = 0,j,k1; i<k; i++)
	{
		cin>>j>>k1;
		v.pb({j,k1});
	}
	for(int i = 1; i<=n; i++)
	{
		if(i>2)
			dp[i] = (dp[i]+dp[i-1])%mod;
		for(int j = 0; j<k; j++)
		{
			if(i+v[j][0]<=n)
			{
				dp[i+v[j][0]] = (dp[i+v[j][0]]+dp[i])%mod;
				dp[min(i+v[j][1]+1,n+1)] = ((dp[min(i+v[j][1]+1,n+1)]-dp[i])%mod+mod)%mod;
			}
		}
	}
	cout<<dp[n]<<'\n';
	return 0;
}

Measured memory_bytes: 5220
#include "iostream"
using namespace std;

int N;
int dis;
int rad;

int main() {
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> dis >> rad;
		if (rad % 30 == 0) {
			if (dis % 100 == 0) {
				cout << rad / 6 + dis / 100 << "\n";
			}
			else {
				cout << rad / 6 + dis / 100 << " " << rad / 6 + dis / 100 + 1 << "\n";
			}
		}
		else if(dis%100==0){
			cout << (rad / 30 * 30) / 6 + dis / 100 << " " << (rad / 30 * 30) / 6 + 5 + dis / 100 << "\n";
		}
		else {
			cout << (rad / 30 * 30) / 6 + dis / 100 << " " << (rad / 30 * 30) / 6 + dis / 100 + 1 << " " << (rad / 30 * 30) / 6 + 5 + dis / 100 << " " << (rad / 30 * 30) / 6 + 5 + dis / 100 + 1 << "\n";
		}
	}
	return 0;
}

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

int main(){
  int n, m, c;
  cin >> n >> m >> c;
  vector<int> b(m);
  for(int i=0; i<m; i++) cin >> b.at(i);

  int ans=0;
  for(int i=0; i<n; i++){
    int sum=0;
    vector<int> a(m);
    for(int j=0; j<m; j++){
      cin >> a.at(j);
      sum+=a.at(j)*b.at(j);
    }
    if(sum+c>0) ans++;
  }
  cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> pll;
typedef complex<double> P;

#define pb push_back
#define pf push_front
#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end()) // ユニークなvectorにする。連続した値を除去して切り出す。
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod (ll)(1e9+7)
#define ADD(a, b) a = (a + b) % mod
#define MUL(a, b) a = (a * b) % mod
#define int ll
#define INF 100000000

#define POS(x) cout<<((x)?"POSSIBLE":"IMPOSSIBLE")<<endl;
#define Pos(x) cout<<((x)?"Possible":"Impossible")<<endl;
#define YES(x) cout<<((x)?"YES":"NO")<<endl;
#define Yes(x) cout<<((x)?"Yes":"No")<<endl;
#define yes(x) cout<<((x)?"yes":"no")<<endl;

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

signed main() {
    int h, w;
    cin >> h >> w;
    vector<string> s;
    rep(i,h) {
        string tmp;
        cin >> tmp;
        s.pb(tmp);
    }

    for (auto itr = s.begin(); itr < s.end(); ++itr) {
        cout << *itr << endl << *itr << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
    int n,k;
    scanf("%d", &n);
    scanf("%d", &k);
    int a,b,c =0,ant = 1;
    for (int i = 0; i < n; i++) {
        if (k+ant < 2*ant) {
            ant+=k;
        }else{
            ant*=2;
        }
    }
    printf("%d\n", ant);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll inf = 1e18;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define per(i, a, b) for (int i = b - 1; i >= a; i--)
#define int ll
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

signed main() {
    string s;
    cin >> s;
    int ans = 0, cnt = 0;
    rep(i, 0, 3) {
        if (s[i] == 'R') {
            cnt++;
        } else {
            cnt = 0;
        }
        ans = max(ans, cnt);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int n,l,dp[100005],a[100005];

int func(int i){

  if(i>n)return 0;
  if(dp[i]>0)return dp[i];
  if(a[i]>a[i-1] && a[i]>a[i+1])return l-a[i];

  int res=0;
  if(a[i]<a[i-1])res=max(res,func(i-1));
  if(a[i]<a[i+1])res=max(res,func(i+1));

  return dp[i]=l-a[i]+res;
}

int main(void){
  int in;
  
  while(cin >> n >> l){
    
    for(int i=0;i<n+2;i++)dp[i]=0;

    for(int i=1;i<n+1;i++)
      cin >> a[i];

    a[0]=a[n+1]=0;

    int res=0;
    for(int i=1;i<n+1;i++)
      res=max(res,func(i));

    cout << res << endl;
  }
  
  return 0;
}

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

int main() {
	int64_t n;
	cin >> n;
	int64_t a[n], b[n];
	for (auto &i : a) {
		cin >> i;
	}
	for (auto &i : b) {
		cin >> i;
	}
	int64_t c[n], num = 0, minus = 0;
	for (int i = 0; i < n; i++) {
		c[i] = b[i] - a[i];
		num += max(int64_t(0), c[i] / 2);
		if (c[i] < 0) {
			minus -= c[i];
		}
	}
	cerr << num << ' ' << minus << endl;
	cout << (minus <= num ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 512
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
f=int(input())
g=int(input())
h=int(input())
i=int(input())
j=int(input())
print(a+b+c+d+e+f+g+h+i+j)



Measured memory_bytes: 5584
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::Integer;
#[allow(unused_imports)]
use proconio::derive_readable;
use proconio::fastout;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::*;

#[fastout]
fn main() {
    input! {
        s: String,
    }
    let ans = s.split('S').map(|r| r.len()).max().unwrap_or(0);

    println!("{}", ans);
}


Measured memory_bytes: 2164
from collections import deque

N, M = map(int, input().split())

dp = [0] * N
E = [[] for _ in range(N)]
deg = [0] * N
for _ in range(M):
    x, y = map(int, input().split())
    E[x-1].append(y-1)
    deg[y-1] += 1

que = deque(v for v in range(N) if deg[v] == 0)
while que:
    v = que.pop()
    for u in E[v]:
        deg[u] -= 1
        if deg[u] == 0:
            que.appendleft(u)
            dp[u] = max(dp[u], dp[v] + 1)

print(max(dp))


Measured memory_bytes: 60576
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

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

   if(s == "KIHBR") {  // 0
        out("YES");
   }
   else if(s == "KIHBRA") {  // 1
        out("YES");
   }
   else if(s == "KIHBAR") {  // 2
        out("YES");
   }
   else if(s == "KIHBARA") {  // 3
        out("YES");
   }
   else if(s == "KIHABR") {  // 4
        out("YES");
   }
   else if(s == "KIHABRA") {  // 5
        out("YES");
   }
   else if(s == "KIHABAR") {  // 6
        out("YES");
   }
   else if(s == "KIHABARA") {  // 7
        out("YES");
   }
   else if(s == "AKIHBR") {  // 8
        out("YES");
   }
   else if(s == "AKIHBRA") {  // 9
        out("YES");
   }
   else if(s == "AKIHBAR") {  // 10
        out("YES");
   }
   else if(s == "AKIHBARA") {  // 11
        out("YES");
   }
   else if(s == "AKIHABR") {  // 12
        out("YES");
   }
   else if(s == "AKIHABRA") {  // 13
        out("YES");
   }
   else if(s == "AKIHABAR") {  // 14
        out("YES");
   }
   else if(s == "AKIHABARA") {  // 15
        out("YES");
   }
   else {
       out("NO");
   }

    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pr(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(v) (v).begin(), (v).end()
#define int long long
#define sz(v) (int)(v).size()
#define mod 1000000007 // ((a- b)% mod+ mod)% mod

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}

int fastPower(int a ,int b){
	if(b== 0)
		return 1;
	int res = fastPower(a, b/ 2);
	if(b% 2== 1)
		return ((res* res)% mod* a)% mod;
	return (res* res)% mod;
}

int findProductSum(vector<int> &A, int n)
{
    // calculating array sum (a1 + a2  ... + an)
    int array_sum = 0;
    for (int i = 0; i < n; i++)
        array_sum = (array_sum + A[i])% mod;

    // calcualting square of array sum
    // (a1 + a2 + ... + an)^2
    int array_sum_square = (array_sum * array_sum)% mod;

    // calcualting a1^2 + a2^2 + ... + an^2
    int individual_square_sum = 0;
    for (int i = 0; i < n; i++)
        individual_square_sum = (individual_square_sum + (A[i]*A[i])% mod)% mod;

    // required sum is (array_sum_square -
    // individual_square_sum) / 2
    int ans= (array_sum_square - individual_square_sum+ mod)% mod;
    int two= fastPower(2, mod- 2);
    return (ans* two)% mod;
}

void solve() {
        int n; cin >> n;
        vector<int> v(n);
        for (auto& i: v) cin >> i;
        cout << findProductSum(v, n);
}

int32_t main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        int T= 1;
        //cin >> T;
        while ( T-- ) {
                solve();
        }
return 0;
}


Measured memory_bytes: 4680
n, a, b = gets.split.map(&:to_i)
if a > b
  puts 0
elsif a == b
  puts 1
elsif n == 1
  puts 0
else
  min_sum = (n-1) * a + b
  max_sum = a + (n-1) * b
  puts max_sum - min_sum + 1
end


Measured memory_bytes: 1788
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <string>
#include <math.h>
#include <map>
#include <numeric>
#include <stack>
#include <queue>
#include <functional>
#include <stdio.h>
#define ll long long
#define pl pair<ll,ll>
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vvvl vector<vector<vector<ll> > >
#define vd vector<double>
#define vvd vector<vector<double> >
#define vvvd vector<vector<vector<double> > >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define vvvb vector<vector<vector<bool> > >
#define rep(i,a) for(ll i = 0;i<a;++i)
#define rrep(i,a) for(ll i = a;i>=0;--i)
#define mod 1000000007
#define inf 10010010010
using namespace std;

int main(){
	ll n, k; 
	cin >> n >> k;
	vl p(n); rep(i, n) cin >> p[i];
	double d = 0;
	double ans = 0;
	rep(i, k) d += (double)(p[i] + 1) / 2;
	ans = d;
	for (ll i = k; i < n; ++i){
		d -= (double)(p[i - k] + 1) / 2;
		d += (double)(p[i] + 1) / 2;
		ans = max(ans, d);
	}cout <<fixed<< ans << setprecision(10)<< endl;
	return 0;
}

Measured memory_bytes: 1792
//    ŦĦ€Ř€'Ş ŇØŦĦƗŇǤ ĦØŁĐƗ'Ň Μ€ βΔĆҜ ΔŁŴΔ¥Ş ΔŇĐ ₣ØŘ€V€Ř 😈🤩😇😈💪🤜👊🤛🤟😉🤩:

#include<bits/stdc++.h>

#define mod 1000003
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define B(a) a.begin()
#define E(a) a.end()
#define For(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define M_P make_pair
#define P_B push_back
#define endd "\n"

using namespace std;

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

    ll a,b,c,d;cin>>a>>b>>c>>d;

    ll ans=0;

    ans=a*c;
    ans=max(ans,a*d);
    ans=max(ans,b*c);
    ans=max(ans,b*d);


   cout<<ans<<endd;





    return 0;
}


Measured memory_bytes: 3648
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <cstdio>
#include <climits>
#include <complex>
#include <cstdint>
#include <tuple>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }
inline int readInt() { int x; scanf("%d", &x); return x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SQ(a) ((a)*(a))
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,s,n) for(int i=s;i<(int)n;++i)
#define REP(i,n) FOR(i,0,n)
#define MOD 1000000007

double bin_pow(double a, LL b){
    double res = 1;
    while(b > 0){
        if(b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}


int main() {
    //cout << fixed << setprecision(20);

    LL N; cin >> N;

    LL ans = 0;

    set<LL> v;
    for(LL i=1; i*i<=N; ++i){
        if(N%i==0){
            LL a = i;
            LL b = N/i;
            a--;
            b--;
            if(a)v.insert(a);
            if(b)v.insert(b);
        }
    }

    for(auto e: v){
        if(N/e == N%e) ans+=e;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
int sosu[1000000];
int main (void)
{
    int n,i,j,ans=0;
    while(scanf("%d",&n)!=EOF){
        for(i=0;i<1000000;i++){
            sosu[i]=1;
        }
        sosu[0]=0;
        sosu[1]=0;
        ans=0;
        for(i=2;i<=sqrt(n)+1;i++){
            if(sosu[i]!=0){
                for(j=2;i*j<=n;j++){
                    sosu[i*j]=0;
                }
            }
        }
        for(i=0;i<=n;i++){
            ans+=sosu[i];
        }
        printf("%d\n",ans);
    }
    return 0;
}

Measured memory_bytes: 4500
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < (n) ; ++i)
int n,ANS,vc[20];

void dfs(int rec,int now){
  if(now == n){
    ANS = min(ANS,abs(rec));
    return;
  }
  dfs(rec+vc[now],now+1);
  dfs(rec-vc[now],now+1);
}

int main(){
  while(cin >> n , n){
    ANS = 100000000;
    rep(i,n) cin >> vc[i];
    dfs(0,0);
    cout << ANS << endl;
  }
}

Measured memory_bytes: 1160
n, k = map(int, input().split())
r, s, p = map(int, input().split())
judge = [False] * n
t = input().strip()
for i in range(n - k):
    if t[i] == t[i + k] and (not judge[i]):
        judge[i + k] = True
ans = 0
for i in range(n):
    if judge[i]:
        continue
    else:
        if t[i] == 'r':
            ans += p
        elif t[i] == 's':
            ans += r
        elif t[i] == 'p':
            ans += s
print(ans)


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

  int n,aS,bS,aC,bC,i;

  while(1){

    aS=bS=0;
    scanf("%d",&n);

    if(n != 0){
      
      for(i=0; i<n; i++){
	
	scanf("%d %d",&aC,&bC);
	
	if(aC > bC){
	  
	  aS += aC+bC;
	  
	} else if(aC < bC) {
	  
	  bS += aC+bC;
	  
	} else {
	  
	  aS += aC;
	  bS += bC;
	  
	}
	
      }
      
      printf("%d %d\n",aS,bS);

    } else {

      break;

    }

  }

  return 0;

}

Measured memory_bytes: 596
macro_rules! input {
    ($t : ty) => {{
        use std::io::BufRead;
        let tmp_handle = std::io::stdin();
        let mut handle = tmp_handle.lock();
        let mut buf = String::new();
        handle.read_line(&mut buf).unwrap();
        let tmp_var: $t = buf.trim().parse().unwrap(); 
        buf.clear();
        tmp_var
    }};
    ($t : ty, $size : expr) => {{
        use std::io::BufRead;
        let tmp_handle = std::io::stdin();
        let mut handle = tmp_handle.lock();
        let mut buf = String::new();
        handle.read_line(&mut buf).unwrap();
        let tmp_var: $t = buf.trim().split_whitespace()
            .map(|a| a.parse().unwrap()).collect();
        buf.clear();
        tmp_var
    }};
}
#[derive(Debug)]
pub struct UnionFind {
    parents: Vec<usize>,
    rank: Vec<usize>,
}
impl UnionFind {
    pub fn new(n: usize) -> Self {
        let mut parents: Vec<usize> = Vec::with_capacity(n);
        for i in 0..n {
            parents.push(i);
        }
        let rank = vec![1; n];
        UnionFind {
            parents: parents,
            rank: rank,
        }
    }
    pub fn find(&mut self, x: usize) -> usize {
        if self.parents[x] == x {
            x
        } else {
            let par = self.parents[x];
            let root = self.find(par);
            self.parents[x] = root;
            root
        }
    }
    // union x and y
    // ルートを付け替えるだけで，新たに付け加えられた木の子供の親は変わらないことに注意
    // unionしたあとも find を呼ぶ必要がある．
    pub fn union(&mut self, x: usize, y: usize) {
        let x_root = self.find(x);
        let y_root = self.find(y);
        // if x_root == y_root, do nothing
        if x_root == y_root { return (); }
        if self.rank[x_root] > self.rank[y_root] {
            // x <--- y
            self.parents[y_root] = x_root;
        } else {
            // y <--- x
            self.parents[x_root] = y_root;
            if self.rank[x_root] == self.rank[y_root] {
                self.rank[y_root] += 1;
            }
        }
    }
}
fn main() {
    let config = input!(Vec<usize>, 2);
    use std::collections::VecDeque;
    let mut edges = VecDeque::with_capacity(config[1]);
    for _ in 0..config[1] {
        let edge = input!(Vec<usize>, 2);
        edges.push_back(edge);
    }
    let mut count = 0;
    for _ in 0..config[1] {
        let one_edge = edges.pop_front().unwrap();
        let mut uf = UnionFind::new(config[0]);
        for edge in &edges {
            uf.union(edge[0]-1, edge[1]-1);
        }
        use std::collections::HashSet;
        let mut vs = HashSet::with_capacity(config[0]);
        for v in 0..config[0] {
            vs.insert(uf.find(v));
        }
        if vs.len() == 1 {
            // one_edge is not a bridge
        } else if vs.len() == 2 {
            // one_edge is a bridge
            count += 1;
        } else {
            panic!("my misunderstanding...");
        }
        edges.push_back(one_edge);
    }
    println!("{}", count);
}


Measured memory_bytes: 4352
N, M = list(map(int, input().split()))
l, r = 0, 100000
for _ in range(M):
    L, R = list(map(int, input().split()))
    if L > l:
        l = L
    if R < r:
        r = R

ans = r - l + 1
if ans < 0:
    ans = 0
print(ans)

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

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int main()
{
    ifstream fIn("input.txt");
    if (fIn.is_open())
        cin.rdbuf(fIn.rdbuf());

    ll n;
    cin >> n;

    vector<ll> vec = divisor(n);

    ll ans = 1e18;
    for(ll i = 0; i < vec.size() - 1; ++i){
        ll j = n / vec[i];
        ans = min(ans, vec[i] + j - 2);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<ll> X(N),Y(N),P(N);
    for(int i=0;i<N;i++) cin >> X[i] >> Y[i] >> P[i];
    ll inf = 1e18;
    vec<ll> ans(N+1,inf);
    vvec<ll> dpx(1<<N,vec<ll>(N,inf));
    vvec<ll> dpy(1<<N,vec<ll>(N,inf));
    for(int i=0;i<N;i++){
        dpx[0][i] = abs(X[i]);
        dpy[0][i] = abs(Y[i]);
        for(int S=0;S<(1<<N);S++){
            for(int j=0;j<N;j++) if(!(S>>j&1)){
                int T = S^(1<<j);
                dpx[T][i] = min(dpx[S][i],abs(X[i]-X[j]));
                dpy[T][i] = min(dpy[S][i],abs(Y[i]-Y[j]));
            }
        }
    }
    for(int S=0;S<(1<<N);S++){
        for(int T=S;T>=0;T=(T-1)&S){
            ll val = 0;
            int A = T,B = S^T;
            for(int i=0;i<N;i++) val += min(dpx[A][i],dpy[B][i])*P[i];
            int n = __builtin_popcount(S);
            ans[n] = min(ans[n],val);
            if(!T) break;
        }
    }
    for(auto& x:ans) cout << x << "\n";
}

Measured memory_bytes: 12960