akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define INF 1e9 + 5

// for using in pairs
#define F first
#define S second

// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

#define int long long

void solve(int tc)
{
	int n;
	cin >> n;

	string s;
	cin >> s;

	int ans = 0;
	int nW = 0, nR = 0;
	
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'W')
			nW++;
		else
			nR++;
	}
	string s2 = "";
	for (int i = 0; i < nR; i++)
		s2 += 'R';
	for (int i = 0; i < nW; i++)
		s2 += 'W';

	int i = 0;
	for (i = 0; i < n; i++)
	{
		if (s2[i] == 'W')
			break;
		if (s[i] != s2[i])
			ans++;
	}

	int ans2 = 0;
	for (i; i < n; i++)
	{
		if (s[i] != s2[i])
			ans2++;
	}

	ans = min(ans, ans2);
	ans = min(ans, nW);
	ans = min(ans, nR);

	cout << ans << "\n";
}

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

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

	int t = 1;
	// cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}
	return 0;
}


Measured memory_bytes: 3872
#include <iostream>
#include <math.h>
#include <stdlib.h>
#define llint long long int
#define inf 4000000000000000005

using namespace std;

int N, K;
llint x[55], y[55];

int main(void)
{
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> x[i] >> y[i];
	}
	
	
	llint ans = inf;
	for(int i = 0; i < N; i++){
		for(int j = 0; j < N; j++){
			if(i >= j) continue;
			
			for(int k = 0; k < N; k++){
				for(int l = 0; l < N; l++){
					if(k >= l) continue;
					
					int pt = 0;
					for(int m = 0; m < N; m++){
						if( (x[i]-x[m]) * (x[j]-x[m]) <= 0 && (y[k]-y[m]) * (y[l]-y[m]) <= 0) pt++;
					}
					
					llint s = (x[i] - x[j])*(y[k] - y[l]);
					if(s < 0) s = -s;
					if(pt >= K) ans = min(ans, s);
					
				}
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SC               scanf
#define PF               printf
#define ull              unsigned long long
#define ld               long double
#define D                double
#define F                first
#define S                second
#define pb               push_back
#define pf               push_front
#define MP               make_pair
#define sort_a(a)        sort(a.begin(),a.end());
#define sort_d(a)        sort(a.rbegin(),a.rend());
#define READ(f)          freopen(f, "r", stdin)
#define WRITE(f)         freopen(f, "w", stdout)
#define rev(s)           reverse(s.begin(),s.end())
#define it(it,mp)        for(auto it=mp.begin() ; it!=mp.end() ; it++)
#define IOS              ios_base :: sync_with_stdio(false); cin.tie(NULL);
const int N = 1e5 + 5;
const int inf = 1e9 + 1;
const double eps = 1e-15;
const double EPS = 1e-9;
const double PI = acos(-1.0);
typedef long long int                   ll;
typedef pair<int,int>                   PII;
int main()
{
    IOS
    // READ("test.txt");
    //WRITE("");
    ll a, b, x ;
    cin >> a >> b >> x ;
    if(a==b && a==0){
        return cout<<1<<endl,0;
    }
    cout<<(b/x)-(a==0?-1:(a-1)/x)<<endl;
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;
typedef long long ll;

ll K;

int main() {
        cin >> K;

        ll N = 50;
        ll a = K/N, b = K%N;

        cout << N << "\n";
        for (int i=0; i<b; i++)
                cout << a+N-(b-1)+N-1 << " ";
        for (int i=b; i<N; i++)
                cout << a-b+N-1 << " ";
        cout << "\n";
}

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




 
int main(){
	char a;
	cin >> a;
	if(islower(a)){
		cout << "a" << endl;
	}else {
		cout << "A" << endl;
	}

}

Measured memory_bytes: 3604
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

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

	string s, t;
	int dp[3005][3005];
	string ans = "";
	P now;

	cin >> s >> t;

	rep(i, s.size() + 1) {
		rep(j, t.size() + 1) {
			dp[i][j] = 0;
		}
	}
	for (int i = 1; i <= s.size(); i++) {
		for (int j = 1; j <= t.size(); j++) {
			if (s[i - 1] == t[j - 1]) dp[i][j] = dp[i - 1][j - 1] + 1;
			else dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}

	/*rep(i, s.size() + 1) {
		rep(j, t.size() + 1) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}*/

	now = { s.size(),t.size() };
	while (dp[now.first][now.second] != 0) {
		//cout << now.first << " " << now.second << endl;
		if (s[now.first - 1] == t[now.second - 1]) {
			ans += s[now.first - 1];
			now.first--, now.second--;
		}
		else if (dp[now.first][now.second] == dp[now.first - 1][now.second]) now.first--;
		else now.second--;
	}
	reverse(ans.begin(),ans.end());
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 70784
#include <set>
#include <map>
#include <list>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
using namespace std;
#define int long long


signed main(void){
  int a,b;
  string s;
  cin >> a >> s >> b;
  if(s == "+"){
    cout << a+b << "\r\n";
  }else{
    cout << a-b << "\r\n";
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

#define MAXN 10000009
ll sievesize, numDiffPF[MAXN];
bitset<MAXN> bs;
vector<ll> primes;

void sieve(ll n) {
	sievesize = n + 1;
	bs.set();
	bs[0] = bs[1] = 0;
	for (ll i = 2; i <= sievesize; i++) {
		if (bs[i]) {
			for (ll j = i * i; j <= (ll)sievesize; j += i) bs[j] = 0;
			primes.push_back(i);
		}
	}
}

set<ll> primeFactors(ll N) {
	set<ll> factors;
	ll PF_idx = 0, PF = primes[PF_idx];
	while (PF * PF <= N) { 
		while (N % PF == 0) {
			N /= PF;
			factors.insert(PF);
		}
		PF = primes[++PF_idx];
	}
	if (N != 1) factors.insert(N);
	return factors;
}

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    ll a, b, g ;
    set<ll> div;
    sieve((ll)1e6+9);
    cin >> a >> b;
    g = __gcd(a,b);
    div = primeFactors(g);
      
    /*trav(x, div) {
        cout << x <<  ' ';
    }
    cout << '\n';*/
    int ans = 0;
    
    cout << sz(div) + 1 << '\n';
    //cout << phi(g) << '\n';
    return 0;
}

Measured memory_bytes: 2680
#include<iostream>
#include<string>
int main(int argc, char const* argv[])
{
	using namespace std;
	
	int a, b;
	
	cin >> a >> b;
	
	if( (a*b)%2==0 ){
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
	
	
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
        int ac = 0;
        int wa = 0;
        int tle = 0;
        int re = 0;
        for(int i = 0; i < n; i++){
        	String s = sc.next();
            if(s.equals("AC")){
            	ac++;
            }else if(s.equals("WA")){
            	wa++;
            }else if(s.equals("TLE")){
            	tle++;
            }else{
            	re++;
            }
        }
        System.out.println("AC x " + ac);
        System.out.println("WA x " + wa);
        System.out.println("TLE x " + tle);
        System.out.println("RE x " + re);
	}
}

Measured memory_bytes: 58688
S=input()
N=len(S)

ANS1=0
ANS2=0

for i in range(N):
    if i%2==0:
        if S[i]=="0":
            ANS1+=1

        else:
            ANS2+=1

    else:
        if S[i]=="0":
            ANS2+=1
        else:
            ANS1+=1

    #print(ANS1,ANS2)

print(min(ANS1,ANS2))
    

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    while(1){
	int w;
	cin >> w;
    if(w == -1) break;
    int sum = 0;
    if(w > 30){
        sum += 160*(w-30);
        w = 30;
    }
    if(w > 20){
        sum += 140*(w-20);
        w = 20;
    }
    if(w > 10){
        sum += 125*(w-10);
        w = 10;
    }
    if(w <= 10){
        sum += 1150;
    }
    cout << 4280-sum << endl;
    }
	return 0;
}

Measured memory_bytes: 1160
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        String s = sc.next();
        sc.close();

        // 主処理
        int result = solve(s);

        // 出力
        System.out.println(result);
    }

    private static int solve(String s) {
        s = s.replaceAll("^R+W", "W").replaceAll("RW+$", "R");
        int n = s.length();

        int result = 0;
        if (!s.contains("R") || !s.contains("W") || !s.contains("WR")) {
            return result;
        }

        int countW = s.length() - s.replace("W", "").length();
        int countR = s.length() - s.replace("R", "").length();
        int min = Math.min(countR, countW);

        char[] c = s.toCharArray();
        int indexW = s.indexOf("W");
        int indexR = s.lastIndexOf("R");
        result++;
        while (indexR - indexW != 1 && indexW < indexR) {
            indexW++;
            while (indexW <= n - 1 && c[indexW] == 'R') {
                indexW++;
            }
            indexR--;
            while (0 <= indexR && c[indexR] == 'W') {
                indexR--;
            }
            if (indexW < indexR) {
                result++;
            }
        }

        result = Math.min(result, min);
        return result;
    }
}


Measured memory_bytes: 42916
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cstring>

using namespace std;

struct node {
	int key;
	node *next, *prev;
};

class list {
	int length;
public:
	node *nil;
	list(): length(0) {
		nil=new node;
		nil->next=nil;
		nil->prev=nil;
	} 

	int len(){  return length;  }

	void insert(int);
	void del(node*);
	void dell();
	void delf();
	node* search(int);

	
};

void list::insert(int k)
{
	node* nx=new node;

	if( !nx ){
		cout<<"MEMORY ALLOCATION ERROR!"<<endl;
		exit(1);
	}

	length++;


	nx->next=nil->next;
	nx->prev=nil;
	nil->next=nx;
	nx->next->prev=nx;

	nx->key=k;

	
}	

void list::del(node *dn) 
{

	if( dn==nil ){
		return;
	}else{
		dn->prev->next=dn->next;
		dn->next->prev=dn->prev;

		delete dn;
	}
		
		
	
}

void list::dell()
{
	del(nil->prev);
}

void list::delf()
{
	del(nil->next);
}

void show(list l) 
{
	for( node *t=l.nil->next; t!=l.nil; t=t->next ){
		if( t->next != l.nil )
			cout<<t->key<<' '<<flush;
		else
			cout<<t->key<<endl;
	}
}

node *list::search(int k) 
{
	node *t=nil->next;
	while( t->key!=k && t!=nil ){
		t=t->next;
	}

	return t;
}
int main() 
{

	long n;cin>>n;
	char com[20];
	int x;
	list dll;

	for( long i=0; i<n; i++ ) {
		scanf("%s",com);

		if( !strcmp(com,"insert") ){
			scanf("%d",&x);
			dll.insert(x);
		}else if( !strcmp(com,"delete") ){
			scanf("%d",&x);
			dll.del(dll.search(x));
		}else if( !strcmp(com,"deleteFirst") ){
			dll.delf();
		}else if( !strcmp(com,"deleteLast") ){
			dll.dell();
		}
		
	}

	show(dll);
}

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

int main() {
  
  int N;
  cin >> N;
  
  int64_t t=1, n=1, e=1;
  
  for (int i = 0; i < N; i++) {
    t = t*10 %1000000007;
  }
  
  for (int i = 0; i < N; i++) {
    n = n*9 %1000000007;
  }
  
  for (int i = 0; i < N; i++) {
    e = e*8 %1000000007;
  }
  
  int64_t s = (t-n-n+e)%1000000007;
  
  if (s<0) {
    s += 1000000007;
  }
  
  cout << s << endl;

return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
int n;
string s;
cin>>n>>s;
int k=count(s.begin(),s.end(),'E');
int ans=k;
for(char c:s)
{
if(c=='E')k--;
ans=min(ans,k);
if(c=='W')k++;
}
cout<<ans;
}

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

int main(){
  int X;
  cin >> X;
  if(400 <= X && X <= 599){
    cout << "8" << endl;
  }
  else if(600 <= X && X <= 799){
    cout << "7" << endl;
  }
  else if(800 <= X && X <= 999){
    cout << "6" << endl;
  }
  else if(1000 <= X && X <= 1199){
    cout << "5" << endl;
  }
  else if(1200 <= X && X <= 1399){
    cout << "4" << endl;
  }
  else if(1400 <= X && X <= 1599){
    cout << "3" << endl;
  }
  else if(1600 <= X && X <= 1799){
    cout << "2" << endl;
  }
  else if(1800 <= X && X <= 1999){
    cout << "1" << endl;
  }
}

Measured memory_bytes: 3128
from collections import defaultdict
n = int(input())
s = defaultdict(int)
t = defaultdict(int)

for i in range(n):
    x = input()
    s[x] += 1

m = int(input())
for i in range(m):
    x = input()
    t[x] += 1

ans = 0
for x, v in s.items():
    now = v - t[x]
    ans = max(ans, now)

print(ans)


Measured memory_bytes: 9436
#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

typedef long long ll;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline ll gl()
{
	ll f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, sum[55], v[55];
map <string, int> p;
string s[55];

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi();
	for (int i = 1; i <= n; i+=1) 
	{
		cin >> s[i];
		v[i] = gi();
		p[s[i]] = i;
	}
	for (int i = n - 1; i >= 1; i-=1)
	{
		sum[i] = sum[i + 1] + v[i + 1];
		//cout << sum[i] << ' ' << p[s[i]] << ' ' << s[i] << endl;
	}
	cin >> s[0];
	//cout << s[0] << ' ' << p[s[0]] << endl;
	cout << sum[p[s[0]]] << endl;
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
#define INF 1LL<<60

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

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

    int X = ceil(N / 1.08);

    if(floor(X*1.08) != N) {
        cout << ":(" << endl;
    } else {
        cout << X << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll n;
    cin >> n;
    ll an = n * (n + 1) / 2;
    vector<ll> z(n+1);
    ll wa = 0;
    for (int i = 0; i < n; i++) {
        cin >> z[i];
        wa += z[i];
    }
    z[n] = z[0];
    string ans = "YES";
    if (wa % an != 0)ans="NO";
    ll all = wa / an;
    ll con = 0;
    for (int i = 0; i < n; i++) {
        ll w = z[i] - z[i+1] + all;
        if (w % n != 0)ans = "NO";
        if (w < 0)ans = "NO";
        con += w / n;
    }
    if (con!= all)ans = "NO";
    cout << ans << endl;
}

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

#define M 1000000007
#define MM 998244353 
#define ll long long 
#define pb push_back
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end()
#define sz(a) (ll)a.size()
#define F first
#define S second
#define PI 3.1415926536
#define INF 2000000000000000000
#define endl "\n"
#define _time_ 1.0 * clock() / CLOCKS_PER_SEC
#define popcount(x) __builtin_popcountll(x)
//RNG based on mersenne_twister 
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll power(ll b,ll e,ll m)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b%m,e/2,m)%m;
	return power(b*b%m,e/2,m);
}
ll power( ll b, ll e)
{
	if(e==0) return 1;
	if(e&1) return b*power(b*b,e/2);
	return power(b*b,e/2);
}
template<typename T, typename U> static inline void amin(T &x, U y){ if(y<x) x=y; }
template<typename T, typename U> static inline void amax(T &x, U y){ if(x<y) x=y; }


int _runtimeTerror_()
{
	ll k,a,b;
	cin>>k>>a>>b;
	ll x=(a/k)+(a%k!=0);
	ll y=(b/k);
	if(x<=y)
		cout<<"OK\n";
	else cout<<"NG\n";
	return 0;
}

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifdef runSieve
		sieve();
	#endif
	#ifdef NCR
		initialize();
	#endif
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
		_runtimeTerror_();
	cerr<<"\n"<<_time_;
	return 0;
}


Measured memory_bytes: 3812
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;

typedef long long ll;

int
main(int argc, char *argv[])
{
  int n; cin >> n;
  char s[200000];
  cin >> s;

  char f = 0; int cn = 0;
  rep(i, n) {
    if (f != s[i]) {
      cn++;
      f = s[i];
    }
  }

  cout << cn << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define REP(i,b,e) for(ll i=(ll)b;i<(ll)e;i++)
#define rep0(i,n) REP(i,0ll,n)
#define rep1(i,n) REP(i,1ll,n+1)
const ll longinf=1ll<<60;
const int inf=(1<<30)-1;


int main(){
    int n;
    cin>>n;
    cout<<180*(n-2)<<endl;
    return 0;
}

Measured memory_bytes: 256
N, T = map(int, input().split())
times = [int(i) for i in input().split()]

loss_time_sum = 0
last_finished_time = T

for i in range(1, N):
    current = times[i]
    loss_time_sum += max(0, last_finished_time - current)
    last_finished_time = current + T
print(N * T - loss_time_sum)


Measured memory_bytes: 25200
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define INF 10e16
#define MOD 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
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;}
int dx[4]={-1,0,1,0};
int dy[4]={0,-1,0,1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    int h,w;cin>>h>>w;
    char a[110][110];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    vector<int>row;
    for(int i=0;i<h;i++){
        int abc=1;
        for(int j=0;j<w;j++)
            if(a[i][j]=='#')
                abc=0;
        if(abc==1)
            row.pb(i);
    }
    vector<int>rei;
    for(int i=0;i<w;i++){
        int abc=1;
        for(int j=0;j<h;j++)
            if(a[j][i]=='#')
                abc=0;
        if(abc==1)
            rei.pb(i);
    }
    int ro=0,re=0;
    for(int i=0;i<h;i++){
        if(ro<siz(row))
        if(i==row[ro]){
            ro++;
            continue;
        }
        for(int j=0;j<w;j++){
            //cout<<j<<" "<<rei[re]<<endl;
            if(re<siz(rei))
            if(j==rei[re]){
                re++;
                continue;
            }
            cout<<a[i][j];
        }
        re=0;
        cout<<endl;
    }
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------


Measured memory_bytes: 256
# coding: utf-8
# Your code here!
K,A,B=map(int,input().split())

if B-A>2:
    if K<=A:
        print(K+1)
    else:
        K-=A-1
        
        print((B-A)*(K//2)+A+K%2)
    
    
else:
    print(K+1)


Measured memory_bytes: 2940
<?php
    while($input_line = trim(fgets(STDIN))){

        $num = explode(" ",$input_line);
        if($num[0]==0 && $num[1]==0){
            break;
        }
        if($num[0]>$num[1]){
            $z =$num[1];
            $num[1] = $num[0];
            $num[0] = $z;
        }
        
        echo $num[0];
        echo " ";
        echo $num[1];
        echo "\n";
    }
?>


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


int main() {
#ifdef HOME
    freopen("in", "r", stdin);
#endif

    int n;
    while (cin >> n) {
        vector<int> a(n);
        int sum = 0;
        int mn = 1e9;
        for (int i = 0; i < n; i++) {
            cin >> a[i];
            sum += a[i];
            if (a[i] % 10) mn = min(mn, a[i]);
        }
        int ans = sum % 10 == 0 ? max(0, sum - mn) : sum;
        cout << ans << endl;
    }

#ifdef HOME
    cerr << clock() / (double)CLOCKS_PER_SEC << endl;
#endif
    return 0;
}


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

#define N 1000002
#define pb push_back
int hit[N], a[N];
int main(){
    int n, m;
    cin >> n >> m;
    for (int i=1; i<=m; i++){
        scanf("%d", &a[i]);
    }
    for (int i=m; i>=1; i--){
        int x = a[i];
        if (hit[x] == 0) printf("%d\n", x);
        hit[x] = 1;
    }
    for (int i=1; i<=n; i++){
        if (hit[i] == 0) printf("%d\n", i);
    }
    return 0;
}

Measured memory_bytes: 4368
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
/*
N?????????????????????????????§????????????????????????(No)????????????????????°??????(Yes)???????????????CheckConsistentDice_N
?????????????????????????????°???????????§?????????????????????CheckConsistentLabel
?????????????????????????????????????????¢????????????????????????TopFront
*/
class DICE
{
private:
	int Label[6];
public:
	void AddLabel() {
		for (int i = 0; i < 6; ++i) {
			std::cin >> Label[i];
		}
		return;
	}
	void RotateDirection(std::string);
	void Rotate(int, int, int, int);
	int GetLabel(int x) { return Label[x]; }
	bool TopBackFront(int, int, int);
	bool CheckConsistentLabel(DICE AnotherDice);
};


void DICE::RotateDirection(std::string s)
{
	if (s == "E") { Rotate(0, 3, 5, 2); }
	if (s == "N") { Rotate(0, 1, 5, 4); }
	if (s == "S") { Rotate(0, 4, 5, 1); }
	if (s == "W") { Rotate(0, 2, 5, 3); }
	return;
}
void DICE::Rotate(int a, int b, int c, int d)
{
	std::swap(Label[a], Label[b]);
	std::swap(Label[b], Label[c]);
	std::swap(Label[c], Label[d]);
	return;
}
bool DICE::TopBackFront(int top, int back, int front)
{
	const int size_str = 7;
	std::string str[size_str] = { "N","N","N","W","N","N","N" };
	for (unsigned int i = 0; i < size_str; ++i)
	{
		if (front == Label[1]) { break; }
		RotateDirection(str[i]);
	}
	if (back != Label[4]) {
		return false;
	}
	
	while (top != Label[0]) {
		RotateDirection("W");
	}
	return true;
}
bool DICE::CheckConsistentLabel(DICE AnotherDice) {
	int NumberLabel[101] = { 0 };
	for (int i = 0; i < 6; ++i) {
		++NumberLabel[Label[i]];
		--NumberLabel[AnotherDice.GetLabel(i)];
	}
	int i = 0;
	while (i <= 100) {
		if (NumberLabel[i] != 0) {
			return false;
		}
		++i;
	}
	return true;
}
bool CheckConsistentDice_N(std::vector<DICE >&dice) {
	const int LastNumberDice = 5;
	for (unsigned int i = 0; i < dice.size(); ++i) {
		for (unsigned int j = i + 1; j < dice.size(); ++j) {


			if (dice[i].CheckConsistentLabel(dice[j]) &&
				dice[i].TopBackFront(dice[j].GetLabel(0), dice[j].GetLabel(4), dice[j].GetLabel(1))) {
				for (int k = 0; k <= LastNumberDice; ++k)
				{
					if (dice[i].GetLabel(k) != dice[j].GetLabel(k)) {
						break;
					}
					else {
						if (k == LastNumberDice) {
							return false;
						}
					}
				}
			}
		}
	}
	return true;
}
int main(void)
{
	int NumberOfDice;
	std::cin >> NumberOfDice;
	std::vector<DICE >dice(NumberOfDice);
	for (int i = 0; i < NumberOfDice; ++i) {
		dice[i].AddLabel();
	}
	if (CheckConsistentDice_N(dice)) {
		std::cout << "Yes" << std::endl;
	}
	else {
		std::cout << "No" << std::endl;
	}
//	system("pause");
	return 0;
}

Measured memory_bytes: 3132
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for(int i = 1, i##_len = (n); i <= i##_len; ++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 INF 100000000

using namespace std;

int n, A, B, C;
vector<int> l;

void chmin(int &a, int b) {
    if(a > b)
        a = b;
}

int dfs(int i, int a, int b, int c) {
    if(i == n) {
        if(a == 0 || b == 0 || c == 0)
            return INF;
        return abs(A - a) + abs(B - b) + abs(C - c);
    }

    int res = INF;

    chmin(res, dfs(i + 1, a, b, c));
    chmin(res, dfs(i + 1, a + l[i], b, c) + (a ? 10 : 0));
    chmin(res, dfs(i + 1, a, b + l[i], c) + (b ? 10 : 0));
    chmin(res, dfs(i + 1, a, b, c + l[i]) + (c ? 10 : 0));

    return res;
}

int main() {
    cin >> n >> A >> B >> C;
    l.resize(n);
    for(int i = 0; i < n; i++)
        cin >> l[i];
    int res = dfs(0, 0, 0, 0);
    cout << res << endl;
    return 0;
}

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

int main()
{
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long int n,x;
    cin>>n>>x;
    long long int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+n);
    long long int ans=0;
    long long int total=0;
    for(int i=0;i<n;i++)
    {
        total+=arr[i];
        if(total==x)
        {
            ans++;
            break;
        }
        if(total>x)
        {
            break;
        }
        ans++;
    }
    if(total<x)
    cout<<ans-1<<"\n";
    else
    cout<<ans<<"\n";
    
}

Measured memory_bytes: 3660
def agc043_a():
    ''' 解説放送見てやってみた '''
    H, W = map(int, input().split())
    grid = []
    grid.append(['#'] * (W+2))  # 周辺埋め
    for _ in range(H):
        grid.append(['#'] + [c for c in str(input())] + ['#'])
    grid.append(['#'] * (W+2))
    grid[1][0] = grid[H][W+1] = '.'  # グリッド外側に白を置く, (1,1)(H,W)が黒の場合に反転カウントするため

    # 白黒が反転する回数を数える
    cost = [[10**6] * (W+2) for _ in range(H+2)]
    cost[1][0] = 0

    for i in range(1, H+1):
        for j in range(1, W+2):
            if i != H and j == W+1: continue  # ゴールの外側のときだけ通過
            rt = cost[i][j-1]
            if grid[i][j-1] != grid[i][j]: rt += 1
            dw = cost[i-1][j]
            if grid[i-1][j] != grid[i][j]: dw += 1
            cost[i][j] = min(rt, dw)

    ans = cost[H][W+1] // 2  # 区間の始まりと終わりを両方カウントしているので半分にする
    print(ans)

agc043_a()

Measured memory_bytes: 3188
#include<iostream>
#include<string>
using namespace std;
struct Dice{
  int s[6];
  void roll(char c){
    int b;
    if(c=='E'){
      b=s[0];
      s[0]=s[3];
      s[3]=s[5];
      s[5]=s[2];
      s[2]=b;
    }
    if(c=='W'){
      b=s[0];
      s[0]=s[2];
      s[2]=s[5];
      s[5]=s[3];
      s[3]=b;
    }
    if(c=='N'){
      b=s[0];
      s[0]=s[1];
      s[1]=s[5];
      s[5]=s[4];
      s[4]=b;
    }
    if(c=='S'){
      b=s[0];
      s[0]=s[4];
      s[4]=s[5];
      s[5]=s[1];
      s[1]=b;
    }
    if(c=='R'){
      b=s[1];
      s[1]=s[2];
      s[2]=s[4];
      s[4]=s[3];
      s[3]=b;
    }    
  }
  int top() {
    return s[0];
  }
  int right(){
    return s[2];
  }
  int left(){
    return s[3];
  }
  int front(){
    return s[1];
  }
};
bool same(Dice a,Dice b){
  for(int i=0;i<6;i++) if(a.s[i]!=b.s[i]) return false;
  return true;
}
int main(){
  Dice d[100];
  int n;cin >> n;
  for(int j=0;j<n;j++) 
    for(int i=0;i<6;i++)
      cin >> d[j].s[i];
   
  bool ff = true;
  for(int k=0;k<n-1;k++){
    for(int l=k+1;l<n;l++){
      bool f=false;
      for(int i=0;i<4;i++){
    d[l].roll('R');
    for(int j=0;j<4;j++){
      d[l].roll('N');
      if(same(d[k],d[l])) f=true;
    }
      }
      d[l].roll('E');
      for(int j=0;j<4;j++){
    d[l].roll('N');
    if(same(d[k],d[l])) f=true;
      }
       
      d[l].roll('W');
      d[l].roll('W');
      for(int j=0;j<4;j++){
    d[l].roll('N');
    if(same(d[k],d[l])) f=true;
      }
      if(f) ff=false;
    }
  }
   
  cout << (ff?"Yes":"No") << endl;
  return 0;
}




Measured memory_bytes: 3108
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int N;

bool ck(vector<string> s){
    rep(i,N)for(int j=i+1;j<N;j++){
        if(s[i][j]!=s[j][i]) return false;
    }
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin>>N;
    
    vector<string> s(N);
    rep(i,N) cin>>s[i];
    
    ll cnt=0;
    rep(i,N){
        rotate(s.begin(),s.begin()+1,s.end());
        cnt+=ck(s);
    }
    cout1(cnt*N)
}

Measured memory_bytes: 512
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""
def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# a^n
def power(a,n,mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod

# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n-1
    while(tmp >= l):
        a = a*tmp%mod
        tmp -= 1
    return a

inf = 10**18
mod = 10**9+7

n = ir()
a = lr()

total = 0
for num in a:
    total+=num
mean_min = total//n

ans = [0,0]
for i in range(mean_min, mean_min+2):
    ind = i%2
    for num in a:
        ans[ind]+=(num-i)*(num-i)
print(min(ans))

Measured memory_bytes: 63980
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    double sum;
    cin>>n;
    int ara[n];
    for(i=0;i<n;i++)cin>>ara[i];
    for(i=0;i<n;i++){
        sum+=(1.0/ara[i]);
    }
    sum=1.0/sum;
    cout<<fixed<<setprecision(14)<<sum<<endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

y = [0, 0]
for k in range(2):
    s = 0
    x = (-1) ** k
    for ai in a:
        si = s + ai
        if si * x > 0:
            s = si
            x *= -1
        else:
            y[k] += abs(si) + 1
            s = x
            x *= -1
print(min(y))


Measured memory_bytes: 14332
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long int n;
	scanf("%ld",&n);
	long long int sum = 0;
	if(n>=500)
	{
		sum = (int)(n/500);
		sum = sum*1000;
		n = n%500;
		//cout<<sum<<" "<<n<<endl;
	}
	if(n>=5)
	{
		int t = n/5;
		sum = sum + t*5;
	}
	printf("%lld\n",sum);


	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
now = a[0]
if now == 0:
  ans = 1
  now = 1
else:
  ans = 0
for i in a[1:]:
  t = now + i
  if now * t >= 0:
    if now >= 0:
      ans += t + 1
      now = -1
    else:
      ans += 1 - t
      now = 1
  else:
    now = t
    
if a[0] >= 0:
  now = -1
  ans2 = a[0] - now
else:
  now = 1
  ans2 = now - a[0]
for i in a[1:]:
  t = now + i
  if now * t >= 0:
    if now >= 0:
      ans2 += t + 1
      now = -1
    else:
      ans2 += 1 - t
      now = 1
  else:
    now = t
ans = min(ans,ans2)
print(ans)

Measured memory_bytes: 14644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=998244353,MAX=305,INF=1<<30;
bool dp[MAX][MAX][MAX];
ll dp2[MAX][MAX][MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string S;cin>>S;
    int N=si(S);
    dp[0][0][0]=1;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=N;j++){
            for(int k=0;k<=N;k++){
                if(dp[i][j][k]==0) continue;
                
                if(i+1<N){
                    if(S[i]=='0') dp[i+2][j+1][k]=1;
                    else dp[i+2][j][k+1]=1;
                    
                    if(S[i+1]=='0') dp[i+2][j+1][k]=1;
                    else dp[i+2][j][k+1]=1;
                    
                    dp[i+1][j][k]=1;
                }
                
                if(j&&S[i]=='1') dp[i+1][j-1][k+1]=1;
                
                if(k&&S[i]=='0') dp[i+1][j+1][k-1]=1;
                
                if(j||k) dp[i+1][j][k]=1;
            }
        }
    }
    
    reverse(all(S));
    
    dp2[0][0][0]=1;
    
    for(int i=0;i<N;i++){
        for(int j=0;j<=N;j++){
            for(int k=0;k<=N;k++){
                if(S[i]=='0'){
                    dp2[i][j][k+1]+=dp2[i][j][k];
                    dp2[i][j][k+1]%=mod;
                }else{
                    dp2[i][j+1][k]+=dp2[i][j][k];
                    dp2[i][j+1][k]%=mod;
                }
                dp2[i+1][j][k]+=dp2[i][j][k];
                dp2[i+1][j][k]%=mod;
            }
        }
    }
    
    ll ans=0;
    
    for(int i=0;i<=N;i++){
        for(int j=0;j<=N;j++){
            for(int k=0;k<=N;k++){
                if(dp[i][j][k]){
                    ans+=dp2[N-i][j][k];
                    ans%=mod;
                }
            }
        }
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 228776
package main

import "fmt"

func main() {
	var n, a, b int
	fmt.Scan(&n, &a, &b)

	var sum int
	for i := 1; i <= n; i++ {
		var kakuketanoSum int //各桁のsum
		kakuketanoSum = calcKakuketanoSum(i)
		if kakuketanoSum >= a && kakuketanoSum <= b {
			sum += i
		}
	}
	fmt.Println(sum)
}

func calcKakuketanoSum(i int) int {
	switch {
	case i < 10:
		return i
	case i < 100:
		ketaOf10 := i - (i % 10) // keta = "桁"
		return ketaOf10/10 + (i % 10)
	case i < 1000:
		ketaOf100 := i - (i % 100)
		ketaOf10 := i - ketaOf100 - (i % 10)
		return ketaOf100/100 + ketaOf10/10 + (i % 10)
	case i < 10000:
		ketaOf1000 := i - (i % 1000)
		ketaOf100 := i - ketaOf1000 - (i % 100)
		ketaOf10 := i - ketaOf1000 - ketaOf100 - (i % 10)
		return ketaOf1000/1000 + ketaOf100/100 + ketaOf10/10 + (i % 10)
	default:
		ketaOf10000 := i - (i % 10000)
		ketaOf1000 := i - ketaOf10000 - (i % 1000)
		ketaOf100 := i - ketaOf10000 - ketaOf1000 - (i % 100)
		ketaOf10 := i - ketaOf10000 - ketaOf1000 - ketaOf100 - (i % 10)
		return ketaOf10000/10000 + ketaOf1000/1000 + ketaOf100/100 + ketaOf10/10 + (i % 10)
	}
}


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

int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
		cin >> v[i];
	vector<int> dp(n,2000000000);
	
	dp[0] = 0;
	dp[1] = abs(v[0] - v[1]);
	for (int i = 2; i < n; i++) {
		int mn = 2000000000;
		for (int j = max(i-k,0); j < n  && j<i; j++) {
			mn = min(mn, dp[j] + abs(v[i] - v[j]));
		}
		dp[i] = mn;
	}
	cout << dp[n - 1];
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
int main()
{
	lli n,k;
	cin>>n>>k;
	lli ans1= n%k;
	lli ans2= abs(ans1-k);
	if(ans1<ans2)
	{
		cout<<ans1;
	}
	else
	{
		cout<<ans2;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_080
{
	class Program
	{
		static void Main(string[] args)
		{
			int N = int.Parse(Console.ReadLine());
			int sum = 0;
			int tmp_num = N;
			while (tmp_num > 0)
			{
				sum += tmp_num % 10;
				tmp_num /= 10;
			}

			if (N % sum == 0) Console.WriteLine("Yes");
			else Console.WriteLine("No");
		}
	}
}

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

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

    int N;
    cin>>N;//データの数に入力
    int a[N], min = 0, count = 0;
    for(int i = 0; i < N; i++) cin>>a[i];//データの入力

    //選択ソート
    for(int i = 0; i < N-1; i++) {
        min = i;
        for(int j = i+1; j < N; j++) {
            if(a[min] > a[j]) min = j;
        }
        if(min != i) {
            int s = a[min]; //入れ替えのための値保持
            a[min] = a[i];
            a[i] = s;
            count++; //カウント
        }
    }

    //出力
    for(int i = 0; i < N-1; i++) cout<<a[i]<<' ';
    cout<<a[N-1]<<endl;
    cout<<count<<endl;

    return 0;
}




Measured memory_bytes: 3156
from collections import deque

sc = iter(open(0).read().split())
ni = lambda: int(next(sc))
ns = lambda: next(sc)

S = ns()
S = deque(S)

rev = False
Q = ni()
for _ in range(Q):
    op = ni()
    if op == 1:
        rev = not rev
    else:
        F, C = ni(), ns()
        if F == 1:
            if rev:
                S.append(C)
            else:
                S.appendleft(C)
        else:
            if rev:
                S.appendleft(C)
            else:
                S.append(C)

print("".join(reversed(S) if rev else S))

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

int main(){
  int N,A,B;
  cin>>N>>A>>B;
  //cout<<N<<A<<B<<endl;
  int res=0;
  int n;
  int sum,dig,top;
  for(n=1;n<=N;n++){
    sum=0;
    dig=1;
    top=10;
    while(1){
      top=n%(dig*10)/dig;
      //cout<<top<<endl;
      sum+=top;
      if(n%(dig*10)==n)	break;
      dig*=10;
    }
    if(sum<=B && sum>=A){
      //cout<<n<<endl;
      res+=n;
    }
  }
  cout<<res<<endl;
  return 0;
}

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

int main(){
  int n, a[100001];
  cin >> n;
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a, a+n);
  int tmp=a[0], appear=0, count=0;
  for(int i=1;i<n;i++){
    if(a[i]==tmp){
      appear++;
    }
    else{
      if(appear%2 == 0) count++;
      tmp = a[i];
      appear = 0;
    }
  }
  if(appear%2 == 0) count++;
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 640
#coding: utf-8
import math
import heapq
import bisect
#from scipy.misc import comb

MOD = 10**9+7

def gcd(A,B):
    if B>A:
        A,B = B,A

    if(A%B==0):
        return B
    else:
        return gcd(B,A%B)

A,B,C,D = map(int, input().split())

L = (A-1)-((A-1)//C+(A-1)//D-(A-1)//(C*D//gcd(C,D)))
U = B-(B//C+B//D-B//(C*D//gcd(C,D)))

print(U-L)

Measured memory_bytes: 3064
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <stack>
#include <map>
#include <ctime>
#include <set>
#include <bitset>
#include <ctime>
#define X first
#define Y second
#define clr(u,v); memset(u,v,sizeof(u));
#define in() freopen("data","r",stdin);
#define out() freopen("data","w",stdout);
#define Clear(Q); while (!Q.empty()) Q.pop();
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, int> pci;
const int maxn = 2e5 + 10;
const int INF = 0x3f3f3f3f;
int f[maxn];
int f2[maxn];
int f3[maxn];

int sum[maxn];
void init(int n)
{
    for (int i = 0; i < maxn; i++)
        f[i] = i, f2[i] = i, f3[i] = i, sum[i] = 1;
}
int find(int x)
{
    return f[x] == x ? x : f[x] = find(f[x]);
}
int find2(int x)
{
    return f2[x] == x ? x : f2[x] = find2(f2[x]);
}

int find3(int x)
{
    return f3[x] == x ? x : f3[x] = find3(f3[x]);
}


void mix(int x, int y)
{
    int fx = find(x), fy = find(y);
    if (fx == fy) return ;
    f[fx] = fy;
}
void mix2(int x, int y)
{
    int fx = find2(x), fy = find2(y);
    if (fx == fy) return ;
    f2[fx] = fy;
}
void mix3(int x, int y)
{
    int fx = find3(x), fy = find3(y);
    if (fx == fy) return ;
    f3[fx] = fy;
    sum[fy] += sum[fx];
}
map <pii, int> M;

int main()
{
#ifdef LOCAL
//    in();
#endif
    int n, k, l, a, b;
    scanf("%d%d%d", &n, &k, &l);
    init(n);
    while (k--)
    {
        scanf("%d%d", &a, &b);
        mix(a, b);
    }
    while (l--)
    {
        scanf("%d%d", &a, &b);
        mix2(a, b);
//        else mix3(a,b);
    }
    for (int i = 1; i <= n; i++)
        M[make_pair(find(i), find2(i))]++;

    for (int i = 1; i <= n; i++)
        printf("%d ", M[make_pair(find(i), find2(i))]);
    puts("");
    return 0;
}


Measured memory_bytes: 15232
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower, islower
#include <stdio.h>

//#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
using namespace std;
using ll = long long; using ld = long double;
using P = pair<int, int>;

int main() {
  int n;
  cin >> n;
  int ans;
  if(n%1000 == 0) ans = 0;
  else ans = 1000 - n%1000; 
  cout << ans << endl;
}

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

using namespace std;

int main(){

	long long int n, lim,res=2;
	cin >> n;
	res=n;
	lim = sqrt(n);

	for(int i=1;i<=lim;i++){
		if(n%i==0){
			if(i+n/i -2<res)
				res = i + n/i -2;
		}
	}

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256