akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

struct Edge {
    int from, to, cap, rev;
    Edge(int f, int t, int c, int r) : from(f), to(t), cap(c), rev(r) {} // 初期化
};

struct Graph {
    vector<vector<Edge>> G;
    Graph(int n = 0) : G(n) {} // 初期化

    vector<Edge>& operator[](int i) { return G[i]; }
    int size() { return G.size(); }
    void add_edge(int from, int to, int cap) {
        G[from].push_back(Edge(from, to, cap, (int)G[to].size()));
        G[to].push_back(Edge(to, from, 0, (int)G[from].size() - 1));
    } // 有向辺を加える
};

struct FordFulkerson {
    const int INF = 1e5;
    vector<int> used; 
    FordFulkerson(){}; // 初期化

    int dfs(Graph &G, int s, int g, int f) {  // 増加可能経路を見つけて増加分のフローを返す
        if (s == g) return f;
        used[s] = true;
        for (auto &e : G[s]) {
            if (!used[e.to] && e.cap > 0) {
                int d = dfs(G, e.to, g, min(f, e.cap));
                if (d > 0) {
                    e.cap -= d;
                    G[e.to][e.rev].cap += d;
                    return d;
                }
            }
        }
        return 0;
    } // 増加可能経路を見つけて増加分のフローを返す

    int max_flow(Graph &G, int s, int g) {
        int flow = 0;
        while (true) {
            used.assign(G.size(), false);
            int f = dfs(G, s, g, INF);  // f が増加分のフロー
            if (f == 0) {
                return flow;
            } else {
                flow += f;
            }
        }
        return 0;
    }
};

int main(){
    int n; cin >> n;
    int a[n], b[n], c[n], d[n];
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,n) cin >> c[i] >> d[i];

    Graph data(2*n+2);

    rep(i,n){
        rep(j,n){
            if(a[i] < c[j] && b[i] < d[j]){
                data.add_edge(i, j+n, 1);
            }
        }
    }
    rep(i,n) data.add_edge(2*n, i, 1);
    rep(i,n) data.add_edge(n+i, 2*n+1, 1);
    
    FordFulkerson ans;
    cout << ans.max_flow(data, 2*n, 2*n+1) << endl;
}



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

#define rep(i, n)for((i) = 0;(i) < (n);++(i))

string solve(string s){
	int i = 0, j;
	string tmp;
	rep(i, 100){
		tmp += "=";
		if(s == ">'" + tmp + "#" + tmp + "~")return "A";
	}
	tmp.clear();
	rep(i, 100){
		tmp += "Q=";
		if(s == ">^" + tmp + "~~")return "B";
	}
	return "NA";
}

int main(void){
	int i, j, n;
	string s;
	scanf("%d", &n);
	for(;n--;){
		cin >> s;
		cout << solve(s) << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3240
#include<bits/stdc++.h>
 
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define M        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;
 
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
	ll n;
	cin>>n;
	ll x=0, s=0;
	for(ll i=0; i<n; i++) {cin>>x; s+=x-1;}
	cout<<s;
	return 0;
}

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

#define roop(i, n) for(int i=0;i<n;i++)

using namespace std;
using ll = long long;
using ull = unsigned long long;

constexpr ull mod = 1e9+7;
constexpr int N = 13;
ull dp[100010][N];

int myPower(int a, int n) { // aのn乗の計算
	int x = 1;
	while (n > 0) { // 全てのbitが捨てられるまで
		if ( n & 1) { // 一番右のbitが１のとき
			x *= a;
		}
		a *= a;
		n >>= 1; // bit全体を右に1つシフトして一番右を捨てる
	}
	return x;
}

int main() {
	int n, i;
	string s;
	cin >> n >> s;
    s.push_back('#');
	int ans = 0;
	for (i = 0; i + 1 < s.size(); i++) {
		if (s[i] != s[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(int argc, char const *argv[])
{
	long long k,a,b;
	cin>>k>>a>>b;
	long long ans=k+1LL;
	if (a<b)
	{
		k-=a-1;
		long long tmp=(k/2)*(b-a)+a;
		if (k%2==1)
		{
			++tmp;
		}
		ans=max(ans,tmp);
	}
	cout<<ans<<endl;
	return 0;
}


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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

constexpr int atcoder_mod = 1e9+7;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

vector<ll> enum_div(ll n){
	vector<ll> ret;
	for(ll i=1;i*i<=n;++i){
		if(n%i==0){
			ret.push_back(i);
			if(i*i!=n){
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}

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

	int A=in(),B=in(),C=in();
	auto D = enum_div(C);
	int num=0;
	for(auto& x:D){
		if(A<=x && x<=B) num++;
	}
	
	out(num);
	return 0;
}



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

typedef struct Node {
	int key;
	struct Node *r,*l,*p;
} Node;

Node *root , *NIL;

Node * treeMinimum(Node *x)
{
	while(x->l != NIL) x = x->l;
	return x;
}

Node * find(Node *u , int k)
{
	while( u != NIL && k != u->key)
	{
		if( k < u->key)u = u->l;
		else u = u ->r;
	}
	return u;
}

Node * treeSuccessor(Node *x)
{
	if(x->r != NIL) return treeMinimum(x->r);
	Node* y = x->p;
	while(y != NIL && x == y->r)
	{
		x = y;
		y = y->p;
	}
	return y;
}

void treeDelete(Node *z)
{
	Node *y;
	Node *x;
	
	if(z->l == NIL || z->r == NIL) y = z;
	else y = treeSuccessor(z);
	
	if( y->l != NIL)
	{
		x = y->l;
	}
	else
	{
		x = y->r;
	}
	
	if( x != NIL)
	{
		x->p = y->p;
	}
	
	if(y->p == NIL)
	{
		root = x;
	}
	else
	{
		if( y == y->p->l)
		{
			y->p->l = x;
		}
		else
		{
			y->p->r = x;
		}
	}
	
	if(y != z)
	{
		z->key = y->key;
	}
	
	free(y);
}	

void insert( int k ) {
	Node *y = NIL;
	Node *x = root;
	Node *z;

	z = ( Node *)malloc( sizeof(Node) );
	z->key = k;
	z->l = NIL;
	z->r = NIL;

	while( x != NIL ) {
		y = x;
		if( z->key < x->key ) {
			x = x->l;
		} else {
			x = x->r;
		}
	}
	z->p = y;

	if( y == NIL ) {
		root = z;
	} else {
		if( z->key < y->key ) {
			y->l = z;
		} else {
			y->r = z;
		}
	}
}

void preorder( Node *u ) {

	if( u == NIL ) {
		return;
	}
	printf( " %d", u->key );
	preorder( u->l );
	preorder( u->r );
}

void inorder( Node *u ) {

	if( u == NIL ) {
		return;
	}
	inorder( u->l );
	printf( " %d", u->key );
	inorder( u->r );
}

int main(void)
{
	int  n , i , x;
	char com[100];
	char str1[] = "insert";
	char str2[] = "print";
	char str3[] = "delete";
	scanf("%d",&n);
	
	for( i = 0; i < n; i++)
	{
		while(scanf("%s",com) != EOF)
		
		if(com[0] == 'f')
		{
			scanf("%d",&x);
			Node *t = find(root,x);
			if( t != NIL) printf("yes\n");
			else printf("no\n");
		}
		else if(strcmp(com,str1) == 0)
		{
			scanf("%d",&x);
			insert(x);
		}
		else if(strcmp(com,str2) == 0)
		{
			inorder(root);
			printf("\n");
			preorder(root);
			printf("\n");
		}
		else if(strcmp(com,str3) ==0)
		{
			scanf("%d",&x);
			treeDelete(find(root,x));
		}
	}
	return 0;
}





Measured memory_bytes: 20448
#include <bits/stdc++.h>
#include <cmath>
#define pi 3.14159265358979
using namespace std;
typedef long long ll;
  

double degreeA(double h, double m) {
    double ans =  h * (360.0 / 12.0) + m * (6.0/12.0);
    return ans;
}

double degreeB(double m) {
    double ans = m * (360.0 / 60.0);
    return ans;
}

double pointX(double len, double degree) {
    double ans = len * sin(pi*degree/180.0);
    return ans;
}

double pointY(double len, double degree) {
    //double ans = len - len * cos(degree);
    double ans = len * cos(pi*degree/180.0);
    return ans;
}


int main(void){
    double a, b, h, m;
    cin >> a >> b >> h >> m;
    

    // ax, ay
    double ax = pointX(a, degreeA(h, m));
    //cout << a << endl;
    //cout << degreeA(h, m) << endl;
    //cout << sin(pi*270.0/180.0) << endl;
    //cout << pointX(a, degreeA(h, m)) << endl;
    double ay = pointY(a, degreeA(h, m));
    
    double bx = pointX(b, degreeB(m));
    double by = pointY(b, degreeB(m));
    //cout << pointY(b, degreeB(m)) << endl;
    
    double ans = abs(sqrt((bx-ax)*(bx-ax) + (by-ay)*(by-ay)));

    //cout << a << " " << b << endl; //3 4
    //cout << degreeA(h,m) << endl;  // 270 
    //cout << degreeB(m) << endl;    // 0

    //cout << ax << " " << ay << " " << bx << " " << by << endl;
    
    cout << setprecision(15) << ans << endl;
    return 0;
}

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

string rotate(string s) {
	return s.substr(1) + s[0];
}

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.length();
	rep(i, n) {
		if (s == t) {
			cout << "Yes" << endl;
			return 0;
		}
		s = rotate(s);
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
abc = input().split(' ')
max_ = max(abc)
abc =[ int(x) for x in abc]
s=  0
min_ = min(abc) 
if abc[0] == abc[1] == abc[2] :
    print(abc[0] + abc[1])

elif abc.count(max(abc)) == 2:
    print(max(abc) + min(abc))

    
else:    
    for i in abc:
        if i != max(abc):
            s += i
    print(s)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
using namespace std;
int main(){
  int kazu = 0;
  int dame = 0;
  int r,s,p;
  string cpu;
  int kotae = 0;
  cin >> kazu >> dame >> r >> s >> p >> cpu;
  vector<int> kattaka(kazu);
  for(int i = 0;i <= kazu - 1;i++){
    if(i < dame){
      if(cpu[i] == 'r'){
        kotae += p;
      }
      else if(cpu[i] == 's'){
        kotae += r;
      }
      else{
        kotae += s;
      }
      kattaka[i] = 1;
    }
    else if(cpu[i - dame] == cpu[i] && kattaka[i - dame] == 1){
      kattaka[i] = 0;
    }
    else{
      if(cpu[i] == 'r'){
        kotae += p;
      }
      else if(cpu[i] == 's'){
        kotae += r;
      }
      else{
        kotae += s;
      }
      kattaka[i] = 1;
    }
  }
  cout << kotae << endl;
  return 0;
}

Measured memory_bytes: 896
import java.util.*;

public class Main {
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int x = sc.nextInt();
	if (x < 600) {
	    System.out.print(8);
	} else if (x < 800) {
	    System.out.print(7);
	} else if (x < 1000) {
	    System.out.print(6);
	} else if (x < 1200) {
	    System.out.print(5);
	} else if (x < 1400) {
	    System.out.print(4);
	} else if (x < 1600) {
	    System.out.print(3);
	} else if (x < 1800) {
	    System.out.print(2);
	} else {
	    System.out.print(1);
	}
    }
}


Measured memory_bytes: 35800
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  string s;
  cin >> s;
  sort(all(s));
  if(s=="abc") pr("Yes");
  else pr("No");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


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

route = [[0, 0, 0]]
judge = "Yes"
for _ in range(n):
  m = [int(i) for i in input().split()]
  route.append(m)
for i in range(1, n+1):
  delt = abs(route[i][0] - route[i-1][0])
  absx = abs(route[i][1] - route[i-1][1])
  absy = abs(route[i][2] - route[i-1][2])
#  print(delt, absx, absy)
#  s1 = delt >= (absx + absy)
# s2 = (delt - (absx +absy))
# print(s1, s2)
  if (delt >= (absx + absy)) and (delt - (absx +absy)) % 2 == 0:
    continue
  else:
    judge = "No"
    break
    
print(judge)
  

Measured memory_bytes: 21156
import math


def main():
    # n = int(input())
    # a, b = map(int, input().split())
    # h = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

    s = list(input())
    # 1010...
    count1 = 0
    # 0101...
    count2 = 0
    for i in range(len(s)):
        if i % 2 == 0 and s[i] != "1":
            count1 += 1
        if i % 2 != 0 and s[i] != "0":
            count1 += 1
        if i % 2 == 0 and s[i] == "1":
            count2 += 1
        if i % 2 != 0 and s[i] == "0":
            count2 += 1

    print(min(count1, count2))


if __name__ == '__main__':
    main()


Measured memory_bytes: 77132
def gcd(a, b):
    while b:
        a %= b
        a, b = b, a
    return a


n = int(input())
nums = list(map(int, input().split()))

prefix_gcd = []

prefix_gcd.append(nums[0])

for i in nums[1:]:
    prefix_gcd.append(gcd(i,prefix_gcd[-1]))

postfix_gcd = []
postfix_gcd.append(nums[-1])

for j in range(n-2,-1,-1):
    postfix_gcd.append(gcd(nums[j],postfix_gcd[-1]))

postfix_gcd = postfix_gcd[::-1]

ans = 1

for i in range(n):
    # del i
    if i == 0:
        ans = max(ans,postfix_gcd[i+1])
    elif i == n-1:
        ans = max(ans,prefix_gcd[i-1])
    else:
        ans = max(ans, gcd(prefix_gcd[i-1], postfix_gcd[i+1]))
print(ans)


Measured memory_bytes: 14436
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b;
	cin>>a;
	b=a;
	reverse(b.begin(),b.end());
	for(int i=0;i<b.size();i++)
	{
		if(b[i]=='b')b[i]='d';
		else if(b[i]=='d')b[i]='b';
		else if(b[i]=='p')b[i]='q';
		else if(b[i]=='q')b[i]='p';
	}
	if(a==b)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

int N;
std::string W[110];

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

    std::cin >> N;

    for(int i=0;i<N;++i){
        std::cin >> W[i];
    }

    for(int i=1;i<N;++i){
        bool dup = false;
        for(int j=0;j<i;++j){
            if(W[j] == W[i]){
                dup = true;
                break;
            }
        }

        if(dup || W[i][0] != W[i-1][W[i-1].size() - 1]){
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
}


Measured memory_bytes: 256
def solve(string):
    n, m, *hab = map(int, string.split())
    h, ab = hab[:n], hab[n:]
    t = [True] * n
    for _a, _b in zip(*[iter(ab)] * 2):
        if h[_a - 1] <= h[_b - 1]:
            t[_a - 1] = False
        if h[_a - 1] >= h[_b - 1]:
            t[_b - 1] = False
    return str(sum(t))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 44008
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

void solveA(){
    ll N,K; cin >> N >> K;
    if(N%K == 0) cout << 0 << endl;
    else cout << 1 << endl;
}
void solveB(){
    ll N; cin >> N;
    vector<int> dp(1000);
    dp[0] = true;
    for(int i = 0; i < 100;i++){
        for(int j = 0; j < 500;j++){
            if(dp[j]){
                dp[j+4] = true;
                dp[j+7] = true;
            }
        }
    }
    if(dp[N]) cout << "Yes" << endl;
    else cout << "No" << endl;
}
void solveC(){
    ll N; cin >> N;
    ll absN = abs(N);
    bitset<64> bit(absN);
}
void solveD(){
    ll N,M; cin >> N >> M;
    vector<ll> A(N); for(auto& in:A) cin >> in;
    for(int i = 0; i < N;i++) A[i]%=M;
    vector<ll> cusum(N+1);
    for(int i = 0; i < N;i++){
        cusum[i+1] = cusum[i] + A[i];
        cusum[i+1]%=M;
    }
    map<ll,ll> mp;
    for(int i = 0; i <= N;i++) mp[cusum[i]]++;
    ll ans = 0;
    for(auto p:mp){
        ll cnt = p.second;
        ans += cnt*(cnt-1)/2;
    }
    cout << ans << endl;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
//    solveA();
//    solveB();
//    solveC();
    solveD();
    return 0;
}


Measured memory_bytes: 5760
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <queue>
#include <cstdlib>
#include <ctime>
#include <cassert>

#define pii pair <int, int>

#define mp make_pair

#define f first
#define s second

#define pb push_back

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;

const int N = 1e5 + 10;
const int NN = 20;
const int INF = 1e9 + 7;

int dist(int x, int y) {
    if (x <= y) return y - x;
    return INF;
}

int main() {
    #define fn "balls"
    #ifdef witch
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #else
//        freopen(fn".in", "r", stdin);
//        freopen(fn".out", "w", stdout);
    #endif
    int x, y;
    cin >> x >> y;
    cout << min(min(dist(-x, -y) + 1, min(dist(-x, y), dist(x, -y))) + 1, dist(x, y));
    return 0;
}

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

namespace ITP1_4_A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            Console.WriteLine("{0} {1} {2}", 
                input[0] / input[1], input[0] % input[1], ((double)input[0] / input[1]).ToString("f5"));
        }
    }
}



Measured memory_bytes: 18380
// includes, macros {{{
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <climits>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
using namespace std;

#define EPS (1e-10)
#define equals(a, b) (fabs((a)-(b)) < EPS)

#define rep(i, s, e)    for (int i = (s); i < (int)(e); i++)
//#define PB(e) push_back(e)
//#define MP(a, b) make_pair(a, b)

// for debug
#define kita            cout << "kita\n"
#define print2(i, n)    cout << (i) << ": " << (n) << endl
#define print3(i, j, n)     cout << "(" << (i) << ", " << (j) << ") : " << (n) << endl
#define print4(i, j, n, m)  cout << "(" << (i) << ", " << (j) << ") : " << (n) << ", " << (m) << endl
#define print_mat(mat, h, w) for(int i=0;i<(h);i++){for(int j=0;j<(w);j++){cout << mat[i][j] << " ";}cout << endl;}
 
typedef long long ll;
typedef unsigned long long ull; // }}}

int a, b;

int main(){
    cin >> a >> b;
    if(a > 0){
        cout << "Positive" << endl;
    }else if(a <= 0 && b >= 0){
        cout << "Zero" << endl;
    }else if(b < 0){
        if((b-a)%2!=0){
            cout << "Positive" << endl;
        }else{
            cout << "Negative" << endl;
        }
    }
    return 0;
}


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



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	int A, B, C; cin >> A >> B >> C;

	bool ans = false;
	REP(i,1000){
		if((A*i)%B == C) ans = true;
	}

	cout << (ans ? "YES" : "NO") << endl;
	return 0;

}


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

const int RLEN=1<<18|1;
inline char nc() {
    static char ibuf[RLEN],*ib,*ob;
    (ib==ob) && (ob=(ib=ibuf)+fread(ibuf,1,RLEN,stdin));
    return (ib==ob) ? -1 : *ib++;
}
inline int rd() {
    char ch=nc(); int i=0,f=1;
    while(!isdigit(ch)) {if(ch=='-')f=-1; ch=nc();}
    while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=nc();}
    return i*f;
}

const int N=2e5+50;
vector <pLL> edge[N];
vector <pLL> f[N];
vector <pLL> tl, tr;
LL lim;
inline void inc(int x,const pLL &t) {
    if(f[x].size() && f[x].back()<=t) return;
    while(f[x].size() && f[x].back().second>=t.second) f[x].pop_back();
    f[x].push_back(t);
}
inline bool dfs(int x,int fa) {
    f[x].clear();
    if(edge[x].size()==1) {f[x].push_back(pLL(0,0)); return true;} 
    LL lc,rc,disl,disr; int fir=0;
    for(int e=edge[x].size()-1;e>=0;e--) {
        int v=edge[x][e].first; if(v==fa) continue;
        if(!dfs(v,x)) return false;
        if(!fir) fir=1, lc=v, disl=edge[x][e].second;
        else rc=v, disr=edge[x][e].second;
    }
    tl.clear(), tr.clear(); LL lim2=lim-disl-disr;
    if(lim2<0) return false; 
    for(int p1=0,p2=0;p2<f[rc].size();p2++) {
        while(p1<f[lc].size() && f[lc][p1].first+f[rc][p2].second>lim2) ++p1;
        if(p1==f[lc].size()) break;
        tl.push_back(pLL(f[rc][p2].first+disr,f[lc][p1].second+disl));
    }
    for(int p1=0,p2=0;p1<f[lc].size();p1++) {
        while(p2<f[rc].size() && f[lc][p1].second+f[rc][p2].first>lim2) ++p2;
        if(p2==f[rc].size()) break;
        tr.push_back(pLL(f[lc][p1].first+disl,f[rc][p2].second+disr));
    }
    int pl=0, pr=0;
    while(pl<tl.size() && pr<tr.size()) {
        if(tl[pl].first>tr[pr].first) inc(x,tl[pl++]);
        else inc(x,tr[pr++]);
    }
    while(pl<tl.size()) inc(x,tl[pl++]);
    while(pr<tr.size()) inc(x,tr[pr++]);
    return f[x].size()>0;
}
inline bool check(LL v) { lim=v; return dfs(1,0);}
int main() {
    int n=rd();
    for(int i=2;i<=n;i++) {
        int x=rd(), w=rd();
        edge[x].push_back(pLL(i,w));
        edge[i].push_back(pLL(x,w));
    }
    LL l=0, r=1e12, ans=0;
    while(l<=r) {
        LL mid=(l+r)>>1;
        if(check(mid)) ans=mid, r=mid-1;
        else l=mid+1;
    } cout<<ans;
}


Measured memory_bytes: 40036
def solve():
    X,K,D = [int(i) for i in input().split()]
    abs_X = abs(X)
    if D*K <= abs_X:
        print(abs_X - D*K)
    else:
        steps2pivot = abs_X // D
        abs_X -= steps2pivot * D
        rest = K - steps2pivot
        if rest % 2 == 0:
            print(abs_X)
        else:
            print(abs(abs_X-D))

if __name__ == "__main__":
    solve()

Measured memory_bytes: 9204
N = int(input())

def check_753(s):
  s = str(int(s))
  a = ''.join(sorted(list(set(s))))
  if a == '357':
    return True
  else:
    return False

def shi(s):
  if int(s) > N:
    return 0
  if check_753(s):
    ret = 1
  else:
    ret = 0
  for i in '753':
    ret += shi(s+i)
  return ret

print(shi('0'))


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

const int MAX_M = 1e9;

long long gcd(long long a, long long b) {
    if (a < b) {
        return gcd(b, a);
    } else if (b == 0) {
        return a;
    } else {
        while (a % b != 0) {
            int r = b;
            b = a % b;
            a = r;
        }
        return b;
    }
}

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

int main() {
    int N, M; cin >> N >> M;
    vector<int> A(N); for(int i = 0; i < N; i++) cin >> A[i];
    ll k = 1; int a = A[0];
    while(a % 2 == 0) {
        a /= 2;
        k *= 2;
    }
    ll l = k / 2;
    for (int i = 0; i < N; i++) {
        if (A[i] % k != 0 || A[i] % (k * 2) == 0) {
            l = M+1;
            break;
        }
        l = lcm(l, (A[i] / k));
        if (l > M) {
            break;
        }
    }
    cout << (M/l + 1) / 2 << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <cstring>
#include <map>

#include <inttypes.h>
using namespace std;

int main()
{
	int64_t W;
	int32_t N;
	scanf("%d%" PRId64, &N, &W);

	int64_t first_w;
	int32_t first_v;
	scanf("%" PRId64 "%d", &first_w, &first_v);

	vector<vector<int32_t>> value(4);
	value[0].push_back(first_v);
	for (int32_t i = 1; i < N; i++) {
		int64_t w;
		int32_t v;
		scanf("%" PRId64 "%d", &w, &v);
		w -= first_w;
		value[w].push_back(v);
	}

	int64_t weights[4];
	for (int32_t i = 0; i < 4; i++) {
		sort(value[i].begin(), value[i].end(), greater<int32_t>());
		weights[i] = first_w + i;
	}

	int32_t res = 0;
	for (int64_t first = 0; first <= (int64_t)value[0].size(); first++) {
		for (int64_t second = 0; second <= (int64_t)value[1].size(); second++) {
			for (int64_t third = 0; third <= (int64_t)value[2].size(); third++) {
				for (int64_t forth = 0; forth <= (int64_t)value[3].size(); forth++) {
					if (first * weights[0] + second * weights[1] +
					    third * weights[2] + forth * weights[3] > W)
						continue;

					int32_t total_value = 0;
					for (int64_t i = 0; i < first; i++)
						total_value += value[0][i];
					for (int64_t i = 0; i < second; i++)
						total_value += value[1][i];
					for (int64_t i = 0; i < third; i++)
						total_value += value[2][i];
					for (int64_t i = 0; i < forth; i++)
						total_value += value[3][i];
					res = max(res, total_value);
				}
			}
		}
	}

	printf("%d\n", res);

	return 0;
}

Measured memory_bytes: 256
import numpy as np

n = int(input())
a = np.array(input().split(), np.int64)
MOD = 10**9 + 7

max_num = np.max(a)
max_digit = len(format(max_num, 'b'))

ans = 0

for digit in range(max_digit):
    b = (a >> digit) & 1
    one = np.count_nonzero(b)
    zero = n - one
    ans += 2 ** digit *  (one * zero)
    ans %= MOD

print(ans)

Measured memory_bytes: 62780
import java.util.*;

public class Main {
    public static int MAX = 1000001;
    
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        
        while (true) {
            int x = sc.nextInt();
            int y = sc.nextInt();
            int p = sc.nextInt();
            if (x == 0 && y == 0 && p == 0) break;
            
            int max = -2000000000;
            
            for (int i = 1; i < p / 2 + 1; i++) {
                int iTax = (int)(i * (100 + x) / 100);
                int jTax = p - iTax;
                int newVal = -2000000000;
                int j = (int)(jTax / (100 + x) / 100);
                while (true) {
                    j++;
                    if ((int)(j * (100 + x) / 100) > p - iTax) {
                        j--;
                        break;
                    }
                }
                if ((int)(i * (100 + x) / 100) + (int)(j * (100 + x) / 100) == p) {
                    newVal = (int)(i * (100 + y) / 100) + (int)(j * (100 + y) / 100);    
                }
                    
                
                max = Math.max(max, newVal);
            }
            
            System.out.println(max);
        }
    }
    
}




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

int mcm(int p[], int n) {
	int m[n+1][n+1];
	memset(m, 0, sizeof(m));

	for (int s = 0; s < n; s++) {
		for (int i = 1, j = s + 2; j <= n; i++, j++) {
			m[i][j] = 1 << 30;
			for (int k = i; k <= j; k++) {
				m[i][j] = min(m[i][j], m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j]);
			}
		}
	}
	return m[1][n];
}

int main() {
	int n, d;
	cin >> n;
	int p[n+1];
	for (int i = 0; i < n-1; i++) {
		cin >> p[i] >> d;
	}
	cin >> p[n-1] >> p[n];
	int ans = mcm(p, n);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3076
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    int A,B,K;
    cin >> A >> B >> K;
    for(int i=0;i<K;i++){
        if(A+i<=B){
            cout << A+i << endl;
        } 
    }
    for(int i=1;i<=K;i++){
        if(A+K<=B-K+i){
            cout << B-K+i << endl;
        }
    }
}

Measured memory_bytes: 3628
#include <algorithm>
#include <cassert>
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define per(i, a, b) for (auto i = (b) - 1; i >= (a); --i)
#define trav(x, v) for (auto &x : v)

#define sz(x) int((x).size())
#define eb(x...) emplace_back(x)
#define ff first
#define ss second

using ll = int64_t;

template<class T> bool ckmin(T& a, const T& b) { return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

using vi = vector<int>;
using vvi = vector<vector<int>>;
constexpr int M = 1e9 + 7;

int n;

vvi operator*(const vvi& a, const vvi& b) {
	vvi c(n, vi(n));
	rep(i, 0, n)
		rep(j, 0, n)
			rep(k, 0, n)
				c[i][j] = (c[i][j] + 1ll * a[i][k] * b[k][j]) % M;
	return c;
}

vvi bpow(vvi a, ll b) {
	assert(b > 0);
	vvi res(a);
	for (--b; b; b >>= 1) {
		if (b & 1) res = res * a;
		a = a * a;
	}
	return res;
}

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

	ll k; cin >> n >> k;
	vvi a(n, vi(n));
	rep(i, 0, n) rep(j, 0, n) cin >> a[i][j];
	auto res = bpow(a, k);
	ll ans = 0;
	rep(i, 0, n) rep(j, 0, n) (ans += res[i][j]) %= M;
	cout << ans;
}

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

const int INF = 1<<28;

struct Edge {
  int to, cost, cap, rev;
  Edge(int to, int cost, int cap, int rev)
    : to(to), cost(cost), cap(cap), rev(rev) {}
  Edge() {}
};

typedef vector<vector<Edge> > Graph;

void addEdgeF(int from, int to, int cost, int cap, Graph &g) {
  g[from].push_back(Edge(to,cost,cap,g[to].size()));
  g[to].push_back(Edge(from,-cost,0,(int)g[from].size()-1));
}

int dfsF(int v, int t, int f, vector<int> &used, Graph &g) {
  if(v == t) return f;
  used[v] = true;
  for(int i = 0; i < g[v].size(); ++i) {
    Edge &e = g[v][i];
    if(!used[e.to] && e.cap > 0) {
      int d = dfsF(e.to, t, min(f, e.cap), used, g);
      if(d > 0) {
        e.cap -= d;
        g[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int maxFlow(int s, int t, Graph g) {
  int flow = 0;
  while(1) {
    vector<int> used(g.size());
    int f = dfsF(s, t, INF, used, g);
    if(f == 0) break;
    flow += f;
  }
  return flow;
}

const int MAXN = 101;
const int MAXM = 101;
int N, M;
double A[MAXN], B[MAXN], V[MAXN];
double C[MAXM], D[MAXM];

double getT(int i, int j) {
  return sqrt(pow(A[i]-C[j], 2.0) + pow(B[i]-D[j], 2.0)) / V[i];
}

bool ok(double t) {
  int V = N+M+2;
  Graph g(V);
  int src = V - 1;
  int dst = V - 2;
  for(int i = 0; i < N; ++i) {
    addEdgeF(src, i, 0, 1, g);
  }
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < M; ++j) {
      if(getT(i, j) <= t) {
        addEdgeF(i, N+j, 0, 1, g);
      }
    }
  }
  for(int j = 0; j < M; ++j) {
    addEdgeF(N+j, dst, 0, 1, g);
  }
  return maxFlow(src, dst, g) == M;
}

int main() {
  while(cin >> N >> M && (N|M)) {
    for(int i = 0; i < N; ++i) {
      cin >> A[i] >> B[i] >> V[i];
    }
    for(int j = 0; j < M; ++j) {
      cin >> C[j] >> D[j];
    }
    vector<double> ts;
    for(int i = 0; i < N; ++i) {
      for(int j = 0; j < M; ++j) {
        ts.push_back(getT(i, j));
      }
    }
    sort(ts.begin(), ts.end());
    int ans = -1;
    for(int l = 0, r = ts.size(); r-l; ) {
      int m = (l + r) / 2;
      if(ok(ts[m])) {
        ans = m;
        r = m;
      } else {
        l = m+1;
      }
    }
    printf("%.8f\n", ts[ans]);
  }
  return 0;
}

Measured memory_bytes: 2008
#include<bits/stdc++.h>
/*
	初始位置在石头1，要求跳到石头N
	每一次可以跳1格或者2格，
	每次从i跳到j，需要代价abs(height[i] - height[j]) 
	求从1跳到N的最小代价
	算法复杂度：O(n) 
*/
using namespace std;
int main(){
	int n;
	scanf("%d", &n);
	int height[n + 1];
	int dp[n + 1];
	for(int i = 1; i <= n; i++){
		scanf("%d", &height[i]);
	}
	dp[1] = 0;
	dp[2] = abs(height[1] - height[2]);
	for(int i = 3; i <= n; i++){
		dp[i] = min(dp[i - 1] + abs(height[i - 1] - height[i]), dp[i - 2] + abs(height[i - 2] - height[i]));
	}
	printf("%d", dp[n]);
	return 0;
} 

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

int main(){
  string S;
  cin >> S;
  int L=S.size();
  int Ans=1;
  if(S.at(0)=='A' && S.at(1)>='a' && S.at(1)<='z' && S.at(L-1)>='a' && S.at(L-1)<='z'){
  }
  else{
    Ans=0;
  }
  int Cat=0;
  int Ccount=0;
  for(int i=2; i<L-1; i++){
    if(S.at(i)=='C'){
      Cat=i;
      Ccount++;
    }
  }
  if(Ccount!=1){
    Ans=0;
  }
  else{
    for(int i=2; i<L-1; i++){
      if(S.at(i)=='C'){
      }
      else{
        if(S.at(i)>='a' && S.at(i)<='z'){
        }
        else{
          Ans=0;
        }
      }
    }
  }
  if(Ans==1){
    cout << "AC" << endl;
  }
  else{
    cout << "WA" << endl;
  }
}

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

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long int ll;
typedef vector<ll> vll;

vll ans;
void init() {
	ans.push_back(2LL);
	ans.push_back(1LL);
	for(int i = 2; i <= 86; i++) {
		ll tmp = (ans[i-1] + ans[i-2])*1LL;
		ans.push_back(tmp);
	}
}

int n;
int main() {
	init();
	cin >> n;
	// cout << n << endl;
	cout << ans[n] << endl;
	return 0;
}

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

using namespace std;

int main() {
	int H, W; cin >> H >> W;

	auto grid = vector<vector<char>>(H);
	for (auto &row: grid) {
		row = vector<char>(W, '0');
	}

	for (auto j = 0; j < H; ++j) {
		string s; cin >> s;

		for (auto i = 0; i < W; ++i) {
			if (s[i] == '#') {
				grid[j][i] = '#';
				for (auto y = j - 1; y <= j + 1; ++y) {
					for (auto x = i - 1; x <= i + 1; ++x) {
						if (x >= 0 && x < W && y >= 0 && y < H && grid[y][x] != '#') {
							grid[y][x]++;
						}
					}
				}
			}
		}
	}

	for (auto j = 0; j < H; ++j) {
		for (auto i = 0; i < W; ++i) {
			cout << grid[j][i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

ll dp[3][200000];

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

    int n;
    cin >> n;

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

    int m = 1 + n % 2;//余裕の個数

    for (int k = 0; k <= m; k++) {
        for (int i = 0; i < n; i++) {
            dp[k][i] = -(1LL << 60);
        }
    }

    for (int i = 0; i <= m; i++) {
        dp[i][i] = a[i];
    }

    for (int i = 2; i < n; i++) {
        for (int k = 0; k <= m; k++) {
            chmax(dp[k][i], dp[k][i - 2] + a[i]);
        }
        if (i - 3 < 0) continue;
        for (int k = 1; k <= m; k++) {
            chmax(dp[k][i], dp[k - 1][i - 3] + a[i]);
        }
        if (i - 4 < 0) continue;
        for (int k = 2; k <= m; k++) {
            chmax(dp[k][i], dp[k - 2][i - 4] + a[i]);
        }
    }

    ll r = -(1LL << 60);
    for (int k = 0; k <= m; k++) {
        chmax(r, dp[k][n - 1 - (m - k)]);
    }

    //for (int k = 0; k <= m; k++) {
    //    for (int i = 0; i < n; i++) {
    //        cout << dp[k][i] << ' ';
    //    }
    //    cout << '\n';
    //}

    cout << r << endl;

    return 0;
}

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

const int N = 3005 , mod = 1e9 + 7 ;
long long inv2 = 5e8 + 4 , mul = 1;
int n , q , a[N] , p[N][N] , ans = 0;

int main() {
    scanf("%d %d" , &n , &q);
    for(int i = 1 ; i <= n ; ++i) scanf("%d" , a + i);
    for(int i = 1 ; i <= n ; ++i)
        for(int j = 1 ; j <= n ; ++j) p[i][j] = (a[i] < a[j]);
    while(q--) {
        mul = (mul << 1) % mod;
        int a , b;
        scanf("%d %d" , &a , &b);
        for(int i = 1 ; i <= n ; ++i)
            if(i != a && i != b) {
                p[i][b] = p[i][a] = (p[i][a] * inv2 + p[i][b] * inv2) % mod;
                p[b][i] = p[a][i] = (p[b][i] * inv2 + p[a][i] * inv2) % mod;
            }
        p[a][b] = p[b][a] = (p[a][b] * inv2 + p[b][a] * inv2) % mod;
    }
    for(int i = 1 ; i <= n ; ++i)
        for(int j = i + 1 ; j <= n ; ++j) ans = (ans + mul * p[j][i]) % mod;
    printf("%d\n" , ans);
    return 0;
}

Measured memory_bytes: 35456
#include <iostream>

using namespace std;

int main() {
	int idx = 0;
	for (int i = 0; i  < 5; i++) {
		int num = 0;
		cin >> num;
		if (num == 0) {
			idx = i + 1;
		}
	}
	cout << idx << endl;
	return 0;
}

Measured memory_bytes: 3620
import java.io.*;

public class Main {
    public static void main(String[] args) throws IOException{
       
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        while (true) {

            String str = br.readLine();

            if (str.equals("0"))
            break;

            int len = str.length();
            int sum = 0;
    
            for(int i = 0;i < len; i++){
                sum += str.charAt(i) - '0';
            }
            System.out.println(sum);
           
        }
    }
}


Measured memory_bytes: 24256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let ss = read::<String>();
    let t = read::<String>();

    if ss.len() < t.len() {
        println!("UNRESTORABLE");
        return;
    }

    for start in (0..(ss.len() - t.len() + 1)).rev() {
        let ok = ss
            .chars()
            .skip(start)
            .zip(t.chars())
            .all(|(cs, ct)| cs == '?' || cs == ct);
        if ok {
            let s: String = ss
                .chars()
                .take(start)
                .map(|c| if c == '?' { 'a' } else { c })
                .chain(t.chars())
                .chain(
                    ss.chars()
                        .skip(start + t.len())
                        .map(|c| if c == '?' { 'a' } else { c }),
                )
                .collect();
            println!("{}", s);
            return;
        }
    }

    println!("UNRESTORABLE");
}


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

const int maxn = 2e5+10;
typedef long long ll;



/*
1
p*n-n+2 .... p*n+1
(p-1)*n+2, .... p*n+1
all minus 2
(p-1)*n, ...., (p-1)*n+n-1
 */
ll n, q, v, u;
int main()
{
  scanf("%lld %lld", &n, &q);
  for (int i = 1; i <= q; ++i)
    {
      scanf("%lld %lld", &u, &v);
      if (n == 1)
	{
	  printf("%lld\n", min(u, v));
	  continue;
	}
      while (u != v)
	{
	  if (u < v)
	    swap(u, v);
	  u = (u-2)/n+1;
	}
      printf("%lld\n", u);
    }
}


Measured memory_bytes: 1280
#include <iostream>
#include <vector>
#include <algorithm>

#define all(c) c.begin(), c.end()

using namespace std;

typedef long long ll;

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> a(n+1, -(1 << 30));
    for(int i=1;i<=n;++i) cin >> a[i];
    int max_a = *max_element(all(a));

    vector<vector<ll>> total(2, vector<ll>(n+1, 0)); // インデックスが偶数の累積和，インデックスが奇数の累積和
    total[1][1] = a[1];
    for(int j=2;j<=n;++j) {
        total[j%2][j] = total[j%2][j-2] + a[j];
        total[1-j%2][j] = total[1-j%2][j-1];
    }


    int q;
    for(int i=0;i<m;++i) {
        cin >> q;

        // 青木くんが最初に取るカードのインデックス
        int nearest_i = distance(a.begin(), lower_bound(all(a), q));
        if(abs(a[nearest_i-1]-q ) <= abs(a[nearest_i]-q)) {
            --nearest_i;
        }

        // 青木くんと高橋くんの戦略が一致
        if(nearest_i >= n) {
            cout << total[n%2][n] << endl;
            continue;
        }

        // 高橋くん区間の開始インデックスを探索
        int ng = nearest_i, ok = n;
        int mid = n;
        while(ok-ng > 1) {
            mid = (ng+ok)/2;
            // 青木くんと高橋くんそれぞれから見た a[mid] の優先順位
            int aoki_rank = mid - distance(a.begin(), lower_bound(all(a), q - (a[mid]-q))) + 1;
            int takahashi_rank = n - mid + 1;
            if(aoki_rank < takahashi_rank) {
                ng = mid;
            } else {
                ok = mid;
            }
        }
        int aoki_left = n - (n-ok+1)*2 + 1;

        cout << (aoki_left?total[1-aoki_left%2][aoki_left-1]:0) + total[0][n]+total[1][n]-total[0][ok-1]-total[1][ok-1] << endl;
    }
}


Measured memory_bytes: 3696
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ld INF = (ld)10000000000000;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
map<int, int> mp;
vector<int> u;
int main() {
	int n, m; cin >> n >> m;
	vector<int> a, b;
	rep(i, n) {
		int z; cin >> z; a.push_back(z);
		mp[z]++; u.push_back(z);
	}
	rep(i, m) {
		int z; cin >> z; b.push_back(z);
		mp[z]++; u.push_back(z);
	}
	//and
	vector<int> an;
	rep(i, n) {
		if (mp[a[i]] >= 2)an.push_back(a[i]);
	}
	rep(i, m) {
		if (mp[b[i]] >= 2)an.push_back(b[i]);
	}
	sort(an.begin(), an.end());
	int len = unique(an.begin(), an.end()) - an.begin();
	cout << len << " ";
	sort(u.begin(), u.end());
	int len2 = unique(u.begin(), u.end()) - u.begin();
	cout << len2 << endl;
	rep(i, len) {
		cout << an[i] << endl;
	}
	rep(i, len2) {
		cout << u[i] << endl;
	}
	//stop
	return 0;
}




Measured memory_bytes: 15260
#include <stdio.h>
int main(){
  int A[100];
  int i,min,j,len,count=0,sw,t;
  scanf("%d",&len);
  for(i=0;i<len;i++){
    scanf("%d",&A[i]);
  } 
  for(i=0;i<len;i++){
    min=i;
    for(j=i;j<len;j++){
      if(A[j]<A[min]){
	min=j;
      }
    }
    if(min>i){
      sw=A[i];
      A[i]=A[min];
      A[min]=sw;
      count++;
    }
  }
  
  
  for(i=0;i<len;i++){
    printf("%d",A[i]);
    if(i==len-1) printf("\n");
    else printf(" ");
  }
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <stdio.h>

using namespace std;

//typedefリスト
typedef vector<int> vint;
typedef vector<string> vstr;




int main(void) {
	long long int N, ans;
	ans = 1;
	cin >> N;
	for (int i = 1; i <= N; i++) {
		ans*= i;
		ans=ans%(1000000000+7);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
/**
 *   @author: pr4shan7 (प्रशांत)
 */
#include <bits/stdc++.h>
using namespace std;

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

    string s;
    cin >> s;
    if (s == "Sunny")
        cout << "Cloudy";
    else if (s == "Cloudy")
        cout << "Rainy";
    else {
        cout << "Sunny";
    }
    cout << '\n';

    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		sc.close();
		long x = n;
		for(int i = 0; i <= n; ++i) {
			long cnt = 0;
			long t = i;
			while(t > 0) {
				cnt += t % 6;
				t /= 6;
			}
			t = n - i;
			while(t > 0) {
				cnt += t % 9;
				t /= 9;
			}
			x = Math.min(x,  cnt);
		}
		
		System.out.println(x);
	}

}


Measured memory_bytes: 23124
#include <algorithm>
#include <array>
#include <cmath>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMod = 1e9 + 7;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

ll f(char c) {
  switch (c) {
    case 'a': {
      return 0;
    }
    case 'b': {
      return 1;
    }
    default: {
      return 2;
    }
  }
}

int main() {
  init();

  string A, B, C;
  cin >> A >> B >> C;

  ll ai = 0, bi = 0, ci = 0;
  ll turn = 0;
  while (true) {
    switch (turn) {
      case 0: {
        if (ai == A.size()) {
          cout << "A" << endl;
          return 0;
        }
        turn = f(A[ai]);
        ai++;
        break;
      }
      case 1: {
        if (bi == B.size()) {
          cout << "B" << endl;
          return 0;
        }
        turn = f(B[bi]);
        bi++;
        break;
      }
      default: {
        if (ci == C.size()) {
          cout << "C" << endl;
          return 0;
        }
        turn = f(C[ci]);
        ci++;
        break;
      }
    }
  }

  return 0;
}


Measured memory_bytes: 256