akhauriyash/Code-Regression huggingface dataset:
n = int(input())
s = input()

r = 0
g = 0
b = 0

for c in s:
    if c == "R":
        r += 1
    elif c == "G":
        g += 1
    else:
        b += 1

all_patterns = r * g * b
sub = 0

for i in range(n):
    for j in range(i+1, n):
        if s[i] == s[j]: continue
        k = j * 2 - i
        if k >= n or s[k] == s[i] or s[k] == s[j]: continue
        sub += 1
print(all_patterns-sub)





Measured memory_bytes: 9108
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

string ans;

void solve(int a,int b,int c,int d,char A,char B){
	int len=(a+b)/(b+1),N=a+b;
	int l=0,r=a/len+1;
	while(r-l>1){
		int m=(l+r)>>1;
		if(len*m+(b-m)/len<=a){
			l=m;
		}else{
			r=m;
		}
	}
	int x=l,y=(b-x)/len;
	a-=len*x+y;
	for(int i=c;i<=d;i++){
		if(i<=x*(len+1)){
			ans+=(i%(len+1)?A:B);
		}else if(N-i+1<=y*(len+1)){
			ans+=((N-i+1)%(len+1)?B:A);
			//cerr<<a+b-i+1<<' '<<len+1<<endl;
		}else{
			ans+=(i<=x*(len+1)+a?A:B);
			//cerr<<x*(len+1)+a<<' '<<i<<' '<<len<<' '<<x<<' '<<a<<endl;
		}
	}
}

int main(){
	int q;
	scanf("%d",&q);
	while(q--){
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		ans="";
		if(a>b){
			solve(a,b,c,d,'A','B');
		}else if(a<b){
			solve(b,a,a+b-d+1,a+b-c+1,'B','A');
			reverse(ans.begin(),ans.end());
		}else{
			for(int i=c;i<=d;i++){
				ans+=(i%2?'A':'B');
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() 
{
    long long  a,b,n;
    cin>>a>>b>>n;
        if((b-1)>n)
        cout<<(floor((a*n)/b))-(a*floor(n/b));
        else
        cout<<(floor((a*(b-1))/b))-(a*floor((b-1)/b));

}

Measured memory_bytes: 3788
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

n = onem()

po = str(n)
co = 0
for i in po:
    co += int(i)
print("Yes" if n % co == 0 else "No")





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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int n;
    cin >> n;
    vi s(n), l(n), p(n);
    rep(i, n) cin >> s[i] >> l[i] >> p[i];
    int m;
    cin >> m;
    vi w(m);
    rep(i, m) cin >> w[i];
    int wsize = 0;
    rep(i, m) wsize = max(wsize, w[i]);
    vector<vi> dp(n+1, vi(wsize+1));
    rep(i, n) rep(j, wsize+1) {
        dp[i+1][j] = dp[i][j];
        if (j-s[i]>=0) {
            for (int k=s[i]; k<=l[i]&&j-k>=0; ++k) {
                dp[i+1][j] = max(dp[i+1][j], dp[i+1][j-k]+p[i]);
            }
        }
    }
    bool ok = true;
    vi ans(m);
    rep(i, m) {
        if (dp[n][w[i]] == 0) ok = false;
        else ans[i] = dp[n][w[i]];
    }
    if (ok) rep(i, m) cout << ans[i] << endl;
    else cout << -1 << endl;
    return 0;
}



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

struct Data {
  int A, B;
  Data(int A, int B) : A(A), B(B){}
  bool operator< (const Data& d) const {
    return A < d.A;
  } 
};

int main() {
  int N, M;
  cin >> N >> M;
  priority_queue<int> q;
  int A, B;
  vector<Data> d;
  for (int i = 0; i < N; i++) {
    cin >> A >> B;
    d.push_back(Data(A, B));
  }
  sort(d.begin(), d.end());
  int c = 0;
  int idx = 0;
  for (int i = 1; i <= M; i++) {
    while (idx < N && d[idx].A <= i) {
      q.push(d[idx].B);
      idx++;
    }
    if (!q.empty()) {
      c += q.top();
      q.pop();
    }
  }
  cout << c << "\n";
  return 0;
}

Measured memory_bytes: 1908
#include <stdio.h>
int main()
{
	int S, h, a, m, s;
	scanf("%d", &S);
	h = S / 3600;
	a = S % 3600;
	m = a / 60;
	s = a % 60;
	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 2756
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <cmath>
#include <cstdio>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define All(v) (v).begin(),(v).end()
typedef long long ll;

int main(){
    int X,Y;cin >> X >> Y;
    cout << X+Y/2 << endl;
    return 0;
}

Measured memory_bytes: 256
def prime_decomposition(n):
    i = 2
    table=[]
    while i*i<=n:
        count=0
        while n%i==0:
            n/= i
            count+=1
        table.append([int(i),count])
        i += 1
    if n > 1:
        table.append([int(n),1])
    return table
N,P=map(int,input().split())
ans=1
for A in prime_decomposition(P):
    if A[1]>=N:
        ans*=A[0]**int(A[1]/N)
print(ans)

Measured memory_bytes: 58788
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner input = new Scanner(System.in);
    int i = 1;
    for (int j = 1; j <= 5; j++) {
      if (input.nextInt() == 0) i = j;
    }
    System.out.println(i);
  }
}

Measured memory_bytes: 35516
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    int a[n][m] = {}, b[m] = {};
    for (int i = 0; i < n; ++i)
    {
        for (int j = 0; j < m; ++j)
        {
            cin >> a[i][j];
        }
    }
    for (int i = 0; i < m; ++i)
        cin >> b[i];
    
    for (int i = 0; i < n; ++i)
    {
        int sum = 0;
        for (int j = 0; j < m; ++j)
            sum += a[i][j] * b[j];
        cout << sum << endl;
    }
}



Measured memory_bytes: 3120
def solve():
    from heapq import heappop, heappush
    from sys import stdin
    f_i = stdin
    
    N, M, X = map(int, f_i.readline().split())
    H = [None] + [int(f_i.readline()) for i in range(N)]
    
    adj = [[] for i in range(N + 1)]
    for i in range(M):
        A, B, T = map(int, f_i.readline().split())
        adj[A].append((B, T))
        adj[B].append((A, T))
    
    hq = [(0, 1, X)] # element: (cost, tree number, height)
    unvisited = [True] * (N + 1)
    cost = [100000000000000] * (N + 1)
    
    # Dijkstra's algorithm with priority queue
    while hq:
        c1, n1, h1 = heappop(hq)
        
        if n1 == N:
            print(c1 + (H[N] - h1))
            break
        
        unvisited[n1] = False
        
        for n2, t2 in adj[n1]:
            if unvisited[n2]:
                h3 = h1 - t2
                if h3 < 0:
                    clb = -h3
                    c2 = c1 + clb + t2
                    if h1 + clb <= H[n1] and c2 < cost[n2]:
                        heappush(hq, (c2, n2, 0))
                        cost[n2] = c2
                elif h3 <= H[n2]:
                    c2 = c1 + t2
                    if c2 < cost[n2]:
                        heappush(hq, (c2, n2, h3))
                        cost[n2] = c2
                else:
                    h2 = H[n2]
                    fall = h3 - h2
                    c2 = c1 + fall + t2
                    if c2 < cost[n2]:
                        heappush(hq, (c2, n2, h2))
                        cost[n2] = c2
    else:
        print(-1)

solve()


Measured memory_bytes: 91596
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
using namespace std;
int main(void){
	int  A,B,C,D,E,ANS=0;
	cin>>A>>B>>C>>D>>E;
	if(A<0){
		ANS+=-A*C;
		A=0;
	}
	if(A==0){
		ANS+=D;
	}
	ANS+=(B-A)*E;
	cout<<ANS<<endl;
	return 0;
}


Measured memory_bytes: 3092
S = input()
n =len(S)
s = S.lower()


if S[0] != 'A':
  print('WA')
  exit()
else:
  for i in range(2, n-1):
    if S[i] != 'C':
      if S[i] != s[i]:
        print('WA')
        exit()
      
if S[n-1] != s[n-1] or S[1] != s[1]:
  print('WA')
  exit()
  
if S.count('C') != 1:
  print('WA')
  exit()
  
print('AC')

Measured memory_bytes: 8980
#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--)
typedef long long LL;
int N;
LL A[100001];
vector<LL>v;
bool check(LL x){
	LL now=0;
	REP(i,x+1){
		now+=v[i];
	}
	for(int i=x+1;i<N;i++){
		//cout<<now<<" "<<v[i]<<endl;
		if(now*2<v[i]){
			return false;
		}else{
			now+=v[i];
		}
	}
	return true;
}
LL binary_search(){
	LL lb=-1;
	LL ub=N;
	while(ub-lb>1){
		LL mid=(ub+lb)/2;
		if(check(mid)==true){
			ub=mid;
		}else{
			lb=mid;
		}
	}
	//cout<<ub<<" "<<lb<<endl;
	return N-1-lb;
}
int main(){
	cin>>N;
	REP(i,N){
		cin>>A[i];
		v.push_back(A[i]);
	}
	sort(v.begin(),v.end());
	//check(0);
	cout<<binary_search()<<endl;
}

Measured memory_bytes: 2040
#define _USE_MATH_DEFINES
#include <cmath>
#include <iostream>
#include <iomanip>
#include <limits>
#include <vector>
#include <algorithm>
#include <functional>

using ll = long long;

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
function <ll*(ll)> array = [=](ll x) {
	ll *array = new ll[x];
	return array;
};
function <ll**(ll,ll)> array2= [=](ll x, ll y) {
	ll **array = new ll*[x];
	rep(i, x)array[i] = new ll[y];
	return array;
};
int main() {
	int m, n;
	cin >> m>>n;
	ll **array = array2(m,n);
	rep(i, m)rep(j, n)cin >> array[i][j];
	ll *array2 = new ll[m];
	rep(j, n)cin >> array2[j];
	rep(i, m) {
		ll count = 0;
		rep(j, n)count += array[i][j] * array2[j];
		cout << count << "\n";
	}
}


Measured memory_bytes: 3132
#include<stdio.h>

int main() {
    int A, B, C, D;
    scanf("%d%d%d%d",&A,&B,&C,&D);
    
    int RemainA = A;
    int RemainC = C;
    while (1) {
        /*Takahasi attack*/
        RemainC -= B;
        if (RemainC <= 0) {
            printf("Yes\n");
            break;
        }
        /*Aoki's attack*/
        RemainA -= D;
        if (RemainA <= 0) {
            printf("No\n");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 1624
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int []a = new int [5];
		int ans = 0;
		
		for(int i = 0 ; i < 5 ;i++) {
			a[i] = Integer.parseInt(sc.next());
			if(a[i] == 0) {
				ans = i+1;
			}
		}
		System.out.println(ans);
		

	}
}


Measured memory_bytes: 35688
#include<bits/stdc++.h>
using namespace std;
typedef pair< int , int > Pi;

bool judge(int area){
  //式変形だね!!
  //area - y = (2y + 1)x
  //(area - y) % (2y + 1)
  for(int y = 1; y < min< int >(100000, area); y++){ 
    if((area - y) % (2 * y + 1) == 0) return true;
  }
  return false;
}

int main(){
  int N, room[100000];

  scanf("%d", &N);
  for(int i = 0; i < N; i++){
    scanf("%d", &room[i]);
  }
  int ret = 0;
  for(int i = 0; i < N; i++){
    ret += !judge(room[i]);
  }
  printf("%d\n", ret);
}

Measured memory_bytes: 1384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second 
#define inf (1<<30)

using namespace std;
typedef long long ll;
const int MAXN = 100005;
inline int readint()
{
	int res = 0, f = 1;
	char c = 0;
	while(!isdigit(c))
	{
		c = getchar();
		if(c=='-')
			f = -1;
	}
	while(isdigit(c))
		res = res*10+c-'0', c = getchar();
	return res*f;
}
int n,m,cnt,mina[MAXN];
pii a[MAXN],b[MAXN];
int pre[MAXN],suf[MAXN];
inline int inter(pii x, pii y)
{
	if(x.fi>y.fi)
		swap(x,y);
	return max(0,min(x.se,y.se)-y.fi+1);
}

int main()
{
	n = readint();
	for(int i = 1; i<=n; i++)
		a[i].fi = readint(), a[i].se = readint();
	if(n==2)
	{
		cout << a[2].se-a[2].fi+1+a[1].se-a[1].fi+1 << endl;
		return 0;
	}
	int maxl = 0, minr = inf;
	int p = 0, q = 0;
	for(int i = 1; i<=n; i++)
	{
		if(a[i].fi>maxl)
			maxl = a[i].fi, p = i;
		if(a[i].se<minr)
			minr = a[i].se, q = i;
	}
	int ans = 0;
	for(int i = 1; i<=n; i++)
		if(i!=p&&i!=q)
			ans = max(ans,a[i].se-a[i].fi+1);
	ans += inter(a[p],a[q]);
	for(int i = 1; i<=n; i++)
		b[i] = mp(max(a[i].se-a[p].fi+1,0),max(a[q].se-a[i].fi+1,0));
	sort(b+1,b+n+1);
	int lst = 1;
	for(int i = 1; i<=n; i++)
		if(i==n||b[i].fi!=b[i+1].fi)
			reverse(b+lst,b+i+1), lst = i+1;
	pre[0] = suf[n+1] = inf;
	for(int i = 1; i<=n; i++)
		pre[i] = min(pre[i-1],b[i].se);
	for(int i = n; i>=1; i--)
		suf[i] = min(suf[i+1],b[i].fi);
	for(int i = 1; i<n; i++)
		ans = max(ans,pre[i]+suf[i+1]); 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#define PB push_back
using namespace std;
int main(void)
{
  int vis[1024];
  int n,m;
  cin >> n >> m;
  for(int i=0;i<n+5;++i) vis[i]=i;
  for(int i=0;i<m;++i){
    int left,right;
    cin >> left >> right;
    if(vis[left]<right)
      vis[left]=right;
  }
  for(int i=0;i<n+5;++i){
    if(vis[i+1]<vis[i]) vis[i+1]=vis[i];
  }
  int answer=n+1;
  for(int pos=0;pos<=n;++pos){
    while(vis[pos]>pos){
      answer+=(vis[pos]-pos)*2;
      pos=vis[pos];
    }
  }
  cout << answer << endl;
  return 0;
}

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


public class Main {
	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		final long W = sc.nextLong();
		final long H = sc.nextLong();	
		final long x = sc.nextLong();
		final long y = sc.nextLong();
		final long r = sc.nextLong();
		
		if(x - r < 0 || x + r > W || y - r < 0 || y + r > H){
			System.out.println("No");
		}else{
			System.out.println("Yes");
		}
		
		
		
	}
	
}

Measured memory_bytes: 17356
#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=1e17+7;
const ll MOD=1000000007;




int main(){
    vector<ll> s;
    for(int i=2;i<2000;i++){
        bool j=true;
        for(int t=0;t<s.size() && j;t++){
            if(i%s[t]==0){j=false;}
        }
        if(j){s.push_back(i);}
    }
    vector<ll> count(s.size(),1);
    ll n;
    cin>>n;
    for(int i=2;i<=n;i++){
        ll m=i;
        for(int t=0;t<s.size();t++){
            while(m%s[t]==0){
                count[t]++;
                count[t]%=MOD;
                m/=s[t];
            }
        }
    }
    ll ans=1;
    for(int i=0;i<count.size();i++){
        ans*=count[i];
        ans%=MOD;
    }
    cout<<ans<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>

#include <cstdio>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

vector<pair<int, int> > adj[10000];
int cost[10000];
int done[10000];

void dijkstra()
{
	priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;
	pair<int, int> next;	/* first: cost, second: index */
	int index;

	cost[0] = 0;
	PQ.push(make_pair(0, 0));

	while (!PQ.empty()) {
		next = PQ.top();
		PQ.pop();

		index = next.second;

		if (done[index] == 1) continue;
		done[index] = 1;

		rep(i, adj[index].size()) {
			if ((done[adj[index][i].second] == 0)
				&& (cost[adj[index][i].second] > cost[index] + adj[index][i].first)) {
				cost[adj[index][i].second] = cost[index] + adj[index][i].first;
				PQ.push(make_pair(cost[adj[index][i].second], adj[index][i].second));
			}
		}
	}
}

int main()
{
	int n, u, k, v, c;


	cin >> n;
	rep(i, n) {
		cost[i] = 1000000001;
		done[i] = 0;
		cin >> u >> k;
		rep(j, k) {
			cin >> v >> c;
			adj[u].push_back(make_pair(c, v));
		}
	}

	dijkstra();

	rep(i, n) {
		cout << i << ' ' << cost[i] << endl;
	}

	return 0;
}



Measured memory_bytes: 8000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include <cstdlib>
#include <math.h>
#include<algorithm>
#include <map>
using namespace std;

int main(int argc,char** argv)
{

	int n,m,X,Y;
	cin >> n >> m >> X >> Y;

	int x[n],y[m];
	for(int i = 0; i < n; i++){
		cin >> x[i];
	}
	for(int i = 0; i < m; i++){
		cin >> y[i];
	}
	sort(x,x+n);
	sort(y,y+m);

	if(Y<=X){
		cout << "War"<<endl;
		return 0;
	}
	else if(y[0]<=X){
		cout << "War"<<endl;
		return 0;
	}
	else if(Y<=x[n-1]){
		cout << "War"<<endl;
		return 0;
	}
	else if(y[0]<=x[n-1]){
		cout << "War"<<endl;
		return 0;
	}

	cout << "No War"<<endl;

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

typedef pair<int, int> P;


int N,W;
int dp[10010];
vector<P> v;

/*
void input2(int n, vector<P> *rv){
    P tmp;
    cin >> tmp.first >> tmp.second;
    rv->push_back(tmp);
}
*/

int main(){
    cin >> N >> W;
    P tmp;
  	for(int i = 0; i < N; i++){
    	cin >> tmp.first >> tmp.second;
    	v.push_back(tmp);
    }
    //input2(N, v);

    for(int i = 0; i < N; i++){
        for(int j = 0; j <= W; j++){
            if(j+v[i].second <= W){
                dp[j+v[i].second] = max(dp[j+v[i].second], dp[j]+v[i].first);
            }
          	//cout << dp[j] << " ";
        }
      	//cout << "" << endl;
    }

    cout << dp[W] << endl;
}


Measured memory_bytes: 3136
#include<cstdio>
#include<algorithm>
#define LL long long
using namespace std;
const int p=1000000007;
int main()
{
	int n,m;
	LL ans=1;
	scanf("%d%d",&n,&m);
	if (n>m) swap(n,m);
	if (n==m)
	{
		for (int i=1;i<=n;i++) ans=ans*i%p;
		ans=ans*ans%p;
		ans=ans*2%p;
	}
	else if (n==m-1)
	{
		for (int i=1;i<=n;i++) ans=ans*i%p;
		ans=ans*ans%p;
		ans=ans*m%p;
	}
	else ans=0;
	printf("%lld\n",ans);
}

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

int main(){
    string s, t;
    int count = 0;
    cin >> s >> t;

    rep(i, (int)(s.length())){
        if(s.at(i) != t.at(i)) count++;
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3852
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m,x,sum=0;
	cin >> n >> m;
	for(int i=0;i<n;i++){
		cin >> x;
		if(x>=m){
			sum++;
		}
	}
	cout << sum << endl;
	return 0;
}

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


long long X,K,D;



int main(){

    cin >>X >> K >>D;

    long long tmp_cnt = 0;
 
    X = abs(X);

    //整数
    tmp_cnt = X/D;
    
    if(tmp_cnt >= K)
    {
        cout << abs(X-K*D);
        return 0;
    }else
    {
        long near_val = min(X-D*tmp_cnt, X -D*tmp_cnt - D) ;
        long next_near_val = max(X-D*tmp_cnt, X -D*tmp_cnt - D) ;
        long near_cnt = (X- near_val)/D;
        long rest_num = K- near_cnt;

        if(rest_num % 2 == 1)
        {
            cout << abs(next_near_val);
        }else
        {
            cout << abs(near_val);
        }
        
        return 0;

    }
    



    return  0;
}



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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

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

template<typename T>
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 U,typename... V>
typename enable_if<is_same<T, U>::value!=0>::type
fill_v(U &u,const V... v){u=U(v...);}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_v(U &u,const V... v){
    for(auto &e:u) fill_v<T>(e,v...);
}

double dis(double a, double b) {
    return sqrt((a+b)*(a+b)-(a-b)*(a-b));
}

int64 to_num(const string& s) {
    int64 res = 0;
    REP(i, s.size()) {
        if ('0' <= s[i] && s[i] <= '9') {
            res = (res << 4) + s[i]-'0';
        } else {
            res = (res << 4) + s[i] - 'a' + 10;
        }
    }
    return res;
}

string to_hex(int64 num) {
    string res = "";
    while(num) {
        int64 c = num%16;
        if (c <= 9) {
            res = string(1, '0' + c) + res;
        } else {
            res = string(1, 'a' + c - 10) + res;
        }
        num >>= 4;
    }
    if (res.size() == 0) return "0";
    return res;
}

void solve() {
    int64 res = 0;
    vector<int64> v(9);
    for (auto &x : v) {
        string s;
        cin >> s;
        x = to_num(s);
    }
    vector<int64> cnt(33, 0);
    REP(i, 32) {
        int64 sum = cnt[i];
//        cout << cnt[i] << " ";
        REP(j, 8) {
            sum += v[j] >> i & 1;
        }
//        cout << (sum & 1) << " " << (v.back() >> i & 1) << " ";
        if ((sum & 1) != (v.back() >> i & 1)) {
            res |= 1LL << i;
            sum = cnt[i] + 8 - (sum - cnt[i]);
        }
        REP(j, 32-i+1) {
            if (sum >> j & 1) {
                cnt[i + j] += 1;
            }
        }
//        cout << sum << " " << res << endl;
    }
    cout << to_hex(res) << endl;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int64 T;
    cin >> T;
    while (T--) {
        solve();
    }
}



Measured memory_bytes: 3208
#coding:utf-8
import random

D = int(input())

C = [int(y) for y in input().split()]

S = []

ans = []

def scoring(inp,poi):
    
    score = 0
    day = 1
    last = [0] * 26
    
    for I in inp:
        score += poi[day-1][I-1]
        last[I-1] = day
        for ind,J in enumerate(last):
            score -= C[ind] * (day - ind - 1)
        day += 1
        
    return score

for i in range(D):
    s = [int(y) for y in input().split()]
    S.append(s)

for i in S:
    k = 0
    num = 0
    for f,t in enumerate(i):
        k = max(k,t)
        if k == t:
            num = f + 1
    ans.append(num)

counter = 100

base = scoring(ans,S)
nbase = 0
d = 0
ansc = ans.copy()

for i in range(counter):
    p = random.randint(0,25)
    q = random.randint(0,D-1)
    ansc[q] = p
    nbase = scoring(ansc,S)
    if nbase > base:
        ans = ansc.copy()
    else:
        ansc = ans.copy()

for i in ans:
    print("{}".format(int(i)))

Measured memory_bytes: 9908
/* Note:
Check constants at the beginning of the code.
    N is set to 4e5 but be careful in problems with large constant factor.
    Setting N in every problem is more effective.
Check corner cases.
    N = 1
No def int long long for now.
Add something here.

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

int mod = 1000000007;
ll dp[100005];;

ll gcd(long long a,long long b){

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


bool sortByVal(const pair<string, int> &a,
               const pair<string, int> &b)
{
    return (a.second < b.second);
}


int main(){

 int n; cin>>n;
 map<long long,long long>mp;

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

    long long a;
    cin>>a;
    mp[a]++;
 }

 vector<long long>Q;

 for(map<long long,long long>::iterator it = mp.begin();it!= mp.end();it++)
 {
   if(it->second >= 4){
    Q.push_back(it->first);
    Q.push_back(it->first);
   }
    else if(it->second >= 2)
        Q.push_back(it->first);
 }

 sort(Q.begin(),Q.end(),greater<long long>());

 if(Q.size() < 2)
    cout<<"0"<<endl;
 else
   cout<<Q[0]*Q[1]<<endl;



 return 0;
}



Measured memory_bytes: 9844
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using Graph = vector<vector<LL>>;

long long gcd(long long a, long long b){
  if (b==0) return a;
  else return gcd(b,a%b);
}
long long chmax(long long a,long long b){
  a = max(a,b);
}
long long chmin(long long a, long long b){
  a = min(a,b);
}
vector<bool> seen;
void dfs(const Graph &G, int v) {
    seen[v] = true;

    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue;
        dfs(G, next_v);
    }
}



int main() {
  LL n,k,sum=0,a=0,b=0,c=0,d=0,ans=0;
  LL MOD = 1000000007;
  LL INF = 1LL << 60;
  string S="";
  cin >> a >> b;
  if(a==b) S = "Yes";
  else S = "No";
  cout << S << endl;
}

Measured memory_bytes: 256
n,d=map(int,input().split())
x=[]
y=[]
for i in range(n):
     a,b=map(int,input().split())
     x.append(a)
     y.append(b)

ans=0
for i in range(n):
     if (abs(x[i])**2+abs(y[i])**2)**0.5<=d:
          ans+=1
print(ans)










Measured memory_bytes: 97720
/*-------------by syr-------------*/
#include<algorithm>
#include<bitset>
#include<cctype>
#include<cstring>
#include<cstdlib>
#include<deque>
#include<fstream>
#include<functional>
#include<iomanip>
#include<iostream>
#include<limits>
#include<list>
#include<map>
#include<math.h>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<sstream>
#include<string>
#include<time.h>
#include<utility>
#include<vector>

using namespace std;

int n,ans=1e9+7;

int findSum(int x){
	int ret=0;
	for(;x!=0;ret+=x%10,x/=10);
	return ret;
}

int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		int a=i,b=n-i;
		ans=min(ans,findSum(a)+findSum(b));
	}
	printf("%d\n",ans);
	return 0;
}


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

int main() {
int a[200000];
	int n;
	cin >>n;
	for (int x = 0; x < n; x++) {
		cin >> a[x];
	}
	int b=0;
	int c = 0;

		for (int x = 0; x < n; x++) {
			if (a[x] != x-b+ 1) {
				
				b++;
			}
		}	

	if(b==n)
	cout << "-1" << endl;
	else
	cout << b << endl;
	return 0;
}


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


int main(){

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

    int n, a, k;
    scanf("%d",&n);
    for(k = 0; k < n; k++){
        scanf("%d",&a);
        for(i = 0; i < 3; i++){
            for(j = 0; j < 3; j++){
                if(a == A[i][j]){
                    judge[i][j] = 1;
                }
            }
        }
    }
    int answer = 0;

    for(i = 0; i < 3; i++)
        answer += judge[i][0]*judge[i][1]*judge[i][2];
    for(j = 0; j < 3; j++)
        answer += judge[0][j]*judge[1][j]*judge[2][j];

    answer += judge[0][0]*judge[1][1]*judge[2][2];
    answer += judge[0][2]*judge[1][1]*judge[2][0];

    if(answer >= 1)
        printf("Yes");
    if(answer == 0)
        printf("No");
    

    return 0;
}

Measured memory_bytes: 128
package main

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

func getScanner(fp *os.File) *bufio.Scanner {
	scanner := bufio.NewScanner(fp)
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 500001), 500000)
	return scanner
}

func getNextString(scanner *bufio.Scanner) string {
	scanner.Scan()
	return scanner.Text()
}

func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}

func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}

func main() {
	fp := os.Stdin
	if len(os.Args) > 1 {
		fp, _ = os.Open(os.Args[1])
	}

	scanner := getScanner(fp)
	writer := bufio.NewWriter(os.Stdout)

	h := getNextInt(scanner)
	w := getNextInt(scanner)
	d := getNextInt(scanner)
	var aa [300][300]int

	points := make([]Point, h*w)
	sums := make([]int, h*w)

	for y := 0; y < h; y++ {
		for x := 0; x < w; x++ {
			aa[y][x] = getNextInt(scanner) - 1
			points[aa[y][x]] = Point{
				x: x,
				y: y,
			}
		}
	}
	for i := 0; i < h*w; i++ {
		if i-d < 0 {
			continue
		}
		sums[i] = sums[i-d]
		sums[i] += absint(points[i].x-points[i-d].x) + absint(points[i].y-points[i-d].y)
	}
	q := getNextInt(scanner)

	for i := 0; i < q; i++ {
		l := getNextInt(scanner) - 1
		r := getNextInt(scanner) - 1
		fmt.Fprintln(writer, sums[r]-sums[l])
	}

	writer.Flush()
}

type Point struct {
	x, y int
}

func absint(a int) int {
	if a < 0 {
		return -a
	}
	return a
}


Measured memory_bytes: 6400
#include <iostream>

using namespace std;

int main()
{
    int a , b;
    
    cin >> a >> b;
    
    if(a < b)
        cout << "a < b" << endl;
    else if (a > b)
        cout << "a > b" << endl;
    else 
        cout << "a == b" << endl;
  
    
    
   
   
   return 0;
}


Measured memory_bytes: 3080
#include <bits/stdc++.h> 
using namespace std;
const long INF=1000000000000000;
const long MOD=1000000007;

int main() {
    long r,g,b;
    cin>>r>>g>>b;
    
    if((2*g+b)%4==0) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
    }

    let mut count = 0;

    for a in 1..n {
        let b_max = (n - 1) / a;
        count += b_max;
    }

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


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

using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<pair<string, int>> entries;
  for (int i = 0; i < n; ++i) {
    string s;
    int t;
    cin >> s >> t;
    entries.emplace_back(s, t);
  }
  string x;
  cin >> x;
  bool asleep = false;
  int total = 0;
  for (auto&& e : entries) {
    if (asleep) {
      total += e.second;
    } else if (e.first == x) {
      asleep = true;
    }
  }
  cout << total << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


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

int main(){
  int n;
  int ans=0,cnt=0;
  cin >> n;
  for(int i=1;i<=n;i+=2){
    for(int j=1;j<=i;j++){
      if(i%j==0) cnt++;
    }
    if(cnt==8) ans++;
    cnt=0;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
　　　  ∧＿∧　やあ
　　 （´・ω・｀)　　　　　/　　　　　ようこそ、バーボンハウスへ。
　　 ／∇y:::::＼　　　 [￣]　　　　　このテキーラはサービスだから、まず飲んで落ち着いて欲しい。
　　 |:⊃:|:::::|　　　|──|
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|　うん、「また」なんだ。済まない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣￣|￣　  仏の顔もって言うしね、謝って許してもらおうとも思っていない。
￣￣￣￣￣￣￣￣￣￣￣￣￣￣／|
　　　　∇　∇　∇　∇　　　／.／|　　　でも、この提出を見たとき、君は、きっと言葉では言い表せない
　　　　┴　┴　┴　┴　／ ／　  |　　　「ときめき」みたいなものを感じてくれたと思う。
￣￣￣￣￣￣￣￣￣￣|／　　  |　　　殺伐としたコンテストの中で、そういう気持ちを忘れないで欲しい
￣￣￣￣￣￣￣￣￣￣　　　　 |　　　そう思って、この提出を投げたんだ。
　　　(⊆⊇)　(⊆⊇)　(⊆⊇)　　|
　    ||　　 ||　　||　　|　　　 じゃあ、判定を聞こうか。
　　.／|＼　／|＼ ／|＼
*/

#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
#define fst first
#define snd second
#define mp make_pair
#define ALL(obj) (obj).begin(),(obj).end()
#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(i,0,n)
#define RREP(i,n) RFOR(i,0,n) 
#define SIZE(x) ((int)(x).size())
#define debug(x) cerr << #x << " -> " << x << " (line:" << __LINE__ << ")" << '\n';
#define debugpair(x, y) cerr << "(" << #x << ", " << #y << ") -> (" << x << ", " << y << ") (line:" << __LINE__ << ")" << '\n';
typedef long long lint;
typedef pair<int, int> pint;
typedef pair<lint, lint> plint;
typedef vector<lint> vec;
typedef vector<vector<lint>> matrix;
typedef priority_queue<lint> p_que;
typedef priority_queue<lint, vector<lint>, greater<lint>> p_que_rev;
const lint INF = INT_MAX;
const lint LINF = LLONG_MAX;
const lint MOD = 1000000000 + 7;
const double EPS = 1e-9;
const double PI = acos(-1);
const int di[]{0, -1, 0, 1, -1, -1, 1, 1};
const int dj[]{1, 0, -1, 0, 1, -1, -1, 1};

lint gcd(lint a, lint b) {
    lint r;
    while (b != 0) {
        r = a % b;
        a = b; 
        b = r;
    }
    return a;
}

lint lcm(lint a, lint b) {
    return (a / gcd(a, b)) * b;
}

lint power(lint x, lint n, lint mod = MOD) {
    lint ret = 1;
    while(n > 0) {
        if(n & 1){
            (ret *= x) %= mod;
        }
        (x *= x) %= mod;
        n >>= 1;
    }
    return ret;
}

vector<lint> make_power(int n, lint base){
    lint num = 1;
    vector<lint> ret;
    for (int i=0; i<=n; ++i){
        ret.push_back(num);
        num *= base;
    }
    return ret;
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    lint ans = 1;
    REP(i, n){
        if(i == 0){
            ans *= k;
        }
        else {
            ans *= k-1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// AtCoder.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
#include <map>
#include <math.h>
#include <cmath>

using namespace std;

int main() {
    int S, W;
    cin >> S >> W;
    if(W >= S) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
}

Measured memory_bytes: 3588
//***********************
//*** writer : Alan Hu **
//***********************
#include<iostream>
#include<vector>
#include<string>
#include<set>
#include<map>
#include<algorithm>
#include<queue>
#include<list>
#include<stack>
#include<cstdio>
#include<fstream>
#include<numeric>
#include<functional>
#include<utility>
#include<memory>
#include<cstring>
#include<cmath>
using namespace std;

#define CLEAN(a,b) memset(a,b,sizeof(a))
#define mp make_pair
#define pb push_back
#define rept(i,a,b) for(int i=(int)(a);i<(int)(b);i++)

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

int main()
{
	int n,k;
	cin>>n>>k;
	rept(i,0,n) 
	{
		int x;
		cin>>x;
	}
	cout<<(n+k-3)/(k-1)<<endl;
	return 0;
}

Measured memory_bytes: 384
N = input()

def dfs(m):
    ans = 0
    if len(set(m)) == 3 and int(m) <= int(N):
        ans += 1

    if len(m) < len(N):
        for c in ['3', '5', '7']:
            ans += dfs(m + c)

    return ans

print(dfs(""))


Measured memory_bytes: 3060
N, M = map(int, input().split())

ans = 1
for i in range(1,int(M ** 0.5) + 1):
    if M % i == 0:
        if i >= N:
            ans = max(ans, M // i)
        if M // i >= N:
            ans = max(ans, i)

print(int(ans))

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;


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

  map<string, int> s;

  for (int i = 0; i < n; i++)
  {
    string t;
    cin >> t;
    if (s.count(t) == 1) s[t]++;
    else s.emplace(make_pair(t, 1));
  }

  int maxc = 0;

  for (auto p: s)
  {
    maxc = max(maxc, p.second);
  }

  for (auto p: s)
  {
    if (p.second == maxc) cout << p.first << endl;
  }

  return 0;
}

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

using namespace std;
#define N 100100
#define SIGMA 26

int n, m, x, i;
int main()
{
    cin >> n >> m;
    for (i = 0; i < m; ++i){
        cin >> x;
        n -= x;
    }
    if (n > -1)
        cout << n;
    else 
        cout << -1;
    return 0;
}


Measured memory_bytes: 3624
n,m = map(int,input().split())
ls = list(map(int,input().split()))
pos = [1]*(n)
for i in range(m):
    a,b = map(int,input().split())
    if ls[a-1] > ls[b-1]:
        pos[b-1] = 0
    elif ls[a-1] < ls[b-1]:
        pos[a-1] = 0
    else:
        pos[a-1] = 0
        pos[b-1] = 0
print(sum(pos))

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

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

    int N, L;
    cin >> N >> L;

    const int MAXN = 200000;
    static int a[MAXN];

    int idx = -1;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        if (i > 0 and a[i] + a[i - 1] >= L) idx = i - 1;
    }

    if (idx < 0) {
        cout << "Impossible\n";
        return 0;
    }

    cout << "Possible\n";
    for (int i = 0; i < idx; i++) {
        cout << i + 1 << '\n';
    }
    for (int i = N - 2; i >= idx; i--) {
        cout << i + 1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 1280
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
using namespace std;

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

#define pb          push_back
#define pf          push_front
#define all(x)      begin(x), end(x)
#define sz(x)       (int)(x).size()
#define ff          first
#define ss          second
#define mp          make_pair
#define lb          lower_bound
#define ub          upper_bound
#define Tcase()     int t; cin >> t; while(t--)
#define Forn(i, x)  for(int i = 0; i < (x); i++)

const int MOD = 1e9 + 7; // 998244353;
const int MX  = 2e5 + 5;
const ll  INF = 1e18;
const ld  PI  = acos((ld) -1);

void setIO(string name = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if(sz(name)){
        freopen((name+".in").c_str(), "r", stdin);
        freopen((name+".out").c_str(), "w", stdout);
    }
}

int main(){

    setIO();

    string s;
    cin >> s;

    if(s[sz(s) - 1] == 's') cout << s << "es";
    else cout << s << "s";
}


Measured memory_bytes: 3652
// Aizu Vol-3 0308: Deadlock
// 2017.8.27 bal4u@uu

#include <stdio.h>

#define MAX  200
#define BASE 100
char tbl[MAX+3][MAX+3];
int  Q[MAX+3], top, end;
int  count[MAX+3];

void topologicalSort(int size)
{
	int i, j;

//	memset(count, 0, sizeof(count));
	top = end = 0;
	for (i = 1; i <= size; i++) for (j = 1; j <= size; j++) if (tbl[i][j]) count[j]++;
	for (i = 1; i <= size; i++) if (!count[i]) Q[end++] = i;
	while (top < end) {
		i = Q[top++];
		for (j = 1; j <= size; j++) {
			if (tbl[i][j]) if (--count[j] == 0) Q[end++] = j;
		}
	}
}

int main(void)
{
	int N, u, d, i;
	char c[30];

	scanf("%d", &N);
//	memset(tbl, 0, sizeof(tbl));
	while (N-- > 0) {
		scanf("%d%s%d", &u, c, &d);
		if (*c == 'w') tbl[u][d+BASE] = 1;
		else           tbl[d+BASE][u] = 1;
	}
	topologicalSort(MAX);
	for (i = 1; i <= MAX; i++) if (count[i]) break;
	puts(i <= MAX ? "1" : "0");
	return 0;
}

Measured memory_bytes: 620
#include <stdio.h>
#include <math.h>

int	main(void)
{
  	int	r;
  	double c;
  	int num;
  	
  	num = scanf("%d", &r);
  	if (num != 1)
  	{
  	    return (0);
  	}
  
  	c = 3.1415926535 * r * 2;
  
  	printf("%f", c);
  	return (0);
}


Measured memory_bytes: 1728
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();

        StringBuilder ans = new StringBuilder();
        int i;

        if (a < b) {
            for (i = 0; i < b; i++) {
                ans.append(String.valueOf(a));
            }
        }
        else {
            for (i = 0; i < a; i++) {
                ans.append(String.valueOf(b));
            }
        }

        System.out.println(ans.toString());
    }
}

Measured memory_bytes: 21204
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <stdlib.h>
using namespace std;

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

  vector<int> p(n), q(n);
  for(int i = 0; i < n; i++)  cin >> p[i];
  for(int i = 0; i < n; i++)  cin >> q[i];

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

  map<vector<int>, int> mp;
  do{
    mp[a] = mp.size();
  } while(next_permutation(a.begin(), a.end()));

  int ans = abs(mp[p] - mp[q]);
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 5248
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using ld = long double;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll N, K; cin >> N >> K;
    vll p(N);
    rep(i, 0, N){
        cin >> p[i];
    }
    sort(p.begin(),p.end());
    ll sum = 0;
    rep(i, 0, K){
        sum += p[i];
    }
    prt(sum);
}


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

using namespace std;
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;

int main() {

    int n; cin >> n;

    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);

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

    for (int i = 0; i < n; ++i) {
        cin >> b[i];
    }

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

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;

    //bを固定して考える
    for (int i = 0; i < n; ++i) {
        auto a_itr = lower_bound(a.begin(), a.end(), b[i]);
        auto c_itr = upper_bound(c.begin(), c.end(), b[i]);

        ans += (a_itr - a.begin()) * (c.end() - c_itr);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1408
#include <stdio.h>

void makeFibonacci();

int F[45],n;

int main(){
  
  scanf("%d",&n);
  
  makeFibonacci();
  
  printf("%d\n",F[n]);

  return 0;
}


void makeFibonacci(){
  int i;
  
  F[0] = 1;
  F[1] = 1;

  for(i = 2; i <= n; i++){
    F[i] = F[i-2] + F[i-1];
  }
}

Measured memory_bytes: 596
// Problem : B - Judge Status Summary
// Contest : AtCoder - AtCoder Beginner Contest 173
// URL : https://atcoder.jp/contests/abc173/tasks/abc173_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) begin(x),end(x)

int mod = 1e9+7;
int inf = 4e18;
const int N = 5e5+5;
		
signed main()
{
    io
    int tt = 1;
    //cin>>tt;
    while(tt--)
    {
		int n;
		cin>>n;
		map<string,int> mp;
		while(n--)
		{
			string s;
			cin>>s;
			mp[s]++;
		}
		cout<<"AC x "<<mp["AC"]<<"\n";
		cout<<"WA x "<<mp["WA"]<<"\n";
		cout<<"TLE x "<<mp["TLE"]<<"\n";
		cout<<"RE x "<<mp["RE"]<<"\n";	
    }
    return 0;
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		long A = sc.nextLong();
		long B = sc.nextLong();
		long K = sc.nextLong();
		sc.close();

		if(A>=K) {
			A-=K;
		}else if((A+B)>=K) {
			B -= (K-A);
			A = 0;
		}else {
			A = 0;
			B = 0;
		}

		System.out.println(A + " " + B);
	}

}

Measured memory_bytes: 23764
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var one = nextIntArray();
	var H = one[0];
	var W = one[1];
	var list = new Array(H);
	var obj = new Array(H);
	for(var i = 0; i < H; i++){
		list[i] = nextCharArray();
		obj[i] = new Array(W);
		for(var j = 0; j < W; j++){
			obj[i][j] = {
				tate : 0,
				yoko : 0
			};
			if(list[i][j] == "."){
				if(j == 0){
					obj[i][j].yoko = 1;
				}else{
					obj[i][j].yoko += obj[i][j - 1].yoko + 1;
				}
			}
		}
	}
	for(var i = 0; i < W; i++){
		for(var j = 0; j < H; j++){
			if(list[j][i] == "."){
				if(j == 0){
					obj[j][i].tate = 1;
				}else{
					obj[j][i].tate += obj[j - 1][i].tate + 1;
				}
			}
		}
	}
	for(var i = H - 1; i >= 0; i--){
		for(var j = W - 1; j >= 0; j--){
			if(list[i][j] == "."){
				if(j != W - 1){
					obj[i][j].yoko = Math.max(obj[i][j].yoko, obj[i][j + 1].yoko);
				}
				if(i != H - 1){
					obj[i][j].tate = Math.max(obj[i][j].tate, obj[i + 1][j].tate);
				}
			}
		}
	}
	var output = 0;
	for(var i = 0; i < H; i++){
		for(var j = 0; j < W; j++){
			output = Math.max(output, obj[i][j].tate + obj[i][j].yoko - 1);
		}
	}
	myout(output);
}

Measured memory_bytes: 284688
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N, diff = 0;
    cin >> N;
    vector<int> p(N);
    for (int i = 0; i < N; i++)
    {
        cin >> p[i];
        if (p[i] != i + 1)
        {
            diff++;
        }
    }
    if (diff > 2)
    {
        cout << "NO" << endl;
    }
    else
    {
        cout << "YES" << endl;
    }
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S, T;
    cin >> S >> T;
    int L = S.length(), ans = 0;
    for (int i = 0; i < L; ++i) {
        if (S[i] != T[i]) {
            ++ans;
        }
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3812