akhauriyash/Code-Regression huggingface dataset:
<?php
$n = fgets(STDIN);

//$a*$b+$c=$n;
$count=0;
/*
for($c=1;$c<=$n-2;$c++){
    for($b=1;$b<=$n-2;$b++) {
        if( ($n-$c)%$b == 0){
            $count++;
        }
        if($n-$c < $b){
            break;
        }
    }
}
print $count;
*/
$amax = sqrt($n);
for($a=1;$a<$amax;$a++) {
    $bmax = $n/$a;
    for ($b = $a; $b < $bmax; $b++) {
        //print($n - $a*$b . "\n");
        if($a == $b){
            $result += 1;
        } else {
            $result += 2;
        }

    }
}
print $result;
?>

Measured memory_bytes: 16312
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    x, y = map(int, input().split())
    if y%2 == 1:
        print('No')
    elif 2*x-y//2 < 0 or  y//2 - x < 0:
        print('No')
    else:
        print('Yes')
        
    


if __name__ == '__main__':
    main()

Measured memory_bytes: 9192
#include<bits/stdc++.h>
#define ll 				long long
#define ld 				long double
#define fastio 			ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) 		cerr<<#x<<" "<<x<<endl
#define cina(a,n) 		for(ll i = 0;i<n;i++)	cin>>a[i];
#define couta(a,n) 		for(ll i = 0;i<n;i++) cout<<a[i]<<" ";
#define fauto(ar)		for(auto x : ar)	cout<<x<<" ";
#define mod 			1000000007
#define siz 			1005 
#define f 				first
#define s 				second
#define pb 				push_back
#define endl 			"\n"
#define ci 				cin.ignore()
using namespace std;
ll a[15][15],answ = 10000000LL;
void getans(ll ind,ll n,ll m,ll x)
{
	ll cans = 0,i = 0,j;
	ll vals[m];
	memset(vals,0,sizeof(vals));
	
	while(ind)
	{
		if(ind&1)
		{
			for(j = 0;j<m;j++)
			vals[j] += a[i][j];
			
			cans += a[i][m];
		}
		i++;
		ind >>= 1;
		
	}
//	cerr<<cans<<" "<<answ<<endl;
	bool v = 1;
	for(i = 0;i<m;i++)
	if(vals[i] < x)
	v = 0;
	if(v)
	answ = min(answ,cans);
}
int main()
{
	ll n,m,x,i,j,range,value;
	cin>>n>>m>>x;
	for(i = 0;i<n;i++)
	{
		cin>>a[i][m];
		for(j = 0;j<m;j++)
		cin>>a[i][j];
	}
	
	range = 1LL<<n;
	
	for(i = 1;i<range;i++)
	{
		getans(i,n,m,x);
	}
	
	if(answ != 10000000LL)
	cout<<answ;
	else
	cout<<"-1";

	
	
	
	
}

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

struct Problem {

    void Solve() {
        UL N; scanf("%d", &N);
        LL V; scanf("%lld", &V);
        LL A[4][1000]; rep(t, 4) rep(i, N) scanf("%lld", &A[t][i]);
        map<LL, LL> AB, CD;
        rep(i, N) rep(j, N) {
            AB[A[0][i] + A[1][j]]++;
            CD[A[2][i] + A[3][j]]++;
        }
        LL ans = 0;
        for (pair<LL, LL> i : AB) {
            auto j = CD.find(V - i.first);
            if (j == CD.end()) continue;
            ans += i.second * j->second;
        }
        printf("%lld\n", ans);
    }
};
int main() {
    unique_ptr<Problem> p(new Problem());
    p->Solve();
    return 0;
}



Measured memory_bytes: 128220
#include <bits/stdc++.h>
#define pb push_back
#define int long long
#define mp make_pair
#define inf 1000000007LL
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
vector< int > nex[214514];
map < pair<int,int> , int > mope;
int used[214514],act[214514];
signed main(){
	int r,c,n;
	cin>>r>>c>>n;
	vector<int> x,y,a;
	for(int i=0;i<n;i++){
		int tx,ty,ta;
		cin>>tx>>ty>>ta;
		x.pb(tx); y.pb(ty); a.pb(ta);
		nex[tx].pb( r+ty );
		nex[r+ty].pb( tx );
		mope[ mp(tx,r+ty) ] = ta;
		mope[ mp(r+ty,tx) ] = ta;
	}
	for(int i=1;i<=r+c;i++){
		act[i] = LINF;
	}
	for(int i=1;i<=r+c;i++){
		if( act[i] == LINF ){
			queue<int> que;
			vector<int> rk;
			act[i] = 0;
			que.push(i);
			rk.pb(i);
			while(!que.empty()){
				int cur = que.front();que.pop();
				for(int j=0;j<nex[cur].size();j++){
					int nx = nex[cur][j];
					//cout<<cur<<" "<<nx<<endl;
					int val = mope[mp(cur,nx)]-act[cur];
					if( act[nx] == LINF){
						act[nx] = val;
						que.push(nx);
						//cout<<nx<<" "<<val<<endl;
						rk.pb(nx);
					}
					else if( act[nx] != val ){
						cout<<"No"<<endl;
						return 0;
					}
				}
			}
			int mi1 = inf, mi2 = inf;
			for(int j=0;j<rk.size();j++){
				if( rk[j] <= r ){
					mi1 = min(mi1, act[ rk[j] ]);
				}
				else{
					mi2 = min(mi2, act[ rk[j] ]);
				}
			}
			if( mi1 + mi2 < 0 ){
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	cout<<"Yes"<<endl;
	return 0;
}

Measured memory_bytes: 29280
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+10;

int a[N],n;
int dp[N];

int main() {
	scanf("%d",&n);
	for (int i = 1; i <= n; i++) scanf("%d",&a[i]);
	dp[1] = 0, dp[2] = abs(a[1] - a[2]);
	for (int i = 3; i <= n; i++) dp[i] = min(dp[i-1]+abs(a[i-1] - a[i]), dp[i-2] + abs(a[i-2] - a[i]));
	printf("%d\n",dp[n]);
	return 0;
}

Measured memory_bytes: 1024
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy

def make_divisors(n):
    divisors = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            divisors.append(i)
            if i != n//i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

cnt = 0
n = int(input())
for i in range(1,n+1):
    if i%2 == 0:
        continue
    a = make_divisors(i)
    if len(a) == 8:
        cnt+=1
print(cnt)

Measured memory_bytes: 3420
#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int main()
{
	int a,b,x;
	double ans;
	double PI=atan(1.0)*4;
	cin>>a>>b>>x;
	if(x*2>a*a*b){
		double h=2.0*(a*a*b-x)/(a*a);
		ans=atan(h/a)*180/PI;
	}
	else{
		double h=2.0*(x)/(a*b);
		ans=90-atan(h/b)*180/PI;
	}
	printf("%.10f\n",ans);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i < (n); i++)
#define lower(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
using namespace std;
using ll = long long;
int INF = 1001001001;
using P = pair<int, int>;

int main() {
  int n, m;
  cin >> n >> m;
  vector<P> p(m);
  rep(i, m) {
    cin >> p[i].first >> p[i].second;
  }
  rep(x, 1000) {
    int dx = x / 10;
    vector<int> d(1, x%10);
    int keta = 1;
    while(dx) {
      keta++;
      d.push_back(dx%10);
      dx /= 10;
    }
    if(keta != n) continue;
    reverse(d.begin(), d.end());
    bool ok = true;
    rep(i, m) {
      if(d[p[i].first-1] != p[i].second) ok = false;
    }
    if(ok) {
      cout << x << endl;
      return 0;
    }
  }
  cout << -1 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <cmath>
#include <queue>
#include <tuple>
#include <set>
#include <assert.h>
#include <sstream>
#include <string>
//#include <bits/stdc++.h>
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i,i0,n) for(int (i)=(i0);(i)<(n);(i)++)
#define FORR(i,i0,n) for(int (i)=(n)-1; (i)>=(i0);(i)--)
#define SORT(x) sort(x.begin(),x.end())
#define SORTR(x) sort(x.begin(),x.end(),greater <>())
#define rn return
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
using namespace std;
using ll = long long;
typedef std::pair<int,int> P;
#include <boost/multiprecision/cpp_int.hpp>
 
using bint = boost::multiprecision::cpp_int;



int main(){
    int n; cin >> n; vector<int> a(n); rep(i,n) cin >> a[i];
    rep(i,n) a[i]-=(i+1);
    
    bint ans  = 0 ;
    SORT(a);
    int l = 0;
    int r = n - 1;
    while(r > l){
        ans += a[r]-a[l];
        l++;r--;
    }
    cout << ans;
}





Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  int m=x/100000000+(x/10000000)%10+(x/1000000)%10+(x/100000)%10+(x/10000)%10+(x/1000)%10+(x/100)%10+(x/10)%10+x%10;
  if(x%m==0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, AB, C):
    def s(C):
        ret = 0
        for a, b in AB:
            ret += min(C[a-1], C[b-1])
        return ret

    vc = Counter()
    g = defaultdict(list)
    for a, b in AB:
        vc[a] += 1
        vc[b] += 1
        g[a].append(b)
        g[b].append(a)
    v = sorted(list(vc.items()), key=lambda x: x[1])[0]
    C.sort()
    ans = [-1] * (N+1)
    ans[v[0]] = C.pop()

    q = deque([v[0]])
    while q:
        v = q.popleft()
        for u in g[v]:
            if ans[u] == -1:
                ans[u] = C.pop()
                q.append(u)
    ans = ans[1:]
    print(s(ans))
    print(' '.join(map(str, ans)))


def main():
    N = read_int()
    AB = [read_int_n() for _ in range(N-1)]
    C = read_int_n()
    (slv(N, AB, C))


if __name__ == '__main__':
    main()


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

using namespace std;
#define lint long long
#define P pair<int, int>

const lint mod = 1E9 + 7;

bool is_prime(int n){
    for(int i = 2; i <= sqrt(n); ++i){
        if(n % i == 0){
            return false;
        }
    }
    return true;
}

int main() {
    int N;
    cin >> N;
    
    map<int, int> fac;
    
    for(int i = 2; i <= N; ++i){
        int num = i;
        for(int j = 2; j <= i; ++j){
            if(is_prime(j)){
                while(num % j == 0){
                    num /= j;
                    fac[j]++;
                }
            }
        }
    }
    
    int num_2 = 0, num_4 = 0, num_14 = 0, num_24 = 0, num_74 = 0;
    
    for(auto e: fac){
        if(e.second >= 2){
            num_2++;
        }
        if(e.second >= 4){
            num_4++;
        }
        if(e.second >= 14){
            num_14++;
        }
        if(e.second >= 24){
            num_24++;
        }
        if(e.second >= 74){
            num_74++;
        }
    }
    
    
    lint ans =  (num_2 - 1) * num_24 + (num_4 - 1) * num_14 + (num_4) * (num_4 - 1) * (num_2 - 2) / 2 + num_74;
    
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
  int n, ans = 0; string s; cin >> n >> s;
  for(int i = 0; i <= 999; i++){
    int c[3] = {i/100, (i/10)%10, i % 10};
    int f = 0;
    for(int j = 0; j < n; j++){
      if(s[j] == ('0'+c[f]))f++;
      if(f == 3)break;
    }
    if(f == 3)ans++;
  }
  cout << ans << endl;
  system("pause");
}

Measured memory_bytes: 504
n,m=map(int,input().split())
xy=[[] for _ in range(n+1)]
for _ in range(m):
    x,y,z=map(int,input().split())
    xy[x].append(y)
    xy[y].append(x)

from collections import deque

visited=[0]*(n+1)
count=0

for i in range(1,n+1):
    if visited[i]==0:
        stack=deque()
        stack.append(i)
        visited[i]+=1
        while stack:
            a=stack.pop()
            for j in xy[a]:
                if visited[j]==0:
                    visited[j]+=1
                    stack.append(j)
        count+=1
print(count)


Measured memory_bytes: 28148
// AOJ 2039: Space Coconut Crab II
// 2017.11.6 bal4u@uu

#include <stdio.h>
#define TM 0
#if TM
#include <time.h>
#endif

#define MAX  30000
char tbl[MAX+1] = {1,1,0,0};		// zero: if prime
int p[3250] = {						// p[39] = 173 = sqrt(MAX), max sz = 3244
 2,   3,  5,  7, 11, 13, 17, 19, 23, 29, 
 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 
 73, 79, 83, 89, 97,101,103,107,109,113, 
127,131,137,139,149,151,157,163,167,173 }; int sz;

void mkprime()
{
	int i, j, k;
	for (i = 0; i <= 39; i++) {
		k = p[i];
		for (j = k<<1; j < MAX; j += k) tbl[j] = 1;
	}
	for (sz = 39, i = 173; i <= MAX; i += 2) if (!tbl[i]) p[sz++] = i;
}

int bsch(int x)
{
	int m, l = 0, r = sz;

    while (l < r) {
        m = (l + r) >> 1;
		if (p[m] == x) return m;
        if (p[m] < x) l = m + 1; else r = m;
    }
	return l-1;
}

int main()
{
	int t, i, j, k, m, n, ans;
#if TM
	clock_t start, end;
	start = clock();
#endif
	mkprime();
	while (scanf("%d", &t) && t > 0) {
		if (!(t & 1)) {
			k = (t>>1)-1;
			if (k > 2 && !(k & 1)) putchar('0');
			else                   putchar('1' - tbl[k]);
			putchar('\n');
		} else {
			ans = 0, m = t/3;
			for (i = 0; i <= m; i++) {
				n = bsch((t-p[i]) >> 1);
				for (j = i; j <= n; j++) {
					if ((k = p[i]+p[j]) >= t) continue;
					if ((k<<1) > t && !tbl[t-k] && t-k >= p[j]) ans++;
				}
			}
			printf("%d\n", ans);
		}
	}
#if TM
	end = clock();
	printf("time %lf\n", (double)(end-start)/CLOCKS_PER_SEC);
#endif
	return 0;
}

Measured memory_bytes: 1724
S = input()
cnt = 0
for i in range(len(S)):
  if i==0 and S[i]!="A":
    print("WA")
    exit()
  if 2<=i<=len(S)-2 and S[i]=="C":
    cnt+=1
    if cnt>1:
      print("WA")
      exit()
  if 1<=i<=len(S)-1:
    if S[i]!="C" and S[i].isupper():
      print("WA")
      exit()
if cnt<1:
  print("WA")
  exit()
print("AC")


Measured memory_bytes: 3064
#include <iostream>
#include <vector>
using namespace std;
int main() {
  int a,b;
  cin>>a>>b;
  int ans = 0;
  if(a>b){
    ans+=a;
    a--;
  }else{
    ans+=b;
    b--;
  }
  if(a>b){
    ans+=a;
    a--;
  }else{
    ans+=b;
    b--;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>

int main(void)
{
  int a, b, c;

  scanf("%d %d %d", &a, &b, &c);

  int weeks = c / (7 * a + b);
  int rem = c % (7 * a + b);
  int remm;

  if (7 * a < rem)
  {
    remm = 7;
  }
  else if (rem % a == 0)
  {
    remm = rem / a;
  }
  else
  {
    remm = rem / a + 1;
  }

  printf("%d\n", weeks * 7 + remm);

  return 0;
}


Measured memory_bytes: 2100
#include <cstdio>
#include <algorithm>
using namespace std;
int N, W, maxW;
int w[1001], v[1001];
int dp[1001][1001];
int c;

void solve() {
    for (int i = 0; i <= W; i++) dp[N][i] = 0;
    for (int i = 0; i < N; i++) dp[i][0] = 0;

    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j <= W; j++) {
            if (j < w[i]) dp[i][j] = dp[i+1][j];
            else dp[i][j] = max(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
        }
    }
    maxW = W;
    for (int i = N - 1; i >= 0; i--) {
        for (int j = 0; j <= W; j++) if (dp[i][j] == dp[0][W]) maxW = min(maxW, j);

    }
    printf("Case %d:\n", c);
    printf("%d\n%d\n", dp[0][W], maxW);
}

int main()
{
    c = 1;
    for (; ;) {
        scanf("%d", &W);
        if (W == 0) break;
        scanf("%d", &N);
        for (int i = 0; i < N; i++) scanf("%d,%d", &v[i], &w[i]);
        solve();
        c++;
    }
    return 0;
}



Measured memory_bytes: 6504
using System;
using System.Collections.Generic;

class Program {
    static int Main(string[] args) {
        List<int[]> list = new List<int[]>();

        while (true) {
            string v = Console.ReadLine();

            int a = int.Parse(v.Split(' ')[0]);
            int b = int.Parse(v.Split(' ')[1]);
            if ((a == 0) && (b == 0)) { break; }

            list.Add(new int[] { a, b });
        }

        for (int i = 0; i < list.Count; i++) {
            Console.WriteLine(string.Format("{0} {1}", Math.Min(list[i][0], list[i][1]),  Math.Max(list[i][0], list[i][1])));
        }

        return 0;
    }
}

Measured memory_bytes: 9732
#include <bits/stdc++.h>
#define int long long
#define pii pair<int,int>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(c) (c).begin(),(c).end()
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template< typename T, typename V > typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) { t = v; }
template< typename T, typename V > typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e, v); }
const int MOD = 1000000007;
const int INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int N,K;
  cin >> N >> K;
  if (K == 0) {
    cout << N*N << endl;
    return 0;
  }
  int sub = N*K;
  for (int p = K+1; p <= N; p++) {
    sub += K*((N+1)/p)+min(K,(N+1)%p)-1;
  }
  cout << N*N-sub << endl;

  return 0;
}

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

import math

# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=1000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
x=callIsPrime(55555)
v=[]
for i in range(len(x)):
    if x[i]%5==1:
        v.append(x[i])
        if len(v)==n:
            break
print(*v)

Measured memory_bytes: 41068
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
using namespace std;
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; }
typedef long long ll;
const int INF = 1e9;
const ll mod = 1000000007;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a * b / gcd(a, b);}

ll pow_kai(ll a, ll n) {
    ll x = 1;
    while(n > 0) {
        if(n&1) {
            x = x*a;
        }
        a = a*a;
        n >>= 1;
    }
    return x;
}


int main() {
    int n,m,p;
    string s;
    vector<bool> judge(1000010,false);
    vector<int> wa(1000010);
    vector<int> _wa(1000010);
    vector<int> ac(1000010);
    cin >> n >> m;
    int wwa = 0;
    rep(i,m) {
        cin >> p >> s;
        if (judge[p]==false) {
            if (s == "WA") {
                _wa[p]++;
            } else {
                ac[p]++;
                wa[p] = _wa[p];
                judge[p] = true;
            }
        }
    }
    int a = 0;
    int w = 0;
    for(int i=1; i<=n; ++i) {
        a += ac[i];
        w += wa[i];
    }
    cout << a << " " << w << "\n";
}


Measured memory_bytes: 12032
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    long long X;
    cin >> X;
    long long res = 0;
    res += (X / 500) * 1000;
    X %= 500;
    res += (X / 5) * 5;
    cout << res << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> sc(M);
  for (int i = 0; i < M; i++) cin >> sc[i].first >> sc[i].second;
  int res = -1;
  vector<int> aa = {0, 10, 100, 1000};
  for (int i = aa[N-1]; i < aa[N]; i++) {
    string tmp = to_string(i);
    bool can = true;
    for (int j = 0; j < M; j++) {
      if (tmp[sc[j].first-1] != sc[j].second) {
          can = false;
      }
    }
    if (can) {
      res = i;
      break;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
from operator import itemgetter
# gcd
from fractions import gcd
# 切り上げ，切り捨て
from math import ceil, floor
# リストの真のコピー（変更が伝播しない）
from copy import deepcopy
# 累積和。list(accumulate(A))としてAの累積和
from itertools import accumulate
# l = ['a', 'b', 'b', 'c', 'b', 'a', 'c', 'c', 'b', 'c', 'b', 'a']
# S = Counter(l)  # カウンタークラスが作られる。S=Counter({'b': 5, 'c': 4, 'a': 3})
# print(S.most_common(2))  # [('b', 5), ('c', 4)]
# print(S.keys())  # dict_keys(['a', 'b', 'c'])
# print(S.values())  # dict_values([3, 5, 4])
# print(S.items())  # dict_items([('a', 3), ('b', 5), ('c', 4)])
from collections import Counter
import math
from functools import reduce
# input関係の定義
# fin = open('in_4.txt', 'r')
# sys.stdin = fin
#
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
# template


YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(S: str):
    lisS = sorted(S)
    if lisS[0] == lisS[1] and lisS[2] == lisS[3] and lisS[1] != lisS[2]:
        print(YES)
    else:
        print(NO)
    return


def main():

    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    solve(S)


if __name__ == '__main__':
    main()


Measured memory_bytes: 66156
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
int main()
{
	int i,j,k,n,m,x,y;
	scanf("%d%d",&n,&m);
	x=1;
	for(i=1;i*i<=m;i++)
	{
		if(m%i==0)
		{
			if(m/i>=n)
			{
				x=max(x,i);
			}
			if(i>=n)
			{
				x=max(x,m/i);
			}
		}
	}
	printf("%d",x);
	return 0;
}

Measured memory_bytes: 256
#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--)

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long double lb;

const int INF=1<<27;
const int MOD=(int)1e9+7;

int main(void)
{
    string s;
    cin >> s;
    s[3] = '8';
    cout << s << endl;
    return 0;
}



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

int main() {
    int n, m;
    cin >> n >> m;
    vector<pair<ll, ll> > ab(n);
    for(int i=0; i<n; i++){
        cin >> ab[i].first >> ab[i].second;
    }

    sort(ab.begin(), ab.end());

    ll sum = 0;
    ll count = 0;
    for(int i=0; i<m; i++){
        if(count+ab[i].second < m){
            sum += ab[i].first * ab[i].second;
            count += ab[i].second;
        }else{
            sum += (ab[i].first) * (m-count);
            count += m-count;
        }

        if(count == m){
            cout << sum << endl;
            return 0;
        }
    }  

    return 0;
}

Measured memory_bytes: 1792
import std.stdio;
import std.array;
import std.conv;
import std.string;
import std.algorithm;
import std.typecons;

long k, a, b;

void main() {
  readf("%d %d %d", &k, &a, &b);
  if (b - a >= 2) {
    k -= a - 1;
    long x = a + (b - a) * (k / 2) + (k % 2);
    writeln(x);
  }
  else  {
    writeln(1 + k);
  }   
}


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

int n;
int a[4];

// 問題文のa,b,c,dをa[0],a[1],a[2],a[3]とする
// kが4なら、a[0]+a[1]+a[2]+a[3]==nかどうかを調べて
// 満たしていたら1を返す。そうでなければ0。
// もしkが3以下ならa[k]を0から9まで調べてsaiki(k+1)を呼び出す。
// それらから返ってくる値の合計が、
// a[k-1]までを固定し、a[k]以降を0から9まで動かした時の
// 場合の数となるので、これをreturnする。
int saiki(int k){
	if(k==4){
		if(a[0]+a[1]+a[2]+a[3]==n){
			return 1;
		}else{
			return 0;
		}
	}else{
		int sum = 0;
		for(int i=0; i<10; i++){
			a[k] = i;
			sum += saiki(k+1);
		}
		return sum;
	}
}

int main(){
	for(;;){
		if(cin >> n){  // 入力が終わったらelse側にまわる
			cout << saiki(0) << endl;
		}else{
			break;
		}
	}

	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
int main()
{
	lli r,c;
	cin>>r>>c;
	char mat[r][c];
	for(lli i=0;i<r;i++)
	{
		for(lli j=0;j<c;j++)
		{
			cin>>mat[i][j];
		}
	}
	
	long long int dp[r][c];
	for(lli i=0;i<r;i++)
	{
		for(lli j=0;j<c;j++)
		{
			if(mat[i][j]=='.')	dp[i][j]=0;
			else	dp[i][j]=-1;
		}
	}
	dp[0][0]=1;
	//first row
	for(lli i=1;i<c;i++)
	{
		if(dp[0][i]==0)	dp[0][i]=1LL;
		else	break;
	}
	
	//first column
	for(lli i=1;i<r;i++)
	{
		if(dp[i][0]==0)	dp[i][0]=1;
		else	break;
	}
	
	for(lli i=1;i<r;i++)
	{
		for(lli j=1;j<c;j++)
		{
			if(dp[i][j]==-1)	continue;
			
			if(dp[i-1][j]>0)	dp[i][j]=(dp[i][j]%mod + dp[i-1][j]%mod)%mod;
			if(dp[i][j-1]>0)	dp[i][j]=(dp[i][j]%mod +dp[i][j-1]%mod)%mod;
		}
	}
	cout<<dp[r-1][c-1];
	return 0;
}

Measured memory_bytes: 9088
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int min = sc.nextInt();
		int max = sc.nextInt();

		for (int i = 2; i < M + 1; i++) {
			int Li = sc.nextInt();
			int Ri = sc.nextInt();

			if (max < Li) {
				System.out.println(0);
				return;
			}

			if (min < Li) {
				min = Li;
			}

			if (max > Ri) {
				max = Ri;
			}
		}

		System.out.println(max - min + 1);
	}
}

Measured memory_bytes: 62788
package main

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

func main() {
  input := Input{bufio.NewReaderSize(os.Stdin,1000000)}
  l,n := input.NextInts()
  x := make([]int64,n)
  y := make([]int64,n)
  x2 := make([]int64,n+1)
  y2 := make([]int64,n+1)
  for i:=0;i<n;i++ {
    x[i] = input.NextInt()
    y[n-1-i] = l-x[i]
  }
  for i:=0;i<n;i++ {
    x2[i+1] = x2[i]+2*x[i]
    y2[i+1] = y2[i]+2*y[i]
  }
  m := max64(x[n-1],y[n-1])
  for i:=n-1;i>0;i-- {
    j := n-i
    m = max64(m,x2[i-1]-x2[max32(i-j-1,0)]+y2[j]-y2[max32(j-i,0)]+x[i-1])
    m = max64(m,x2[i]-x2[max32(i-j,0)]+y2[j-1]-y2[max32(j-i-1,0)]+y[j-1])
  }
  fmt.Println(m)
}
func max32(n,m int) int {
  if n > m { return n }
  return m
}
func max64(n,m int64) int64 {
  if n > m { return n }
  return m
}

type Input struct {
  reader *bufio.Reader
}
func(i *Input) NextLine() string {
  var buffer []byte
  for {
    line,isPrefix,err := i.reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer,line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func(i *Input) NextInt() int64 {
  n,_ := strconv.ParseInt(i.NextLine(),10,64)
  return n
}
func(i *Input) NextInts() (int64,int) {
  s := strings.Split(i.NextLine()," ")
  x,_ := strconv.ParseInt(s[0],10,64)
  y,_ := strconv.Atoi(s[1])
  return x,y
}

Measured memory_bytes: 14080
import java.util.*;
import java.util.stream.IntStream;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        List<Integer> s,c;
        s = new ArrayList<>();
        c = new ArrayList<>();
        for(int i=0;i<M;i++) {
            s.add(sc.nextInt());
            c.add(sc.nextInt());
        }
        int res;
        if(N == 1){
            res = IntStream.range(0, pow10(N)).filter(a ->
                    {
                        for (int i = 0; i < M; i++) {
                            if (getKeta(N - s.get(i) + 1, a) != c.get(i)) {
                                return false;
                            }
                        }
                        return true;
                    }
            ).findFirst().orElseGet(() -> -1);
        }else {
            res = IntStream.range(pow10(N - 1), pow10(N)).filter(a ->
                    {
                        for (int i = 0; i < M; i++) {
                            if (getKeta(N - s.get(i) + 1, a) != c.get(i)) {
                                return false;
                            }
                        }
                        return true;
                    }
            ).findFirst().orElseGet(() -> -1);
        }
        System.out.println(res);
    }

    private static int getKeta(int k, int val){
        return (val / pow10(k-1)) % 10;
    }

    private static int pow10(int k){
        if(k == 0){return 1;}
        return pow10(k-1) * 10;
    }

}


Measured memory_bytes: 29012
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <map>
#include <set>
#include <cstring>
#include <string>
#include <cctype>
#include <cassert>
#include <queue>

using namespace std;

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)
#define INF (1001001001)
#define EPS (1e-15)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define pra(x,n) rep(__i,n) pri(x,__i);
#define prar(x,b,e) repr(__i,b,e) pri(x,__i);

typedef long long ll;
typedef pair<int, int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;

ll MOD = 1000000007;

int in() {
	int a;
	scanf("%d ", &a);
	return a;
}

int main() {
	string s;
	cin >> s;
	string xigai = s;
	xigai.erase(remove(xigai.begin(), xigai.end(), 'x'), xigai.end());
	bool ok = true;
	rep(i,xigai.size()) {
		if (xigai[i] != xigai[xigai.size() - 1 - i]) {
			ok = false;
			break;
		}
	}
	if (! ok) {
		cout << -1 << endl;
		return 0;
	}
	int head = 0, tail = s.size() - 1;
	int ans = 0;
	while (head < tail) {
		int n = 0, m = 0;
		while (s[head] == 'x') n++, head++;
		while (s[tail] == 'x') m++, tail--;
		ans += abs(n - m);
		head++;
		tail--;
	}
	
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 512
w,h,n=map(int, input().split());
x,y=0,0
for i in '1'*n:
	a,b,c=map(int, input().split())
	if c==1:x=max(x,a)
	elif c==2:w=min(w,a)
	elif c==3:y=max(y,b)
	else: h=min(h,b)
print((max(w-x,0))*(max(h-y,0)))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	int n;
	cin >> n;
	ll a[n];
	ll ans = 0;
	int cnt = 0;
	REP(i, n){
		cin >> a[i];
		if (a[i] < 0) cnt++;
	}

	if (cnt % 2 == 0){
		REP(i, n) ans += (a[i] > 0 ? a[i] : -a[i]);
	}
	else {
		REP(i, n) ans += (a[i] > 0 ? a[i] : -a[i]);
		ll minn = abs(a[0]);
		REP(i, n) minn = min(abs(a[i]), minn);

		ans -= 2 * minn;
	}

	cout << ans << endl;


}


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


int prime[1000001]={};

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

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
  




int main()
{
   //pr();
  int t;
   //cin>>t;
   t=1;

  while(t--)
{

   int x,y,z;
   cin>>x>>y>>z;
  cout<<z<<" "<<x<<" "<<y;
   
}




return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    string s,t;cin>>s>>t;
    REP(i,s.size()){
        cout << s[i];
        if(i<t.size()) cout << t[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long a[n];
  long long sum = 1;
  for (int i = 0; i < n; i++)
  {
    cin >> a[i];
    if (a[i] == 0) {
      cout << "0" << endl;
      return 0;
    }
  }
  for (int i = 0; i < n; i++)
  {
    if (a[i] <= 1000000000000000000/sum) {
      sum *= a[i];
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }

  cout << sum << endl;
}

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std ;
const int Mod = 1000000007 ;
const int MaxN = 100 + 10 ;
const int MaxM = 1000000 + 10 ;
int N , M , K , Dp[2][MaxM] , Len[MaxM] , Max[MaxM] , Bit ;
map<int,int> Map ;
int main() {
	scanf( "%d%d" , &M , &N ) ;
	for(register int L = 1 , R ; L <= M ; L = R + 1 ) {
		R = M / ( M / L ) ;
		Map[R] = ++K ;
		Len[K] = R - L + 1 ;
		Max[K] = R ;
	}
	for(register int i = 0 ; ++i <= K ; )
		Dp[0][i] = 1 ;
	while( N-- ) {
		Bit ^= 1 ;
		for(register int i = 0 ; ++i <= K ; ) {
			assert( Map[M/Max[i]] ) ;
			Dp[Bit][i] = ( Dp[Bit][i-1] + 1ll * Len[i] * Dp[Bit^1][Map[M/Max[i]]] % Mod ) % Mod ;
		}
	}
	return not printf( "%d\n" , Dp[Bit][K] ) ;
}

Measured memory_bytes: 11648
#include <bits/stdc++.h>
#include <limits>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
#define fi(i, n) for( int i=0 ; i<n ; i++ )
#define f(i, a, b) for( int i=a ; i<b ; i++ )
#define vi vector<int>
#define pb push_back
#define mod 1000000007
int gcd(int a, int b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
ll fact(ll n)
{
    ll ans = 1e14;
    for(ll i = 1; i<=sqrt(n); i++)
    {
        if(n%i==0)
        {
            ll sol = (i - 1) + (n/i - 1);
            ans = min(ans,sol);
        }
    }
    return ans;
}
int visited[200000] = {0};
vector<vector<int> > v(200000);
int dfs(int x)
{
    int ans = 0;
    if(visited[x]==0)
    {
        visited[x] = 1;
        ans++;
        int a = v[x].size();
        for(int j = 0; j<a; j++)
        {
            int data = v[x][j];
            ans = ans + dfs(data);
        }
    }
    return ans;
}
void primefactors(int n)
{
    for (int i = 3; i <= sqrt(n); i = i + 2)
    {
        // While i divides n, print i and divide n
        while (n % i == 0)
        {
            cout << i << " ";
            n = n/i;
        }
    }

    // This condition is to handle the case when n
    // is a prime number greater than 2
    if (n > 2)
        cout << n << " ";

}
double fib(int n)
{
    double sol1,sol2;
    sol1 = (1 + sqrt(5))/2;
    sol2 = (1 - sqrt(5))/2;
    sol1 = pow(sol1,n);
    sol2 = pow(sol2,n);
    double ans = sol1 - sol2;
    ans = ans/sqrt(5);
    //ans = int(ans);
    return ans;
}

ll digits(ll n)
{
    return floor(log10(double(n))) + 1;
}

ll index(ll n)
{
    n = double(n);
    double sol = n*n + n;
    sol = sol*2 + 1;
    double ans = -1 + sqrt(sol);
    ans = ans/2;
    ans = ll(ans);
    return ans;
}
int main()
{
    ll n;
    cin>>n;
    if(n==1 || n==2)
    {
        cout<<"0";
        return 0;
    }
    else if(n==3 || n ==4)
    {
        cout<<"1";
        return 0;
    }
    ll dp[n + 1];
    dp[3] = 1;
    dp[4] = 1;
    for(int i = 5;i<=n;i++)
    {
        dp[i] = 1;
        for(int j = 3;j<=i - 3;j++)
        {
            dp[i] = (dp[i]%mod + dp[j]%mod)%mod;
        }
    }
    cout<<dp[n];


}


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

const int MOD = 1e9+7;
int add(int a, int b){return ((ll)a + (ll)b)%MOD;}
int mul(int a, int b){return ((ll)a * (ll)b)%MOD;}

void solve(){
    int k, a, b;
    cin >> k >> a >> b;
    for(int i = a; i <= b; i++){
        if(i%k == 0){
            cout << "OK" << '\n';
            return;
        }
    }
    cout << "NG" << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}


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

#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a)-1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a)-1; (i) >= (b); (i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<< C <<endl;
#define VI vector <int>
#define VII vector <VI>
#define VL vector <LL>
#define VLL vector <VL>
#define VD vector <double>
#define VDD vector <VD>
#define PII pair <int, int>
#define PDD pair <double, double>
#define PLL pair <LL, LL>
#define VPII vector <PII>
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a, b) for (auto &&a:b)
#define FIND(s, e) (s.find(e) != s.end())
#define EB emplace_back

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9;
const int MOD = INF+7;
const LL LLINF = 1e18;

int main(void) {
    int a;
    set<int> s;
    REP(i, 3) {
        cin >> a;
        s.insert(a);
    }
    cout << s.size() << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;


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

int main(void) {
    int k, i, j, l;
    ll ans = 0;

    cin >> k;

    for (i = 1; i <= k; i++) for (j = 1; j <= k; j++) for (l = 1; l <= k; l++) {
        ans += gcd(gcd(i, j), l);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3676
import qualified Data.ByteString.Char8 as B
import Data.Char
import Control.Monad
readInput :: Read a => IO [a]
readInput = map read . words <$> getLine

main = do
    [n, m] <- readInput
    constraints <- replicateM m readInput
    case [ i | i <- [0..999]
        , let str = B.pack $ show (i :: Int)
        , B.length str == n
        , all (\[s, c] -> str `B.index` pred s == intToDigit c) constraints
        ] of
            [] -> print (-1)
            i : _ -> print i

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

int main(){
  int A,B,C,K;
  cin>>A>>B>>C>>K;
  
  int count=0;
  if(K>=A){
  for(int i=0; i<A; i++){
    count++;}
  }
  else{ 
    for(int i=0; i<K; i++){
    count++;}
  }
  int S=K-A-B;
  if(S>=0){
    for(int i=0; i<S; i++){
      count--;}
  }
  
  cout<<count<<endl;
    

}

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

std::string balanced_ternary(int n) {
  std::string bt;
  while(n) {
    bt += "0+-"[n % 3];
    n /= 3;
    if(bt.back() == '-') ++n;
  }
  std::reverse(std::begin(bt), std::end(bt));
  return bt;
}

int main() {
  int w;
  cin >> w;
  cout << balanced_ternary(w) << endl;
}

Measured memory_bytes: 3192
h, w = map(int, input().split())
a = [list(input()) for _ in range(h)]

# 行を削除
for i in range(h-1, -1, -1):
    if '#' not in a[i]:
        del a[i]

# 列を削除
h = len(a)
for i in range(w-1, -1, -1):
    res = True
    for j in range(h):
        if a[j][i] == '#':
            res = False
    if res:
        for j in range(h):
            del a[j][i]
for i in range(len(a)):
    print("".join(a[i]))

Measured memory_bytes: 3064
import sys
K = input()
if K[-1] == '2' or K[-1] == '4' or K[-1] == '5' or K[-1] == '6' or K[-1] == '8' or K[-1] == '0':
    print(-1)
    sys.exit()
K = int(K)
n = 7 % K
i = 1
while i <= K:
    if n == 0:
        print(i)
        sys.exit()
    n = 10 * n + 7
    n %= K
    i += 1
print(-1)

Measured memory_bytes: 9144
//2017-10-11
//miaomiao
//
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
#define For(i, a, b) for(int i = (a); i <= (int)(b); ++i)
#define N (100000+5)

bool had[N];
int tot[N];

int main(){
	int n, m, x, y;
	scanf("%d%d", &n, &m);

	had[1] = true;
	For(i, 1, n) tot[i] = 1;

	while(m--){
		scanf("%d%d", &x, &y);
		
		--tot[x]; ++tot[y];
		if(had[x]) had[y] = true;
		if(!tot[x]) had[x] = false;
	}

	int ans = 0;
	For(i, 1, n) ans += had[i]; 
	printf("%d\n", ans);

	return 0;
}

Measured memory_bytes: 768
#include <vector>
#include <iostream>
#include <string>
#include <math.h>
#include <algorithm>


using namespace std;


int main(void){
  
  int N,M,min;
  vector<int> X;
  
  cin >> N;

  for(int i = 0; i < N; i++){
    int tmp;
    cin >> tmp;
    X.push_back(tmp);
  }
  
  min = 0;
  for(int i = 0; i < N; i++){
    min += (X.at(i) - 1)*(X.at(i) - 1); 
  }

 for(int j = 2; j <= 100; j++){
   int tmp = 0;
 for(int i = 0; i < N; i++){
    tmp += (X.at(i) - j)*(X.at(i) - j); 
    
  }
  if(tmp < min) min = tmp;
}

  cout << min << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int data[4][3][10] = {};

	int b, f, r, v;
	for(int i = 0; i < n; ++i){
		cin >> b >> f >> r >> v;
		data[b-1][f-1][r-1] += v;
	}

	for(int i = 0; i < 4; ++i){
		for(int j = 0; j < 3; ++j){
			for(int k = 0; k < 10; ++k){
				cout << " " << data[i][j][k];
			}
			cout << "\n";
		}
		if( i != 3 )
			cout << "####################\n";
	}
	return 0;
}

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

int main() {
  int A, B;
  string op;
  cin >> A >> op >> B;
  
  if (op == "+"){
    cout << A + B << endl;
  }
  else if (op == "-"){
    cout << A - B << endl;
  }
    
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define collect(arr, size) rep(i,size) cin >> arr[i];
#define int long long

signed main(){
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> a(A), b(B), m(M);
    collect(a, A); collect(b, B);
    int minimum = INT_MAX;
    rep(i,M){
        int x,y,c;
        cin >> x >> y >> c;
        x--; y--;
        minimum = min(minimum, a[x]+b[y]-c);
    }
    sort(all(a)); sort(all(b));
    minimum = min(a[0]+b[0],minimum);
    cout << minimum << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
ll power(ll x, ll y, ll p)
{ll res = 1;x = x % p;while (y > 0){if (y & 1) res = (res*x) % p;y = y>>1;x = (x*x) % p;}return res;}
ll modInverse(ll n, ll p)
{return power(n, p-2, p);}
ll nCr(ll n, ll r, ll p)
{if (r==0) return 1;ll fac[n+1];fac[0] = 1;for(ll i=1 ; i<=n; i++)fac[i] = fac[i-1]*i%p;return (fac[n]*modInverse(fac[r], p) % p * modInverse(fac[n-r], p) % p) % p;}
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll i, j, k, n, m, t, p=1e9+7, temp, flag, x, y, z, count, a, b, c, d;
	cin >> n;
	ll arr[n], suf[n];
	count=0;
	ll ans=0;
	for(i=0; i<n; i++)
	{
		cin >> arr[i];
		count+=arr[i];
	}
	//cout << count << endl;
	suf[0]=count-arr[0];
	for(i=1; i<n; i++)
	{
		suf[i]=suf[i-1]-arr[i];
	}
	//cout << suf[n-1] << endl;
	for(i=0; i<n; i++)
	{
		ans += (((arr[i]%p)*(suf[i]%p))%p);
		ans%=p;
	}
	cout << ans%p << endl;
	return 0;
}


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

using namespace std;

static constexpr int64_t mod = INT64_C(1000000007);

int64_t solve(const std::string& s) {
  std::array<int, 26> counts{};
  for (auto const c : s) {
    counts[c - 'a']++;
  }
  int64_t ret = 1;
  for (auto const count : counts) {
    ret *= (count + 1);
    ret %= mod;
  }
  ret--;
  return ret;
}

int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n;
  std::string s;
  std::cin >> n >> s;
  std::cout << solve(s) << std::endl;
  return 0;
}

Measured memory_bytes: 512