akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>

int main(){
    int N,K;
    scanf("%d %d",&N,&K);
    char *s = malloc(sizeof(char)*(N+2)),c;
    *s='R';
    scanf("%s",&s[1]);
    s[N+1]='L';
    // 実際は1~N;R|1~N|L
    // "RL"の個数を数える
    int i,j,count=0,widecount=0;
    for(i=0;i<N+1;i++){
        if(s[i]=='R'&&s[i+1]=='L'){
            if(i==0 || i==N)widecount++;
            else count++;
        }
    }
    free(s);
    if(K >= count){
        if(widecount==2){
            if(K-count>=1){
                printf("%d\n",N-1);
            } else {
                printf("%d\n",N-2);
            }
        } else {
            printf("%d\n",N-1);
        }
    } else {
        printf("%d\n",N-2*(count-K)-widecount);
    }
    return 0;
}

Measured memory_bytes: 1808
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNextInt()) {
			int n = in.nextInt();
			int[] a=new int[n*2];
			for(int i=0;i<a.length;i++){
				a[i]=in.nextInt();
			}
			Arrays.sort(a);
			int sum=0;
			for(int i=0;i<a.length;i+=2){
				sum+=a[i];
			}
			System.out.println(sum);
		}
	}
}


Measured memory_bytes: 10324
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		int ct = 0;
		Scanner scan = new Scanner(System.in);
		String S = scan.next();
		String[] str = S.split("");
		for(int i = 0; i < str.length; i++) {
			for(int k = 0; k < str.length; k++) {
				if(i == k) continue;
				if(str[i].equals(str[k]) == true) ct++;
			}
		}
		if(ct == 0) System.out.println("yes");
		else System.out.println("no");
		scan.close();
	}
}


Measured memory_bytes: 23764
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()

S += "Z"
ans = 0

cnt = 0
for s in S:
    if s in "ACGT":
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 0

print(ans)

Measured memory_bytes: 3060
N, X = map(int,input().split())
x = list(map(int,input().split()))
tmp = []
for i in range(N):
  tmp.append(abs(x[i] - X))

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m
ans = tmp[0]
for t in tmp:
  if(t%ans != 0):
    ans = gcd(ans, t)
print(ans)

Measured memory_bytes: 14224
#include <iostream>

using namespace std;

int main() {
	int M, D, days;
	int daysOfMonth[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	string daysOfWeek[] = {"Wednesday", "Thursday", "Friday", "Saturday", "Sunday", "Monday", "Tuesday"};
	while (1) {
		cin >> M >> D;
		if (M == 0 && D == 0)
			break;
		days = 0;
		for (int i = 0; i < M; i++)
			days += daysOfMonth[i];
		days += D;
		cout << daysOfWeek[days % 7] << endl;
	}
	return 0;
}

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

typedef long long ll;

int main(){
	ll n = 0;
	ll x = 0;
	scanf("%lld",&n);
	for(ll i=1;i<=n;i++){
		if(i%3==0&&i%5==0){
		}
		else if(i%3==0){
		}
		else if(i%5==0){
		}
		else
			x+=i;
	}
	printf("%lld",x);
}

Measured memory_bytes: 1712
import sys
import numpy as np

def dump(x):
    print(x, file=sys.stderr)


MOD = 10**9+7

N = int(input())
arr = np.zeros((N+1,N+1),dtype=int)
for i in range(3,N+1):
    arr[0,i] = 1

for i in range(1,N+1):
    sum_ = 0
    for j in range(3*i,N+1):
        sum_ += arr[i-1,j]
        sum_ %= MOD
        if j+3 >= N + 1:
            break
        arr[i,j+3] = sum_

dump(arr)

ans = 0
for i in range(N+1):
    ans += arr[i,N]
    ans %= MOD
print(ans)










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


typedef long long ll;
#define reg register
#define rep(a,b,c) for(reg int a=b,a##end=c;a<=a##end;++a)
#define drep(a,b,c) for(reg int a=b,a##end=c;a>=a##end;--a)

char IO;
int rd(){
	int s=0,f=0;
	while(IO=getchar(),IO<'0'||IO>'9')if(IO=='-')f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(IO=getchar(),IO>='0'&&IO<='9');
	return f?-s:s;
}


const int N=1e5+10,P=1e9+7;

int n,m;

ll po[N]={1},Inv[N]={1,1};

ll C(int n,int m){
	if(n<0||m<0||n<m) return 0;
	return po[n]*Inv[m]%P*Inv[n-m]%P;
}



struct Edge{
	int to,nxt;
}e[N<<1];
int head[N],ecnt,ind[N];
void AddEdge(int u,int v){
	e[++ecnt]=(Edge){v,head[u]};
	head[u]=ecnt;
	ind[v]++;
}
#define erep(u,i) for(int i=head[u];i;i=e[i].nxt)

ll ans=1;


void dfs(int u,int f,int d){
	if(d<0) puts("0"), exit(0);
	int nd=m-1-(f>0);
	//cout<<u<<' '<<d<<endl;
	ans=ans*d%P;
	erep(u,i){
		int v=e[i].to;
		if(v==f) continue;
		dfs(v,u,nd--);
	}
}






int main(){
	rep(i,1,N-1) po[i]=i*po[i-1]%P;
	rep(i,2,N-1) Inv[i]=(-Inv[P%i]*(P/i)%P+P)%P;
	rep(i,2,N-1) Inv[i]=Inv[i]*Inv[i-1]%P;
	n=rd(),m=rd();
	rep(i,2,n) {
		int u=rd(),v=rd();
		AddEdge(u,v);AddEdge(v,u);
	}
	dfs(1,0,m);
	printf("%lld\n",ans);
}















Measured memory_bytes: 7680
N = input()
K = int(input())

keta = len(N)

dp = [[[0] * (K + 1) for _ in range(2)] for _ in range(keta + 1)]

dp[0][0][0] = 1

for i in range(1, keta + 1):
    for j in range(K + 1):
        if j > 0:
            dp[i][0][j] += dp[i-1][0][j-1] * (N[i-1] != '0')
            dp[i][1][j] += dp[i-1][0][j-1] * (max((int(N[i-1]) - 1),0)) + dp[i-1][1][j-1] * 9

        dp[i][0][j] += dp[i-1][0][j] * (N[i-1] == '0')
        dp[i][1][j] += dp[i-1][0][j] * (N[i-1] != '0') + dp[i-1][1][j]
        
ans = dp[keta][0][K] + dp[keta][1][K]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main()
{
	string n;
	cin >> n;

	string a[4];
	int b[4];

	a[0] = n.front();
	a[1] = n.substr(1, 1);
	a[2] = n.substr(2, 1);
	a[3] = n.back();
	b[0] = std::atoi(a[0].c_str());
	b[1] = std::atoi(a[1].c_str());
	b[2] = std::atoi(a[2].c_str());
	b[3] = std::atoi(a[3].c_str());

	if (b[0] + b[1] + b[2] + b[3] == 7) {
		printf("%d+%d+%d+%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}
	if (b[0] + b[1] + b[2] - b[3] == 7) {
		printf("%d+%d+%d-%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}
	if (b[0] + b[1] - b[2] + b[3] == 7) {
		printf("%d+%d-%d+%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}
	if (b[0] + b[1] - b[2] - b[3] == 7) {
		printf("%d+%d-%d-%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}
	if (b[0] - b[1] + b[2] + b[3] == 7) {
		printf("%d-%d+%d+%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}
	if (b[0] - b[1] + b[2] - b[3] == 7) {
		printf("%d-%d+%d-%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}
	if (b[0] - b[1] - b[2] + b[3] == 7) {
		printf("%d-%d-%d+%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}
	if (b[0] - b[1] - b[2] - b[3] == 7) {
		printf("%d-%d-%d-%d=7", b[0], b[1], b[2], b[3]);
		return 0;
	}

	return 0;
}

Measured memory_bytes: 256
/*
 *
 * Author: r3gz3n
 * 
 * 3b 13 12 9 56 4e
 * 6 56 a a 5f f
 * 6 56 47 18 56 d
 * 13 46 14 1f 13 27
 * 52 52 a 5a 47 1
 * 1d 13 b 1b 49 17
 *
 */


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;


#define pb push_back


#define rep(i, a, b, k) for(__typeof(a) i = a;i < b;i += k)

#define repeach(i, a) for(auto i: a)


#define endl '\n'


typedef vector<int> vii;


class Solution {
public:
    const int static MAX = 1e5 + 5;
    vii adj[MAX];
    bool vis[MAX];

    void dfs(int from) {
        vis[from] = true;
        repeach(to, adj[from]) {
            if (vis[to] == false) dfs(to);
        }
    }

    void solve(std::istream& in, std::ostream& out) {
		int n, m, ans = 0, x, y, z;
        memset(vis, false, sizeof(vis));
        in >> n >> m;
        rep(i, 0, m, 1) {
            in >> x >> y >> z;
            adj[x].pb(y);
            adj[y].pb(x);
        }
        rep(i, 1, n+1, 1) {
            if (vis[i] == false) {
                ans++;
                dfs(i);
            }
        }
        out << ans << endl;
    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 7680
#include <iostream>
#include <string.h>
using namespace std;

int main(int argc, char *argv[]) {
    int c=1;
    string s;
    cin >> s;
    if(s=="SSS") c=0;
    else if(s=="RRS" || s=="SRR") c=2;
    else if(s=="RRR") c=3;
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define ll long long
#define nl '\n'
#define ar array
#define AC ios_base::sync_with_stdio(0); cin.tie(NULL);
using namespace std;
const int MOD = 998244353;
const int N = 1e6;
const int DIST_MAX = 2147483647;

struct mi {
	ll v; explicit operator ll() const { return v; }
	mi() { v = 0; }
	mi(ll _v) { 
		v = (-MOD < _v && _v < MOD) ? _v : _v % MOD;
		if (v < 0) v += MOD;
	}
	friend bool operator==(const mi& a, const mi& b) { 
		return a.v == b.v; }
	friend bool operator!=(const mi& a, const mi& b) { 
		return !(a == b); }
	friend bool operator<(const mi& a, const mi& b) { 
		return a.v < b.v; }
   
	mi& operator+=(const mi& m) { 
		if ((v += m.v) >= MOD) v -= MOD; 
		return *this; }
	mi& operator-=(const mi& m) { 
		if ((v -= m.v) < 0) v += MOD; 
		return *this; }
	mi& operator*=(const mi& m) { 
		v = v*m.v%MOD; return *this; }
	mi& operator/=(const mi& m) { return (*this) *= inv(m); }
	friend mi pow(mi a, ll p) {
		mi ans = 1; assert(p >= 0);
		for (; p; p /= 2, a *= a) if (p&1) ans *= a;
		return ans;
	}
	friend mi inv(const mi& a) { assert(a.v != 0); 
		return pow(a,MOD-2); }
		
	mi operator-() const { return mi(-v); }
	mi& operator++() { return *this += 1; }
	mi& operator--() { return *this -= 1; }
    mi operator++(int) { mi temp; temp.v = v++; return temp; }
    mi operator--(int) { mi temp; temp.v = v--; return temp; }
	friend mi operator+(mi a, const mi& b) { return a += b; }
	friend mi operator-(mi a, const mi& b) { return a -= b; }
	friend mi operator*(mi a, const mi& b) { return a *= b; }
	friend mi operator/(mi a, const mi& b) { return a /= b; }
    friend ostream& operator<<(ostream& os, const mi& m) {
        os << m.v; return os;
    }
    friend istream& operator>>(istream& is, mi& m) {
        ll x; is >> x;
        m.v = x;
        return is;
    }
};


mi dp[3005];
int n, s;

int main(){
    AC
    cin>>n>>s;
    mi two = 2;
    mi inv2 = inv(two);
    dp[0]=pow(two, n);
    for(int i=0; i<n; i++){
        int a;
        cin>>a;
        for(int j=s; j>=a; j--){
            dp[j] = dp[j]+dp[j-a]*inv2;
            //cout<<"cur j "<<j<<endl;
            //cout<<dp[j]<<endl;
        }
    }
    cout<<dp[s]<<endl;

}

Measured memory_bytes: 3624
# -*- coding: utf-8 -*-
"""
Created on Sun Oct 27 21:13:33 2019

@author: doppe
"""

import math

a, b, l = (int(x) for x in input().split())
if (a * a * b / 2 >= l):
    x = 2 * l / a / b
    print(90 - math.degrees(math.atan(x / b)))
else:
    x = 2 * l / a / a - b
    x = b - x
    print(math.degrees(math.atan(x / a)))

Measured memory_bytes: 3064
num1, num2 = [int(i) for i in input().split()]

numArray = [[0]*2]*num2

for index1 in range(num2):
    numArray[index1] = [int(j) for j in input().split()]

num3 = [int(k) for k in input().split()]

numArray2 = [[0 for i in range(num1)] for j in range(num2)]

for index5 in range(num2):
    for index4 in range(numArray[index5][0]):
        numArray2[index5][int(numArray[index5][index4+1])-1] = 1

count1 = 0

for index2 in range(2 ** num1):
    num4  = format(index2, 'b').zfill(num1)

    for index6 in range(num2):
        num5 = "".join(map(str,numArray2[index6]))
        num6 = bin(int(num4, 2) & int(num5, 2))
        num7 = sum(list(map(int,num6[2:])))

        if num7 % 2 != num3[index6]:
            break
        if index6 == num2-1:
            count1 +=1

print(str(count1))

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

int main(){
  int N;
  cin >> N;
  vector<int> H(N);
  for(int i=0; i<N; i++){
    cin >> H.at(i);
  }

  int right = 0;
  int right_max = 0;
  
  for(int i=0; i<N-1; i++){
    if(H.at(i) < H.at(i+1)){
      right_max = max(right, right_max);
      right = 0;
    }
    else{
      right++;
    }
  }
  right_max = max(right, right_max);

  cout << right_max << endl;
}

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

template <class T>
inline void read(T &x) {
    x = 0;
    char c = getchar();
    bool f = 0;
    for (; !isdigit(c); c = getchar()) f ^= c == '-';
    for (; isdigit(c); c = getchar()) x = x * 10 + (c ^ 48);
    x = f ? -x : x;
}

template <class T>
inline void write(T x) {
    if (x < 0) {
        putchar('-');
        x = -x;
    }
    T y = 1;
	int len = 1;
    for (; y <= x / 10; y *= 10) ++len;
    for (; len; --len, x %= y, y /= 10) putchar(x / y + 48);
}

const int MAXN = 1e5;
int n, a[MAXN + 5], b[MAXN + 5];
LL sum1, sum2;

int main() {
	read(n);
	for (int i = 1; i <= n; ++i) {
		read(a[i]);
		sum1 += a[i];
		if (!(i & 1)) sum2 += 2 * a[i];
	}
	b[1] = sum1 - sum2;
	for (int i = 2; i < n; ++i)
		b[i] = 2 * a[i - 1] - b[i - 1];
	b[n] = 2 * a[n] - b[1];
	for (int i = 1; i <= n; ++i) {
		write(b[i]);
		putchar(' ');
	}
	putchar('\n');
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define int long long
#define ll long long
using ull = unsigned long long;
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x)                             \
    if (dbg) {                              \
        cerr << #x << " = " << (x) << endl; \
    }
#define overload4(_1, _2, _3, _4, name, ...) name
#define FOR1(n) for (ll i = 0; i < (n); ++i)
#define FOR2(i, n) for (ll i = 0; i < (n); ++i)
#define FOR3(i, a, b) for (ll i = (a); i < (b); ++i)
#define FOR4(i, a, b, c) for (ll i = (a); i < (b); i += (c))
#define FOR(...) overload4(__VA_ARGS__, FOR4, FOR3, FOR2, FOR1)(__VA_ARGS__)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
template <class T>
bool chmin(T& a, const T& b) {
    if (a > b) {
        a = b;
        return 1;
    } else
        return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    } else
        return 0;
}
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(), (v).end()
#define SZ(x) ((int)(x).size())
#define P pair<int, int>
#define V vector<int>
//#define S set<int>
#define itn int
bool dbg = false;
int N, A, B;

void solve() {
    int ans = 0;
    ans += (N / (A + B)) * A;
    ans += min(N % (A + B), A);
    cout << ans << endl;
}

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> A >> B;

    solve();
    return 0;
}


Measured memory_bytes: 256
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s1 = Console.ReadLine();
            var s2 = Console.ReadLine();
            var s3 = Console.ReadLine();

            Console.WriteLine(s1[0].ToString() + s2[1].ToString() + s3[2].ToString());
        }
    }
}


Measured memory_bytes: 13140
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int ,int> pi;
typedef pair<ll ,ll> pl;
typedef map<ll ,ll> ml;
#define modulo 1000000007
#define maxN 10000001
#define PI 3.14159265
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

void solve()
{ 
    ll n;
    cin >> n;
    n--;
    string str="";
    // cout << char((n%27)+'a') << endl;
    // cout << n/27 ;
    while(n>25)
    {
        str+=char((n%26)+'a');
        n=n/26;
        n--;
    }
    str+=char(n+'a');
    reverse(str.begin(),str.end());
    cout << str << endl;
}

int main()
{
    
    fast;
    int t;
    //cin>>t;
    t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}

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

#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<long long,long long>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vvvl vector<vector<vector<long long>>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vs vector<string>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define eb emplace_back

const int MOD1=1000000007;
const int MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const int dx[]={0,1,0,-1,1,-1,1,-1};
const int dy[]={1,0,-1,0,1,1,-1,-1};

#define unless(a) if(!(a))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(n);i++)
#define bitrep(i,s,n) for(int i=(s);i<(1LL<<(n));i++)
#define bitcheck(bit,i) (bit)&(1LL<<(i))
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define Lin(s) getline(cin,(s))

void Yes(bool a){cout<<(a?"Yes":"No")<<endl;}
void YES(bool a){cout<<(a?"YES":"NO")<<endl;}
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}
long long cutup(long long a,long long b){return (a+b-1)/b;}
long long popcnt(long long a){return __builtin_popcountll(a);}
template<class T,class U> inline bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template<class T,class U> inline bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

struct edge{long long to,cost;};
struct edge2{long long from,to,cost;};

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    vl C(26,INF);
    rep(i,n){
        string s;
        cin>>s;
        rep(j,26)chmin(C[j],count(all(s),char('a'+j)));
    }
    rep(i,26){
        if(C[i]==INF)continue;
        rep(j,C[i]){
            cout<<char('a'+i);
        }
    }
    cout<<endl;
}

Measured memory_bytes: 3632
s = input()
n = len(s)
for k in range(1,n):
    if s[k-1] == s[k]:
        print(k,k+1)
        exit(0)

for k in range(1,n-1):
    if s[k-1] == s[k+1]:
        print(k,k+2)
        exit(0)
print(-1,-1)


Measured memory_bytes: 3188
import io.StdIn.{readInt, readLine}
object Main extends App {
  val Array(n,k) = readLine.split(" ").map(_.toInt)

  // general expression
  // k*(k-1)^(n-1)

  val factor1 = BigInt(k)
  val factor2 = BigInt(k-1).pow(n-1)
  println(factor1*factor2)
  
}

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

/* clang-format off */
#define int long long
// #define double long double
struct Fast {Fast() {cin.tie(0); ios::sync_with_stdio(false);}} fast;

template <typename T> inline size_t maxElement(T beginIt, T endIt) { return max_element(beginIt, endIt); }
template <typename T> inline size_t minElement(T beginIt, T endIt) { return min_element(beginIt, endIt); }
template <typename T> inline size_t maxIndex(T beginIt, T endIt) { return distance(beginIt, *max_element(beginIt, endIt)); }
template <typename T> inline size_t minIndex(T beginIt, T endIt) { return distance(beginIt, *min_element(beginIt, endIt)); }
template <typename T> inline int sum(T beginIt, T endIt) { return accumulate(beginIt, endIt, 0); }
template <typename T> inline int mean(T beginIt, T endIt) { return sum(beginIt, endIt) / distance(beginIt, endIt); }
template <typename T> inline void debug(T x) { cerr << x << " " << "(L:" << __LINE__ << ")" << endl; }
/* clang-format on */

signed main(void) {
  /* */
  int num; // num
  num = 0; // count, result
  // num = numeric_limits<int>::min(); // max
  // num = numeric_limits<int>::max(); // min
  // double num; // num
  // num = 0; // count, result
  // num = numeric_limits<double>::min(); // max
  // num = numeric_limits<double>::max(); // min
  int N, M;
  array<int, 100000> A;
  string S;
  /* */

  cin >> N;
  for (int i = 0; i < N; ++i) cin >> A[i];

  for (int i = 0; i < N; ++i) num += A[i] - 1;
  
  cout << num << endl;
  // cout << fixed << setprecision(10) << num << endl;
  return 0;
}


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

const ll INF = 1LL << 60;

ll N, K;
int main() {
    cin >> N >> K;

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

    ll ans = 0;

    for (int b = 1; b <= N; b++) {
        // はみ出た分
        ll r = N % b;
        ans += max(0LL, r - K + 1);

        // 商
        ll p = N / b;
        ans += p * (max(0LL, b - K));
    }

    cout << ans << endl;
}

Measured memory_bytes: 3560
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	N := nextInt()
	A := nextInts(N)
	// よくよく考えたら累積和リスト自体が必要なわけではなく結果となった数とその総数だけ欲しいので
	// ruiseki := make([]int, N)
	// ruiseki[0] = A[0]
	r := A[0]
	T := make(map[int]int)
	T[r]++
	for i := 1; i < N; i++ {
		// ruiseki[i] += A[i-1]
		r += A[i]
		T[r]++
	}
	/// T[0]++ // これクソわからんけど多分「2つ選ばなくても総和が0になるとき、ex)1個のときだとncrの計算がうまくいかない」からだと思う
	// 累積和と組み合わせの話してるからてっきり問題文で禁止されているはずの「何も選ばない（部分列が空）」をやってるんじゃねぇかと悩んで1時間くらい無駄にした
	// ↑ってことはncrを無視して最後にT[0]だけを加えてやってもいいということか
	ans := T[0]
	for _, v := range T {
		// if k == 0 { は？これいらんの？と思ったらたしかにそうか 1 -1 1 -1って1と-1と0のぶん2C2あるな
		// 	continue
		// }
		if v > 1 {
			ans += ncr(v, 2)
		}
	}
	fmt.Fprintln(out, ans)
}

func ncr(n, r int) int {
	res := 1
	for i := 1; i <= r; i++ {
		res = res * (n - i + 1) / i
	}
	return res
}

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

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}

func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func chars(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}


Measured memory_bytes: 14464
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int A,B,T;
      A = sc.nextInt();
      B = sc.nextInt();
      T = sc.nextInt();
      int result = (T / A) * B;
      System.out.println(result);
    }
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	ll n,k;
	cin>>n>>k;
	vector<ll> a(n);
	rep(i,n)cin>>a[i];

	vector<vector<ll>> dp(n+1,vector<ll>(k+1,0));
	rep(i,n+1)dp[i][0]=1;

	vector<ll> sum(k+2,0);
	rep(i,k+1)sum[i+1] = sum[i]+dp[0][i];
	ll cnt=0;
	rep(i,n){
		repi(j,1,k+1){
			dp[i+1][j]=sum[j+1] - sum[max(j-a[i],0LL)];
			dp[i+1][j]+=mod;
			dp[i+1][j]%=mod;
		}
		// sum[0]=1;
		rep(j,k+1)sum[j+1] = (sum[j]+dp[i+1][j])%mod;
	}

	// rep(i,n+1){
	// 	rep(j,k+1)cout<<dp[i][j]<<" ";
	// 	cout<<endl;
	// }



	cout<<dp[n][k]<<endl;
	return 0;
}

Measured memory_bytes: 83152
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int MOD = (int)1e9 + 7;

int main() {
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int &ai: a) cin >> ai;
    long long ans = 0;
    for (int i = 0; i < n; i++) {
        int cnt1 = 0;
        for (int j = 0; j < i; j++) if (a[j] > a[i]) cnt1++;
        int cnt2 = 0;
        for (int j = 0; j < n; j++) if (a[j] > a[i]) cnt2++;
        ans += 1LL * cnt1 * k % MOD;
        ans %= MOD;
        ans += 1LL * k * (k - 1) / 2 % MOD * cnt2 % MOD;
        ans %= MOD;
    }
    cout << ans % MOD << endl;
    return 0;
}

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

#define FOR(a, b, c) for(int a = b; a <= c; ++a)
#define fi first
#define se second
#define pb push_back
#define int long long

typedef pair<int, int> ii;
typedef pair<int, ii> iii;

const int N = 2e5 + 10;
const int oo = 1e18;

int a[3], b, c;

signed main()  {
//    freopen("test.inp", "r", stdin);
//    freopen("test.out", "w", stdout);
    ios_base::sync_with_stdio(false); cout.tie(0);
    cin >> a[1] >> a[2] >> a[0];
    sort(a, a + 3);
    cout << a[0] * a[1] / 2;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v) (v).begin,(v).end()
#define INF 1e9
typedef long long llong;
using namespace std;

int main(){
	int a, b;
	string s;
	cin >> a >> b >> s;

	for(int i = 0; i < a; ++i){
		if(s[i] < '0' || '9' < s[i]){
			cout << "No" << endl;
			return 0;
		}
	}
	if(s[a] != '-'){
		cout << "No" << endl;
		return 0;
	}
	for(int i = a + 1; i < a + 1 + b; ++i){
		if(s[i] < '0' || '9' < s[i]){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
# frozen_string_literal: true

a, b, c, d = gets.each_char.map(&:to_i)
op = [1, -1]
sgn = %w[+ -]

(2**3 - 1).times do |i|
  if a + op[i[0]] * b + op[i[1]] * c + op[i[2]] * d == 7
    puts "#{a}#{sgn[i[0]]}#{b}#{sgn[i[1]]}#{c}#{sgn[i[2]]}#{d}=7"
    exit
  end
end

Measured memory_bytes: 1916
#include <iostream>
#include <string>
#include <cstdio>
#include <cmath>

using namespace std;
int main() {
    int a,b,c;
    cin >> a >> b >> c;
    double pi =acos(-1);
    double d;
    d = c*pi/180;
    double x,y,z;
    x=a*b*sin(d)/2;
    y=a*a+b*b-2*a*b*cos(d);
    z=x*2/a;
    printf("%.8f\n", x);
    printf("%.8f\n", sqrt(y)+a+b);
    printf("%.8f\n", z);
}


Measured memory_bytes: 3380
#include <bits/stdc++.h>
#define PI 3.1415926535897932
#define _GLIBCXX_DEBUG
using namespace std;
long long GCD(long long A,long long B){
  if(B==0){
    return A;
  }
  else{
    return GCD(B,A%B);
  }
}
int main() {
  
  int W,H,N;
  cin>>W>>H>>N;
  
  vector<vector<int>> vec(N,vector<int>(3));
  for(int i=0;i<N;i++){
    cin>>vec[i][0]>>vec[i][1]>>vec[i][2];
  }
  
  int X=0;
  int Y=0;
  
  
  for(int i=0;i<N;i++){
    if(vec[i][2]==1){
      X=max(X,vec[i][0]);
    }
    else if(vec[i][2]==2){
      W=min(W,vec[i][0]);
    }
    else if(vec[i][2]==3){
      Y=max(Y,vec[i][1]);
    }
    else{
      H=min(H,vec[i][1]);
    }
  }
  
  cout<<max(0,W-X)*max(0,H-Y)<<endl;
}

Measured memory_bytes: 3604
#include<iostream>

int main(){

    int data,udata,ldata;
    std::cin>>data;

    int uflag=0;
    int lflag=0;

    udata = data/100;
    ldata = data%100;


    if(udata > 12){
        uflag =1;
    }
    else if(udata ==0){
        uflag = 1;
    }
    
    if(ldata > 12){
        lflag =1;
    }
    else if(ldata ==0){
        lflag = 1;
    }


    if((uflag == 1)&&(lflag ==1)){
        std::cout<< "NA"<<std::endl;
    }
    else if((uflag == 0)&&(lflag ==1)){
        std::cout<< "MMYY"<<std::endl;
    }
    else if((uflag == 1)&&(lflag ==0)){
        std::cout<< "YYMM"<<std::endl;
    }
    else{
        std::cout<< "AMBIGUOUS"<<std::endl;
    }

    return 0;

}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int ans=0;
    for(int i=0;i<=c;i++){
        if((i != 0) && (i >= a) && (i <= b) && (c%i == 0)){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/


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

unsigned gaps[] = {1,8,23,77,281,1073,4193,16577,65921,262913,1050113};
// generated from pow(4,i)+3*pow(2,i-1)+1 (prefixed with 1)

unsigned insertion_sort(unsigned a[], unsigned n, unsigned gap){
  unsigned i,count = 0;
  for(i = gap; i < n; i++){
    unsigned v = a[i];
    int j = i - gap;
    while(j >= 0 && a[j] > v){
      a[j+gap] = a[j];
      j -= gap;
      count++;
    }
    a[j+gap] = v;
  }
  return count;
}

void shell_sort(unsigned a[], unsigned n){
  int i;
  unsigned gap_num = 0;
  while(gaps[++gap_num] < n);
  gap_num--;

  unsigned count = 0;
  for(i = gap_num; i >= 0; i--) count += insertion_sort(a,n,gaps[i]);

  printf("%u\n",(gap_num+1));

  for(i = gap_num; i; i--) printf("%u ",gaps[i]);
  printf("%u\n",gaps[0]);

  printf("%u\n",count);
}

int main(){
  unsigned n,i;
  scanf("%u",&n);
  unsigned* a = (unsigned*)malloc(sizeof(unsigned)*n);
  for(i = 0; i < n; i++) scanf("%u",&a[i]);
  shell_sort(a,n);
  for(i = 0; i < n; i++) printf("%u\n",a[i]);
  free(a);
  return 0;
}

Measured memory_bytes: 4896
#include <stdio.h>

int Partition(int p,int r);

int A[100000];
int n;

main(){
  int i,p;
  scanf("%d",&n);

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

  p = Partition(0,n-1);

  for(i=0;i<n;i++){
    if(p==i)printf("[%d]",A[i]);
    else printf("%d",A[i]);
if(i!=n-1) printf(" ");
  }
  printf("\n");

  return 0;
}

int Partition(int p, int r){

  int x, i,j, tmp;

  x = A[r];
  i = p-1;
  for(j=p; j<=r-1; j++){

    if(A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }

  }
      tmp = A[i+1];
      A[i+1] = A[r];
      A[r] = tmp;

  return i+1;

}

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

int N,x;
int main(){
	cin >> N >> x;
	int A[N+1];
	for(int i=0;i<N;i++){
		cin >> A[i];
	}
	sort(A,A+N);
	int ans = 0;
	for(int i=0;i<N-1;i++){
		if(x>=A[i]){
			ans++;
			x -= A[i];
		}
		if(x<A[i]) break;
	}
	if(x==A[N-1]) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
H = list(map(int, input().split()))
connected = [list() for _ in range(N)]
for _ in range(M):
    a, b = map(int, input().split())
    connected[a-1].append(H[b-1])
    connected[b-1].append(H[a-1])

result = 0
for i, c in enumerate(connected):
    if len(c) == 0 or H[i] > max(c):
        result += 1
print(result)


Measured memory_bytes: 23124
object Main {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val A = sc.nextInt
    val B = sc.nextInt
    val T = sc.nextInt
    sc.close()

    val createCount = Math.floor((T + 0.5) / A).toInt
    val createNum = createCount * B
    println(createNum)
  }
}

Measured memory_bytes: 27212
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int cm = 1 << 11;
char cn[cm], * ci = cn, ct;
inline int getint() {
	int A = 0;
	while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	fread(cn, 1, cm, stdin);
	int N = getint(), W = getint();

	vector<ll> dp(W + 1);
	rep(i, N) {
		int w = getint();
		int v = getint();
		for (int j = W; j >= w; j--) {
			dp[j] = max(dp[j], dp[j - w] + v);
		}
	}

	printf("%lld", dp[W]);

	Would you please return 0;
}

Measured memory_bytes: 1024
a,b = map(int, input().split())
l = list(map(int, input().split()))
L = []

for i in range(a):
  l2 = [l[i],l[i] + b]
  L.append(l2)
  
L = sorted(L, key = lambda x:x[1])
#print(L)

ri = 0
sum = 0

for x,y in L:
#  print(x,y)
  if ri > x:
#    sum += y - sum
    sum += y - ri
  else:
    sum += b
  ri = y
#  print("sum:" + str(sum), "ri:" + str(ri))

print(sum)

Measured memory_bytes: 41836
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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; }

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

const ll INF = 1LL << 60;

int main(){
  int x,y,z,k; cin >> x >> y >> z >> k;
  vector<ll> A(x), B(y), C(z);
  rep(i, x) cin >> A[i];
  rep(i, y) cin >> B[i];
  rep(i, z) cin >> C[i];

  sort(all(A),greater<ll>());sort(all(B),greater<ll>());sort(all(C),greater<ll>());

  vector<ll> ans;
  rep(a, x) rep(b, y){
    if((a+1)*(b+1) > k) break;
    rep(c, z){
      if((a+1)*(b+1)*(c+1) > k) break;
      ans.pb(A[a]+B[b]+C[c]);
    }
  }
  sort(all(ans), greater<ll>());
  rep(i, k) std::cout << ans[i] << '\n';
}


Measured memory_bytes: 1404
//#include <bits/stdc++.h>
#include <iostream>
#include <cmath>

using namespace std;

#define rep(i , n) for(int i=0 ; i<n ; i++)
#define rep1(i , n) for(int i=1 ; i<=n ; i++)

typedef long long int ll;

int main()
{
	ios_base :: sync_with_stdio(false);
	cin.tie(NULL);

	int n,d;
	cin >> n >> d;

	cout << (int)ceil((float)n / (2*d+1) );

	return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
N = int(input())
S1 = input()
S2 = input()


if N == 1:
    print(3)
    exit()

if S1[0] != S2[0]:
    ans = 6
    i = 2
    prev = 0  # 0: horizontal, 1:vertical
else:
    ans = 3
    i = 1
    prev = 1

while i <= N-1:
    if prev == 0 and S1[i] != S2[i]:
        ans *= 3
        i += 2
        prev = 0
    elif prev == 0 and S1[i] == S2[i]:
        ans *= 1
        i += 1
        prev = 1
    elif prev == 1 and S1[i] != S2[i]:
        ans *= 2
        i += 2
        prev = 0
    else:
        ans *= 2
        i += 1
        prev = 1
    ans %= MOD
print(ans)


Measured memory_bytes: 38448
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>
#define ll long long
#define ull unsigned long long
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define FOR(i,start,stop)  for(int i=(start); i < (stop); i++)
#define FORD(i,start,stop) for(int i=(start); i >= (stop); i--)
#define RIP(i,stop) FOR(i,0,stop)
#define PI 3.141592653589793
#define PRECISION(c,f) fixed << setprecision(c) << f
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int X,Y,Z; cin >> X >> Y >> Z;

  swap(X,Y);
  swap(X,Z);

  cout << X << " " << Y << " " << Z;

  return 0;
}


Measured memory_bytes: 3608
def sum_list(l1, l2):
  for i in range(len(l1)):
    l1[i] += l2[i]

  return l1


n = (int)(input())
s = input()
l_e = [0 for _ in range(n+1)]
l_w = [0 for _ in range(n+1)]

for i in range(n):
  if s[i] == 'W':
    l_e[i] += 1
  l_e[i+1] = l_e[i]

for i in reversed(range(n)):
  if s[i] == 'E':
    l_w[i] += 1
  l_w[i-1] = l_w[i]

l_e = l_e[:-1]
l_w = l_w[:n]


#print("E", l_e)
#print("W", l_w)

print(min(sum_list(l_e, l_w))-1)


Measured memory_bytes: 26940
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Map<Integer, BloodType> map = new TreeMap<Integer, BloodType>();
		
		String input;
		while((input = br.readLine()) != null){
			String[] str = input.split(",");
			map.put(Integer.parseInt(str[0]), parseBlood(str[1]));
		}
		int[] numPersonBloodType = getNumPersonBloodType(map);
		for(int n : numPersonBloodType){
			System.out.println(n);
		}
	}

	private static BloodType parseBlood(String str){
		if(str.equals("A"))			return BloodType.A;
		else if(str.equals("AB")) 	return BloodType.AB;
		else if(str.equals("B"))	return BloodType.B;
		else if(str.equals("O"))	return BloodType.O;
		else						return null;
	}

	private static int[] getNumPersonBloodType(Map map){
		int[] numPersonBloodType = new int[4];
		for(int i = 0; i < numPersonBloodType.length; i++){
			numPersonBloodType[i] = 0;
		}
		
		Set keySet = map.keySet();
		Iterator ite = keySet.iterator();
		while(ite.hasNext()){
			Integer key = (Integer)ite.next();
			BloodType bloodType = (BloodType)map.get(key);
			if(bloodType == BloodType.A)	numPersonBloodType[0]++;
			if(bloodType == BloodType.B)	numPersonBloodType[1]++;
			if(bloodType == BloodType.AB) 	numPersonBloodType[2]++;
			if(bloodType == BloodType.O)	numPersonBloodType[3]++;
		}
		return numPersonBloodType;
	}
	
	enum BloodType{
		A, B, AB, O
	}
}

Measured memory_bytes: 9764
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int r;
    cin>>r;
    double pi = 3.14159265;
    cout<<2*pi*r<<'\n';
    return 0;
}


Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
using namespace std;

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


Measured memory_bytes: 256
#include<iostream>
 #include<stdio.h>
 #include<string>
 #include<math.h>
 #include<iomanip>
 #include<algorithm>
 #include<string.h>
 #include<cctype>
 #include<map>
 #include<set>
 #include<vector>
 #include<sstream>
 #include<stack>
 #include<queue>
 
 using namespace std;

 char arr[8][8];
 
 int main()
 {
   while(cin>>arr[0][0])
   {
     int x[4],y[4];
     int cnt1,cnt2;
     cnt1=cnt2=0;
     if(arr[0][0]=='1') 
     {
       x[cnt1++]=0;
       y[cnt2++]=0;                   
     }
     for(int i=0;i<8;i++)
     {
       for(int j=0;j<8;j++)
       {
           if(i==0&&j==0) continue;
           else
           {
             cin>>arr[i][j];
             if(arr[i][j]=='1')
             {
               x[cnt1++]=j;
               y[cnt2++]=i;                
             }
           }    
                 
       }        
     }             
     if(y[0]==y[1]&&y[2]==y[3]&&x[1]==x[0]+1&&x[3]==x[2]+1&&y[2]==y[0]+1&&x[3]==x[0]+1) cout<<"A"<<endl;
     else if(x[0]==x[1]&&x[1]==x[2]&&x[2]==x[3]) cout<<"B"<<endl;
     else if(y[0]==y[1]&&y[1]==y[2]&&y[2]==y[3]) cout<<"C"<<endl;
     else if(y[1]==y[2]&&y[3]==y[0]+2&&x[0]==x[3]+1) cout<<"D"<<endl;
     else if(x[1]==x[2]&&(x[3]==x[0]+2&&y[3]==y[0]+1)) cout<<"E"<<endl;
     else if(y[1]==y[2]&&y[3]==y[0]+2) cout<<"F"<<endl;
     else cout<<"G"<<endl;        
   }
   //while(1);
   return 0;
 }

Measured memory_bytes: 3088
#include <cstdio>
#include <iostream>

using namespace std;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;++i){
        int x=i;
        if(x%3==0){
            cout<<" "<<i;
        }else{
            do{
                if(x%10==3){
                    cout<<" "<<i;break;
                }
                x/=10;
            }while(x);
        }
    }
    cout<<endl;
}

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

int main(){
  int N;
  
  cin >> N;
  if (N==1){
    cout<<1;
  }else if(N<=3){
    cout<<2;
  }else if(N<=7){
    cout<<4;
  }else if(N<=15){
    cout<<8;
  }else if(N<=31){
    cout<<16;
  }else if(N<=63){
    cout<<32;
  }else{
    cout<<64;
  }
  
}


Measured memory_bytes: 256
// Last Change: 05/09/2019 18:32:07.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

namespace NS {
void LoopUntilZeroInpput() {
  int hogegegege = 0;
  while (cin >> hogegegege && hogegegege != 0) {
  }
}
} // namespace NS

int main() {
  ll A, B;
  ll ans = 0;
  cin >> A >> B;

  if (A == B) {
    ans = 2 * A;
  } else {
    ans += 2 * max(A, B) - 1;
  }
  cout << ans << endl;

  //NS::LoopUntilZeroInpput();
}


Measured memory_bytes: 256
"""
各人についての移動回数
偶数 -> 状態同じ
奇数 -> 一回移動
"""
S = [False if s == "L" else True for s in input()]
N = len(S)

from collections import deque

F_idx = deque([idx for idx in range(N) if not S[idx]])
T_idx = deque([idx for idx in range(N) if S[idx]])

state = [0] * N
# ->
for i in range(N):
    if S[i]:
        if (F_idx[0] - i) % 2 == 0:
            state[F_idx[0]] += 1
        else:
            state[F_idx[0] - 1] += 1
    if i == F_idx[0]:
        F_idx.popleft()

# <-
for i in range(N-1,-1,-1):
    if not S[i]:
        if abs(T_idx[-1] - i) % 2 == 0:
            state[T_idx[-1]] += 1
        else:
            state[T_idx[-1] + 1] += 1
    if i == T_idx[-1]:
        T_idx.pop()

print(*state)

Measured memory_bytes: 9836
#include<iostream>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int dp[7][1100];
int main(){
	int n;
	char r[1100];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>r[i];
	}
	long long int ans=0;
	//0=joi,1=jo,2=ji,3=oi,4=j,5=o,6=i;
	dp[4][0]=1;
		for(int i=0;i<n+2;i++){
				//0=joi,1=jo,2=ji,3=oi,4=j,5=o,6=i;

		if(r[i]=='O'){
			dp[0][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[3][i]+dp[4][i]+dp[5][i]+dp[6][i])%10007;
			dp[1][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[3][i]+dp[5][i]+dp[4][i])%10007;
			dp[2][i+1]=0;
			dp[3][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[3][i]+dp[5][i]+dp[6][i])%10007;
			dp[4][i+1]=0;
			dp[5][i+1]=(dp[0][i]+dp[1][i]+dp[3][i]+dp[5][i])%10007;
			dp[6][i+1]=0;
		}
		else if(r[i]=='J'){
			dp[0][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[3][i]+dp[4][i]+dp[5][i]+dp[6][i])%10007;
			dp[1][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[4][i]+dp[3][i]+dp[5][i])%10007;
			dp[2][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[4][i]+dp[3][i]+dp[6][i])%10007;
			dp[3][i+1]=0;
			dp[4][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[4][i])%10007;
			dp[5][i+1]=0;
			dp[6][i+1]=0;
		}
		else if(r[i]=='I'){
			dp[0][i+1]=(dp[0][i]+dp[1][i]+dp[2][i]+dp[3][i]+dp[4][i]+dp[5][i]+dp[6][i])%10007;
			dp[1][i+1]=0;
			dp[2][i+1]=(dp[0][i]+dp[2][i]+dp[3][i]+dp[6][i]+dp[1][i]+dp[4][i])%10007;
			dp[3][i+1]=(dp[0][i]+dp[2][i]+dp[3][i]+dp[6][i]+dp[1][i]+dp[5][i])%10007;
			dp[4][i+1]=0;
			dp[5][i+1]=0;
			dp[6][i+1]=(dp[0][i]+dp[2][i]+dp[3][i]+dp[6][i])%10007;
		}
	}
	//0=joi,1=jo,2=ji,3=oi,4=j,5=o,6=i;
	for(int i=0;i<7;i++){
		ans+=dp[i][n];
		
	}
	cout<<ans%10007<<endl;
	return 0;
}

Measured memory_bytes: 1184
R, G, B, N = map(int,  input().split())
ans = 0
for i in range(3000 // R + 1):
    for j in range(3000 // G + 1):
        tmp = (N - i * R - j * G)
        if tmp % B == 0 and tmp >= 0:
            ans += 1
        elif tmp < 0:
            break
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define printVec(v) printf("{"); for (const auto& i : v) { std::cout << i << ", "; } printf("}\n");
#define degreeToRadian(deg) (((deg)/360)*2*M_PI)
#define radianTodegree(rad) (((rad)/2/M_PI)*360)
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; }
using namespace std;
using P = pair<int,int>;
using ll = long long;
const ll INF = 1LL<<60;
const int MOD = 1e9 + 7;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//cin.tie(0);ios::sync_with_stdio(false);
//cout << fixed << setprecision(15) << y << endl;
int main() {
  ll n;
  cin >> n;

  const int maxn = 1e6;
  ll ans = INF;
  for (ll i = 1; i <= maxn; i++) {
    if (n % i == 0) {
      ans = min(ans, (i - 1) + ((n / i) - 1));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3592
#n : switch
#m : light
n, m = map(int, input().split())
s = [list(map(int, input().split())) for _ in range(m)]
p = list(map(int, input().split()))

ans = 0

#generate all n-bit patern
for i in range(2 ** n):
    #generate pattern(i)
    pattern = bin(i)[2:].rjust(n, '0')
    flag= True
    #print(pattern)
    #print(type(pattern))
    for j in range(m):
        #count on-state
        tmp = 0
        for k in range(1, s[j][0] + 1):
            if pattern[s[j][k] - 1] == "1":
                tmp += 1

        if tmp % 2 != p[j] % 2:
            flag = False

    if flag:
        ans += 1



print(ans)

Measured memory_bytes: 3064
from collections import Counter

N = int(input())
D = list(map(int, input().split()))
MOD = 998244353

# 条件をみたす木が存在するには D1 = 0 が必要
if D[0] != 0:
  print(0)
  exit()
# 0 == 1
ctr = Counter(D)
if ctr[0] != 1:
  print(0)
  exit()
  
ans = 1
for i in range(len(ctr)-1):
  ans *= pow(ctr[i], ctr[i+1], MOD)
  ans %= MOD
print(ans)  

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

ll a, b;

// ll get_mx_one_to_x(ll x) {
//     for (int i = 62; i >= 0; i--) {
//         if ((1ll << i) & x) {
//             return (1ll << (i + 1)) - 1;
//         }
//     }
//     return 0ll;
// }

ll get_mn_corr_to_pref(ll pref, int pos) {
    ll prefa = (a >> pos);

    if (prefa < pref)
        return 0;
    if (prefa == pref)
        return a & ((1ll << pos) - 1);
    return (1ll << pos);
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    
    cin >> a >> b;

    ll x = b, ans = b - a + 1;
    int pos = 0;

    while (x > 0) {

        // if (pos != 1) //!!!!!!
        if ((x & 1) == 0) {
            ll pref = ((x - 1) & (x + 1));

            ll mn = get_mn_corr_to_pref(pref, pos);
            ans += (1ll << pos) - mn;
        }
        
        x >>= 1;
        pos++;
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256