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

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}


//main関数
int main() {
	int K; 
	char S[100];
	scanf("%d",&K);
	scanf("%s",S);
	if (strlen(S) <= K ){
		for(int i=0;i<strlen(S);i++){
			printf("%c",S[i]);
		}
	} else {
		for(int i=0;i<K;i++){
			printf("%c",S[i]);
		}
		printf("...");
	}
	return 0;
}

Measured memory_bytes: 1724
// C - Sugar Water
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

void solve(int w1,int w2, int s1, int s2, int solute, int volume){
	int WS = w1*100, S = 0;
	int wend = volume/100 + 1;
	double maxper = 0.0;
	rp(iw, 1, wend){
		rp(jw, 0, wend){
			int w = w1*iw + w2*jw;
			if(w < wend){
				int send = volume - w*100 + 1;
				rp(is, 0, send){
					rp(js, 0, send){
						int s = s1*is + s2*js;
						if(s < send){
							int ws = w * 100 + s;
							if(ws <= volume && s <= solute*w){
								double per = 100.0*s/ws;
								if(maxper < per){
									maxper = per;
									WS = ws;
									S = s;
								}
							}
						}
					}
				}
			}
		}
	}
	printf("%d %d\n",WS,S);
}

int main(){
	int a,b,c,d,e,f;
	cin>>a>>b>>c>>d>>e>>f;
	solve(a,b,c,d,e,f);
}

Measured memory_bytes: 256
n=int(input())
s=list(input())

pin=set()
for i in range(0,1000):
    yn=""
    stri=format(i,"03d")
    for ii in range(n-2):
        if stri[0]!=s[ii]:
            continue
        else:
            yn="yes1"
            break
    if yn!="yes1":
        yn="no"
        continue
    for iii in range(ii+1,n-1):
        if stri[1]!=s[iii]:
            continue
        else:
            yn="yes2"
            break
    if yn!="yes2":
        yn="no"
        continue
    for iiii in range(iii+1,n):
        if stri[2]!=s[iiii]:
            continue
        else:
            yn="yes3"
            break
    if yn=="yes3":
        pin.add(stri)
    else:
        continue

print(len(pin))        
    

Measured memory_bytes: 44696
import java.util.*;
import java.lang.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        if (s.charAt(0) == t.charAt(2) && s.charAt(1) == t.charAt(1) && s.charAt(2) == t.charAt(0)) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 22996
#include<iostream>
using namespace std;
typedef long long int ll;
int main(){
  ll A, V;
  cin >> A >> V;
  ll B,W;
  cin >> B >> W;
  ll T;
  cin >> T;
  ll D=abs(A-B);
  ll D2=(V-W)*T;
  puts(D<=D2?"YES":"NO");
}


Measured memory_bytes: 3612
import java.util.*;
 
public class Main { //クラス名はMain
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s=sc.next();
        long k=sc.nextLong();
        int l=s.length();
        int x=0;
      	long o=0;
        char a=s.charAt(0);
      	char b;
        boolean p=false;
        for(int i=0;i<l-1;i++){
        	if(s.charAt(i)==s.charAt(i+1)){
                if(i==l-2){
                	o=k*l/2;
                    System.out.println(o);
                    return;
                }
            	continue;
            }else{
            	break;
            }
          
        }
        if(l>1){
            b=s.charAt(1);
            for(int i=1;i<l;i++){
                b=s.charAt(i);
                if(a==b && !p){
                    p=true;
                    x++;
                }else{
                    p=false;
                }
                a=b;
            }
            o+=x*k;
            if(!p && b==s.charAt(0)){
                o+=k-1;
            }
          
            int x2=0;
      		long o2=0;
        	char a2=s.charAt(l-1);
      		char b2=s.charAt(l-2);
            boolean p2=false;
            for(int i=l-2;i>=0;i--){
                b2=s.charAt(i);
                if(a2==b2 && !p2){
                    p2=true;
                    x2++;
                }else{
                    p2=false;
                }
                a2=b2;
            }
            o2+=x2*k;
            if(!p2 && b2==s.charAt(l-1)){
                o2+=k-1;
            }
            o=Math.min(o,o2);
        }else{
        	o=k/2;
        }
        System.out.println(o);
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
#define MOD 1000000007
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	LL N, D;
	cin >> N >> D;

	LL ans = 1;
	LL count = 0;
	for (LL i = 0; i < N; i++)
	{
		if (count == 2*D+1) {
			ans++;
			count = 0;
		}
		count++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
n = gets.to_i
s = gets.chomp

stack = []
(0...n).each do |i|
  stack << i if s[i] == "R"
end

ans = 0
(0...n).each do |i|
  if s[i] == "W"
    j = stack.pop
    break if j.nil? || i > j
    ans += 1
  end
end

puts ans

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

typedef long long ll; 

const int N = 4000; 
const int MOD = 1000000007;

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

inline ll add( ll a, ll b ) { return a + b >= MOD ? a + b - MOD : a + b; }

inline ll dec( ll a, ll b ) { return a - b < 0 ? a - b + MOD : a - b; }

inline ll ksm( ll a, ll b )
{
	ll ret = 1; 
	for( ; b; b >>= 1, a = a * a % MOD ) 
		if( b & 1 ) ret = ret * a % MOD;
	return ret; 
}

int n, q, a[N];

ll f[N][N], temp[N][N]; 

int main()
{
//	freopen( "d.in", "r", stdin );
	
	n = read(); q = read(); 
	
	for( int i = 1; i <= n; i ++ ) 	
		a[i] = read(); 
		
	for( int i = 1; i <= n; i ++ )
		for( int j = 1; j <= n; j ++ )
			f[i][j] = a[i] > a[j] ? 1 : 0;
		
	ll inv = ksm( 2, MOD - 2 ); int x, y;
	for( int i = 1; i <= q; i ++ )
	{
		x = read(); y = read(); 
		
		for( int j = 1; j <= n; j ++ )
			if( j != x && j != y )
				f[x][j] = f[y][j] = inv * add( f[x][j], f[y][j] ) % MOD, 
				f[j][x] = f[j][y] = inv * add( f[j][x], f[j][y] ) % MOD;
			
		f[x][y] = f[y][x] = inv * add( f[x][y], f[y][x] ) % MOD;
	}  

	ll ans = 0; 
	for( int i = 1; i <= n; i ++ )
		for( int j = i + 1; j <= n; j ++ )
			ans = add( ans, f[i][j] ); 
			
	ans = ans * ksm( 2, q ) % MOD;
			
	cout << ans << endl; 
	
	return 0; 
}

Measured memory_bytes: 94464
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 1000000000
#define InfLL 1000000000000000000LL
#define nmax_def 110000
#define Cmax_def 2200
#define mod 1000000007
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=(n-1);(i)>=(0);(i)--)
using namespace std;
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;


vl pow_;
vl pow_1;
vl pow_2;
void pow_ini(ll n) {
	pow_.clear();
	pow_.push_back(n);
	rep(j, 62) {
		ll nxt = pow_[j] * pow_[j];
		nxt %= mod;
		pow_.push_back(nxt);
	}
	return;
}
void pow_ini1(ll n) {
	pow_1.clear();
	pow_1.push_back(n);
	rep(j, 62) {
		ll nxt = pow_1[j] * pow_1[j];
		nxt %= mod;
		pow_1.push_back(nxt);
	}
	return;
}
void pow_ini2(ll n) {
	pow_2.clear();
	pow_2.push_back(n);
	rep(j, 62) {
		ll nxt = pow_2[j] * pow_2[j];
		nxt %= mod;
		pow_2.push_back(nxt);
	}
	return;
}

ll pow1(ll k) {
	ll ans = 1;
	rep(ntmp, 62) {
		if ((k >> ntmp) % 2 == 1) {
			ans *= pow_[ntmp];
			ans %= mod;
		}
	}
	return ans;
}
ll pow25(ll k) {
	ll ans = 1;
	rep(ntmp, 62) {
		if ((k >> ntmp) % 2 == 1) {
			ans *= pow_1[ntmp];
			ans %= mod;
		}
	}
	return ans;
}
ll pow26(ll k) {
	ll ans = 1;
	rep(ntmp, 62) {
		if ((k >> ntmp) % 2 == 1) {
			ans *= pow_2[ntmp];
			ans %= mod;
		}
	}
	return ans;
}

vl fact;
vl fact_inv;

void fact_ini(ll n) {
	fact.resize(n + 1);
	fact[0] = 1;
	for (ll i = 1; i <= n; i++) {
		ll fact_tmp = fact[i - 1] * i;
		fact_tmp %= mod;
		fact[i] = fact_tmp;
	}
	fact_inv.resize(n + 1);
	pow_ini(fact[n]);
	fact_inv[n] = pow1(mod - 2);
	for (ll i = n - 1; i >= 0; i--) {
		fact_inv[i] = fact_inv[i + 1] * (i + 1);
		fact_inv[i] %= mod;
	}
}

ll nCm(ll n, ll m) {
	assert(m >= 0);
	assert(n < fact.size());
	assert(n >= m);
	ll ans = fact[n] * fact_inv[m];
	ans %= mod;
	ans *= fact_inv[n - m];
	ans %= mod;
	return ans;
}

int main() {
	fact_ini(2200000);
	pow_ini1(25);
	pow_ini2(26);
	ll K;
	cin >> K;
	string S;
	cin >> S;
	ll N = S.length();
	ll ans = 0;
	for (ll k = 0; k <= K; k++) {
		ll n = N + K - k;
		ll anstmp = 1;
		anstmp *= pow26(k);
		anstmp %= mod;
		anstmp *= nCm(n - 1, N - 1);
		anstmp %= mod;
		anstmp *= pow25(n - N);
		anstmp %= mod;
		ans += anstmp;
		ans %= mod;

	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 39720
// B.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 3030, mod = 998244353;

int n, m, a, b, dp[MAX_N][MAX_N];

int main()
{
    scanf("%d%d%d%d", &a, &b, &n, &m);
    dp[a][b] = 1;
    for (int i = a; i <= n; i++)
        for (int j = b; j <= m; j++)
            if (i != a || j != b)
                dp[i][j] = (0LL + 1LL * dp[i - 1][j] * j % mod + 1LL * dp[i][j - 1] * i % mod + mod - 1LL * dp[i - 1][j - 1] * (i - 1) % mod * (j - 1) % mod) % mod;
    printf("%d\n", dp[n][m]);
    return 0;
}

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

int main()
{
    int K;
    cin >> K;
    int amari = 7;
    int count = 1;
    for (int i = 0; i < K; i++)
    {
        if (amari % K == 0)
        {
            break;
        }
        amari = (amari * 10 + 7) % K;
        count += 1;
    }
    if (count == K + 1)
    {
        count = -1;
    }
    cout << count << endl;
}

Measured memory_bytes: 3520
#include<iostream>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<stack>
#include<map>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std;

#define mod 998244353
#define inf 0x7f7f7f7f
#define maxn 500005
#define N 300005
typedef long long ll;

inline int read()
{
    int x = 0;
    int f = 1;
    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 x*f;
}

int n, a[N], p[N];
typedef multiset<int>::iterator st;
int main() {
    cin >> n;
    multiset<int> s;
    s.insert(0), s.insert(0);
    s.insert(n + 1), s.insert(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        p[a[i]] = i;
    }
    ll ans = 0;
    for (int i = n; i >= 1; i--) {
        st r2 = s.upper_bound(p[i]), l2 = r2++;
        st r1 = l2--, l1 = l2--;
        ans += 1ll * (*l1 - *l2) * (*r1 - p[i]) * i;
        ans += 1ll * (*r2 - *r1) * (p[i] - *l1) * i;
        s.insert(p[i]);
    }
    cout << ans << endl;
}   

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

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  vector<vector<ll>> a = {vector<ll>(x), vector<ll>(y), vector<ll>(z)};
  for (auto &e : a[0]) cin >> e;
  for (auto &e : a[1]) cin >> e;
  for (auto &e : a[2]) cin >> e;
  for (auto &e : a) {
    sort(rbegin(e), rend(e));
  }
  vector<ll> r = a[0];
  for (int i = 1; i < a.size(); i++) {
    vector<ll> t;
    for (int p = 0; p < r.size(); p++) {
      for (int q = 0; q < a[i].size(); q++) {
        t.push_back(r[p] + a[i][q]);
      }
    }
    sort(rbegin(t), rend(t));
    r = vector<ll>(begin(t), begin(t) + min(k, (int)t.size()));
  }
  for (auto e : r) cout << e << endl;
}


Measured memory_bytes: 35248
#include<stdio.h>
#define MAX 101

main(){
  int n, A[MAX], i, pre, cnt;
  while(1){
    scanf("%d", &n);
    if ( n == 0 ) break;
    for ( i = 0; i < n; i++ ) scanf("%d", &A[i]);
    A[n] = 1000;
    pre = A[0];

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

Measured memory_bytes: 0
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    vector<vector<ll>> a(n,vector<ll>(n,E));
    for(int i=0;i<n;i++){
        a[i][i]=0;
    }
    for(int i=0;i<n;i++){
        ll u,k;
        cin>>u>>k;
        for(int t=0;t<k;t++){
            ll v,c;
            cin>>v>>c;
            a[i][v]=c;
        }
    }
    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int t=0;t<n;t++){
                a[i][t]=min(a[i][t],a[i][k]+a[k][t]);
            }
        }
    }
    for(int i=0;i<n;i++){
        cout<<i<<" "<<a[0][i]<<endl;
    }
    
    
    return 0;
}


Measured memory_bytes: 3160
S = list(input())
N = len(S)
s10 = ['1' if i%2==0 else '0' for i in range(N)]
s01 = ['0' if i%2==0 else '1' for i in range(N)]
ans10, ans01 = 0, 0
for i in range(N):
    if S[i] != s10[i]:
        ans10 += 1
    elif S[i] != s01[i]:
        ans01 += 1
print(min(ans10, ans01))


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

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <algorithm>

#include <bits/stdc++.h>
#include <cmath>
#include <limits>

using namespace std;
long long INF = (1LL<<62);
typedef long long LL;

LL N;
vector<LL> A, B, C;

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> N;
	for(int i=0; i<N; i++){
		LL a;
		cin >> a;
		A.push_back(a);
	}
	for(int i=0; i<N; i++){
		LL b;
		cin >> b;
		B.push_back(b);
	}
	for(int i=0; i<N; i++){
		C.push_back(B[i] - A[i]);
	}
	sort(C.begin(), C.end());
	LL remain = 0;
	for(int i=0; i<N; i++){
		if(C[i] < 0){
			LL c = 0 - C[i];
			remain = c;
			for(int j=i+1; j<N; j++){
				if(C[j] >= 2){
					LL k = min(C[j] / 2, remain);
					C[j] = C[j] - (2*k);
					remain -= k;
					if(remain == 0){
						break;
					}
				}
			}
			if(remain > 0){
				break;
			}
			if(remain == 0){
				C[i] = 0;
			}
		}
	}
	if(remain > 0){
		printf("No\n");
	}
	else{
		printf("Yes\n");
	}
	return 0;
}



Measured memory_bytes: 3808
from collections import deque
n, m = map(int, input().split())
TO = [[] for i in range(n)] #隣接リスト adjacency list
for i in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b -1
    TO[a].append(b)
    TO[b].append(a)

#BFS
#変数定義
Q = deque([])
DIST = [-1 for i in range(n)]
PRE = [-1 for i in range(n)]
#初期値の設定
DIST[0] = 0
Q.append(0)
#処理
while len(Q) > 0:
    x = Q.popleft()  
    for i in range(len(TO[x])):
        y = TO[x][i]
        if DIST[y] != -1: continue
        DIST[y] = DIST[x] + 1
        PRE[y] = x
        Q.append(y)

print('Yes')
for i in range(n):
    if i == 0: continue
    ans = PRE[i] + 1 
    print(ans)

Measured memory_bytes: 34868
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cmath>
#include <map>
#define ull unsigned long long
#define ll long long
using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,a;
    cin >> n;
    vector<int> q;
    for(int i;i<n;i++){
        cin >> a;
        q.emplace_back(a);
    }
    cout << *max_element(q.begin(),q.end()) - *min_element(q.begin(),q.end()) << endl;
    
    return 0;
}

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

long long n;

int main() {
	cin >> n;
	long long ans = 1e15;
	for (int i=1; i<=sqrt(n); i++) {
		if (n % i == 0) {
			ans = min(ans, i + (n / i));
		}
	}
	cout << ans - 2 << '\n';
}

Measured memory_bytes: 3684
#include<bits/stdc++.h>//author::@whohet-->Het Patel
#define fasterthanlight ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define test int T; cin>>T; while(T--)
#define endl "\n"
#define int long long
#define vi vector<int>
#define pb push_back
#define mod 1000000007
#define MAX 1e9
#define MIN -1e9
using namespace std;

//author::@whohet-->Het Patel

signed main()
{
	fasterthanlight;
	int a, b;
	cin >> a >> b;
	if (a > 12)
		cout << b;
	else if (a <= 5)
		cout << 0;
	else
		cout << b / 2;
	return 0;
}


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

int main(){
  vector<int> a(5);
  for (int i=0;i<5;++i){
    cin >> a.at(i);}
  int d;
  cin >> d;
  if (a.at(4)-a.at(0)>d) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

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

#define mp make_pair

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

int ExtendedGCD(int a,int b,int& x,int& y)
{
	if(b==0){
		x=1,y=0;
		return a;
	}
	else{
		int g=ExtendedGCD(b,a%b,x,y);
		tie(x,y)=make_tuple(y,x-a/b*y);
		return g;
	}
}

//int ExtendedGCD(int a,int b,int& x,int& y)
//{
//	x=1,y=0;
//	for(int u=0,v=1;b;){
//		ll t=a/b;
//		swap(a-=b*t,b);
//		swap(x-=u*t,u);
//		swap(y-=v*t,v);
//	}
//	return a;
//}

int main()
{
	for(int a,b;cin>>a>>b && a|b;){
		int x,y;
		for(int i=0;i<1000000;i++)
			ExtendedGCD(a,b,x,y);
		cout<<x<<' '<<y<<endl;;
	}
}

Measured memory_bytes: 1164
using System;
using System.Collections.Generic;
using System.Linq;
using static Atcoder;
using System.Threading.Tasks;
using System.ComponentModel;

public class Hello
{

    public static void Main()
    {
        int n = intRead();
        Console.WriteLine((n %2 == 1?n * 2:n));
    }
}


public class Atcoder
{
    static void Swap<T>(ref T a, ref T b)
    {
        var t = a;
        a = b;
        b = t;
    }
    public static int LCM(int a, int b)
    {
        int c = a * b;
        if (a < b) Swap(ref a, ref b);
        int d = a % b;
        while (d != 0)
        {
            a = b;
            b = d;
            d = a % b;
        }
        return c / b;
    }
    public static string strReverce(string s)
    {
        return new string(s.Reverse().ToArray());
    }
    public static int intRead()
    {
        return int.Parse(Console.ReadLine());
    }
    public static bool IsPrime(int n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        if (n % 2 == 0) return false;

        //double sqrtNum = Math.Sqrt(n);
        for (int i = 3; i < n; i += 2)
        {
            if (n % i == 0) return false;
        }
        return true;
    }
    public static string[] SpRead(char c)
    {
        return Console.ReadLine().Split(c);
    }
    public static int[] SpIntRead(char c)
    {
        return Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
    }

}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define Fast_IO ios::sync_with_stdio(false);
#define fir first
#define sec second
#define int long long
#define mod 998244353
inline int read()
{
	char ch=getchar(); int nega=1; while(!isdigit(ch)) {if(ch=='-') nega=-1; ch=getchar();}
	int ans=0; while(isdigit(ch)) {ans=ans*10+ch-48;ch=getchar();}
	if(nega==-1) return -ans;
	return ans;
}
typedef pair<int,int> pii;
#define N 100005
int d[N],cnt[N];
signed main()
{
#ifdef __LOCAL__
	freopen("in.txt","r",stdin);
#endif
	int n=read();
	for(int i=1;i<=n;i++)
	{
		d[i]=read();
		if(i==1)
		{
			if(d[i]!=0) return cout<<"0\n",0;
		}
		else
		{
			if(d[i]==0) return cout<<"0\n",0;
		}
	}
	for(int i=1;i<=n;i++) cnt[d[i]]++;
	int ans=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=cnt[i];j++) ans=ans*cnt[i-1]%mod;
	}
	cout<<ans<<endl;
#ifdef __LOCAL__
	printf("Time Used : %d\n",clock());
#endif
	return 0;
}



Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	double n, sum;
	int i;
	
	while (scanf("%lf", &n) != EOF){
		sum = n;
		for (i = 0; i < 9; i++){
			if (i % 2 == 0){
				n *= 2;
				sum += n;
			}
			else {
				n /= 3;
				sum += n;
			}
		}
		printf("%.8lf\n", sum);
	}
	
	return (0);
}

Measured memory_bytes: 652
k = int(input())
if k % 2 == 0 or k % 5 == 0:
    print(-1)
    exit()
curr = 0
i = 1
while True:
  curr *= 10
  curr += 7
  curr %= k
  if curr == 0:
    print(i)
    break
  i += 1
  if i > 1000000:
      print(-1)
      break

Measured memory_bytes: 63200
import collections

n = int(input())
s = [str(input()) for _ in range(n)]
word_dict = collections.Counter(s)
maxVal = max(word_dict.values())
max_list = [key for key, value in word_dict.items() if value == maxVal]
max_list.sort()
for item in max_list:
    print(item)

Measured memory_bytes: 35572
DBG = !true
n = gets.to_i
a = gets.split.map{|x| x.to_i}

sum = 0
for i in 0...n
  sum += a[i]
end

mindif = 99999
minsuf = 999
for i in 0...n
  if (a[i]*n - sum).abs < mindif
    mindif = (a[i]*n - sum).abs
    minsuf = i
  end
end
print minsuf


Measured memory_bytes: 3836
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define int         long long   
#define double      long double
#define endl        "\n"
#define pb          push_back
#define PI          3.1415926535897932384626433832795l
#define F           first
#define S           second
#define mp          make_pair
#define f(i,n)      for(int i=0;i<n;i++)
#define fastio      ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)      (v).begin(),(v).end()
#define rall(v)     (v).rbegin(),(v).rend()
#define sort(v)     sort((v).begin(),(v).end())
#define rsort(v)    sort((v).rbegin(),(v).rend())
#define gcd(a,b)    __gcd((a),(b))
#define minn(v)     *min_element(v.begin(), v.end());
#define maxx(v)     *max_element(v.begin(), v.end());
#define print(x)    cout<<(x)<<endl;
#define sum(v)+x    accumulate(v.begin(), v.end(),x);
typedef pair<int,int> pii;  
typedef vector<int> vi;
//x.substr(start, length);
/*
// Create a vector containing n 
//vectors of size m.  
    vector<vector<int> > vec( n , vector<int> (m, 0));  
*/
struct type{
    int k, i, j;
};
//to check if a no is prime or not?
bool isPrime(int n) 
{ 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
}

// minimum subaaray sum of size k-sliding window approach
int findSubarray(int arr[], int n, int k)
{
	int window_sum = 0;
	int min_window = INT_MAX;
	int last = 0;
	for (int i = 0; i < n; i++)
	{
		window_sum += arr[i];
		if (i + 1 >= k)
		{
			if (min_window > window_sum)
			{
				min_window = window_sum;
				last = i;
			}
			window_sum -= arr[i + 1 - k];
		}
	}
	int sum=0;
	for(int i=last-k+1;i<=last;i++)
	{
	    sum+=arr[i];
	}
	return sum;
}
//finds the next permutation to given sequence of nos
int nextpermutation(vi v)
{
    vi t=v;
    sort(t);
    int x=0;
    while(true)
    {
        x++;
        if(t==v)
        {
            return x;
        }
        next_permutation(all(t));
    }
}
signed main() 
{
    fastio;
    //cout << fixed << setprecision(0);
    int n,k;
    cin>>n>>k;
    int r,s,p;
    cin>>r>>s>>p;
    map<char,int> m;
    m['r']=p;
    m['s']=r;
    m['p']=s;
    bool flag[100007];
    for(int i=0;i<100007;i++)
    {
        flag[i]=1;
    }
    string S;
    cin>>S;
    int ans=0;
    for(int i=0;i<S.size();i++)
    {
        if(flag[i%k] or S[i]!=S[i-k])
        {
            ans+=m[S[i]];
            flag[i%k]=0;
        }
        else
        {
            flag[i%k]=1;
        }
        
    }
    print(ans)
    
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rua system("pause")
using namespace std;
typedef long long ll;
inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while (!isdigit(c)) {if (c == '-') f = -1; c = getchar();}
	while (isdigit(c)) {x = x * 10 + c - '0', c = getchar();}
	return x * f;
}

int Q, A, B, C, D;

int main()
{
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
	Q = read();
	while (Q --)
	{
		A = read(), B = read(), C = read(), D = read();
		int k = (max(A, B) + min(A, B)) / (min(A, B) + 1);
 		int l = 0, r = A, res = 0;
		while (l <= r)
		{
			int mid = (l + r) >> 1;
			int cnt = (mid + k - 1) / k, need_b = max(0, cnt - 1);
			int remain_b = B - need_b;
			if (remain_b < 0)
			{
				r = mid - 1;
				continue;
			}
			if ((remain_b + k - 1) / k <= A - mid + 1)
			{
				res = mid, l = mid + 1;
			}
			else r = mid - 1;
		}
		int cnt = max(0, (res + k - 1) / k), need_b = max(0, cnt - 1);
//		cerr << "res = " << res << endl; rua;
		int front_all = res + need_b;
		for (int i = C; i <= min(front_all, D); i ++)
			putchar(i % (k + 1) == 0 ? 'B' : 'A');
		int all = A + B;
		for (int i = max(C, front_all + 1); i <= D; i ++)
			putchar((all - i + 1) % (k + 1) == 0 ? 'A' : 'B');
		putchar(10);
	}
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lvector vector<ll> 
#define P pair<ll,ll>
#define rep(i,n) for(ll (i)=0; i<(n); ++(i))
#define print(a) cout << (a) << endl

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll n,x,l;cin>>n;
  vector<P> xv(n);
  rep(i,n) {cin>>x>>l;xv[i]=P{x+l,x-l};}
  sort(xv.begin(),xv.end());
  ll ans=0,pos=-1e9;
  rep(i,n) {
    if(pos<=xv[i].second) {
      ans++;
      pos=xv[i].first;
    }
  }
  print(ans);
  return 0;
}

Measured memory_bytes: 1792
// In the name of ALLAH
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n , a , b ;
    cin >> n >> a >> b ;
    for( int i = a ; i <= b ; i ++ )
    {
        if( i%n==0 )
        {
             cout << "OK" <<endl;
            return 0 ;
        }
    }
    cout <<"NG" <<endl;
    return 0;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int l, r, d;
    cin>>l>>r>>d;
    int cnt = 0;
    for(int i=l; i<=r; i++)
    {
        if(i>=d)
        {
            if(i%d==0) cnt++;
        }
    }
    cout<<cnt<<endl;
    return 0;
}


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

int x, y;
long long ans;

int main() {
  	cin >> x >> y;
  	if (x == 3)
      	ans += 100000;
    if (x == 2)
		ans += 200000;
    if (x == 1)
    	ans += 300000;
    if (y == 3)
      	ans += 100000;
    if (y == 2)
		ans += 200000;
    if (y == 1)
    	ans += 300000;
    if (x == 1 && y == 1)
      	ans += 400000;
    cout << ans << '\n';
 	return 0; 
}

Measured memory_bytes: 256
import numpy as np

n, k = map(int, input().split())
p = list(map(int, input().split()))
p = [0] + p
m = (np.array(p) + 1)/2
m[0] = 0
cum  = np.cumsum(m)

ma = 0
for i in range(n - k + 1):
    a = cum[i + k] - cum[i]
    if ma < a:
        ma = a
print(ma)

Measured memory_bytes: 34108
n = list(str(input()))
maxcnt = 0
cnt = 1
tmp = n[0]
for i in range(1, 4):
    if n[i] == tmp:
        cnt += 1
    else:
        maxcnt = max(maxcnt, cnt)
        tmp = n[i]
        cnt = 1
maxcnt = max(maxcnt, cnt)

ans = 'No'
if maxcnt >= 3:
    ans = 'Yes'

print(ans)


Measured memory_bytes: 3064
#include <iostream>
#include <set>

using namespace std;
set<int > s;
int N,M;
int a,b;
int main() {
    cin>>N>>M;
    for(int i=0 ; i<M ; i++){
        cin>>a>>b;
        if(a==1 || a==N){
            if(s.find(b)!=s.end()){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
            else
                s.insert(b);
        }
        if(b==1 || b==N){
            if(s.find(a)!=s.end()){
                cout<<"POSSIBLE"<<endl;
                return 0;
            }
            else
                s.insert(a);
        }
            
    }
    cout<<"IMPOSSIBLE"<<endl;
}


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

int main(){
	int a, b, c, x, y, cost = 0;
	cin >> a >> b >> c >> x >> y;
	if((a+b)/2 < c)	cost += a*x + b*y;
	else {
		if(x<y) {
			int cost_, cost_min = 1000000000;
			for(int i = 0; i <= y - x; i++) {
				cost_ = b*i + 2*c*(y-x-i);
				if(cost_min > cost_)	cost_min = cost_;
			}
			cost += c*2*x + cost_min;
		} else {
			int cost_, cost_min = 1000000000;
			for(int i = 0; i <= x-y; i++) {
				cost_ = a*i + 2*c*(x-y-i);
				if(cost_min > cost_)	cost_min = cost_;
			}
			cost += c*2*y + cost_min;
		}
	}
	cout << cost << "\n";
}

Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Sun Mar 22 23:25:40 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni      = lambda: int(ns())
nin     = lambda y: [ni() for _ in range(y)]
na      = lambda: list(map(int, stdin.readline().split()))
nan     = lambda y: [na() for _ in range(y)]
nf      = lambda: float(ns())
nfn     = lambda y: [nf() for _ in range(y)]
nfa     = lambda: list(map(float, stdin.readline().split()))
nfan    = lambda y: [nfa() for _ in range(y)]
ns      = lambda: stdin.readline().rstrip()
nsn     = lambda y: [ns() for _ in range(y)]
ncl     = lambda y: [list(ns()) for _ in range(y)]
nas     = lambda: stdin.readline().split()

s = ns()
print("yes" if len(s) == len(set(s)) else "no")

Measured memory_bytes: 3064
import java.util.*;

public class Main{
	
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
  	int n=sc.nextInt(),k=sc.nextInt(),sum=0;
    int[] p=new int[n];
    for(int i=0;i<n;i++){
      p[i]=sc.nextInt();
    }
    Arrays.sort(p);
    for(int i=0;i<k;i++){
      sum+=p[i];
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 39180
a, b, c = map(int, input().split())
k = int(input())

ans = "No"
for bi in range(k+1):
    bb = b
    cc = c * (2 ** (k - bi))

    if a < bb and bb < cc:
        ans = "Yes"
        break

    for _ in range(bi):
        bb *= 2
        if a < bb and bb < cc:
            ans = "Yes"

    if ans == "Yes":
        break

print(ans)


Measured memory_bytes: 9192
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
    N = II()
    if N%1000==0:
        ans = 0
    else:
        ans = 1000 - N%1000
    print(ans)
	

if __name__ == '__main__':
    main()

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

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

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << a[n - 1] - a[0] << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    Main(){
        Scanner sc = new Scanner(System.in);
        int tmp, case_num = 1;
        while((tmp = sc.nextInt()) != 0){
            System.out.printf("Case %d: %d\n", case_num++, tmp);
        }
    }

    public static void main(String[] args){
        new Main();
    }
}



Measured memory_bytes: 64156
import numpy as np

h, n = map(int,input().split())
a = np.zeros(n, dtype = int)
b = np.zeros(n, dtype = int)
for i in range(n):
    a[i], b[i] = map(int,input().split())

dp = np.zeros(10001, dtype = int)

for i in range(1,10001):
    dp[i] = (dp[i-a]+b).min()

print(dp[h])


Measured memory_bytes: 12484
#include <stdio.h>

int main(void) {
	int i,j,t;
	int yama[10];
	for(i=0;i<10;i++){
		scanf("%d",&yama[i]);
	}
	for(i=0;i<10;i++){
		for(j=i+1;j<10;j++){
			if(yama[i]<yama[j]){
				t=yama[i];
				yama[i]=yama[j];
				yama[j]=t;
			}
		}
	}
	for(i=0;i<3;i++){
		printf("%d\n",yama[i]);
	}
	return 0;
}

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

using namespace std;

#define fo(i,CApiTaL_N) for(int i=0; i<CApiTaL_N; i++)
#define Fo(i,k,CApiTaL_N) for(int i=k; i<CApiTaL_N; i++)
#define ll long long
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it=a.begin(); it!=a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;

int t;
const int mxN=3e3;
int n;
vl a(mxN+1);
vector<vector<vpll>> dp(mxN+1,vector<vpll>(mxN+1,vpll(4)));

void test_case(){
    cin>>n;
    Fo(i,1,n+1)cin>>a[i];
    Fo(i,1,n+1){
        dp[i][i][0]=mp(a[i],0);
        dp[i][i][1]=mp(0,a[i]);
    }
    Fo(len,2,n+1){
        Fo(srt,1,n+2-len){
            // cout<<srt<<" "<<len<<endl;
            dp[srt][srt+len-1][0]=max(mp(dp[srt+1][srt+len-1][1].first+a[srt],dp[srt+1][srt+len-1][1].second),mp(dp[srt][srt+len-2][1].first+a[srt+len-1],dp[srt][srt+len-2][1].second));
            if(a[srt]+dp[srt+1][srt+len-1][0].second > a[srt+len-1]+dp[srt][srt+len-2][0].second){
                dp[srt][srt+len-1][1]=mp(dp[srt+1][srt+len-1][0].first,a[srt]+dp[srt+1][srt+len-1][0].second);
            }else{
                dp[srt][srt+len-1][1]=mp(dp[srt][srt+len-2][0].first,a[srt+len-1]+dp[srt][srt+len-2][0].second);
            }
        }
    }
    cout<<dp[1][n][0].first-dp[1][n][0].second<<endl;
}

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

    t=1;
    while(t--){
        test_case();
    }
    
    return 0;
}

Measured memory_bytes: 918684
#include "bits/stdc++.h"
#include <set>

using namespace std;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()
#define int long long
#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
#define mod 1000000007
#define INF 10e10
template <typename T>

void print(T x)
{
	std::cout << x << " ";
}
template <typename T>

void println(T x)
{
	std::cout << x << "\n";
}

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

signed main(void) {
	int K;
	cin >> K;
	int sum = 0;
	rep1(i, K + 1) {
		rep1(j, K + 1) {
			rep1(k, K + 1) {
				sum += gcd(gcd(i, j), k);
			}
		}
	}
	print(sum);
}


Measured memory_bytes: 3620
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int w,h,x,y;
    cin >> w >> h >> x >> y;
    double ans = ((double)w*h)/2.0;
    int f=0;
    if(x*2==w&&y*2==h){
        f=1;
    }
    printf("%.9f %d\n",ans,f);
    return 0;
}

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

using namespace std;
 
/// ----------------------------- (Debug) ------------------------------
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; }; sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0); sim > char dud(...);
struct debug {
#ifndef ONLINE_JUDGE
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {ris << "(" << d.first << ", " << d.second << ")";}
sim dor(rge<c> d) {*this << "["; for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it; ris << "]";}
#else
sim dor(const c&) { ris; }
#endif
};
vector<char*> tokenizer(const char* args) {
	char *token = new char[111]; strcpy(token, args); token = strtok(token, ", ");
	vector<char*> v({token});
	while(token = strtok(NULL,", ")) v.push_back(token);
	return reverse(v.begin(), v.end()), v;
}
void debugg(vector<char*> args) { cerr << "\b\b "; }
template <typename Head, typename... Tail>
void debugg(vector<char*> args, Head H, Tail... T) {
	debug() << " [" << args.back() << ": " << H << "] ";
	args.pop_back(); debugg(args, T...);
}
#define harg(...) #__VA_ARGS__
#ifndef ONLINE_JUDGE
#define dbg(...) { debugg(tokenizer(harg(__VA_ARGS__, \b\t-->Line)), __VA_ARGS__, __LINE__); cerr << endl;}
#else
#define dbg(...) { }
#endif
/// -----------------------------------------------------------------------
 
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi; 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)    
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define print(x) cout << x << "\n";
#define REP(i,a,b) for(i=a;i<=b;i++)
#define RAP(i,a,b) for(i=a;i>=b;i--)
#define spa <<" "<<
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)x.size()
ll mod=1e9+7;
const int MX=0x3f3f3f3f;

int main(){
	int k;
	cin>>k;
	if(__gcd(k,10)>1){
		cout<<-1;
		return 0;
	}
	if(k%7==0) k/=7;
	int num=1,ans=1;
	num=num%k;
	while(num!=0){
		ans++;
		num=num*10+1;
		num%=k;
	}
	cout<<ans;	
 	return 0;
}

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

int main() {
    int N,i,j,k,l,m;
    string S,t,ds="";
    set<string> ps;
    set<char> pd;
    cin >> N >> S;

    for(i=0; i<N; i++)
        pd.insert(S.at(i));
    m = pd.size();

    for(auto x : pd)
        ds += x;
    
    for(i=0; i<m; i++)
        for(j=0; j<m; j++)
            for(k=0; k<m; k++) {
                int d1=-1,d2=-1,d3=-1;
                for(l=0; l<N; l++) {
                    if(d1==-1 && S.at(l)==ds.at(i))
                        d1 = l;
                    else if(d1!=-1 && d2==-1 && S.at(l)==ds.at(j))
                        d2 = l;
                    else if(d1!=-1 && d2!=-1 && d3==-1 && S.at(l)==ds.at(k)) {
                        d3 = l;
                        break;
                    }
                }
                if(d1!=-1 && d2!=-1 && d3!=-1) {
                    t = "";
                    t += S.at(d1);
                    t += S.at(d2);
                    t += S.at(d3);
                    ps.insert(t);
                }
            }
    
    cout << ps.size() << endl;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <math.h>
int main(void) {
	int a[4][3][10];
	int n,b,f,r,v;
	int i,j,k;
	int x;
	for( i = 0; i < 4; ++i ){
		for( j = 0; j < 3; ++j ) {
			for( k = 0; k < 10; ++k ) {
				a[i][j][k] = 0;
			}
		}
	}
	scanf("%d", &n );
	for( i = 0; i < n; ++i ) {
		scanf( "%d %d %d %d", &b, &f, &r, &v );
		x = a[b-1][f-1][r-1];
		a[b-1][f-1][r-1] = fmin(9,fmax(x+v,0));
	}

	
	for( i = 0; i < 4; ++i ){
		if( i > 0 ) {  
			printf("####################\n");
		}
		for( j = 0; j < 3; ++j ) {
			for( k = 0; k < 10; ++k ) {
				printf(" %d",a[i][j][k]);
			}
			putchar('\n');
		}
	}

	return 0;
}

Measured memory_bytes: 1044
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define MAX 100005
#define NIL -1

struct Node { int p, l, r;};

Node T[MAX];
int n, D[MAX];

void print(int u) {
    int i, c;
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    if (T[u].p == NIL) {
        cout << "root, ";
    }
    else if (T[u].l == NIL) {
        cout << "leaf, ";
    }
    else {
        cout << "internal node, ";
    }
    cout << "[";
    for (i = 0, c = T[u].l; c != NIL; i++, c = T[c].r) {
        if (i) {
            cout << ", ";
        }
        cout << c;
    }
    cout << "]" << endl;
}

int rec(int u, int p) {
    D[u] = p;
    if (T[u].r != NIL) {
        rec(T[u].r, p);
    }
    if (T[u].l != NIL) {
        rec(T[u].l, p + 1);
    }
}

int main() {
    int i, j, d, v, c, l, r;
    cin >> n;
    for (i = 0; i < n; i++) {
        T[i].p = T[i].l = T[i].r = NIL;
    }
    for (i = 0; i < n; i++) {
        cin >> v >> d;
        for (j = 0; j < d; j++) {
            cin >> c;
            if (j == 0) {
                T[v].l = c;
            }
            else {
                T[l].r = c;
            }
            l = c;
            T[c]. p = v;
        }
    }
    for (i = 0; i < n; i++) {
        if (T[i].p == NIL) {
            r = i;
        }
    }
    rec(r, 0);
    for (i = 0; i < n; i++) {
        print(i);
    }
    return 0;
}


Measured memory_bytes: 7744
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class T> istream& operator>>(istream& is,vector<T>& v) { for(T& t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream& os,const vector<T>& v) { rep(i,v.size())os<<v[i]<<(i==v.size()-1?"\n":" "); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

// Decomposition of Strongly Connected Components
class strongly_connected_comp {
    int n;
    vvi G,rG;
    vi ord,bel;
    vb used;
    void init() {
        rG.resize(n);
        rep(i,n) for(int j : G[i]) rG[j].pb(i);
        bel.resize(n);
        used.resize(n);
    }
    void dfs(int v) {
        used[v] = true;
        for(int u : G[v]) if(!used[u]) dfs(u);
        ord.pb(v);
    }
    void rdfs(int v,int k) {
        used[v] = true;
        bel[v] = k;
        for(int u : rG[v]) if(!used[u]) rdfs(u,k);
    }

public:
    // number of components
    int num;
    strongly_connected_comp(vvi G):G(G) {
        n = G.size();
        init();
        used.assign(n,false);
        rep(i,n) if(!used[i]) dfs(i);
        used.assign(n, false);
        int k = 0;
        rrep(i,n) if(!used[ord[i]]) rdfs(ord[i],k++);
        num = k;
    }
    // belonging components(topological order)
    int get(int i) { return bel[i]; }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int V,e;
    cin >> V >> e;
    vvi G(V);
    rep(_,e) {
        int s,t;
        cin >> s >> t;
        G[s].pb(t);
    }
    strongly_connected_comp sc(G);
    int q;
    cin >> q;
    rep(_,q) {
        int u,v;
        cin >> u >> v;
        cout << (sc.get(u) == sc.get(v)) << "\n";
    }
}



Measured memory_bytes: 5548
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
vector<pii> adj[100001];
bool color[100001];
void dfs (int cur, int par) {
  for (pii p : adj[cur]) if (p.first != par) {
    if (p.second % 2 == 0) color[p.first] = color[cur];
    else color[p.first] = !color[cur];
    dfs(p.first,cur);
  }
}
int main() {
  int n;scanf("%d",&n);
  for (int x = 0; x < n-1; x++) {
    int a,b,c;
    scanf ("%d %d %d",&a,&b,&c);
    adj[a].push_back({b,c});
    adj[b].push_back({a,c});
  }
  dfs(1,1);
  for (int x = 1; x <= n; x++) printf ("%d\n",color[x]);
  return 0;
}

Measured memory_bytes: 8064
#include<iostream>

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

	bool ok = false;
	int ans;
	std::string tmp, tmp1;
	for(int i = s.length() - 1; i > 0; i--){
		if(i % 2 != 0)continue;
		if(ok)break;

		tmp = "";
		for(int j = 0; j < i / 2; j++)tmp += s[j];

		tmp1 = "";
		for(int j = 0; j < i / 2; j++)tmp1 += s[j + i / 2];

		if(tmp == tmp1){
			ok = true;
			ans = i;
		}
	}
	std::cout << ans << std::endl;
}


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

int main(){

  int n; cin>>n;

  vector<int> l(n); vector<int> r(n);

  for(int i=0; i<n; i++){

    cin>>l.at(i)>>r.at(i);
  }

  vector<int> peo(n);

  int sum =0;

  for (int i=0; i<n; i++){

    peo.at(i) = r.at(i) - l.at(i) + 1;

    sum += peo.at(i);
    
  }

  cout<<sum<<endl;

  return 0;
  
}


Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int main()
{
    string s;
    cin >> s;
    if (s == "ABC")
    {
        cout << "ARC" << endl;
    }
    else
    {
        cout << "ABC" << endl;
    }
    return 0;
}

Measured memory_bytes: 3596
#include<bits/stdc++.h>                                                                                                   
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
     
#define pb push_back
#define PII pair<int,int>
     
#define VS vector<string>
#define VI vector<int>
#define ll long long int
#define debug(x) cout << x << " :" <<#x << endl 
int main(void) {
    int n;
    cin >> n;
    vector<int> d;
    int tmp;
    REP(i,n) {
        cin >> tmp;
        d.pb(tmp);
    }   
    int m;cin >> m;
    vector<int> t;
    REP(i,m) {
        cin >> tmp;
        t.pb(tmp);
    }   
    sort(d.begin(), d.end());
    sort(t.begin(), t.end());
    int i=0,j=0;
    while(1) {
        if(d[i] == t[j]) {
            i++;
            j++;
        } else if(d[i] < t[j]) {
            i++;
        } else {
            cout << "NO" << endl;
            break;
        }   
        if(j == m) {
            cout << "YES" << endl;
            break; 
        }
        if(i == n) {
            cout << "NO" << endl;
            break; 
        }   
    }
} 

Measured memory_bytes: 2548