akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

int main(void)
{
	int n; cin>>n;
	string s; cin>>s;
	int x = 0;
	int max = 0;
	for(int i = 0; i < n; i++){
		if(s[i] == 'I') x++;
		else if(s[i] == 'D') x--;
		if(max < x) max = x;
	}
	
	cout<<max<<endl;
	return 0;
}



Measured memory_bytes: 256
/**
 * 挿入ソート
 */
fun main(args: Array<String>) {

    Main.init()

    Main.execute()
}

class Main {

    companion object {

        // 連結リスト
        private lateinit var list: MutableList<Int>
        private var size: Int = 0

        fun init() {

            size = readLine()!!.toInt()

            val inputs = readLine()!!.split(" ")

            list = inputs.map {
                it.toInt()
            }.toMutableList()
        }

        fun execute() {
            for (index in 0 until size) {
                var targetIndex = index

                for (compareIndex in 0 until targetIndex) {
                    if (list[targetIndex] < list[compareIndex]) {
                        // 交換
                        val temp = list[targetIndex]
                        list.removeAt(targetIndex)
                        list.add(compareIndex, temp)
                        break
                    }
                }

                println(list.joinToString(" "))
            }
        }
    }
}




Measured memory_bytes: 33216
#include <bits/stdc++.h>
 
using namespace std;
#define repr(i,a,b) for (int i=a; i<b; i++)
#define rep(i,n) for (int i=0; i<  n; i++)
 
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
 
const long long INF = 1LL << 60;
 
bool dp[100100];
 
int main () {
    long double A;
    long double B;
 
    cin >> A >> B;
 
    long double C = A*B;
    string S = to_string(C);
 
    for( auto i :S){
        if( i  == '.'){
            cout << endl;
            return 0;
        }
        cout << i;
    }
 
 
 
 
 
}

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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;

int main()
{
    speed;
    cout << fixed << setprecision(6);
    /*start*/
    int n;
    int k;
    cin >> n >> k;
    map<int, int> m;
    rep(i, n) m[i] = 0;
    rep(i,k){
        int d;
        cin >> d;
        rep(i,d){
            int a;
            cin >> a;
            m.at(a - 1)++;
        }
    }
    int res = 0;
    rep(i,n){
        if(m[i]==0)
            res++;
    }
    c(res);
}


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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int X = sc.nextInt();
		int[] C = new int[N];
		int[][] A = new int[N][M];
		for (int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
			for (int j = 0; j < M; j++) {
				A[i][j] = sc.nextInt();	
			}
		}
		int ans = 1 << 25;
		int[] r = new int[M];
		L: for (int S = 1; S < 1 << N; S++) {
			int csum = 0;
			Arrays.fill(r, 0);
			for (int i = 0; i < N; i++) {
				if (((S >> i) & 1) > 0) {
					csum += C[i];
				}
			}
			if (csum >= ans) continue;
			for (int i = 0; i < N; i++) {
				if (((S >> i) & 1) > 0) {
					for (int j = 0; j < M; j++) {
						r[j] += A[i][j];
					}
				}
			}
			for (int j = 0; j < M; j++) {
				if (r[j] < X) {
					continue L;
				}
			}
			ans = csum;
		}
		System.out.println(ans < 1 << 25? ans : -1);
	}
}


Measured memory_bytes: 37328
#include <stdio.h>
 
typedef struct{
  char suit;
  char value;
} Card;

void Bubble(Card *, int);
void Selection(Card *, int);
int TorF(Card *, Card *, int);
void Print(Card *, int);

int main()
{
  int n, i;
  Card c1[100], c2[100];
 
  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf(" %c%c",&c1[i].suit,&c1[i].value);
    c2[i] = c1[i];
  }
 
  Bubble(c1, n);
  Selection(c2, n);
 
  Print(c1, n);
  printf("Stable\n");
  Print(c2, n);
  if(TorF(c1, c2, n) == n) printf("Stable\n");
  else printf("Not stable\n");
   
  return 0;
}

void Bubble(Card *X, int n)
{
  int i, j;
  Card card1;
  for(i = 0; i < n; i++){
    for(j = n-1; j >= i; j--){
      if(X[j].value < X[j-1].value){
    card1 = X[j];
    X[j] = X[j-1];
    X[j-1] = card1;
      }
    }
  }
}
 
void Selection(Card *X, int n)
{
  int i, j, k;
  Card card2;
  for(i = 0; i < n; i++){
    k = i;
    for(j = i; j < n; j++) if(X[j].value < X[k].value) k = j;
    card2 = X[i];
    X[i] = X[k];
    X[k] = card2;
  }
}
 
int TorF(Card *X, Card *Y, int n)
{
  int i, count=0;
  for(i = 0; i < n; i++) if(X[i].suit == Y[i].suit) count++;
  return count;
}
 
void Print(Card *X, int n)
{
  int i;
  for(i = 0; i < n; i++){
    if(i != n-1) printf("%c%c ", X[i].suit, X[i].value);
    else printf("%c%c", X[i].suit, X[i].value);
  }
  printf("\n");
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int n=s.size();
    map<char,int> mp;
    if(n==26){
        if(s=="zyxwvutsrqponmlkjihgfedcba") cout<<-1;
        else{
            string t=s;
            next_permutation(all(t));
            rep(i,n){
                cout<<t[i];
                if(s[i]!=t[i]) return 0;
            }
        }
    }
    else{
        rep(i,n) mp[s[i]]++;
        char c;
        for(c='a';c<='z';c++) if(mp[c]==0) break;
        cout<<s<<c;
    }
}

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(bool x) {cerr << (x ? "true" : "false");}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}

template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";}
template <typename T, typename... V>void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define ff first
#define endl "\n"
#define ss second
#define maxn 2000006
#define pb push_back
#define ll long long
#define lll __int128
#define vll vector<ll>
#define mll map<ll,ll>
#define MOD 1000000007
#define pll pair<ll,ll>
#define ull unsigned long long
#define f(i,x,n) for(ll i=x;i<=n;i++)
#define fr(i,x,n) for(ll i=x;i>=n;i--)
inline ll min(ll a, ll b, ll c) { return min(min(a, b), c);}
inline ll max(ll a, ll b, ll c) { return max(max(a, b), c);}
inline void fastio() {ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);}

int dx[] = { -1, 0, 1, 0, -1, -1, 1, 1};
int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};



int main() {
	fastio();

	int h, w; cin >> h >> w;
	vector<vector<char>> mat(h + 1, vector<char>(w + 1, '\0'));
	f(i, 1, h) f(j, 1, w) cin >> mat[i][j];

	vector<vector<ll> > dp(h + 1, vector<ll>(w + 1, 0));

	dp[1][1] = (mat[1][1] == '.');
	f(j, 2, w) dp[1][j] = (dp[1][j - 1] * (mat[1][j] == '.'));
	f(i, 2, h) dp[i][1] = (dp[i - 1][1] * (mat[i][1] == '.'));

	f(i, 2, h) {
		f(j, 2, w) {
			if (mat[i][j] == '#') continue;

			dp[i][j] = (dp[i - 1][j] % MOD + dp[i][j - 1] % MOD) % MOD;
		}
	}

	cout << dp[h][w];

	return 0;
}

Measured memory_bytes: 9088
#include<bits/stdc++.h>
using namespace std;
string to_string(const string& s) {
	return '"' + s + '"';
}
string to_string(const bool b) {
	return (b ? "true" : "false");
}
string to_string(const char* s) {
	return to_string((string)s);
}
string to_string(const char c) {
	string s = "'";
	s += c;
	s += "'";
	return s;
}
template<class T, class U>
string to_string(const pair<T, U>& p) {
	string s = "(";
	s += to_string(p.first);
	s += ", ";
	s += to_string(p.second);
	s += ")";
	return s;
}
template<class T>
string to_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += to_string(x);
	}
	s += "}";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << to_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod1 = 1e9 + 7;
const int mod2 = 1e9 + 9;
const int inf = 1e9 + 100;
const ll inf64 = 7e18l;
const int b1 = 1215135141;
const int b2 = 1256165151;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int a, b;
	int k;
	cin >> k >> a >> b;
	int next = -1;
	if (a % k == 0) {
		next = a;
	} else {
		next = a + (k - a % k);
	}
	if (next <= b) {
		cout << "OK\n";
	} else {
		cout << "NG\n";
	}
 	return 0;
}


Measured memory_bytes: 3652
#include<iostream>
#include<string>
#include <algorithm>

using namespace std;

int main() {
	long int a, b, c, d, A, B, C, D;
	cin >> a >> b >> c >> d;
	A = a * c;
	B = a * d;
	C = b * c;
	D = b * d;
	cout << max({ A,B,C,D });

	return 0;
}

Measured memory_bytes: 3608
import sys
import bisect

sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
def gcd(a,b):
    r = a%b;
    while r > 0:
        a = b
        b = r
        r = a%b
    return b
def lcm(a,b):
    return a*b//gcd(a,b)
def main():
    a,b,c,d = map(int,read().split())
    acnum = (a-1)//c
    bcnum = (b)//c
    adnum = (a-1)//d
    bdnum = (b)//d
    acdnum = (a-1)//(lcm(c,d))
    bcdnum = (b)//(lcm(c,d))

    print((b-a+1)-(bcnum-acnum)-(bdnum-adnum) + (bcdnum-acdnum))
if __name__ == '__main__':
    main()


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

long long A;
long long B;
long long C;

int main()
{
    cin>>A>>B>>C;

    if (A+B>=C)
    {
        cout<<B+C<<endl;
    }

    else
    {
        cout<<A+2*B+1<<endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int H, W;
	while (1){
		cin >> H>>W;
		if (H == 0 & W == 0)break;
		for (int i = 0; i < H; i++){
			for (int k = 0; k < W; k++){
				if (i == 0 || k == 0 || i==H-1 || k==W-1){
					cout << "#";
				}
				else cout << ".";
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}
	

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

int N, M, ans = 1;

int main() {
    cin >> N >> M;
    for (int a = 1; a * a <= M; a++) {
        if (M % a != 0) continue;
        int b = M / a;
        if ((ll)a * N <= M) ans = max(ans, a);
        if ((ll)b * N <= M) ans = max(ans, b);
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
from sys import stdin

class Vector:
    def __init__(self, x=None, y=None):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector(self.x + other.x, self.y + other.y)

    def __sub__(self, other):
        return Vector(self.x - other.x, self.y - other.y)

    def __mul__(self, k):
        return Vector(self.x * k, self.y * k)

    def __gt__(self, other):
        return self.x > other.x and self.y > other.y

    def __eq__(self, other):
        return self.x == other.x and self.y == other.y

    def dot(self, other):
        return self.x * other.x + self.y * other.y

    # usually cross operation return Vector but it returns scalor
    def cross(self, other):
        return self.x * other.y - self.y * other.x

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

class Segment:
    def __init__(self, p1=Vector(0, 0), p2=Vector(1, 1)):
        self.p1 = p1
        self.p2 = p2

def is_orthogonal(*args, **kwargs):
    # input two vectors with the startpoint (0, 0)
    if len(args) == 2:
        v1, v2 = args
        return v1.dot(v2) == 0
    # input two vectors with the startpoint (a1, b1) and endpoint (a2, b2)
    elif len(args) == 4:
        a1, a2, b1, b2 = args
        return is_orthogonal(a1 - a2, b1 - b2)
    # input two segments
    elif len(kwargs) == 2:
        v1 = kwargs['s1'].p1 - kwargs['s1'].p2
        v2 = kwargs['s2'].p1 - kwargs['s2'].p2
        return v1.dot(v2) == 0
    else:
        raise ArgsError

def is_parallel(*args, **kwargs):
    # input two vectors with the startpoint (0, 0)
    if len(args) == 2:
        v1, v2 = args
        return v1.cross(v2) == 0
    # input two vectors with the startpoint (a1, b1) and endpoint (a2, b2)
    elif len(args) == 4:
        a1, a2, b1, b2 = args
        return is_parallel(a1 - a2, b1 - b2)
    # input two segments
    elif len(kwargs) == 2:
        v1 = kwargs['s1'].p1 - kwargs['s1'].p2
        v2 = kwargs['s2'].p1 - kwargs['s2'].p2
        return v1.cross(v2) == 0
    else:
        raise ArgsError

from sys import stdin

def read_and_print_results(n):
    for _ in range(n):
        line = stdin.readline().strip().split()
        p0 = Vector(int(line[0]), int(line[1]))
        p1 = Vector(int(line[2]), int(line[3]))
        p2 = Vector(int(line[4]), int(line[5]))
        p3 = Vector(int(line[6]), int(line[7]))
        s1 = Segment(p0, p1)
        s2 = Segment(p2, p3)
        if is_parallel(s1=s1, s2=s2):
            print('2')
        elif is_orthogonal(s1=s1, s2=s2):
            print('1')
        else:
            print('0')

n = int(input())
read_and_print_results(n)


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

using namespace std;

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

	vector<int> created;
	created.push_back(s);
	int ans = 1;
	int prev = s;
	while (true)
	{
		ans++;

		if (prev % 2 == 0) prev = prev / 2;
		else prev = 3 * prev + 1;


		if (find(created.begin(), created.end(), prev) == created.end()) created.push_back(prev);
		else break;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
using dou = double;
const ll INF = 1LL << 60;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b; return true;}return false;}
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b; return true;}return false;}
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
/*  vector<ll> vec = {1,2,5,6,8,9,10};
    cout << binary_search(all(vec),5) << endl; -> true*/
/*
    vector<ll> vec = {1,2,5,6,8,9,10};
    auto n = upper_bound(all(vec),4);
    cout << *n << endl; -> 5*/
/*
    cout << fixed << setprecision(15);
    */
int main(){
    ll N;
    cin >> N;
    ll cnt = 0;
    while(N){
        cnt++;
        N /= 2;
    }
    ll ans = 1;
    rep(i,cnt - 1){
        ans *= 2;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000009
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    { 
       string s;
       cin>>s;
       if(s[2]==s[3] && s[4]==s[5] && s[0]!=s[1])
       cout<<"Yes";
       else
       cout<<"No";
       
    }
}

    
// 🍪 🍪 🍪


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

using ll = long long;
using namespace std;

int main() {
  map<string, int> mp;
  int n;
  cin >> n;
  string s;
  set<string> items;
  rep(i, n) {
    cin >> s;
    items.insert(s);
  }
  cout << items.size() << endl;
  return 0;
}

Measured memory_bytes: 19044
# -*- coding: utf-8 -*-
from sys import stdin

s_in = lambda: stdin.readline()[:-1] # s = s_in()
d_in = lambda: int(stdin.readline()) # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split())) # List = ds_in()

S = s_in()
Mod = 10**9 + 7

dp = [0] * 4 # [*, A, B, C]
dp[0] = 1

for s in S:
    if s == 'A':
        dp[1] += dp[0]
    elif s == 'B':
        dp[2] += dp[1]
    elif s == 'C':
        dp[3] += dp[2]
    else:
        temp = dp.copy()
        for i in range(4):
            dp[i] *= 3
        dp[1] += temp[0]
        dp[2] += temp[1]
        dp[3] += temp[2]
    for i in range(4):
        dp[i] %= Mod

print(dp[3])


Measured memory_bytes: 3188
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define repr(i, n) for(int i = (n-1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    string n; cin >> n;
    string ans = "";
    rep(i, (int)n.size()){
        if(n[i]=='1') ans += "9";
        else if(n[i]=='9') ans += "1";
        else ans += n[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 888
use std::io;
use std::cmp;
use std::collections::HashMap;
fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let N: i64 = iter.next().unwrap().parse().unwrap();
    let P: i64 = iter.next().unwrap().parse().unwrap();
    let mut max: i64 = 1;
    for (divisor, count2) in &primeFactor(P) {
//        println!("{} {}", *divisor,*count2);
        let mut count: i64 = *count2;
                while count >= N {
                    max *= *divisor;
                    count -= N;
                }
    }
    println!("{}", max);
}
fn primeFactor(n0: i64) -> HashMap<i64,i64> {
    let mut n: i64 = n0;
    let mut res: HashMap<i64,i64> = HashMap::new();
    let mut i: i64 = 2;
    while i*i<=n {
        while n % i == 0 {
            let count = match res.get(&i) {
                Some(&c) => c,
                None => 0
            };
            res.insert(i, 1+count);
            n/=i;
        }
        i+=1;
    }
    if n!=1 {
            let count = match res.get(&n) {
                Some(&c) => c,
                None => 0
            };
            res.insert(n, 1+count);
//            match res.get(&n) {
//                Some(count) => res.insert(n, 1+count),
//                None => res.insert(n, 1)
//            }
//            let count: i64 = * res.get(&n).unwrap();
//        res.insert(n, 1+count);
    }
    return res;
}


Measured memory_bytes: 4352
from math import gcd

from math import factorial as f

from math import ceil,floor,sqrt


import bisect
import re
import heapq


from copy import deepcopy
import itertools

from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

yes = "Yes"
no = "No"

def main():
    s = input()
    for i in s:
        if i == '7':
            print(yes)
            exit()
    print(no)


main()





Measured memory_bytes: 9896
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t; cin >> s >> t;
  int x = -1;
  FOR(i,0,s.length()) {
    bool ok = true;
    FOR(j,0,t.length()) {
      if(s[i+j] == '?') continue;
      if(s[i+j] != t[j]) ok = false;
    }
    if(ok) x = i;
  }
  if(x < 0) cout << "UNRESTORABLE" << endl;
  else {
    FOR(i,0,x) {
      if(s[i] == '?') cout << "a";
      else cout << s[i];
    }
    cout << t;
    FOR(i,x+t.length(),s.length()) {
      if(s[i] == '?') cout << "a";
      else cout << s[i];
    }
    cout << endl;
  }
  return 0;
}

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

int main() {
  int a , b;
  cin >> a >> b;
  if (a * b % 2 == 0) {
  	cout << "Even" << endl;
  }
  else if (a * b % 2 == 1) {
    cout << "Odd" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int main(){
  int n;
  char a[101];
  char b[101];
  int temp;
  int p = 0;
  int i;
  int flag;
  cin >> n;
  while(p < n){
    flag = 0;
    for(i = 0;i < 101;i++){
      a[i] = '0';
      b[i] = '0';
    }
    scanf("%s %s",a,b);
    temp = 100;
    for(i = strlen(a) - 1;i >= 0;i--){
      a[temp] = a[i];
      a[i] = '0';
      temp--;
    }
    temp = 100;
    for(i = strlen(b) - 1;i >= 0;i--){
      b[temp] = b[i];
      b[i] = '0';
      temp--;
    }
    for(i = 100;i >= 0;i--){
      a[i] += b[i] - '0';
      if(a[i] > '9'){
	a[i - 1]++;
	a[i] -= 10;
      }
    }
    for(i = 0;i < 101;i++){
      if(a[i] >= '1'){
	if(i <= 20){
	  cout << "overflow";
	  break;
	}
	flag = 1;
      }
      if(flag || i == 100){
	cout << a[i];
      }
    }
    cout << endl;
    p++;
  }
  return(0);
}

Measured memory_bytes: 1180
module WeightedDirectedGraph
  (Weight : sig
    type t
    val inf : t (* オーバーフローの恐れはないので，max_intとか突っ込んでも良い *)
    val zero : t
    val neg_inf : t (* オーバーフローの恐れはないので，min_intとか突っ込んでも良い *)
    val ( + ) : t -> t -> t
    val compare : t -> t -> int
  end) :
sig
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  val bellman_ford :
    (* 頂点数n *)
    int ->
    (* 辺のリスト
       頂点は0からn-1までの整数でなくてはならない *)
    (int * int * Weight.t) church_list ->
    (* 始点 *)
    int ->
    (* 頂点を受け取り，そこまでの距離を返す関数
       頂点に到達するパスが無ければinfを返し，
       そこに到達するまでに負閉路があればneg_infを返す *)
    (int -> Weight.t)
end =
struct
  type 'a church_list = { fold : 'b. ('a -> 'b -> 'b) -> 'b -> 'b }

  let bellman_ford n es s =
    (* 距離を覚えるやつ *)
    let d = Array.make n Weight.inf in
    (* 自己辺の最小のコスト *)
    let self = Array.make n Weight.inf in
    (* 始点より終点のインデックスが大きくなる辺を集めた隣接リスト *)
    let inc = Array.make n [] in
    (* 始点より終点のインデックスが小さくなる辺を集めた隣接リスト *)
    let dec = Array.make n [] in
    es.fold (fun ((u, v, c) as e) () ->
      match compare v u with
      | 0 -> if 0 < Weight.compare self.(u) c then self.(u) <- c
      | cmp when 0 < cmp -> inc.(u) <- e :: inc.(u)
      | _ -> dec.(u) <- e :: dec.(u)) ();
    (* 自己辺は最初に緩和する必要がある *)
    Array.iteri (fun v c ->
      if 0 < Weight.compare Weight.inf c then
        inc.(v) <- (v, v, c) :: inc.(v)) self;
    d.(s) <- Weight.zero;
    (* 残りの反復回数 *)
    let i = ref n in
    (* 更新が行われたか *)
    let is_modified = ref true in
    (* 各辺の処理 *)
    let f (u, v, c) =
      let open Weight in
      (* 原点から到達できない頂点は更新しない *)
      if 0 < Weight.compare inf d.(u) then
        let dv = if 0 <= Weight.compare neg_inf d.(u) then neg_inf else d.(u) + c in
        if 0 < Weight.compare d.(v) dv then
          (is_modified := true; d.(v) <- if !i <= succ n lsr 1 then neg_inf else dv) in
    while 0 < !i && !is_modified do
      is_modified := false;
      (* インデックスが増加する辺の処理 *)
      for u = 0 to n - 1 do
        List.iter f inc.(u)
      done;
      (* インデックスが減少する辺の処理 *)
      for u = n - 1 downto 0 do
        List.iter f dec.(u)
      done;
      decr i
    done;
    Array.get d
end

module G = WeightedDirectedGraph (struct
  type t = int
  let zero = 0
  let inf = min_int
  let neg_inf = max_int
  let ( + ) = ( + )
  let compare x y = compare y x
end)

let () = Scanf.scanf "%d %d %d\n" @@ fun n m p ->
  let abc = Array.init m @@ fun _ ->
    Scanf.scanf "%d %d %d\n" @@ fun a b c -> a - 1, b - 1, c - p in
  let d = G.bellman_ford n { G.fold = fun f -> Array.fold_right f abc } 0 (n - 1) in
  if max_int <= d
  then print_endline "-1"
  else Printf.printf "%d\n" @@ max 0 d


Measured memory_bytes: 6204
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	string s;
	while(cin >> s) {
		int a = 0, b = 0;
		rep(i, s.size() - 2) {
			if(s[i] == 'J' && s[i+1] == 'O' && s[i+2] == 'I') a++;
			if(s[i] == 'I' && s[i+1] == 'O' && s[i+2] == 'I') b++;
		}

		cout << a << endl;
		cout << b << endl;
	}
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cstring>
using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

const int MAXN = 101;
int res[MAXN];
int po[MAXN];
bool used[MAXN];
typedef pair<int, int> pp;

int main()
{
    int n, game;
    cin >> n; game = n * (n - 1) /2;
    vector<pp> p;

    int a, b, c, d;
    REP(game)
    {
        cin >> a >> b >> c >> d;
        a--; b--;
        if(c > d){ po[a] += 3; continue;}
        if(c < d){ po[b] += 3; continue;}
        po[a]++; po[b]++;
    }
    REP(n) p.push_back(pp(po[i], i));
    sort(all(p), greater<pp>() );
    
    int junni = 1;
    res[p[0].second] = junni;
    for(int i = 1;i <n;i++)
    {
        if(p[i].first == p[i-1].first )res[p[i].second] = junni;
        else{ junni = i + 1; res[p[i].second] = junni;}
    }
    REP(n) cout << res[i] << endl;
    return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;

int** dp;
int N,M;
int POW[23],base[500],work[500];
char table[500][501];

int makeCode(){

	int ret = 0;

	for(int i = 0; i < M; i++){
		if(work[i] == 1){
			ret += POW[i];
		}
	}
	return ret;
}


void func_N(){

	int limit = POW[N];

	int ans = 0,count;
	bool FLG;

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

		for(int k = 0; k < M; k++)work[k] = 0;

		count = 0;

		for(int loop = 0; loop < N; loop++){
			if(i & (1 << loop)){
				count++;
				for(int k = 0; k < M; k++){
					work[k] += table[loop][k] - '0';
				}
			}
		}

		FLG = true;
		for(int k = 0; k < M; k++){
			if(work[k]%2 == 1){
				FLG = false;
				break;
			}
		}

		if(FLG)ans = max(ans,count);

	}

	printf("%d\n",ans);
}


void func_M(){

	int limit = POW[M];

	for(int i = 0; i < limit; i++){
		dp[0][i] = 0;
		dp[1][i] = 0;
	}

	for(int i = 0; i < M; i++){
		work[i] = table[0][i]-'0';
	}
	dp[1][makeCode()] = 1;

	int array[500],tmp;

	for(int i = 1; i < N; i++){

		for(int state = 0; state < limit; state++){
			dp[0][state] = dp[1][state];
		}

		for(int k = 0; k < M; k++){
			array[k] = table[i][k] - '0';
		}

		for(int state = 0; state < limit; state++){
			if(dp[0][state] == 0)continue;

			for(int loop = 0; loop < M; loop++){
				if(state & (1 << loop)){
					base[loop] = 1;
				}else{
					base[loop] = 0;
				}
			}

			for(int k = 0; k < M; k++){
				work[k] = base[k]+array[k];
				work[k] %= 2;
			}

			tmp = makeCode();
			dp[1][tmp] = max(dp[1][tmp],dp[0][state]+1);
		}

		for(int k = 0; k < M; k++){
			work[k] = array[k];
		}

		tmp = makeCode();
		dp[1][tmp] = max(dp[1][tmp],1);
	}

	printf("%d\n",dp[1][0]);
}


int main(){

	for(int i = 0; i <= 22; i++){
		POW[i] = pow(2,i);
	}

	dp = new int*[2];
	dp[0] = new int[POW[22]];
	dp[1] = new int[POW[22]];


	while(true){
		scanf("%d %d",&N,&M);
		if(N == 0 && M == 0)break;

		for(int i = 0; i < N; i++){
			scanf("%s",table[i]);
		}

		if(N <= M)func_N();
		else{
			func_M();
		}
	}

	return 0;
}

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

using namespace std;

typedef long long ll;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main()
{
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int m,n,ans=0;
    cin>>m>>n;
    for(int i=1;i<=m;i++)
    {
        for(int j=10;j<=n;j++)
        {
            int t1=j/10;
            int t2=j%10;
            if(t1>=2&&t2>=2&&t1*t2==i)
                ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
def check(i):
  i = int(i)
  if 12 < i or i == 0:
    return "YY"
  else:
    return "MM"


S = input().strip()
l, r = map(check, (S[:2], S[2:]))

if l == r:
  if l == "MM":
    print("AMBIGUOUS")
  else:
    print("NA")
else:
  print(l + r)


Measured memory_bytes: 2940
using System;
using System.Linq;

class Program{
	static void Main(){
    	var HtC = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
      	var arts = Console.ReadLine().Split(' ').Select(int.Parse).Sum();
		
      	if(HtC[0]-arts >0){
        	Console.Write("No");
        }else{
        	Console.Write("Yes");      
        }
    }
}

Measured memory_bytes: 16224
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repA(i,a,b) for(int i=a;i<=b;i++)
#define repD(i,b,a) for(int i=b;i>=a;i--)
#define mset(a,val) memset(a,val,sizeof(a))
#define f first
#define s second
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
int main()
{
    int n;
    cin>>n;
    unordered_map<string,int>mp;
    rep(i,0,n)
    {
        string str;
        cin>>str;
        mp[str]++;
    }
    string a[]={"AC","WA","TLE","RE"};
    rep(i,0,4)
    cout<<a[i]<<" x "<<mp[a[i]]<<endl;
}


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

int main()
{
  int n, x, l, d = 0, ans = 1;
  cin >> n >> x;
  while (n--)
  {
    cin >> l;
    d += l;
    ans +=  d <= x;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint q;std::cin>>q;
    std::multiset<lint>left,right;
    lint ans=0;
    while(q--){
        lint c;std::cin>>c;
        if(c==1){
            lint a,b;std::cin>>a>>b;
            ans+=b;
            left.insert(a),right.insert(a);
            lint x=*left.rbegin(),y=*right.begin();
            if(x>y){
                ans+=x-y;
                left.erase(std::prev(left.end())),right.erase(right.begin());
                left.insert(y),right.insert(x);
            }
        }
        if(c==2){
            std::cout<<*left.rbegin()<<' '<<ans<<'\n';
        }
    }
}


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

int main(void) {
    int H, N;
    cin >> H >> N;
    int A[N+10];

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

    sort(A, A + N, greater<int>());

    int sum = 0;
    for(int i = 0; i < N; i++){
        sum += A[i];
    }
    if(sum < H) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }

    return 0;
}

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

#define ff first
#define ss second
#define mp make_pair
#define pb push_back

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    int A, B;
    string S;
    cin >> A >> B >> S;
    int cnt = 0;
    for (char e : S) if (e == '-')
		cnt++;
	
	if (cnt == 1 && S[A] == '-')
		cout << "Yes";
	else
		cout << "No";
	
	
		
	
	return 0;
}


Measured memory_bytes: 256
#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int64_t Prev(const vector<int64_t> &count, char ch, int64_t possibilities)
{
    if (ch == 'A') {
        return possibilities;
    }
    return count[ch - 'A' - 1];
}

int main()
{
    string str;
    getline(cin, str);

    constexpr int64_t kMod = 1e9 + 7;
    vector<int64_t> count(3, 0);

    int64_t possibilities = 1;
    for (const auto &ch : str) {
        if (ch != '?') {
            count[ch - 'A'] += Prev(count, ch, possibilities);
            count[ch - 'A'] %= kMod;
            continue;
        }

        vector<int64_t> new_count(3);
        for (char i = 'A'; i <= 'C'; i += 1) {
            new_count[i - 'A'] = 3 * count[i - 'A'] + Prev(count, i, possibilities);
            new_count[i - 'A'] %= kMod;
        }
        count = new_count;
        possibilities *= 3;
        possibilities %= kMod;
    }

    cout << count[2] << "\n";
    return 0;
}


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

int a,b,c,lim1,lim2,tp;

void exgcd(int a,int b,int &x,int &y) {
	if(!b) { x=1;y=0;return; }
	exgcd(b,a%b,y,x);y-=a/b*x;
}

int inv(int a,int p) {
	int x,y;exgcd(a,p,x,y);
	return (x+p)%p;
}

struct dat {
	int x,y,cnt;
} st[110];

void get(int c,int d) {
	tp=0;int a=1,b=0;
	while(d) {
		++tp;st[tp]=(dat){st[tp-1].x+c/d*a,st[tp-1].y+c/d*d,c/d};
		for(int t=0;t<2&&d;t++) {
			if(!t) b+=c/d*a; else a+=c/d*b;
			swap(c,d);d%=c;
		}
	}
}

ll Div(ll a,ll b) {
	if(a<0) return -1;
	return a/b;
}

int main() {
	ios::sync_with_stdio(0);cin.tie(0);
	int T;cin>>T;
	while(T--) {
		cin>>a>>lim1>>b>>lim2>>c;
		int g=__gcd(a,b);a/=g;b/=g;c/=__gcd(c,g);
		g=__gcd(a,c);lim2/=g/__gcd(g,b);a/=g;b/=__gcd(g,b);c/=g;
		g=__gcd(b,c);lim1/=g/__gcd(g,a);a/=__gcd(g,a);b/=g;c/=g;
		a%=c;b%=c;
		if(c==1) { cout<<lim1+lim2<<'\n';continue; }
		int d=1ll*a*inv(b,c)%c;get(c,d);int ans=0;
		if(st[tp].x!=c) st[++tp]=(dat){c,c,1};
		for(int i=1;i<=tp;i++) {
			int lx=st[i-1].x,ly=c-st[i-1].y,rx=st[i].x,ry=c-st[i].y;
			int dx=(rx-lx)/st[i].cnt,dy=(ly-ry)/st[i].cnt;
			//cerr<<lx<<' '<<ly<<' '<<rx<<' '<<ry<<' '<<dx<<' '<<dy<<' '<<st[i].cnt<<'\n';
			int l=ans,r=lim1+lim2;
			while(l<r) {
				int mid=(1ll+l+r)>>1;
				if(max(0ll,Div(1ll*mid*ly-lim2+dy-1,dy))<=min(1ll*st[i].cnt*mid,Div(lim1-1ll*mid*lx,dx))) l=mid;
				else r=mid-1;
			}
			ans=max(ans,l);
		}
		cout<<ans<<'\n';
	}
	return 0;
}


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

using namespace std;

int sosu(int num){
	int k;
	for(k = 2;k < num; k++){
		if(num%k == 0) return 0;
	}
	return num;
}

int main(void)
{
	int x;
	cin>>x;
	int i,ans;
	ans = 0;
	i = x;
	while(ans == 0){
		ans = sosu(i);
		i++;
	}
	cout<<ans<<endl;
	return 0;
}
/*
int main(void)
{
	long int a,b,k;
	cin>>a>>b>>k;
	if(a > k){
		//cout<<a-k<<" "<<b<<endl;
		printf("%ld %ld\n",a-k,b);
	}
	else if(a < k && a+b > k){
		//cout<<"0 "<<a+b-k<<endl;
		printf("0 %ld\n",a+b-k);
	}
	else{
		printf("0 0\n");
		//cout<<"0 0"<<endl;
	}
	return 0;
}
*/
/*
int main(void){
	int a;
	char S[110],T[110];
	cin>>S>>T;
	cout<<T<<S<<endl;
	
	return 0;
}
*/


Measured memory_bytes: 256
N = int(input())
List9 = [9 ** i for i in range(1,7) if 9 ** i <= N]
List6 = [6 ** i for i in range(1,7) if 6 ** i <= N]

def recur(n,con):
  if n == 0:
    return con

  elif n < 6:
    return con + n
    
  elif n < 9:
    return con + (n - 5)

  else:
    max9 = [i for i in List9 if i <= n][-1]
    max6 = [i for i in List6 if i <= n][-1]
    
    return min(recur(n - max9,con + 1),recur(n - max6,con + 1))
    
print(recur(N,0))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int q, n, p,res;
int main(){
    
    
    cin>>n;
    for(int i=1,x;i<=n;i++){
        cin>>x;
        res += (i%2 + x%2 == 2);
    }
    cout<<res;


}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
using namespace std;
using Graph = vector<vector<int>>;

void dfs(const Graph &G, int v, int p, vector<int> &cnt){
    if(p != -1){
        cnt[v] += cnt[p];
    }

    for(auto nv : G[v]){
        if(nv == p) continue;
        dfs(G, nv, v, cnt);
    }
}

int main(){
    int n, q;
    cin >> n >> q;
    Graph G(n+1);
    int a, b;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    vector<int> cnt(n+1, 0);
    int p, x;
    for (int i = 0; i < q; ++i) {
        cin >> p >> x;
        cnt[p] += x;
    }

    dfs(G, 1, -1, cnt);
    for (int i = 0; i < n; ++i) {
        cout << cnt[i+1] << " ";
    }
    cout << endl;
}

Measured memory_bytes: 26624
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 21;
const int mod = (int) 1e9 + 7;

int n;
bool mat[N][N];
int memo[1 << N];

int dp(int mask) {
  if (mask == (1 << n) - 1) return 1;
  if (memo[mask] != -1) return memo[mask];
  int x = __builtin_popcount(mask);
  int ans = 0;
  for (int j = 0; j < n; j++) {
    if (!(mask & (1 << j)) && mat[x][j]) {
      ans = (ans + dp(mask | (1 << j))) % mod;
    }
  }
  return memo[mask] = ans;
}

int main() {
  cin >> n;
  memset(memo, -1, sizeof memo);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      int x;
      cin >> x;
      mat[i][j] = x;
    }
  }
  cout << dp(0) << endl;
  return 0;
}


Measured memory_bytes: 8448
#include<stdio.h>
#define N 500000
int a;

void maxHeapify(int *A,int i);
void buildMaxHeap(int *A);

int main(){
  
  int B[N+1];
  int i;
  
  scanf("%d",&a);
  
  for(i=1;i<=a;i++) scanf("%d",&B[i]);
  
  buildMaxHeap(B);

  for(i=1;i<=a;i++) printf(" %d",B[i]);
  
  printf("\n");

  return 0;
}

void maxHeapify(int *A,int i){
  
  int c;
  int l,r,largest;
  
  l = 2*i;
  
  r = 2*i+1;

  if(l<=a && A[l] > A[i]) largest = l;
  
  else largest = i;
  
  if(r<=a && A[r]>A[largest]) largest = r;
  
  if(largest != i){
    
    c = A[i];
    
    A[i] = A[largest];
    
    A[largest] = c;
    
    maxHeapify(A,largest);
    
  } 
}

void buildMaxHeap(int *A){
  
  int i;

  for(i=a/2;i>=1;i--) maxHeapify(A,i);
  
}



Measured memory_bytes: 3716
def swap(a,b,arr):
    tmp = arr[a]
    arr[a] = arr[b]
    arr[b] = tmp

N = int(input())
P = [0] + list(map(int,input().split()))
cnt = 0
for i in range(1,N+1):
    if P[i] == i:
        swap(i,i+1,P) if i<N else 0
        cnt += 1 
print(cnt)

Measured memory_bytes: 13880
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)
##############################

N, M = map(int, input().split())
src = [tuple(map(int, input().split())) for _ in range(M)]
#print(src)

# 1-index なので+1
X = [ [] for _ in range(N+1) ]

for i, (p, y) in enumerate(src):
    X[p].append((y, i))
for c in X:
    c.sort()

#print(X)

ans = [None] * M
for p in range(len(X)):
    # 0([])の場合は、通らない
    for i,(_,j) in enumerate(X[p]):
        s = str(p).zfill(6) + str(i+1).zfill(6)
        ans[j] = s

print(*ans, sep='\n')

Measured memory_bytes: 47844
#include<iostream>
using namespace std;
int map[114][514];
void dfs(int i, int j) {
	map[i][j] = 0;
	for (int a = -1; a < 2; a++) {
		for (int b = -1; b < 2; b++) {
			if (map[i + a][b + j] == 1)dfs(i + a, b + j);
		}
	}
	return;
}
int main() {
	int h, w; 
	while (cin >> h >> w, h, w) {
		for (int i = 1; i <= w; i++) {
			for (int j = 1; j <= h; j++) {
				cin >> map[i][j];
			}
		}
		int ans = 0;
		for (int i = 1; i <= w; i++) {
			for (int j = 1; j <= h; j++) {
				if (map[i][j]) {
					dfs(i, j);
					ans++;
				}
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3300
from collections import defaultdict

def main():
    N = int(input())
    combs = [(S[0], S[-1]) for S in map(str, range(1, N+1))]
    d = defaultdict(int)
    for pre, suf in combs:
        if suf != "0":
            d[(pre, suf)] += 1
            d[(suf, pre)]

    ans = 0
    for key, val in d.items():
        pre, suf = key
        ans += val * d[(suf, pre)]
        
    print(ans)
if __name__ == "__main__":
    main()

Measured memory_bytes: 17652
#include <chrono>
#include <iostream>

using namespace std;
using namespace std::chrono;

int main() {
  auto start = high_resolution_clock::now();

  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, k;
  cin >> n >> k;
  int ans = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    ans += 2 * min(x, abs(x - k));
  }
  cout << ans << endl;

  cerr << "Total execution time : " << duration_cast<milliseconds>(high_resolution_clock::now() - start).count() << " ms" << endl;

  return 0;
}


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

struct edge{
  int to;
  int64_t cost;
  edge(){}
  edge(int t,int64_t c):to(t),cost(c){}
};
vector<vector<edge>> adj;
vector<int64_t> dist,dist2;

void dfs1(int cur,int prv){
  for(auto nxt:adj[cur]){
    if(nxt.to==prv)continue;
    dfs1(nxt.to,cur);
    dist[cur] = max(dist[cur],dist[nxt.to]+nxt.cost);
  }
}

void dfs2(int cur,int prv){
  vector<pair<int64_t,int>> tmp;
  tmp.emplace_back(dist2[cur],prv);
  for(auto nxt:adj[cur]){
    if(nxt.to==prv)continue;
    tmp.emplace_back(dist[nxt.to]+nxt.cost,nxt.to);
  }
  sort(tmp.begin(),tmp.end(),greater<>());
  for(auto nxt:adj[cur]){
    if(nxt.to==prv)continue;
    dist2[nxt.to] = max(dist2[nxt.to],tmp[tmp[0].second==nxt.to].first+nxt.cost);
    dfs2(nxt.to,cur);
  }
}

signed main(){

  int n;
  cin>>n;
  adj.resize(n);
  dist.resize(n);
  dist2.resize(n);
  for(int i=0;i<n-1;++i){
    int s,t,w;
    cin>>s>>t>>w;
    adj[s].emplace_back(t,w);
    adj[t].emplace_back(s,w);
  }
  dfs1(0,-1);
  dfs2(0,-1);;
  for(int i=0;i<n;++i){
    cout<< max(dist[i],dist2[i]) <<endl;
  }

}


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

const int INF = 1 << 30;

int main() {
  int dp[50010];
  int bills[30];
  int n,m,c,i,j;

  cin >> n >> m;

  for (i = 0; i < m; ++i) {
    cin >> bills[i];
  }

  for (i = 0; i <= n; ++i) {
    dp[i] = INF;
  }

  dp[0] = 0;

  for (i = 0; i < m; ++i) {
    for (j = bills[i]; j <= n; ++j) {
      dp[j] = min(dp[j],dp[j - bills[i]] + 1);
    }
  }

  cout << dp[n] << endl;

  return 0;
}



Measured memory_bytes: 3316
# include <algorithm>
# include <cassert>
# include <cctype>
# include <cstdio>
# include <cstdlib>
# include <cstring>
# include <cmath>
# include <iostream>
# include <map>
# include <queue>
# include <set>
# include <sstream>
# include <stack>
# include <string>
# include <vector>
# include <iomanip>

# define rep(i, n) for (int i = 0; i < (int)(n); i++)
# define irep(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++)

using namespace std;

long long gcd(long long x, long long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}

int main() {
  long long a, b;
  cin >> a >> b;

  cout << gcd(a, b) << endl;
}

Measured memory_bytes: 1156
import heapq
import numpy as np

N, M = map(int, input().split())
A = list(map(int, input().split()))

for i in range(N):
    A[i] *= -1
    
heapq.heapify(A)  # Aをheapに変換
for _ in range(M):
    x = heapq.heappop(A)  # Aの中の最小値を取り出して返す
    heapq.heappush(A, (-x//2)*-1)
    
print(-sum(A))

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T>
void remove_duplication(vector<T> &v){
    sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

template<typename T>
struct BIT{
    private:
        using Func = function<T(T, T)>;

        int n;
        vector<T> node;

        T init_v;
        Func func;

    public:

        BIT(int N, Func _func, T _init_v) {
            n = N + 1;
            init_v = _init_v;
            func = _func;

            node.resize(n, init_v);
            for(int i=1; i<n; i++) if((i+(i&-i)) < n) node[i+(i&-i)] = func(node[i+(i&-i)], node[i]);
        }

        BIT() {}

        void add(int pos, T v) {
            // 1-indexed
            while(pos < n){
                node[pos] = func(node[pos], v);
                pos += pos & -pos;
            }
        }

        T sum(int pos){
            // 1-indexed
            T res = init_v;
            while(pos > 0){
                res = func(res, node[pos]);
                pos = pos & (pos-1);
            }
            return res;
        }
};

void Main(){
    ll N,K; cin >> N >> K;
    VL a(N); REP(i,N) cin >> a[i];
    VL S(N+1,0); REP(i,N) S[i+1] = S[i] + a[i];

    VL b(N+1); REP(i,N+1) b[i] = S[i]-K*i; remove_duplication(b);
    map<ll,ll> m;
    REP(i,b.size()) m[b[i]] = i;

    ll ans = 0;
    BIT<ll> bit(N+1,[](ll a,ll b){return a+b;},0);
    bit.add(m[0]+1,1);
    REP(i,N){
        ll c = S[i+1] - K*(i+1);
        ans += bit.sum(m[c]+1);
        bit.add(m[c]+1,1);
    }
    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 19072