akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M, K = map(int, input().split())
uf = UnionFind(N+1)
start = [0] * (N+1)

friend = defaultdict(list)
for _ in range(M):
    a, b = map(int, input().split())
    uf.union(a, b)
    start[a] -= 1
    start[b] -= 1


block = defaultdict(list)
for _ in range(K):
    c, d = map(int, input().split())
    if uf.same(c, d):
        start[c] -= 1
        start[d] -= 1

for i in range(1, N+1):
    ans = uf.size(i)-1 + start[i]
    print(ans, end=" ")

print("")


Measured memory_bytes: 9108
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<cstdio> 
#include<algorithm>
#define ll long long 
using namespace std;
const int maxn=500010,inf=1e9;
int n,m,x,y,z,tot;
int a[maxn],ans;
void read(int &k)
{
	int f=1;k=0;char c=getchar();
	while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
	while(c<='9'&&c>='0')k=k*10+c-'0',c=getchar();
	k*=f;
}
int main()
{
	read(n);a[0]=1;
	for(int i=1;i<=n;i++)
	{
		read(a[i]);
		if(a[i]==i)ans++;
		if(a[i]==i&&a[i-1]==i-1)ans--,a[i]=i-1;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 640
fun main(args: Array<String>) {
    val (n, m) = readInputLine().split(" ").map { it.toInt() }
    
    val roadList = mutableListOf<Int>()
    
    for (i in 1..n) {
        roadList.add(0)
    }
    
    for (i in 1..m) {
        val (a, b) = readInputLine().split(" ").map { it.toInt() }
        
        roadList[a - 1] = roadList[a - 1] + 1
        roadList[b - 1] = roadList[b - 1] + 1
    }
    
    for (i in 0 until n) {
        println(roadList[i])
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 36008
def main():
    import sys
    input = sys.stdin.readline
    
    N,M = map(int,input().split())
    A = list(map(int,input().split()))
    
    import heapq
    P = []
    for i in A:
        heapq.heappush(P,-i)
    for i in range(M):
        X = heapq.heappop(P)
        #print(X)
        X = -(-X//2)
        heapq.heappush(P,X)
    ans = 0
    for i in range(N):
        X = heapq.heappop(P)
        ans -= X
    print(ans)
    
main()

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

int main(){
  string S,T,N;
  int A,B;

  cin>>S>>T;
  cin>>A>>B;
  cin>>N;

  if(S == N){
    A--;
  }else if(T == N){
    B--;
  }

  cout<<A<<" "<<B<<endl;

  return 0;

}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = LI()
    r = 0
    d = collections.Counter(a)
    for i,c in d.items():
        if i < c:
            r += c-i
        else:
            r += c%i

    return r



print(main())




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

int main() {

  string s;
  cin >> s;
  
  string a;
  for(int i=0;i<s.size();i++){
    if(i%2==0){
      a+=s.at(i);
    }
    
  }
  
  cout << a << endl;
  
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <climits>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
using namespace std;

int main() {
    int a,b;
    cin >> a >> b;
    int z[100][100];
    int p = 0;
    for (int j = 0; j < 100; ++j) {
        for (int i = 0; i < 100; ++i) {
            if(j < 50) z[j][i] = 0;
            else z[j][i] = 1;
        }
    }

    for (int i = 0; i < b-1; ++i) {
        z[p/49+1][1 + p%98 + (p/98) % 2] = 1;
        p+=2;
    }
    p = 0;
    for (int i = 0; i < a-1; ++i) {
        z[p/49+52][1 + p%98 + (p/98) % 2] = 0;
//        z[p/50 + 51][p%50 + (p/50) % 2] = 0;
        p+=2;
    }

    cout << "100 100" << endl;
    for (int k = 0; k < 100; ++k) {
        for (int i = 0; i < 100; ++i) {
            if(z[k][i]) cout << '#' ;
            else cout << '.';
            if(i==99) cout << endl;
        }

    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<iomanip>
#include<utility>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<map>
#include<string>
#include<cctype>
#include<cmath>
#include<cassert>
#include<deque>
inline bool check(int a)
{
	int a1,a2,a3,a4,a5;
	a1=a/10000;
	a2=(a-a1*10000)/1000;
	a3=(a-a1*10000-a2*1000)/100;
	a4=(a-a1*10000-a2*1000-a3*100)/10;
	a5=a%10;
	if(a1==a5 && a2==a4)
	return true;
	return false;
}
using namespace std;
int main()
{
	int n,m;
	cin >> n >> m;
	int k=0;
	for(int i=n;i<=m;i++)
	{
		if(check(i))
		k++;
	}
	cout << k;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <functional>
#include <cstring>

int field[100000] = { 0 };
int field2[100000] = { 0 };
bool roop[100000] = { false };
//bool safe[100000] = { 0 };
int min[100000] = { 0 };

int main() {
	int n;
	std::cin >> n;
	for (int i = 0; i < n; i++) {
		std::cin >> field[i];
	}

	std::memset(field2, -1, sizeof(int) * 100000);

	//???????????´??????????´¢
	for (int i = 1; i < n; i++) { //????§???????
		std::vector<int> passed;
		bool isOk = false;
		int pos = i;
		passed.push_back(pos);
		while (!isOk) {
			int d = field[pos];
			pos += d;
			if (field[pos]) { //?¬????n???????§????
				if (std::find(passed.begin(), passed.end(), pos) != passed.end()) {
					break;//?????????????????¨????????????????????????????????????????????????
				}
				if (roop[pos]) break; //?????????????????´?????¨???????¨??????????
				if (field2[pos] >= 0) {
					isOk = true;
					pos = field2[pos];
					break; //OK??´?????¨???????¨??????????
				}
			}
			else {
				isOk = true; //0????????????????????£??????
				break;
			}
			passed.push_back(pos);
		}
		passed.push_back(pos);
		if (isOk) {
			for (auto& x : passed) field2[x] = pos;
		}
		else for (auto& x : passed) roop[x] = true;
	}
	std::queue<std::pair<int, int>> q;
	q.push(std::make_pair(0, 0));
	while (!q.empty()) {
		auto node = q.front(); q.pop();

		for (int i = 1; i <= 6; i++) {
			auto next = node;
			next.second += i;
			if (next.second >= n - 1) { //??´????????????
				std::cout << next.first + 1 << std::endl;
				return 0;
			}
			if (roop[next.second] || field2[next.second] == -1) continue;
			next.second = field2[next.second]; //?£???¶
			next.first++;
			if (next.second >= n - 1) { //??´????????????
				std::cout << next.first << std::endl;
				return 0;
			}
			if (min[next.second] && min[next.second] <= next.first) continue;
			min[next.second] = next.first;
			q.push(next);
		}
	}

	return 0;
}

Measured memory_bytes: 4396
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
ll knapSack(int W,int wt[], ll val[], int n) 
{ 
int i, w; 
ll K[n+1][W+1]; 
for (i = 0; i <= n; i++) 
{ 
	for (w = 0; w <= W; w++) 
	{ 
		if (i==0 || w==0) 
			K[i][w] = 0; 
		else if (wt[i-1] <= w) 
				K[i][w] = max(val[i-1] + K[i-1][w-wt[i-1]], K[i-1][w]); 
		else
				K[i][w] = K[i-1][w]; 
	} 
} 

return K[n][W]; 
} 
int main() 
{ 
ios_base::sync_with_stdio(false);
cout.tie(0);
cin.tie(NULL);
int nm,W; 
	cin>>nm;
	cin>>W; 
  ll val[nm];
  int wt[nm];
  for(int i=0;i<nm;i++)
  {
    cin>>wt[i]>>val[i];
  }
cout<< knapSack(W, wt, val, nm); 
	return 0; 
} 

Measured memory_bytes: 79232
n=int(input())
#a,b,x=map(int,input().split())
#pl=list(map(str,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

s=list(input())
count=0
for i in range(n-2):
    if s[i:i+3]==["A","B","C"]:
        count+=1

print(count)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	int a,b;
	scanf("%d%d",&a,&b);
	printf("%d\n",max(a+b,max(a-b,a*b)));
	
	return 0;
}


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

using namespace std;

int gcd(int a, int b) {
	return a % b ? gcd(b, a % b) : b;
}

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

int main() {
	int a, b;
	while (cin >> a >> b) {
		cout << gcd(a, b) << " " << lcm(a, b) << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <functional>
#include <bitset>
#include <utility>
#include <sstream>
#include <fstream>
#include <stack>
#include <cstdlib>
#include <complex>
#include <set>

using namespace std;

#define INF 1070000000LL
#define pb push_back
#define irep(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) irep(i,0,n)

typedef long long lint;
typedef pair<int, int> pint;
struct Edge{
    int to,weight;
};
typedef vector<vector<Edge> > Graph;


int main(){
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;
    vector<int> chank_pos,chank_neg;
    int temp_count = 1;
    char pre = s[0];
    irep(i,1,n){
	if(s[i]!=pre){
	    pre == '1' ? chank_pos.pb(temp_count) : chank_neg.pb(temp_count);
	    pre = s[i];
	    temp_count = 1;
	}
	else ++temp_count;
    }
    pre == '1' ? chank_pos.pb(temp_count) : chank_neg.pb(temp_count);
    
    if(chank_neg.size() <= k){
	cout << s.length() << endl;
	return 0;
    }


    if(s.back() == '0')chank_pos.pb(0);
    if(s.front() == '0')chank_pos.insert(chank_pos.begin(),0);

    int res = 0;
    rep(i,chank_neg.size()-k+1){
	int temp = 0;
	rep(j,k+1)temp += chank_pos[i+j];
	rep(j,k)temp += chank_neg[i+j];
	res = max(res, temp);
    }
    cout << res << endl;
}


Measured memory_bytes: 1020
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_B main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif


int main_B() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    
    int N; cin >> N;
    vs S(N);vi P(N);
    REP(i, N) cin >> S[i] >> P[i];

    vector<tuple<string, int, int> > rs;
    REP(i,N) {
        rs.push_back(make_tuple(S[i], P[i]*-1, i + 1));
    }

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

    string s; int i, j;
    for (auto p : rs) {
        tie(s, i, j) = p;        
        cout << j << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repp(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
typedef long long ll;
struct edge { ll s, t, x; };
typedef pair<ll, ll> P;
typedef pair<double, P> event;
const ll MAX = 510000;
const ll MOD = 1000000007;
#define INF (ll)10000000000000000

int main() {
  int L,R,d;
  cin>>L>>R>>d;
  int cnt=0;
  for(int i=L;i<=R;i++){
    if(i%d==0){cnt++;}
  }
  cout<<cnt;
}

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

int N;

int main(){
	scanf("%d", &N);
	int x = 0, y = 0;
	for(int i = 0; i < N; i++){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		int dist = abs(c - y) + abs(b - x);
		if(!(dist <= a && (dist % 2 == 0 && a % 2 == 0 || dist % 2 == 1 && a % 2 == 1))){
			printf("No\n");
			return 0;
		} 
	}
	printf("Yes\n");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define fix10 cout << fixed << setprecision(10);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define MOD 1000000007
#define NINF -1e17

struct ed{
  int from;
  int to;
  long cost;
};

int main(){
  int n,m,p;
  cin >> n >> m >> p;
  vector<ed> eds(m);
  rep(i,m){
    cin >> eds.at(i).from >> eds.at(i).to >> eds.at(i).cost;
    eds.at(i).from--;
    eds.at(i).to--;
    eds.at(i).cost -= p;
  }
  vector<long> d(n,NINF);
  vector<bool> neg(n,false);
  d.at(0) = 0;
  rep(i,n){
    rep(j,m){
      struct ed e = eds.at(j);
      if(d.at(e.from) == NINF) continue;
      
      if(d.at(e.to) < d.at(e.from) + e.cost){
        d.at(e.to) = d.at(e.from) + e.cost;
        if(i == n-1){
          neg.at(e.to) = true;
        }
      }
    }
  }
  rep(i,n){
    rep(i,m){
      struct ed e = eds.at(i);
      if(neg.at(e.from)) neg.at(e.to) = true;
    }
  }
  if(neg.at(n-1)){
    cout << -1 << endl;
    return 0;
  }
  long x = 0;
  cout << max(d.at(n-1),x) << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main()
{
 int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++)
    {
        cin >> v[i];
    }
    vector<int> dp(n + 1);
    int h1 = 0;
    int h2 = abs(v[0] - v[1]);
    for (int i = 2; i < n; i++)
    {
        int temp = min((h1 + abs(v[i] - v[i - 2])), (h2 + abs(v[i] - v[i - 1])));
        h1 = h2;
        h2 = temp;
    }
    cout << h2 << endl;
    return 0;
}

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

int main() {

  int N;
  cin >> N;

  vector<int> C(N);
  vector<int> S(N);
  vector<int> F(N);
  for (int i = 0; i < N - 1; i++) {
    cin >> C[i] >> S[i] >> F[i];
  }

  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    int answer = 0;
    if (i != N - 1) {
      for (int j = i; j < N - 1; j++) {
        if (answer < S[j]) {
          answer = S[j];
        } else if (answer % F[j] != 0) {
          answer = answer + F[j] - answer % F[j];
        }
        answer += C[j];
      }
      
    }
    cout << answer << endl;
  }

  return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

using namespace std;

typedef int64_t ll;
typedef vector<int> Vi;

int n;
Vi vi;

void init()
{
	cin >> n;
	vi.resize(n + 1);

	REP(i, n)
	{
		int x;
		cin >> x;
		vi[x] = i + 1;
	}
}


int main()
{
	init();

	ll ans = 0;
	multiset<int> s;

	s.insert(0); s.insert(0);
	s.insert(n + 1); s.insert(n + 1);

	for (ll x = n; x >= 1; --x)
	{
		auto it = s.lower_bound(vi[x]);
		int i_r = *it++;
		int i_rr = *it--;
		int i_l = *(--it);
		int i_ll = *(--it);

		ans += x * (vi[x] - i_l) * (i_rr - i_r);
		ans += x * (i_r - vi[x]) * (i_l - i_ll);

		s.insert(vi[x]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 5376
#include "bits/stdc++.h"
 
using namespace std;

#define VI vector<int>
#define PII pair<int,int>
#define VPII vector<pair<int,int>>
#define REP(i,n) for(int i=0; i<int(n); i++)
#define REREP(i,n) for(int i=int(n-1); i>=0; i--)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define Cout(str) cout << str << endl

int main(){
	int N;
	int index;
	int freq_e1, freq_e2;
	int freq_o1, freq_o2;
	map<int,int> even{};
	map<int,int> odd{};

	cin >> N;
 
	REP(i,N/2){
		cin >> index;
		even[index]++;
		cin >> index;
		odd[index]++;
	}

	freq_e1 = freq_e2 = 0;
	freq_o1 = freq_o2 = 0;

	for(auto itr = even.begin(); itr != even.end(); ++itr){
		if(even[freq_e1] < itr->second){
			freq_e2 = freq_e1;
			freq_e1 = itr->first;
		}else if(even[freq_e2] < itr->second){
			freq_e2 = itr->first;
		}
	}


	for(auto itr = odd.begin(); itr != odd.end(); ++itr){
		if(odd[freq_o1] < itr->second){
			freq_o2 = freq_o1;
			freq_o1 = itr->first;
		}else if(odd[freq_o2] < itr->second){
			freq_o2 = itr->first;
		}
	}
	
	if(freq_e1 != freq_o1){
		cout << N - (even[freq_e1] + odd[freq_o1]) << endl;
	}else{
		cout << N - max(even[freq_e1] + odd[freq_o2], even[freq_e2] + odd[freq_o1]) << endl;
	}

	return 0;
}



Measured memory_bytes: 4992
/**
 *    author        : Saurav Paul 
 *    created       : August 06, 2020 10:43 PM
 *    Problem Name  : C - Vacation
 *    Problem Limit : 2000 ms , 1024 MB
 *    Problem Url   : https://atcoder.jp/contests/dp/tasks/dp_c
 *    @genarated by : ai-virtual-assistant
**/

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios_base::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<vector<int>>v(n+1,vector<int>(4)) ;

    for(int i = 1; i <= n; i++){
        for(int j = 1 ; j <= 3; j++){
            cin >> v[i][j] ;
        }
    }

    vector<vector<int>> dp(4,vector<int>(2)) ;

    int prev = 0 , nxt = 1;
    dp[1][prev]=v[1][1],dp[2][prev]=v[1][2],dp[3][prev]=v[1][3] ;

    for(int i = 2 ; i <= n ; i++){
        for(int j = 1 ; j <= 3 ; j++){
            for(int k = 1; k <= 3; k++){
                if(j == k) continue ;
                dp[j][nxt] = max(dp[j][nxt] , v[i][j] + dp[k][prev]) ;
            }
        }
        prev ^= 1;
        nxt ^= 1;
    }

    cout << max({dp[1][prev],dp[2][prev],dp[3][prev]}) << endl ;

    return 0 ;
}


Measured memory_bytes: 8804
H, W, N = map(int, input().split())
d = {}
ans = [0] * 10
ans[0] = (H - 2) * (W - 2)
for i in range(N):
    a, b = map(int, input().split())
    for v in [a - 1, a, a + 1]:
        if v < 2 or v > H - 1:
            continue
        for w in [b - 1, b, b + 1]:
            if w < 2 or w > W - 1:
                continue
            black = 0
            for x in [v - 1, v, v + 1]:
                for y in [w - 1, w, w + 1]:
                    black += d.get((x, y), 0)
            ans[black] -= 1
            ans[black + 1] +=1
            #print(a, b, black, ans)
    d[a, b] = 1
    #print(d)
for i in ans:
    print(i)

Measured memory_bytes: 67160
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int main()
{
    int N;
    cin >> N;
    
    int wa1 = 0;
    int wa2 = 0;
    for(int i=0;i<9;i++){
        wa1= N / pow(10,i);
        wa2 =wa2 + (wa1 % 10);
    }
    if(N%wa2==0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    
    return 0;
}

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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i)
#define fore(i,a) for (auto &i : a)
#define repr(i, n) for (int i = n; i >= 0; --i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int mod = 1000000000 + 7;
const static int inf = INT_MAX / 2;
const static llong INF = LLONG_MAX / 2;
const static double eps = 1e-10;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

const int A=0, G=1, C=2, T=3;
llong dp[101][4][4][4];

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

    int n;
    cin>>n;
    dp[0][T][T][T] = 1;
    rep(i, n) {
        rep(j, 4) {
            rep(k, 4) {
                rep(l, 4) {
                    rep(m, 4) {
                        if (k==A && l==G && m==C) continue;
                        if (k==G && l==A && m==C) continue;
                        if (k==A && l==C && m==G) continue;
                        if (j==A && l==G && m==C) continue;
                        if (j==A && k==G && m==C) continue;
                        dp[i+1][k][l][m] += dp[i][j][k][l];
                        dp[i+1][k][l][m] %= mod;
                    }
                }
            }
        }
    }

    llong ans = 0;
    rep(i, 4)rep(j, 4)rep(k, 4)ans+=dp[n][i][j][k];
    cout << ans%mod << endl;
    return 0;
}

Measured memory_bytes: 256
n,a,b= input().split()
N = int(n)
A = int(a)
B = int(b)

ab_list = []
for i in range(1,N+1):
	numbers = list(str(i))
	num_list = list(map(int,numbers))

	sum_numlist = 0
	for j in range(len(num_list)):
		sum_numlist += num_list[j]

	if(A<=sum_numlist and sum_numlist<=B):
		ab_list.append(i)

count = 0
for n in range(len(ab_list)):
	count += ab_list[n]

print(count)


Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
const int mod=10007;
typedef pair<int,int> P;

int M,cnt;
vector<P> v[100001];
bool u[100001];
vector<int> a;

void dfs(int x) {
  u[x]=true;
  a.push_back(x);
  for(int i=0; i<v[x].size(); i++) {
    if(!u[v[x][i].first]) {
      M=max(M,v[x][i].second);
      dfs(v[x][i].first);
    }
  }
}

void solve() {
  cnt=0;
  for(int i=0; i<a.size(); i++) {
    for(int j=0; j<v[a[i]].size(); j++) {
      if(M==v[a[i]][j].second) cnt++;
    }
  }
}

int main() {
  int n;
  while(cin >> n && n) {
    for(int i=0; i<n; i++) {
      v[i].clear();
      int x,y;
      cin >> x >> y;
      v[i].push_back(P(x,y));
      cin >> x >> y;
      v[i].push_back(P(x,y));
    }
    int ans=1;
    memset(u,false,sizeof(u));
    for(int i=0; i<n; i++) {
      if(!u[i]) {
	M=0;
	a.clear();
	dfs(i);
	solve();
	ans*=cnt/2;
	ans%=mod;
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4388
#include <stdio.h>

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

  for(int a=1;a<=9;a++)
  {for(int b=1;b<=9;b++)
  {if(n==a*b){
    puts("Yes");
    return 0;
  }
}
}
puts("No");

return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int n,a,b,s[400000];
int main(){
	int nowmax,i,j,k,tmp,remain;
	cin>>n>>a>>b;
	i=0; nowmax=b; tmp=b;	remain=n-b;	a--;
	while(tmp)s[i++]=tmp--;
	while(i<n){
		j=remain-a+1;
		if(j<=0){
			cout<<-1<<endl;
			return 0;
		}
		tmp=nowmax+min(j,b);
		while(tmp-nowmax)s[i++]=tmp--;
		remain-=min(j,b);
		nowmax+=min(j,b);
		a--;
	}
	if(a!=0){
		cout<<-1<<endl;
		return 0;
	}
	for(i=0;i<n;i++)cout<<s[i]<<" ";
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3328
import scala.io.StdIn

case class Card(suit: String, rank: Int) extends Ordered[Card] {
  override def toString():String = {
    s"$suit $rank"
  }

  def compare(that: Card): Int = {
    val (thisSuitIdx, thatSuitIdx) = (Card.suitSeq.indexWhere(_ == this.suit),
      Card.suitSeq.indexWhere(_ == that.suit))
    val suitComp = thisSuitIdx compare thatSuitIdx
    if(suitComp != 0){
      suitComp
    }else{
      this.rank compare that.rank
    }
  }

  def getNextCard: Option[Card] = {
    this match {
      case Card("D", 13) => None
      case Card(s, 13) =>
        Some(Card(Card.suitSeq(Card.suitSeq.indexWhere(_ == s)+1), 1))
      case Card(s, r) => Some(Card(s, r+1))
    }
  }
}

object Card{
  val suitSeq = Seq("S", "H", "C", "D")
}

object Main {
  def missingCardList(cardList: Seq[Card],
    nextCard: Card = Card("S", 1), newCardList: Seq[Card] = Seq[Card]()): Seq[Card] = {
      if(cardList.contains(nextCard) == false){
        nextCard.getNextCard match {
          case None => (nextCard +: newCardList).reverse
          case Some(card) => missingCardList(cardList, card, nextCard +: newCardList)
        }
        }else{
          nextCard.getNextCard match {
            case None => newCardList.reverse
            case Some(card) => missingCardList(cardList, card, newCardList)
          }
        }
  }


  def main(args: Array[String]): Unit = {
    StdIn.readInt()
    val inputs = Iterator.continually(StdIn.readLine()).takeWhile(_ != null).toList
    val cardList = for{
      in <- inputs
      val Array(suit, rankT, _*) = in.split(" ")
    }yield(Card(suit, rankT.toInt))
    missingCardList(cardList.sorted).foreach(println _)
  }
}

Measured memory_bytes: 44180
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
#define mod 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);

}
int main()
{
    ios_base:: sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
    ll n,m;
    cin>>n>>m;
    ll temp = n/m;
    cout<<min(abs(n-temp*m),abs(n-(temp+1)*m));
}


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

int main(){
    int64_t n,k;
    cin>>n>>k;
    vector<int64_t> h(n);
    for(auto &p:h) cin>>p;
    sort(h.begin(),h.end());
    int64_t sum=0;
    for(int i=0;i<n-k;i++){
        sum+=h.at(i);
    }
    cout<<sum;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, X = LI()

"""
Lv i のバーガーの厚みをa[i]
Lv i に含まれるパティの数をp[i]
とすると
a[0] = 1
a[i] = 2 * a[i-1] + 3
p[0] = 1
p[i] = 2 * p[i - 1] + 1

X = 1 f(N, X) = 0

1 < X <= 1 + a[i - 1]
一番したのバン

2 + a[i - 1] < X
一番したのバン　＋　
"""
a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    elif X <= 1 + a[N - 1]:
        return f(N - 1, X - 1)
    else:
        return p[N - 1] + 1 + f(N - 1, X - 2 - a[N - 1])
print(f(N, X))







Measured memory_bytes: 10936
#include<bits/stdc++.h>
#define mod 998244353

using namespace std;

long long p[300001];

void pre(){
	p[1]=p[0]=1;
	for(int i=2; i<=300000; i++) p[i]=(p[i-1]*i)%mod;
}

long long pw(long long n, long long t){
	if(t==0) return 1;
	long long ret=pw(n, t/2);
	ret*=ret;
	ret%=mod;
	if(t%2) ret*=n;
	ret%=mod;
	return ret;
}

long long C(long long n, long long t){
	long long ret=p[n];
	ret*=pw(p[t], mod-2);
	ret%=mod;
	ret*=pw(p[n-t], mod-2);
	ret%=mod;
	return ret;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    pre();
    long long res=0, n, a, b, k, tmp, tmp1;
    cin >> n >> a >> b >> k;
    for(int i=0; i<=n; i++){
    	tmp=i*a;
    	if(tmp>k) break;
    	if((k-tmp)%b==0 && (k-tmp)/b<=n){
    		tmp1=(k-tmp)/b;
    		//cout << tmp << " " << tmp1 << endl;
    		res+=(C(n, i)*C(n, tmp1))%mod;
    		res%=mod;
    	}

    }
    cout << res;

    return 0;
}

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>
#include <bitset>
#include <sstream>
#include <cassert>
#include <time.h>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}
void printvec (vec &v) {
    Rep (i, (ll)v.size()) {
        cout << v[i] << " \n"[i+1 == (ll)v.size()];
    }
}

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

    ll N;
    cin >> N;
    vec a(N);
    vec cnt(N, 0);
    Rep (i, N) {
        cin >> a[i];
        cnt[a[i]]++;
    }

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

    ll M = *max_element(a.begin(), a.end());
    ll m = *min_element(a.begin(), a.end());

    if ((M+1)/2 != m) {
        cout << "Impossible\n";
        return 0;
    }

    if (M%2 == 1 and cnt[m] != 2) {
        cout << "Impossible\n";
        return 0;
    }

    if (M%2 == 0 and cnt[m] != 1) {
        cout << "Impossible\n";
        return 0;
    }

    for (ll i = m+1; i <= M; i++) {
        if (cnt[i] < 2) {
            cout << "Impossible\n";
            return 0;
        }
    }

    cout << "Possible\n";
    return 0;
}

Measured memory_bytes: 3660
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int m = scan.nextInt();
		int l = scan.nextInt();
		
		//n*m???????????£??\
		int[][]  aryA = new int[n][m];
		for(int ai = 0; ai < n; ai++){
			for(int aj = 0; aj < m; aj++){
				aryA[ai][aj] = scan.nextInt();
			}
		}
		//m*l???????????£??\
		int[][] aryB = new int[m][l];
		for(int bi = 0; bi < m; bi++ ){
			for(int bj = 0; bj < l; bj++){
				aryB[bi][bj] = scan.nextInt();
			}
		}
		scan.close();
		//n*l????????????????????£??\
		long[][] aryC = new long[n][l];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < l; j++){
				for(int k = 0; k < m; k++){
					aryC[i][j] += aryA[i][k] * aryB[k][j]; 					
				}				
			}
		}
		
		//??????
		for(int ci = 0; ci < n; ci++){
		 for(int cj = 0; cj < l; cj++){
			 System.out.print(aryC[ci][cj]);
			 if(cj != l-1){
				 System.out.print(" ");
			 }
		 }
		 System.out.println();
		}
		
	}

}

Measured memory_bytes: 45472
import java.util.*;
import java.io.*;
import static java.util.Comparator.*;
 
class Main{
    public static void main(String[] args){
       BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
       in.lines().map(Integer::new).sorted(reverseOrder()).limit(3).forEach(System.out::println);
    }
}

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

namespace ConsoleApp1
{
    static class BPowerSocket
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            int a = ab[0];
            int b = ab[1];

            int tapCount = 0;
            int noUseCount = 1;

            while (noUseCount < b)
            {
                tapCount++;
                noUseCount += a - 1;
            }

            Console.WriteLine(tapCount);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 13268
N = int(input())
h = list(map(int, input().split()))
 
DP = [0, abs(h[0]-h[1])]
for i in range(N-2):
    DP += [min(DP[-2] + abs(h[i]-h[i+2]), DP[-1] + abs(h[i+1]-h[i+2]))]
 
print(DP[-1])

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

#define FO(i,a,b) for (int i = (a); i < (b); i++)
#define sz(v) int(v.size())

using namespace std;

typedef long long ll;

int n;
int a[200005];
ll v[200005];
vector<int> c[200005];
vector<pair<ll,ll> > f[200005];

int main() {
    scanf("%d", &n);
    FO(i,1,n) {
        scanf("%d %lld", a+i+1, v+i+1);
        c[a[i+1]].push_back(i+1);
    }
    ll s = 0, e = 1e13, b = 1e13;
    while (s <= e) {
        ll m = (s+e)/2;
        for (int i = n; i >= 1; i--) {
            if (sz(c[i]) == 0) {
                f[i].emplace_back(0,0);
                continue;
            }
            auto x = f[c[i][0]], y = f[c[i][1]];
            ll v1 = v[c[i][0]];
            ll v2 = v[c[i][1]];
            vector<pair<ll,ll> > r;
            int j = 0, k = 0;
            while (j < sz(x) && k < sz(y)) {
                if (x[j].second+y[k].first+v1+v2 <= m) {
                    r.emplace_back(x[j].first+v1, y[k].second+v2);
                    k++;
                } else {
                    j++;
                }
            }
            int sr = sz(r);
            FO(l,0,sr) r.emplace_back(r[l].second, r[l].first);
            sort(r.begin(), r.end());
            for (auto p : r) {
                if (sz(f[i]) && f[i].back().second <= p.second) continue;
                f[i].push_back(p);
            }
        }
        if (sz(f[1])) {
            b = m;
            e = m-1;
        } else {
            s = m+1;
        }
        FO(i,1,n+1) f[i].clear();
    }
    printf("%lld\n", b);
}


Measured memory_bytes: 39984
import sys
from collections import Counter

stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

mod = 10 ** 9 + 7

a, b, x = na()
if a % x == 0:
    print(b // x - a // x + 1)
else:
    print(b // x - a // x)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
using namespace std;
int main(){
    int K,X; cin >> K >> X;

    int left = X -K + 1;
    int right = X + K - 1;

    for(int i = left;i<=right;i++){cout << i << " ";}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rank Gacho_0716
#define M 1000000007
using namespace std;

class UF{
public:
  int V;
  vector<int> par,rank;
  UF(){}
  UF(int V):V(V),par(V),rank(V,0){for(int i=0;i<V;i++)par[i]=i;}
  
  int find(int x){
    assert(x < V);
    if(par[x]==x)return x;
    return par[x]=find(par[x]);
  }
  
  void unite(int x,int y){
    x=find(x), y=find(y);
    if(x==y)return;
    if(rank[x]<rank[y])par[x]=y;
    else{
      par[y]=x;
      if(rank[x]==rank[y])rank[x]++;
    }
  }

  bool same(int x,int y){return find(x)==find(y);}
};

set<int> memo;

int main(){
  
  while(1){
    
    int n, m;
    
    cin>>n>>m;
    if(!n&&!m) break;
    
    UF uf = UF(n);
    
    for(int i=0;i<m;i++){
      int a, b;
      cin>>a>>b;
      a--, b--;
      uf.unite(a,b);
    }
    
    memo.clear();
    
    for(int i=0;i<n;i++) memo.insert(uf.find(i));
    
    int x=1, y=1;
    
    for(int i=0;i<n;i++) x=x*2%M;
    
    for(int i=0;i<memo.size();i++) y=y*2%M;

    cout<<(y%M + (x!=y))%M<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 8636
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int n;
string S;
int c[100001]; //羊1, 狼0

bool dfs(int idx, int now, int pre) {
  if (idx==n-1  && c[idx] != now) return false;
  if (idx==n) return c[0]==now;
  c[idx] = now;
  if (S[idx]=='o') {
    if (now) return dfs(idx+1, pre, now);
    else return dfs(idx+1, !pre, now);
  } else {
    if (now) return dfs(idx+1, !pre, now);
    else return dfs(idx+1, pre, now);
  }
  return 0;
}

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

  rep(i, 2) {
    rep(j, 2) {
      fill(c, c+n, -1);
      c[0]=j;
      if  (S[0]=='o') c[n-1] = j?i:!i;
      else c[n-1] = j?!i:i;
      if (dfs(1, i, j)) {
        rep(k, n) {
          char a = c[k]?'S':'W';
          cout << a;
        }
        cout << endl;
        return 0;
      }
    }
  }
  cout << -1 << "\n";
  return 0;
}

Measured memory_bytes: 976
use proconio::input;

fn main() {
    input! {
        n: usize,
        a: [u32; n],
    }
    let mut xors = 0;
    for v in &a {
        xors ^= v;
    }
    for i in 0..n {
        let ans = xors ^ a[i];
        print!("{}", ans);
        if i == n-1 {
            println!();
        } else {
            print!(" ");
        }
    }
}


Measured memory_bytes: 5616
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <cstring>
#include <cctype>
#include <cmath>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <stdio.h>
#include <string.h>
#include <cstdlib>
#include <math.h>
#include <bitset>
#include <iterator>	
#include <iomanip>
#include <sstream>
#include <numeric>
#include <cassert>
#define INF 2000000000
#define MOD 1000000007
#define sym cout<<"---------"<<endl;
#define ll long long
#define mk make_pair
#define en endl
#define RE return 0
#define int ll
#define P pair<int,int>
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int gcd(int a,int b){if(a%b==0){return b;}else return gcd(b,a%b);}
int lcm(int a,int b){if(a==0){return b;} return a/gcd(a,b)*b;}

#define MAX 100005

int x[MAX],y[MAX];
P sort_x[MAX],sort_y[MAX];
int dis[MAX];
vector<P> G[MAX];
int fin[MAX];

signed main(){
	int n; cin>>n;
	for(int i=0; i<n; i++){
		cin>>x[i]>>y[i];
		sort_x[i]=mk(x[i],i);
		sort_y[i]=mk(y[i],i);
	}
	sort(sort_x, sort_x+n);
	sort(sort_y, sort_y+n);
	for(int i=0; i<n; i++){
		P p=sort_x[i];
		if(i){
			G[p.second].push_back(mk(sort_x[i-1].second, abs(x[p.second]-sort_x[i-1].first)));
			G[sort_y[i].second].push_back(mk(sort_y[i-1].second, abs(y[sort_y[i].second]-sort_y[i-1].first)));
		}
		if(i!=n-1){
			G[p.second].push_back(mk(sort_x[i+1].second, abs(x[p.second]-sort_x[i+1].first)));
			G[sort_y[i].second].push_back(mk(sort_y[i+1].second, abs(y[sort_y[i].second]-sort_y[i+1].first)));
		}
	}
	
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(mk(0,0));
	int ans=0;
	while(!que.empty()){
		int now=que.top().second; int p=que.top().first; que.pop();
		if(fin[now]) continue;
		else{ 
			ans+=p; 
			fin[now]=true;
		}
		for(int i=0; i<G[now].size(); i++){
			int to=G[now][i].first, d=G[now][i].second;
			if(fin[to]) continue;
			que.push(mk(d,to));
		}
	}
	cout<<ans<<en;
}



Measured memory_bytes: 19444
count :: [Int] -> Int -> [Int]
count ns k = c 0 <$> ns
  where c :: Int -> Int -> Int
        c n v = if v < k then c (n + 1) (v * 2) else n

average :: [Double] -> Double
average ns = sum ns / fromIntegral (length ns)

main :: IO ()
main = do
  [n, k] <- map read . words <$> getLine
  print . sum $ (\x -> 1 / fromIntegral n * 0.5 ^ x) <$> count [1..n] k

Measured memory_bytes: 636
import java.util.Scanner


object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = for (_ <- 0 until n) yield sc.nextLong()
    (n, a)
  }

  def solve(n: Int, a: IndexedSeq[Long]): Long = {
    val minabs = a.map(Math.abs).min
    val cntMinus = a.count(n => n < 0)
    if(cntMinus %2 == 0) a.map(Math.abs).sum
    else a.map(Math.abs).sum - 2 * minabs
  }

  def main(args: Array[String]): Unit = {
    val (n, a) = read()
    println(solve(n, a))
  }
}

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

// #define int long long
#define ll long long
#define pb push_back
#define vi vector<int>
#define vii vector<vector<int> >

template <class X> void print(X Target){ cout << Target << '\n'; }

int check_digit(int *num)
{
  int sum = 0;
  for (int i = 1; i <= 11; i++){
    if (i <= 6){
      sum += num[i] * (i + 1);
      // print(num[i] * (i + 1));
    }
    else {
      sum += num[i] * (i - 5);
      // print(num[i] * (i - 5));
    }
  }

  return (11 - (sum % 11 <= 1 ? 11 : sum % 11));
}

bool check_digit2(int *num)
{
	int sum = 0;
  for (int i = 1; i <= 11; i++){
    if (i <= 6){
      sum += num[i] * (i + 1);
      // print(num[i] * (i + 1));
    }
    else {
      sum += num[i] * (i - 5);
      // print(num[i] * (i - 5));
    }
  }
  // print(11 - (sum % 11 <= 1 ? 0 : sum % 11));
  return ((11 - (sum % 11 <= 1 ? 11 : sum % 11)) == num[0]);
}

signed main()
{
  ios::sync_with_stdio(false);
  char s[12];
  int num[12];
  cin >> s;

  for (int i = 0; i < 12; i++){
    if (isdigit(s[11 - i])){
      num[i] = s[11 - i] - '0';
    }
    else {
      num[i] = -1;
    }
  }

  if (num[0] == -1) print(check_digit(num));
  else {
    int t;
    for (int i = 1; i <= 11; i++){
      if (num[i] == -1){
        t = i;
        break;
      }
    }
    int ans, cnt = 0;
    for (int i = 0; i < 10; i++){
      num[t] = i;
      if (check_digit2(num)){
        cnt++;
        ans = i;
      }
    }
    if (cnt == 1){
      print(ans);
    }
    else {
      print("MULTIPLE");
    }
  }

  return (0);
}

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

string s;
map<char, bool> mp;

int main() {
  cin >> s;

  long long N = s.size();
  long long ans = 1 + N * (N - 1) / 2, cnt = 0, k = 0;


  // 高々O(N * 26)
  for (int i = 0; i < N; ++i) {
    if (!mp[s[i]]) {
      cnt = 1;
      for (int j = i + 1; j < N; ++j) {
	if (s[i] == s[j]) {
	  ans -= cnt;
	  cnt++;
	}
      }
      mp[s[i]] = true;
    }
  }

  if (ans < 0) for (long long i = 0; i < 10000000000; i++) k += i;
  
  cout << ans << endl;
  
  return 0;
}


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

int main()
{
    int n,t;
    cin >> n >> t;
    vector<pair<int,int>> ab(n);
    rep(i,n) cin >> ab[i].first >> ab[i].second;
    sort(ab.begin(), ab.end());
    int t_max = t + ab.back().first;

    // dp[n+1][t_max+1] 
    vector<vector<int>> dp(n+1, vector<int>(t_max+1, 0));

    int ans = 0;
    rep(ti,t_max) {
        rep(k,n) {
            dp[k+1][ti] = dp[k][ti];
            int pt = ti-ab[k].first;
            if(pt >= 0 && pt < t) {
                int eat_k = dp[k][pt] + ab[k].second;
                dp[k+1][ti] = max(dp[k+1][ti], eat_k);
            }
            ans = max(ans, dp[k+1][ti]);
            // printf("ti=%d k=%d dp[k+1][ti]=%d pt=%d dp[k+1][ti]=%d \n",ti,k,dp[k+1][ti],pt,dp[k+1][ti]);          
        }
    }

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

Measured memory_bytes: 70784
import sys
import numpy as np

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

# テスト用コード
# Ciの値でsortする、Tを0000で固定した後、最後に2**N倍
N = ir()
C = np.array(lr())
MOD = 10 ** 9 + 7
C.sort()
# N-2がマイナスになる時に注意、一番右は2**(N-1)
two_power = np.array([(1+N-i) * pow(2, (N-2), MOD) % MOD if i < N-1 else pow(2, i, MOD) for i in range(N)])
answer = (C * two_power % MOD).sum() % MOD
answer *= pow(2, N, MOD)
print(answer%MOD)


Measured memory_bytes: 34508
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
        long soukei = 0;

		for(int i = 0 ; i <=n.length()-1 ; i++){
        	soukei = soukei + Character.getNumericValue(n.charAt(i));    	
        }
		
      	if(soukei%9 == 0){
      		System.out.println("Yes");
        }else{
        	System.out.println("No");
        }
	}
}

Measured memory_bytes: 40624
k, n = map(int, input().split())
a = list(map(int, input().split()))
a.append(a[0] + k)

d = [a[i+1] - a[i] for i in range(n)]
l = 0
for i in range(n):
    l = max(l, a[i+1] - a[i])
print(k - l)

Measured memory_bytes: 86140
#!/usr/bin/env python3

import sys
import pprint

sys.setrecursionlimit(10 ** 6)

class Logger:
	def __init__(self, debug):
		self.debug = debug
	def print(self, *args):
		if self.debug:
			pprint.pprint(args)


def main():
	log = Logger(0)
	n = int(sys.stdin.readline())
	a = list(map(int, sys.stdin.readline().split()))
	q = int(sys.stdin.readline())
	b = []
	c = []
	for i in range(q):
		bi, ci = map(int, sys.stdin.readline().split())
		b.append(bi)
		c.append(ci)
	v = {}
	for i in range(n):
		v[a[i]] = v.get(a[i], 0) + 1
	suma = sum(a)
	for i in range(q):
		suma += v.get(b[i], 0) * (c[i] - b[i])
		v[c[i]] = v.get(c[i], 0) +  v.get(b[i], 0)
		v[b[i]] = 0
		log.print(v)
		print(suma)
	


main()

Measured memory_bytes: 31000
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
 
#define INF 1000000000000000
#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 pair<ll,ll> P;

ll n,m,k,s;
vector<ll> G[200000];
vector<P> g[200000];
ll c[200000];
ll d[200000];
bool used[200000];
bool is_d[200000];
bool is_z[200000];

void get_d(ll cen){
    queue<P> que;
    fill(used,used + n,false);
    REP(i,G[cen].size()){
        que.push(P(G[cen][i],1));
        used[G[cen][i]] = is_d[G[cen][i]] = true;
    }
    while(!que.empty()){
        P p = que.front();
        que.pop();
        if(p.second >= s)
            break;

        REP(i,G[p.first].size()){
            if(used[G[p.first][i]])
                continue;
            que.push(P(G[p.first][i],p.second + 1));
            used[G[p.first][i]] = is_d[G[p.first][i]] = true;
        }
    }
}
int main(){

    scanf("%lld%lld%lld%lld",&n,&m,&k,&s);
    ll p,q;
    scanf("%lld%lld",&p,&q);

    REP(i,k){
        scanf("%lld",c + i);
        c[i]--;
    }
    REP(i,m){
        ll a,b;
        scanf("%lld%lld",&a,&b);
        a--;b--;
        G[a].pb(b);G[b].pb(a);
    }
    fill(is_d,is_d + n,false);

    REP(i,k)
        get_d(c[i]);

    fill(is_z,is_z + n, false);
    REP(i,k)
        is_z[c[i]] = true;
    REP(i,n){
        if(is_z[i])
            continue;
        REP(j,G[i].size()){
            if(is_z[G[i][j]])
                continue;

            g[i].pb(P(G[i][j],is_d[G[i][j]] ? q : p));
        }
    }

    priority_queue<P,vector<P> ,greater<P> > que;
    fill(d,d + n,INF);
    d[0] = 0;
    que.push(P(0,0));

    while(!que.empty()){
        P p = que.top(); que.pop();
        int v = p.second;
        if(d[v] < p.first) continue;
        REP(i,g[v].size()){
            P e = g[v][i];
            if(d[e.first] > d[v] + e.second){
                d[e.first] = d[v] + e.second;
                que.push(P(d[e.first],e.first));
            }
        }
    }
    printf("%lld\n",d[n - 1] - (is_d[n - 1] ? q : p));
    return 0;
}

Measured memory_bytes: 29344
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
#define pii pair<int,int>
#define LL long long int
using namespace std;










void solve() {
    int k, a, b;
    cin >> k >> a >> b;
    bool flag = false;
    int ans;
    for (int i = a; i <= b; i++)
    {
        if (i % k == 0)
        {
            flag = true;
            break;
        }
    }
    if (flag)
        cout << "OK" << "\n";

    else
        cout << "NG" << "\n";







}




int main()
{


    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}


/*int n, q;
   cin >> n >> q;
   string s;
   cin >> s;
   transform(s.begin(), s.end(), s.begin(), ::tolower);
   int a[26] = {0};
   for (int i = 0; i < s.length(); i++)
   {
       a[s[i] - 'a']++;
   }
   int maxOcc = 0;
   for (int i = 0; i < 26; i++)
       maxOcc = max(maxOcc, a[i]);*/

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

using namespace std;

typedef long long ll;

int main(){
  ll N,M,s,t,e;
  cin >> N >> M;
  vector<ll> S,T,E,c(N);
  while(cin >> s >> t >> e, s){
    S.push_back(s-1);
    T.push_back(t-1);
    E.push_back(e);
  }
  ll L;
  cin >> L;
  for(int i = 0 ; i < L ; i++){
    ll b[M];
    for(int j = 0 ; j < N ; j++){
      c[j] = 0;
    }
    for(int j = 0 ; j < M ; j++){
      cin >> b[j];
    }
    for(int j = 0 ; j < (int)S.size() ; j++){
      c[S[j]] += b[T[j]]*E[j];
    }
    for(int j = 0 ; j < N ; j++){
      if(j > 0){ cout << " "; }
      cout << c[j];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 2528